Ver Fonte

新增sql,设备导入

luowei há 2 anos atrás
pai
commit
8742660b89
16 ficheiros alterados com 387 adições e 30 exclusões
  1. 60 1
      project_data/sql/0.0.2/soc/soc.sql
  2. 129 8
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/controller/SysDeviceController.java
  3. 4 2
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/mapper/SysDeviceMapper.java
  4. 7 0
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/mapper/SysDictDataMapper.java
  5. 1 0
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/mapper/SysOrgMapper.java
  6. 16 0
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/ISysDeviceService.java
  7. 1 1
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/ISysDictDataService.java
  8. 1 0
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/ISysOrgService.java
  9. 102 17
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysDeviceServiceImpl.java
  10. 5 0
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysDictDataServiceImpl.java
  11. 6 0
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysOrgServiceImpl.java
  12. 39 0
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/util/DeviceExport.java
  13. 9 0
      soc-modules/soc-modules-system/src/main/resources/mapper/system/SysDeviceMapper.xml
  14. 4 1
      soc-modules/soc-modules-system/src/main/resources/mapper/system/SysDictDataMapper.xml
  15. 3 0
      soc-modules/soc-modules-system/src/main/resources/mapper/system/SysOrgMapper.xml
  16. BIN
      soc-modules/soc-modules-system/src/main/resources/templates/device.xlsx

+ 60 - 1
project_data/sql/0.0.2/soc/soc.sql

@@ -2,6 +2,59 @@
 -- ----------新增表脚本 start ----------------------------
 -- -------------------------------------------------------
 DROP TABLE
