Selaa lähdekoodia

批量移动电梯接口

别傲 5 vuotta sitten
vanhempi
commit
d876ed5c25

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

@@ -82,19 +82,34 @@ public class LiftController {
         return RestResponse.success(page, MessageUtils.get("msg.query.success"));
     }
 
+    /**
+     * @param request 项目id,项目电梯关联id列表
+     * @return 1.成功, 0.失败, 消息描述
+     * @description 批量移动电梯
+     * @date 2020/1/7 7:57 下午
+     */
+    @PostMapping("batch/move")
+    public RestResponse move(@Valid @RequestBody LiftBatchMoveRequest request){
+        boolean result = projectLiftRelevanceService.move(request);
+        if (!result) {
+            return RestResponse.fail(MessageUtils.get("msg.modify.batch.fail"));
+        }
+        return RestResponse.success(null, MessageUtils.get("msg.modify.batch.success"));
+    }
+
     /**
      * @param request 项目电梯关联列表请求
      * @return 1.成功, 0.失败, 消息描述
      * @description 批量插入项目电梯关联数据
      * @date 2020/1/2 2:59 下午
      */
-    @PostMapping("insertBatch")
+    @PostMapping("batch/insert")
     public RestResponse insertBatch(@Valid @RequestBody ProjectLiftBatchRequest request) {
         boolean result = projectLiftRelevanceService.insertBatch(request.getList());
         if (!result) {
-            return RestResponse.fail(MessageUtils.get("msg.batch.fail"));
+            return RestResponse.fail(MessageUtils.get("msg.add.batch.fail"));
         }
-        return RestResponse.success(null, MessageUtils.get("msg.batch.success"));
+        return RestResponse.success(null, MessageUtils.get("msg.add.batch.success"));
     }
 
     /**

+ 28 - 0
lift-business-service/src/main/java/cn/com/ty/lift/business/library/dao/entity/model/request/LiftBatchMoveRequest.java

@@ -0,0 +1,28 @@
+package cn.com.ty.lift.business.library.dao.entity.model.request;
+
+import cn.com.ty.lift.business.project.dao.entity.ProjectLiftRelevance;
+import lombok.Data;
+
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+import java.util.List;
+
+/**
+ * @author bieao
+ * @date 2020/1/7
+ * @description 批量移动电梯请求
+ */
+@Data
+public class LiftBatchMoveRequest {
+    /**
+     * 项目电梯关联id列表
+     */
+    @NotEmpty(message = "notEmpty")
+    private List<ProjectLiftRelevance> list;
+
+    /**
+     * 项目id
+     */
+    @NotNull(message = "notEmpty")
+    private Long projectId;
+}

+ 7 - 2
lift-business-service/src/main/java/cn/com/ty/lift/business/library/dao/entity/model/response/LiftResponse.java

