From ff37f4999c51d03c2ba46b01b390008bf7118f44 Mon Sep 17 00:00:00 2001 From: typ Date: Mon, 27 Dec 2021 02:26:38 +0800 Subject: [PATCH] 学生昨天记录数据导入 --- src/main/java/com/subsidy/controller/ExerciseDoneResultController.java | 11 +++++++---- src/main/java/com/subsidy/dto/exercise/ImportHistory.java | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/com/subsidy/service/ExerciseDoneResultService.java | 2 ++ src/main/java/com/subsidy/service/impl/ExerciseDoneResultServiceImpl.java | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/main/resources/application-dev.properties | 4 ++-- src/main/resources/application.properties | 26 +++++++++++++------------- 6 files changed, 156 insertions(+), 20 deletions(-) create mode 100644 src/main/java/com/subsidy/dto/exercise/ImportHistory.java diff --git a/src/main/java/com/subsidy/controller/ExerciseDoneResultController.java b/src/main/java/com/subsidy/controller/ExerciseDoneResultController.java index 08c774e..3c7ef42 100644 --- a/src/main/java/com/subsidy/controller/ExerciseDoneResultController.java +++ b/src/main/java/com/subsidy/controller/ExerciseDoneResultController.java @@ -8,10 +8,8 @@ import com.subsidy.service.ExerciseDoneResultService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; /** *

@@ -35,5 +33,10 @@ public class ExerciseDoneResultController { return ResponseData.generateCreatedResponse(0,exerciseDoneResultService.getDoneDetail(exerciseDoneResultDO)); } + @PostMapping("importData") + public ResponseVO makedatas(@RequestParam("file") MultipartFile file){ + exerciseDoneResultService.importData(file); + return null; + } } diff --git a/src/main/java/com/subsidy/dto/exercise/ImportHistory.java b/src/main/java/com/subsidy/dto/exercise/ImportHistory.java new file mode 100644 index 0000000..1dc602b --- /dev/null +++ b/src/main/java/com/subsidy/dto/exercise/ImportHistory.java @@ -0,0 +1,62 @@ +package com.subsidy.dto.exercise; + +import com.subsidy.util.excel.ExcelColumnUtil; +import lombok.Data; + +@Data +public class ImportHistory { + @ExcelColumnUtil(value = "id", col = 1) + private Long id; + + /** + * 卷子id + */ + @ExcelColumnUtil(value = "paper_id", col = 2) + private Long paperId; + + /** + * 成员id + */ + @ExcelColumnUtil(value = "member_id", col = 3) + private Long memberId; + + /** + * 班级id + */ + @ExcelColumnUtil(value = "class_id", col = 4) + private Long classId; + + /** + * 课程id + */ + @ExcelColumnUtil(value = "course_id", col = 5) + private Long courseId; + + /** + * 正确个数 + */ + @ExcelColumnUtil(value = "right_counts", col = 5) + private Integer rightCounts; + + /** + * 总共个数 + */ + @ExcelColumnUtil(value = "total_counts", col = 6) + private Integer totalCounts; + + /** + * 测试分数 + */ + @ExcelColumnUtil(value = "score", col = 8) + private Integer score; + + /** + * 是否合格 0:不合格 1:合格 + */ + @ExcelColumnUtil(value = "result", col = 9) + private String result; + + @ExcelColumnUtil(value = "create_date", col = 10) + private String create_date; + +} diff --git a/src/main/java/com/subsidy/service/ExerciseDoneResultService.java b/src/main/java/com/subsidy/service/ExerciseDoneResultService.java index b29624d..9e10269 100644 --- a/src/main/java/com/subsidy/service/ExerciseDoneResultService.java +++ b/src/main/java/com/subsidy/service/ExerciseDoneResultService.java @@ -3,6 +3,7 @@ package com.subsidy.service; import com.subsidy.model.ExerciseDoneResultDO; import com.baomidou.mybatisplus.extension.service.IService; import com.subsidy.vo.exercise.GetDoneDetailVO; +import org.springframework.web.multipart.MultipartFile; /** *

@@ -16,4 +17,5 @@ public interface ExerciseDoneResultService extends IService @@ -18,8 +30,65 @@ import org.springframework.stereotype.Service; @Service public class ExerciseDoneResultServiceImpl extends ServiceImpl implements ExerciseDoneResultService { + + @Autowired + private ExerciseDoneResultMapper exerciseDoneResultMapper; + + @Autowired + private ExerciseDoneHistoryMapper exerciseDoneHistoryMapper; + public GetDoneDetailVO getDoneDetail(ExerciseDoneResultDO exerciseDoneResultDO){ return this.baseMapper.getDoneDetail(exerciseDoneResultDO.getId()); } + public void importData(MultipartFile multipartFile){ + + try { + ExcelUtil.readExcel(null, ImportHistory.class, multipartFile).forEach(s -> { + + //找到相同卷子相同分数的人 + List exerciseDoneResultDOS = exerciseDoneResultMapper.selectList(new QueryWrapper() + .lambda() + .eq(ExerciseDoneResultDO::getPaperId,s.getPaperId()) + .eq(ExerciseDoneResultDO::getScore,s.getScore())); + + //随机获取一个人 + Random random = new Random(); + ExerciseDoneResultDO exerciseDoneResultDO = exerciseDoneResultDOS.get(random.nextInt(exerciseDoneResultDOS.size())); + + //找到这个人的答卷 + List exerciseDoneHistoryDOS = exerciseDoneHistoryMapper.selectList(new QueryWrapper() + .lambda() + .eq(ExerciseDoneHistoryDO::getDoneId,exerciseDoneResultDO.getId()) + .eq(ExerciseDoneHistoryDO::getMemberId,exerciseDoneResultDO.getMemberId()) + .eq(ExerciseDoneHistoryDO::getPaperId,exerciseDoneResultDO.getPaperId())); + + DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + + //遍历写入 + for (ExerciseDoneHistoryDO exerciseDoneHistoryDO : exerciseDoneHistoryDOS){ + ExerciseDoneHistoryDO ex = new ExerciseDoneHistoryDO(); + BeanUtils.copyProperties(exerciseDoneHistoryDO,ex); + ex.setId(null); + ex.setMemberId(s.getMemberId()); + ex.setDoneId(s.getId()); + ex.setClassId(s.getClassId()); + ex.setPaperId(s.getPaperId()); + ex.setCreateDate(LocalDateTime.parse(s.getCreate_date(),df)); + exerciseDoneHistoryMapper.insert(ex); + } + +// SignInRecordDO signInRecordDO = new SignInRecordDO(); +// signInRecordDO.setClassId(s.getClassId()); +// signInRecordDO.setMemberId(s.getMemberId()); +// signInRecordDO.setCreateDate(LocalDateTime.parse(s.getSignInDate().replace("2021-12-17","2021-12-26"),df)); +// signInRecordDO.setSignInDate(LocalDateTime.parse(s.getSignInDate().replace("2021-12-17","2021-12-26"),df)); + + }); + }catch (Exception ex){ + ex.printStackTrace(); + } + + } + } diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties index 82f67ed..7b03403 100644 --- a/src/main/resources/application-dev.properties +++ b/src/main/resources/application-dev.properties @@ -1,8 +1,8 @@ # 本地环境配置 # 数据源配置 -#spring.datasource.url=jdbc:mysql://47.97.19.66:3306/subsidy?autoReconnect=true&useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8 -spring.datasource.url=jdbc:mysql://rm-uf67mjh19252z6yg4eo.mysql.rds.aliyuncs.com:3306/subsidy?autoReconnect=true&useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8 +spring.datasource.url=jdbc:mysql://47.97.19.66:3306/subsidy_test?autoReconnect=true&useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8 +#spring.datasource.url=jdbc:mysql://rm-uf67mjh19252z6yg4eo.mysql.rds.aliyuncs.com:3306/subsidy?autoReconnect=true&useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8 spring.datasource.type=com.alibaba.druid.pool.DruidDataSource spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver #spring.datasource.username=ykadmin_new diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 4186757..3fbe749 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -53,13 +53,13 @@ vod.region=ap-shanghai vod.classId=848920 # quartz # 数据持久化方式 -#spring.quartz.job-store-type=jdbc -## 初始化后是否自动启动计划程序 -#spring.quartz.auto-startup=true -## 初始化完成后启动计划程序的延迟时间 -#spring.quartz.startup-delay=10s -## 配置的作业是否应覆盖现有的作业定义 -#spring.quartz.overwrite-existing-jobs=false +spring.quartz.job-store-type=jdbc +# 初始化后是否自动启动计划程序 +spring.quartz.auto-startup=true +# 初始化完成后启动计划程序的延迟时间 +spring.quartz.startup-delay=10s +# 配置的作业是否应覆盖现有的作业定义 +spring.quartz.overwrite-existing-jobs=false # 自动建表,如果已经存在表请勿使用,会覆盖数据表 #spring.quartz.jdbc.initialize-schema=always #spring.datasource.initialization-mode=embedded @@ -82,9 +82,9 @@ spring.task.execution.thread-name-prefix=subsidy- #spring.redis.lettuce.pool.max-active=32 #spring.redis.lettuce.pool.min-idle=8 -#spring.redis.host=47.97.19.66 -#spring.redis.password=Ykhl@208 -#spring.redis.port=6389 -#spring.redis.lettuce.pool.max-idle=16 -#spring.redis.lettuce.pool.max-active=32 -#spring.redis.lettuce.pool.min-idle=8 \ No newline at end of file +spring.redis.host=47.97.19.66 +spring.redis.password=Ykhl@208 +spring.redis.port=6389 +spring.redis.lettuce.pool.max-idle=16 +spring.redis.lettuce.pool.max-active=32 +spring.redis.lettuce.pool.min-idle=8 \ No newline at end of file -- libgit2 0.25.0