|
@@ -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;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|