main
xingzi 2 years ago
parent 3641bba15a
commit 3cefdee896

@ -0,0 +1,9 @@
FROM openjdk:8u272-jdk
RUN apt-get update && apt-get install -y redis-server
WORKDIR /application
ARG JAR_FILE=./eladmin-system/target/eladmin-system-2.7.jar
COPY ${JAR_FILE} application.jar
ENTRYPOINT ["java", "-jar", "/application/application.jar"]

@ -15,21 +15,39 @@
*/ */
package me.zhengjie; package me.zhengjie;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.ApplicationPidFileWriter; import org.springframework.boot.context.ApplicationPidFileWriter;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing; import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.repository.query.FluentQuery.FetchableFluentQuery;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.alipay.api.domain.Goods;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.rest.AnonymousGetMapping; import me.zhengjie.annotation.rest.AnonymousGetMapping;
import me.zhengjie.mapper.db1.IStoreMapper; import me.zhengjie.mapper.db1.IStoreMapper;
import me.zhengjie.mapper.db2.IStoreMapper2; import me.zhengjie.mapper.db2.IStoreMapper2;
import me.zhengjie.modules.goods.repository.GoodsRepository;
import me.zhengjie.utils.SpringContextHolder; import me.zhengjie.utils.SpringContextHolder;
/** /**
@ -42,9 +60,10 @@ import me.zhengjie.utils.SpringContextHolder;
@RestController @RestController
@Api(hidden = true) @Api(hidden = true)
@SpringBootApplication @SpringBootApplication
@EnableTransactionManagement // @EnableTransactionManagement
@EnableJpaAuditing(auditorAwareRef = "auditorAware") // @EnableJpaAuditing(auditorAwareRef = "auditorAware")
@RequiredArgsConstructor @RequiredArgsConstructor
@Component
public class AppRun { public class AppRun {
public static void main(String[] args) { public static void main(String[] args) {
@ -73,6 +92,265 @@ public class AppRun {
public String index() { public String index() {
System.out.println(iStoreMapper.findByName("店1")); System.out.println(iStoreMapper.findByName("店1"));
System.out.println(iStoreMapper2.findByName("店1")); System.out.println(iStoreMapper2.findByName("店1"));
// test();
return "Backend service started successfully"; return "Backend service started successfully";
} }
// public void test() {
// // 设置使用主数据源
// DynamicDataSource.setCurrentLookupKey("primaryDataSource");
// // 执行数据库操作
// System.out.println("query start:");
// GoodsRepository goodsRepository = new GoodsRepository() {
// @Override
// public List<me.zhengjie.modules.goods.domain.Goods> findAll() {
// // TODO Auto-generated method stub
// Goods goods = new Goods();
// }
// @Override
// public List<me.zhengjie.modules.goods.domain.Goods> findAll(Sort sort) {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method 'findAll'");
// }
// @Override
// public List<me.zhengjie.modules.goods.domain.Goods>
// findAllById(Iterable<Integer> ids) {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method
// 'findAllById'");
// }
// @Override
// public <S extends me.zhengjie.modules.goods.domain.Goods> List<S>
// saveAll(Iterable<S> entities) {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method 'saveAll'");
// }
// @Override
// public void flush() {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method 'flush'");
// }
// @Override
// public <S extends me.zhengjie.modules.goods.domain.Goods> S saveAndFlush(S
// entity) {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method
// 'saveAndFlush'");
// }
// @Override
// public <S extends me.zhengjie.modules.goods.domain.Goods> List<S>
// saveAllAndFlush(Iterable<S> entities) {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method
// 'saveAllAndFlush'");
// }
// @Override
// public void deleteAllInBatch(Iterable<me.zhengjie.modules.goods.domain.Goods>
// entities) {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method
// 'deleteAllInBatch'");
// }
// @Override
// public void deleteAllByIdInBatch(Iterable<Integer> ids) {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method
// 'deleteAllByIdInBatch'");
// }
// @Override
// public void deleteAllInBatch() {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method
// 'deleteAllInBatch'");
// }
// @Override
// public me.zhengjie.modules.goods.domain.Goods getOne(Integer id) {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method 'getOne'");
// }
// @Override
// public me.zhengjie.modules.goods.domain.Goods getById(Integer id) {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method 'getById'");
// }
// @Override
// public <S extends me.zhengjie.modules.goods.domain.Goods> List<S>
// findAll(Example<S> example) {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method 'findAll'");
// }
// @Override
// public <S extends me.zhengjie.modules.goods.domain.Goods> List<S>
// findAll(Example<S> example, Sort sort) {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method 'findAll'");
// }
// @Override
// public Page<me.zhengjie.modules.goods.domain.Goods> findAll(Pageable
// pageable) {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method 'findAll'");
// }
// @Override
// public <S extends me.zhengjie.modules.goods.domain.Goods> S save(S entity) {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method 'save'");
// }
// @Override
// public Optional<me.zhengjie.modules.goods.domain.Goods> findById(Integer id)
// {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method 'findById'");
// }
// @Override
// public boolean existsById(Integer id) {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method 'existsById'");
// }
// @Override
// public long count() {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method 'count'");
// }
// @Override
// public void deleteById(Integer id) {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method 'deleteById'");
// }
// @Override
// public void delete(me.zhengjie.modules.goods.domain.Goods entity) {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method 'delete'");
// }
// @Override
// public void deleteAllById(Iterable<? extends Integer> ids) {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method
// 'deleteAllById'");
// }
// @Override
// public void deleteAll(Iterable<? extends
// me.zhengjie.modules.goods.domain.Goods> entities) {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method 'deleteAll'");
// }
// @Override
// public void deleteAll() {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method 'deleteAll'");
// }
// @Override
// public <S extends me.zhengjie.modules.goods.domain.Goods> Optional<S>
// findOne(Example<S> example) {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method 'findOne'");
// }
// @Override
// public <S extends me.zhengjie.modules.goods.domain.Goods> Page<S>
// findAll(Example<S> example,
// Pageable pageable) {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method 'findAll'");
// }
// @Override
// public <S extends me.zhengjie.modules.goods.domain.Goods> long
// count(Example<S> example) {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method 'count'");
// }
// @Override
// public <S extends me.zhengjie.modules.goods.domain.Goods> boolean
// exists(Example<S> example) {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method 'exists'");
// }
// @Override
// public <S extends me.zhengjie.modules.goods.domain.Goods, R> R
// findBy(Example<S> example,
// Function<FetchableFluentQuery<S>, R> queryFunction) {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method 'findBy'");
// }
// @Override
// public Optional<me.zhengjie.modules.goods.domain.Goods> findOne(
// Specification<me.zhengjie.modules.goods.domain.Goods> spec) {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method 'findOne'");
// }
// @Override
// public List<me.zhengjie.modules.goods.domain.Goods> findAll(
// Specification<me.zhengjie.modules.goods.domain.Goods> spec) {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method 'findAll'");
// }
// @Override
// public Page<me.zhengjie.modules.goods.domain.Goods> findAll(
// Specification<me.zhengjie.modules.goods.domain.Goods> spec, Pageable
// pageable) {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method 'findAll'");
// }
// @Override
// public List<me.zhengjie.modules.goods.domain.Goods> findAll(
// Specification<me.zhengjie.modules.goods.domain.Goods> spec, Sort sort) {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method 'findAll'");
// }
// @Override
// public long count(Specification<me.zhengjie.modules.goods.domain.Goods> spec)
// {
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method 'count'");
// }
// };
// System.out.println("query end:");
// // ...
// // 清除数据源上下文
// DynamicDataSource.clearCurrentLookupKey();
// // 设置使用辅数据源
// DynamicDataSource.setCurrentLookupKey("secondDataSource");
// // 执行数据库操作
// System.out.println("query2 start:");
// System.out.println("query2 end:");
// // ...
// // 清除数据源上下文
// DynamicDataSource.clearCurrentLookupKey();
// }
} }

@ -0,0 +1,23 @@
package me.zhengjie;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
public class DynamicDataSource extends AbstractRoutingDataSource {
private static final ThreadLocal<String> contextHolder = new ThreadLocal<>();
@Override
protected Object determineCurrentLookupKey() {
System.out.println("get:" + contextHolder.get());
return contextHolder.get();
}
public static void setCurrentLookupKey(String key) {
System.out.println("set:" + key);
contextHolder.set(key);
}
public static void clearCurrentLookupKey() {
contextHolder.remove();
}
}

@ -15,16 +15,18 @@
*/ */
package me.zhengjie.modules.quartz.config; package me.zhengjie.modules.quartz.config;
import lombok.RequiredArgsConstructor; import java.util.List;
import me.zhengjie.modules.quartz.domain.QuartzJob;
import me.zhengjie.modules.quartz.repository.QuartzJobRepository;
import me.zhengjie.modules.quartz.utils.QuartzManage;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner; import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List;
import lombok.RequiredArgsConstructor;
import me.zhengjie.modules.quartz.domain.QuartzJob;
import me.zhengjie.modules.quartz.repository.QuartzJobRepository;
import me.zhengjie.modules.quartz.utils.QuartzManage;
/** /**
* @author Zheng Jie * @author Zheng Jie
@ -48,4 +50,5 @@ public class JobRunner implements ApplicationRunner {
quartzJobs.forEach(quartzManage::addJob); quartzJobs.forEach(quartzManage::addJob);
log.info("Timing task injection complete"); log.info("Timing task injection complete");
} }
} }

@ -15,6 +15,25 @@
*/ */
package me.zhengjie.modules.quartz.rest; package me.zhengjie.modules.quartz.rest;
import java.io.IOException;
import java.util.Set;
import javax.servlet.http.HttpServletResponse;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -27,15 +46,6 @@ import me.zhengjie.modules.quartz.service.QuartzJobService;
import me.zhengjie.modules.quartz.service.dto.JobQueryCriteria; import me.zhengjie.modules.quartz.service.dto.JobQueryCriteria;
import me.zhengjie.utils.PageResult; import me.zhengjie.utils.PageResult;
import me.zhengjie.utils.SpringContextHolder; import me.zhengjie.utils.SpringContextHolder;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Set;
/** /**
* @author Zheng Jie * @author Zheng Jie

Loading…
Cancel
Save