root 2 jaren geleden
bovenliggende
commit
8814692a08

+ 3 - 0
api-common/src/main/java/api/common/pojo/constants/DictConstants.java

@@ -43,6 +43,9 @@ public class DictConstants {
     public static final String YES = "1";//是
     public static final String NO = "0";//否
 
+    public static final String IS_SHARED = "1";//是
+    public static final String IS_NOT_SHARED = "0";//否
+
     public static final String SCENE_NATURAL = "1"; // 自然驾驶
     public static final String SCENE_STANDARD = "2";    // 标准法规
     public static final String SCENE_ACCIDENT = "3";    // 交通事故

+ 41 - 51
simulation-resource-server/src/main/java/com/css/simulation/resource/model/ctrl/ConfigCtrl.java

@@ -10,33 +10,29 @@ import api.common.pojo.vo.model.ConfigVO;
 import api.common.util.ObjectUtil;
 import com.css.simulation.resource.model.service.ConfigService;
 import com.github.pagehelper.PageInfo;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.stereotype.Controller;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestController;
 
+import javax.annotation.Resource;
 import java.util.List;
 import java.util.Map;
 
-@Controller
-@RequestMapping(value = "/config",name = LogConstants.MODULE_CONFIG)
+@RestController
+@RequestMapping(value = "/config", name = LogConstants.MODULE_CONFIG)
 public class ConfigCtrl {
 
-    @Autowired
-    ConfigService configService;
+    @Resource
+    private ConfigService configService;
 
     /**
      * 获取列表
      */
     @RequestMapping("/getConfigPageList")
-    @ResponseBody
-    public ResponseBodyVO<PageInfo<ConfigVO>> getConfigPageList(@RequestBody @Validated ConfigPageParam pageParam){
-        ResponseBodyVO<PageInfo<ConfigVO>> response = new ResponseBodyVO<PageInfo<ConfigVO>>(ResponseBodyVO.Response.SUCCESS);
-        response.setInfo(configService.getConfigPageList(pageParam));
-        return response;
+    public ResponseBodyVO<PageInfo<ConfigVO>> getConfigPageList(@RequestBody @Validated ConfigPageParam pageParam) {
+        return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS, configService.getConfigPageList(pageParam));
     }
 
 
@@ -44,8 +40,7 @@ public class ConfigCtrl {
      * 根据id获取详情
      */
     @RequestMapping("/getConfigInfo")
-    @ResponseBody
-    public ResponseBodyVO<ConfigVO> getConfigInfo(@RequestBody ConfigVO configVO){
+    public ResponseBodyVO<ConfigVO> getConfigInfo(@RequestBody ConfigVO configVO) {
         ResponseBodyVO<ConfigVO> response = new ResponseBodyVO<ConfigVO>(ResponseBodyVO.Response.SUCCESS);
         response.setInfo(configService.getConfigInfo(configVO));
         return response;
@@ -55,26 +50,25 @@ public class ConfigCtrl {
      * 新增、修改
      */
     @RequestMapping("/saveConfig")
-    @ResponseBody
-    public ResponseBodyVO<ConfigPO> saveConfig(@RequestBody ConfigVO configVO){
-        if(ObjectUtil.isNull(configVO)){
-            return new ResponseBodyVO(false, 500, "参数必传!",null);
+    public ResponseBodyVO<ConfigPO> saveConfig(@RequestBody ConfigVO configVO) {
+        if (ObjectUtil.isNull(configVO)) {
+            return new ResponseBodyVO(false, 500, "参数必传!", null);
         }
         //端口重复校验
         Map<String, List<ConfigSensorVO>> configSensors = configVO.getConfigSensors();
-        if(ObjectUtil.isNotNull(configSensors)){
+        if (ObjectUtil.isNotNull(configSensors)) {
             List<ConfigSensorVO> configSensorVOS = configSensors.get("ogt");//完美传感器
-            if(ObjectUtil.isNotNull(configSensorVOS)){
+            if (ObjectUtil.isNotNull(configSensorVOS)) {
                 long count = configSensorVOS.stream().mapToInt(ConfigSensorVO::getSensorPort).distinct().count();
-                if(configSensorVOS.size() != count){
-                    return new ResponseBodyVO(false, 500, "端口重复!",null);
+                if (configSensorVOS.size() != count) {
+                    return new ResponseBodyVO(false, 500, "端口重复!", null);
                 }
             }
         }
         ResponseBodyVO<ConfigPO> response = new ResponseBodyVO<ConfigPO>(ResponseBodyVO.Response.SUCCESS);
         ConfigPO po = configService.saveConfig(configVO);
-        if(ObjectUtil.isNull(po.getId())){
-            return new ResponseBodyVO(false, 500, "配置名称重复!",null);
+        if (ObjectUtil.isNull(po.getId())) {
+            return new ResponseBodyVO(false, 500, "配置名称重复!", null);
         }
         response.setInfo(po);
         return response;
@@ -84,26 +78,25 @@ public class ConfigCtrl {
      * 另存为
      */
     @RequestMapping("/saveAnotherConfig")
-    @ResponseBody
-    public ResponseBodyVO<ConfigPO> saveAnotherConfig(@RequestBody ConfigVO configVO){
-        if(ObjectUtil.isNull(configVO)){
-            return new ResponseBodyVO(false, 500, "参数必传!",null);
+    public ResponseBodyVO<ConfigPO> saveAnotherConfig(@RequestBody ConfigVO configVO) {
+        if (ObjectUtil.isNull(configVO)) {
+            return new ResponseBodyVO(false, 500, "参数必传!", null);
         }
         //端口重复校验
         Map<String, List<ConfigSensorVO>> configSensors = configVO.getConfigSensors();
-        if(ObjectUtil.isNotNull(configSensors)){
+        if (ObjectUtil.isNotNull(configSensors)) {
             List<ConfigSensorVO> configSensorVOS = configSensors.get("ogt");//完美传感器
-            if(ObjectUtil.isNotNull(configSensorVOS)){
+            if (ObjectUtil.isNotNull(configSensorVOS)) {
                 long count = configSensorVOS.stream().mapToInt(ConfigSensorVO::getSensorPort).distinct().count();
-                if(configSensorVOS.size() != count){
-                    return new ResponseBodyVO(false, 500, "端口重复!",null);
+                if (configSensorVOS.size() != count) {
+                    return new ResponseBodyVO(false, 500, "端口重复!", null);
                 }
             }
         }
         ResponseBodyVO<ConfigPO> response = new ResponseBodyVO<ConfigPO>(ResponseBodyVO.Response.SUCCESS);
         ConfigPO po = configService.saveAnotherConfig(configVO);
-        if(ObjectUtil.isNull(po.getId())){
-            return new ResponseBodyVO(false, 500, "配置名称重复!",null);
+        if (ObjectUtil.isNull(po.getId())) {
+            return new ResponseBodyVO(false, 500, "配置名称重复!", null);
         }
         response.setInfo(po);
         return response;
@@ -113,16 +106,15 @@ public class ConfigCtrl {
      * 详情分享
      */
     @RequestMapping("/shareConfigByInfo")
-    @ResponseBody
     @PreAuthorize("@AuthorityCheck.admin()")
-    public ResponseBodyVO<ConfigPO> shareConfigByInfo(@RequestBody ConfigVO configVO){
-        if(ObjectUtil.isNull(configVO)){
-            return new ResponseBodyVO(false, 500, "参数必传!",null);
+    public ResponseBodyVO<ConfigPO> shareConfigByInfo(@RequestBody ConfigVO configVO) {
+        if (ObjectUtil.isNull(configVO)) {
+            return new ResponseBodyVO(false, 500, "参数必传!", null);
         }
         ResponseBodyVO<ConfigPO> response = new ResponseBodyVO<ConfigPO>(ResponseBodyVO.Response.SUCCESS);
         ConfigPO po = configService.shareConfigByInfo(configVO);
-        if(ObjectUtil.isNull(po.getId())){
-            return new ResponseBodyVO(false, 500, "配置名称重复!",null);
+        if (ObjectUtil.isNull(po.getId())) {
+            return new ResponseBodyVO(false, 500, "配置名称重复!", null);
         }
         response.setInfo(po);
         return response;
@@ -132,16 +124,15 @@ public class ConfigCtrl {
      * 列表分享
      */
     @RequestMapping("/shareConfigById")
-    @ResponseBody
     @PreAuthorize("@AuthorityCheck.admin()")
-    public ResponseBodyVO<ConfigPO> shareConfigById(@RequestBody ConfigVO configVO){
-        if(ObjectUtil.isNull(configVO) || ObjectUtil.isNull(configVO.getId())){
-            return new ResponseBodyVO(false, 500, "参数必传!",null);
+    public ResponseBodyVO<ConfigPO> shareConfigById(@RequestBody ConfigVO configVO) {
+        if (ObjectUtil.isNull(configVO) || ObjectUtil.isNull(configVO.getId())) {
+            return new ResponseBodyVO(false, 500, "参数必传!", null);
         }
         ResponseBodyVO<ConfigPO> response = new ResponseBodyVO<ConfigPO>(ResponseBodyVO.Response.SUCCESS);
         ConfigPO po = configService.shareConfigById(configVO);
-        if(ObjectUtil.isNull(po.getId())){
-            return new ResponseBodyVO(false, 500, "配置名称重复!",null);
+        if (ObjectUtil.isNull(po.getId())) {
+            return new ResponseBodyVO(false, 500, "配置名称重复!", null);
         }
         response.setInfo(po);
         return response;
@@ -151,13 +142,12 @@ public class ConfigCtrl {
      * 删除
      */
     @RequestMapping("/delConfigById")
-    @ResponseBody
-    public ResponseBodyVO delConfigById(@RequestBody ConfigVO configVO){
+    public ResponseBodyVO delConfigById(@RequestBody ConfigVO configVO) {
         int i = configService.delConfigById(configVO);
-        if(i>0){
+        if (i > 0) {
             return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
-        }else{
-            return new ResponseBodyVO(false, 500, "删除失败!",null);
+        } else {
+            return new ResponseBodyVO(false, 500, "删除失败!", null);
         }
     }
 }

+ 34 - 28
simulation-resource-server/src/main/java/com/css/simulation/resource/model/service/ConfigService.java

@@ -7,53 +7,59 @@ import api.common.pojo.vo.model.*;
 import api.common.util.*;
 import com.css.simulation.resource.common.utils.AuthUtil;
 import com.css.simulation.resource.common.utils.PageUtil;
-import com.css.simulation.resource.model.mapper.CameraMapper;
 import com.css.simulation.resource.model.mapper.ConfigMapper;
 import com.css.simulation.resource.model.mapper.VehicleMapper;
 import com.github.pagehelper.PageInfo;
-import org.checkerframework.checker.units.qual.C;
-import org.springframework.beans.BeanUtils;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.sql.Timestamp;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 @Service
 public class ConfigService {
 
-    @Autowired
-    ConfigMapper configMapper;
+    @Resource
+    private ConfigMapper configMapper;
+    @Resource
+    private VehicleMapper vehicleMapper;
+    @Resource
+    private VehicleService vehicleService;
+    @Resource
+    private CameraService cameraService;
+    @Resource
+    private LidarService lidarService;
+    @Resource
+    private OgtService ogtService;
+    @Resource
+    private GpsService gpsService;
 
-    @Autowired
-    VehicleMapper vehicleMapper;
-
-    @Autowired
-    VehicleService vehicleService;
-
-    @Autowired
-    CameraService cameraService;
-
-    @Autowired
-    LidarService lidarService;
-
-    @Autowired
-    OgtService ogtService;
-
-    @Autowired
-    GpsService gpsService;
+    //* -------------------------------- Comment --------------------------------
 
+    /**
+     *  获取车辆配置列表
+     * @param pageParam
+     * @return
+     */
     public PageInfo<ConfigVO> getConfigPageList(ConfigPageParam pageParam) {
         PageUtil.setPageInfo(pageParam);
         pageParam.setCreateUserId(AuthUtil.getCurrentUserId());
-        if(DictConstants.YES.equals(pageParam.getShare())){//公有查询去掉创建人id条件
+
+        // 私有查询需获取当前人 userId
+        if(DictConstants.IS_NOT_SHARED.equals(pageParam.getShare())){
+            pageParam.setCreateUserId(AuthUtil.getCurrentUserId());
+        }
+        // 公有查询不需要当前人 userId
+        if(DictConstants.IS_SHARED.equals(pageParam.getShare())){
             pageParam.setCreateUserId(null);
         }
-        List<ConfigVO> list = configMapper.getConfigPageList(pageParam);
-        //传感器数量
+        List<ConfigVO> list = configMapper.getConfigPageList(pageParam);    // 查询《配置-传感器关系表》
         list.forEach(configVO -> {
-            List<ConfigSensorVO> sensorList = configMapper.getConfigSensors(configVO);
+            List<ConfigSensorVO> sensorList = configMapper.getConfigSensors(configVO);  // 根据配置 id 获取传感器列表
             Map<String, List<ConfigSensorVO>> configSensors = sensorList.stream().collect(Collectors.groupingBy(ConfigSensorVO::getSensorType));
             Map<String,String> sensorCount = new HashMap<>();
             configSensors.forEach((sensorType,configSensorVOs)->{

+ 7 - 11
simulation-resource-server/src/main/resources/mapper/model/ConfigMapper.xml

@@ -22,7 +22,13 @@
             c.share
         from model_config c
         LEFT JOIN model_vehicle v on c.vehicle_id = v.id
-        WHERE c.is_deleted = '0' and c.share = #{share,jdbcType=VARCHAR}
+        WHERE c.is_deleted = '0'
+        <if test="share != null and share != ''">
+            and c.share = #{share,jdbcType=VARCHAR}
+        </if>
+        <if test="createUserId != null and createUserId != ''">
+            and c.create_user_id = #{createUserId,jdbcType=VARCHAR}
+        </if>
         <if test="configCode != null and configCode != ''">
             and c.config_code like CONCAT('%',#{configCode,jdbcType=VARCHAR},'%')
         </if>
@@ -38,12 +44,6 @@
         <if test="vehicleDescription != null and vehicleDescription != ''">
             and v.description like CONCAT('%',#{vehicleDescription,jdbcType=VARCHAR},'%')
         </if>
-        <if test="share != null and share != ''">
-            and c.share = #{share,jdbcType=VARCHAR}
-        </if>
-        <if test="createUserId != null and createUserId != ''">
-            and c.create_user_id = #{createUserId,jdbcType=VARCHAR}
-        </if>
         order by c.create_time desc
     </select>
 
@@ -66,7 +66,6 @@
     </select>
 
     <select id="getConfigSensors" parameterType="api.common.pojo.vo.model.ConfigVO" resultMap="ConfigSensorVOMap">
-        <!--摄像头-->
         SELECT
             r.id,r.config_id,r.sensor_id,
             s.sensor_name, s.description as sensorDescription,
@@ -76,7 +75,6 @@
         INNER JOIN model_sensor_camera s ON r.sensor_id = s.id
         WHERE r.is_deleted = '0' and r.config_id = #{id,jdbcType=VARCHAR}
         UNION
-        <!--完美传感器-->
         SELECT
             r.id,r.config_id,r.sensor_id,
             s.sensor_name, s.description as sensorDescription,
@@ -86,7 +84,6 @@
         INNER JOIN model_sensor_ogt s ON r.sensor_id = s.id
         WHERE r.is_deleted = '0' and r.config_id = #{id,jdbcType=VARCHAR}
         UNION
-        <!--激光雷达-->
         SELECT
             r.id,r.config_id,r.sensor_id,
             s.sensor_name, s.description as sensorDescription,
@@ -96,7 +93,6 @@
         INNER JOIN model_sensor_lidar s ON r.sensor_id = s.id
         WHERE r.is_deleted = '0' and r.config_id = #{id,jdbcType=VARCHAR}
         UNION
-        <!--GPS-->
         SELECT
             r.id,r.config_id,r.sensor_id,
             s.sensor_name, s.description as sensorDescription,