Browse Source

换表管理

lin 4 years ago
parent
commit
541680059f

+ 2 - 0
smart-city-platform/src/main/java/com/bz/smart_city/commom/model/ResultStatus.java

@@ -36,6 +36,8 @@ public enum ResultStatus {
     BUILDING_IS_NOT_EXISTED(-310,"建筑不存在,请先录入建筑信息"),
     NUMBER_IS_OUT_RANGE(-311,"安装数量大于5000"),
     DEVICE_TYPE_NOT_EXISTED(-312,"设备类型不存在,请先录入设备类型"),
+    DEVICE_NO_NOT_EXISTED(-313,"设备编号已经存在"),
+    DEVICE_ELECTRONIC_NO_NOT_EXISTED(-314,"水表电子号已经存在"),
     CREATE_ORDER_NO_DEVICE1(-501,"创建工单失败,无法获取设备编号"),
     CREATE_ORDER_NO_DEVICE2(-502,"创建工单失败,无法获取设备"),
     CREATE_ORDER_NO_ALARMTYPE(-503,"创建工单失败,无对应告警类型"),

+ 17 - 1
smart-city-platform/src/main/java/com/bz/smart_city/controller/assistant/MobileController.java

@@ -5,6 +5,7 @@ import java.util.List;
 
 import com.bz.smart_city.commom.util.AssistantUserUtil;
 import com.bz.smart_city.dto.FloorDto;
+import com.bz.smart_city.dto.WaterMeterReplaceInputDto;
 import com.bz.smart_city.dto.assistant.*;
 import com.bz.smart_city.entity.DeviceAlarmLevel;
 import com.bz.smart_city.entity.OperationLog;
@@ -175,8 +176,10 @@ public class MobileController {
 		List<Integer> list = installManagerService.queryFloorList(buildingId);
 		return new AjaxMessage<>(ResultStatus.OK, list);
 	}
+
+	@Deprecated
 	@PostMapping("/replace/v2")
-	@ApiOperation(value = "调试换表接口(新)")
+	@ApiOperation(value = "调试换表接口(v2)")
 	public AjaxMessage replaceWaterMeter(
 			@ApiParam(value = "设备主键", required = true) @RequestParam(required = true) Long deviceId,
 			@ApiParam(value = "新表水表类型", required = false) @RequestParam(required = false) Integer deviceTypeId,
@@ -210,6 +213,19 @@ public class MobileController {
 		return new AjaxMessage<>(ResultStatus.OK);
 	}
 
+	@PostMapping("/replace/v3")
+	@ApiOperation(value = "调试换表接口(新)")
+	public AjaxMessage replaceWaterMeterV3(
+			@ApiParam(value = "表单处理结果", required = true) @RequestBody(required = true) WaterMeterReplaceInputDto waterMeterReplaceInputDto
+	){
+		LoginAssistantUser loginAssistantUser = AssistantUserUtil.getCurrentUser();
+		boolean isOk =  installManagerService.replaceWaterMeterV3(waterMeterReplaceInputDto);
+		if(log.isDebugEnabled()) {
+			log.debug("installManagerService replaceWaterMeter result = {}", isOk);
+		}
+		return new AjaxMessage<>(ResultStatus.OK);
+	}
+
 	@DeleteMapping("/delete")
 	@ApiOperation(value = "安装删除接口")
 	public AjaxMessage singleInstallDelete(

+ 6 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/assistant/InstallManagerService.java

@@ -2,6 +2,7 @@ package com.bz.smart_city.service.assistant;
 
 import java.util.List;
 
+import com.bz.smart_city.dto.WaterMeterReplaceInputDto;
 import org.springframework.web.multipart.MultipartFile;
 
 import com.bz.smart_city.commom.model.Pagination;
@@ -74,6 +75,9 @@ public interface InstallManagerService {
 	 * @return
 	 */
 	boolean replaceWaterMeter(InstallListDTO dto);
+
+
+	boolean replaceWaterMeterV3(WaterMeterReplaceInputDto waterMeterReplaceInputDto);
 	/**
 	  * 获取水表类型
 	 * @param parentId 1,远传表 2 智能表 9 流量计
@@ -94,4 +98,6 @@ public interface InstallManagerService {
 	Integer checkDevice(String deviceNo, String waterMeterNo);
 
 	List<Integer> queryFloorList(Integer buildingId);
+
+
 }

+ 17 - 1
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/WaterMeterMaintenanceLogServiceImpl.java

@@ -2,6 +2,7 @@ package com.bz.smart_city.service.impl;
 
 import com.alibaba.fastjson.JSON;
 import com.bz.smart_city.commom.exception.ServiceException;
+import com.bz.smart_city.commom.model.ResultStatus;
 import com.bz.smart_city.commom.util.UserUtil;
 import com.bz.smart_city.dao.*;
 import com.bz.smart_city.dao.assistant.InstallListMapper;
@@ -94,6 +95,19 @@ public class WaterMeterMaintenanceLogServiceImpl implements WaterMeterMaintenanc
         WorkOrder workOrder = workOrderMapper.findbyOrderNo(waterMeterMaintenanceLog.getOrdeNo());
         DeviceErrorDto deviceErrorDto = deviceErrorMapper.getDetail(Long.valueOf(workOrder.getReleationId()));
         Device device = deviceMapper.findByDeviceId(deviceErrorDto.getDeviceId());
+
+        //判断设备编号和电子号是否已经存在
+        int resultDeviceNo = deviceMapper.findByDeviceNoUnique(device.getId(), waterMeterMaintenanceLog.getNewDeviceNo());
+        if (resultDeviceNo > 0) {
+            throw new ServiceException(ResultStatus.DEVICE_NO_NOT_EXISTED);
+        }
+        if (waterMeterMaintenanceLog.getNewWaterNo() != null && !StringUtils.equals("",waterMeterMaintenanceLog.getNewWaterNo())) {
+            int resultWaterMeterNo = deviceMapper.findByWaterMeterNoUnique(device.getId(), waterMeterMaintenanceLog.getNewWaterNo());
+            if (resultWaterMeterNo > 0) {
+                throw new ServiceException(ResultStatus.DEVICE_ELECTRONIC_NO_NOT_EXISTED);
+            }
+        }
+
         if (!StringUtils.equals(workOrder.getOrderStatus(), "3")) {
             //1、添加维修记录
             waterMeterMaintenanceLog.setAlarmId(deviceErrorDto.getId());
@@ -120,13 +134,15 @@ public class WaterMeterMaintenanceLogServiceImpl implements WaterMeterMaintenanc
                 waterMeterMaintenanceImagesMapper.insertList(imagesList);
             }
 
+            Integer deviceTypeId = waterMeterMaintenanceLog.getNewDeviceTypeId()!=null?waterMeterMaintenanceLog.getNewDeviceTypeId():device.getDeviceType();
+
             //3、根据解决方案添加相关的记录(1 更换模块,2 更换整表)
             WaterMeterReplaceLog waterMeterReplaceLog = new WaterMeterReplaceLog();
             waterMeterReplaceLog.setMainLogId(waterMeterMaintenanceLog.getId());
             waterMeterReplaceLog.setSiteId(loginUser.getSiteId());
             waterMeterReplaceLog.setDeviceId(waterMeterMaintenanceLog.getDeviceId());
             waterMeterReplaceLog.setReplaceMethod(waterMeterMaintenanceLog.getSolutionMethod());
-            waterMeterReplaceLog.setNewDeviceTypeId(waterMeterMaintenanceLog.getNewDeviceTypeId());
+            waterMeterReplaceLog.setNewDeviceTypeId(deviceTypeId);
             waterMeterReplaceLog.setOldDeviceTypeId(device.getDeviceType());
             waterMeterReplaceLog.setNewWaterNo(waterMeterMaintenanceLog.getNewWaterNo());
             waterMeterReplaceLog.setOldWaterNo(device.getWaterMeterNo());

+ 17 - 1
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/WaterMeterReplaceLogServiceImpl.java

@@ -3,6 +3,7 @@ package com.bz.smart_city.service.impl;
 import com.alibaba.fastjson.JSON;
 import com.bz.smart_city.commom.exception.ServiceException;
 import com.bz.smart_city.commom.model.Pagination;
+import com.bz.smart_city.commom.model.ResultStatus;
 import com.bz.smart_city.commom.util.ExcelUtil;
 import com.bz.smart_city.commom.util.UserUtil;
 import com.bz.smart_city.dao.DeviceMapper;
@@ -13,6 +14,7 @@ import com.bz.smart_city.service.BuildingService;
 import com.bz.smart_city.service.udip.UdipUnitService;
 import com.github.pagehelper.PageHelper;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import javax.annotation.Resource;
@@ -131,6 +133,20 @@ public class WaterMeterReplaceLogServiceImpl implements WaterMeterReplaceLogServ
         LoginUser loginUser = UserUtil.getCurrentUser();
         Device device = deviceMapper.findByDeviceId(waterMeterReplaceInputDto.getDeviceId());
 
+        //判断设备编号和电子号是否已经存在
+        int resultDeviceNo = deviceMapper.findByDeviceNoUnique(waterMeterReplaceInputDto.getDeviceId(), waterMeterReplaceInputDto.getNewDeviceNo());
+        if (resultDeviceNo > 0) {
+            throw new ServiceException(ResultStatus.DEVICE_NO_NOT_EXISTED);
+        }
+
+        if (waterMeterReplaceInputDto.getNewElectronicNo() != null && !StringUtils.equals("",waterMeterReplaceInputDto.getNewElectronicNo())) {
+            int resultWaterMeterNo = deviceMapper.findByWaterMeterNoUnique(waterMeterReplaceInputDto.getDeviceId(), waterMeterReplaceInputDto.getNewElectronicNo());
+            if (resultWaterMeterNo > 0) {
+                throw new ServiceException(ResultStatus.DEVICE_ELECTRONIC_NO_NOT_EXISTED);
+            }
+        }
+
+        Integer deviceTypeId = waterMeterReplaceInputDto.getNewDeviceTypeId()!=null?waterMeterReplaceInputDto.getNewDeviceTypeId():device.getDeviceType();
 
         //1、换表记录
         WaterMeterReplaceLog waterMeterReplaceLog = new WaterMeterReplaceLog();
@@ -138,7 +154,7 @@ public class WaterMeterReplaceLogServiceImpl implements WaterMeterReplaceLogServ
         waterMeterReplaceLog.setSiteId(loginUser.getSiteId());
         waterMeterReplaceLog.setDeviceId(waterMeterReplaceInputDto.getDeviceId());
         waterMeterReplaceLog.setReplaceMethod(waterMeterReplaceInputDto.getReplaceMethod());
-        waterMeterReplaceLog.setNewDeviceTypeId(waterMeterReplaceInputDto.getNewDeviceTypeId());
+        waterMeterReplaceLog.setNewDeviceTypeId(deviceTypeId);
         waterMeterReplaceLog.setOldDeviceTypeId(device.getDeviceType());
         waterMeterReplaceLog.setNewWaterNo(waterMeterReplaceInputDto.getNewElectronicNo());
         waterMeterReplaceLog.setOldWaterNo(device.getWaterMeterNo());

+ 38 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/assistant/InstallManagerServiceImpl.java

@@ -16,9 +16,11 @@ import javax.annotation.Resource;
 import com.bz.smart_city.commom.util.UserUtil;
 import com.bz.smart_city.dao.assistant.InstallAbnormalDeviceMapper;
 import com.bz.smart_city.dao.assistant.InstallAbnormalRecordMapper;
+import com.bz.smart_city.dto.WaterMeterReplaceInputDto;
 import com.bz.smart_city.entity.assistant.InstallAbnormalDevice;
 import com.bz.smart_city.entity.assistant.InstallAbnormalRecord;
 import com.bz.smart_city.service.DeviceService;
+import com.bz.smart_city.service.WaterMeterReplaceLogService;
 import com.bz.smart_city.service.udip.UdipUnitService;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.ss.usermodel.*;
@@ -121,6 +123,8 @@ public class InstallManagerServiceImpl implements InstallManagerService, Initial
 	private InstallAbnormalDeviceMapper installAbnormalDeviceMapper;
 	@Autowired
 	private UdipUnitService udipUnitService;
+	@Autowired
+	private WaterMeterReplaceLogService waterMeterReplaceLogService;
 
 
 	@Override
@@ -562,6 +566,7 @@ public class InstallManagerServiceImpl implements InstallManagerService, Initial
 	}
 	@Override
 	@Transactional
+	@Deprecated
 	public boolean replaceInstallInfo(InstallListDTO dto) {
 		log.info("begin InstallManagerService replaceInstallInfo ,request dto = {}",JSON.toJSONString(dto));
 		boolean isSuccess = false ;
@@ -597,6 +602,39 @@ public class InstallManagerServiceImpl implements InstallManagerService, Initial
 		return isSuccess;
 	}
 
+	@Override
+	@Transactional
+	public boolean replaceWaterMeterV3(WaterMeterReplaceInputDto waterMeterReplaceInputDto) {
+		log.info("begin InstallManagerService replaceWaterMeterV3 ,request waterMeterReplaceInputDto = {}",JSON.toJSONString(waterMeterReplaceInputDto));
+		Device device = deviceMapper.findByDeviceId(waterMeterReplaceInputDto.getDeviceId());
+		if(device.getSysId() == -99){
+			// 1,查询安装计划
+			InstallList  old = installListMapper.findByDeviceId(waterMeterReplaceInputDto.getDeviceId()) ;
+			// 2,更新安装记录
+			InstallList  InstallListUpdate = new InstallList();
+			InstallListUpdate.setId(old.getId());
+			InstallListUpdate.setDeviceNo(waterMeterReplaceInputDto.getNewDeviceNo());
+			InstallListUpdate.setElectronicNo(waterMeterReplaceInputDto.getNewElectronicNo());
+			InstallListUpdate.setNewMeterStart(waterMeterReplaceInputDto.getNewBeginWsv());
+			InstallListUpdate.setOldMeterEnd(waterMeterReplaceInputDto.getOldEndWsv());
+			InstallListUpdate.setDeviceTypeId(waterMeterReplaceInputDto.getNewDeviceTypeId());
+			InstallListUpdate.setIsAccepted(0);
+			InstallListUpdate.setDateUpdate(LocalDateTime.now());
+			installListMapper.updateByPrimaryKeySelective(InstallListUpdate);
+
+			// 6,检查设备号和电子号异常
+			DeviceDto d = new DeviceDto();
+			d.setId(waterMeterReplaceInputDto.getDeviceId());
+			d.setDeviceNo(waterMeterReplaceInputDto.getNewDeviceNo());
+			d.setWaterMeterNo(waterMeterReplaceInputDto.getNewElectronicNo());
+			d.setSiteId(device.getSiteId());
+			checkInstallAbnormal(d);
+		}
+		waterMeterReplaceLogService.submitWaterMeterReplace(waterMeterReplaceInputDto);
+
+		log.info("end InstallManagerService replaceWaterMeterV3");
+		return true;
+	}
 
 
 	@Override