|
|
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.entity.export.CgxqycData;
|
|
|
import com.sztzjy.linkCommerce.mapper.CgxqycAnswerMapper;
|
|
|
import com.sztzjy.linkCommerce.mapper.CgxqycStuAnswerMapper;
|
|
|
import com.sztzjy.linkCommerce.mapper.StuGradeMapper;
|
|
|
import com.sztzjy.linkCommerce.service.ScoreService;
|
|
|
import com.sztzjy.linkCommerce.util.CompareListsUtil;
|
|
|
import com.sztzjy.linkCommerce.util.ResultEntity;
|
|
|
import com.sztzjy.linkCommerce.util.excel.FilePortUtil;
|
|
|
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 javax.servlet.http.HttpServletResponse;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.UUID;
|
|
|
|
|
|
@Api(tags = "采购需求预测相关 PRO_GYQDGL,MODULE_CGXQYC")
|
|
|
@RequestMapping("api/cgxqyc")
|
|
|
@RestController
|
|
|
public class CgxqycController {
|
|
|
@Autowired
|
|
|
CgxqycStuAnswerMapper cgxqycStuAnswerMapper;
|
|
|
@Autowired
|
|
|
CgxqycAnswerMapper cgxqycAnswerMapper;
|
|
|
@Autowired
|
|
|
StuGradeMapper stuGradeMapper;
|
|
|
@Autowired
|
|
|
CompareListsUtil compareListsUtil;
|
|
|
@Autowired
|
|
|
ScoreService scoreService;
|
|
|
|
|
|
@PostMapping("/selectCgxqycStuAnswer")
|
|
|
@ApiOperation("采购需求预测-回显")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity<CgxqycStuAnswer> selectCgxqycAnswer(@RequestParam String userId) {
|
|
|
CgxqycStuAnswerExample example = new CgxqycStuAnswerExample();
|
|
|
example.createCriteria().andUserIdEqualTo(userId);
|
|
|
List<CgxqycStuAnswer> list = cgxqycStuAnswerMapper.selectByExample(example);
|
|
|
if (list == null || list.isEmpty()) {
|
|
|
return new ResultEntity<>(HttpStatus.OK, "未提交");
|
|
|
} else {
|
|
|
return new ResultEntity<>(HttpStatus.OK, "采购需求预测-回显", list.get(0));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@PostMapping("/commitCgxqycAnswer")
|
|
|
@ApiOperation("采购需求预测-提交")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity commitCgxqycAnswer(@RequestBody CgxqycStuAnswer stuAnswer, @RequestParam String userId) {
|
|
|
//先查询是否提交过
|
|
|
StuGradeExample stuGradeExample = new StuGradeExample();
|
|
|
stuGradeExample.createCriteria().andUserIdEqualTo(userId).andProjectEqualTo(Constant.PRO_GYQDGL).andModuleEqualTo(Constant.MODULE_CGXQYC);
|
|
|
List<StuGrade> stuGradeList = stuGradeMapper.selectByExample(stuGradeExample);
|
|
|
if (stuGradeList.isEmpty() || stuGradeList == null) {
|
|
|
CgxqycAnswer answer = cgxqycAnswerMapper.selectByExample(new CgxqycAnswerExample()).get(0);
|
|
|
String monthlyDataStu = stuAnswer.getMonthlyData();
|
|
|
String monthlyData = answer.getMonthlyData();
|
|
|
int monthlyDataErrorCount = compareListsUtil.compareLists(monthlyDataStu, monthlyData).getErrorCount();
|
|
|
String seasonalIndexStu = stuAnswer.getSeasonalIndex();
|
|
|
String seasonalIndex = answer.getSeasonalIndex();
|
|
|
int seasonalIndexErrorCount = compareListsUtil.compareLists(seasonalIndexStu, seasonalIndex).getErrorCount();
|
|
|
String demandForecastStu = stuAnswer.getDemandForecast();
|
|
|
String demandForecast = answer.getDemandForecast();
|
|
|
int demandForecastErrorCount = compareListsUtil.compareLists(demandForecastStu, demandForecast).getErrorCount();
|
|
|
int errorCount = monthlyDataErrorCount + seasonalIndexErrorCount + demandForecastErrorCount;
|
|
|
Boolean aBoolean = scoreService.insertScore(userId, Constant.PRO_GYQDGL, Constant.MODULE_CGXQYC, BigDecimal.valueOf(100 - errorCount), null);
|
|
|
stuAnswer.setId(UUID.randomUUID().toString());
|
|
|
cgxqycStuAnswerMapper.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("采购需求预测-重新实训")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity restartTraining(@RequestParam String userId) {
|
|
|
Boolean b = scoreService.deleteScore(userId, Constant.PRO_GYQDGL, Constant.MODULE_CGXQYC);
|
|
|
if (b) {
|
|
|
CgxqycStuAnswerExample example = new CgxqycStuAnswerExample();
|
|
|
example.createCriteria().andUserIdEqualTo(userId);
|
|
|
cgxqycStuAnswerMapper.deleteByExample(example);
|
|
|
return new ResultEntity<>(HttpStatus.OK, "重新实训成功");
|
|
|
} else {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "重新实训失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
@AnonymousAccess
|
|
|
@GetMapping("/exportCgxqycData")
|
|
|
@ApiOperation("采购需求预测-数据下载")
|
|
|
public void exportSummaryOfResults(HttpServletResponse response) {
|
|
|
List<CgxqycData> list = new ArrayList<>();
|
|
|
// 2022 Data
|
|
|
list.add(new CgxqycData("2022", "120", "150", "280", "350", "480", "720", "850", "800", "600", "400", "250", "180"));
|
|
|
// 2023 Data
|
|
|
list.add(new CgxqycData("2023", "130", "160", "300", "380", "520", "780", "920", "870", "640", "430", "270", "190"));
|
|
|
// 2024 Data
|
|
|
list.add(new CgxqycData("2024", "140", "170", "320", "400", "550", "830", "950", "900", "680", "460", "290", "200"));
|
|
|
|
|
|
//导出的表名
|
|
|
String title = "采购需求预测数据";
|
|
|
//表中第一行表头字段
|
|
|
String[] headers = {"年份", "1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"};
|
|
|
|
|
|
//具体需要写入excel需要哪些字段,这些字段取自UserReward类,也就是上面的实际数据结果集的泛型
|
|
|
List<String> listColumn = Arrays.asList("year", "oneMonth", "twoMonth", "threeMonth", "fourMonth", "fiveMonth", "sixMonth", "sevenMonth", "eightMonth", "nineMonth", "tenMonth", "elevenMonth", "twelveMonth");
|
|
|
try {
|
|
|
FilePortUtil.exportExcel(response, title, headers, list, listColumn);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|