From a29e0df3c165dfe2ddd825bb340ed480a64865db Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期四, 02 四月 2026 15:02:30 +0800
Subject: [PATCH] 解决冲突

---
 server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceServiceImpl.java |  293 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 264 insertions(+), 29 deletions(-)

diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceServiceImpl.java b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceServiceImpl.java
index 57eeaa2..2845622 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceServiceImpl.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceServiceImpl.java
@@ -2,29 +2,36 @@
 
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.doumee.biz.system.SystemDictDataBiz;
-import com.doumee.core.constants.ResponseStatus;
-import com.doumee.core.exception.BusinessException;
-import com.doumee.core.haikang.model.HKConstants;
-import com.doumee.core.haikang.model.param.BaseResponse;
-import com.doumee.core.haikang.model.param.request.*;
-import com.doumee.core.model.PageData;
-import com.doumee.core.model.PageWrap;
-import com.doumee.core.utils.Constants;
-import com.doumee.core.utils.Utils;
-import com.doumee.dao.business.DeviceMapper;
-import com.doumee.dao.business.PlatformBroadcastLogMapper;
-import com.doumee.dao.business.model.Device;
-import com.doumee.dao.business.model.PlatformBroadcastLog;
-import com.doumee.service.business.DeviceService;
 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.doumee.biz.system.SystemDictDataBiz;
+import com.doumee.core.constants.ResponseStatus;
+import com.doumee.core.device.WaterElectricityUtil;
+import com.doumee.core.exception.BusinessException;
+import com.doumee.core.haikang.model.HKConstants;
+import com.doumee.core.haikang.model.param.BaseResponse;
+import com.doumee.core.haikang.model.param.request.CustomBroadcastRequest;
+import com.doumee.core.haikang.model.param.request.TransparentChannelSingleRequest;
+import com.doumee.core.haikang.service.HKService;
+import com.doumee.core.model.LoginUserInfo;
+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.core.utils.Utils;
+import com.doumee.dao.business.*;
+import com.doumee.dao.business.model.Device;
+import com.doumee.dao.business.model.DeviceData;
+import com.doumee.dao.business.model.PlatformBroadcastLog;
+import com.doumee.service.business.DeviceService;
 import com.doumee.service.business.impl.hksync.HkSyncPushServiceImpl;
+import lombok.extern.slf4j.Slf4j;
 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 java.util.*;
@@ -35,25 +42,54 @@
  * @date 2023/11/30 15:33
  */
 @Service
