Ver código fonte

[chg]新增修改电梯增加校验逻辑,原有校验逻辑修改

别傲 5 anos atrás
pai
commit
392361cf6b

+ 4 - 1
lift-business-service/src/main/java/cn/com/ty/lift/business/framework/conf/MetaHandler.java

@@ -68,6 +68,9 @@ public class MetaHandler implements MetaObjectHandler {
                 .getRequest();
         HttpSession session = request.getSession();
         Object userId = session.getAttribute(ApiConstants.CURRENT_USER);
-        return Long.parseLong(Objects.toString(userId));
+        if (ObjectUtil.isNotEmpty(userId)) {
+            return Long.parseLong(Objects.toString(userId));
+        }
+        return null;
     }
 }

+ 8 - 6
lift-business-service/src/main/java/cn/com/ty/lift/business/library/controller/LiftController.java

@@ -10,6 +10,7 @@ import cn.com.ty.lift.business.library.service.ProjectLiftRelevanceService;
 import cn.com.ty.lift.common.base.ExportRequest;
 import cn.com.xwy.boot.web.dto.RestResponse;
 import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.springframework.web.bind.annotation.*;
 
@@ -86,7 +87,12 @@ public class LiftController {
      */
     @PostMapping("preJudgment")
     public RestResponse preJudgment(@RequestBody LiftExtensionRequest request) {
-        return liftService.preJudgment(request.getMtCompanyId(), request.getCode());
+        Lift lift = request.getLift();
+        String liftId = StrUtil.EMPTY;
+        if (ObjectUtil.isNotEmpty(lift.getId())) {
+            liftId = lift.getId().toString();
+        }
+        return liftService.preJudgment(request.getMtCompanyId(), request.getCode(), liftId);
     }
 
     /**
@@ -108,11 +114,7 @@ public class LiftController {
      */
     @PostMapping("modify")
     public RestResponse modify(@RequestBody Lift lift) {
-        Integer result = liftService.modify(lift);
-        if (result > 0) {
-            return RestResponse.success();
-        }
-        return RestResponse.fail(MessageUtils.get("msg.modify.fail"));
+       return liftService.modify(lift);
     }
 
     /**

+ 2 - 1
lift-business-service/src/main/java/cn/com/ty/lift/business/library/dao/mapper/LiftMapper.java

@@ -21,10 +21,11 @@ public interface LiftMapper extends BaseMapper<Lift> {
 
     /**
      * @param registrationCode 电梯注册代码
+     * @param liftId 0:新增电梯,1:修改电梯
      * @return 条数
      * @description 查询电梯是否存在
      * @date 2019/12/20 11:04 AM
      */
-    Long findLiftExist(String registrationCode);
+    Long findLiftExist(@Param("registrationCode") String registrationCode, @Param("liftId") String liftId);
 
 }

+ 31 - 14
lift-business-service/src/main/java/cn/com/ty/lift/business/library/service/LiftService.java

@@ -16,6 +16,7 @@ import cn.com.ty.lift.common.export.ExportUtils;
 import cn.com.ty.lift.common.utils.DateUtils;
 import cn.com.xwy.boot.web.dto.RestResponse;
 import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import org.springframework.stereotype.Service;
