Commit ff37f499 by 涂亚平

学生昨天记录数据导入

1 parent 07127669
......@@ -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;
/**
* <p>
......@@ -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;
}
}
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;
}
......@@ -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;
/**
* <p>
......@@ -16,4 +17,5 @@ public interface ExerciseDoneResultService extends IService<ExerciseDoneResultDO
GetDoneDetailVO getDoneDetail(ExerciseDoneResultDO exerciseDoneResultDO);
void importData(MultipartFile file);
}
package com.subsidy.service.impl;
import com.subsidy.model.ExerciseDoneResultDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.subsidy.dto.exercise.ImportHistory;
import com.subsidy.mapper.ExerciseDoneHistoryMapper;
import com.subsidy.model.*;
import com.subsidy.mapper.ExerciseDoneResultMapper;
import com.subsidy.service.ExerciseDoneResultService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.util.excel.ExcelUtil;
import com.subsidy.vo.exercise.GetDoneDetailVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Random;
/**
* <p>
......@@ -18,8 +30,65 @@ import org.springframework.stereotype.Service;
@Service
public class ExerciseDoneResultServiceImpl extends ServiceImpl<ExerciseDoneResultMapper, ExerciseDoneResultDO> 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<ExerciseDoneResultDO> exerciseDoneResultDOS = exerciseDoneResultMapper.selectList(new QueryWrapper<ExerciseDoneResultDO>()
.lambda()
.eq(ExerciseDoneResultDO::getPaperId,s.getPaperId())
.eq(ExerciseDoneResultDO::getScore,s.getScore()));
//随机获取一个人
Random random = new Random();
ExerciseDoneResultDO exerciseDoneResultDO = exerciseDoneResultDOS.get(random.nextInt(exerciseDoneResultDOS.size()));
//找到这个人的答卷
List<ExerciseDoneHistoryDO> exerciseDoneHistoryDOS = exerciseDoneHistoryMapper.selectList(new QueryWrapper<ExerciseDoneHistoryDO>()
.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();
}
}
}
# 本地环境配置
# 数据源配置
#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
......
......@@ -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
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!