+@Slf4j
 public class DeviceServiceImpl implements DeviceService {
 
     @Autowired
     private DeviceMapper deviceMapper;
     @Autowired
+    private DeviceDataMapper deviceDataMapper;
+    @Autowired
+    private PlatformMapper platformMapper;
+    @Autowired
+    private PlatformDeviceMapper platformDeviceMapper;
+    @Autowired
     private SystemDictDataBiz systemDictDataBiz;
     @Autowired
     private PlatformBroadcastLogMapper platformBroadcastLogMapper;
+    @Autowired
+    private InterfaceLogMapper interfaceLogMapper;
 
 
     @Override
-    public Integer create(Device device) {
-        deviceMapper.insert(device);
-        return device.getId();
+    public Integer create(Device model) {
+        model.setCreator(model.getLoginUserInfo().getId()+"");
+        model.setEdirot(model.getCreator());
+        model.setIsdeleted(Constants.ZERO);
+        model.setEditDate(new Date());
+        model.setCreateDate(model.getEditDate());
+        if(model.getDoorNameObj()!=null &&
+                (Constants.equalsInteger(model.getType(),Constants.DEVICE_TYPE.duanluqi)
+                        ||Constants.equalsInteger(model.getType(),Constants.DEVICE_TYPE.dianbiao))){
+            model.setDoorName(JSONObject.toJSONString(model.getDoorNameObj()));
+            if(StringUtils.isNotBlank(model.getLevel())){
+                if(getNumberByStr(model.getLevel()) <300){
+                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝鎺у埗鏃堕暱蹇呴』澶т簬绛変簬300绉�");
+                }
+            }
+        }
+        deviceMapper.insert(model);
+        return model.getId();
     }
 
     @Override
-    public void deleteById(Integer id) {
-        deviceMapper.deleteById(id);
+    public void deleteById(Integer id, LoginUserInfo userInfo) {
+        Device update = new Device();
+        update.setEdirot(userInfo.getId()+"");
+        update.setEditDate(new Date());
+        update.setIsdeleted(Constants.ONE);
+        update.setId(id);
+        deviceMapper.updateById(update);
     }
 
     @Override
@@ -63,16 +99,30 @@
     }
 
     @Override
-    public void deleteByIdInBatch(List<Integer> ids) {
+    public void deleteByIdInBatch(List<Integer> ids, LoginUserInfo userInfo) {
         if (CollectionUtils.isEmpty(ids)) {
             return;
         }
-        deviceMapper.deleteBatchIds(ids);
+        for(Integer id :ids){
+            deleteById(id,userInfo);
+        }
     }
 
     @Override
     public void updateById(Device device) {
+        device.setEdirot(device.getLoginUserInfo().getId()+"");
+        device.setEditDate(new Date());
+        if(device.getDoorNameObj()!=null &&
+                (Constants.equalsInteger(device.getType(),Constants.DEVICE_TYPE.duanluqi)
+                        ||Constants.equalsInteger(device.getType(),Constants.DEVICE_TYPE.dianbiao))){
+            device.setDoorName(JSONObject.toJSONString(device.getDoorNameObj()));
+        }
+        Device model = deviceMapper.selectById(device.getId());
+        if(model ==null){
+            throw  new BusinessException(ResponseStatus.DATA_EMPTY);
+        }
         deviceMapper.updateById(device);
+
     }
 
     @Override
@@ -87,7 +137,16 @@
 
     @Override
     public Device findById(Integer id) {
-        return deviceMapper.selectById(id);
+        Device d = deviceMapper.selectById(id);
+        if(StringUtils.isNotBlank(d.getDoorName()) &&Constants.equalsInteger(d.getType(),Constants.DEVICE_TYPE.duanluqi)){
+            try {
+                //鏂矾鍣ㄨ澶囧弬鏁�
+                d.setDoorNameObj(JSONObject.parseObject(d.getDoorName()));
+            }catch (Exception e){
+
+            }
+        }
+        return d;
     }
 
     @Override
@@ -98,6 +157,7 @@
 
     @Override
     public List<Device> findList(Device device) {
+        device.setIsdeleted(Constants.ZERO);
         QueryWrapper<Device> wrapper = new QueryWrapper<>(device);
         return deviceMapper.selectList(wrapper);
     }
@@ -107,12 +167,25 @@
         LambdaQueryWrapper<Device> wrapper = new LambdaQueryWrapper<>(param);
         wrapper.select(Device::getId, Device::getName, Device::getDoorName,Device::getRegionPathName, Device::getRegionName);
         wrapper.eq(null != param.getType(),Device::getType,param.getType())
-               .eq(null !=param.getIsdeleted(),Device::getIsdeleted,param.getIsdeleted())
-               .eq(Objects.isNull(param.getIsdeleted()),Device::getIsdeleted,Constants.ZERO)
-               .eq(null != param.getHkStatus(),Device::getHkStatus,param.getHkStatus());
-        return deviceMapper.selectList(wrapper);
+                .eq(null !=param.getIsdeleted(),Device::getIsdeleted,param.getIsdeleted())
+                .eq(Objects.isNull(param.getIsdeleted()),Device::getIsdeleted,Constants.ZERO)
+                .eq(null != param.getHkStatus(),Device::getHkStatus,param.getHkStatus());
+        List<Device> list = deviceMapper.selectList(wrapper);
+        if(list!=null){
+            for(Device d : list){
+                if(StringUtils.isNotBlank(d.getDoorName()) &&Constants.equalsInteger(d.getType(),Constants.DEVICE_TYPE.duanluqi)){
+                    try {
+                        //鏂矾鍣ㄨ澶囧弬鏁�
+                        d.setDoorNameObj(JSONObject.parseObject(d.getDoorName()));
+                    }catch (Exception e){
+
+                    }
+                }
+            }
+        }
+        return list;
     }
-  
+
     @Override
     public PageData<Device> findPage(PageWrap<Device> pageWrap) {
         IPage<Device> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
@@ -147,6 +220,12 @@
         }
         if (pageWrap.getModel().getName() != null) {
             queryWrapper.lambda().like(Device::getName, pageWrap.getModel().getName());
+        }
+        if (pageWrap.getModel().getDoorNo() != null) {
+            queryWrapper.lambda().like(Device::getDoorNo, pageWrap.getModel().getDoorNo());
+        }
+        if (pageWrap.getModel().getNo() != null) {
+            queryWrapper.lambda().like(Device::getNo, pageWrap.getModel().getNo());
         }
         if (pageWrap.getModel().getDoorName() != null) {
             queryWrapper.lambda().like(Device::getDoorName, pageWrap.getModel().getDoorName());
@@ -219,7 +298,22 @@
                 queryWrapper.orderByAsc(sortData.getProperty());
             }
         }
-        return PageData.from(deviceMapper.selectPage(page, queryWrapper));
+        IPage<Device> result = deviceMapper.selectPage(page, queryWrapper);
+        if(result!=null){
+            for(Device d : result.getRecords()){
+                if(StringUtils.isNotBlank(d.getDoorName())
+                        && (Constants.equalsInteger(d.getType(),Constants.DEVICE_TYPE.duanluqi)||
+                        Constants.equalsInteger(d.getType(),Constants.DEVICE_TYPE.dianbiao))){
+                    try {
+                        //鏂矾鍣ㄨ澶囧弬鏁�
+                        d.setDoorNameObj(JSONObject.parseObject(d.getDoorName()));
+                    }catch (Exception e){
+
+                    }
+                }
+            }
+        }
+        return PageData.from(result);
     }
 
     @Override
