From e1a66ecbe02e1e70dc0a8880a11e6879ac10a5c1 Mon Sep 17 00:00:00 2001 From: yangwei <867012372@qq.com> Date: Fri, 16 May 2025 16:43:16 +0800 Subject: [PATCH 1/8] =?UTF-8?q?[feat]=201=E3=80=81=E5=9B=9E=E9=80=80?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=202=E3=80=81=E7=A7=BB=E4=BA=A4=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=203=E3=80=81=E5=A2=9E=E5=8A=A0=E6=A1=88=E4=BB=B6?= =?UTF-8?q?=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/BusinessAlertController.java | 11 ++++ .../business/domain/BusinessAlert.java | 6 +++ .../business/domain/bo/BusinessAlertBo.java | 5 ++ .../business/domain/vo/BusinessAlertVo.java | 5 ++ .../business/mapper/BusinessAlertMapper.java | 3 ++ .../service/IBusinessAlertService.java | 1 + .../impl/BusinessAlertServiceImpl.java | 51 +++++++++++++++++++ .../BusinessAlertStatisticsServiceImpl.java | 7 ++- .../mapper/business/BusinessAlertMapper.xml | 21 ++++++++ .../common/enums/ButtonPermissionEnum.java | 5 ++ .../workflow/domain/bo/BackProcessBo.java | 2 +- .../service/impl/FlwTaskServiceImpl.java | 23 ++++++--- 12 files changed, 132 insertions(+), 8 deletions(-) diff --git a/dk-modules/business/src/main/java/org/dromara/business/controller/BusinessAlertController.java b/dk-modules/business/src/main/java/org/dromara/business/controller/BusinessAlertController.java index 0eb51ab..01079b0 100644 --- a/dk-modules/business/src/main/java/org/dromara/business/controller/BusinessAlertController.java +++ b/dk-modules/business/src/main/java/org/dromara/business/controller/BusinessAlertController.java @@ -143,4 +143,15 @@ public class BusinessAlertController extends BaseController { businessAlertService.addBusinessAlertList(alertVoList); return R.ok(); } + + /** + * 移交预警 + */ + @Operation(summary ="移交预警",description = "移交预警") + @PostMapping("/alert/transfer") + public R transferAlert(BusinessAlertVo vo) { + return R.ok(businessAlertService.transferAlert(vo)); + } + + } diff --git a/dk-modules/business/src/main/java/org/dromara/business/domain/BusinessAlert.java b/dk-modules/business/src/main/java/org/dromara/business/domain/BusinessAlert.java index 4102743..84d7ef2 100644 --- a/dk-modules/business/src/main/java/org/dromara/business/domain/BusinessAlert.java +++ b/dk-modules/business/src/main/java/org/dromara/business/domain/BusinessAlert.java @@ -193,6 +193,12 @@ public class BusinessAlert { */ private Integer handleSource; + + /** + * 案件号 + */ + private String caseNumber; + /** * 指派人员名称 */ diff --git a/dk-modules/business/src/main/java/org/dromara/business/domain/bo/BusinessAlertBo.java b/dk-modules/business/src/main/java/org/dromara/business/domain/bo/BusinessAlertBo.java index db985fa..5db6e46 100644 --- a/dk-modules/business/src/main/java/org/dromara/business/domain/bo/BusinessAlertBo.java +++ b/dk-modules/business/src/main/java/org/dromara/business/domain/bo/BusinessAlertBo.java @@ -242,4 +242,9 @@ public class BusinessAlertBo { private String aiName; private Integer businessType; + /** + * 案件号 + */ + private String caseNumber; + } diff --git a/dk-modules/business/src/main/java/org/dromara/business/domain/vo/BusinessAlertVo.java b/dk-modules/business/src/main/java/org/dromara/business/domain/vo/BusinessAlertVo.java index bc23174..cfc7d8e 100644 --- a/dk-modules/business/src/main/java/org/dromara/business/domain/vo/BusinessAlertVo.java +++ b/dk-modules/business/src/main/java/org/dromara/business/domain/vo/BusinessAlertVo.java @@ -206,4 +206,9 @@ public class BusinessAlertVo implements Serializable { //1:图片比对预警 2:AI实时预警 private Integer businessType; private String deviceSn; + + /** + * 案件号 + */ + private String caseNumber; } diff --git a/dk-modules/business/src/main/java/org/dromara/business/mapper/BusinessAlertMapper.java b/dk-modules/business/src/main/java/org/dromara/business/mapper/BusinessAlertMapper.java index 138c33b..97c2a2d 100644 --- a/dk-modules/business/src/main/java/org/dromara/business/mapper/BusinessAlertMapper.java +++ b/dk-modules/business/src/main/java/org/dromara/business/mapper/BusinessAlertMapper.java @@ -116,4 +116,7 @@ public interface BusinessAlertMapper extends BaseMapperPlus> listOneDepartAlertStatus(@Param("param") BusinessAlertBo businessAlertBo); + Integer selectCurrentAlertCount(@Param("currentDate") String currentDate); + + void batchUpdateCaseNumber(@Param("list") List alertVoList); } diff --git a/dk-modules/business/src/main/java/org/dromara/business/service/IBusinessAlertService.java b/dk-modules/business/src/main/java/org/dromara/business/service/IBusinessAlertService.java index df8ba7b..6a1bac8 100644 --- a/dk-modules/business/src/main/java/org/dromara/business/service/IBusinessAlertService.java +++ b/dk-modules/business/src/main/java/org/dromara/business/service/IBusinessAlertService.java @@ -93,4 +93,5 @@ public interface IBusinessAlertService { List listHandleHistory(String lng, String lat, String createTime); + Boolean transferAlert(BusinessAlertVo vo); } diff --git a/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertServiceImpl.java b/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertServiceImpl.java index b0a592c..90408da 100644 --- a/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertServiceImpl.java +++ b/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertServiceImpl.java @@ -46,6 +46,7 @@ import java.util.Date; import java.util.List; import java.util.Map; import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; /** @@ -78,6 +79,7 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService { public BusinessAlert addBusinessAlert(BusinessAlertVo param) { BusinessAlert alert = MapstructUtils.convert(param, BusinessAlert.class); alert.setCreateTime(new Date()); + alert.setCaseNumber(param.getCaseNumber()); alert.setJobName(alert.getDeptName()+alert.getLabelCn()+ DateUtils.getTime()); this.baseMapper.insert(alert); return alert; @@ -86,6 +88,8 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService { @Override public void addBusinessAlertList(List alertVoList) { if(!alertVoList.isEmpty()) { + incrementalCount(alertVoList); + List remoteStartProcessList = new ArrayList<>(); for (BusinessAlertVo alertVo : alertVoList) { alertVo.setBusinessType(2); @@ -680,7 +684,35 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService { @Override public void batchUpdateDept(List alertVoList) { + //更新部门 this.baseMapper.batchUpdateDept(alertVoList); + + incrementalCount(alertVoList); + + //更新number + this.baseMapper.batchUpdateCaseNumber(alertVoList); + + } + + + /** + * 创建递归caseNumber + * @param alertVoList + */ + public void incrementalCount(List alertVoList){ + //查询当天时间有多少条预警 + Integer currentCount = this.baseMapper.selectCurrentAlertCount(DateUtils.getDate()); + //获取当天的时间戳 + String currentDate = DateUtils.getDate().replace("-",""); + + //然后0 + 个数 + 1 当前年月日 例如 202505150 total + 1 + AtomicInteger number = new AtomicInteger(1); + + alertVoList.forEach(alertVo -> { + int incremental = currentCount + number.get(); + alertVo.setCaseNumber(currentDate + "0" + incremental); + number.getAndIncrement(); + }); } @@ -780,6 +812,25 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService { return businessAlerts; } + @Override + public Boolean transferAlert(BusinessAlertVo vo) { + if (ObjectUtil.hasEmpty(vo.getId(),vo.getDeptId(),vo.getDeptName())){ + throw new RuntimeException("参数为空!"); + } + + BusinessAlert businessAlert = this.baseMapper.selectById(vo.getId()); + + LambdaUpdateWrapper wrapper = new LambdaUpdateWrapper<>(); + wrapper.eq(BusinessAlert::getId, businessAlert.getId()); + + wrapper.set(BusinessAlert::getDeptId,vo.getDeptId()); + wrapper.set(BusinessAlert::getDeptName,vo.getDeptName()); + wrapper.set(BusinessAlert::getJobName,vo.getDeptName() + businessAlert.getLabelCn() + businessAlert.getCreateTime()); + + + return this.baseMapper.update(wrapper) > 0; + } + public static void main(String[] args) { System.out.println(getLastSixDays()); diff --git a/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertStatisticsServiceImpl.java b/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertStatisticsServiceImpl.java index 168cdfd..bdefec6 100644 --- a/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertStatisticsServiceImpl.java +++ b/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertStatisticsServiceImpl.java @@ -280,7 +280,12 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist // } //----------------------------------------------获取飞行总架次、总时长---------------------------------------------- - Map devices = feignDeviceGroup.getDevices(); + Map devices = new HashMap<>(); + try { + devices = feignDeviceGroup.getDevices(); + } catch (Exception e) { + log.error(e.getMessage(),e); + } Map panel = baseMapper.countPanelAlert(businessAlertBo); diff --git a/dk-modules/business/src/main/resources/mapper/business/BusinessAlertMapper.xml b/dk-modules/business/src/main/resources/mapper/business/BusinessAlertMapper.xml index fd1fdf4..4a938ec 100644 --- a/dk-modules/business/src/main/resources/mapper/business/BusinessAlertMapper.xml +++ b/dk-modules/business/src/main/resources/mapper/business/BusinessAlertMapper.xml @@ -915,5 +915,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + UPDATE business_alert + SET + case_number = + + WHEN #{item.id} THEN #{item.caseNumber} + + WHERE id IN + + #{item.id} + + diff --git a/dk-modules/workflow/src/main/java/org/dromara/workflow/common/enums/ButtonPermissionEnum.java b/dk-modules/workflow/src/main/java/org/dromara/workflow/common/enums/ButtonPermissionEnum.java index 0a79d84..b438fe2 100644 --- a/dk-modules/workflow/src/main/java/org/dromara/workflow/common/enums/ButtonPermissionEnum.java +++ b/dk-modules/workflow/src/main/java/org/dromara/workflow/common/enums/ButtonPermissionEnum.java @@ -53,6 +53,11 @@ public enum ButtonPermissionEnum implements NodeExtEnum { */ TASK_DISPOSE("任务处置","taskDispose",false), + /** + * 是否能移交 + */ + TRANSFER("是否能移交", "transfer", false), + /** * 忽略 */ diff --git a/dk-modules/workflow/src/main/java/org/dromara/workflow/domain/bo/BackProcessBo.java b/dk-modules/workflow/src/main/java/org/dromara/workflow/domain/bo/BackProcessBo.java index 4c6a8ff..8d9be72 100644 --- a/dk-modules/workflow/src/main/java/org/dromara/workflow/domain/bo/BackProcessBo.java +++ b/dk-modules/workflow/src/main/java/org/dromara/workflow/domain/bo/BackProcessBo.java @@ -43,7 +43,7 @@ public class BackProcessBo implements Serializable { /** * 驳回的节点id(目前未使用,直接驳回到申请人) */ - @NotBlank(message = "驳回的节点不能为空", groups = AddGroup.class) +// @NotBlank(message = "驳回的节点不能为空", groups = AddGroup.class) private String nodeCode; /** diff --git a/dk-modules/workflow/src/main/java/org/dromara/workflow/service/impl/FlwTaskServiceImpl.java b/dk-modules/workflow/src/main/java/org/dromara/workflow/service/impl/FlwTaskServiceImpl.java index 71ec239..c121541 100644 --- a/dk-modules/workflow/src/main/java/org/dromara/workflow/service/impl/FlwTaskServiceImpl.java +++ b/dk-modules/workflow/src/main/java/org/dromara/workflow/service/impl/FlwTaskServiceImpl.java @@ -497,9 +497,14 @@ public class FlwTaskServiceImpl implements IFlwTaskService { public boolean backProcess(BackProcessBo bo) { try { Long taskId = bo.getTaskId(); - String notice = bo.getNotice(); - List messageType = bo.getMessageType(); +// String notice = bo.getNotice(); + String notice = "您有一条预警流程被退回!"; +// List messageType = bo.getMessageType(); + List messageType = List.of("1"); String message = bo.getMessage(); + if (ObjectUtil.isEmpty(message)){ + message = "退回"; + } FlowTask task = flowTaskMapper.selectById(taskId); if (ObjectUtil.isNull(task)) { throw new ServiceException("任务不存在!"); @@ -508,13 +513,19 @@ public class FlwTaskServiceImpl implements IFlwTaskService { BusinessStatusEnum.checkBackStatus(inst.getFlowStatus()); Long definitionId = task.getDefinitionId(); Definition definition = defService.getById(definitionId); - String applyNodeCode = flwCommonService.applyNodeCode(definitionId); + //获取当前节点 + String currentNodeCode = inst.getNodeCode(); + //获取返回节点 + Node skipNode = getBackTaskNode(definitionId, currentNodeCode).getFirst(); FlowParams flowParams = FlowParams.build(); - flowParams.nodeCode(bo.getNodeCode()); + flowParams.nodeCode(skipNode.getNodeCode()); flowParams.message(message); flowParams.skipType(SkipType.REJECT.getKey()); - flowParams.flowStatus(applyNodeCode.equals(bo.getNodeCode()) ? TaskStatusEnum.BACK.getStatus() : TaskStatusEnum.WAITING.getStatus()) - .hisStatus(TaskStatusEnum.BACK.getStatus()); + flowParams.flowStatus(TaskStatusEnum.WAITING.getStatus()).hisStatus(TaskStatusEnum.BACK.getStatus()); + +// flowParams.flowStatus(skipNode.getNodeCode().equals(bo.getNodeCode()) ? TaskStatusEnum.BACK.getStatus() : TaskStatusEnum.WAITING.getStatus()) +// .hisStatus(TaskStatusEnum.BACK.getStatus()); + flowParams.hisTaskExt(bo.getFileId()); taskService.skip(task.getId(), flowParams); From ce1e5cbd75b94b23b212c7f0103b904b3d928f3b Mon Sep 17 00:00:00 2001 From: yangwei <867012372@qq.com> Date: Fri, 16 May 2025 16:48:03 +0800 Subject: [PATCH 2/8] =?UTF-8?q?[feat]=201=E3=80=81=E5=9B=9E=E9=80=80?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=202=E3=80=81=E7=A7=BB=E4=BA=A4=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=203=E3=80=81=E5=A2=9E=E5=8A=A0=E6=A1=88=E4=BB=B6?= =?UTF-8?q?=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/dromara/workflow/service/impl/FlwTaskServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dk-modules/workflow/src/main/java/org/dromara/workflow/service/impl/FlwTaskServiceImpl.java b/dk-modules/workflow/src/main/java/org/dromara/workflow/service/impl/FlwTaskServiceImpl.java index c121541..f705e55 100644 --- a/dk-modules/workflow/src/main/java/org/dromara/workflow/service/impl/FlwTaskServiceImpl.java +++ b/dk-modules/workflow/src/main/java/org/dromara/workflow/service/impl/FlwTaskServiceImpl.java @@ -498,7 +498,7 @@ public class FlwTaskServiceImpl implements IFlwTaskService { try { Long taskId = bo.getTaskId(); // String notice = bo.getNotice(); - String notice = "您有一条预警流程被退回!"; + String notice = "您有一条流程被退回!"; // List messageType = bo.getMessageType(); List messageType = List.of("1"); String message = bo.getMessage(); From d44957773c0739b5bb86bba66c334ba25e67cf3d Mon Sep 17 00:00:00 2001 From: shizisheng Date: Fri, 16 May 2025 17:33:55 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E5=A4=A9=E7=BF=BC=E4=BA=91-minio=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E4=BF=AE=E5=A4=8D=EF=BC=8C=E9=81=BF=E5=85=8D=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/config/OssTianyiConfig.java | 52 +++++-------------- 1 file changed, 12 insertions(+), 40 deletions(-) diff --git a/dk-modules/system/src/main/java/org/dromara/system/config/OssTianyiConfig.java b/dk-modules/system/src/main/java/org/dromara/system/config/OssTianyiConfig.java index 8ea7cdb..3d03a4d 100644 --- a/dk-modules/system/src/main/java/org/dromara/system/config/OssTianyiConfig.java +++ b/dk-modules/system/src/main/java/org/dromara/system/config/OssTianyiConfig.java @@ -1,6 +1,9 @@ package org.dromara.system.config; import io.minio.MinioClient; +import lombok.Getter; +import lombok.Setter; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -12,51 +15,23 @@ import org.springframework.context.annotation.Configuration; */ @Configuration @ConfigurationProperties(prefix = "osstianyi") +@Getter +@Setter public class OssTianyiConfig { + @Value("${osstianyi.endPoint:https://jiangsu-10.zos.ctyun.cn}") private String endPoint; - private String accessKey; - private String secretKey; - private String bucketName; - - public String getEndPoint() { - return endPoint; - } - - public void setEndPoint(String endPoint) { - this.endPoint = endPoint; - } - - public String getAccessKey() - { - return accessKey; - } - - public void setAccessKey(String accessKey) - { - this.accessKey = accessKey; - } - public String getSecretKey() - { - return secretKey; - } + @Value("${osstianyi.accessKey:22e3f37368a242b38f4f25d98c9baf1f}") + private String accessKey; - public void setSecretKey(String secretKey) - { - this.secretKey = secretKey; - } + @Value("${osstianyi.secretKey:0d858850666248e59830d9a596847062}") + private String secretKey; - public String getBucketName() - { - return bucketName; - } + @Value("${osstianyi.bucketName:dkossbucket}") + private String bucketName; - public void setBucketName(String bucketName) - { - this.bucketName = bucketName; - } @Override public String toString() { @@ -71,9 +46,6 @@ public class OssTianyiConfig @Bean public MinioClient getMinioClient() { -// System.out.println("OssTianyiConfig"); -// System.out.println("OssTianyiConfig" + endPoint); - System.out.println(toString()); return MinioClient.builder().endpoint(endPoint).credentials(accessKey, secretKey).build(); } } From d3a3107accfef0f78a9ccfba3239d0210fb1fec3 Mon Sep 17 00:00:00 2001 From: yq183 <645046984@qq.com> Date: Mon, 19 May 2025 15:50:25 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E6=8F=90=E4=BA=A4;=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sample/manage/service/impl/DeviceQrtzServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/impl/DeviceQrtzServiceImpl.java b/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/impl/DeviceQrtzServiceImpl.java index ed730c3..343173e 100644 --- a/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/impl/DeviceQrtzServiceImpl.java +++ b/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/impl/DeviceQrtzServiceImpl.java @@ -292,7 +292,7 @@ public class DeviceQrtzServiceImpl implements IDeviceQrtzService { DateTimeFormatter formatterS = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); // 格式化当前日期 String formattedDate = currentDate.format(formatter); - List qrtzFileEntityList = deviceQrtzFileMapper.selectList(new QueryWrapper().eq("device_sn", device.getDeviceSn()).eq("exec_date", formattedDate).eq("status", DeviceQrtzConstants.QRTZ_FILE_STATUS_1).orderByAsc("sort")); + List qrtzFileEntityList = deviceQrtzFileMapper.selectList(new QueryWrapper().eq("device_sn", qrtzEntityList.get(0).getDeviceSn()).eq("exec_date", formattedDate).eq("status", DeviceQrtzConstants.QRTZ_FILE_STATUS_1).orderByAsc("sort")); if (!qrtzFileEntityList.isEmpty()) { DeviceQrtzFileEntity deviceQrtzFileEntity = qrtzFileEntityList.get(0); List qrtzDateEntityList = deviceQrtzDateMapper.listDeviceQrtzDateByQrtzAndDate(deviceQrtzFileEntity.getQrtzId()); From edead5b97d4378c0f25e07b047cdcb2c8a6c7ee0 Mon Sep 17 00:00:00 2001 From: yq183 <645046984@qq.com> Date: Mon, 19 May 2025 16:59:42 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sample/manage/service/impl/DeviceQrtzServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/impl/DeviceQrtzServiceImpl.java b/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/impl/DeviceQrtzServiceImpl.java index 343173e..c99d426 100644 --- a/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/impl/DeviceQrtzServiceImpl.java +++ b/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/impl/DeviceQrtzServiceImpl.java @@ -292,7 +292,7 @@ public class DeviceQrtzServiceImpl implements IDeviceQrtzService { DateTimeFormatter formatterS = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); // 格式化当前日期 String formattedDate = currentDate.format(formatter); - List qrtzFileEntityList = deviceQrtzFileMapper.selectList(new QueryWrapper().eq("device_sn", qrtzEntityList.get(0).getDeviceSn()).eq("exec_date", formattedDate).eq("status", DeviceQrtzConstants.QRTZ_FILE_STATUS_1).orderByAsc("sort")); + List qrtzFileEntityList = deviceQrtzFileMapper.selectList(new QueryWrapper().eq("device_sn", qrtzEntityList.get(0).getDeviceSn()).eq("exec_date", formattedDate).eq("qrtz_id",qrtzEntityList.get(0).getId()).eq("status", DeviceQrtzConstants.QRTZ_FILE_STATUS_1).orderByAsc("sort")); if (!qrtzFileEntityList.isEmpty()) { DeviceQrtzFileEntity deviceQrtzFileEntity = qrtzFileEntityList.get(0); List qrtzDateEntityList = deviceQrtzDateMapper.listDeviceQrtzDateByQrtzAndDate(deviceQrtzFileEntity.getQrtzId()); From 66c5aa1c049d9060ad4ddc79dded386f4d1a9cd9 Mon Sep 17 00:00:00 2001 From: yangwei <867012372@qq.com> Date: Tue, 20 May 2025 09:59:57 +0800 Subject: [PATCH 6/8] =?UTF-8?q?[feat]=E7=AC=AC=E4=B8=89=E6=96=B9=E5=85=8D?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E8=AE=A4=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/api/RemoteSubscribeService.java | 8 ++ .../api/domain/vo/RemoteSubscribeApiVo.java | 49 +++++++ dk-auth/pom.xml | 5 + .../auth/controller/TokenController.java | 76 ++++++++++- .../org/dromara/auth/form/CasLoginBody.java | 22 +++ .../auth/service/impl/CasAuthStrategy.java | 56 ++++++++ .../org/dromara/auth/util/HttpClientUtil.java | 108 +++++++++++++++ .../system/SubscribeApiController.java | 64 +++++++++ .../dromara/system/domain/SubscribeApi.java | 59 ++++++++ .../system/domain/bo/SubscribeApiBo.java | 55 ++++++++ .../dubbo/RemoteSubscribeServiceImpl.java | 27 ++++ .../system/handle/ListTypeHandler.java | 51 +++++++ .../system/mapper/SubscribeApiMapper.java | 7 + .../system/service/ISubscribeApiService.java | 14 ++ .../impl/ISubscribeApiServiceImpl.java | 51 +++++++ .../org/dromara/system/utils/JsonUtil.java | 126 ++++++++++++++++++ .../mapper/system/SubscribeApiMapper.xml | 7 + 17 files changed, 781 insertions(+), 4 deletions(-) create mode 100644 dk-api/api-system/src/main/java/org/dromara/system/api/RemoteSubscribeService.java create mode 100644 dk-api/api-system/src/main/java/org/dromara/system/api/domain/vo/RemoteSubscribeApiVo.java create mode 100644 dk-auth/src/main/java/org/dromara/auth/form/CasLoginBody.java create mode 100644 dk-auth/src/main/java/org/dromara/auth/service/impl/CasAuthStrategy.java create mode 100644 dk-auth/src/main/java/org/dromara/auth/util/HttpClientUtil.java create mode 100644 dk-modules/system/src/main/java/org/dromara/system/controller/system/SubscribeApiController.java create mode 100644 dk-modules/system/src/main/java/org/dromara/system/domain/SubscribeApi.java create mode 100644 dk-modules/system/src/main/java/org/dromara/system/domain/bo/SubscribeApiBo.java create mode 100644 dk-modules/system/src/main/java/org/dromara/system/dubbo/RemoteSubscribeServiceImpl.java create mode 100644 dk-modules/system/src/main/java/org/dromara/system/handle/ListTypeHandler.java create mode 100644 dk-modules/system/src/main/java/org/dromara/system/mapper/SubscribeApiMapper.java create mode 100644 dk-modules/system/src/main/java/org/dromara/system/service/ISubscribeApiService.java create mode 100644 dk-modules/system/src/main/java/org/dromara/system/service/impl/ISubscribeApiServiceImpl.java create mode 100644 dk-modules/system/src/main/java/org/dromara/system/utils/JsonUtil.java create mode 100644 dk-modules/system/src/main/resources/mapper/system/SubscribeApiMapper.xml diff --git a/dk-api/api-system/src/main/java/org/dromara/system/api/RemoteSubscribeService.java b/dk-api/api-system/src/main/java/org/dromara/system/api/RemoteSubscribeService.java new file mode 100644 index 0000000..9a2f9a0 --- /dev/null +++ b/dk-api/api-system/src/main/java/org/dromara/system/api/RemoteSubscribeService.java @@ -0,0 +1,8 @@ +package org.dromara.system.api; + +import org.dromara.system.api.domain.vo.RemoteSubscribeApiVo; + +public interface RemoteSubscribeService { + RemoteSubscribeApiVo getPrivateKey(String subscribeApiCode); + +} diff --git a/dk-api/api-system/src/main/java/org/dromara/system/api/domain/vo/RemoteSubscribeApiVo.java b/dk-api/api-system/src/main/java/org/dromara/system/api/domain/vo/RemoteSubscribeApiVo.java new file mode 100644 index 0000000..8ac4002 --- /dev/null +++ b/dk-api/api-system/src/main/java/org/dromara/system/api/domain/vo/RemoteSubscribeApiVo.java @@ -0,0 +1,49 @@ +package org.dromara.system.api.domain.vo; + +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; +import java.util.List; + +@Data +public class RemoteSubscribeApiVo implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + + private Long id; + + /** + * 订阅名称 + */ + private String subscribeName; + + /** + * 订阅编码 + */ + private String subscribeCode; + + /** + * 订阅人 + */ + private List subscribeUser; + + /** + * 公钥 + */ + private String publicKey; + + /** + *私钥 + */ + private String privateKey; + + /** + *是否开启 + */ + private Boolean isEnable; + + +} diff --git a/dk-auth/pom.xml b/dk-auth/pom.xml index 9a64994..585d0ec 100644 --- a/dk-auth/pom.xml +++ b/dk-auth/pom.xml @@ -86,6 +86,11 @@ api-resource + + org.dromara + api-system + + diff --git a/dk-auth/src/main/java/org/dromara/auth/controller/TokenController.java b/dk-auth/src/main/java/org/dromara/auth/controller/TokenController.java index 0930841..e192e64 100644 --- a/dk-auth/src/main/java/org/dromara/auth/controller/TokenController.java +++ b/dk-auth/src/main/java/org/dromara/auth/controller/TokenController.java @@ -4,6 +4,8 @@ import cn.dev33.satoken.exception.NotLoginException; import cn.hutool.core.codec.Base64; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.servlet.http.HttpServletRequest; @@ -21,11 +23,13 @@ import org.dromara.auth.form.RegisterBody; import org.dromara.auth.form.SocialLoginBody; import org.dromara.auth.service.IAuthStrategy; import org.dromara.auth.service.SysLoginService; +import org.dromara.auth.util.HttpClientUtil; import org.dromara.common.core.constant.UserConstants; import org.dromara.common.core.domain.R; import org.dromara.common.core.domain.model.LoginBody; import org.dromara.common.core.utils.*; import org.dromara.common.encrypt.annotation.ApiEncrypt; +import org.dromara.common.encrypt.utils.EncryptUtils; import org.dromara.common.json.utils.JsonUtils; import org.dromara.common.satoken.utils.LoginHelper; import org.dromara.common.social.config.properties.SocialLoginConfigProperties; @@ -33,14 +37,13 @@ import org.dromara.common.social.config.properties.SocialProperties; import org.dromara.common.social.utils.SocialUtils; import org.dromara.common.tenant.helper.TenantHelper; import org.dromara.resource.api.RemoteMessageService; -import org.dromara.system.api.RemoteClientService; -import org.dromara.system.api.RemoteConfigService; -import org.dromara.system.api.RemoteSocialService; -import org.dromara.system.api.RemoteTenantService; +import org.dromara.system.api.*; import org.dromara.system.api.domain.vo.RemoteClientVo; +import org.dromara.system.api.domain.vo.RemoteSubscribeApiVo; import org.dromara.system.api.domain.vo.RemoteTenantVo; import org.springframework.web.bind.annotation.*; +import java.io.IOException; import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.HashMap; @@ -74,6 +77,8 @@ public class TokenController { private final RemoteSocialService remoteSocialService; @DubboReference(stub = "true") private final RemoteMessageService remoteMessageService; + @DubboReference + private final RemoteSubscribeService remoteSubscribeService; /** * 登录方法 @@ -238,4 +243,67 @@ public class TokenController { return R.ok(result); } + /** + * 负责根据调用方传入的url和参数,还有用户名进行免登录执行redirect_url + */ + @PostMapping("/thirdParty/{subscribeApiCode}") + public R getAuthThirdParty(@RequestBody String param, @PathVariable("subscribeApiCode") String subscribeApiCode) { + //根据订阅组和用户获取私钥 + RemoteSubscribeApiVo remoteSubscribeApiVo = remoteSubscribeService.getPrivateKey(subscribeApiCode); + + //解密 + String decrypt = null; + try { + decrypt = EncryptUtils.decryptByRsa(param, remoteSubscribeApiVo.getPrivateKey()); + } catch (Exception e) { + throw new RuntimeException(e); + } + + if (ObjectUtil.isEmpty(decrypt)){ + throw new RuntimeException("解析内容失败,请检查公钥是否正确!"); + } + + //解析传过来的参数 + JSONObject body = JSON.parseObject(decrypt); + + if (!remoteSubscribeApiVo.getSubscribeUser().contains(body.getString("username"))){ + throw new RuntimeException("当前用户没有权限!"); + } + + //获取接口请求方式 + String method = body.getString("method"); + + //获取客户端id + String clientId = body.getString("clientId"); + + // 授权类型和客户端id + RemoteClientVo clientVo = remoteClientService.queryByClientId(clientId); + + //获取token + JSONObject result = new JSONObject(); + result.put("username", body.getString("username")); + LoginVo loginVo = IAuthStrategy.login(result.toJSONString(), clientVo, "cas"); + + //构建请求header添加token、header + Map header = new HashMap<>(); + header.put("Authorization", "Bearer " + loginVo.getAccessToken()); + header.put("clientId", clientId); + + //发送 + try { + switch (method.toLowerCase()){ + case "post": + HttpClientUtil.sendPost(body.getString("redirectUrl"),body.toJSONString(),header); + break; + case "get": + HttpClientUtil.sendGet(body.getString("redirectUrl"),header); + break; + } + } catch (IOException e) { + log.error(e.getMessage(),e); + } + + return R.ok(); + } + } diff --git a/dk-auth/src/main/java/org/dromara/auth/form/CasLoginBody.java b/dk-auth/src/main/java/org/dromara/auth/form/CasLoginBody.java new file mode 100644 index 0000000..d2924d9 --- /dev/null +++ b/dk-auth/src/main/java/org/dromara/auth/form/CasLoginBody.java @@ -0,0 +1,22 @@ +package org.dromara.auth.form; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.dromara.common.core.domain.model.LoginBody; + +/** + * 免密登录对象 + * + * @author Lion Li + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class CasLoginBody extends LoginBody { + + /** + * 用户名 + */ + private String username; + + +} diff --git a/dk-auth/src/main/java/org/dromara/auth/service/impl/CasAuthStrategy.java b/dk-auth/src/main/java/org/dromara/auth/service/impl/CasAuthStrategy.java new file mode 100644 index 0000000..4360b85 --- /dev/null +++ b/dk-auth/src/main/java/org/dromara/auth/service/impl/CasAuthStrategy.java @@ -0,0 +1,56 @@ +package org.dromara.auth.service.impl; + + +import cn.dev33.satoken.stp.SaLoginModel; +import cn.dev33.satoken.stp.StpUtil; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.dubbo.config.annotation.DubboReference; +import org.dromara.auth.domain.vo.LoginVo; +import org.dromara.auth.form.CasLoginBody; +import org.dromara.auth.service.IAuthStrategy; +import org.dromara.common.json.utils.JsonUtils; +import org.dromara.common.satoken.utils.LoginHelper; +import org.dromara.common.tenant.helper.TenantHelper; +import org.dromara.system.api.RemoteUserService; +import org.dromara.system.api.domain.vo.RemoteClientVo; +import org.dromara.system.api.model.LoginUser; +import org.springframework.stereotype.Service; + +@Slf4j +@Service("cas" + IAuthStrategy.BASE_NAME) +@RequiredArgsConstructor +public class CasAuthStrategy implements IAuthStrategy{ + + @DubboReference + private RemoteUserService remoteUserService; + + @Override + public LoginVo login(String body, RemoteClientVo client) { + CasLoginBody loginBody = JsonUtils.parseObject(body, CasLoginBody.class); + String tenantId = loginBody.getTenantId(); + String username = loginBody.getUsername(); + + LoginUser loginUser = TenantHelper.dynamic(tenantId, () -> { + return remoteUserService.getUserInfo(username, tenantId); + }); + + loginUser.setClientKey(client.getClientKey()); + loginUser.setDeviceType(client.getDeviceType()); + SaLoginModel model = new SaLoginModel(); + model.setDevice(client.getDeviceType()); + // 例如: 后台用户30分钟过期 app用户1天过期 + model.setTimeout(client.getTimeout()); + model.setActiveTimeout(client.getActiveTimeout()); + model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId()); + + // 生成token + LoginHelper.login(loginUser, model); + + LoginVo loginVo = new LoginVo(); + loginVo.setAccessToken(StpUtil.getTokenValue()); + loginVo.setExpireIn(StpUtil.getTokenTimeout()); + loginVo.setClientId(client.getClientId()); + return loginVo; + } +} diff --git a/dk-auth/src/main/java/org/dromara/auth/util/HttpClientUtil.java b/dk-auth/src/main/java/org/dromara/auth/util/HttpClientUtil.java new file mode 100644 index 0000000..ddf2249 --- /dev/null +++ b/dk-auth/src/main/java/org/dromara/auth/util/HttpClientUtil.java @@ -0,0 +1,108 @@ +package org.dromara.auth.util; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.*; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; + +import java.io.IOException; +import java.util.Map; + +public class HttpClientUtil { + + // 默认超时时间 + private static final int TIMEOUT = 5000; + + // 创建默认的 HttpClient + private static CloseableHttpClient createHttpClient() { + RequestConfig config = RequestConfig.custom() + .setConnectTimeout(TIMEOUT) + .setConnectionRequestTimeout(TIMEOUT) + .setSocketTimeout(TIMEOUT) + .build(); + return HttpClients.custom() + .setDefaultRequestConfig(config) + .build(); + } + + // 发送 GET 请求 + public static String sendGet(String url, Map headers) throws IOException { + HttpGet httpGet = new HttpGet(url); + if (headers != null) { + headers.forEach(httpGet::addHeader); + } + + try (CloseableHttpClient httpClient = createHttpClient(); + CloseableHttpResponse response = httpClient.execute(httpGet)) { + + return handleResponse(response); + } + } + + // 发送 POST 请求 + public static String sendPost(String url, String body, Map headers) throws IOException { + HttpPost httpPost = new HttpPost(url); + if (headers != null) { + headers.forEach(httpPost::addHeader); + } + if (body != null) { + HttpEntity entity = new StringEntity(body, ContentType.APPLICATION_JSON); + httpPost.setEntity(entity); + } + + try (CloseableHttpClient httpClient = createHttpClient(); + CloseableHttpResponse response = httpClient.execute(httpPost)) { + + return handleResponse(response); + } + } + + // 发送 PUT 请求 + public static String sendPut(String url, String body, Map headers) throws IOException { + HttpPut httpPut = new HttpPut(url); + if (headers != null) { + headers.forEach(httpPut::addHeader); + } + if (body != null) { + HttpEntity entity = new StringEntity(body, ContentType.APPLICATION_JSON); + httpPut.setEntity(entity); + } + + try (CloseableHttpClient httpClient = createHttpClient(); + CloseableHttpResponse response = httpClient.execute(httpPut)) { + + return handleResponse(response); + } + } + + // 发送 DELETE 请求 + public static String sendDelete(String url, Map headers) throws IOException { + HttpDelete httpDelete = new HttpDelete(url); + if (headers != null) { + headers.forEach(httpDelete::addHeader); + } + + try (CloseableHttpClient httpClient = createHttpClient(); + CloseableHttpResponse response = httpClient.execute(httpDelete)) { + + return handleResponse(response); + } + } + + // 处理响应 + private static String handleResponse(HttpResponse response) throws IOException { + int statusCode = response.getStatusLine().getStatusCode(); + if (statusCode >= 200 && statusCode < 300) { + HttpEntity entity = response.getEntity(); + return entity != null ? EntityUtils.toString(entity) : null; + } else { + throw new ClientProtocolException("Unexpected response status: " + statusCode); + } + } +} diff --git a/dk-modules/system/src/main/java/org/dromara/system/controller/system/SubscribeApiController.java b/dk-modules/system/src/main/java/org/dromara/system/controller/system/SubscribeApiController.java new file mode 100644 index 0000000..2dd45a5 --- /dev/null +++ b/dk-modules/system/src/main/java/org/dromara/system/controller/system/SubscribeApiController.java @@ -0,0 +1,64 @@ +package org.dromara.system.controller.system; + + +import cn.dev33.satoken.annotation.SaCheckPermission; +import jakarta.validation.constraints.NotEmpty; +import lombok.RequiredArgsConstructor; +import org.dromara.common.core.domain.R; +import org.dromara.common.core.validate.AddGroup; +import org.dromara.common.core.validate.EditGroup; +import org.dromara.common.encrypt.utils.EncryptUtils; +import org.dromara.common.idempotent.annotation.RepeatSubmit; +import org.dromara.common.log.annotation.Log; +import org.dromara.common.log.enums.BusinessType; +import org.dromara.common.web.core.BaseController; +import org.dromara.system.domain.SubscribeApi; +import org.dromara.system.domain.bo.SubscribeApiBo; +import org.dromara.system.service.ISubscribeApiService; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; + +@Validated +@RequiredArgsConstructor +@RestController +@RequestMapping("/subscribe") +public class SubscribeApiController extends BaseController { + + private final ISubscribeApiService iSubscribeApiService; + + + @Log(title = "订阅添加", businessType = BusinessType.INSERT) + @RepeatSubmit() + @PostMapping() + public R add(@Validated(AddGroup.class) @RequestBody SubscribeApiBo bo) { + return R.ok(iSubscribeApiService.addSubscribeApi(bo)); + } + + + @Log(title = "订阅编辑", businessType = BusinessType.UPDATE) + @RepeatSubmit() + @PutMapping() + public R edit(@Validated(EditGroup.class) @RequestBody SubscribeApiBo bo) { + return R.ok(iSubscribeApiService.editSubscribeApi(bo)); + } + + + @Log(title = "订阅删除", businessType = BusinessType.DELETE) + @DeleteMapping("/delete/{id}") + public R remove(@PathVariable Long id) { + return R.ok(iSubscribeApiService.deleteSubscribeApi(id)); + } + + + /** + * 生成秘钥(公钥和私钥) + */ + @GetMapping("/generate") + public R> generateRsaKey() { + + return R.ok(EncryptUtils.generateRsaKey()); + } + +} diff --git a/dk-modules/system/src/main/java/org/dromara/system/domain/SubscribeApi.java b/dk-modules/system/src/main/java/org/dromara/system/domain/SubscribeApi.java new file mode 100644 index 0000000..2a7694f --- /dev/null +++ b/dk-modules/system/src/main/java/org/dromara/system/domain/SubscribeApi.java @@ -0,0 +1,59 @@ +package org.dromara.system.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import org.dromara.system.handle.ListTypeHandler; + +import java.util.List; + +/** + * 第三方接口订阅类 + */ +@Data +@TableName(value = "subscribe_api",autoResultMap = true) +public class SubscribeApi { + + @TableId(type = IdType.ASSIGN_ID) + private Long id; + + /** + * 订阅名称 + */ + @TableField(value = "subscribe_name") + private String subscribeName; + + /** + * 订阅编码 + */ + @TableField(value = "subscribe_code") + private String subscribeCode; + + /** + * 订阅人 + */ + @TableField(value = "subscribe_user",typeHandler = ListTypeHandler.class) + private List subscribeUser; + + /** + * 公钥 + */ + @TableField(value = "public_key") + private String publicKey; + + /** + *私钥 + */ + @TableField(value = "private_key") + private String privateKey; + + /** + *是否开启 + */ + @TableField(value = "is_enable") + private Boolean isEnable; + + +} diff --git a/dk-modules/system/src/main/java/org/dromara/system/domain/bo/SubscribeApiBo.java b/dk-modules/system/src/main/java/org/dromara/system/domain/bo/SubscribeApiBo.java new file mode 100644 index 0000000..7098cee --- /dev/null +++ b/dk-modules/system/src/main/java/org/dromara/system/domain/bo/SubscribeApiBo.java @@ -0,0 +1,55 @@ +package org.dromara.system.domain.bo; + + +import io.github.linpeilie.annotations.AutoMapper; +import jakarta.validation.constraints.NotNull; +import lombok.Data; +import org.dromara.common.core.validate.AddGroup; +import org.dromara.common.core.validate.EditGroup; +import org.dromara.system.domain.SubscribeApi; + +import java.util.List; + +@Data +@AutoMapper(target = SubscribeApi.class, reverseConvertGenerate = false) +public class SubscribeApiBo { + + + private Long id; + + /** + * 订阅名称 + */ + @NotNull(message = "订阅名称不能为空", groups = { EditGroup.class, AddGroup.class }) + private String subscribeName; + + /** + * 订阅编码 + */ + @NotNull(message = "订阅编码不能为空", groups = { EditGroup.class, AddGroup.class }) + private String subscribeCode; + + /** + * 订阅人 + */ + private List subscribeUser; + + /** + * 公钥 + */ + @NotNull(message = "公钥不能为空", groups = { EditGroup.class, AddGroup.class }) + private String publicKey; + + /** + *私钥 + */ + @NotNull(message = "私钥不能为空", groups = { EditGroup.class, AddGroup.class }) + private String privateKey; + + /** + *是否开启 + */ + private Boolean isEnable; + + +} diff --git a/dk-modules/system/src/main/java/org/dromara/system/dubbo/RemoteSubscribeServiceImpl.java b/dk-modules/system/src/main/java/org/dromara/system/dubbo/RemoteSubscribeServiceImpl.java new file mode 100644 index 0000000..273b027 --- /dev/null +++ b/dk-modules/system/src/main/java/org/dromara/system/dubbo/RemoteSubscribeServiceImpl.java @@ -0,0 +1,27 @@ +package org.dromara.system.dubbo; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import lombok.RequiredArgsConstructor; +import org.apache.dubbo.config.annotation.DubboService; +import org.dromara.common.core.utils.MapstructUtils; +import org.dromara.system.api.RemoteSubscribeService; +import org.dromara.system.api.domain.vo.RemoteSubscribeApiVo; +import org.dromara.system.domain.SubscribeApi; +import org.dromara.system.service.ISubscribeApiService; +import org.springframework.stereotype.Service; + + +@RequiredArgsConstructor +@Service +@DubboService +public class RemoteSubscribeServiceImpl implements RemoteSubscribeService { + + private final ISubscribeApiService subscribeApiService; + + + @Override + public RemoteSubscribeApiVo getPrivateKey(String subscribeApiCode) { + SubscribeApi subscribeApi = subscribeApiService.getPrivateKey(subscribeApiCode); + return MapstructUtils.convert(subscribeApi, RemoteSubscribeApiVo.class); + } +} diff --git a/dk-modules/system/src/main/java/org/dromara/system/handle/ListTypeHandler.java b/dk-modules/system/src/main/java/org/dromara/system/handle/ListTypeHandler.java new file mode 100644 index 0000000..8ae1f87 --- /dev/null +++ b/dk-modules/system/src/main/java/org/dromara/system/handle/ListTypeHandler.java @@ -0,0 +1,51 @@ +package org.dromara.system.handle; + +import org.apache.commons.lang3.StringUtils; +import org.apache.ibatis.type.JdbcType; +import org.apache.ibatis.type.MappedJdbcTypes; +import org.apache.ibatis.type.MappedTypes; +import org.apache.ibatis.type.TypeHandler; +import org.dromara.system.utils.JsonUtil; + +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +@MappedJdbcTypes(JdbcType.VARCHAR) // 数据库类型 +@MappedTypes({List.class}) // java数据类型 +public class ListTypeHandler implements TypeHandler> { + + @Override + public void setParameter(PreparedStatement preparedStatement, int i, List alertTypeList, JdbcType jdbcType) throws SQLException { + preparedStatement.setString(i, JsonUtil.toJson(alertTypeList)); + } + + @Override + public List getResult(ResultSet resultSet, String s) throws SQLException { + if (StringUtils.isBlank(resultSet.getString(s))) { + return new ArrayList<>(); + } + return JsonUtil.jsonToList(resultSet.getString(s), String.class); + } + + @Override + public List getResult(ResultSet resultSet, int i) throws SQLException { + if (StringUtils.isBlank(resultSet.getString(i))) { + return new ArrayList<>(); + } + return JsonUtil.jsonToList(resultSet.getString(i), String.class); + } + + @Override + public List getResult(CallableStatement callableStatement, int i) throws SQLException { + String value = callableStatement.getString(i); + + if (StringUtils.isBlank(value)) { + return new ArrayList<>(); + } + return JsonUtil.jsonToList(value, String.class); + } +} diff --git a/dk-modules/system/src/main/java/org/dromara/system/mapper/SubscribeApiMapper.java b/dk-modules/system/src/main/java/org/dromara/system/mapper/SubscribeApiMapper.java new file mode 100644 index 0000000..bd4ab40 --- /dev/null +++ b/dk-modules/system/src/main/java/org/dromara/system/mapper/SubscribeApiMapper.java @@ -0,0 +1,7 @@ +package org.dromara.system.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.dromara.system.domain.SubscribeApi; + +public interface SubscribeApiMapper extends BaseMapper { +} diff --git a/dk-modules/system/src/main/java/org/dromara/system/service/ISubscribeApiService.java b/dk-modules/system/src/main/java/org/dromara/system/service/ISubscribeApiService.java new file mode 100644 index 0000000..7fd3c79 --- /dev/null +++ b/dk-modules/system/src/main/java/org/dromara/system/service/ISubscribeApiService.java @@ -0,0 +1,14 @@ +package org.dromara.system.service; + +import org.dromara.system.domain.SubscribeApi; +import org.dromara.system.domain.bo.SubscribeApiBo; + +public interface ISubscribeApiService { + SubscribeApi addSubscribeApi(SubscribeApiBo bo); + + SubscribeApi editSubscribeApi(SubscribeApiBo bo); + + Boolean deleteSubscribeApi(Long id); + + SubscribeApi getPrivateKey(String subscribeApiCode); +} diff --git a/dk-modules/system/src/main/java/org/dromara/system/service/impl/ISubscribeApiServiceImpl.java b/dk-modules/system/src/main/java/org/dromara/system/service/impl/ISubscribeApiServiceImpl.java new file mode 100644 index 0000000..06b9f33 --- /dev/null +++ b/dk-modules/system/src/main/java/org/dromara/system/service/impl/ISubscribeApiServiceImpl.java @@ -0,0 +1,51 @@ +package org.dromara.system.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import lombok.RequiredArgsConstructor; +import org.dromara.common.core.utils.MapstructUtils; +import org.dromara.system.domain.SubscribeApi; +import org.dromara.system.domain.bo.SubscribeApiBo; +import org.dromara.system.mapper.SubscribeApiMapper; +import org.dromara.system.service.ISubscribeApiService; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class ISubscribeApiServiceImpl extends ServiceImpl implements ISubscribeApiService { + + + @Override + public SubscribeApi addSubscribeApi(SubscribeApiBo bo) { + SubscribeApi convert = MapstructUtils.convert(bo, SubscribeApi.class); + + this.baseMapper.insert(convert); + + return convert; + } + + @Override + public SubscribeApi editSubscribeApi(SubscribeApiBo bo) { + SubscribeApi subscribeApi = this.baseMapper.selectById(bo.getId()); + + BeanUtils.copyProperties(bo, subscribeApi); + + this.baseMapper.updateById(subscribeApi); + + return subscribeApi; + } + + @Override + public Boolean deleteSubscribeApi(Long id) { + return this.baseMapper.deleteById(id) > 0; + } + + @Override + public SubscribeApi getPrivateKey(String subscribeApiCode) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(SubscribeApi::getSubscribeCode, subscribeApiCode); + + return this.baseMapper.selectOne(wrapper); + } +} diff --git a/dk-modules/system/src/main/java/org/dromara/system/utils/JsonUtil.java b/dk-modules/system/src/main/java/org/dromara/system/utils/JsonUtil.java new file mode 100644 index 0000000..a6eea9b --- /dev/null +++ b/dk-modules/system/src/main/java/org/dromara/system/utils/JsonUtil.java @@ -0,0 +1,126 @@ +package org.dromara.system.utils; + +import cn.hutool.core.util.ObjectUtil; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.commons.lang3.StringUtils; + +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * 定义响应结构 + */ +public class JsonUtil { + + private static ObjectMapper MAPPER; + static{ + MAPPER=new ObjectMapper(); + } + + /** + * 将对象转换成json字符串。 + * @param data + * @return + */ + public static String toJson(Object data){ + String string = null; + try { + string = MAPPER.writeValueAsString(data); + if(StringUtils.isEmpty(string)){ + return null; + } + return string; + } catch (JsonProcessingException e) { + e.printStackTrace(); + return null; + } + } + + /** + * 将json结果集转化为对象 + * + * @param jsonData json数据 + * @return + */ + public static T jsonToPojo(String jsonData, Class beanType) { + try { + T t = MAPPER.readValue(jsonData, beanType); + return t; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + /** + * 将json数据转换成pojo对象list + *

Title: jsonToList

+ *

Description:

+ * @param jsonData + * @param beanType + * @return + */ + public static List jsonToList(String jsonData, Class beanType) { + JavaType javaType = MAPPER.getTypeFactory().constructParametricType(List.class, beanType); + try { + List list = MAPPER.readValue(jsonData, javaType); + return list; + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + + /** + * 将Object对象里面的属性和值转化成Map对象 + * + * @param obj + * @return + * @throws IllegalAccessException + */ + public static Map objectToMap(Object obj){ + try { + Map map = new HashMap(); + Class clazz = obj.getClass(); + for (Field field : clazz.getDeclaredFields()) { + field.setAccessible(true); + String fieldName = field.getName(); + if(ObjectUtil.isNotEmpty(field.get(obj))){ + Object value = field.get(obj); + map.put(fieldName, value); + }else{ + map.put(fieldName, ""); + } + } + return map; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public static Map jsonToMap(String json){ + try { + return MAPPER.readValue(json, new TypeReference>(){}); + } catch (JsonProcessingException e) { + e.printStackTrace(); + return null; + } + } + + public static LinkedHashMap jsonToStrMap(String json){ + try { + return MAPPER.readValue(json, new TypeReference>(){}); + } catch (JsonProcessingException e) { + e.printStackTrace(); + return null; + } + } +} diff --git a/dk-modules/system/src/main/resources/mapper/system/SubscribeApiMapper.xml b/dk-modules/system/src/main/resources/mapper/system/SubscribeApiMapper.xml new file mode 100644 index 0000000..d81c0ee --- /dev/null +++ b/dk-modules/system/src/main/resources/mapper/system/SubscribeApiMapper.xml @@ -0,0 +1,7 @@ + + + + + From f17a1432c1440d8d6df5aa1e6b78e44d790a28f8 Mon Sep 17 00:00:00 2001 From: yangwei <867012372@qq.com> Date: Tue, 20 May 2025 11:04:07 +0800 Subject: [PATCH 7/8] =?UTF-8?q?[feat]=E4=BF=AE=E6=94=B9=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=A1=88=E4=BB=B6=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/BusinessAlertServiceImpl.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertServiceImpl.java b/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertServiceImpl.java index 90408da..503906c 100644 --- a/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertServiceImpl.java +++ b/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertServiceImpl.java @@ -687,10 +687,14 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService { //更新部门 this.baseMapper.batchUpdateDept(alertVoList); - incrementalCount(alertVoList); + try { + incrementalCount(alertVoList); - //更新number - this.baseMapper.batchUpdateCaseNumber(alertVoList); + //更新number + this.baseMapper.batchUpdateCaseNumber(alertVoList); + } catch (Exception e) { + log.error(e.getMessage(),e); + } } From 045159043f227ec05114b06be7fc5fa5a3adce4f Mon Sep 17 00:00:00 2001 From: yq183 <645046984@qq.com> Date: Tue, 20 May 2025 12:27:31 +0800 Subject: [PATCH 8/8] =?UTF-8?q?[bug]=E5=AE=9E=E6=97=B6=E9=A2=84=E8=AD=A6?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/BusinessAlertController.java | 23 ++++++++++++++----- .../service/IBusinessAlertService.java | 1 + .../impl/BusinessAlertServiceImpl.java | 5 ++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/dk-modules/business/src/main/java/org/dromara/business/controller/BusinessAlertController.java b/dk-modules/business/src/main/java/org/dromara/business/controller/BusinessAlertController.java index 01079b0..5f28a52 100644 --- a/dk-modules/business/src/main/java/org/dromara/business/controller/BusinessAlertController.java +++ b/dk-modules/business/src/main/java/org/dromara/business/controller/BusinessAlertController.java @@ -1,6 +1,7 @@ package org.dromara.business.controller; import cn.dev33.satoken.annotation.SaCheckPermission; +import cn.hutool.core.convert.Convert; import com.alibaba.fastjson.JSON; import com.alibaba.nacos.client.utils.TenantUtil; import io.swagger.v3.oas.annotations.Operation; @@ -108,27 +109,37 @@ public class BusinessAlertController extends BaseController { public R saveAlert(@RequestBody BusinessAlertVo vo) { vo.setBusinessType(2); BusinessAlert businessAlert = businessAlertService.addBusinessAlert(vo); + return R.ok(); + } + + /** + * ai实时流预警保存 + */ + @Operation(summary ="预警推送-实时预警模块专用",description = "预警推送-实时预警模块专用") + @GetMapping("/pushAlert") + public R pushAlert(Long alertId) { + BusinessAlert businessAlert= businessAlertService.getBusinessAlert(alertId); RemoteStartProcess startProcess = new RemoteStartProcess(); startProcess.setBusinessId(String.valueOf(businessAlert.getId())); startProcess.setFlowCode("alertChz"); remoteWorkflowService.startWorkFlowBatch(List.of(startProcess)); RemoteNoticeBo remoteNoticeBo = new RemoteNoticeBo(); - remoteNoticeBo.setNoticeTitle(vo.getDeptName()+"产生预警,预警类型["+vo.getLabelCn()+"],请立即查看"); + remoteNoticeBo.setNoticeTitle(businessAlert.getDeptName()+"产生预警,预警类型["+businessAlert.getLabelCn()+"],请立即查看"); remoteNoticeBo.setNoticeType("3"); - remoteNoticeBo.setNoticeContent(vo.getDeptName()+"产生预警,预警类型["+vo.getLabelCn()+"],请立即查看"); + remoteNoticeBo.setNoticeContent(businessAlert.getDeptName()+"产生预警,预警类型["+businessAlert.getLabelCn()+"],请立即查看"); remoteNoticeBo.setStatus("0"); remoteNoticeBo.setIsRead(0); remoteNoticeBo.setCreateBy(1L); remoteNoticeBo.setCreateDept(1L); remoteNoticeBo.setCreateTime(businessAlert.getCreateTime()); if (businessAlert.getBusinessType() == 2){ - businessAlert.setImages(MinioUntil.getObjectUrlOne(MinIOConstants.BUCKET_DKCY, vo.getImages(), 3600).toString()); + businessAlert.setImages(MinioUntil.getObjectUrlOne(MinIOConstants.BUCKET_DKCY, businessAlert.getImages(), 3600).toString()); } - remoteNoticeBo.setDeviceSn(vo.getDeviceSn()); - businessAlert.setDeviceSn(vo.getDeviceSn()); + remoteNoticeBo.setDeviceSn(businessAlert.getDeviceSn()); + businessAlert.setDeviceSn(businessAlert.getDeviceSn()); remoteNoticeBo.setParam(JSON.toJSONString(businessAlert)); remoteNoticeService.saveNotice(remoteNoticeBo); - remoteSubmailConfigService.remoteCmdSend("smsMultixsend", JSON.toJSONString(vo)); + remoteSubmailConfigService.remoteCmdSend("smsMultixsend", JSON.toJSONString(businessAlert)); return R.ok(); } diff --git a/dk-modules/business/src/main/java/org/dromara/business/service/IBusinessAlertService.java b/dk-modules/business/src/main/java/org/dromara/business/service/IBusinessAlertService.java index 6a1bac8..641c988 100644 --- a/dk-modules/business/src/main/java/org/dromara/business/service/IBusinessAlertService.java +++ b/dk-modules/business/src/main/java/org/dromara/business/service/IBusinessAlertService.java @@ -94,4 +94,5 @@ public interface IBusinessAlertService { List listHandleHistory(String lng, String lat, String createTime); Boolean transferAlert(BusinessAlertVo vo); + BusinessAlert getBusinessAlert(Long alertId); } diff --git a/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertServiceImpl.java b/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertServiceImpl.java index 90408da..038de9d 100644 --- a/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertServiceImpl.java +++ b/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertServiceImpl.java @@ -831,6 +831,11 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService { return this.baseMapper.update(wrapper) > 0; } + @Override + public BusinessAlert getBusinessAlert(Long alertId) { + return baseMapper.selectById(alertId); + } + public static void main(String[] args) { System.out.println(getLastSixDays());