Browse Source

增加井和设备的绑定处理,设备标定信息的备份存储

chenwen 2 năm trước cách đây
mục cha
commit
09b0330c6b

+ 12 - 0
src/main/java/com/hb/proj/base/controller/DeviceController.java

@@ -1,5 +1,7 @@
 package com.hb.proj.base.controller;
 
+import java.util.List;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -27,6 +29,16 @@ public class DeviceController {
 	private DeviceService  service;
 	
 	
+	/**
+	 * 加载某类设备的基本信息
+	 * @param devType 设备类型
+	 * @return
+	 */
+	@RequestMapping("/loadByType")
+	public RespVO<List<DeviceVO>> loadByType(@NotBlank(message="设备类型不应为空") String devType){
+		return RespVOBuilder.ok(service.loadByType(devType));
+	}
+	
 	
 	/**
 	 * 查询设备列表

+ 15 - 3
src/main/java/com/hb/proj/base/controller/WellController.java

@@ -7,7 +7,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import com.hb.proj.allconfig.AccessToken;
+import com.hb.proj.base.service.DeviceService;
 import com.hb.proj.base.service.WellService;
+import com.hb.proj.model.DevicePO;
 import com.hb.proj.model.Well;
 import com.hb.proj.model.WellVO;
 import com.hb.proj.utils.RespVO;
@@ -23,6 +25,9 @@ public class WellController {
 	@Autowired
 	private WellService service;
 	
+	@Autowired
+	private DeviceService deviceService;
+	
 	/**
 	 * 获得单个井数据
 	 * @param wellId  井id
@@ -37,32 +42,39 @@ public class WellController {
 	/**
 	 * 增加新井
 	 * @param well  新井实体
+	 * @param  deviceCode 采集设备编码
 	 * @param token 登录人信息,自动从请求获取
 	 * @return
 	 */
 	@PostMapping("/add")
-	public RespVO<String> add(@Validated Well  well,AccessToken token){
+	public RespVO<String> add(@Validated Well  well,String deviceCode,AccessToken token){
 		if(service.existWellName(well.getWellName(),null)) {
 			return RespVOBuilder.error("该井名已存在");
 		}
 		well.setModifyBy(token!=null?token.getTokenId():"unknow");
 		well.setCreateBy(well.getModifyBy());
-		return RespVOBuilder.ok(service.insert(well));
+		String wellId=service.insert(well);
+		
+		deviceService.updateBindWell(deviceCode,DevicePO.GATHER_DEV, wellId);
+		return RespVOBuilder.ok(wellId);
 	}
 	
 	/**
 	 * 更新井数据
 	 * @param org  井实体
+	 * @param  deviceCode 采集设备编码
 	 * @param token 登录人信息,自动从请求获取
 	 * @return
 	 */
 	@PostMapping("/update")
-	public RespVO<Object> update(@Validated Well  well,AccessToken token){
+	public RespVO<Object> update(@Validated Well  well,String deviceCode,AccessToken token){
 		if(service.existWellName(well.getWellName(),well.getWellId())) {
 			return RespVOBuilder.error("更换的新井名已存在");
 		}
 		well.setModifyBy(token!=null?token.getTokenId():"unknow");
 		service.update(well);
+		
+		deviceService.updateBindWell(deviceCode,DevicePO.GATHER_DEV, well.getWellId());
 		return RespVOBuilder.ok();
 	}
 	

+ 40 - 0
src/main/java/com/hb/proj/base/controller/WellIdGenerator.java

@@ -0,0 +1,40 @@
+package com.hb.proj.base.controller;
+
+import java.util.Date;
+import java.util.Random;
+
+import com.hb.xframework.util.DateUtil;
+
+
+/**
+ * 井号生成器
+ * @author cwen
+ *
+ */
+public class WellIdGenerator {
+	
+	private static Random random = new Random();
+	
+	private static String preId=null;
+
+	public static synchronized String generate() {
+		String id=DateUtil.format(new Date(), "yyMMddmmssSSS")+String.format("%03d", random.nextInt(1000));
+		if(id.equals(preId)) {
+			try {
+				Thread.sleep(0);
+				id=DateUtil.format(new Date(), "yyMMddmmssSSS")+String.format("%03d", random.nextInt(1000));
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+		}
+		preId=id;
+		return id;
+	}
+	
+	public static void main(String[] args) {
+		
+		for(int i=0;i<100;i++) {
+			System.out.println(WellIdGenerator.generate());
+		}
+	}
+}

+ 31 - 0
src/main/java/com/hb/proj/base/controller/WellParamController.java

@@ -3,6 +3,7 @@ package com.hb.proj.base.controller;
 import java.util.Date;
 import java.util.Map;
 
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -11,8 +12,12 @@ import org.springframework.web.bind.annotation.RestController;
 
 import com.hb.proj.allconfig.AccessToken;
 import com.hb.proj.allconfig.SysLog;
+import com.hb.proj.base.service.DeviceService;
 import com.hb.proj.base.service.WellParamService;
+import com.hb.proj.base.service.WellService;
+import com.hb.proj.model.DeviceParamPO;
 import com.hb.proj.model.WellParamPO;
+import com.hb.proj.model.WellVO;
 import com.hb.proj.utils.RequestParams;
 import com.hb.proj.utils.RespVO;
 import com.hb.proj.utils.RespVOBuilder;
@@ -28,6 +33,12 @@ public class WellParamController {
 	@Autowired
 	private WellParamService  service;
 	
+	@Autowired
+	private WellService  wellService;
+	
+	@Autowired
+	private DeviceService  deviceService;
+	
 	/**
 	 * 加载井的参数
 	 * @param wellId
@@ -91,6 +102,9 @@ public class WellParamController {
 		 }
 		 param.setModifyTime(new Date());
 		 param.setModifyBy(token.getTokenId());
+		 param.setParamId(param.getWellId()+"_"+param.getParamCode());  //按特定规则生成  wellId+"_"+paramCode
+		
+		 deviceService.updateDeviceParamConfig(buildDeviceParam(param));
 		 return RespVOBuilder.ok(service.add(param));
 		
 	}
@@ -113,8 +127,25 @@ public class WellParamController {
 		param.setModifyBy(token.getTokenId());
 		service.update(param);
 		
+		deviceService.updateDeviceParamConfig(buildDeviceParam(param));
+		
 		return RespVOBuilder.ok();
 	  
 		
 	}
+	
+	private DeviceParamPO  buildDeviceParam(WellParamPO wparam) {
+		WellVO well=wellService.get(wparam.getWellId());
+		if(StringUtils.isBlank(well.getDeviceCode())) {
+			return null;
+		}
+		DeviceParamPO dparam=new DeviceParamPO();
+		dparam.setDeviceCode(well.getDeviceCode());
+		dparam.setParamCode(wparam.getParamCode());
+		dparam.setCalibrateA(wparam.getCalibrateA());
+		dparam.setCalibrateB(wparam.getCalibrateB());
+		dparam.setCalibrateC(wparam.getCalibrateC());
+		dparam.setGatherUnit(wparam.getGatherUnit());
+		return dparam;
+	}
 }

+ 35 - 1
src/main/java/com/hb/proj/base/service/DeviceService.java

@@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import com.hb.proj.model.DevicePO;
+import com.hb.proj.model.DeviceParamPO;
 import com.hb.proj.model.DeviceVO;
 import com.hb.xframework.dao.core.SpringJdbcDAO;
 import com.hb.xframework.dao.util.PageModel;
@@ -21,7 +22,9 @@ public class DeviceService {
 	@Autowired
 	private SpringJdbcDAO  dao;
 	
-	
+	public List<DeviceVO> loadByType(String devType){
+		return dao.queryForList("select device_name,device_code from tzl_gather_device where del_if=false and device_type=?", DeviceVO.class, devType);
+	}
 	
 	
 	public PageModel<DeviceVO> query(Map<String,Object> args,int pageNo,int pageSize){
@@ -90,4 +93,35 @@ public class DeviceService {
 		
 	}
 	
+	
+	/**
+	 * 更新设备的相关设置(标定、采集单位)
+	 * @param param
+	 * @return
+	 */
+	public boolean updateDeviceParamConfig(DeviceParamPO  param) {
+		if(param==null) {
+			return false;
+		}
+		dao.exeUpdate("delete from tzl_gather_device_param where device_code=? and param_code=?", param.getDeviceCode(),param.getParamCode());
+		UUIDHexGenerator uuid=UUIDHexGenerator.getInstance();
+		param.setDevParamId(uuid.generate());
+		param.setModifyTime(new Date());
+		dao.insert(param,"tzl_gather_device_param");
+		return true;
+	}
+	
+	/**
+	 * 对设备进行井的绑定(同类设备只能绑定一个)
+	 * @param deviceCode
+	 * @param deviceType
+	 * @param wellId
+	 * @return
+	 */
+	public boolean updateBindWell(String deviceCode,String deviceType,String wellId) {
+		dao.exeUpdate("update tzl_gather_device set well_id=null where well_id=? and device_type=?", wellId,deviceType); //先解绑原有的绑定
+		dao.exeUpdate("update tzl_gather_device set well_id=? where device_code=?", wellId,deviceCode);
+		return true;
+	}
+	
 }

+ 0 - 3
src/main/java/com/hb/proj/base/service/WellParamService.java

@@ -12,7 +12,6 @@ import org.springframework.stereotype.Service;
 import com.hb.proj.model.WellParamPO;
 import com.hb.xframework.dao.core.SpringJdbcDAO;
 import com.hb.xframework.dao.util.PageModel;
-import com.hb.xframework.dao.util.UUIDHexGenerator;
 
 @Service
 public class WellParamService {
@@ -54,8 +53,6 @@ public class WellParamService {
 	}
 	
 	public String add(WellParamPO param) {
-		UUIDHexGenerator uuid=UUIDHexGenerator.getInstance();
-		param.setParamId(uuid.generate());
 		param.setModifyTime(new Date());
 		param.setDelIf(false);
 		dao.insert(param,"tzl_well_param");

+ 5 - 5
src/main/java/com/hb/proj/base/service/WellService.java

@@ -8,11 +8,11 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import com.hb.proj.base.controller.WellIdGenerator;
 import com.hb.proj.model.SideTreeNode;
 import com.hb.proj.model.Well;
 import com.hb.proj.model.WellVO;
 import com.hb.xframework.dao.core.SpringJdbcDAO;
-import com.hb.xframework.dao.util.UUIDHexGenerator;
 
 @Service
 public class WellService {
@@ -39,8 +39,8 @@ public class WellService {
     
     
     public String insert(Well well) {
-    	UUIDHexGenerator uuid = UUIDHexGenerator.getInstance();
-    	well.setWellId(uuid.generate());
+    	//UUIDHexGenerator uuid = UUIDHexGenerator.getInstance();
+    	well.setWellId(WellIdGenerator.generate());
     	well.setCreateTime(new Date());
     	well.setModifyTime(well.getCreateTime());
     	well.setDelIf(false);
@@ -65,10 +65,10 @@ public class WellService {
     public WellVO get(String wellId){
         String sql="""
 				
-				select w.*,g.org_name belong_org_name,
-				(select group_concat(d.device_code) from tzl_gather_device d where d.well_id=w.well_id and d.del_if=false group by d.well_id) device_code 
+				select w.*,g.org_name belong_org_name,d.device_code
 				from tzl_well w
 				left join tsys_org g on w.org_id=g.org_id and g.del_if=false
+				left join tzl_gather_device d on d.well_id=w.well_id and d.del_if=false
 				where w.well_id=?
 				
 				""";

+ 4 - 0
src/main/java/com/hb/proj/model/DevicePO.java

@@ -6,6 +6,10 @@ import lombok.Data;
 
 @Data
 public class DevicePO {
+	
+	public static final String GATHER_DEV="gather";
+
+	
 
 	private String deviceId;
 	

+ 25 - 0
src/main/java/com/hb/proj/model/DeviceParamPO.java

@@ -0,0 +1,25 @@
+package com.hb.proj.model;
+
+import java.util.Date;
+
+import lombok.Data;
+
+@Data
+public class DeviceParamPO {
+	
+	private String devParamId;
+	
+	private String deviceCode;
+	
+	private String paramCode;
+	
+	private String gatherUnit;
+	
+	private Double calibrateA;
+	
+	private Double calibrateB;
+	
+	private Double calibrateC;
+	
+	private Date modifyTime;
+}

+ 1 - 1
src/main/java/com/hb/proj/sys/controller/SortCodeController.java

@@ -30,7 +30,7 @@ public class SortCodeController {
 	
 	
 	/**
-	 * 加载多类直接子编码
+	 * 加载多个分类类直接子编码(页面多个下拉框的初始化)
 	 * @param superId
 	 * @return
 	 */