|
@@ -2,13 +2,12 @@ package com.css.simulation.resource.server.app.service;
|
|
|
|
|
|
import api.common.pojo.common.ResponseBodyVO;
|
|
import api.common.pojo.common.ResponseBodyVO;
|
|
import api.common.pojo.constants.DictConstants;
|
|
import api.common.pojo.constants.DictConstants;
|
|
|
|
+import api.common.pojo.param.scene.SceneEvaluationRuleParam;
|
|
import api.common.pojo.param.scene.ScoringRulesParam;
|
|
import api.common.pojo.param.scene.ScoringRulesParam;
|
|
import api.common.pojo.po.scene.SceneEvaluationRulePO;
|
|
import api.common.pojo.po.scene.SceneEvaluationRulePO;
|
|
import api.common.pojo.po.scene.ScoringRulesPO;
|
|
import api.common.pojo.po.scene.ScoringRulesPO;
|
|
-import api.common.util.LogUtil;
|
|
|
|
-import api.common.util.PythonUtil;
|
|
|
|
-import api.common.util.StringUtil;
|
|
|
|
-import api.common.util.TimeUtil;
|
|
|
|
|
|
+import api.common.util.*;
|
|
|
|
+import com.css.simulation.resource.server.infra.db.mysql.mapper.SceneEvaluationRuleMapper;
|
|
import com.css.simulation.resource.server.infra.db.mysql.mapper.ScenePackageMapper;
|
|
import com.css.simulation.resource.server.infra.db.mysql.mapper.ScenePackageMapper;
|
|
import com.css.simulation.resource.server.infra.db.mysql.mapper.ScoringRulesMapper;
|
|
import com.css.simulation.resource.server.infra.db.mysql.mapper.ScoringRulesMapper;
|
|
import com.css.simulation.resource.server.infra.feign.service.FileDownService;
|
|
import com.css.simulation.resource.server.infra.feign.service.FileDownService;
|
|
@@ -30,6 +29,8 @@ public class ScoringRulesService {
|
|
private ScoringRulesMapper scoringRulesMapper;
|
|
private ScoringRulesMapper scoringRulesMapper;
|
|
@Resource
|
|
@Resource
|
|
private ScenePackageMapper scenePackageMapper;
|
|
private ScenePackageMapper scenePackageMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private SceneEvaluationRuleMapper sceneEvaluationRuleMapper;
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
private FileDownService fileDownService;
|
|
private FileDownService fileDownService;
|
|
@@ -91,9 +92,8 @@ public class ScoringRulesService {
|
|
}
|
|
}
|
|
|
|
|
|
@SneakyThrows
|
|
@SneakyThrows
|
|
- public SceneEvaluationRulePO querySceneEvaluationRuleOnly(String ruleName, String createUserId) {
|
|
|
|
-// return scoringRulesMapper.querySceneEvaluationRuleOnly(ruleName, createUserId);
|
|
|
|
- return new SceneEvaluationRulePO();
|
|
|
|
|
|
+ public int querySceneEvaluationRuleOnly(String ruleName, String ruleId) {
|
|
|
|
+ return sceneEvaluationRuleMapper.querySceneEvaluationRuleOnly(ruleName, ruleId);
|
|
}
|
|
}
|
|
|
|
|
|
@SneakyThrows
|
|
@SneakyThrows
|
|
@@ -170,34 +170,85 @@ public class ScoringRulesService {
|
|
|
|
|
|
|
|
|
|
@SneakyThrows
|
|
@SneakyThrows
|
|
- public ResponseBodyVO<Map<String, String>> uploadPyScript(MultipartFile file) {
|
|
|
|
- // 检查文件内容是否合规
|
|
|
|
- String pyStr = new String(file.getBytes(), StandardCharsets.UTF_8);
|
|
|
|
- //1 校验 python 语法错误
|
|
|
|
- String pylint = PythonUtil.pylint(pyStr, PythonUtil.C, PythonUtil.R, PythonUtil.W, PythonUtil.E0401, PythonUtil.E0601);
|
|
|
|
- if (!pylint.contains(PythonUtil.PASS)) {
|
|
|
|
- return new ResponseBodyVO<>(ResponseBodyVO.Response.CLIENT_FAILURE, "代码格式错误,请检查。");
|
|
|
|
|
|
+ public ResponseBodyVO<String> uploadPyScriptAndSaveRule(MultipartFile file, SceneEvaluationRulePO sceneEvaluationRulePO) {
|
|
|
|
+
|
|
|
|
+ boolean hasRuleId = StringUtil.isEmpty(sceneEvaluationRulePO.getRuleId());
|
|
|
|
+
|
|
|
|
+ // 检查是否存在同名场景评价规则
|
|
|
|
+ int repeatPyScriptAndSaveRuleCount = querySceneEvaluationRuleOnly(sceneEvaluationRulePO.getRuleName(),
|
|
|
|
+ hasRuleId ? null : sceneEvaluationRulePO.getRuleId());
|
|
|
|
+ if (repeatPyScriptAndSaveRuleCount > 0) {
|
|
|
|
+ return new ResponseBodyVO<>(ResponseBodyVO.Response.CLIENT_FAILURE, "场景规则 " + sceneEvaluationRulePO.getRuleName() + " 已存在,请重新命名。");
|
|
}
|
|
}
|
|
- // 获取文件原本的名字
|
|
|
|
- String originName = file.getOriginalFilename();
|
|
|
|
- if (null == originName) {
|
|
|
|
- return new ResponseBodyVO<>(ResponseBodyVO.Response.CLIENT_FAILURE, "文件名为空,请检查!");
|
|
|
|
|
|
+ // 新建或者是编辑时重新上传文件
|
|
|
|
+ if ((hasRuleId) || sceneEvaluationRulePO.getUploadNewFile()) {
|
|
|
|
+ String roleCode = AuthUtil.getCurrentUserRoleCode();
|
|
|
|
+ if (!DictConstants.ROLE_CODE_ADMIN.equals(roleCode) && !DictConstants.ROLE_CODE_SYSADMIN.equals(roleCode)) {
|
|
|
|
+ return new ResponseBodyVO<>(ResponseBodyVO.Response.CLIENT_FAILURE, "非管理员禁止上传文件");
|
|
|
|
+ }
|
|
|
|
+ // 检查文件内容是否合规
|
|
|
|
+ String pyStr = new String(file.getBytes(), StandardCharsets.UTF_8);
|
|
|
|
+ //1 校验 python 语法错误
|
|
|
|
+ String pylint = PythonUtil.pylint(pyStr, PythonUtil.C, PythonUtil.R, PythonUtil.W, PythonUtil.E0401, PythonUtil.E0601);
|
|
|
|
+ if (!pylint.contains(PythonUtil.PASS)) {
|
|
|
|
+ return new ResponseBodyVO<>(ResponseBodyVO.Response.CLIENT_FAILURE, "代码格式错误,请检查。");
|
|
|
|
+ }
|
|
|
|
+ // 获取文件原本的名字
|
|
|
|
+ String originName = file.getOriginalFilename();
|
|
|
|
+ if (null == originName) {
|
|
|
|
+ return new ResponseBodyVO<>(ResponseBodyVO.Response.CLIENT_FAILURE, "文件名为空,请检查!");
|
|
|
|
+ }
|
|
|
|
+ String fileName = originName.substring(0, originName.lastIndexOf("."));
|
|
|
|
+ Integer nowTime = TimeUtil.getRq(new Date(), 0);
|
|
|
|
+ String randomCode = StringUtil.getRandomCode();
|
|
|
|
+ fileName = "/" + DictConstants.SCENE_EVALUATION_RULE_PY_FILE + "/" + nowTime + "/" + randomCode + "/" + fileName;
|
|
|
|
+ ResponseBodyVO<String> response = fileDownService.upload(file, fileName);
|
|
|
|
+ if (response.isStatus()) {
|
|
|
|
+ String previewUrl = response.getInfo();
|
|
|
|
+ sceneEvaluationRulePO.setScriptName(fileName);
|
|
|
|
+ sceneEvaluationRulePO.setScriptPath(previewUrl);
|
|
|
|
+ }
|
|
|
|
+ return new ResponseBodyVO<>(ResponseBodyVO.Response.CLIENT_FAILURE, "上传失败!");
|
|
}
|
|
}
|
|
- String fileName = originName.substring(0, originName.lastIndexOf("."));
|
|
|
|
- Integer nowTime = TimeUtil.getRq(new Date(), 0);
|
|
|
|
- String randomCode = StringUtil.getRandomCode();
|
|
|
|
- fileName = "/" + DictConstants.VEHICLE_IMG_FILE + "/" + nowTime + "/" + randomCode + "/" + fileName;
|
|
|
|
- ResponseBodyVO<String> response = fileDownService.upload(file, fileName);
|
|
|
|
- if (response.isStatus()) {
|
|
|
|
- String previewUrl = response.getInfo();
|
|
|
|
- Map<String, String> map = new HashMap<>();
|
|
|
|
- map.put("previewUrl", previewUrl);
|
|
|
|
- map.put("fileName", fileName);
|
|
|
|
- return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS, map);
|
|
|
|
|
|
+
|
|
|
|
+ // 判断 ruleId 是否为空
|
|
|
|
+ if (StringUtil.isEmpty(sceneEvaluationRulePO.getRuleId())) {
|
|
|
|
+ // 创建
|
|
|
|
+ saveSceneEvaluationRule(sceneEvaluationRulePO);
|
|
|
|
+ } else {
|
|
|
|
+ // 修改
|
|
|
|
+ updateSceneEvaluationRule(sceneEvaluationRulePO);
|
|
}
|
|
}
|
|
- return new ResponseBodyVO<>(ResponseBodyVO.Response.CLIENT_FAILURE, "上传失败!");
|
|
|
|
|
|
+ return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询场景评价规则列表
|
|
|
|
+ */
|
|
|
|
+ @SneakyThrows
|
|
|
|
+ public List<SceneEvaluationRulePO> querySceneEvaluationRuleList(SceneEvaluationRuleParam params) {
|
|
|
|
+ return sceneEvaluationRuleMapper.querySceneEvaluationRuleList(params);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
|
|
+ @SneakyThrows
|
|
|
|
+ public void saveSceneEvaluationRule(SceneEvaluationRulePO params) {
|
|
|
|
+ params.setCreateTime(TimeUtil.getNowForMysql());
|
|
|
|
+ params.setModifyTime(TimeUtil.getNowForMysql());
|
|
|
|
+ params.setRuleId(StringUtil.getRandomUUID());
|
|
|
|
+ params.setRuleCode(StringUtil.getRandomCode());
|
|
|
|
+ params.setCreateUserId(AuthUtil.getCurrentUserId());
|
|
|
|
+ params.setIsDeleted("0");
|
|
|
|
+ sceneEvaluationRuleMapper.saveSceneEvaluationRule(params);
|
|
|
|
+ LogUtil.insert();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @SneakyThrows
|
|
|
|
+ public void updateSceneEvaluationRule(SceneEvaluationRulePO params) {
|
|
|
|
+ params.setModifyTime(TimeUtil.getNowForMysql());
|
|
|
|
+ params.setModifyUserId(AuthUtil.getCurrentUserId());
|
|
|
|
+ sceneEvaluationRuleMapper.updateSceneEvaluationRule(params);
|
|
|
|
+ LogUtil.update();
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|