From 5f9bf98779e2c3e69324d75849efdda00868da4f Mon Sep 17 00:00:00 2001
From: doum <doum>
Date: 星期五, 29 五月 2026 15:45:47 +0800
Subject: [PATCH] 新增智能电表、空调管理

---
 server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwElectricalServiceImpl.java |  469 +++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 396 insertions(+), 73 deletions(-)

diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwElectricalServiceImpl.java b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwElectricalServiceImpl.java
index f25aa2d..da8d93c 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwElectricalServiceImpl.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwElectricalServiceImpl.java
@@ -1,137 +1,460 @@
 package com.doumee.service.business.impl;
 
+import com.alibaba.fastjson.JSONObject;
 import com.doumee.core.constants.ResponseStatus;
+import com.doumee.core.device.ElectronicToolUtil;
+import com.doumee.core.device.WaterElectricityUtil;
+import com.doumee.core.device.model.response.CollectorStatusResponse;
+import com.doumee.core.device.model.response.ElectronicDataResponse;
+import com.doumee.core.device.model.response.MeterInfoResponse;
 import com.doumee.core.exception.BusinessException;
-import com.doumee.core.model.LoginUserInfo;
+import com.doumee.core.haikang.model.param.respose.AcsDeviceInfoResponse;
+import com.doumee.core.haikang.model.param.respose.AscDeviceStatusInfoResponse;
+import com.doumee.core.haikang.model.param.respose.DoorsInfoResponse;
+import com.doumee.core.haikang.model.param.respose.LedRecordsInfoResponse;
 import com.doumee.core.model.PageData;
 import com.doumee.core.model.PageWrap;
 import com.doumee.core.utils.Constants;
 import com.doumee.core.utils.DateUtil;
+import com.doumee.dao.business.model.Device;
+import com.doumee.dao.business.model.DeviceData;
+import com.doumee.dao.business.model.YwDevice;
+import com.doumee.dao.business.model.YwElectrical;
+import com.doumee.dao.business.model.YwElectricalParam;
 import com.doumee.core.utils.Utils;
 import com.doumee.dao.business.YwElectricalMapper;
-import com.doumee.dao.business.model.YwElectrical;
-import com.doumee.dao.business.model.YwGateway;
+import com.doumee.service.business.YwElectricalBizService;
 import com.doumee.service.business.YwElectricalService;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.github.yulichang.wrapper.MPJLambdaWrapper;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
+import com.doumee.core.model.LoginUserInfo;
 
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Date;
 import java.util.List;
-import java.util.Objects;
 
 /**
  * 鐢佃〃璁惧淇℃伅Service瀹炵幇
- * @author renkang
- * @date 2026/04/03
+ * @author doumee
+ * @date 2026-05-20 14:59:06
  */
 @Service
 public class YwElectricalServiceImpl implements YwElectricalService {
 
     @Autowired
     private YwElectricalMapper ywElectricalMapper;
+    @Autowired
+    private YwElectricalBizService ywElectricalBizService;
 
     @Override
     public Integer create(YwElectrical ywElectrical) {
-        if (Objects.isNull(ywElectrical)
-                || StringUtils.isBlank(ywElectrical.getName())
-                || StringUtils.isBlank(ywElectrical.getCode())) {
-            throw new BusinessException(ResponseStatus.BAD_REQUEST);
-        }
-        LoginUserInfo loginUserInfo = ywElectrical.getLoginUserInfo();
-        // 鏍¢獙琛ㄥ彿鍞竴
-        if (ywElectricalMapper.selectCount(new QueryWrapper<YwElectrical>().lambda()
-                .eq(YwElectrical::getIsdeleted, Constants.ZERO)
-                .eq(YwElectrical::getCode, ywElectrical.getCode())) > Constants.ZERO) {
-            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "琛ㄥ彿閲嶅!");
-        }
-        ywElectrical.setCreateDate(new Date());
-        ywElectrical.setCreator(loginUserInfo.getId());
-        ywElectrical.setEditDate(new Date());
-        ywElectrical.setEditor(loginUserInfo.getId());
-        ywElectrical.setIsdeleted(Constants.ZERO);
         ywElectricalMapper.insert(ywElectrical);
         return ywElectrical.getId();
     }
 
     @Override