@@ -87,17 +88,16 @@ public class LiftService {
 
     /**
      * @param mtCompanyId 公司id
-     * @param code 注册代码
+     * @param code        注册代码
+     * @param liftId      电梯id
      * @return RestResponse 判断结果
-     * @description 新增电梯前置判断条件
+     * @description 新增/修改电梯前置判断条件
      * @date 2019/12/20 2:31 PM
      */
-    public RestResponse preJudgment(Long mtCompanyId, String code) {
-        /*if (judge(mtCompanyId))
-            return RestResponse.fail(ApiConstants.RESULT_ERROR, MessageUtils.get("msg.limit.num"));*/
+    public RestResponse preJudgment(Long mtCompanyId, String code, String liftId) {
         //查询电梯表是否有该电梯
-        Long id = findLiftExist(code);
-        if (ObjectUtil.isNotEmpty(id)) {
+        Long id = findLiftExist(code, liftId);
+        if (ObjectUtil.isNotEmpty(id) && ObjectUtil.isEmpty(liftId)) {
             Map<String, Object> paramMap = new HashMap<>(2);
             paramMap.put("id", id);
             paramMap.put("mtCompanyId", mtCompanyId);
@@ -109,6 +109,8 @@ public class LiftService {
                 Lift detail = detail(id);
                 return RestResponse.success(detail, ApiConstants.RESULT_SUCCESS, MessageUtils.get("msg.lift.company.exist"));
             }
+        } else if (ObjectUtil.isNotEmpty(id) && ObjectUtil.isNotEmpty(liftId)) {
+            return RestResponse.fail(MessageUtils.get("msg.lift.library.exist"));
         } else {
             return RestResponse.success(null, ApiConstants.RESULT_SUCCESS, MessageUtils.get("msg.pre.judge"));
         }
@@ -131,12 +133,13 @@ public class LiftService {
 
     /**
      * @param registrationCode 电梯注册代码
+     * @param liftId 电梯id
      * @return 电梯id
      * @description 查询电梯是否存在
      * @date 2019/12/20 11:04 AM
      */
-    public Long findLiftExist(String registrationCode) {
-        return liftMapper.findLiftExist(registrationCode);
+    public Long findLiftExist(String registrationCode, String liftId) {
+        return liftMapper.findLiftExist(registrationCode, liftId);
     }
 
     /**
@@ -150,7 +153,13 @@ public class LiftService {
         //获取新增标记 (0:新增,1:查询后带入)
         String mark = request.getMark();
         Lift lift = request.getLift();
-        if ("0".equals(mark)){
+        //公司id
+        Long mtCompanyId = request.getMtCompanyId();
+        /*if (judge(mtCompanyId))
+        return RestResponse.fail(ApiConstants.RESULT_ERROR, MessageUtils.get("msg.limit.num"));*/
+        RestResponse response = preJudgment(mtCompanyId, lift.getRegistrationCode(), null);
+        if (ObjectUtil.isNotEmpty(response.getData())) return response;
+        if ("0".equals(mark)) {
             //按当前日期时间戳自动生成电梯编号
             String liftCode = ApiConstants.STRAIGHT_LADDER + DateUtils.generateCode();
             if (CommonEnum.LiftType.STAIRCASE.getCode().equals(Objects.toString(lift.getLiftType()))) {
@@ -164,8 +173,6 @@ public class LiftService {
         }
         //电梯id
         Long id = lift.getId();
-        //公司id
-        Long mtCompanyId = request.getMtCompanyId();
         //新增电梯来源
         String source = request.getSource();
         switch (source) {
@@ -212,8 +219,18 @@ public class LiftService {
      * @description 修改电梯
      * @date 2019/11/27 2:22 PM
      */
-    public Integer modify(Lift lift) {
-        return liftMapper.updateById(lift);
+    public RestResponse modify(Lift lift) {
+        String liftId = StrUtil.EMPTY;
+        if (ObjectUtil.isNotEmpty(lift.getId())) {
+            liftId = lift.getId().toString();
+        }
+        RestResponse response = preJudgment(null, lift.getRegistrationCode(), liftId);
+        if (ObjectUtil.isNotEmpty(response.getData())) return response;
+        int result = liftMapper.updateById(lift);
+        if (result > 0) {
+            return RestResponse.success();
+        }
+        return RestResponse.fail(MessageUtils.get("msg.modify.fail"));
     }
 
     /**

+ 1 - 0
lift-business-service/src/main/resources/locale/response.properties

@@ -9,6 +9,7 @@ msg.modify.batch.success=\u6279\u91CF\u4FEE\u6539\u6210\u529F
 msg.modify.batch.fail=\u6279\u91CF\u4FEE\u6539\u5931\u8D25
 msg.limit.num=\u5F53\u524D\u7535\u68AF\u53F0\u91CF\u5927\u4E8E\u4F01\u4E1A\u8BBE\u7F6E\u7535\u68AF\u53F0\u91CF
 msg.param.empty=\u53C2\u6570\u4E0D\u80FD\u4E3A\u7A7A
+msg.lift.library.exist=\u7535\u68AF\u5E93\u5DF2\u5B58\u5728\u8BE5\u7535\u68AF
 msg.lift.exist=\u516C\u53F8\u4E0B\u5DF2\u6709\u6B64\u7535\u68AF\uFF0C\u4E0D\u80FD\u91CD\u590D\u6DFB\u52A0
 msg.lift.company.exist=\u5176\u4ED6\u516C\u53F8\u5DF2\u6709\u6B64\u7535\u68AF\uFF0C\u8FD4\u56DE\u7535\u68AF\u4FE1\u606F
 msg.pre.judge=\u524D\u7F6E\u6821\u9A8C\u901A\u8FC7

+ 10 - 2
lift-business-service/src/main/resources/mapper/lift/LiftMapper.xml

@@ -71,7 +71,7 @@
 		l.device_position        AS devicePosition,
 		lb.name                  AS liftBrand,
 		pclr.lift_company_status AS liftStatus,
-		le.first_time            AS firstMaintenanceTime,
+		plr.first_time           AS firstMaintenanceTime,
 		p.project_name           AS projectName
         FROM platform_company_lift_relevance pclr
         LEFT JOIN lift l ON pclr.lift_id = l.id
@@ -123,7 +123,15 @@
 
 	<!--根据注册代码查询电梯是否存在,返回电梯id -->
 	<select id="findLiftExist" parameterType="java.lang.String" resultType="java.lang.Long">
-		SELECT id FROM lift WHERE registration_code = #{registrationCode,jdbcType=VARCHAR}
+		SELECT id FROM lift
+		WHERE 1=1
+		<if test="liftId ==null ">
+			AND registration_code = #{registrationCode,jdbcType=VARCHAR}
+		</if>
+		<if test="liftId!=null and liftId!=''">
+			AND registration_code = #{registrationCode,jdbcType=VARCHAR}
+			AND id != #{liftId,jdbcType=VARCHAR}
+		</if>
 	</select>
 
 </mapper>