diff --git a/src/main/java/com/sztzjy/money_management/controller/RankController.java b/src/main/java/com/sztzjy/money_management/controller/RankController.java index 1471e40..5214245 100644 --- a/src/main/java/com/sztzjy/money_management/controller/RankController.java +++ b/src/main/java/com/sztzjy/money_management/controller/RankController.java @@ -28,4 +28,17 @@ public class RankController { } return flag; } + + @AnonymousAccess + @ApiOperation("执行排行方法") + @PostMapping("doRankOne") + public Boolean doRankOne(String schoolId){ + Boolean flag=scoreRankService.doRankOne(schoolId); + if(flag){ + System.out.println("排行方法执行成功"); + }else { + System.out.println("排行方法执行失败"); + } + return flag; + } } diff --git a/src/main/java/com/sztzjy/money_management/controller/SynthesisPlanController.java b/src/main/java/com/sztzjy/money_management/controller/SynthesisPlanController.java index e2ef66d..0cadae7 100644 --- a/src/main/java/com/sztzjy/money_management/controller/SynthesisPlanController.java +++ b/src/main/java/com/sztzjy/money_management/controller/SynthesisPlanController.java @@ -9,6 +9,7 @@ import com.sztzjy.money_management.entity.*; import com.sztzjy.money_management.entity.dto.SynthesisPlanScoreDto; import com.sztzjy.money_management.entity.dto.UserStatisticsDto; import com.sztzjy.money_management.mapper.*; +import com.sztzjy.money_management.service.ScoreRankService; import com.sztzjy.money_management.service.SynthesisPlanService; import com.sztzjy.money_management.util.ResultEntity; import io.swagger.annotations.Api; @@ -47,6 +48,8 @@ public class SynthesisPlanController { ClientFamilyInfoMapper clientFamilyInfoMapper; @Autowired SynthesisPlanService synthesisPlanService; + @Autowired + ScoreRankService scoreRankService; //目标客户查询 //根据create_time排序 @@ -246,6 +249,7 @@ public class SynthesisPlanController { } synthesisPlanClient.setSubmitStatus("未审核"); synthesisPlanClientMapper.updateByPrimaryKeySelective(synthesisPlanClient); + return new ResultEntity<>(HttpStatus.OK, "规划报告提交成功!"); } return new ResultEntity<>(HttpStatus.BAD_REQUEST, "规划报告提交失败!提交状态错误"); diff --git a/src/main/java/com/sztzjy/money_management/service/ScoreRankService.java b/src/main/java/com/sztzjy/money_management/service/ScoreRankService.java index 9cae7f1..3befabf 100644 --- a/src/main/java/com/sztzjy/money_management/service/ScoreRankService.java +++ b/src/main/java/com/sztzjy/money_management/service/ScoreRankService.java @@ -8,6 +8,7 @@ import java.util.List; public interface ScoreRankService { Boolean doRank(); + Boolean doRankOne(String schoolId); List selectExportScoreRankList(String schoolId); diff --git a/src/main/java/com/sztzjy/money_management/service/impl/CaseServiceImpl.java b/src/main/java/com/sztzjy/money_management/service/impl/CaseServiceImpl.java index f45f631..9912384 100644 --- a/src/main/java/com/sztzjy/money_management/service/impl/CaseServiceImpl.java +++ b/src/main/java/com/sztzjy/money_management/service/impl/CaseServiceImpl.java @@ -2383,14 +2383,14 @@ public class CaseServiceImpl implements CaseService { example.createCriteria().andCaseidEqualTo(caseID); List comCases = comCaseMapper.selectByExample(example); - SynthesisPlanClientExample example1 = new SynthesisPlanClientExample(); - example1.createCriteria().andUseridEqualTo(userId).andCaseidEqualTo(caseID); - List synthesisPlanClientList = synthesisPlanClientMapper.selectByExample(example1); - if (synthesisPlanClientList != null && !synthesisPlanClientList.isEmpty()) { - SynthesisPlanClient synthesisPlanClient = synthesisPlanClientList.get(0); - synthesisPlanClient.setSubmitStatus("未审核"); - synthesisPlanClientMapper.updateByPrimaryKey(synthesisPlanClient); - } +// SynthesisPlanClientExample example1 = new SynthesisPlanClientExample(); +// example1.createCriteria().andUseridEqualTo(userId).andCaseidEqualTo(caseID); +// List synthesisPlanClientList = synthesisPlanClientMapper.selectByExample(example1); +// if (synthesisPlanClientList != null && !synthesisPlanClientList.isEmpty()) { +// SynthesisPlanClient synthesisPlanClient = synthesisPlanClientList.get(0); +// synthesisPlanClient.setSubmitStatus("未审核"); +// synthesisPlanClientMapper.updateByPrimaryKey(synthesisPlanClient); +// } if (comCases == null || comCases.isEmpty()) { log.info("未查询到综合案例信息表"); return new ResultEntity<>(HttpStatus.INTERNAL_SERVER_ERROR, "服务器异常,请联系管理员!"); diff --git a/src/main/java/com/sztzjy/money_management/service/impl/ChapterServiceImpl.java b/src/main/java/com/sztzjy/money_management/service/impl/ChapterServiceImpl.java index e447849..121baf5 100644 --- a/src/main/java/com/sztzjy/money_management/service/impl/ChapterServiceImpl.java +++ b/src/main/java/com/sztzjy/money_management/service/impl/ChapterServiceImpl.java @@ -40,7 +40,7 @@ public class ChapterServiceImpl implements ChapterService { list.add(schoolId); criteria.andSourceIn(list); } - + chapterExample.setOrderByClause("add_time asc"); List chapters = chapterMapper.selectByExample(chapterExample); return chapters; } diff --git a/src/main/java/com/sztzjy/money_management/service/impl/ScoreRankServiceImpl.java b/src/main/java/com/sztzjy/money_management/service/impl/ScoreRankServiceImpl.java index af498a8..047c32c 100644 --- a/src/main/java/com/sztzjy/money_management/service/impl/ScoreRankServiceImpl.java +++ b/src/main/java/com/sztzjy/money_management/service/impl/ScoreRankServiceImpl.java @@ -38,10 +38,14 @@ public class ScoreRankServiceImpl implements ScoreRankService { @Override @Scheduled(cron = "0 0 1 * * ?") public Boolean doRank() { + //先删除当天所有的数据 防止脏数据 + ScoreRankExample scoreRankExample = new ScoreRankExample(); + scoreRankExample.createCriteria().andUpdateDateEqualTo(getNowDate()); + scoreRankMapper.deleteByExample(scoreRankExample); //先查询userInfo表 获取所有学校ID List schoolIdList = userInfoMapper.selectAllSchoolIds(); for (int i = 0; i < schoolIdList.size(); i++) { - List scoreRankList=new ArrayList<>(); + List scoreRankList = new ArrayList<>(); String schoolId = schoolIdList.get(i); //根据学校ID 获取所有学生userId UserInfoExample userInfoExample = new UserInfoExample(); @@ -53,8 +57,8 @@ public class ScoreRankServiceImpl implements ScoreRankService { //查询成绩总览权重 TotalWeight totalWeight = totalWeightMapper.selectByPrimaryKey(schoolId); - if(totalWeight==null){ - totalWeight=new TotalWeight(); + if (totalWeight == null) { + totalWeight = new TotalWeight(); totalWeight.setKhan(BigDecimal.valueOf(0.4)); totalWeight.setZhgh(BigDecimal.valueOf(0.4)); totalWeight.setLlkh(BigDecimal.valueOf(0.2)); @@ -97,7 +101,7 @@ public class ScoreRankServiceImpl implements ScoreRankService { if (stuTrainings != null) { for (int k = 0; k < stuTrainings.size(); k++) { StuTraining stuTraining = stuTrainings.get(k); - if(stuTraining.getChapterName()==null){ + if (stuTraining.getChapterName() == null) { continue; } Integer knowledgeStatus = stuTraining.getKnowledgeSummaryCompleteStatus() == null ? 0 : stuTraining.getKnowledgeSummaryCompleteStatus(); @@ -109,7 +113,7 @@ public class ScoreRankServiceImpl implements ScoreRankService { BigDecimal resourceScore = studentScoreWeight.getResourceLearningScore().multiply(BigDecimal.valueOf(resourceStatus)).multiply(studentScoreWeight.getResourceLearningWeight()); BigDecimal learningScore = studentScoreWeight.getLearningAssessmentScore().multiply(BigDecimal.valueOf(learningEvalCompleteStatus)).multiply(studentScoreWeight.getLearningAssessmentWeight()); BigDecimal experimentalScore = studentScoreWeight.getExperimentalTrainingScore().multiply(BigDecimal.valueOf(expStatus)).multiply(studentScoreWeight.getExperimentalTrainingWeight()); - BigDecimal sum=summaryScore.add(resourceScore).add(learningScore).add(experimentalScore); + BigDecimal sum = summaryScore.add(resourceScore).add(learningScore).add(experimentalScore); if ("风险测评".equals(stuTraining.getChapterName())) { scoreRank.setFxcp(sum); } else if ("财务分析".equals(stuTraining.getChapterName())) { @@ -174,13 +178,13 @@ public class ScoreRankServiceImpl implements ScoreRankService { BigDecimal weightKhan = totalWeight.getKhan(); BigDecimal weightZhgh = totalWeight.getZhgh(); BigDecimal weightLlkh = totalWeight.getLlkh(); - if(scoreRank.getKhalScore()==null){ + if (scoreRank.getKhalScore() == null) { scoreRank.setKhalScore(BigDecimal.ZERO); } - if(scoreRank.getZhghScore()==null){ + if (scoreRank.getZhghScore() == null) { scoreRank.setZhghScore(BigDecimal.ZERO); } - if(scoreRank.getLlkhScore()==null){ + if (scoreRank.getLlkhScore() == null) { scoreRank.setLlkhScore(BigDecimal.ZERO); } scoreRank.setTotalScore(scoreRank.getKhalScore().multiply(weightKhan).add(scoreRank.getZhghScore().multiply(weightZhgh)).add(scoreRank.getLlkhScore().multiply(weightLlkh))); @@ -192,7 +196,7 @@ public class ScoreRankServiceImpl implements ScoreRankService { .collect(Collectors.toList()); for (int j = 0; j < totalSortedList.size(); j++) { - totalSortedList.get(j).setTotalRank(j+1); + totalSortedList.get(j).setTotalRank(j + 1); } //客户案例排序 @@ -201,7 +205,7 @@ public class ScoreRankServiceImpl implements ScoreRankService { .collect(Collectors.toList()); for (int j = 0; j < khanSortedList.size(); j++) { - khanSortedList.get(j).setKhalRank(j+1); + khanSortedList.get(j).setKhalRank(j + 1); } //综合规划排序 @@ -210,7 +214,7 @@ public class ScoreRankServiceImpl implements ScoreRankService { .collect(Collectors.toList()); for (int j = 0; j < zhghSortedList.size(); j++) { - zhghSortedList.get(j).setKhalRank(j+1); + zhghSortedList.get(j).setKhalRank(j + 1); } //理论考核排序 @@ -219,7 +223,7 @@ public class ScoreRankServiceImpl implements ScoreRankService { .collect(Collectors.toList()); for (int j = 0; j < llkhSortedList.size(); j++) { - llkhSortedList.get(j).setKhalRank(j+1); + llkhSortedList.get(j).setKhalRank(j + 1); } //保存到数据库 @@ -239,8 +243,8 @@ public class ScoreRankServiceImpl implements ScoreRankService { List scoreRankList = scoreRankMapper.selectByExample(scoreRankExample); //查询成绩总览权重 TotalWeight totalWeight = totalWeightMapper.selectByPrimaryKey(schoolId); - if(totalWeight==null){ - totalWeight=new TotalWeight(); + if (totalWeight == null) { + totalWeight = new TotalWeight(); totalWeight.setKhan(BigDecimal.valueOf(0.4)); totalWeight.setZhgh(BigDecimal.valueOf(0.4)); totalWeight.setLlkh(BigDecimal.valueOf(0.2)); @@ -251,7 +255,7 @@ public class ScoreRankServiceImpl implements ScoreRankService { scoreRank.setTotalScore((totalWeight.getKhan().multiply(scoreRank.getKhalScore())) .add(totalWeight.getZhgh().multiply(scoreRank.getZhghScore())) .add(totalWeight.getLlkh().multiply(scoreRank.getLlkhScore()))); - scoreRank.setRankId(String.valueOf(i+1)); + scoreRank.setRankId(String.valueOf(i + 1)); } return scoreRankList; } @@ -263,10 +267,10 @@ public class ScoreRankServiceImpl implements ScoreRankService { criteria.andSchoolIdEqualTo(schoolId); theoryRecordExample.setOrderByClause("average_score desc"); List stuTheoryRecords = stuTheoryRecordMapper.selectByExample(theoryRecordExample); - if(!stuTheoryRecords.isEmpty()){ + if (!stuTheoryRecords.isEmpty()) { for (int i = 0; i < stuTheoryRecords.size(); i++) { //将排名设置到classId中 用于返回 - stuTheoryRecords.get(i).setClassId(String.valueOf(i+1)); + stuTheoryRecords.get(i).setClassId(String.valueOf(i + 1)); } } @@ -276,12 +280,205 @@ public class ScoreRankServiceImpl implements ScoreRankService { //获取当天时间 @Override - public String getNowDate(){ + public String getNowDate() { LocalDateTime now = LocalDateTime.now(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); String nowDate = now.format(formatter); return nowDate; } + @Override + public Boolean doRankOne(String schoolId) { + ScoreRankExample scoreRankExample = new ScoreRankExample(); + scoreRankExample.createCriteria().andUpdateDateEqualTo(getNowDate()).andSchoolIdEqualTo(schoolId); + scoreRankMapper.deleteByExample(scoreRankExample); + //先查询userInfo表 获取所有学校ID + List scoreRankList = new ArrayList<>(); + //根据学校ID 获取所有学生userId + UserInfoExample userInfoExample = new UserInfoExample(); + userInfoExample.createCriteria().andSchoolIdEqualTo(schoolId).andRoleIdEqualTo(4); + List userList = userInfoMapper.selectByExample(userInfoExample); + //查询学习成绩权重表 + Map clientWeight = trainingService.getClientWeight(schoolId); //客户案例权重 + Map studentScoreWeightMap = trainingService.getStudentScoreWeightMap(schoolId); //学习成绩权重 + + //查询成绩总览权重 + TotalWeight totalWeight = totalWeightMapper.selectByPrimaryKey(schoolId); + if (totalWeight == null) { + totalWeight = new TotalWeight(); + totalWeight.setKhan(BigDecimal.valueOf(0.4)); + totalWeight.setZhgh(BigDecimal.valueOf(0.4)); + totalWeight.setLlkh(BigDecimal.valueOf(0.2)); + } + + for (int j = 0; j < userList.size(); j++) { + UserInfo userInfo = userList.get(j); + String userId = userInfo.getUserid(); + ScoreRank scoreRank = new ScoreRank(); + scoreRank.setRankId(String.valueOf(UUID.randomUUID())); + scoreRank.setUserid(userId); + scoreRank.setName(userInfo.getName()); + scoreRank.setStudentId(userInfo.getStudentId()); + scoreRank.setClassId(userInfo.getClassId()); + scoreRank.setClassName(userInfo.getClassName()); + scoreRank.setSchoolId(userInfo.getSchoolId()); + + //设置更新日期 年月日 + String nowDate = getNowDate(); + scoreRank.setUpdateDate(nowDate); + + //设置总数据 + //设置客户案例数据 根据userId 查询学生实训表 循环查询对象 + StuTrainingExample stuTrainingExample = new StuTrainingExample(); + stuTrainingExample.createCriteria().andUserIdEqualTo(userId); + List stuTrainings = stuTrainingMapper.selectByExample(stuTrainingExample); + scoreRank.setFxcp(BigDecimal.ZERO); + scoreRank.setCwfx(BigDecimal.ZERO); + scoreRank.setXjgh(BigDecimal.ZERO); + scoreRank.setJygh(BigDecimal.ZERO); + scoreRank.setXfgh(BigDecimal.ZERO); + scoreRank.setCygh(BigDecimal.ZERO); + scoreRank.setTxgh(BigDecimal.ZERO); + scoreRank.setBxgh(BigDecimal.ZERO); + scoreRank.setTzgh(BigDecimal.ZERO); + scoreRank.setSwch(BigDecimal.ZERO); + scoreRank.setCcfp(BigDecimal.ZERO); + scoreRank.setCccc(BigDecimal.ZERO); + scoreRank.setKhalScore(BigDecimal.ZERO); + if (stuTrainings != null) { + for (int k = 0; k < stuTrainings.size(); k++) { + StuTraining stuTraining = stuTrainings.get(k); + if (stuTraining.getChapterName() == null) { + continue; + } + Integer knowledgeStatus = stuTraining.getKnowledgeSummaryCompleteStatus() == null ? 0 : stuTraining.getKnowledgeSummaryCompleteStatus(); + Integer resourceStatus = stuTraining.getResourceLearningCompleteStatus() == null ? 0 : stuTraining.getResourceLearningCompleteStatus(); + Integer learningEvalCompleteStatus = stuTraining.getLearningEvalCompleteStatus() == null ? 0 : stuTraining.getLearningEvalCompleteStatus(); + Integer expStatus = stuTraining.getExpTrainingCompleteStatus() == null ? 0 : stuTraining.getExpTrainingCompleteStatus(); + StudentScoreWeight studentScoreWeight = studentScoreWeightMap.get(stuTraining.getChapterName()); + BigDecimal summaryScore = studentScoreWeight.getSummaryOfKnowledgeScore().multiply(BigDecimal.valueOf(knowledgeStatus)).multiply(studentScoreWeight.getSummaryOfKnowledgeWeight()); + BigDecimal resourceScore = studentScoreWeight.getResourceLearningScore().multiply(BigDecimal.valueOf(resourceStatus)).multiply(studentScoreWeight.getResourceLearningWeight()); + BigDecimal learningScore = studentScoreWeight.getLearningAssessmentScore().multiply(BigDecimal.valueOf(learningEvalCompleteStatus)).multiply(studentScoreWeight.getLearningAssessmentWeight()); + BigDecimal experimentalScore = studentScoreWeight.getExperimentalTrainingScore().multiply(BigDecimal.valueOf(expStatus)).multiply(studentScoreWeight.getExperimentalTrainingWeight()); + BigDecimal sum = summaryScore.add(resourceScore).add(learningScore).add(experimentalScore); + if ("风险测评".equals(stuTraining.getChapterName())) { + scoreRank.setFxcp(sum); + } else if ("财务分析".equals(stuTraining.getChapterName())) { + scoreRank.setCwfx(sum); + } else if ("现金规划".equals(stuTraining.getChapterName())) { + scoreRank.setXjgh(sum); + } else if ("教育规划".equals(stuTraining.getChapterName())) { + scoreRank.setJygh(sum); + } else if ("消费规划".equals(stuTraining.getChapterName())) { + scoreRank.setXfgh(sum); + } else if ("创业规划".equals(stuTraining.getChapterName())) { + scoreRank.setCygh(sum); + } else if ("退休规划".equals(stuTraining.getChapterName())) { + scoreRank.setTxgh(sum); + } else if ("保险规划".equals(stuTraining.getChapterName())) { + scoreRank.setBxgh(sum); + } else if ("投资规划".equals(stuTraining.getChapterName())) { + scoreRank.setTzgh(sum); + } else if ("税务筹划".equals(stuTraining.getChapterName())) { + scoreRank.setSwch(sum); + } else if ("财产分配".equals(stuTraining.getChapterName())) { + scoreRank.setCcfp(sum); + } else if ("财产传承".equals(stuTraining.getChapterName())) { + scoreRank.setCccc(sum); + } + } + scoreRank.setKhalScore((scoreRank.getFxcp().multiply(clientWeight.get("风险测评"))) + .add(scoreRank.getCwfx().multiply(clientWeight.get("财务分析"))) + .add(scoreRank.getXjgh().multiply(clientWeight.get("现金规划"))) + .add(scoreRank.getJygh().multiply(clientWeight.get("教育规划"))) + .add(scoreRank.getXfgh().multiply(clientWeight.get("消费规划"))) + .add(scoreRank.getCygh().multiply(clientWeight.get("创业规划"))) + .add(scoreRank.getTxgh().multiply(clientWeight.get("退休规划"))) + .add(scoreRank.getBxgh().multiply(clientWeight.get("保险规划"))) + .add(scoreRank.getTzgh().multiply(clientWeight.get("投资规划"))) + .add(scoreRank.getSwch().multiply(clientWeight.get("税务筹划"))) + .add(scoreRank.getCcfp().multiply(clientWeight.get("财产分配"))) + .add(scoreRank.getCccc().multiply(clientWeight.get("财产传承")))); + } + + //设置综合规划数据 先根据userId到综合规划客户表中获取提交状态为未审核、已审核的案例个数 再到综合规划成绩表中根据userId获取得分之和 + SynthesisPlanClientExample synthesisPlanClientExample = new SynthesisPlanClientExample(); + List submitStatusList = new ArrayList<>(); + submitStatusList.add("未审核"); + submitStatusList.add("已审核"); + synthesisPlanClientExample.createCriteria().andUseridEqualTo(userId).andSubmitStatusIn(submitStatusList); + long countCase = synthesisPlanClientMapper.countByExample(synthesisPlanClientExample); + scoreRank.setCountCase((int) countCase); + + BigDecimal zhghScore = synthesisPlanScoreMapper.selectTotalScoreByUserId(userId); + scoreRank.setZhghScore(zhghScore); + + //设置理论考核平均分成绩 + StuTheoryRecord stuTheoryRecord = theoryRecordMapper.selectByPrimaryKey(userId); + if (stuTheoryRecord == null) { + scoreRank.setLlkhScore(BigDecimal.ZERO); + } else { + scoreRank.setLlkhScore(stuTheoryRecord.getAverageScore()); + } + + //设置totalscore + BigDecimal weightKhan = totalWeight.getKhan(); + BigDecimal weightZhgh = totalWeight.getZhgh(); + BigDecimal weightLlkh = totalWeight.getLlkh(); + if (scoreRank.getKhalScore() == null) { + scoreRank.setKhalScore(BigDecimal.ZERO); + } + if (scoreRank.getZhghScore() == null) { + scoreRank.setZhghScore(BigDecimal.ZERO); + } + if (scoreRank.getLlkhScore() == null) { + scoreRank.setLlkhScore(BigDecimal.ZERO); + } + scoreRank.setTotalScore(scoreRank.getKhalScore().multiply(weightKhan).add(scoreRank.getZhghScore().multiply(weightZhgh)).add(scoreRank.getLlkhScore().multiply(weightLlkh))); + scoreRankList.add(scoreRank); + } + //总排名排序 + List totalSortedList = scoreRankList.stream() + .sorted((o1, o2) -> o2.getTotalScore().compareTo(o1.getTotalScore())) + .collect(Collectors.toList()); + + for (int j = 0; j < totalSortedList.size(); j++) { + totalSortedList.get(j).setTotalRank(j + 1); + } + + //客户案例排序 + List khanSortedList = totalSortedList.stream() + .sorted((o1, o2) -> o2.getKhalScore().compareTo(o1.getKhalScore())) + .collect(Collectors.toList()); + + for (int j = 0; j < khanSortedList.size(); j++) { + khanSortedList.get(j).setKhalRank(j + 1); + } + + //综合规划排序 + List zhghSortedList = khanSortedList.stream() + .sorted((o1, o2) -> o2.getZhghScore().compareTo(o1.getZhghScore())) + .collect(Collectors.toList()); + + for (int j = 0; j < zhghSortedList.size(); j++) { + zhghSortedList.get(j).setKhalRank(j + 1); + } + + //理论考核排序 + List llkhSortedList = zhghSortedList.stream() + .sorted((o1, o2) -> o2.getLlkhScore().compareTo(o1.getLlkhScore())) + .collect(Collectors.toList()); + + for (int j = 0; j < llkhSortedList.size(); j++) { + llkhSortedList.get(j).setKhalRank(j + 1); + } + + //保存到数据库 + for (int j = 0; j < llkhSortedList.size(); j++) { + scoreRankMapper.insert(llkhSortedList.get(j)); + } + return true; + } + }