-    public void deleteById(Integer id, LoginUserInfo user) {
-        ywElectricalMapper.update(new UpdateWrapper<YwElectrical>()
-                .lambda()
-                .set(YwElectrical::getIsdeleted, Constants.ONE)
-                .set(YwElectrical::getEditDate, DateUtil.getCurrDateTime())
-                .set(YwElectrical::getEditor, user.getId())
-                .eq(YwElectrical::getId, id)
-        );
+    public void deleteById(Integer id) {
+        ywElectricalMapper.deleteById(id);
     }
-
+  @Override
+    public void deleteByIdInBatch(List<Integer> ids ) {
+        if (CollectionUtils.isEmpty(ids)) {
+            return;
+        }
+        for(Integer id :ids){
+            deleteById(id);
+        }
+    }
     @Override
+    public void deleteById(Integer id, LoginUserInfo user) {
+        ywElectricalMapper.deleteById(id);
+    }
+  @Override
     public void deleteByIdInBatch(List<Integer> ids, LoginUserInfo user) {
         if (CollectionUtils.isEmpty(ids)) {
             return;
         }
-        for (Integer id : ids) {
-            this.deleteById(id, user);
+       for(Integer id :ids){
+            deleteById(id,user);
         }
     }
+    @Override
+    public void delete(YwElectrical ywElectrical) {
+        UpdateWrapper<YwElectrical> deleteWrapper = new UpdateWrapper<>(ywElectrical);
+        ywElectricalMapper.delete(deleteWrapper);
+    }
+
 
     @Override
     public void updateById(YwElectrical ywElectrical) {
-        if (Objects.isNull(ywElectrical)
-                || Objects.isNull(ywElectrical.getId())
-                || StringUtils.isBlank(ywElectrical.getName())
-                || StringUtils.isBlank(ywElectrical.getCode())) {
-            throw new BusinessException(ResponseStatus.BAD_REQUEST);
-        }
-        LoginUserInfo loginUserInfo = ywElectrical.getLoginUserInfo();
-        // 鏍¢獙琛ㄥ彿鍞竴锛堟帓闄よ嚜韬級
-        if (ywElectricalMapper.selectCount(new QueryWrapper<YwElectrical>().lambda()
-                .eq(YwElectrical::getIsdeleted, Constants.ZERO)
-                .eq(YwElectrical::getCode, ywElectrical.getCode())
-                .ne(YwElectrical::getId, ywElectrical.getId())) > Constants.ZERO) {
-            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "琛ㄥ彿閲嶅!");
-        }
-        ywElectrical.setEditDate(new Date());
-        ywElectrical.setEditor(loginUserInfo.getId());
         ywElectricalMapper.updateById(ywElectrical);
     }
 
     @Override
-    public YwElectrical findById(Integer id) {
-        return ywElectricalMapper.selectJoinOne(YwElectrical.class,
-                new MPJLambdaWrapper<YwElectrical>()
-                        .selectAll(YwElectrical.class)
-                        .selectAs(YwGateway::getName, YwElectrical::getGatewayName)
-                        .leftJoin(YwGateway.class, YwGateway::getId, YwElectrical::getGatewayId)
-                        .eq(YwElectrical::getId, id)
-                        .last(" limit 1 ")
-        );
+    public void updateByIdInBatch(List<YwElectrical> ywElectricals) {
+        if (CollectionUtils.isEmpty(ywElectricals)) {
+            return;
+        }
+        for (YwElectrical ywElectrical: ywElectricals) {
+            this.updateById(ywElectrical);
+        }
     }
 
+    @Override
+    public YwElectrical findById(Integer id) {
+        return ywElectricalMapper.selectById(id);
+    }
+
+    @Override
+    public YwElectrical findOne(YwElectrical ywElectrical) {
+        QueryWrapper<YwElectrical> wrapper = new QueryWrapper<>(ywElectrical).last("limit 1");
+        return ywElectricalMapper.selectOne(wrapper);
+    }
+
+    @Override
+    public List<YwElectrical> findList(YwElectrical ywElectrical) {
+        QueryWrapper<YwElectrical> wrapper = new QueryWrapper<>(ywElectrical);
+        return ywElectricalMapper.selectList(wrapper);
+    }
+  
     @Override
     public PageData<YwElectrical> findPage(PageWrap<YwElectrical> pageWrap) {
         IPage<YwElectrical> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
         MPJLambdaWrapper<YwElectrical> queryWrapper = new MPJLambdaWrapper<>();
         Utils.MP.blankToNull(pageWrap.getModel());
-        YwElectrical model = pageWrap.getModel();
         queryWrapper.selectAll(YwElectrical.class)
-                .selectAs(YwGateway::getName, YwElectrical::getGatewayName)
-                .leftJoin(YwGateway.class, YwGateway::getId, YwElectrical::getGatewayId)
-                .and(Objects.nonNull(model) && StringUtils.isNotBlank(model.getName()),
-                        i -> i.like(YwElectrical::getName, model.getName())
-                             .or()
-                             .like(YwElectrical::getCode, model.getName()))
-                .eq(Objects.nonNull(model) && Objects.nonNull(model.getRunStatus()), YwElectrical::getRunStatus, model.getRunStatus())
-                .eq(Objects.nonNull(model) && Objects.nonNull(model.getGatewayId()), YwElectrical::getGatewayId, model.getGatewayId())
-                .eq(YwElectrical::getIsdeleted, Constants.ZERO)
-                .orderByDesc(YwElectrical::getCreateDate);
-        IPage<YwElectrical> iPage = ywElectricalMapper.selectJoinPage(page, YwElectrical.class, queryWrapper);
-        return PageData.from(iPage);
+                .selectAs(YwElectricalParam::getName, YwElectrical::getParamName)
+                .leftJoin(YwElectricalParam.class, on -> on
+                        .eq(YwElectricalParam::getId, YwElectrical::getElectricalParamId)
+                        .eq(YwElectricalParam::getIsdeleted, Constants.ZERO))
+                .eq(YwElectrical::getIsdeleted, Constants.ZERO);
+        if (StringUtils.isNotBlank(pageWrap.getModel().getMeterKeyword())) {
+            String kw = pageWrap.getModel().getMeterKeyword().trim();
+            queryWrapper.and(w -> w.like(YwElectrical::getName, kw).or().like(YwElectrical::getAddress, kw));
+        }
+        queryWrapper.eq(pageWrap.getModel().getId() != null,YwElectrical::getId, pageWrap.getModel().getId());
+        queryWrapper.eq(pageWrap.getModel().getCreator() != null,YwElectrical::getCreator, pageWrap.getModel().getCreator());
+        if (pageWrap.getModel().getCreateDate() != null) {
+            queryWrapper.ge(YwElectrical::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate()));
+            queryWrapper.le(YwElectrical::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate()));
+        }
+        queryWrapper.eq(pageWrap.getModel().getEdirot() != null,YwElectrical::getEdirot, pageWrap.getModel().getEdirot());
+        if (pageWrap.getModel().getEditDate() != null) {
+            queryWrapper.ge(YwElectrical::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate()));
+            queryWrapper.le(YwElectrical::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate()));
+        }
+        queryWrapper.eq(pageWrap.getModel().getIsdeleted() != null,YwElectrical::getIsdeleted, pageWrap.getModel().getIsdeleted());
+        queryWrapper.eq(pageWrap.getModel().getRemark() != null,YwElectrical::getRemark, pageWrap.getModel().getRemark());
+        queryWrapper.eq(pageWrap.getModel().getCollectorId() != null,YwElectrical::getCollectorId, pageWrap.getModel().getCollectorId());
+        queryWrapper.eq(pageWrap.getModel().getCode() != null,YwElectrical::getCode, pageWrap.getModel().getCode());
+        queryWrapper.eq(pageWrap.getModel().getAddress() != null,YwElectrical::getAddress, pageWrap.getModel().getAddress());
+        queryWrapper.eq(pageWrap.getModel().getDeviceType() != null,YwElectrical::getDeviceType, pageWrap.getModel().getDeviceType());
+        queryWrapper.eq(pageWrap.getModel().getRate() != null,YwElectrical::getRate, pageWrap.getModel().getRate());
+        queryWrapper.eq(pageWrap.getModel().getPayType() != null,YwElectrical::getPayType, pageWrap.getModel().getPayType());
+        queryWrapper.eq(pageWrap.getModel().getName() != null,YwElectrical::getName, pageWrap.getModel().getName());
+        queryWrapper.eq(pageWrap.getModel().getGatewayId() != null,YwElectrical::getGatewayId, pageWrap.getModel().getGatewayId());
+        queryWrapper.eq(pageWrap.getModel().getGatewayPort() != null,YwElectrical::getGatewayPort, pageWrap.getModel().getGatewayPort());
+        if (pageWrap.getModel().getLastHeartbeatDate() != null) {
+            queryWrapper.ge(YwElectrical::getLastHeartbeatDate, Utils.Date.getStart(pageWrap.getModel().getLastHeartbeatDate()));
+            queryWrapper.le(YwElectrical::getLastHeartbeatDate, Utils.Date.getEnd(pageWrap.getModel().getLastHeartbeatDate()));
+        }
+        queryWrapper.eq(pageWrap.getModel().getBalance() != null,YwElectrical::getBalance, pageWrap.getModel().getBalance());
+        queryWrapper.eq(pageWrap.getModel().getRelayStatus() != null,YwElectrical::getRelayStatus, pageWrap.getModel().getRelayStatus());
+        if (pageWrap.getModel().getLastOpenDate() != null) {
+            queryWrapper.ge(YwElectrical::getLastOpenDate, Utils.Date.getStart(pageWrap.getModel().getLastOpenDate()));
+            queryWrapper.le(YwElectrical::getLastOpenDate, Utils.Date.getEnd(pageWrap.getModel().getLastOpenDate()));
+        }
+        if (pageWrap.getModel().getLastCleanDate() != null) {
+            queryWrapper.ge(YwElectrical::getLastCleanDate, Utils.Date.getStart(pageWrap.getModel().getLastCleanDate()));
+            queryWrapper.le(YwElectrical::getLastCleanDate, Utils.Date.getEnd(pageWrap.getModel().getLastCleanDate()));
+        }
+        queryWrapper.eq(pageWrap.getModel().getOnline() != null,YwElectrical::getOnline, pageWrap.getModel().getOnline());
+        queryWrapper.eq(pageWrap.getModel().getAccountStatus() != null,YwElectrical::getAccountStatus, pageWrap.getModel().getAccountStatus());
+        queryWrapper.eq(pageWrap.getModel().getStatus() != null,YwElectrical::getStatus, pageWrap.getModel().getStatus());
+        queryWrapper.eq(pageWrap.getModel().getWarnType() != null,YwElectrical::getWarnType, pageWrap.getModel().getWarnType());
+        queryWrapper.eq(pageWrap.getModel().getType() != null,YwElectrical::getType, pageWrap.getModel().getType());
+        queryWrapper.eq(pageWrap.getModel().getDId() != null,YwElectrical::getDId, pageWrap.getModel().getDId());
+        queryWrapper.eq(pageWrap.getModel().getCId() != null,YwElectrical::getCId, pageWrap.getModel().getCId());
+        queryWrapper.eq(pageWrap.getModel().getDescription() != null,YwElectrical::getDescription, pageWrap.getModel().getDescription());
+        queryWrapper.eq(pageWrap.getModel().getCsq() != null,YwElectrical::getCsq, pageWrap.getModel().getCsq());
+        if (pageWrap.getModel().getDisconnectTime() != null) {
+            queryWrapper.ge(YwElectrical::getDisconnectTime, Utils.Date.getStart(pageWrap.getModel().getDisconnectTime()));
+            queryWrapper.le(YwElectrical::getDisconnectTime, Utils.Date.getEnd(pageWrap.getModel().getDisconnectTime()));
+        }
+        if (pageWrap.getModel().getConnectTime() != null) {
+            queryWrapper.ge(YwElectrical::getConnectTime, Utils.Date.getStart(pageWrap.getModel().getConnectTime()));
+            queryWrapper.le(YwElectrical::getConnectTime, Utils.Date.getEnd(pageWrap.getModel().getConnectTime()));
+        }
+        queryWrapper.eq(pageWrap.getModel().getBalanceBattery() != null,YwElectrical::getBalanceBattery, pageWrap.getModel().getBalanceBattery());
+        if (pageWrap.getModel().getBalanceTime() != null) {
+            queryWrapper.ge(YwElectrical::getBalanceTime, Utils.Date.getStart(pageWrap.getModel().getBalanceTime()));
+            queryWrapper.le(YwElectrical::getBalanceTime, Utils.Date.getEnd(pageWrap.getModel().getBalanceTime()));
+        }
+         queryWrapper.orderByDesc(YwElectrical::getId);
+         IPage<YwElectrical> result = ywElectricalMapper.selectJoinPage(page, YwElectrical.class,queryWrapper);
+         PageData<YwElectrical> pageData = PageData.from(result);
+         ywElectricalBizService.enrichList(pageData.getRecords());
+         return pageData;
+    }
+    @Override
+    public long count(YwElectrical ywElectrical) {
+        QueryWrapper<YwElectrical> wrapper = new QueryWrapper<>(ywElectrical);
+        return ywElectricalMapper.selectCount(wrapper);
+    }
+    @Override
+    @Transactional
+    public void getElectricalStatus(){
+        if(Constants.DEALING_ELECTRICAL_STATUS){
+            return ;
+        }
+        Constants.DEALING_ELECTRICAL_STATUS =true;
+        try {
+            List<Device> editList = new ArrayList<>();
+            Date date = new Date();
+            //鏌ヨ鍏ㄩ儴闂ㄧ璁惧鏁版嵁
+            ElectronicDataResponse<List<CollectorStatusResponse>>  response = ElectronicToolUtil.collectorStatus();
+            if (!ElectronicToolUtil.isDataApiSuccess(response)) {
+                throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),
+                        ElectronicToolUtil.dataApiErrorMessage(response, "鍚屾閲囬泦鍣ㄧ姸鎬佸紓甯�"));
+            }
+            if(response.getData()!=null && response.getData().size()>0){
+                //閫昏緫鍒犻櫎
+                for(CollectorStatusResponse d : response.getData()){
+                    ywElectricalMapper.update(null,new UpdateWrapper<YwElectrical>().lambda()
+                            .set(YwElectrical::getOnline, d.getOnline()?1:0)
+                            .set(YwElectrical::getDescription,d.getDescription())
+                            .set(YwElectrical::getCsq,d.getCsq())
+                            .set(YwElectrical::getDisconnectTime,d.getDisconnect_time())
+                            .set(YwElectrical::getConnectTime,d.getConnect_time())
+                            .set(YwElectrical::getEditDate,date)
+                            .eq(YwElectrical::getCollectorId,d.getCollectorid()));
+                }
+            }
+        }catch (Exception e){
+            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "鍚屾璁惧鐘舵�佸け璐ワ紒");
+        }finally {
+            Constants.DEALING_ELECTRICAL_STATUS =false;
+        }
+    }
+    @Override
+    @Transactional
+    public String syncAll(YwElectrical ywElectrical){
+        if(Constants.DEALING_ELECTRICAL_SYNCDEVICE){
+            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "鍚屾浠诲姟姝e湪鎵ц鍝︼紝璇风◢鍚庢煡鐪嬬粨鏋滐紒") ;
+        }
+        Constants.DEALING_ELECTRICAL_SYNCDEVICE =true;
+        try {
+            List<YwElectrical> deleteList = new ArrayList<>();
+            List<YwElectrical> addList = new ArrayList<>();
+            List<YwElectrical> editList = new ArrayList<>();
+            Date date = new Date();
+            //鏌ヨ鍏ㄩ儴闂ㄧ璁惧鏁版嵁
+            List<YwElectrical> allList = ywElectricalMapper.selectList(new QueryWrapper<YwElectrical>().lambda()
+                    .eq(YwElectrical::getIsdeleted,Constants.ZERO));
+            ElectronicDataResponse<List<MeterInfoResponse>>  response = ElectronicToolUtil.meterList();
+            if (!ElectronicToolUtil.isDataApiSuccess(response)) {
+                throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),
+                        ElectronicToolUtil.dataApiErrorMessage(response, "鍚屾鐢佃〃鏁版嵁寮傚父"));
+            }
+            List<MeterInfoResponse> meterData = response.getData();
+            if (meterData == null) {
+                meterData = Collections.emptyList();
+            }
+            if (meterData.isEmpty()) {
+                return "鍚屾瀹屾垚锛氱涓夋柟骞冲彴鏆傛棤鐢佃〃鏁版嵁";
+            }
+            getDataChangeList(allList, meterData, addList, editList, deleteList, date);
+            if(deleteList.size()>0){
+                for(YwElectrical d : deleteList){
+                    ywElectricalMapper.updateById(d);
+                }
+            }
+            if(addList.size()>0){
+                for (YwElectrical d : addList) {
+                    ywElectricalMapper.insert(d);
+                }
+            }
+            if(editList.size()>0){
+                for(YwElectrical d : editList){
+                    ywElectricalMapper.updateById(d);
+                }
+            }
+            return "鍚屾鏁版嵁锛氭柊澧炪��"+addList.size()+"銆戞潯锛屾洿鏂般��"+editList.size()+"銆戞潯锛屽垹闄ゃ��"+deleteList.size()+"銆戞潯";
+        } catch (BusinessException e) {
+            throw e;
+        } catch (Exception e) {
+            e.printStackTrace();
+            String detail = StringUtils.isNotBlank(e.getMessage()) ? e.getMessage() : e.getClass().getSimpleName();
+            throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "鍚屾澶辫触锛�" + detail);
+        } finally {
+            Constants.DEALING_ELECTRICAL_SYNCDEVICE =false;
+        }
+    }
+    private void getDataChangeList(List<YwElectrical> allList,
+                                   List<MeterInfoResponse> dataList ,
+                                   List<YwElectrical> addList,
+                                   List<YwElectrical> editList,
+                                   List<YwElectrical> deleteList,
+                                   Date date ) {
+        if(dataList!=null && dataList.size()>0){
+            //鑾峰彇娴峰悍鍏ㄩ儴闂ㄧ缁勬暟鎹�
+            for(MeterInfoResponse device : dataList){
+                YwElectrical model = getExistedDevice(device,allList);
+                if(model !=null){
+                    //濡傛灉宸插瓨鍦紝鍒欐洿鏂版暟鎹�
+                    model =  initDeviceDataByData(model,device,date,dataList);
+                    editList.add(model);
+                }else{
+                    //濡傛灉涓嶅瓨鍦紝鍒欐柊澧炴暟鎹�
+                    model = new YwElectrical();
+                    model =  initDeviceDataByData(model,device,date,dataList);
+                    addList.add(model);
+                }
+            }
+        }
+        if (dataList != null && !dataList.isEmpty()) {
+            getDeleteDeviceList(allList, dataList, deleteList, date);
+        }
+    }
+    private boolean isDeletedDevice(YwElectrical device, List<MeterInfoResponse> allHkList) {
+        if (allHkList != null && allHkList.size() > 0) {
+            for(MeterInfoResponse r : allHkList){
+                if(StringUtils.equals(device.getDId(), r.getId())){
+                    //琛ㄧず鏈垹闄�
+                    return  false;
+                }
+            }
+        }
+        return  true;
+
+    }
+    private void getDeleteDeviceList(List<YwElectrical> allList,  List<MeterInfoResponse> allHkList,List<YwElectrical> deleteList ,Date date) {
+        if(allList!=null && allList.size()>0){
+            for(YwElectrical device : allList){
+                if(isDeletedDevice(device,allHkList)){
+                    device.setIsdeleted(Constants.ONE);
+                    device.setEditDate(date);
+                    deleteList.add(device);
+                }
+            }
+        }
+    }
+    private YwElectrical initDeviceDataByData(YwElectrical model, MeterInfoResponse door, Date date, List<MeterInfoResponse> allHkList) {
+        MeterInfoResponse device = getDeviceByid(door.getCollectorid(),allHkList);
+        Date originCreateDate = model.getCreateDate();
+        model.setIsdeleted(Constants.ZERO);
+        model.setEditDate(date);
+        if (originCreateDate == null) {
+            model.setCreateDate(date);
+        }
+        model.setDescription(door.getDescription());
+        model.setName(door.getDescription());
+        model.setCId(door.getCid());
+        model.setDId(door.getId());
+        model.setPriceid(door.getPriceid());
+        model.setParamId(door.getParam_id());
+        model.setDeviceType(door.getDevice_type());
+        model.setAccountId(door.getAccount_id());
+        model.setAddress(door.getAddress());
+        model.setCollectorId(door.getCollectorid());
+        model.setType(door.getType());
+        model.setRelayStatus(door.getRelay_state());
+        model.setCsq(door.getCsq());
+        model.setAccountStatus(resolveAccountStatusByPurchaseCount(door.getCount()));
+        model.setRemark(JSONObject.toJSONString(device));
+        return  model;
+    }
+
+    /** 璐拱娆℃暟澶т簬 0 瑙嗕负宸插紑鎴� */
+    private Integer resolveAccountStatusByPurchaseCount(String purchaseCount) {
+        if (StringUtils.isBlank(purchaseCount)) {
+            return Constants.ZERO;
+        }
+        try {
+            return new BigDecimal(purchaseCount.trim()).compareTo(BigDecimal.ZERO) > 0
+                    ? Constants.ONE : Constants.ZERO;
+        } catch (NumberFormatException e) {
+            return Constants.ZERO;
+        }
+    }
+    private MeterInfoResponse getDeviceByid(String indexCode, List<MeterInfoResponse> allHkList ) {
+        if(allHkList!=null && allHkList.size()>0){
+            for(MeterInfoResponse info : allHkList){
+                if(StringUtils.equals(indexCode,info.getCollectorid())){
+                    return info;
+                }
+            }
+        }
+
+        return new MeterInfoResponse();
+    }
+    private YwElectrical getExistedDevice(MeterInfoResponse device, List<YwElectrical> allList) {
+        if(allList.size()>0){
+            for(YwElectrical r : allList){
+                if(StringUtils.equals(r.getCollectorId(), device.getCollectorid())){
+                    //琛ㄧず鏈垹闄�
+                    return  r;
+                }
+            }
+        }
+        return  null;
+    }
+
+    @Override
+    public void controlDo(Device param){
+        YwElectrical model = ywElectricalMapper.selectById(param.getId());
+        if(model ==null && Constants.equalsInteger(param.getType(),Constants.DEVICE_TYPE.dianbiao)){
+            throw  new BusinessException(ResponseStatus.DATA_EMPTY);
+        }
+        if (param.getStatus() == null || param.getCmdDate() == null
+                ||param.getCmdDate().getTime() <= System.currentTimeMillis()) {
+            //濡傛灉鏄紑闂�
+            throw  new BusinessException(ResponseStatus.BAD_REQUEST);
+        }
+
+        boolean r ;
+        String date = DateUtil.formatDate(new Date(),"yyyyMMddHHmmss");
+        if(Constants.equalsInteger(param.getStatus(),Constants.ONE)) {
+            //濡傛灉鏄紑闂�
+            r = WaterElectricityUtil.electricityAct(param.getIp(),Integer.parseInt(param.getPort()),param.getNo(),0,date);
+        }else {
+            //濡傛灉鏄悎闂�
+            r = WaterElectricityUtil.electricityAct(param.getIp(),Integer.parseInt(param.getPort()),param.getNo(),1,date);
+        }
+        if(!r){
+            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"杩滅▼鎺у埗鐢佃〃澶辫触锛岃绋嶅悗閲嶈瘯锛�");
+        }
+        /*String curremak = "銆�"+param.getLoginUserInfo().getRealname()
+                +"銆戜簬"+ DateUtil.getPlusTime2(new Date()) +"杩涜浜�"+(Constants.equalsInteger(param.getStatus(),Constants.ONE)?"銆愬悎闂搞��":"銆愬垎闂搞��")+"鎿嶄綔,寮�鍏炽��"+param.getChannelNo()+"銆戯紱";
+        deviceMapper.update(null,new UpdateWrapper<Device>().lambda()
+                .set(Device::getRemark,curremak)
+                .set(Device::getEditDate,new Date())
+                .set(Device::getEdirot,param.getLoginUserInfo().getId())
+                .eq(Device::getId,param.getId()));
+        DeviceData data = new DeviceData();
+        data.setCreateDate(new Date());
+        data.setEditDate(new Date());
+        data.setCreator(param.getLoginUserInfo().getId());
+        data.setEditor(param.getLoginUserInfo().getId());
+        data.setDeviceId(param.getId()+"");
+        data.setDataType(Constants.ONE);//
+        data.setVal1("杩滅▼鎺у埗");
+        data.setVal2(curremak);
+        data.setHappenTime(DateUtil.getPlusTime2(data.getCreateDate()));
+        data.setVal3((Constants.equalsInteger(param.getStatus(),Constants.ONE)?"銆愬悎闂搞��":"銆愬垎闂搞��"));
+        data.setVal4(param.getLoginUserInfo().getRealname());
+        data.setVal5(param.getChannelNo());
+        deviceDataMapper.insert(data);
+*/
     }
 }

--
Gitblit v1.9.3