@@ -16,9 +16,14 @@ public class LiftResponse {
     private String id;
 
     /**
-     * 关联id
+     * 公司电梯关联主键id
      */
-    private String relevanceId;
+    private String companyRelevanceId;
+
+    /**
+     * 项目电梯关联主键id
+     */
+    private String projectRelevanceId;
 
     /**
      * 项目id

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

@@ -25,14 +25,6 @@ public interface LiftMapper extends BaseMapper<Lift> {
 
     IPage<LiftResponse> findLiftListByProjectId(IPage<LiftResponse> page, @Param("request") ProjectLiftRequest request);
 
-    /**
-     * @param registrationCode 电梯注册代码
-     * @return 电梯id
-     * @description 查询电梯是否存在
-     * @date 2019/12/20 11:04 AM
-     */
-    Long findLiftExist(@Param("registrationCode") String registrationCode);
-
     List<LiftProjectModel> listByCompanyAndProject(@Param("mtCompanyId") Long mtCompanyId, @Param("projectId") Long projectId);
 
     IPage<LiftResponse> chooseLiftList(IPage<LiftResponse> page, @Param("request") LiftChooseRequest request);

+ 0 - 6
lift-business-service/src/main/java/cn/com/ty/lift/business/library/dao/mapper/PlatformCompanyLiftRelevanceMapper.java

@@ -2,9 +2,6 @@ package cn.com.ty.lift.business.library.dao.mapper;
 
 import cn.com.ty.lift.business.library.dao.entity.PlatformCompanyLiftRelevance;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import org.apache.ibatis.annotations.Param;
-
-import java.util.Map;
 
 /**
  * @author bieao
@@ -13,7 +10,4 @@ import java.util.Map;
  */
 public interface PlatformCompanyLiftRelevanceMapper extends BaseMapper<PlatformCompanyLiftRelevance> {
 
-    Integer count(@Param("id") Long id);
-
-    Integer findCompanyLiftExist(@Param("paramMap") Map<String,Object> paramMap);
 }

+ 11 - 5
lift-business-service/src/main/java/cn/com/ty/lift/business/library/service/LiftService.java

@@ -22,6 +22,8 @@ import cn.com.xwy.boot.web.dto.RestResponse;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -117,17 +119,17 @@ public class LiftService extends ServiceImpl<LiftMapper,Lift> {
      */
     public RestResponse preJudgment(Long mtCompanyId, String registrationCode) {
         //查询电梯表是否有该电梯
-        Long id = findLiftExist(registrationCode);
-        if (ObjectUtil.isNotEmpty(id)) {
+        Long liftId = findLiftExist(registrationCode);
+        if (ObjectUtil.isNotEmpty(liftId)) {
             Map<String, Object> paramMap = new HashMap<>(2);
-            paramMap.put("id", id);
+            paramMap.put("liftId", liftId);
             paramMap.put("mtCompanyId", mtCompanyId);
             //查询该公司下是否有此电梯
             boolean result = platformService.findCompanyLiftExist(paramMap);
             if (result) {
                 return RestResponse.fail(MessageUtils.get("msg.lift.exist"));
             } else {
-                LiftExtendResponse detail = detail(id);
+                LiftExtendResponse detail = detail(liftId);
                 return RestResponse.success(detail, MessageUtils.get("msg.lift.company.exist"));
             }
         }  else {
@@ -157,7 +159,11 @@ public class LiftService extends ServiceImpl<LiftMapper,Lift> {
      * @date 2019/12/20 11:04 AM
      */
     public Long findLiftExist(String registrationCode) {
-        return liftMapper.findLiftExist(registrationCode);
+        QueryWrapper<Lift> queryWrapper = new QueryWrapper<>();
+        LambdaQueryWrapper<Lift> lambdaQueryWrapper = queryWrapper.lambda();
+        lambdaQueryWrapper.eq(Lift::getRegistrationCode, registrationCode);
+        Lift lift = getOne(lambdaQueryWrapper);
+        return Optional.ofNullable(lift).map(Lift::getId).orElse(null);
     }
 
     /**

+ 15 - 11
lift-business-service/src/main/java/cn/com/ty/lift/business/library/service/PlatformCompanyLiftRelevanceService.java

@@ -54,30 +54,34 @@ public class PlatformCompanyLiftRelevanceService extends ServiceImpl<PlatformCom
         PlatformCompanyLiftRelevance companyLiftEntry = new PlatformCompanyLiftRelevance();
         companyLiftEntry.setLiftId(id);
         companyLiftEntry.setMtCompanyId(mtCompanyId);
-        if (save(companyLiftEntry)) {
-            return companyLiftEntry;
-        }
-        return null;
+        return save(companyLiftEntry) ? companyLiftEntry : null;
     }
 
     /**
      * @param paramMap 电梯id,公司id
      * @return 是否存在
-     * @description 查询该公司下是否有此电梯
+     * @description 根据电梯id和公司id查询该公司是否关联过此电梯
      * @date 2019/12/20 11:39 AM
      */
     public boolean findCompanyLiftExist(Map<String, Object> paramMap) {
-        return mapper.findCompanyLiftExist(paramMap) > 0;
+        QueryWrapper<PlatformCompanyLiftRelevance> queryWrapper = new QueryWrapper<>();
+        LambdaQueryWrapper<PlatformCompanyLiftRelevance> lambdaQueryWrapper = queryWrapper.lambda();
+        lambdaQueryWrapper.eq(PlatformCompanyLiftRelevance::getMtCompanyId, paramMap.get("mtCompanyId"));
+        lambdaQueryWrapper.eq(PlatformCompanyLiftRelevance::getLiftId, paramMap.get("liftId"));
+        return count(lambdaQueryWrapper) > 0;
     }
 
     /**
-     * @param id 公司ID
-     * @return 可用电梯台量
-     * @description 查询维保公司下的最多可用电梯台量
+     * @param mtCompanyId 公司ID
+     * @return 当前电梯台量
+     * @description 查询维保公司下的实际电梯台量
      * @date 2019/12/12 5:16 PM
      */
-    public Integer countLiftNum(Long id) {
-        return mapper.count(id);
+    public Integer countLiftNum(Long mtCompanyId) {
+        QueryWrapper<PlatformCompanyLiftRelevance> queryWrapper = new QueryWrapper<>();
+        LambdaQueryWrapper<PlatformCompanyLiftRelevance> lambdaQueryWrapper = queryWrapper.lambda();
+        lambdaQueryWrapper.eq(PlatformCompanyLiftRelevance::getMtCompanyId, mtCompanyId);
+        return count(lambdaQueryWrapper);
     }
 
     /**

+ 15 - 3
lift-business-service/src/main/java/cn/com/ty/lift/business/project/service/ProjectLiftRelevanceService.java

@@ -2,6 +2,7 @@ package cn.com.ty.lift.business.project.service;
 
 import cn.com.ty.lift.business.framework.util.MessageUtils;
 import cn.com.ty.lift.business.library.dao.entity.Lift;
+import cn.com.ty.lift.business.library.dao.entity.model.request.LiftBatchMoveRequest;
 import cn.com.ty.lift.business.library.dao.entity.model.request.LiftLockRequest;
 import cn.com.ty.lift.business.library.dao.entity.model.request.LiftExtensionRequest;
 import cn.com.ty.lift.business.project.dao.entity.Project;
@@ -11,7 +12,6 @@ import cn.com.ty.lift.business.project.dao.entity.model.request.ProjectLockReque
 import cn.com.ty.lift.business.project.dao.entity.model.response.ProjectRelevanceResponse;
 import cn.com.ty.lift.business.project.dao.mapper.ProjectLiftRelevanceMapper;
 import cn.com.ty.lift.business.project.dao.mapper.ProjectMapper;
-import cn.com.ty.lift.common.constants.ApiConstants;
 import cn.com.xwy.boot.web.dto.RestResponse;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjectUtil;
@@ -48,7 +48,7 @@ public class ProjectLiftRelevanceService extends ServiceImpl<ProjectLiftRelevanc
         if (!result) {
             return RestResponse.fail(MessageUtils.get("msg.modify.fail"));
         }
-        return RestResponse.success(null, ApiConstants.RESULT_SUCCESS, MessageUtils.get("msg.modify.success"));
+        return RestResponse.success(null, MessageUtils.get("msg.modify.success"));
     }
 
     /**
@@ -81,6 +81,18 @@ public class ProjectLiftRelevanceService extends ServiceImpl<ProjectLiftRelevanc
         return saveBatch(list, list.size());
     }
 
+    /**
+     * @param request 项目id,项目电梯关联id列表
+     * @return 1.成功, 0.失败, 消息描述
+     * @description 批量移动电梯
+     * @date 2020/1/7 7:57 下午
+     */
+    public boolean move(LiftBatchMoveRequest request){
+        List<ProjectLiftRelevance> list = request.getList();
+        list.forEach(entry -> entry.setProjectId(request.getProjectId()));
+        return updateBatchById(list, list.size());
+    }
+
 
     /**
      * @param mtCompanyId 公司id
@@ -113,7 +125,7 @@ public class ProjectLiftRelevanceService extends ServiceImpl<ProjectLiftRelevanc
         if (!result) {
             return RestResponse.fail(MessageUtils.get("msg.modify.fail"));
         }
-        return RestResponse.success(null, ApiConstants.RESULT_SUCCESS, MessageUtils.get("msg.modify.success"));
+        return RestResponse.success(null, MessageUtils.get("msg.modify.success"));
     }
 
     /**

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

@@ -5,8 +5,8 @@ msg.add.success=\u65B0\u589E\u6210\u529F
 msg.add.fail=\u65B0\u589E\u5931\u8D25
 msg.modify.success=\u4FEE\u6539\u6210\u529F
 msg.modify.fail=\u4FEE\u6539\u5931\u8D25
-msg.batch.success=\u6279\u91CF\u65B0\u589E\u6210\u529F
-msg.batch.fail=\u6279\u91CF\u65B0\u589E\u5931\u8D25
+msg.add.batch.success=\u6279\u91CF\u65B0\u589E\u6210\u529F
+msg.add.batch.fail=\u6279\u91CF\u65B0\u589E\u5931\u8D25
 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

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

@@ -112,8 +112,9 @@
           l.device_position         AS devicePosition,
           lb.name                   AS liftBrand,
           l.annual_inspection_date  AS annualInspectionDate,
-		  pclr.id                   AS relevanceId,
+		  pclr.id                   AS companyRelevanceId,
           pclr.lift_company_status  AS liftStatus,
+		  plr.id                    AS projectRelevanceId,
           plr.project_id            AS projectId,
           plr.worker_id             AS workerId,
 		  plr.lift_locked           AS liftLocked,
@@ -152,19 +153,12 @@
 		LEFT JOIN platform_company_lift_relevance pclr ON plr.lift_id = pclr.lift_id AND pclr.id = plr.relevance_id
 		WHERE 1=1
 		AND pclr.lift_company_status != '1'
-		AND l.lift_status = '2'
         AND plr.delete_flag = '0'
 		<if test="request.mtCompanyId!=null and request.mtCompanyId!=''">
 			AND plr.mt_company_id != #{request.mtCompanyId,jdbcType=BIGINT}
 		</if>
 	</select>
 
-	<!--根据注册代码查询电梯是否存在,返回电梯id -->
-	<select id="findLiftExist" parameterType="java.lang.String" resultType="java.lang.Long">
-		SELECT id FROM lift
-		WHERE registration_code = #{registrationCode,jdbcType=VARCHAR}
-	</select>
-
 	<!--根据公司和项目查询电梯 -->
 	<select id="listByCompanyAndProject" resultType="cn.com.ty.lift.business.library.dao.entity.model.LiftProjectModel">
 		SELECT

+ 0 - 12
lift-business-service/src/main/resources/mapper/lift/PlatformCompanyLiftRelevanceMapper.xml

@@ -7,16 +7,4 @@
 		<result column="mt_company_id" property="mtCompanyId" jdbcType="BIGINT" />
 		<result column="lift_company_status" property="liftCompanyStatus" jdbcType="TINYINT" />
 	</resultMap>
-
-	<select id="count" resultType="java.lang.Long">
-		SELECT count(1) FROM platform_company_lift_relevance
-		WHERE id = #{id,jdbcType=BIGINT}
-	</select>
-
-	<!--根据电梯id和公司id查询该公司是否关联过此电梯 -->
-	<select id="findCompanyLiftExist" parameterType="map" resultType="java.lang.Integer">
-		SELECT count(1) FROM platform_company_lift_relevance
-		WHERE lift_id = #{paramMap.id,jdbcType=BIGINT}
-		AND mt_company_id = #{paramMap.mtCompanyId,jdbcType=BIGINT}
-	</select>
 </mapper>