宣城同步宿州的一些改动

ds-xuancheng
luyya 2025-06-11 10:07:38 +08:00
parent b9e405d599
commit 2f1536afd9
6 changed files with 78 additions and 39 deletions

View File

@ -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) {

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
/**
*
*/

View File

@ -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<TDeviceImportVo
private final ITDeviceService deviceService;
private final ISysDeptService deptService;
private final Boolean isUpdateSupport;
@ -37,42 +41,60 @@ public class TDeviceImportListener extends AnalysisEventListener<TDeviceImportVo
public TDeviceImportListener(Boolean isUpdateSupport) {
this.deviceService = SpringUtils.getBean(ITDeviceService.class);
this.deptService = SpringUtils.getBean(ISysDeptService.class);
this.isUpdateSupport = isUpdateSupport;
}
@Override
public void invoke(TDeviceImportVo deviceImportVo, AnalysisContext context) {
TDeviceVo deviceVo = this.deviceService.queryByDeviceCode(deviceImportVo.getDeviceCode());
try {
// 验证是否存在这个设备
if (ObjectUtil.isNull(deviceVo)) {
TDeviceBo deviceBo = BeanUtil.toBean(deviceImportVo, TDeviceBo.class);
ValidatorUtils.validate(deviceBo);
deviceService.insertByBo(deviceBo);
successNum++;
successMsg.append("<br/>").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("<br/>").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("<br/>").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("<br/>").append(successNum).append("、设备 ").append(deviceImportVo.getDeviceCode()).append(" 更新成功");
} else {
failureNum++;
failureMsg.append("<br/>").append(failureNum).append("、设备 ").append(deviceImportVo.getDeviceCode()).append(" 已存在");
}
} catch (Exception e) {
failureNum++;
failureMsg.append("<br/>").append(failureNum).append("、设备 ").append(deviceImportVo.getDeviceCode()).append(" 已存在");
String msg = "<br/>" + 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 = "<br/>" + 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

View File

@ -70,7 +70,7 @@
</if>
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 @@
</if>
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 @@
</if>
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 @@
</if>
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 @@
</if>
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
</select>
@ -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
<where>
<if test="deptId != null and deptId != ''">