You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dianshang-houduan/src/main/java/com/sztzjy/linkCommerce/controller/stu/IndustryDemandAnalysisContr...

326 lines
12 KiB
Java

package com.sztzjy.linkCommerce.controller.stu;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSONObject;
import com.sztzjy.linkCommerce.annotation.AnonymousAccess;
import com.sztzjy.linkCommerce.config.Constant;
import com.sztzjy.linkCommerce.entity.*;
import com.sztzjy.linkCommerce.entity.dto.CompetitiveEnvDTO;
import com.sztzjy.linkCommerce.entity.dto.MonthlyCakeIndex;
import com.sztzjy.linkCommerce.entity.dto.StuIndustryAnalysisDTO;
import com.sztzjy.linkCommerce.entity.dto.YearCakeIndexDto;
import com.sztzjy.linkCommerce.mapper.HyxqfxDataMapper;
import com.sztzjy.linkCommerce.mapper.HyxqfxStuAnswerMapper;
import com.sztzjy.linkCommerce.mapper.JzhyfxStuAnswerMapper;
import com.sztzjy.linkCommerce.mapper.StuGradeMapper;
import com.sztzjy.linkCommerce.service.IndustryDemandAnalysisService;
import com.sztzjy.linkCommerce.service.ScoreService;
import com.sztzjy.linkCommerce.util.CompareListsUtil;
import com.sztzjy.linkCommerce.util.ResultEntity;
import com.sztzjy.linkCommerce.util.file.IFileUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.*;
/**
* @author 17803
* @date 2025-04-24 13:30
*/
@Api(tags = "行业需求分析")
@RestController
@RequestMapping("api/industryAnalysis")
public class IndustryDemandAnalysisController {
@Autowired
private HyxqfxStuAnswerMapper hyxqfxStuAnswerMapper;
@Autowired
private ScoreService scoreService;
@Autowired
private CompareListsUtil compareListsUtil;
@Autowired
private JzhyfxStuAnswerMapper jzhyfxStuAnswerMapper;
@Autowired
private IFileUtil fileUtil;
//数据查询
@ApiOperation("行业需求分析提交")
@PostMapping("/analysisSubmit")
@AnonymousAccess
@Transactional(rollbackFor = Exception.class)
public ResultEntity uploadExcel(@RequestBody StuIndustryAnalysisDTO analysisDTO) {
//查询数据
HyxqfxStuAnswerExample example = new HyxqfxStuAnswerExample();
example.createCriteria().andUserIdEqualTo(analysisDTO.getUserId());
List<HyxqfxStuAnswer> hyxqfxStuAnswerList = hyxqfxStuAnswerMapper.selectByExample(example);
if (!CollectionUtils.isEmpty(hyxqfxStuAnswerList)) {
return new ResultEntity<>(HttpStatus.ACCEPTED,"请勿重复提交!");
}
//读取文件内容 批量导入excel中 以文件名区分
Map<String, Double> yearMap = new HashMap<>();
yearMap.put("2018年", 0.28);
yearMap.put("2019年", 0.25);
yearMap.put("2020年", 0.24);
yearMap.put("2021年", 0.22);
yearMap.put("2022年", 0.21);
yearMap.put("2023年", 0.22);
yearMap.put("2024年", 0.20);
Map<String, Double> monthMap = new HashMap<>();
monthMap.put("2024年4月", 0.21);
monthMap.put("2024年5月", 0.20);
monthMap.put("2024年6月", 0.20);
monthMap.put("2024年7月", 0.22);
monthMap.put("2024年8月", 0.33);
monthMap.put("2024年9月", 0.30);
monthMap.put("2024年10月", 0.33);
monthMap.put("2024年11月", 0.23);
monthMap.put("2024年12月", 0.22);
monthMap.put("2025年1月", 0.22);
monthMap.put("2025年2月", 0.15);
monthMap.put("2025年3月", 0.27);
int count = 0;
List<YearCakeIndexDto> yearCakeIndexDtoList = analysisDTO.getYearCakeIndexDtoList();
for (YearCakeIndexDto yearCakeIndexDto : yearCakeIndexDtoList) {
Double v = yearMap.get(yearCakeIndexDto.getYear());
if (yearCakeIndexDto.getYearAnswer() == null) {
count++;
continue;
}
BigDecimal frontValue = new BigDecimal(v);
BigDecimal backendValue = new BigDecimal(yearCakeIndexDto.getYearAnswer());
if (frontValue.compareTo(backendValue) != 0) {
count++;
}
}
//分别将两个字段转为json格式
List<MonthlyCakeIndex> monthlyCakeIndexList = analysisDTO.getMonthlyCakeIndexList();
for (MonthlyCakeIndex yearCakeIndexDto : monthlyCakeIndexList) {
String cleanKey = Convert.toStr(yearCakeIndexDto.getYear())
.replaceAll("[\\u200C\\uFEFF\\u200B\\s\\u3000\\u00A0]+", "") // 移除各种不可见字符和空格
.trim();
Double v = monthMap.get(cleanKey);
// Double v = monthMap.get(yearCakeIndexDto.getYear());
if (yearCakeIndexDto.getMonthAnswer() == null) {
count++;
continue;
}
BigDecimal frontValue = new BigDecimal(v);
BigDecimal backendValue = new BigDecimal(yearCakeIndexDto.getMonthAnswer());
if (frontValue.compareTo(backendValue) != 0) {
count++;
}
}
BigDecimal subtract = BigDecimal.ZERO;
//学生答案
String jsonString = JSONObject.toJSONString(analysisDTO);
HyxqfxStuAnswer hyxqfxStuAnswer = new HyxqfxStuAnswer();
hyxqfxStuAnswer.setId(IdUtil.randomUUID());
hyxqfxStuAnswer.setUserId(analysisDTO.getUserId());
hyxqfxStuAnswer.setAnswer(jsonString);
hyxqfxStuAnswer.setErrorNumber(count);
hyxqfxStuAnswerMapper.insertSelective(hyxqfxStuAnswer);
//主观题
int i = compareListsUtil.calculateLengthPenaltyEnhanced(analysisDTO.getContext());
count = count + i;
subtract = BigDecimal.valueOf(100).subtract(Convert.toBigDecimal(count));
Boolean aBoolean = scoreService.insertScore(analysisDTO.getUserId(), Constant.PRO_SCXQWJ, Constant.MODULE_HYXQFX, subtract, analysisDTO.getContext());
// scoreService.insertScore(userId, Constant.PRO_GYQDGL, Constant.MODULE_CGXQYC, BigDecimal.valueOf(100 - errorCount), null);
if (aBoolean) {
return new ResultEntity<>(HttpStatus.OK, "提交成功");
} else {
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "提交失败");
}
}
@ApiOperation("行业需求分析根据用户ID查询")
@GetMapping("/selectByUserId")
@AnonymousAccess
public ResultEntity selectByUserId(@ApiParam("用户ID") String userId) {
//读取文件内容 批量导入excel中 以文件名区分\
HyxqfxStuAnswerExample hyxqfxStuAnswer = new HyxqfxStuAnswerExample();
hyxqfxStuAnswer.createCriteria().andUserIdEqualTo(userId);
List<HyxqfxStuAnswer> hyxqfxStuAnswersList = hyxqfxStuAnswerMapper.selectByExampleWithBLOBs(hyxqfxStuAnswer);
if (CollectionUtils.isEmpty(hyxqfxStuAnswersList)) {
return new ResultEntity<>(HttpStatus.OK);
} else {
JSONObject jsonObject = JSONObject.parseObject(hyxqfxStuAnswersList.get(0).getAnswer());
return new ResultEntity<>(HttpStatus.OK, jsonObject);
}
}
@ApiOperation("重新实训接口")
@GetMapping("/restartExperment")
@AnonymousAccess
public ResultEntity restartExperment(@ApiParam("用户ID") String userId, @ApiParam("小模块") String module) {
if (Constant.MODULE_HYXQFX.equals(module)) {
//查询学生答题数据,删除成绩
HyxqfxStuAnswerExample example = new HyxqfxStuAnswerExample();
example.createCriteria().andUserIdEqualTo(userId);
hyxqfxStuAnswerMapper.deleteByExample(example);
scoreService.deleteScore(userId, Constant.PRO_SCXQWJ, Constant.MODULE_HYXQFX);
}
if (Constant.MODULE_JZHJFX.equals(module)) {
//查询学生答题数据,删除成绩
JzhyfxStuAnswerExample jzhyfxStuAnswerExample = new JzhyfxStuAnswerExample();
jzhyfxStuAnswerExample.createCriteria().andUserIdEqualTo(userId);
jzhyfxStuAnswerMapper.deleteByExample(jzhyfxStuAnswerExample);
scoreService.deleteScore(userId, Constant.PRO_SCXQWJ, Constant.MODULE_JZHJFX);
}
return new ResultEntity<>(HttpStatus.OK, "重新实训成功!");
}
@ApiOperation("竞争环境分析提交")
@PostMapping("/competitiveEnvSubmit")
@AnonymousAccess
public ResultEntity competitiveEnvSubmit(@RequestBody CompetitiveEnvDTO competitiveEnvDTO) {
//校验答案是否正确
//查询数据库 是否已经答过题
JzhyfxStuAnswerExample example = new JzhyfxStuAnswerExample();
example.createCriteria().andUserIdEqualTo(competitiveEnvDTO.getUserId());
List<JzhyfxStuAnswer> stuAnswerList = jzhyfxStuAnswerMapper.selectByExample(example);
if (!CollectionUtils.isEmpty(stuAnswerList)) {
return new ResultEntity(HttpStatus.ACCEPTED,"请勿重复答题!");
}
Double answer = 0.116;
Double stuAnswer = competitiveEnvDTO.getAnswer();
int count = 0;
BigDecimal frontValue = new BigDecimal(answer);
BigDecimal backendValue = new BigDecimal(stuAnswer);
if (frontValue.compareTo(backendValue) != 0) {
count++;
}
int i = compareListsUtil.calculateLengthPenaltyEnhanced(competitiveEnvDTO.getContext());
count = count + i;
//首次提交
JzhyfxStuAnswer jzhyfxStuAnswer = new JzhyfxStuAnswer();
jzhyfxStuAnswer.setUserId(competitiveEnvDTO.getUserId());
jzhyfxStuAnswer.setAnswer(stuAnswer.toString());
jzhyfxStuAnswer.setId(IdUtil.randomUUID());
jzhyfxStuAnswer.setContext(competitiveEnvDTO.getContext());
jzhyfxStuAnswerMapper.insertSelective(jzhyfxStuAnswer);
Boolean aBoolean = scoreService.insertScore(competitiveEnvDTO.getUserId(), Constant.PRO_SCXQWJ, Constant.MODULE_JZHJFX, BigDecimal.valueOf(100 - count), null);
// scoreService.insertScore(userId, Constant.PRO_GYQDGL, Constant.MODULE_CGXQYC, BigDecimal.valueOf(100 - errorCount), null);
if (aBoolean) {
return new ResultEntity<>(HttpStatus.OK, "提交成功");
} else {
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "提交失败");
}
}
@ApiOperation("竞争环境分析根据用户ID查询")
@GetMapping("/competitiveEnvSubmitByUserId")
@AnonymousAccess
public ResultEntity competitiveEnvSubmitByUserId(@ApiParam("用户ID") String userId) {
//读取文件内容 批量导入excel中 以文件名区分\
//查询数据库 是否已经答过题
JzhyfxStuAnswerExample example = new JzhyfxStuAnswerExample();
example.createCriteria().andUserIdEqualTo(userId);
List<JzhyfxStuAnswer> stuAnswerList = jzhyfxStuAnswerMapper.selectByExampleWithBLOBs(example);
if (CollectionUtils.isEmpty(stuAnswerList)) {
return new ResultEntity<>(HttpStatus.OK);
} else {
return new ResultEntity<>(HttpStatus.OK, stuAnswerList.get(0));
}
}
@ApiOperation("EXCEL下载数据")
@GetMapping("/downloadExcel")
@AnonymousAccess
public void downloadExcel(HttpServletResponse response,
@ApiParam("对应小模块如:行业需求分析") String module,
@RequestParam(required = false) @ApiParam("对应数据如:年度数据、月度数据,没有就不传参")String fileName) {
if (Constant.MODULE_HYXQFX.equals(module))
{
if (Constant.INFO_NDSJ.equals(fileName))
{
fileUtil.download(response,"行业需求分析年度数据.xls");
}
if (Constant.INFO_YDSJ.equals(fileName))
{
fileUtil.download(response,"行业需求分析月度数据.xls");
}
}
if (Constant.MODULE_JZHJFX.equals(module))
{
fileUtil.download(response,"竞争环境分析.xls");
}
}
}