From 2f1536afd9b7446104865bc1097a1c66aa43605a Mon Sep 17 00:00:00 2001 From: luyya Date: Wed, 11 Jun 2025 10:07:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A3=E5=9F=8E=E5=90=8C=E6=AD=A5=E5=AE=BF?= =?UTF-8?q?=E5=B7=9E=E7=9A=84=E4=B8=80=E4=BA=9B=E6=94=B9=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/system/TDeviceController.java | 1 + .../org/dromara/system/domain/SysDept.java | 4 + .../dromara/system/domain/bo/SysDeptBo.java | 6 ++ .../dromara/system/domain/vo/SysDeptVo.java | 4 + .../listener/TDeviceImportListener.java | 78 ++++++++++++------- .../resources/mapper/system/SysDeptMapper.xml | 24 +++--- 6 files changed, 78 insertions(+), 39 deletions(-) diff --git a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/controller/system/TDeviceController.java b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/controller/system/TDeviceController.java index 40e8563f..bf3f0092 100644 --- a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/controller/system/TDeviceController.java +++ b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/controller/system/TDeviceController.java @@ -72,6 +72,7 @@ public class TDeviceController extends BaseController { * 导出device列表 */ @SaCheckPermission("system:device:export") + @Log(title = "device", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export(TDeviceBo bo, HttpServletResponse response) { diff --git a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/domain/SysDept.java b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/domain/SysDept.java index 2113f91d..0ab84dd1 100644 --- a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/domain/SysDept.java +++ b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/domain/SysDept.java @@ -40,6 +40,8 @@ public class SysDept extends TenantEntity { */ private String deptName; + private String shortName; + /** * 显示顺序 @@ -79,4 +81,6 @@ public class SysDept extends TenantEntity { private String fullName; + private String isVisible; + } diff --git a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/domain/bo/SysDeptBo.java b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/domain/bo/SysDeptBo.java index e0812819..297a69bc 100644 --- a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/domain/bo/SysDeptBo.java +++ b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/domain/bo/SysDeptBo.java @@ -24,6 +24,7 @@ public class SysDeptBo extends BaseEntity { /** * 部门id */ + @Size(min = 0, max = 12, message = "部门机构代码长度不能超过{max}个字符") private String deptId; /** @@ -38,6 +39,9 @@ public class SysDeptBo extends BaseEntity { @Size(min = 0, max = 30, message = "部门名称长度不能超过{max}个字符") private String deptName; + @NotBlank(message = "部门简称不能为空") + private String shortName; + /** * 部门类别编码 */ @@ -75,4 +79,6 @@ public class SysDeptBo extends BaseEntity { private String fullName; + private String isVisible; + } diff --git a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/domain/vo/SysDeptVo.java b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/domain/vo/SysDeptVo.java index 75d16f5b..0730b7ca 100644 --- a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/domain/vo/SysDeptVo.java +++ b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/domain/vo/SysDeptVo.java @@ -52,6 +52,8 @@ public class SysDeptVo implements Serializable { @ExcelProperty(value = "部门名称") private String deptName; + private String shortName; + /** * 部门类别编码 */ @@ -93,6 +95,8 @@ public class SysDeptVo implements Serializable { @ExcelDictFormat(dictType = "sys_normal_disable") private String status; + private String isVisible; + /** * 创建时间 */ diff --git a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/listener/TDeviceImportListener.java b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/listener/TDeviceImportListener.java index 046e5b8a..87162912 100644 --- a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/listener/TDeviceImportListener.java +++ b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/listener/TDeviceImportListener.java @@ -16,8 +16,10 @@ import org.dromara.common.excel.core.ExcelListener; import org.dromara.common.excel.core.ExcelResult; import org.dromara.common.satoken.utils.LoginHelper; import org.dromara.system.domain.bo.TDeviceBo; +import org.dromara.system.domain.vo.SysDeptVo; import org.dromara.system.domain.vo.TDeviceImportVo; import org.dromara.system.domain.vo.TDeviceVo; +import org.dromara.system.service.ISysDeptService; import org.dromara.system.service.ITDeviceService; import java.util.List; @@ -27,6 +29,8 @@ public class TDeviceImportListener extends AnalysisEventListener").append(successNum).append("、设备 ").append(deviceBo.getDeviceCode()).append(" 导入成功"); - } else if (isUpdateSupport) { - Long id = deviceVo.getId(); - TDeviceBo deviceBo = BeanUtil.toBean(deviceVo, TDeviceBo.class); - deviceBo.setId(id); - ValidatorUtils.validate(deviceBo); - deviceService.updateByBo(deviceBo); - successNum++; - successMsg.append("
").append(successNum).append("、设备 ").append(deviceImportVo.getDeviceCode()).append(" 更新成功"); - } else { + + if (null != deviceImportVo.getDeviceCode() && deviceImportVo.getDeviceCode().contains("设备编码为国标编码")){ + failureNum = 1; + failureMsg.append("请删除Excel中提示必须删除的行后重新导入!"); + }else { + String deviceCode = deviceImportVo.getDeviceCode().replaceAll("[\\p{Zs}\\s]", ""); + TDeviceVo deviceVo = this.deviceService.queryByDeviceCode(deviceCode); + try { + // 验证是否存在这个设备 + if (ObjectUtil.isNull(deviceVo)) { + deviceImportVo.setDeviceCode(deviceCode); + SysDeptVo deptVo = deptService.selectDeptById(deviceImportVo.getZzjgdm()); + if(null != deptVo){ + deviceImportVo.setZzjgmc(deptVo.getShortName()); + } + TDeviceBo deviceBo = BeanUtil.toBean(deviceImportVo, TDeviceBo.class); + ValidatorUtils.validate(deviceBo); + deviceService.insertByBo(deviceBo); + successNum++; + successMsg.append("
").append(successNum).append("、设备 ").append(deviceBo.getDeviceCode()).append(" 导入成功"); + } else if (isUpdateSupport) { + Long id = deviceVo.getId(); + SysDeptVo deptVo = deptService.selectDeptById(deviceVo.getZzjgdm()); + if(null != deptVo){ + deviceVo.setZzjgmc(deptVo.getShortName()); + } + TDeviceBo deviceBo = BeanUtil.toBean(deviceVo, TDeviceBo.class); + deviceBo.setId(id); + ValidatorUtils.validate(deviceBo); + deviceService.updateByBo(deviceBo); + successNum++; + successMsg.append("
").append(successNum).append("、设备 ").append(deviceImportVo.getDeviceCode()).append(" 更新成功"); + } else { + failureNum++; + failureMsg.append("
").append(failureNum).append("、设备 ").append(deviceImportVo.getDeviceCode()).append(" 已存在"); + } + } catch (Exception e) { failureNum++; - failureMsg.append("
").append(failureNum).append("、设备 ").append(deviceImportVo.getDeviceCode()).append(" 已存在"); + String msg = "
" + failureNum + "、设备 " + HtmlUtil.cleanHtmlTag(deviceImportVo.getDeviceCode()) + " 导入失败:"; + String message = e.getMessage(); + if (e instanceof ConstraintViolationException cvException) { + message = StreamUtils.join(cvException.getConstraintViolations(), ConstraintViolation::getMessage, ", "); + } + failureMsg.append(msg).append(message); + log.error(msg, e); } - } catch (Exception e) { - failureNum++; - String msg = "
" + failureNum + "、设备 " + HtmlUtil.cleanHtmlTag(deviceImportVo.getDeviceCode()) + " 导入失败:"; - String message = e.getMessage(); - if (e instanceof ConstraintViolationException cvException) { - message = StreamUtils.join(cvException.getConstraintViolations(), ConstraintViolation::getMessage, ", "); - } - failureMsg.append(msg).append(message); - log.error(msg, e); } + } @Override diff --git a/stwzhj-modules/wzhj-system/src/main/resources/mapper/system/SysDeptMapper.xml b/stwzhj-modules/wzhj-system/src/main/resources/mapper/system/SysDeptMapper.xml index 98fa431b..be96c75b 100644 --- a/stwzhj-modules/wzhj-system/src/main/resources/mapper/system/SysDeptMapper.xml +++ b/stwzhj-modules/wzhj-system/src/main/resources/mapper/system/SysDeptMapper.xml @@ -70,7 +70,7 @@ group by SUBSTRING(zzjgdm,1,8)) a on SUBSTRING(d.dept_id,1,8) = SUBSTRING(a.zzjgdm,1,8) - where `status` = '0' and del_flag =0 and parent_id = '341800000000' and dept_id like '341800%' + where `status` = '0' and del_flag =0 and is_visible = '1' and parent_id = '341800000000' and dept_id like '341800%' union @@ -92,7 +92,7 @@ group by SUBSTRING(zzjgdm,1,6)) a on SUBSTRING(d.dept_id,1,6) = SUBSTRING(a.zzjgdm,1,6) - where `status` = '0' and del_flag =0 and parent_id = '341800000000' and dept_id not like '341800%' + where `status` = '0' and del_flag =0 and is_visible = '1' and parent_id = '341800000000' and dept_id not like '341800%' union @@ -113,7 +113,7 @@ group by SUBSTRING(zzjgdm,1,8)) a on SUBSTRING(d.dept_id,1,8) = SUBSTRING(a.zzjgdm,1,8) - where `status` = '0' and del_flag =0 and parent_id != '341800000000' and dept_id not like '341800%' and dept_id like '%0000' + where `status` = '0' and del_flag =0 and is_visible = '1' and parent_id != '341800000000' and parent_id != '0' and dept_id like '%0000' UNION select dept_id as deptId,short_name as deptName,parent_id as parentId,IFNULL(onlineCount,0) as onlineCount,IFNULL(allCount,0) as allCount from sys_dept d @@ -133,7 +133,8 @@ group by SUBSTRING(zzjgdm,1,10)) a on SUBSTRING(d.dept_id,1,10) = SUBSTRING(a.zzjgdm,1,10) - where `status` = '0' and del_flag =0 and parent_id != '341800000000' and parent_id != '0' and dept_id like '341800%' and dept_id like '%00' + where `status` = '0' and del_flag =0 and is_visible = '1' and parent_id != '341800000000' + and parent_id != '0' and dept_id not like '%0000' and dept_id like '%00' union @@ -154,7 +155,7 @@ group by zzjgdm) a on d.dept_id = a.zzjgdm - where `status` = '0' and del_flag =0 and LENGTH(ancestors) = 40 + where `status` = '0' and del_flag =0 and is_visible = '1' and dept_id not like '%00' and LENGTH(ancestors) >= 40 ) a order by a.deptId asc @@ -175,7 +176,7 @@ LEFT JOIN (select substring(zzjgdm,1,8) as zzjgdm ,count(*) as allCount from t_device where device_type = #{deviceType} and valid =1 group by SUBSTRING(zzjgdm,1,8)) a on SUBSTRING(d.dept_id,1,8) = SUBSTRING(a.zzjgdm,1,8) - where `status` = '0' and del_flag =0 and parent_id = '340100000000' and dept_id like '340100%' + where `status` = '0' and del_flag =0 and is_visible = '1' and parent_id = '340100000000' and dept_id like '340100%' union @@ -187,7 +188,7 @@ LEFT JOIN (select substring(zzjgdm,1,6) as zzjgdm ,count(*) as allCount from t_device where device_type = #{deviceType} and valid =1 group by SUBSTRING(zzjgdm,1,6)) a on SUBSTRING(d.dept_id,1,6) = SUBSTRING(a.zzjgdm,1,6) - where `status` = '0' and del_flag =0 and parent_id = '340100000000' and dept_id not like '340100%' + where `status` = '0' and del_flag =0 and is_visible = '1' and parent_id = '340100000000' and dept_id not like '340100%' union @@ -198,7 +199,7 @@ LEFT JOIN (select substring(zzjgdm,1,8) as zzjgdm ,count(*) as allCount from t_device where device_type = #{deviceType} and valid = 1 group by SUBSTRING(zzjgdm,1,8)) a on SUBSTRING(d.dept_id,1,8) = SUBSTRING(a.zzjgdm,1,8) - where `status` = '0' and del_flag =0 and parent_id != '340100000000' and dept_id not like '340100%' and dept_id like '%0000' + where `status` = '0' and del_flag =0 and is_visible = '1' and parent_id != '341800000000' and parent_id != '0' and dept_id like '%0000' UNION select dept_id as deptId,short_name as deptName,parent_id as parentId,IFNULL(onlineCount,0) as onlineCount,IFNULL(allCount,0) as allCount from sys_dept d @@ -208,18 +209,19 @@ LEFT JOIN (select substring(zzjgdm,1,10) as zzjgdm ,count(*) as allCount from t_device where device_type = #{deviceType} and valid = 1 group by SUBSTRING(zzjgdm,1,10)) a on SUBSTRING(d.dept_id,1,10) = SUBSTRING(a.zzjgdm,1,10) - where `status` = '0' and del_flag =0 and parent_id != '340100000000' and parent_id != '0' and dept_id like '340100%' and dept_id like '%00' + where `status` = '0' and del_flag =0 and is_visible = '1' and parent_id != '341800000000' + and parent_id != '0' and dept_id not like '%0000' and dept_id like '%00' union - select dept_id as deptId,dept_name as deptName,parent_id,IFNULL(onlineCount,0) onlineCount,IFNULL(allCount,0) as allCount from sys_dept d + select dept_id as deptId,short_name as deptName,parent_id,IFNULL(onlineCount,0) onlineCount,IFNULL(allCount,0) as allCount from sys_dept d left JOIN (select zzjgdm ,count(*) as onlineCount from t_device_redis where online =1 and device_type = #{deviceType} group by zzjgdm) o on d.dept_id = o.zzjgdm LEFT JOIN (select zzjgdm as zzjgdm ,count(*) as allCount from t_device where device_type = #{deviceType} and valid = 1 group by zzjgdm) a on d.dept_id = a.zzjgdm - where `status` = '0' and del_flag =0 and LENGTH(ancestors) = 40 + where `status` = '0' and del_flag =0 and is_visible = '1' and dept_id not like '%00' and LENGTH(ancestors) >= 40 ) count_temp