|
@@ -2,23 +2,22 @@ package cn.com.ty.lift.business.library.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.LiftExtension;
|
|
|
import cn.com.ty.lift.business.library.dao.entity.PlatformCompanyLiftRelevance;
|
|
|
import cn.com.ty.lift.business.library.dao.entity.model.LiftExtensionRequest;
|
|
|
import cn.com.ty.lift.business.library.dao.entity.model.LiftRequest;
|
|
|
import cn.com.ty.lift.business.library.dao.entity.model.LiftResponse;
|
|
|
-import cn.com.ty.lift.business.library.dao.mapper.LiftExtensionMapper;
|
|
|
import cn.com.ty.lift.business.library.dao.mapper.LiftMapper;
|
|
|
import cn.com.ty.lift.business.maintenance.dao.entity.MaintenanceCompany;
|
|
|
import cn.com.ty.lift.business.maintenance.service.MaintenanceService;
|
|
|
import cn.com.ty.lift.common.base.ExportRequest;
|
|
|
import cn.com.ty.lift.common.constants.ApiConstants;
|
|
|
+import cn.com.ty.lift.common.constants.CommonEnum;
|
|
|
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 com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -36,9 +35,6 @@ public class LiftService {
|
|
|
@Resource
|
|
|
private LiftMapper liftMapper;
|
|
|
|
|
|
- @Resource
|
|
|
- private LiftExtensionMapper liftExtensionMapper;
|
|
|
-
|
|
|
@Resource
|
|
|
private PlatformCompanyLiftRelevanceService platformService;
|
|
|
|
|
@@ -48,9 +44,6 @@ public class LiftService {
|
|
|
@Resource
|
|
|
private MaintenanceService maintenanceService;
|
|
|
|
|
|
- @Resource
|
|
|
- private RedisTemplate redisTemplate;
|
|
|
-
|
|
|
private Map<String, String> paramMap = new HashMap<String, String>() {{
|
|
|
put("liftCode", "电梯号");
|
|
|
put("registrationCode", "注册代码");
|
|
@@ -91,20 +84,34 @@ public class LiftService {
|
|
|
return liftMapper.selectById(id);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
- * @param request 电梯
|
|
|
- * @return 电梯扩展实体
|
|
|
- * @description 初始化电梯扩展实体
|
|
|
- * @date 2019/12/3 3:25 PM
|
|
|
+ * @param mtCompanyId 公司id
|
|
|
+ * @param code 注册代码
|
|
|
+ * @return RestResponse 判断结果
|
|
|
+ * @description 新增电梯前置判断条件
|
|
|
+ * @date 2019/12/20 2:31 PM
|
|
|
*/
|
|
|
- private LiftExtension init(LiftExtensionRequest request) {
|
|
|
- Long id = request.getLift().getId();
|
|
|
- Date annualInspectionDate = DateUtils.localDate2Date(request.getAnnualInspectionDate());
|
|
|
- LiftExtension extension = new LiftExtension();
|
|
|
- extension.setId(id);
|
|
|
- extension.setAnnualInspectionDate(annualInspectionDate);
|
|
|
- extension.setMtCompanyId(request.getMtCompanyId());
|
|
|
- return extension;
|
|
|
+ public RestResponse preJudgment(Long mtCompanyId, String code) {
|
|
|
+ /*if (judge(mtCompanyId))
|
|
|
+ return RestResponse.error(ApiConstants.RESULT_ERROR, MessageUtils.get("msg.limit.num"));*/
|
|
|
+ //查询电梯表是否有该电梯
|
|
|
+ Long id = findLiftExist(code);
|
|
|
+ if (ObjectUtil.isNotEmpty(id)) {
|
|
|
+ Map<String, Object> paramMap = new HashMap<>(2);
|
|
|
+ paramMap.put("id", id);
|
|
|
+ paramMap.put("mtCompanyId", mtCompanyId);
|
|
|
+ //查询该公司下是否有此电梯
|
|
|
+ boolean result = platformService.findCompanyLiftExist(paramMap);
|
|
|
+ if (result) {
|
|
|
+ return RestResponse.error(ApiConstants.RESULT_ERROR, MessageUtils.get("msg.lift.exist"));
|
|
|
+ } else {
|
|
|
+ Lift detail = detail(id);
|
|
|
+ return RestResponse.ok(detail, ApiConstants.RESULT_SUCCESS, MessageUtils.get("msg.lift.company.exist"));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return RestResponse.ok(null, ApiConstants.RESULT_SUCCESS, MessageUtils.get("msg.pre.judge"));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -114,12 +121,24 @@ public class LiftService {
|
|
|
* @date 2019/12/12 5:27 PM
|
|
|
*/
|
|
|
public boolean judge(Long mtCompanyId) {
|
|
|
+ //查询维保公司设置的最大电梯台量
|
|
|
MaintenanceCompany company = maintenanceService.selectById(mtCompanyId);
|
|
|
Integer limitedNum = company.getLimitedNum();
|
|
|
+ //获取该公司企业电梯关联表的实际电梯台量
|
|
|
Integer currentNum = platformService.countLiftNum(mtCompanyId);
|
|
|
return currentNum >= limitedNum;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param registrationCode 电梯注册代码
|
|
|
+ * @return 电梯id
|
|
|
+ * @description 查询电梯是否存在
|
|
|
+ * @date 2019/12/20 11:04 AM
|
|
|
+ */
|
|
|
+ public Long findLiftExist(String registrationCode) {
|
|
|
+ return liftMapper.findLiftExist(registrationCode);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param request 新增电梯数据项
|
|
|
* @return RestResponse 状态码和返回消息
|
|
@@ -128,45 +147,54 @@ public class LiftService {
|
|
|
*/
|
|
|
@Transactional
|
|
|
public RestResponse add(LiftExtensionRequest request) {
|
|
|
- /*Long mtCompanyId = lift.getMtCompanyId();
|
|
|
- if (judge(mtCompanyId))
|
|
|
- return RestResponse.error(ApiConstants.RESULT_ERROR, MessageUtils.get("msg.limit.num"));*/
|
|
|
- //新增电梯表
|
|
|
+ String mark = request.getMark();
|
|
|
Lift lift = request.getLift();
|
|
|
- //按当前日期时间戳自动生成电梯编号
|
|
|
- String liftCode = DateUtils.generateCode();
|
|
|
- lift.setLiftCode("DT" + liftCode);
|
|
|
- int liftResult = liftMapper.insert(lift);
|
|
|
- if (liftResult == 0) {
|
|
|
- return RestResponse.error(ApiConstants.RESULT_ERROR, MessageUtils.get("msg.add.fail"));
|
|
|
- }
|
|
|
- //初始化电梯扩展实体
|
|
|
- LiftExtension extension = init(request);
|
|
|
- //新增电梯扩展表
|
|
|
- int extensionResult = liftExtensionMapper.insert(extension);
|
|
|
- if (extensionResult == 0) {
|
|
|
- return RestResponse.error(ApiConstants.RESULT_ERROR, MessageUtils.get("msg.add.fail"));
|
|
|
+ if ("0".equals(mark)){
|
|
|
+ //按当前日期时间戳自动生成电梯编号
|
|
|
+ String liftCode = ApiConstants.STRAIGHT_LADDER + DateUtils.generateCode();
|
|
|
+ if (CommonEnum.LiftType.STAIRCASE.getCode().equals(Objects.toString(lift.getLiftType()))) {
|
|
|
+ lift.setLiftCode(ApiConstants.STAIRCASE + liftCode);
|
|
|
+ }
|
|
|
+ //新增电梯表
|
|
|
+ int liftResult = liftMapper.insert(lift);
|
|
|
+ if (liftResult == 0) {
|
|
|
+ return RestResponse.error(ApiConstants.RESULT_ERROR, MessageUtils.get("msg.add.fail"));
|
|
|
+ }
|
|
|
}
|
|
|
+ //电梯id
|
|
|
+ Long id = lift.getId();
|
|
|
+ //公司id
|
|
|
+ Long mtCompanyId = request.getMtCompanyId();
|
|
|
//新增电梯来源
|
|
|
String source = request.getSource();
|
|
|
switch (source) {
|
|
|
//电梯管理入口
|
|
|
case "0":
|
|
|
- //新增平台企业电梯关联表
|
|
|
- PlatformCompanyLiftRelevance ret = platformService.save(extension);
|
|
|
+ //新增企业电梯关联表
|
|
|
+ PlatformCompanyLiftRelevance ret = platformService.save(id, mtCompanyId);
|
|
|
if (ret == null) {
|
|
|
return RestResponse.error(ApiConstants.RESULT_ERROR, MessageUtils.get("msg.add.fail"));
|
|
|
}
|
|
|
+ //新增平台电梯关联表
|
|
|
+ PlatformCompanyLiftRelevance liftRelevance = platformService.save(id, ApiConstants.PLATFORM_COMPANY_ID);
|
|
|
+ if (liftRelevance == null) {
|
|
|
+ return RestResponse.error(ApiConstants.RESULT_ERROR, MessageUtils.get("msg.add.fail"));
|
|
|
+ }
|
|
|
break;
|
|
|
//项目管理入口
|
|
|
case "1":
|
|
|
- //新增平台企业电梯关联表
|
|
|
- PlatformCompanyLiftRelevance companyLiftEntry = platformService.save(extension);
|
|
|
+ //新增企业电梯关联表
|
|
|
+ PlatformCompanyLiftRelevance companyLiftEntry = platformService.save(id, mtCompanyId);
|
|
|
if (companyLiftEntry == null) {
|
|
|
return RestResponse.error(ApiConstants.RESULT_ERROR, MessageUtils.get("msg.add.fail"));
|
|
|
}
|
|
|
+ //新增平台电梯关联表
|
|
|
+ PlatformCompanyLiftRelevance relevance = platformService.save(id, ApiConstants.PLATFORM_COMPANY_ID);
|
|
|
+ if (relevance == null) {
|
|
|
+ return RestResponse.error(ApiConstants.RESULT_ERROR, MessageUtils.get("msg.add.fail"));
|
|
|
+ }
|
|
|
//新增项目电梯关联表
|
|
|
- boolean result = projectRelevanceService.save(extension, companyLiftEntry.getId(), request.getWorkerId());
|
|
|
+ boolean result = projectRelevanceService.save(request, companyLiftEntry.getId(), request.getWorkerId());
|
|
|
if (!result) {
|
|
|
return RestResponse.error(ApiConstants.RESULT_ERROR, MessageUtils.get("msg.add.fail"));
|
|
|
}
|