Browse Source

修改group_code和project_id必须在url路径上传

yanguofeng 2 years ago
parent
commit
132150a523

+ 9 - 1
adm-business/adm-server/src/main/java/com/persagy/adm/server/custom/controller/AdmFileController.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.persagy.adm.server.custom.entity.CadFileQueryParam;
 import com.persagy.adm.server.custom.entity.db.AdmCad;
 import com.persagy.adm.server.custom.service.IAdmCadService;
+import com.persagy.dmp.common.context.AppContext;
 import com.persagy.dmp.common.model.response.CommonResult;
 import com.persagy.dmp.common.utils.ResultHelper;
 import org.apache.commons.lang.StringUtils;
@@ -32,8 +33,10 @@ public class AdmFileController {
 
     @PostMapping("/queryCadFiles")
     public CommonResult<List<AdmCad>> queryCadFiles(@RequestBody CadFileQueryParam queryParam){
+        AppContext context = AppContext.getContext();
         Wrapper<AdmCad> eq = new LambdaQueryWrapper<AdmCad>()
-                .eq(StringUtils.isNotBlank(queryParam.getProjectId()), AdmCad::getProjectId, queryParam.getProjectId())
+                .eq(StringUtils.isNotBlank(context.getGroupCode()), AdmCad::getGroupCode, context.getProjectId())
+                .eq(StringUtils.isNotBlank(context.getProjectId()), AdmCad::getProjectId, context.getProjectId())
                 .eq(StringUtils.isNotBlank(queryParam.getBuildingId()),AdmCad::getBuildingId,queryParam.getBuildingId())
                 .eq(StringUtils.isNotBlank(queryParam.getFloorId()),AdmCad::getFloorId,queryParam.getFloorId())
                 .eq(StringUtils.isNotBlank(queryParam.getFileKey()),AdmCad::getFileKey,queryParam.getFileKey())
@@ -46,6 +49,11 @@ public class AdmFileController {
      */
     @PostMapping("/saveCadFileInfo")
     public CommonResult<Void> saveCadFileInfo(@RequestBody List<AdmCad> admFiles){
+        AppContext context = AppContext.getContext();
+        admFiles.forEach(admCad -> {
+            admCad.setGroupCode(context.getGroupCode());
+            admCad.setProjectId(context.getProjectId());
+        });
         iAdmCadService.saveOrUpdateBatch(admFiles);
         return ResultHelper.success();
     }

+ 0 - 4
adm-business/adm-server/src/main/java/com/persagy/adm/server/custom/entity/CadFileQueryParam.java

@@ -8,10 +8,6 @@ import lombok.Data;
 @Data
 public class CadFileQueryParam {
     /**
-     * 项目ID
-     */
-    private String projectId;
-    /**
      * 建筑ID
      */
     private String buildingId;

+ 6 - 0
adm-business/adm-server/src/main/java/com/persagy/adm/server/custom/entity/db/AdmCad.java

@@ -69,6 +69,12 @@ public class AdmCad extends AuditableEntity<AdmCad> implements Serializable {
     private String projectId;
 
     /**
+     * 集团编码
+     */
+    @TableField("group_code")
+    private String groupCode;
+
+    /**
      * 乐观锁时间戳
      */
     @TableField("ts")

+ 16 - 0
adm-business/adm-server/src/main/java/com/persagy/adm/server/custom/interceptor/AppContextConfig.java

@@ -0,0 +1,16 @@
+package com.persagy.adm.server.custom.interceptor;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+@Configuration
+public class AppContextConfig implements WebMvcConfigurer {
+
+    @Override
+    public void addInterceptors(InterceptorRegistry registry) {
+        InterceptorRegistration registration = registry.addInterceptor(new AppContextInterceptor());
+        registration.addPathPatterns("/adm/adm-file/**");
+    }
+}

+ 23 - 0
adm-business/adm-server/src/main/java/com/persagy/adm/server/custom/interceptor/AppContextInterceptor.java

@@ -0,0 +1,23 @@
+package com.persagy.adm.server.custom.interceptor;
+
+import com.persagy.dmp.common.constant.ResponseCode;
+import com.persagy.dmp.common.context.AppContext;
+import com.persagy.dmp.common.exception.BusinessException;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.stereotype.Component;
+import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+@Component
+public class AppContextInterceptor extends HandlerInterceptorAdapter {
+
+    @Override
+    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+        if(StringUtils.isBlank(AppContext.getContext().getGroupCode()) || StringUtils.isBlank(AppContext.getContext().getProjectId())){
+            throw new BusinessException(ResponseCode.A0402.getCode(),ResponseCode.A0402.getDesc());
+        }
+        return true;
+    }
+}

+ 1 - 0
adm-business/adm-server/src/main/resources/db/init/schema.sql

@@ -8,6 +8,7 @@ CREATE TABLE IF NOT EXISTS `adm_cad`  (
   `floor_id` varchar(255) NOT NULL COMMENT '楼层ID',
   `building_id` varchar(255) NOT NULL COMMENT '建筑ID',
   `project_id` varchar(255) NOT NULL COMMENT '项目ID',
+  `group_code` varchar(255) NOT NULL COMMENT '集团编码',
   `creator` varchar(32) NULL DEFAULT NULL COMMENT '创建人',
   `creation_time` char(14) NULL DEFAULT NULL COMMENT '创建时间',
   `modifier` varchar(32) NULL DEFAULT NULL COMMENT '最后修改人',