2 Commitit 0f2284ee20 ... 0963c2b39f

Tekijä SHA1 Viesti Päivämäärä
  Jimmy 0963c2b39f 设备删除接口 -- 未实现1 3 vuotta sitten
  Jimmy 3fac9f70e8 批量新增设备接口 3 vuotta sitten

+ 3 - 2
src/main/java/com/comtika/safe/common/enums/api/ApiRequestURI.java

@@ -4,8 +4,9 @@ import com.comtika.safe.common.utils.StringUtil;
 
 
 public enum ApiRequestURI {
-	addEquipTerminal(		"/equip/equipTerminal/addEquipTerminal",	"新增设备",			"equip"),
-	updateEquipTerminal(	"/equip/equipTerminal/updateEquipTerminal",	"修改设备",			"equip"),
+	addEquipTerminal(		"/equip/equipTerminal/addEquipTerminal",	"新增设备",		"equip"),
+	addEquipTerminalList(	"/equip/equipTerminal/addEquipTerminalList","批量新增设备",		"equip"),
+	updateEquipTerminal(	"/equip/equipTerminal/updateEquipTerminal",	"修改设备",		"equip"),
 	addProduct(				"/equip/product/add",						"新增产品类型",		"equip"),
 	updateProduct(			"/equip/product/update",					"修改产品类型",		"equip"),
 	addOTAHsVersion(		"/ota/addOTAHsVersion",						"新增OTA版本",		"equip"),

+ 18 - 1
src/main/java/com/comtika/safe/controller/equip/equip/EquipTerminalController.java

@@ -2,7 +2,9 @@ package com.comtika.safe.controller.equip.equip;
 
 
 
+import com.comtika.safe.entity.equip.AddEquipListEntity;
 import com.comtika.safe.entity.equip.help.TerminalExcelHelp;
+
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
@@ -40,6 +42,13 @@ public class EquipTerminalController extends BaseController{
 	public RespWrapper<Object> addEquipTerminal(@RequestBody EquipTerminalAddEntity equip) {
 		return equipTerminalService.addEquipTerminal(equip,request);
 	}
+	
+	@ApiOperation(value = "批量新增设备信息", notes = "批量新增设备信息")
+    @ApiImplicitParam(name = "equip", value = "批量新增设备参数实体", required = false, dataType = "AddEquipListEntity")
+	@PostMapping(value = "/addEquipTerminalList")
+	public RespWrapper<Object> addEquipTerminalList(@RequestBody AddEquipListEntity equip) {
+		return equipTerminalService.addEquipTerminalList(equip,request);
+	}
 
 	@ApiOperation(value = "查询设备列表", notes = "查询设备列表")
 	@ApiImplicitParams({
@@ -91,5 +100,13 @@ public class EquipTerminalController extends BaseController{
 	public RespWrapper<Object> queryLoopNumberByTerminalNo(String terminalNo) {
 		return equipTerminalService.queryLoopNumberByTerminalNo(terminalNo, request);
 	}
-
+	
+	@ApiOperation(value = "删除集中器信息", notes = "删除集中器信息")
+	@ApiImplicitParams({
+        @ApiImplicitParam(name = "terminalId", value = "集中器id", dataType = "Long", required = false)
+	})
+	@PostMapping(value = "/deleteEquipTerminal")
+	public RespWrapper<Object> deleteEquipTerminal(Long terminalId) {
+		return equipTerminalService.deleteEquipTerminal(terminalId, request);
+	}
 }

+ 3 - 0
src/main/java/com/comtika/safe/dao/equip/terminal/EquipTerminalDao.java

@@ -62,4 +62,7 @@ public interface EquipTerminalDao extends BaseMapper<CtkEquipTerminal> {
 
     @Sql(value = "select count(1) from ctk_equip_socket s where s.equip_terminal_id = ?")
 	int findSocketCount(Long terminalId);
+
+
+	List<String> querySerialNobySerialNoList(@Param("list") List<String> list);
 }

+ 69 - 0
src/main/java/com/comtika/safe/entity/equip/AddEquipListEntity.java

@@ -0,0 +1,69 @@
+package com.comtika.safe.entity.equip;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.comtika.safe.common.response.RespWrapper;
+import com.comtika.safe.common.utils.StringUtil;
+
+import lombok.Data;
+
+/**
+ * 批量新增设备入参实体类
+ * @author Jimmy
+ *
+ */
+@Data
+public class AddEquipListEntity {
+	
+	private String startSerialNo; 		//批量导入设备 - 开始设备编码
+	
+	private String endSerialNo; 		//批量导入设备 - 结束设备编码
+	
+	private Long siteId;				// 站点id
+	
+	private Long equipProductTypeId;	//产品类型id
+	
+	private String remark;				//备注
+
+	public RespWrapper<Object> ParameterValidation() {
+		if(StringUtil.isEmpty(this.startSerialNo)) return RespWrapper.makeFailResp("未输入开始设备编码!");
+		if(StringUtil.isEmpty(this.endSerialNo)) return RespWrapper.makeFailResp("未输入结束设备编码!");
+		if(this.siteId == null) return RespWrapper.makeFailResp("未选择站点!");
+		if(this.equipProductTypeId == null) return RespWrapper.makeFailResp("未选择产品类型!");
+		//验证设备数量  -- 暂时不能超过100台
+		try {
+			Long startSerialNo = Long.parseLong(this.startSerialNo, 16);
+			Long endSerialNo = Long.parseLong(this.endSerialNo, 16);
+			if(endSerialNo < startSerialNo)return RespWrapper.makeFailResp("结束设备编码不能小于开始设备编码!");
+			if((endSerialNo - startSerialNo) > 99) return RespWrapper.makeFailResp("批量新增设备暂时只支持100台以内!");
+		} catch (Exception e) {
+			e.printStackTrace();
+			return RespWrapper.makeFailResp("输入的设备编码有误!");
+		}
+		return RespWrapper.makeSuccessResp("参数验证通过!");
+	}
+	
+	
+	public List<String> createSerialNo() {
+		//将16进制转成10进制
+		Long startSerialNo = Long.parseLong(this.startSerialNo, 16);
+		Long endSerialNo = Long.parseLong(this.endSerialNo, 16);
+		System.out.println("十六进制转成十进制结果startSerialNo:"+startSerialNo +",endSerialNo:" + endSerialNo);
+		List<String> list = new ArrayList<String>();
+    	for( Long i = startSerialNo; i <= endSerialNo; i++ ){
+    		//将10进制转成16进制
+    		String serialNo = Long.toHexString(i).toUpperCase();
+    		list.add(serialNo);
+    	}
+    	System.out.println("十进制转成十六进制结果:"+String.join(",", list));
+		return list;
+	}
+	
+	public static void main(String[] args) {
+		Long startSerialNo = Long.parseLong("10F09AA", 16);
+		System.out.println(startSerialNo);
+		String a = Long.toHexString(startSerialNo).toUpperCase();
+		System.out.println(a);
+	}
+}

+ 6 - 0
src/main/java/com/comtika/safe/service/equip/terminal/EquipTerminalService.java

@@ -6,7 +6,9 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import com.comtika.safe.core.UserCoreCache;
+import com.comtika.safe.entity.equip.AddEquipListEntity;
 import com.comtika.safe.entity.equip.help.TerminalExcelHelp;
+
 import org.beetl.sql.core.engine.PageQuery;
 
 import com.comtika.safe.common.response.RespWrapper;
@@ -28,4 +30,8 @@ public interface EquipTerminalService {
     RespWrapper fadFindTerminalList(TerminalExcelHelp help, UserCoreCache userCache);
 
 	RespWrapper terminalListExcel(TerminalExcelHelp help, UserCoreCache userCache, HttpServletResponse response);
+
+	RespWrapper<Object> addEquipTerminalList(AddEquipListEntity equip,HttpServletRequest request);
+
+	RespWrapper<Object> deleteEquipTerminal(Long terminalId,HttpServletRequest request);
 }

+ 109 - 0
src/main/java/com/comtika/safe/service/equip/terminal/impl/EquipTerminalServiceImpl.java

@@ -9,8 +9,10 @@ import com.comtika.safe.common.constant.ProjectConstant;
 import com.comtika.safe.common.utils.JXLUtil;
 import com.comtika.safe.core.UserCoreCache;
 import com.comtika.safe.core.protocol.cache.SafeCache;
+import com.comtika.safe.entity.equip.AddEquipListEntity;
 import com.comtika.safe.entity.equip.help.TerminalExcelHelp;
 import com.comtika.safe.service.warn.impl.WarnServiceImpl;
+
 import org.beetl.sql.core.engine.PageQuery;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -133,7 +135,106 @@ public class EquipTerminalServiceImpl implements EquipTerminalService {
 		}
 		return RespWrapper.makeSuccessResp("新增成功!");
 	}
+	
+	@Override
+	public RespWrapper<Object> addEquipTerminalList(AddEquipListEntity equip,HttpServletRequest request) {
+		try {
+			//1.参数验证
+			if(equip == null)return RespWrapper.makeFailResp("参数有误,请检查!!");
+			RespWrapper<Object> parameterValidation = equip.ParameterValidation();
+			if( !parameterValidation.isSuccess() ) return parameterValidation;
+			
+			//2.生成所有设备编码
+			List<String> serialNoList = equip.createSerialNo();
+			
+			//3.验证当前设备编码是否存在
+			List<String> dataSerialNo = equipTerminalDao.querySerialNobySerialNoList(serialNoList);
+			if(null != dataSerialNo && !dataSerialNo.isEmpty() && dataSerialNo.size() > 0){
+				String data = String.join(",", dataSerialNo);
+				return RespWrapper.makeFailResp("导入失败,已存在以下设备编码:" + data);
+			}
+			
+			//4.检查设备类型是否存在,以及查询该设备类型的回路数
+			CtkProductType type = new CtkProductType();
+			type.setId(equip.getEquipProductTypeId());
+			type = productDao.templateOne(type);
+			if( null == type) return RespWrapper.makeFailResp("产品类型不存在,请检查!");
+
+			//5.查询站点,并且检查站点是否存在
+			CtkSite ctkSite = new CtkSite();
+			ctkSite.setSiteId(equip.getSiteId());
+			ctkSite = siteDao.templateOne(ctkSite);
+			if( null == ctkSite) return RespWrapper.makeFailResp("站点不存在,请检查!");
+			for(String serialNo : serialNoList){
+                String terminalNo = serialNo + "80";
+                //生成集中器编号
+                if(serialNo.length() == 8){
+                	terminalNo = "00" + terminalNo ;
+                }else if(serialNo.length() == 9){
+                	terminalNo = "0" + terminalNo;
+                }
+                //6.新增设备
+    			CtkEquipTerminal terminal = new CtkEquipTerminal();
+    			terminal.setMerchantId(ctkSite.getMerchantId());
+                terminal.setTerminalNo(terminalNo);
+                terminal.setEquipProductTypeId(equip.getEquipProductTypeId());
+                terminal.setSiteId(equip.getSiteId());
+                terminal.setSerialNo(serialNo);// 流水号
+                terminal.setCreatTime(System.currentTimeMillis());
+                terminal.setStatus(TerminalStatusEnum.IN_MAINTEN.getId());//初始化
+                terminal.setOtaStatus(OTAStatus.OTA_SUCCESS.getId());
+                terminal.setRemark(equip.getRemark());
+                equipTerminalDao.insertTemplate(terminal, true);
+                
+                
+                //生成两个子板编号
+                String nodeOneNo = terminalNo.substring(0,terminalNo.length()-1) + "1";
+                String nodeTwoNo = terminalNo.substring(0,terminalNo.length()-1) + "2";
+                //6.新增子板
+                List<CtkEquipNode> listNode = new ArrayList<CtkEquipNode>();
+                CtkEquipNode node1 = new CtkEquipNode();
+                node1.setEquipTerminalId(terminal.getTerminalId());
+                node1.setNodeNo(nodeOneNo);
+                CtkEquipNode node2 = new CtkEquipNode();
+                node2.setEquipTerminalId(terminal.getTerminalId());
+                node2.setNodeNo(nodeTwoNo);
+                listNode.add(node1);
+                listNode.add(node2);
+                equipNodeDao.insertBatch(listNode, true);
 
+                //7.新增回路
+                //生成设备插座,协议规定,不管多少个子板,一个子板最多放8个插座。不满8个插座的,都放在子板1
+                String serialStr = "";
+                int num = type.getLoopNumber();
+                List<CtkEquipSocket> socketList = new ArrayList<CtkEquipSocket>();
+                CtkEquipSocket socket = null;
+                for (int i = 1; i < num + 1; i++) {
+                    socket = new CtkEquipSocket();
+                    if( i < 9 ) {
+                        socket.setEquipNodeId(node1.getId());
+                        socket.setSocketNo( i - 1 );
+                    }else {
+                        socket.setSocketNo( i - 9 );
+                        socket.setEquipNodeId(node2.getId());
+                    }
+                    String dealCount = i < 10 ? ("0" + i) : i + "";
+                    serialStr = serialNo + dealCount;
+                    socket.setSerialNo(serialStr);
+                    socket.setEquipTerminalId(terminal.getTerminalId());
+                    socket.setSocketStatus(SocketStatus.IDLE.getId());//插座状态初始化?
+                    socketList.add(socket);
+                }
+                equipSocketDao.insertBatch(socketList);
+    			SafeCache.removeTerminalBaseInfo(terminalNo);
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+			LuceneUtils.apiErrorLucene(ApiErrorType.equip.getType(), request, "批量新增设备", e.getMessage());
+			return RespWrapper.makeErrorResp("新增失败:" + e.getMessage());
+		}
+		return RespWrapper.makeSuccessResp("新增成功!");
+	}
+	
 	@Override
 	public RespWrapper<Object> findTerminalList(HttpServletRequest request,PageQuery<Map<String, Object>> pageQuery) {
 		try {
@@ -393,4 +494,12 @@ public class EquipTerminalServiceImpl implements EquipTerminalService {
 		return pageQuery;
 	}
 
+	@Override
+	public RespWrapper<Object> deleteEquipTerminal(Long terminalId,HttpServletRequest request) {
+		//此方法未实现
+		return null;
+	}
+
+	
+
 }

+ 8 - 0
src/main/resources/sql/equip/terminal.md

@@ -118,3 +118,11 @@ WHERE 1 = 1
 @if(!isEmpty(terminalType)){
 	AND cet.equip_product_type_id = #terminalType# 
 @}
+
+querySerialNobySerialNoList
+===
+SELECT 
+  serial_no 
+FROM
+  ctk_equip_terminal 
+WHERE serial_no in (#join(list)#)