@@ -227,6 +321,123 @@
         QueryWrapper<Device> wrapper = new QueryWrapper<>(device);
         return deviceMapper.selectCount(wrapper);
     }
+
+    @Override
+    public void setBroadcaseBobao(Device model){
+        List<String> ids = new ArrayList<>();
+        ids.add(model.getHkId());
+        CustomBroadcastRequest request = new CustomBroadcastRequest();
+        request.setAudioPointIndexCode(ids);
+        request.setPlayDuration(15);//鍗曚綅绉�
+        request.setBroadCastMode("tts");
+        request.setPriority(1);
+        request.setState(1);//鎾斁/鍋滄鏍囪瘑 1-鎾斁锛�0-鍋滄
+        request.setPlayTtsContent(model.getSendInfo());
+        BaseResponse response =  HKService.customBroadcast(request);
+        if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){
+            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"鍙戦�佸け璐ワ細"+ JSONObject.toJSONString(response));
+        }
+    }
+
+    @Override
+    public   void updateUsedById(Device param){
+        Device model = deviceMapper.selectById(param.getId());
+        if(model ==null && Constants.equalsInteger(param.getType(),Constants.DEVICE_TYPE.duanluqi)){
+            throw  new BusinessException(ResponseStatus.DATA_EMPTY);
+        }
+
+        this.updateById(param);
+    }
+
+    @Override
+    public  void dianbaoCmd(Device param){
+        Device model = deviceMapper.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);
+
+    }
+    @Override
+    @Transactional
+    public  void dianbiaoData(Device param){
+        Device model = deviceMapper.selectById(param.getId());
+        if(model ==null && Constants.equalsInteger(param.getType(),Constants.DEVICE_TYPE.dianbiao)){
+            throw  new BusinessException(ResponseStatus.DATA_EMPTY);
+        }
+        try {
+            Map<String, Object>  readData=  WaterElectricityUtil.electricityData(model.getIp(),Integer.parseInt(model.getPort()),model.getNo());
+            if(readData!=null){
+                String curremak = "銆�"+param.getLoginUserInfo().getRealname()
+                        +"銆戜簬"+ DateUtil.getPlusTime2(new Date()) +"杩涜浜嗘暟鎹鍙栨搷浣�";
+                Date time =(Date) readData.get("time");
+                String total = (Double) readData.get("total")+"";
+                String status =  (String) readData.get("status");
+                model.setHkDate(new Date());//鏈�杩戝悓姝ユ椂闂�
+                model.setOnline(Constants.ONE);//鏍囪瘑璁惧鍦ㄧ嚎
+                model.setRemark(curremak);
+
+                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.ZERO);//
+                data.setVal1(total);
+                data.setVal2(status);
+                data.setHappenTime(DateUtil.getPlusTime2(data.getCreateDate()));
+                data.setVal3(DateUtil.getPlusTime2(time));
+                data.setVal4(param.getLoginUserInfo().getRealname());
+                data.setVal5(param.getNo());//鍦板潃鍩�
+                deviceDataMapper.insert(data);
+                deviceMapper.updateById(model);
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+            log.error("鐢佃〃鏁版嵁璇诲彇澶辫触锛�"+e.getMessage());
+            throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"璇诲彇鐢佃〃鏁版嵁澶辫触锛�");
+        }
+    }
+
 
     @Override
     public void setLedContent(TransparentChannelSingleRequest model) {
@@ -250,4 +461,28 @@
             throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "瀵逛笉璧凤紝灞忓箷鍐呭璁剧疆澶辫触"+(log!=null?log.getHkInfo():""));
         }
     }
+
+
+    private DeviceData getLastDataByVal1(String b, List<DeviceData> dataList,double limit) {
+        List<DeviceData> list = new ArrayList<>();
+        for(DeviceData d :dataList){
+            if(StringUtils.equals(d.getVal1(),b)){
+                if(limit <= getNumberByStr(d.getVal2())){
+                    //濡傛灉鏈夊疄鏃剁數娴佸�煎ぇ浜庣┖闂查槇鍊硷紝鍒欒〃绀哄伐浣滀腑锛屼笉鍋氬鐞�
+                    return null;
+                }
+                list.add(d);
+            }
+        }
+        return list.size()>0?list.get(0):null;
+    }
+
+    private double getNumberByStr(String level) {
+        try {
+            return Double.parseDouble(level);
+        }catch (Exception e){
+
+        }
+        return 0;
+    }
 }

--
Gitblit v1.9.3