diff --git a/blockchain-server/blockchain-server-user/src/main/resources/bootstrap.yml b/blockchain-server/blockchain-server-user/src/main/resources/bootstrap.yml index edf2f92..2ce250b 100644 --- a/blockchain-server/blockchain-server-user/src/main/resources/bootstrap.yml +++ b/blockchain-server/blockchain-server-user/src/main/resources/bootstrap.yml @@ -1,7 +1,5 @@ server: port: 8101 - servlet: - context-path: /user #注册中心 eureka: client: diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/entity/YyyfMoney.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/entity/YyyfMoney.java index 46eb713..deff9bc 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/entity/YyyfMoney.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/entity/YyyfMoney.java @@ -16,7 +16,7 @@ import java.util.Date; * @description * @date 2020-05-26 21:30 */ -@Table(name = "Yyyf_money") +@Table(name = "yyyf_money") @Data public class YyyfMoney implements Serializable { private static final long serialVersionUID = 8690026237757740821L; diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/init/InitData.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/init/InitData.java new file mode 100644 index 0000000..00b2701 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/init/InitData.java @@ -0,0 +1,47 @@ +package com.blockchain.server.yyyf.init; + +import com.blockchain.server.yyyf.service.AssessUserService; + +/** + * @author Mr.Xu + * @version 1.0 + * @className InitData + * @description + * @date 2020-05-06 15:42 + */ +public class InitData { + private static InitData initData=null; + + public InitData(){ + + } + + + public static InitData getInstance(){ + synchronized (InitData.class){ + if(initData==null){ + initData=new InitData(); + } + } + return initData; + } + + + public void init(){ + initExamPaperDto(); + } + + /** + * @description 初始化试卷(项目)数据 + * @author Mr.Xu + * @date 2020-05-06 16:21:52 + * @param [] + * @return void + **/ + private void initExamPaperDto(){ + AssessUserService trainManageService= (AssessUserService) SpringContextUtil.getBean("assessUserService"); + trainManageService.initAllExamPaperDto(); + } + + +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/init/InitProject.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/init/InitProject.java new file mode 100644 index 0000000..2d493d3 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/init/InitProject.java @@ -0,0 +1,33 @@ +package com.blockchain.server.yyyf.init; + + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.stereotype.Component; + +/** + * @author Mr.Xu + * @version 1.0 + * @className InitProject + * @description 初始化项目 + * @date 2020-05-06 16:16 + */ +@Component +public class InitProject implements ApplicationRunner { + private static final Logger LOG = LoggerFactory.getLogger(InitProject.class); + + + @Override + public void run(ApplicationArguments args) throws Exception { + LOG.info("==========init project==========="); + try { + InitData.getInstance().init(); + LOG.info("============init data success============"); + } catch (Exception e) { + LOG.error("init data error={}", e.getMessage()); + } + + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/init/SpringContextUtil.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/init/SpringContextUtil.java new file mode 100644 index 0000000..e025ce1 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/init/SpringContextUtil.java @@ -0,0 +1,59 @@ +package com.blockchain.server.yyyf.init; + +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +@Component +public class SpringContextUtil implements ApplicationContextAware { + + // Spring应用上下文环境 + private static ApplicationContext applicationContext; + + /** + * 实现ApplicationContextAware接口的回调方法。设置上下文环境 + * + * @param applicationContext + */ + public void setApplicationContext(ApplicationContext applicationContext) { + SpringContextUtil.applicationContext = applicationContext; + } + + /** + * @return ApplicationContext + */ + public static ApplicationContext getApplicationContext() { + return applicationContext; + } + + /** + * 获取对象 + * + * @param name + * @return Object + * @throws BeansException + */ + public static Object getBean(String name) throws BeansException { + return applicationContext.getBean(name); + } + public static T getBean(Class requiredType) throws BeansException { + return applicationContext.getBean(requiredType); + } + public static HttpServletRequest getHttpServletRequest() { + return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); + } + public static HttpServletResponse getHttpServletResponse() { + return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse(); + } + public static HttpSession getHttpSession() { + HttpServletRequest request = getHttpServletRequest(); + return request.getSession(); + } +} \ No newline at end of file diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/TrainCaseManageMapper.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/TrainCaseManageMapper.java new file mode 100644 index 0000000..343d33f --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/TrainCaseManageMapper.java @@ -0,0 +1,27 @@ +package com.blockchain.server.yyyf.mapper; + +import com.blockchain.server.train.dto.ExamPaperDto; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * (TrainCaseManage)表数据库访问层 + * + * @author qianqian.zhang + * @since 2020-04-16 16:03:48 + */ +@Repository +public interface TrainCaseManageMapper { + + + /** + * @description + * @author Mr.Xu + * @date 2020-05-06 15:50:51 + * @param [] + * @return void + **/ + + List getAllExamPaperDto(); +} \ No newline at end of file diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/AssessUserService.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/AssessUserService.java index 018f047..be32c31 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/AssessUserService.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/AssessUserService.java @@ -1,6 +1,7 @@ package com.blockchain.server.yyyf.service; +import com.blockchain.server.train.dto.ExamPaperDto; import com.blockchain.server.train.dto.TrainCaseTargetDto; import com.blockchain.server.yyyf.dto.AssessUserDto; import com.blockchain.server.yyyf.dto.UserTimeMoneyDto; @@ -106,4 +107,13 @@ public interface AssessUserService { * @return com.blockchain.server.yyyf.dto.UserTimeMoneyDto **/ UserTimeMoneyDto getUserTimeMoneyDtoByAssessUserId(String assessUserId); + + /** + * @description 缓存获取所有练习和考核 + * @author zijie + * @date 2020-07-22 21:48:16 + * @param [] + * @return void + **/ + void initAllExamPaperDto(); } diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssessUserServiceImpl.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssessUserServiceImpl.java index 935af93..c512dbf 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssessUserServiceImpl.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssessUserServiceImpl.java @@ -1,6 +1,7 @@ package com.blockchain.server.yyyf.service.impl; import com.blockchain.common.base.constant.YyyfConstant; +import com.blockchain.server.train.dto.ExamPaperDto; import com.blockchain.server.train.dto.TrainCaseTargetDto; import com.blockchain.server.yyyf.dto.AssessUserDto; import com.blockchain.server.yyyf.dto.ExamDto; @@ -14,6 +15,7 @@ import com.blockchain.server.yyyf.exceprion.YyyfException; import com.blockchain.server.yyyf.indicators.IndicatorsManager; import com.blockchain.server.yyyf.mapper.AssessUserMapper; import com.blockchain.server.yyyf.mapper.AssessUserTargetMapper; +import com.blockchain.server.yyyf.mapper.TrainCaseManageMapper; import com.blockchain.server.yyyf.mapper.YyyfMoneyMapper; import com.blockchain.server.yyyf.service.AssessUserService; import com.blockchain.server.yyyf.utils.HttpClientUtil; @@ -56,6 +58,8 @@ public class AssessUserServiceImpl implements AssessUserService { private AssessUserTargetMapper assessUserTargetMapper; @Autowired private YyyfMoneyMapper yyyfMoneyMapper; + @Autowired + private TrainCaseManageMapper trainCaseManageMapper; //@Autowired private IndicatorsManager indicatorsManager; @@ -304,6 +308,18 @@ public class AssessUserServiceImpl implements AssessUserService { return this.assessUserMapper.getUserTimeMoneyDtoByAssessUserId(assessUserId); } + @Override + public void initAllExamPaperDto() { + + List examPaperDtoList = trainCaseManageMapper.getAllExamPaperDto(); + redisTemplate.delete(YyyfConstant.EXAM_PAPER_KEY); + HashOperations examPaperOpsForHash = redisTemplate.opsForHash(); + + for (ExamPaperDto examPaperDto : examPaperDtoList) { + examPaperOpsForHash.put(YyyfConstant.EXAM_PAPER_KEY, examPaperDto.getId(), examPaperDto); + } + } + /** * @param [assessUserTarget, targetResultMap] * @return void diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/task/ScheduleTask.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/task/ScheduleTask.java index ad2610b..e757f3a 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/task/ScheduleTask.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/task/ScheduleTask.java @@ -36,6 +36,10 @@ public class ScheduleTask { @Scheduled(initialDelay = 5000,fixedRate=60000) private void OneMinuteTask() { + logger.info("开始扫描案例"+ new Date()); + this.assessUserService.initAllExamPaperDto(); + logger.info("完成扫描案例"+ new Date()); + logger.info("开始扫描考试"+ new Date()); HashOperations examDtoOpsForHash = redisTemplate.opsForHash(); Map examDtoMap = examDtoOpsForHash.entries(YyyfConstant.EXAM_KEY); diff --git a/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/TrainCaseManageMapper.xml b/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/TrainCaseManageMapper.xml new file mode 100644 index 0000000..43503fe --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/TrainCaseManageMapper.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file