|
|
|
@ -2,8 +2,10 @@ package com.ccsens.mt.service; |
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import cn.hutool.core.lang.Snowflake; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import cn.hutool.crypto.SecureUtil; |
|
|
|
import com.ccsens.cloudutil.bean.tall.vo.MemberVo; |
|
|
|
import com.ccsens.cloudutil.bean.tall.vo.TaskVo; |
|
|
|
import com.ccsens.cloudutil.feign.TallFeignClient; |
|
|
|
@ -16,18 +18,22 @@ import com.ccsens.mt.persist.dao.MtJudgeDao; |
|
|
|
import com.ccsens.mt.persist.dao.MtScoreDao; |
|
|
|
import com.ccsens.mt.persist.dao.MtScoreLogDao; |
|
|
|
import com.ccsens.util.CodeEnum; |
|
|
|
import com.ccsens.util.ExcelUtil; |
|
|
|
import com.ccsens.util.JsonResponse; |
|
|
|
import com.ccsens.util.WebConstant; |
|
|
|
import com.ccsens.util.exception.BaseException; |
|
|
|
import lombok.Data; |
|
|
|
import org.apache.poi.xssf.usermodel.XSSFCell; |
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet; |
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.core.io.DefaultResourceLoader; |
|
|
|
import org.springframework.core.io.ResourceLoader; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.io.*; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashSet; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
import static java.math.BigDecimal.ROUND_HALF_UP; |
|
|
|
|
|
|
|
@ -48,6 +54,7 @@ public class ScoreService implements IScoreService{ |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取评分项 |
|
|
|
* |
|
|
|
* @param userId |
|
|
|
* @param playerId |
|
|
|
* @return |
|
|
|
@ -101,6 +108,7 @@ public class ScoreService implements IScoreService{ |
|
|
|
|
|
|
|
/** |
|
|
|
* 提交评分 |
|
|
|
* |
|
|
|
* @param userId |
|
|
|
* @param submitScore |
|
|
|
*/ |
|
|
|
@ -133,6 +141,7 @@ public class ScoreService implements IScoreService{ |
|
|
|
MtScore score = new MtScore(); |
|
|
|
score.setId(snowflake.nextId()); |
|
|
|
score.setJudgeUserId(memberInfo.getId()); |
|
|
|
score.setProjectId(taskInfo.getProjectId()); |
|
|
|
score.setTaskId(taskInfo.getId()); |
|
|
|
score.setTaskName(taskInfo.getName()); |
|
|
|
score.setScoreLogId(data.getId()); |
|
|
|
@ -146,6 +155,7 @@ public class ScoreService implements IScoreService{ |
|
|
|
throw new BaseException(CodeEnum.SCORE_REPEAT); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void addJudge(MemberVo.MemberInfo memberInfo) { |
|
|
|
MtJudge judge = judgeDao.selectByPrimaryKey(memberInfo.getId()); |
|
|
|
if (ObjectUtil.isNull(judge)) { |
|
|
|
@ -157,6 +167,7 @@ public class ScoreService implements IScoreService{ |
|
|
|
|
|
|
|
/** |
|
|
|
* 提交单项评分 |
|
|
|
* |
|
|
|
* @param userId |
|
|
|
* @param submitOnlyOneScore |
|
|
|
*/ |
|
|
|
@ -187,6 +198,7 @@ public class ScoreService implements IScoreService{ |
|
|
|
MtScore score = new MtScore(); |
|
|
|
score.setId(snowflake.nextId()); |
|
|
|
score.setJudgeUserId(memberInfo.getId()); |
|
|
|
score.setProjectId(taskInfo.getProjectId()); |
|
|
|
score.setTaskId(taskInfo.getId()); |
|
|
|
score.setTaskName(taskInfo.getName()); |
|
|
|
score.setScore(submitOnlyOneScore.getScore()); |
|
|
|
@ -200,37 +212,46 @@ public class ScoreService implements IScoreService{ |
|
|
|
|
|
|
|
/** |
|
|
|
* 查看评分 |
|
|
|
* |
|
|
|
* @param userId |
|
|
|
* @param roleId |
|
|
|
* @param playerId |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<ScoreVo.AdminScore> adminScore(Long userId, Long roleId, Long playerId) { |
|
|
|
List<ScoreVo.AdminScore> adminScoreList = new ArrayList<>(); |
|
|
|
ScoreVo.AdminScore adminScore = null; |
|
|
|
//
|
|
|
|
public ScoreVo.AdminScore adminScore(Long userId, Long roleId, Long playerId) { |
|
|
|
ScoreVo.AdminScore adminScore = new ScoreVo.AdminScore(); |
|
|
|
List<ScoreVo._adminScoreList> judgeScoreList = new ArrayList<>(); |
|
|
|
ScoreVo._adminScoreList judgeScore = new ScoreVo._adminScoreList(); |
|
|
|
// Score scoreMax = scoreDao.maxScore(playerId);//最高分
|
|
|
|
// Score scoreMin = scoreDao.minScore(playerId);//最低分
|
|
|
|
TaskVo.TaskInfoWithFeign taskInfo = tallFeignClient.getProjectId(playerId); |
|
|
|
if (ObjectUtil.isNull(taskInfo)) { |
|
|
|
throw new BaseException(CodeEnum.NOT_TASK); |
|
|
|
} |
|
|
|
//总分
|
|
|
|
BigDecimal totalScore = BigDecimal.valueOf(0); |
|
|
|
//获取项目下的所有评委
|
|
|
|
MtJudgeExample judgeExample = new MtJudgeExample(); |
|
|
|
judgeExample.createCriteria().andProjectIdEqualTo(taskInfo.getProjectId()); |
|
|
|
List<MtJudge> judgeList = judgeDao.selectByExample(judgeExample); |
|
|
|
if (CollectionUtil.isNotEmpty(judgeList)) { |
|
|
|
for (MtJudge mtJudge : judgeList) { |
|
|
|
BigDecimal score = scoreDao.sumScoreByJudgeId(mtJudge.getId(), taskInfo.getId()); |
|
|
|
adminScore = new ScoreVo.AdminScore(); |
|
|
|
judgeScore = new ScoreVo._adminScoreList(); |
|
|
|
|
|
|
|
adminScore.setJudge(mtJudge.getId()); |
|
|
|
adminScore.setScore(score); |
|
|
|
adminScore.setJudgeName(mtJudge.getNickname()); |
|
|
|
adminScoreList.add(adminScore); |
|
|
|
judgeScore.setJudge(mtJudge.getId()); |
|
|
|
judgeScore.setScore(score); |
|
|
|
judgeScore.setJudgeName(mtJudge.getNickname()); |
|
|
|
judgeScoreList.add(judgeScore); |
|
|
|
if (ObjectUtil.isNotNull(score)) { |
|
|
|
totalScore = totalScore.add(score); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return adminScoreList; |
|
|
|
adminScore.setTotalScore(totalScore); |
|
|
|
adminScore.setJudgeScore(judgeScoreList); |
|
|
|
return adminScore; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
@ -240,6 +261,7 @@ public class ScoreService implements IScoreService{ |
|
|
|
public List<ScoreVo.RankingScore> getRanking(Long projectId) { |
|
|
|
//获取所有参赛任务
|
|
|
|
Set<Long> taskIdList = new HashSet<>(); |
|
|
|
|
|
|
|
MtScoreLogExample scoreLogExample = new MtScoreLogExample(); |
|
|
|
scoreLogExample.createCriteria().andProjectIdEqualTo(projectId); |
|
|
|
List<MtScoreLog> scoreLogList = scoreLogDao.selectByExample(scoreLogExample); |
|
|
|
@ -254,6 +276,15 @@ public class ScoreService implements IScoreService{ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
MtScoreExample mtScoreExample = new MtScoreExample(); |
|
|
|
mtScoreExample.createCriteria().andProjectIdEqualTo(projectId); |
|
|
|
List<MtScore> scoreList = scoreDao.selectByExample(mtScoreExample); |
|
|
|
if (CollectionUtil.isNotEmpty(scoreList)) { |
|
|
|
for (MtScore score : scoreList) { |
|
|
|
taskIdList.add(score.getTaskId()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//查找每个任务的分数
|
|
|
|
List<ScoreVo.RankingScore> rankingScoreList = new ArrayList<>(); |
|
|
|
@ -280,7 +311,7 @@ public class ScoreService implements IScoreService{ |
|
|
|
aveScore = aveScore.divide(BigDecimal.valueOf(judgeScoreList.size()), 2, ROUND_HALF_UP); |
|
|
|
} |
|
|
|
rankingScore.setAveScore(aveScore); |
|
|
|
|
|
|
|
rankingScore.setJudgeScoreList(judgeScoreList); |
|
|
|
rankingScoreList.add(rankingScore); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -425,6 +456,210 @@ public class ScoreService implements IScoreService{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 导出签字表 |
|
|
|
* |
|
|
|
* @param projectId |
|
|
|
* @param taskId |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public String exportExcel(Long projectId, Long taskId) throws Exception { |
|
|
|
//返回excel地址
|
|
|
|
String excelPath = ""; |
|
|
|
//获取模板
|
|
|
|
ResourceLoader resourceLoader = new DefaultResourceLoader(); |
|
|
|
InputStream is = resourceLoader.getResource("classpath:template/judgeTemplate.xlsx").getInputStream(); |
|
|
|
XSSFWorkbook excel = new XSSFWorkbook(is); |
|
|
|
//获取任务和项目信息
|
|
|
|
TaskVo.TaskInfoWithFeign taskInfo = tallFeignClient.getProjectId(taskId); |
|
|
|
//查找项目下所有评委
|
|
|
|
MtJudgeExample judgeExample = new MtJudgeExample(); |
|
|
|
judgeExample.createCriteria().andProjectIdEqualTo(projectId); |
|
|
|
List<MtJudge> judgeList = judgeDao.selectByExample(judgeExample); |
|
|
|
if (CollectionUtil.isNotEmpty(judgeList)) { |
|
|
|
for (int i = 0; i < judgeList.size(); i++) { |
|
|
|
MtJudge judge = judgeList.get(i); |
|
|
|
writeExcel(taskInfo, judge, excel.getSheetAt(i)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//保存地址
|
|
|
|
String path = taskInfo.getName(); |
|
|
|
String dir = WebConstant.UPLOAD_PATH_BASE + File.separator + WebConstant.UPLOAD_PATH_BASE_MT_JUDGE; |
|
|
|
String extraPath = DateUtil.format(new Date(), "yyyyMMdd"); |
|
|
|
String ePath = dir + File.separator + extraPath + File.separator + path + ".xlsx"; |
|
|
|
//导出
|
|
|
|
File tmpFile = new File(dir + File.separator + extraPath); |
|
|
|
if (!tmpFile.exists()) { |
|
|
|
tmpFile.mkdirs(); |
|
|
|
} |
|
|
|
File file = new File(ePath); |
|
|
|
//将文件写入创建的file当中
|
|
|
|
OutputStream stream = new FileOutputStream(file); |
|
|
|
excel.write(stream); |
|
|
|
//关闭流
|
|
|
|
stream.close(); |
|
|
|
String rePath = WebConstant.TEST_URL_BASE_MT + WebConstant.UPLOAD_PATH_BASE_MT_JUDGE + File.separator + extraPath + File.separator + path + ".xlsx"; |
|
|
|
return rePath; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 写入excel |
|
|
|
* |
|
|
|
* @param taskInfo |
|
|
|
* @param judge |
|
|
|
* @throws Exception |
|
|
|
*/ |
|
|
|
public void writeExcel(TaskVo.TaskInfoWithFeign taskInfo, MtJudge judge, XSSFSheet judgeSheet) throws Exception { |
|
|
|
XSSFCell industry = judgeSheet.getRow(5).getCell(3); |
|
|
|
//项目名
|
|
|
|
XSSFCell projectName = judgeSheet.getRow(5).getCell(5); |
|
|
|
projectName.setCellValue(taskInfo.getProjectName()); |
|
|
|
//任务名
|
|
|
|
XSSFCell company = judgeSheet.getRow(5).getCell(9); |
|
|
|
company.setCellValue(taskInfo.getName()); |
|
|
|
XSSFCell cell1 = judgeSheet.getRow(8).getCell(10); |
|
|
|
XSSFCell cell2 = judgeSheet.getRow(9).getCell(10); |
|
|
|
//评委名
|
|
|
|
XSSFCell judgeName = judgeSheet.getRow(10).getCell(6); |
|
|
|
judgeName.setCellValue(judge.getNickname()); |
|
|
|
|
|
|
|
MtScoreExample mtScoreExample = new MtScoreExample(); |
|
|
|
mtScoreExample.createCriteria().andJudgeUserIdEqualTo(judge.getId()).andTaskIdEqualTo(taskInfo.getId()); |
|
|
|
List<MtScore> scoreList = scoreDao.selectByExample(mtScoreExample); |
|
|
|
if (CollectionUtil.isNotEmpty(scoreList)) { |
|
|
|
for (int i = 0; i < scoreList.size(); i++) { |
|
|
|
cell1.setCellValue(scoreList.get(0).getScore().toString()); |
|
|
|
} |
|
|
|
|
|
|
|
BigDecimal score = new BigDecimal(0); |
|
|
|
for (MtScore score1 : scoreList) { |
|
|
|
score = score.add(score1.getScore()); |
|
|
|
} |
|
|
|
cell2.setCellValue(score.toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 导出排名表 |
|
|
|
* @param projectId |
|
|
|
* @return |
|
|
|
* @throws Exception |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public String rankingExcel(Long projectId) throws Exception { |
|
|
|
String path = ""; |
|
|
|
//获取模板
|
|
|
|
ResourceLoader resourceLoader = new DefaultResourceLoader(); |
|
|
|
InputStream is = resourceLoader.getResource("classpath:template/rankingTemplate.xlsx").getInputStream(); |
|
|
|
XSSFWorkbook excel = new XSSFWorkbook(is); |
|
|
|
XSSFSheet sheet = excel.getSheetAt(0); |
|
|
|
List<ScoreVo.RankingScore> rankingScoreList = getRanking(projectId); |
|
|
|
if(CollectionUtil.isNotEmpty(rankingScoreList)){ |
|
|
|
for(int i=0; i<rankingScoreList.size(); i++){ |
|
|
|
ScoreVo.RankingScore rankingScore = rankingScoreList.get(i); |
|
|
|
XSSFCell no = sheet.getRow(i+1).getCell(0); |
|
|
|
XSSFCell taskName = sheet.getRow(i+1).getCell(1); |
|
|
|
XSSFCell aveScore = sheet.getRow(i+1).getCell(2); |
|
|
|
no.setCellValue(i+1); |
|
|
|
taskName.setCellValue(rankingScore.getCompany()); |
|
|
|
aveScore.setCellValue(rankingScore.getAveScore().toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
//保存地址
|
|
|
|
String filePath = SecureUtil.simpleUUID(); |
|
|
|
String dir = WebConstant.UPLOAD_PATH_BASE + File.separator + WebConstant.UPLOAD_PATH_BASE_MT_JUDGE; |
|
|
|
String extraPath = DateUtil.format(new Date(), "yyyyMMdd"); |
|
|
|
String ePath = dir + File.separator + extraPath + File.separator + filePath + ".xlsx"; |
|
|
|
//导出
|
|
|
|
File tmpFile = new File(dir + File.separator + extraPath); |
|
|
|
if (!tmpFile.exists()) { |
|
|
|
tmpFile.mkdirs(); |
|
|
|
} |
|
|
|
File file = new File(ePath); |
|
|
|
//将文件写入创建的file当中
|
|
|
|
OutputStream stream = new FileOutputStream(file); |
|
|
|
excel.write(stream); |
|
|
|
//关闭流
|
|
|
|
stream.close(); |
|
|
|
path = WebConstant.TEST_URL_BASE_MT + WebConstant.UPLOAD_PATH_BASE_MT_JUDGE + File.separator + extraPath + File.separator + filePath + ".xlsx"; |
|
|
|
return path; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取总评分表 |
|
|
|
* @param projectId |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public String rankingAllExcel(Long projectId) throws Exception{ |
|
|
|
//获取模板
|
|
|
|
ResourceLoader resourceLoader = new DefaultResourceLoader(); |
|
|
|
InputStream is = resourceLoader.getResource("classpath:template/gradeTemplate.xlsx").getInputStream(); |
|
|
|
XSSFWorkbook excel = new XSSFWorkbook(is); |
|
|
|
XSSFSheet sheet = excel.getSheetAt(0); |
|
|
|
//获取排名信息
|
|
|
|
List<ScoreVo.RankingScore> rankingScoreList = getRanking(projectId); |
|
|
|
//获取所有评委信息
|
|
|
|
//获取项目下的所有评委
|
|
|
|
int a = 2; |
|
|
|
MtJudgeExample judgeExample = new MtJudgeExample(); |
|
|
|
judgeExample.createCriteria().andProjectIdEqualTo(projectId); |
|
|
|
List<MtJudge> judgeList = judgeDao.selectByExample(judgeExample); |
|
|
|
if(CollectionUtil.isNotEmpty(judgeList)){ |
|
|
|
for(MtJudge judge:judgeList){ |
|
|
|
XSSFCell judgeName = sheet.getRow(0).getCell(a); |
|
|
|
judgeName.setCellValue(judge.getNickname()); |
|
|
|
a++; |
|
|
|
} |
|
|
|
XSSFCell aveScore = sheet.getRow(0).getCell(a); |
|
|
|
aveScore.setCellValue("平均分"); |
|
|
|
} |
|
|
|
|
|
|
|
if(CollectionUtil.isNotEmpty(rankingScoreList)){ |
|
|
|
int index = 1; |
|
|
|
for(ScoreVo.RankingScore rankingScore : rankingScoreList){ |
|
|
|
XSSFCell taskName = sheet.getRow(index).getCell(1); |
|
|
|
taskName.setCellValue(rankingScore.getCompany()); |
|
|
|
if(CollectionUtil.isNotEmpty(rankingScore.getJudgeScoreList())){ |
|
|
|
for(int i = 2; i < a; i++){ |
|
|
|
String judgeName = ExcelUtil.getCellValue(sheet.getRow(0).getCell(i)); |
|
|
|
for(ScoreVo.JudgeScore judgeScore : rankingScore.getJudgeScoreList()){ |
|
|
|
if(judgeName.equalsIgnoreCase(judgeScore.getJudgeName())){ |
|
|
|
XSSFCell score = sheet.getRow(index).getCell(i); |
|
|
|
score.setCellValue(judgeScore.getScore().toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
XSSFCell aveScore = sheet.getRow(index).getCell(a); |
|
|
|
aveScore.setCellValue(rankingScore.getAveScore().toString()); |
|
|
|
index++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//保存地址
|
|
|
|
String filePath = SecureUtil.simpleUUID(); |
|
|
|
String dir = WebConstant.UPLOAD_PATH_BASE + File.separator + WebConstant.UPLOAD_PATH_BASE_MT_JUDGE; |
|
|
|
String extraPath = DateUtil.format(new Date(), "yyyyMMdd"); |
|
|
|
String ePath = dir + File.separator + extraPath + File.separator + filePath + ".xlsx"; |
|
|
|
//导出
|
|
|
|
File tmpFile = new File(dir + File.separator + extraPath); |
|
|
|
if (!tmpFile.exists()) { |
|
|
|
tmpFile.mkdirs(); |
|
|
|
} |
|
|
|
File file = new File(ePath); |
|
|
|
//将文件写入创建的file当中
|
|
|
|
OutputStream stream = new FileOutputStream(file); |
|
|
|
excel.write(stream); |
|
|
|
//关闭流
|
|
|
|
stream.close(); |
|
|
|
String path = WebConstant.TEST_URL_BASE_MT + WebConstant.UPLOAD_PATH_BASE_MT_JUDGE + File.separator + extraPath + File.separator + filePath + ".xlsx"; |
|
|
|
return path; |
|
|
|
} |
|
|
|
|
|
|
|
/*=====================================================*/ |
|
|
|
|
|
|
|
@Override |
|
|
|
|