From dc533427ccc2a3b2fc19334dbb6fc87f9399d5d0 Mon Sep 17 00:00:00 2001
From: lishuai <260038442@qq.com>
Date: 星期五, 15 十二月 2023 14:17:13 +0800
Subject: [PATCH] 事件图片处理

---
 server/dmvisit_service/src/main/java/com/doumee/core/utils/Constants.java                         |    3 +
 server/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceRoleServiceImpl.java  |    6 +-
 server/dmvisit_service/src/main/java/com/doumee/dao/system/SystemDictDataMapper.java              |    5 ++
 server/dmvisit_admin/src/main/java/com/doumee/api/business/DeviceController.java                  |    7 +++
 server/dmvisit_service/src/main/java/com/doumee/service/business/DeviceService.java               |   10 ++++
 server/dmvisit_service/src/main/resources/mappers/SystemDictDataMapper.xml                        |   14 +++++++
 server/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceEventServiceImpl.java |   44 +++++++++++++++++++++-
 server/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceServiceImpl.java      |   16 ++++++++
 8 files changed, 99 insertions(+), 6 deletions(-)

diff --git a/server/dmvisit_admin/src/main/java/com/doumee/api/business/DeviceController.java b/server/dmvisit_admin/src/main/java/com/doumee/api/business/DeviceController.java
index 70c7f05..b143bea 100644
--- a/server/dmvisit_admin/src/main/java/com/doumee/api/business/DeviceController.java
+++ b/server/dmvisit_admin/src/main/java/com/doumee/api/business/DeviceController.java
@@ -87,4 +87,11 @@
     public ApiResponse findById(@PathVariable Integer id) {
         return ApiResponse.success(deviceService.findById(id));
     }
+
+    @ApiOperation("鑾峰彇闂ㄧ闆嗗悎-鎻愪緵缁欓棬绂佺粍")
+    @PostMapping("/getList")
+    //@RequiresPermissions("business:device:query")
+    public ApiResponse findList(@RequestBody Device device) {
+        return ApiResponse.success(deviceService.findIdAndNameList(device));
+    }
 }
diff --git a/server/dmvisit_service/src/main/java/com/doumee/core/utils/Constants.java b/server/dmvisit_service/src/main/java/com/doumee/core/utils/Constants.java
index 4949a87..abdc922 100644
--- a/server/dmvisit_service/src/main/java/com/doumee/core/utils/Constants.java
+++ b/server/dmvisit_service/src/main/java/com/doumee/core/utils/Constants.java
@@ -57,6 +57,9 @@
     // ERP ACCESS_SECRET
     public static final String ERP_ACCESS_SECRET = "ERP_ACCESS_SECRET";
 