+    IF
+    EXISTS `core_evaluate_plan`;
+CREATE TABLE `core_evaluate_plan` (
+                                      `id` BIGINT NOT NULL,
+                                      `org_id` BIGINT DEFAULT NULL COMMENT '机构id',
+                                      `u_id` VARCHAR ( 255 ) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '前端需要的',
+                                      `org_name` VARCHAR ( 255 ) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '机构名称',
+                                      `org_type` VARCHAR ( 2 ) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '机构类型',
+                                      `evaluate_name` VARCHAR ( 255 ) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '外包评价名称',
+                                      `evaluate_cycle` VARCHAR ( 2 ) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '周期',
+                                      `create_time` DATETIME NULL DEFAULT NULL COMMENT '创建时间',
+                                      `update_time` DATETIME NULL DEFAULT NULL COMMENT '修改时间',
+                                      `is_deleted` VARCHAR ( 1 ) CHARACTER
+                                          SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '\0' COMMENT '是否删除',
+                                      `create_by` VARCHAR ( 255 ) CHARACTER
+                                          SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
+                                      `update_by` VARCHAR ( 32 ) CHARACTER
+                                          SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
+                                      PRIMARY KEY ( `id` )
+) ENGINE = INNODB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '外包评价计划';
+
+DROP TABLE
+    IF
+    EXISTS `core_evaluate_role`;
+CREATE TABLE `core_evaluate_role` (
+                                      `id` BIGINT NOT NULL,
+                                      `evaluate_id` BIGINT DEFAULT NULL COMMENT '评价id',
+                                      `role_id` BIGINT DEFAULT NULL COMMENT '角色id',
+                                      PRIMARY KEY ( `id` )
+) ENGINE = INNODB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '外包评价计划和角色绑定';
+
+DROP TABLE
+    IF
+    EXISTS `core_evaluate_content`;
+CREATE TABLE `core_evaluate_content` (
+                                         `id` BIGINT NOT NULL,
+                                         `code` BIGINT DEFAULT NULL COMMENT '编号',
+                                         `content_type` VARCHAR ( 2 ) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '评价类型',
+                                         `content` VARCHAR ( 1000 ) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '内容',
+                                         PRIMARY KEY ( `id` )
+) ENGINE = INNODB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '外包评价内容';
+
+DROP TABLE
+    IF
+    EXISTS `core_evaluate_plan_content`;
+CREATE TABLE `core_evaluate_plan_content` (
+                                              `id` BIGINT NOT NULL,
+                                              `evaluate_id` BIGINT DEFAULT NULL COMMENT '评价id',
+                                              `content_id` BIGINT DEFAULT NULL COMMENT '内容id',
+                                              PRIMARY KEY ( `id` )
+) ENGINE = INNODB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '外包评价计划和内容绑定';
+
+DROP TABLE
 IF
 	EXISTS `sync_fjnx_org_move`;
 CREATE TABLE `sync_fjnx_org_move` (
@@ -1437,7 +1490,7 @@ INSERT INTO sys_config (config_name, config_key, config_value, config_type, crea
 DELETE from `sys_dict_type` WHERE dict_type='question_confirm_status' or dict_type='question_reform_status';
 INSERT INTO `sys_dict_type` (`dict_name`, `dict_type`, `status`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES ( '问题确认状态', 'question_confirm_status', '0', '超级管理员', '2023-09-13 18:14:59', '', NULL, NULL);
 INSERT INTO `sys_dict_type` (`dict_name`, `dict_type`, `status`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES ( '问题整改状态', 'question_reform_status', '0', '超级管理员', '2023-09-13 18:15:18', '', NULL, NULL);
-delete  from sys_dict_type WHERE dict_type in ('send_time_type' ,'message_type' ,'send_status' ,'evaluate_cycle');
+delete  from sys_dict_type WHERE dict_type in ('send_time_type' ,'message_type' ,'send_status' ,'evaluate_cycle','evaluate_type');
 INSERT INTO `sys_dict_type` (`dict_name`, `dict_type`, `status`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`)
 VALUES ( '发送时间类型', 'send_time_type', '0', '超级管理员', '2023-09-13 18:14:59', '', NULL, NULL);
 INSERT INTO `sys_dict_type` (`dict_name`, `dict_type`, `status`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`)
@@ -1446,6 +1499,8 @@ INSERT INTO `sys_dict_type` (`dict_name`, `dict_type`, `status`, `create_by`, `c
 VALUES ( '发送状态', 'send_status', '0', '超级管理员', '2023-09-13 18:14:59', '', NULL, NULL);
 INSERT INTO `sys_dict_type` (`dict_name`, `dict_type`, `status`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`)
 VALUES ( '评价周期', 'evaluate_cycle', '0', '超级管理员', '2023-09-13 18:14:59', '', NULL, NULL);
+INSERT INTO `sys_dict_type` (`dict_name`, `dict_type`, `status`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`)
+VALUES ( '评价类型', 'evaluate_type', '0', '超级管理员', '2023-09-13 18:14:59', '', NULL, NULL);
 
 DELETE from `sys_dict_data` WHERE dict_type in ('post_no_pass','question_confirm_status','question_reform_status','send_status','message_type','send_time_type','evaluate_cycle');
 INSERT INTO `sys_dict_data` (`dict_sort`, `dict_label`, `dict_value`, `dict_type`, `css_class`, `list_class`, `is_default`, `status`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`)
@@ -1455,6 +1510,10 @@ VALUES ( 1, '每季度', '1', 'evaluate_cycle', NULL, 'default', 'N', '0', '超
 INSERT INTO `sys_dict_data` (`dict_sort`, `dict_label`, `dict_value`, `dict_type`, `css_class`, `list_class`, `is_default`, `status`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`)
 VALUES ( 2, '每年', '2', 'evaluate_cycle', NULL, 'default', 'N', '0', '超级管理员', '2023-09-13 18:15:44', '', NULL, NULL);
 
+INSERT INTO `sys_dict_data` (`dict_sort`, `dict_label`, `dict_value`, `dict_type`, `css_class`, `list_class`, `is_default`, `status`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`)
+VALUES ( 1, '文本输入', '1', 'evaluate_type', NULL, 'default', 'N', '0', '超级管理员', '2023-09-13 18:15:44', '', NULL, NULL);
+INSERT INTO `sys_dict_data` (`dict_sort`, `dict_label`, `dict_value`, `dict_type`, `css_class`, `list_class`, `is_default`, `status`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`)
+VALUES ( 2, '评价打分', '2', 'evaluate_type', NULL, 'default', 'N', '0', '超级管理员', '2023-09-13 18:15:44', '', NULL, NULL);
 INSERT INTO `sys_dict_data` (`dict_sort`, `dict_label`, `dict_value`, `dict_type`, `css_class`, `list_class`, `is_default`, `status`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES ( 0, '待确认', '0', 'question_confirm_status', NULL, 'default', 'N', '0', '超级管理员', '2023-09-13 18:15:44', '', NULL, NULL);
 INSERT INTO `sys_dict_data` (`dict_sort`, `dict_label`, `dict_value`, `dict_type`, `css_class`, `list_class`, `is_default`, `status`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (1, '提出异议', '1', 'question_confirm_status', NULL, 'default', 'N', '0', '超级管理员', '2023-09-13 18:16:01', '', NULL, NULL);
 INSERT INTO `sys_dict_data` (`dict_sort`, `dict_label`, `dict_value`, `dict_type`, `css_class`, `list_class`, `is_default`, `status`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES ( 2, '已确认', '2', 'question_confirm_status', NULL, 'default', 'N', '0', '超级管理员', '2023-09-13 18:16:18', '', NULL, NULL);

+ 129 - 8
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/controller/SysDeviceController.java

@@ -1,25 +1,33 @@
 package com.xunmei.system.controller;
 
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
+import java.util.UUID;
 import java.util.stream.Collectors;
 
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.context.AnalysisContext;
+import com.alibaba.excel.event.AnalysisEventListener;
 import com.xunmei.common.core.vo.IdNameVo;
 import com.xunmei.common.security.annotation.InnerAuth;
 import com.xunmei.system.api.domain.SysDevice;
 import com.xunmei.system.api.domain.SysDictData;
 import com.xunmei.system.api.domain.SysOrg;
 import com.xunmei.system.api.domain.SysRole;
+import com.xunmei.system.domain.SysUserRole;
+import com.xunmei.system.service.ISysDictDataService;
 import com.xunmei.system.service.ISysDictTypeService;
+import com.xunmei.system.service.ISysOrgService;
 import com.xunmei.system.service.impl.SysDeviceServiceImpl;
+import com.xunmei.system.util.DeviceExport;
+import com.xunmei.system.util.UserExport;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.*;
 import com.xunmei.common.log.annotation.Log;
 import com.xunmei.common.log.enums.BusinessType;
 import com.xunmei.common.security.annotation.RequiresPermissions;
@@ -29,6 +37,9 @@ import com.xunmei.common.core.web.domain.AjaxResult;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import com.xunmei.common.core.web.page.TableDataInfo;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletResponse;
 
 /**
  * 【请填写功能名称】Controller
@@ -44,6 +55,11 @@ public class SysDeviceController extends BaseController {
     private ISysDeviceService sysDeviceService;
     @Autowired
     private ISysDictTypeService dictTypeService;
+    @Autowired
+    private ISysOrgService sysOrgService;
+    @Autowired
+    private ISysDictDataService sysDictDataService;
+
     /**
      * 查询【请填写功能名称】列表
      */
@@ -158,4 +174,109 @@ public class SysDeviceController extends BaseController {
     public AjaxResult remove(@PathVariable Long[] ids) {
         return toAjax(sysDeviceService.deleteSysDeviceByIds(ids));
     }
+
+    /**
+     * 导入
+     */
+    //@RequiresPermissions("system:device:importData")
+    @ResponseBody
+    @PostMapping("/importData")
+    @Transactional(rollbackFor = {RuntimeException.class, Exception.class})
+    public AjaxResult importData(MultipartFile file, boolean updateSupport) {
+        List<DeviceExport> list = new ArrayList<>();
+        // 读取excel
+        EasyExcel.read(multipartFileToFile(file), DeviceExport.class, new AnalysisEventListener<DeviceExport>() {
+
+            @Override
+            public void invoke(DeviceExport deviceExport, AnalysisContext analysisContext) {
+                list.add(deviceExport);
+            }
+
+            @Override
+            public void doAfterAllAnalysed(AnalysisContext analysisContext) {
+                for (DeviceExport d : list) {
+                    SysDevice sysDevice = new SysDevice();
+                    BeanUtils.copyProperties(d, sysDevice);
+                    sysDevice.setDelFlag("0");
+                    SysOrg sysOrg = sysOrgService.selectByShortName(d.getOrgName());
+                    if (null == d.getDeviceName() || null == d.getOrgName() || null == d.getAssetType() || null == d.getDeviceType()) {
+                        throw new RuntimeException("请完善数据");
+                    }
+                    if (null != sysOrg) {
+                        SysDevice sysDevice1 = sysDeviceService.selectByHostNameAndOrgId(d.getHostName(), sysOrg.getId());
+                        sysDevice.setOrgId(sysOrg.getId());
+                        //查询资产类别
+                        String sys_asset_type = sysDictDataService.selectDictValue("sys_asset_type", d.getAssetType());
+                        if (null == sys_asset_type) {
+                            throw new RuntimeException("设备" + d.getDeviceName() + "的资产类别不正确");
+                        }
+                        sysDevice.setAssetType(sys_asset_type);
+                        //根据资产类别和设备分类查询
+                        List<SysDictData> deviceTypeByAssetType = dictTypeService.getDeviceTypeByAssetType(sys_asset_type);
+                        List<String> collect = deviceTypeByAssetType.stream().map(SysDictData::getDictLabel).collect(Collectors.toList());
+                        if (collect.contains(d.getDeviceType())) {
+                            deviceTypeByAssetType.forEach(de -> {
+                                if (de.getDictLabel().equals(d.getDeviceType())) {
+                                    sysDevice.setDeviceType(de.getDictValue());
+                                }
+                            });
+                        } else {
+                            throw new RuntimeException("设备" + d.getDeviceName() + "的设备分类不正确");
+                        }
+                        //根据机构和主机查询
+                        if (d.getDeviceType().equals("摄像机")) {
+                            if (null != sysDevice1) {
+                                sysDevice.setHostId(sysDevice1.getId());
+                            } else {
+                                throw new RuntimeException("设备" + d.getDeviceName() + "关联主机不正确");
+                            }
+                        }
+                        if (d.getAssetType().equals("消防类")) {
+                            if (null == d.getCheckTime()) {
+                                throw new RuntimeException("设备名称" + d.getDeviceName() + "的有效期至缺失");
+                            }
+                        } else {
+                            sysDevice.setCheckTime(null);
+                        }
+                        SysDevice device = sysDeviceService.checkName(sysDevice.getOrgId(), sysDevice.getDeviceName());
+                        if (null != device) {
+                            throw new RuntimeException("设备名称" + device.getDeviceName() + "已存在");
+                        }
+                        sysDeviceService.insertSysDevice(sysDevice);
+                    } else {
+                        throw new RuntimeException("机构名称" + d.getOrgName() + "不存在");
+                    }
+                }
+            }
+        }).sheet().doRead();
+        return success();
+    }
+
+    @RequiresPermissions("system:device:export")
+    @PostMapping("/downInChargeOfTemplate")
+    public void downInChargeOfTemplate(HttpServletResponse response) throws IOException{
+        sysDeviceService.downInChargeOfTemplate(response);
+    }
+
+    /***
+     * 功能描述:
+     * MultipartFile 转 File
+     * @return: java.io.File
+     */
+    public static File multipartFileToFile(MultipartFile multipartFile) {
+        // 获取文件名
+        String fileName = multipartFile.getOriginalFilename();
+        // 获取文件后缀
+        assert fileName != null;
+        String suffix = fileName.substring(fileName.lastIndexOf("."));
+        // 若需要防止临时文件重复,需要在文件名后加上UUID
+        try {
+            File file = File.createTempFile(fileName.substring(0, fileName.lastIndexOf(".")) + UUID.randomUUID(), suffix);
+            multipartFile.transferTo(file);
+            return file;
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
 }

+ 4 - 2
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/mapper/SysDeviceMapper.java

@@ -26,6 +26,8 @@ public interface SysDeviceMapper extends BaseMapper<SysDevice> {
      */
     SysDevice selectSysDeviceById(Long id);
 
+    SysDevice selectByHostNameAndOrgId(@Param("hostName") String hostName, @Param("orgId") Long orgId);
+
     List<Long> selectVideoChannelByMonitorId(Long monitorId);
 
     /**
@@ -37,13 +39,13 @@ public interface SysDeviceMapper extends BaseMapper<SysDevice> {
     List<SysDevice> getHostByOrgId(Long orgId);
 
     /**
-     *
      * @param orgId
      * @param videoId
      * @return
      */
 
-    List<AccessType> getAccessByVideo(@Param("videoId") Long videoId,@Param("taskId") Long taskId);
+    List<AccessType> getAccessByVideo(@Param("videoId") Long videoId, @Param("taskId") Long taskId);
+
     /**
      * 查询【请填写功能名称】列表
      *

+ 7 - 0
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/mapper/SysDictDataMapper.java

@@ -46,6 +46,13 @@ public interface SysDictDataMapper extends BaseMapper<SysDictData>
      String selectDictLabel(@Param("dictType") String dictType, @Param("dictValue") String dictValue);
 
     /**
+     *
+     * @param dictType
+     * @param dictLabel
+     * @return
+     */
+    String  selectDictValue(@Param("dictType") String dictType, @Param("dictLabel") String dictLabel);
+    /**
      * 根据字典数据ID查询信息
      * 
      * @param dictCode 字典数据ID

+ 1 - 0
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/mapper/SysOrgMapper.java

@@ -18,6 +18,7 @@ import java.util.List;
  */
 @Component
 public interface SysOrgMapper extends BaseMapper<SysOrg> {
+    SysOrg selectByShortName(String name);
     /**
      * 查询【请填写功能名称】
      *

+ 16 - 0
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/ISysDeviceService.java

@@ -1,6 +1,7 @@
 package com.xunmei.system.service;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.List;
 
 import com.baomidou.mybatisplus.extension.service.IService;
@@ -8,6 +9,8 @@ import com.xunmei.common.core.web.page.TableDataInfo;
 import com.xunmei.system.api.domain.SysDevice;
 import com.xunmei.system.vo.area.HostVO;
 
+import javax.servlet.http.HttpServletResponse;
+
 /**
  * 【设备管理】Service接口
  *
@@ -42,6 +45,15 @@ public interface ISysDeviceService extends IService<SysDevice> {
     List<SysDevice> getSysDeviceByHostId(Long hostId, Long monitorId);
 
     /**
+     * 一个机构下名字不重复
+     *
+     * @param orgId
+     * @param name
+     * @return
+     */
+    SysDevice checkName(Long orgId, String name);
+
+    /**
      * 新增【设备管理】
      *
      * @param sysDevice 【设备管理】
@@ -49,6 +61,8 @@ public interface ISysDeviceService extends IService<SysDevice> {
      */
     int insertSysDevice(SysDevice sysDevice);
 
+    void downInChargeOfTemplate(HttpServletResponse response)throws IOException;
+
     /**
      * 修改【设备管理】
      *
@@ -65,6 +79,8 @@ public interface ISysDeviceService extends IService<SysDevice> {
      */
     int deleteSysDeviceByIds(Long[] ids);
 
+    SysDevice selectByHostNameAndOrgId(String hostName, Long orgId);
+
     /**
      * 删除【设备管理】信息
      *

+ 1 - 1
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/ISysDictDataService.java

@@ -30,7 +30,7 @@ public interface ISysDictDataService extends IService<SysDictData>
      * @return 字典标签
      */
     String selectDictLabel(String dictType, String dictValue);
-
+String selectDictValue(String dictType,String dictLabel);
     /**
      * 根据字典数据ID查询信息
      *

+ 1 - 0
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/ISysOrgService.java

@@ -139,4 +139,5 @@ public interface ISysOrgService extends IService<SysOrg> {
     OrgTreeResp getOrgTreeReq(OrgTreeReq req);
 
     List<SysOrg> selectOrgTreeListByCurOrgId(Long id);
+    SysOrg selectByShortName(String shortName);
 }

+ 102 - 17
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysDeviceServiceImpl.java

@@ -1,30 +1,41 @@
 package com.xunmei.system.service.impl;
 
-import java.util.ArrayList;
-import java.util.List;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.*;
 
+import cn.hutool.core.io.IoUtil;
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.excel.EasyExcel;
 import com.alibaba.nacos.common.utils.CollectionUtils;
+import com.xunmei.common.core.constant.ErrorMsgConstants;
 import com.xunmei.common.core.constant.SecurityConstants;
+import com.xunmei.common.core.domain.retrieval.vo.CoreMonitoringRetrievalTaskExcelVo;
 import com.xunmei.common.core.exception.ServiceException;
+import com.xunmei.common.core.utils.DateHelper;
 import com.xunmei.common.core.utils.DateUtils;
 import com.xunmei.common.security.utils.SecurityUtils;
 import com.xunmei.system.api.RemoteProtectionService;
 import com.xunmei.system.api.domain.SysDevice;
+import com.xunmei.system.api.domain.SysDictData;
 import com.xunmei.system.api.domain.SysOrg;
 import com.xunmei.system.api.dto.ProtectionDTO;
+import com.xunmei.system.api.function.RemoteCallHandlerExecutor;
 import com.xunmei.system.api.vo.ProtectionVO;
 import com.xunmei.system.mapper.SysOrgMapper;
+import com.xunmei.system.util.DeviceExport;
 import com.xunmei.system.vo.area.AccessType;
 import com.xunmei.system.vo.area.HostVO;
 import com.xunmei.system.vo.area.VideoVO;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Service;
 import com.xunmei.system.service.ISysOrgService;
 
-import java.util.Arrays;
-import java.util.Map;
-
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -32,6 +43,8 @@ import com.xunmei.common.core.web.page.TableDataInfo;
 import com.xunmei.system.mapper.SysDeviceMapper;
 import com.xunmei.system.service.ISysDeviceService;
 
+import javax.servlet.http.HttpServletResponse;
+
 /**
  * 【请填写功能名称】Service业务层处理
  *
@@ -47,7 +60,8 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
     @Autowired
     private SysOrgMapper sysOrgMapper;
     @Autowired
-  private RemoteProtectionService remoteProtectionService;
+    private RemoteProtectionService remoteProtectionService;
+
     @Override
     public TableDataInfo<SysDevice> selectPage(SysDevice sysDevice) {
         //未删除
@@ -107,7 +121,7 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
                 QueryWrapper queryWrapper = new QueryWrapper();
                 queryWrapper.eq("del_flag", "0");
                 queryWrapper.eq("host_id", hostByOrgId.get(i).getId());
-                queryWrapper.eq("device_type","0");
+                queryWrapper.eq("device_type", "0");
                 List<SysDevice> list = baseMapper.selectList(queryWrapper);
                 if (CollectionUtils.isEmpty(list) || list.size() == longs.size()) {
                     hostByOrgId.remove(hostByOrgId.get(i));
@@ -138,8 +152,8 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
                     videoVO.setVideoId(s.getId());
                     videoVO.setVideoName(s.getDeviceName());
                     List<AccessType> accessByVideo = sysDeviceMapper.getAccessByVideo(s.getId(), taskId);
-                    if (accessByVideo.size()>0) {
-                        for (AccessType a:accessByVideo){
+                    if (accessByVideo.size() > 0) {
+                        for (AccessType a : accessByVideo) {
                             String situation = a.getSituation();
                             int num = a.getNum();
                             videoVO.setType(1);
@@ -184,6 +198,14 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
         return list;
     }
 
+    @Override
+    public SysDevice checkName(Long orgId, String name) {
+        QueryWrapper queryWrapper = new QueryWrapper();
+        queryWrapper.eq("org_id", orgId);
+        queryWrapper.eq("device_name", name);
+        return baseMapper.selectOne(queryWrapper);
+    }
+
     /**
      * 新增【请填写功能名称】
      *
@@ -196,10 +218,14 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
         sysDevice.setCreateBy(SecurityUtils.getUsername());
         SysOrg sysOrg = orgService.selectSysOrgById(sysDevice.getOrgId());
         sysDevice.setOrgName(sysOrg.getShortName());
+        SysDevice sysDevice1 = this.checkName(sysDevice.getOrgId(), sysDevice.getDeviceName());
+        if (null != sysDevice1) {
+            throw new RuntimeException("设备名称重复");
+        }
         int insert = sysDeviceMapper.insert(sysDevice);
         //新增防区只有报警主机
-        if (sysDevice.getDeviceType().equals("1")){
-            ProtectionDTO protectionDTO=new ProtectionDTO();
+        if (sysDevice.getDeviceType().equals("1")) {
+            ProtectionDTO protectionDTO = new ProtectionDTO();
             protectionDTO.setName(sysDevice.getDeviceName());
             protectionDTO.setOrgPath(sysOrg.getPath());
             protectionDTO.setAllHour(0);
@@ -211,6 +237,56 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
         return insert;
     }
 
+    @Override
+    public void downInChargeOfTemplate(HttpServletResponse response) throws IOException{
+//        responseSetting(response, "device", ".xlsx",
+//                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+//
+//        InputStream inputStream = null;
+//        OutputStream outputStream = null;
+//        try {
+//            // 读取文件的输入流
+//            inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("templates/device.xlsx");
+//            XSSFWorkbook wb = new XSSFWorkbook(inputStream);
+//            outputStream = response.getOutputStream();
+//            wb.write(outputStream);
+//            outputStream.flush();
+//        } catch (IOException e) {
+//            e.printStackTrace();
+//        } finally {
+//            IoUtil.close(inputStream);
+//            IoUtil.close(outputStream);
+//        }
+        response.setContentType("application/vnd.ms-excel");
+        response.setCharacterEncoding("utf-8");
+        String fileName = URLEncoder.encode("设备导入" + DateHelper.getDateString(new Date()), "UTF-8");
+        response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
+        // 调用EasyExcel的导出方法
+        EasyExcel.write(response.getOutputStream(), DeviceExport.class).sheet("Sheet1").doWrite(null);
+    }
+
+    public void responseSetting(HttpServletResponse response, String fileName, String suffix, String contentType) {
+        // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
+        String newFileName = null;
+        try {
+            newFileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+        // 当客户端请求的资源是一个可下载的资源(这里的“可下载”是指浏览器会弹出下载框或者下载界面)时,对这个可下载资源的描述(例如下载框中的文件名称)就是来源于该头域。
+        response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + newFileName + suffix);
+        // 服务器告诉浏览器它发送的数据属于什么文件类型,也就是响应数据的MIME类型
+        response.setContentType(contentType);
+        response.setCharacterEncoding("utf-8");
+        // 关闭缓存(HTTP/1.1)
+        response.setHeader("Cache-Control", "no-store");
+        // 关闭缓存(HTTP/1.0)
+        response.setHeader("Pragma", "no-cache");
+        // 缓存有效时间
+        response.setDateHeader("Expires", 0);
+    }
+
+
     /**
      * 修改【请填写功能名称】
      *
@@ -223,10 +299,10 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
         sysDevice.setUpdateBy(SecurityUtils.getUsername());
         SysOrg sysOrg = orgService.selectSysOrgById(sysDevice.getOrgId());
         sysDevice.setOrgName(sysOrg.getShortName());
-        if (sysDevice.getDeviceType().equals("1")){
+        if (sysDevice.getDeviceType().equals("1")) {
             ProtectionVO byDeviceId = remoteProtectionService.getByDeviceId(sysDevice.getId(), SecurityConstants.INNER);
-            ProtectionDTO protectionDTO=new ProtectionDTO();
-            if (null!=byDeviceId){
+            ProtectionDTO protectionDTO = new ProtectionDTO();
+            if (null != byDeviceId) {
                 protectionDTO.setId(byDeviceId.getId());
             }
             protectionDTO.setDeviceId(sysDevice.getId());
@@ -234,7 +310,11 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
             protectionDTO.setOrgPath(sysOrg.getPath());
             protectionDTO.setOrgId(sysOrg.getId());
             protectionDTO.setAllHour(0);
-            remoteProtectionService.addByDevice(protectionDTO,SecurityConstants.INNER);
+            remoteProtectionService.addByDevice(protectionDTO, SecurityConstants.INNER);
+        }
+        SysDevice sysDevice1 = this.checkName(sysDevice.getOrgId(), sysDevice.getDeviceName());
+        if (null != sysDevice1) {
+            throw new RuntimeException("设备名称重复");
         }
         return sysDeviceMapper.updateById(sysDevice);
     }
@@ -258,12 +338,17 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
                 throw new ServiceException("主机" + sysDevice.getDeviceName() + "已关联摄像头,不能删除");
             }
         }
-        for (int i=0;i<ids.length;i++){
-            remoteProtectionService.delByDeviceId(ids[i],SecurityConstants.INNER);
+        for (int i = 0; i < ids.length; i++) {
+            remoteProtectionService.delByDeviceId(ids[i], SecurityConstants.INNER);
         }
         return sysDeviceMapper.deleteBatchIds(Arrays.asList((ids)));
     }
 
+    @Override
+    public SysDevice selectByHostNameAndOrgId(String hostName, Long orgId) {
+        return sysDeviceMapper.selectByHostNameAndOrgId(hostName, orgId);
+    }
+
     /**
      * 删除【请填写功能名称】信息
      *

+ 5 - 0
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysDictDataServiceImpl.java

@@ -63,6 +63,11 @@ public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDi
         return dictDataMapper.selectDictLabel(dictType, dictValue);
     }
 
+    @Override
+    public String selectDictValue(String dictType, String dictLabel) {
+        return dictDataMapper.selectDictValue(dictType,dictLabel);
+    }
+
     /**
      * 根据字典数据ID查询信息
      *

+ 6 - 0
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysOrgServiceImpl.java

@@ -543,4 +543,10 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
         }
         return BeanHelper.copyProperties(result, SysOrg.class);
     }
+
+    @Override
+    public SysOrg selectByShortName(String shortName) {
+        SysOrg sysOrg = baseMapper.selectByShortName(shortName);
+        return sysOrg;
+    }
 }

+ 39 - 0
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/util/DeviceExport.java

@@ -0,0 +1,39 @@
+package com.xunmei.system.util;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.alibaba.excel.annotation.write.style.ColumnWidth;
+import com.alibaba.excel.annotation.write.style.ContentRowHeight;
+import com.alibaba.excel.annotation.write.style.HeadRowHeight;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * @author :LuoWei
+ * @date : 2023/10/9
+ */
+@Data
+@ColumnWidth(15) //列宽,最大值为255
+@HeadRowHeight(16) //表头行高
+@ContentRowHeight(16) //数据行高
+public class DeviceExport {
+    @ExcelProperty(value = "设备名称", index = 0)
+    private String deviceName;
+    @ExcelProperty(value = "机构名称", index = 1)
+    private String orgName;
+    @ExcelProperty(value = "资产类别", index = 2)
+    private String assetType;
+    @ExcelProperty(value = "设备分类", index = 3)
+    private String deviceType;
+    @ExcelProperty(value = "设备品牌", index = 4)
+    private String deviceBrand;
+    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
+    @ExcelProperty(value = "有效期至", index = 5)
+    private Date checkTime;
+    @ExcelProperty(value = "主机", index = 6)
+    private String hostName;
+    @ExcelProperty(value = "通道", index = 7)
+    private Long channel;
+}

+ 9 - 0
soc-modules/soc-modules-system/src/main/resources/mapper/system/SysDeviceMapper.xml

@@ -108,6 +108,15 @@
            GROUP BY cmtmi.situation
 
     </select>
+    <select id="selectByHostNameAndOrgId" resultType="com.xunmei.system.api.domain.SysDevice">
+        SELECT
+            *
+        FROM
+            sys_device
+        WHERE
+            org_id = #{orgId}
+          AND device_name = #{hostName}
+    </select>
     <!--    <select id="getAccessByVideo" resultType="java.util.Map">-->
 <!--        SELECT cmtmi.situation AS situation,-->
 <!--               COUNT(cmtrm.id) AS num-->

+ 4 - 1
soc-modules/soc-modules-system/src/main/resources/mapper/system/SysDictDataMapper.xml

@@ -71,8 +71,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 			#{item}
 		</foreach>
 	</select>
+    <select id="selectDictValue" resultType="java.lang.String">
+		SELECT dict_value FROM sys_dict_data WHERE dict_label=#{dictLabel} AND dict_type=#{dictType}
+	</select>
 
-	<delete id="deleteDictDataById" parameterType="Long">
+    <delete id="deleteDictDataById" parameterType="Long">
  		delete from sys_dict_data where dict_code = #{dictCode}
  	</delete>
  	

+ 3 - 0
soc-modules/soc-modules-system/src/main/resources/mapper/system/SysOrgMapper.xml

@@ -686,4 +686,7 @@
         select c.* from sys_org c where c.type = #{orgType} and c.path like concat('%',#{path}, '%')  and deleted=0
 
     </select>
+    <select id="selectByShortName" resultType="com.xunmei.system.api.domain.SysOrg">
+        SELECT * FROM sys_org WHERE short_name=#{name}  AND deleted=0
+    </select>
 </mapper>

BIN
soc-modules/soc-modules-system/src/main/resources/templates/device.xlsx