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.
115 lines
4.8 KiB
Java
115 lines
4.8 KiB
Java
|
1 year ago
|
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.CgxqycAnswerMapper;
|
||
|
|
import com.sztzjy.linkCommerce.mapper.CgxqycStuAnswerMapper;
|
||
|
|
import com.sztzjy.linkCommerce.mapper.StuGradeMapper;
|
||
|
|
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.util.ArrayList;
|
||
|
|
import java.util.List;
|
||
|
|
|
||
|
|
@Api(tags = "采购需求预测相关")
|
||
|
|
@RequestMapping("api/cgxqyc")
|
||
|
|
@RestController
|
||
|
|
public class CgxqycController {
|
||
|
|
@Autowired
|
||
|
|
CgxqycStuAnswerMapper cgxqycStuAnswerMapper;
|
||
|
|
@Autowired
|
||
|
|
CgxqycAnswerMapper cgxqycAnswerMapper;
|
||
|
|
@Autowired
|
||
|
|
StuGradeMapper stuGradeMapper;
|
||
|
|
|
||
|
|
@PostMapping("/selectCgxqycAnswer")
|
||
|
|
@ApiOperation("采购需求预测-回显")
|
||
|
|
@AnonymousAccess
|
||
|
|
public ResultEntity<CgxqycStuAnswer> selectCgxqycAnswer(@RequestParam String userId) {
|
||
|
|
CgxqycStuAnswerExample cgxqycStuAnswerExample = new CgxqycStuAnswerExample();
|
||
|
|
cgxqycStuAnswerExample.createCriteria().andUserIdEqualTo(userId);
|
||
|
|
List<CgxqycStuAnswer> cgxqycStuAnswerList = cgxqycStuAnswerMapper.selectByExample(cgxqycStuAnswerExample);
|
||
|
|
if (cgxqycStuAnswerList == null || cgxqycStuAnswerList.isEmpty()) {
|
||
|
|
return new ResultEntity<>(HttpStatus.OK, "未提交");
|
||
|
|
} else {
|
||
|
|
return new ResultEntity<>(HttpStatus.OK, "采购需求预测-回显", cgxqycStuAnswerList.get(0));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// @PostMapping("/commitCgxqycAnswer")
|
||
|
|
// @ApiOperation("采购需求预测-提交")
|
||
|
|
// @AnonymousAccess
|
||
|
|
// public ResultEntity commitCgxqycAnswer(@RequestBody CgxqycStuAnswer cgxqycStuAnswer, @RequestParam String userId) {
|
||
|
|
// CgxqycAnswer cgxqycAnswer = cgxqycAnswerMapper.selectByExample(new CgxqycAnswerExample()).get(0);
|
||
|
|
// String monthlyDataStu = cgxqycStuAnswer.getMonthlyData();
|
||
|
|
// String monthlyData = cgxqycAnswer.getMonthlyData();
|
||
|
|
// int monthlyDataErrorCount = compareLists(monthlyDataStu, monthlyData).errorCount;
|
||
|
|
// String seasonalIndexStu = cgxqycStuAnswer.getSeasonalIndex();
|
||
|
|
// String seasonalIndex = cgxqycAnswer.getSeasonalIndex();
|
||
|
|
// int seasonalIndexErrorCount = compareLists(seasonalIndexStu, seasonalIndex).errorCount;
|
||
|
|
// String demandForecastStu = cgxqycStuAnswer.getDemandForecast();
|
||
|
|
// String demandForecast = cgxqycAnswer.getDemandForecast();
|
||
|
|
// int demandForecastErrorCount = compareLists(demandForecastStu, demandForecast).errorCount;
|
||
|
|
// int errorCount = monthlyDataErrorCount + seasonalIndexErrorCount + demandForecastErrorCount;
|
||
|
|
// //先查询是否提交过
|
||
|
|
// 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) {
|
||
|
|
// //新建学生成绩
|
||
|
|
//// stuGradeMapper.insert()
|
||
|
|
// } else {
|
||
|
|
// return new ResultEntity<>(HttpStatus.BAD_REQUEST, "已提交过");
|
||
|
|
// }
|
||
|
|
//
|
||
|
|
// }
|
||
|
|
|
||
|
|
|
||
|
|
public Result compareLists(String stulist, String answerList) {
|
||
|
|
// 将字符串分割成数组
|
||
|
|
String[] submitted = stulist.split(",");
|
||
|
|
String[] answers = answerList.split(",");
|
||
|
|
|
||
|
|
int errorCount = 0; // 错误数量
|
||
|
|
List<Integer> errorPositions = new ArrayList<>(); // 错误位置
|
||
|
|
|
||
|
|
// 获取较长数组的长度
|
||
|
|
int maxLength = Math.max(submitted.length, answers.length);
|
||
|
|
|
||
|
|
// 遍历较长的数组
|
||
|
|
for (int i = 0; i < maxLength; i++) {
|
||
|
|
String submittedValue = (i < submitted.length) ? submitted[i] : null;
|
||
|
|
String answerValue = (i < answers.length) ? answers[i] : null;
|
||
|
|
|
||
|
|
// 检查对应位置是否相同
|
||
|
|
if (!equals(submittedValue, answerValue)) {
|
||
|
|
errorCount++;
|
||
|
|
errorPositions.add(i + 1); // +1 使位置从 1 开始
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return new Result(errorCount, errorPositions);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 自定义 equals 方法处理 null 和空字符串的场景
|
||
|
|
public static boolean equals(String a, String b) {
|
||
|
|
return (a == null ? b == null : a.equals(b));
|
||
|
|
}
|
||
|
|
|
||
|
|
// 内部类用来保存比较结果
|
||
|
|
static class Result {
|
||
|
|
int errorCount;
|
||
|
|
List<Integer> errorPositions;
|
||
|
|
|
||
|
|
Result(int errorCount, List<Integer> errorPositions) {
|
||
|
|
this.errorCount = errorCount;
|
||
|
|
this.errorPositions = errorPositions;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|