+    // FTP鏂囦欢鏈嶅姟鍣ㄨ祫婧愯闂湴鍧�
+    public static final String FTP_RESOURCE_PATH = "FTP_RESOURCE_PATH";
+
     public static  Date  getBirthdyByCardNo(String idCard){
     if(idCard ==null || idCard.length()<14){
         return null;
diff --git a/server/dmvisit_service/src/main/java/com/doumee/dao/system/SystemDictDataMapper.java b/server/dmvisit_service/src/main/java/com/doumee/dao/system/SystemDictDataMapper.java
index 1a11139..9e0b291 100644
--- a/server/dmvisit_service/src/main/java/com/doumee/dao/system/SystemDictDataMapper.java
+++ b/server/dmvisit_service/src/main/java/com/doumee/dao/system/SystemDictDataMapper.java
@@ -4,6 +4,7 @@
 import com.doumee.dao.system.dto.QuerySystemDictDataDTO;
 import com.doumee.dao.system.model.SystemDictData;
 import com.doumee.dao.system.vo.SystemDictDataListVO;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -16,4 +17,8 @@
      */
     List<SystemDictDataListVO> selectManageList(QuerySystemDictDataDTO dto);
 
+    /**
+     * 鏍规嵁Code 鏌ヨ瀛楀吀琛╟ode瀵瑰簲鐨勫��
+     */
+    List<SystemDictData> list(@Param("codes") List<String> codes);
 }
diff --git a/server/dmvisit_service/src/main/java/com/doumee/service/business/DeviceService.java b/server/dmvisit_service/src/main/java/com/doumee/service/business/DeviceService.java
index 229c4b8..272e3e1 100644
--- a/server/dmvisit_service/src/main/java/com/doumee/service/business/DeviceService.java
+++ b/server/dmvisit_service/src/main/java/com/doumee/service/business/DeviceService.java
@@ -1,5 +1,6 @@
 package com.doumee.service.business;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.doumee.core.haikang.model.param.request.AcsDeviceListRequest;
 import com.doumee.core.model.PageData;
 import com.doumee.core.model.PageWrap;
@@ -79,7 +80,14 @@
      * @return List<Device>
      */
     List<Device> findList(Device device);
-  
+
+    /**
+     * 鏍规嵁鏉′欢鏌ヨ,鎵�鏈夐棬绂佺殑ID鍜屽悕绉�
+     * @param device
+     * @return
+     */
+    List<Device> findIdAndNameList(Device device);
+
     /**
      * 鍒嗛〉鏌ヨ
      *
diff --git a/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceEventServiceImpl.java b/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceEventServiceImpl.java
index 6b0577f..4ff5d86 100644
--- a/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceEventServiceImpl.java
+++ b/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceEventServiceImpl.java
@@ -6,6 +6,7 @@
 import cn.hutool.core.util.ReUtil;
 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.admin.request.DeviceEventQuery;
 import com.doumee.dao.admin.response.DeviceEventDTO;
@@ -14,19 +15,24 @@
 import com.doumee.dao.business.model.Company;
 import com.doumee.dao.business.model.DeviceEvent;
 import com.doumee.dao.business.model.Member;
+import com.doumee.dao.system.SystemDictDataMapper;
+import com.doumee.dao.system.model.SystemDictData;
+import com.doumee.dao.system.vo.SystemDictDataListVO;
 import com.doumee.service.business.DeviceEventService;
 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 com.sun.org.apache.xerces.internal.xs.StringList;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 
 /**
  * 闂ㄧ浜嬩欢鎺ㄩ�佽褰曡〃Service瀹炵幇
@@ -42,6 +48,9 @@
 
     @Autowired
     private DeviceEventJoinMapper deviceEventJoinMapper;
+
+    @Autowired
+    private SystemDictDataMapper systemDictDataMapper;
 
     @Override
     public Integer create(DeviceEvent deviceEvent) {
@@ -322,6 +331,37 @@
                                                 pageWrap.getModel().getEndTime());
         queryWrapper.orderByDesc(DeviceEvent::getHappenTime);
         IPage<DeviceEventDTO> deviceEventDTOIPage = deviceEventJoinMapper.selectJoinPage(page, DeviceEventDTO.class, queryWrapper);
+        if(null != deviceEventDTOIPage && deviceEventDTOIPage.getRecords().size() > 0) {
+            deviceEventDTOIPage.setRecords(newDeviceEvent(deviceEventDTOIPage.getRecords()));
+        }
         return PageData.from(deviceEventDTOIPage);
     }
+
+    // 瀵瑰浘鐗囪繘琛屽垽鏂鐞�
+    private List<DeviceEventDTO> newDeviceEvent(List<DeviceEventDTO> DeviceEventDTOList) {
+        List<DeviceEventDTO> newDeviceEventDTOS = new ArrayList<>();
+        for (DeviceEventDTO dto:DeviceEventDTOList) {
+           if(StringUtils.isNotBlank(dto.getExtEventPictureURL())) {
+               String extEventPictureURL = dto.getExtEventPictureURL();
+               // 浣跨敤split("/")灏哢RL鎸夌収"/"杩涜鍒嗗壊鎴愬涓儴鍒�
+               String[] parts = extEventPictureURL.split("\\\\");
+               String newStr = parts[0];
+               boolean number = Validator.isNumber(newStr);
+               if(number) {
+                   List<String> codes = Arrays.asList(Constants.FTP_RESOURCE_PATH,Constants.DEVICE_EVENT_IMG);
+                   List<SystemDictData> list = systemDictDataMapper.list(codes);
+                   if(null != list && list.size() > 0) {
+                       Map<String,SystemDictData> dataMap = list.stream().collect(Collectors.toMap(SystemDictData::getLabel, Function.identity()));
+                       dto.setExtEventPictureURL(dataMap.get(Constants.FTP_RESOURCE_PATH).getCode()
+                                                 +dataMap.get(Constants.DEVICE_EVENT_IMG).getCode()
+                                                 +dto.getExtEventPictureURL());
+                   }
+               }else {
+                   dto.setExtEventPictureURL(null);
+               }
+           }
+            newDeviceEventDTOS.add(dto);
+        }
+        return newDeviceEventDTOS;
+    }
 }
diff --git a/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceRoleServiceImpl.java b/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceRoleServiceImpl.java
index a5b0b7d..e34a72e 100644
--- a/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceRoleServiceImpl.java
+++ b/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceRoleServiceImpl.java
@@ -56,7 +56,7 @@
                 .eq(DeviceRole::getStatus,Constants.ONE);
         List<DeviceRole> deviceRoles = deviceRoleMapper.selectList(query);
         if (CollectionUtils.isNotEmpty(deviceRoles) && Constants.equalsInteger(Constants.ONE,deviceRole.getStatus())){
-            throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"鍚屼竴涓敤鎴风被鍨嬶紝鍙兘鏈変竴涓粯璁よ鑹�");
+            throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"绠$悊鍐呴儴鍛樺伐鍙兘鏈変竴涓粯璁ら棬绂佺粍");
         }
 
         LoginUserInfo loginUserInfo = (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
@@ -113,7 +113,7 @@
                 .eq(DeviceRole::getStatus,Constants.ONE);
         List<DeviceRole> deviceRoles = deviceRoleMapper.selectList(query);
         if (CollectionUtils.isNotEmpty(deviceRoles) && Constants.equalsInteger(Constants.ONE,deviceRole.getStatus())){
-            throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"鍚屼竴涓敤鎴风被鍨嬶紝鍙兘鏈変竴涓粯璁よ鑹�");
+            throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"绠$悊鍐呴儴鍛樺伐鍙兘鏈変竴涓粯璁ら棬绂佺粍");
         }
         deviceRole.setIsDefault(Constants.equalsInteger(Constants.ONE,deviceRole.getStatus()) ? 0 : 1);
         deviceRoleMapper.updateById(deviceRole);
@@ -128,7 +128,7 @@
                 .eq(DeviceRole::getStatus,Constants.ONE);
         List<DeviceRole> deviceRoles = deviceRoleMapper.selectList(query);
         if (CollectionUtils.isNotEmpty(deviceRoles) && Constants.equalsInteger(Constants.ONE,deviceRole.getStatus())){
-            throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"鍚屼竴涓敤鎴风被鍨嬶紝鍙兘鏈変竴涓粯璁よ鑹�");
+            throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"绠$悊鍐呴儴鍛樺伐鍙兘鏈変竴涓粯璁ら棬绂佺粍");
         }
         LoginUserInfo loginUserInfo = (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
         DeviceRole update = new DeviceRole();
diff --git a/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceServiceImpl.java b/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceServiceImpl.java
index c90c76f..cdf4578 100644
--- a/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceServiceImpl.java
+++ b/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceServiceImpl.java
@@ -1,5 +1,6 @@
 package com.doumee.service.business.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.doumee.core.constants.ResponseStatus;
 import com.doumee.core.exception.BusinessException;
 import com.doumee.core.haikang.model.HKConstants;
@@ -13,7 +14,9 @@
 import com.doumee.core.utils.Constants;
 import com.doumee.core.utils.Utils;
 import com.doumee.dao.business.DeviceMapper;
+import com.doumee.dao.business.model.Company;
 import com.doumee.dao.business.model.Device;
+import com.doumee.dao.business.model.Retention;
 import com.doumee.service.business.DeviceService;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
@@ -28,6 +31,7 @@
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.Objects;
 
 /**
  * 璁惧淇℃伅琛⊿ervice瀹炵幇
@@ -97,6 +101,18 @@
         QueryWrapper<Device> wrapper = new QueryWrapper<>(device);
         return deviceMapper.selectList(wrapper);
     }
+
+    @Override
+    public List<Device> findIdAndNameList(Device param) {
+        LambdaQueryWrapper<Device> wrapper = new LambdaQueryWrapper<>(param);
+        wrapper.select(Device::getId, Device::getName);
+        if(null != param.getType() && null != param.getIsdeleted() && null != param.getHkStatus()) {
+            wrapper.eq(Device::getType,param.getType())
+                   .eq(Device::getIsdeleted,param.getIsdeleted())
+                   .eq(Device::getHkStatus,param.getHkStatus());
+        }
+        return deviceMapper.selectList(wrapper);
+    }
   
     @Override
     public PageData<Device> findPage(PageWrap<Device> pageWrap) {
diff --git a/server/dmvisit_service/src/main/resources/mappers/SystemDictDataMapper.xml b/server/dmvisit_service/src/main/resources/mappers/SystemDictDataMapper.xml
index 6de601b..ae3a515 100644
--- a/server/dmvisit_service/src/main/resources/mappers/SystemDictDataMapper.xml
+++ b/server/dmvisit_service/src/main/resources/mappers/SystemDictDataMapper.xml
@@ -29,5 +29,19 @@
       </if>
     </where>
   </select>
+  <select id="list" resultType="com.doumee.dao.system.vo.SystemDictDataListVO">
+    SELECT
+      dict_data.`ID`, dict_data.`DICT_ID`, dict_data.`CODE`, dict_data.`LABEL`
+    FROM SYSTEM_DICT_DATA dict_data
+    <where>
+      dict_data.DELETED = 0
+      <if test="codes != null and codes.size > 0">
+        AND dict_data.`LABEL` in
+        <foreach collection="codes" index="index" item="code" open="(" separator="," close=")">
+          #{code}
+        </foreach>
+      </if>
+    </where>
+  </select>
 
 </mapper>

--
Gitblit v1.9.3