package com.sztzjy.linkCommerce.controller.stu; import com.sztzjy.linkCommerce.annotation.AnonymousAccess; import com.sztzjy.linkCommerce.config.Constant; import com.sztzjy.linkCommerce.entity.*; import com.sztzjy.linkCommerce.mapper.*; import com.sztzjy.linkCommerce.service.ScoreService; import com.sztzjy.linkCommerce.util.CompareListsUtil; import com.sztzjy.linkCommerce.util.ResultEntity; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; import java.math.BigDecimal; import java.util.List; import java.util.UUID; @Api(tags = "产品问题诊断-流量数据分析法 PRO_CPPGYKH MODULE_CPWTZD_LLSJFXF") @RequestMapping("api/cpwtzdllsjfxf") @RestController public class CpwtzdLlsjfxfController { @Autowired CpwtzdLlsjfxfStuAnswerMapper cpwtzdLlsjfxfStuAnswerMapper; @Autowired ScoreService scoreService; @Autowired StuGradeMapper stuGradeMapper; @Autowired CpwtzdLlsjfxfAnswerMapper cpwtzdLlsjfxfAnswerMapper; @Autowired CompareListsUtil compareListsUtil; @PostMapping("/selectCpwtzdLlsjfxfStuAnswer") @ApiOperation("产品问题诊断-流量数据分析法-回显") @AnonymousAccess public ResultEntity selectCpwtzdLlsjfxfStuAnswer(@RequestParam String userId) { CpwtzdLlsjfxfStuAnswerExample example = new CpwtzdLlsjfxfStuAnswerExample(); example.createCriteria().andUserIdEqualTo(userId); List list = cpwtzdLlsjfxfStuAnswerMapper.selectByExample(example); if (list == null || list.isEmpty()) { return new ResultEntity<>(HttpStatus.OK, "未提交"); } else { return new ResultEntity<>(HttpStatus.OK, "产品问题诊断-流量数据分析法-回显", list.get(0)); } } @PostMapping("/commitCpwtzdLlsjfxfAnswer") @ApiOperation("产品问题诊断-流量数据分析法-提交") @AnonymousAccess public ResultEntity commitCpwtzdLlsjfxfAnswer(@RequestBody CpwtzdLlsjfxfStuAnswer stuAnswer, @RequestParam String userId) { //先查询是否提交过 StuGradeExample stuGradeExample = new StuGradeExample(); stuGradeExample.createCriteria().andUserIdEqualTo(userId).andProjectEqualTo(Constant.PRO_CPPGYKH).andModuleEqualTo(Constant.MODULE_CPWTZD_LLSJFXF); List stuGradeList = stuGradeMapper.selectByExample(stuGradeExample); if(stuGradeList.isEmpty() || stuGradeList == null){ CpwtzdLlsjfxfAnswer answer = cpwtzdLlsjfxfAnswerMapper.selectByExample(new CpwtzdLlsjfxfAnswerExample()).get(0); int errorCount=0; if(!answer.getRw1One().equals(stuAnswer.getRw1One())){ errorCount++; } if(!answer.getRw1Two().equals(stuAnswer.getRw1Two())){ errorCount++; } if(!answer.getRw1Three().equals(stuAnswer.getRw1Three())){ errorCount++; } if(!answer.getRw1Four().equals(stuAnswer.getRw1Four())){ errorCount++; } if(!answer.getRw1Five().equals(stuAnswer.getRw1Five())){ errorCount++; } if(!answer.getRw1Five().equals(stuAnswer.getRw1Five())){ errorCount++; } int i1 = compareListsUtil.calculateLengthPenaltyEnhanced(stuAnswer.getRw1Six()); if(!answer.getRw1Five().equals(stuAnswer.getRw1Seven())){ errorCount++; } int i2 = compareListsUtil.calculateLengthPenaltyEnhanced(stuAnswer.getRw1Eight()); if(!answer.getRw2One().equals(stuAnswer.getRw2One())){ errorCount++; } if(!answer.getRw2Two().equals(stuAnswer.getRw2Two())){ errorCount++; } if(!answer.getRw2Three().equals(stuAnswer.getRw2Three())){ errorCount++; } int i3 = compareListsUtil.calculateLengthPenaltyEnhanced(stuAnswer.getYhcs()); errorCount=errorCount+i1+i2+i3; Boolean aBoolean = scoreService.insertScore(userId, Constant.PRO_CPPGYKH, Constant.MODULE_CPWTZD_LLSJFXF, BigDecimal.valueOf(100 - errorCount), null); stuAnswer.setId(UUID.randomUUID().toString()); cpwtzdLlsjfxfStuAnswerMapper.insert(stuAnswer); if(aBoolean){ return new ResultEntity<>(HttpStatus.OK, "提交成功"); }else { return new ResultEntity<>(HttpStatus.BAD_REQUEST, "提交失败"); } }else { return new ResultEntity<>(HttpStatus.BAD_REQUEST, "已提交过"); } } @PostMapping("/restartTraining") @ApiOperation("产品问题诊断-Kano模型-重新实训") @AnonymousAccess public ResultEntity restartTraining(@RequestParam String userId) { Boolean b=scoreService.deleteScore(userId,Constant.PRO_CPPGYKH,Constant.MODULE_CPWTZD_LLSJFXF); if(b){ CpwtzdLlsjfxfStuAnswerExample example = new CpwtzdLlsjfxfStuAnswerExample(); example.createCriteria().andUserIdEqualTo(userId); cpwtzdLlsjfxfStuAnswerMapper.deleteByExample(example); return new ResultEntity<>(HttpStatus.OK, "重新实训成功"); }else { return new ResultEntity<>(HttpStatus.BAD_REQUEST, "重新实训失败"); } } }