diff --git a/dk-api/api-business/src/main/java/org/dromara/business/api/RemoteBusinessAlertService.java b/dk-api/api-business/src/main/java/org/dromara/business/api/RemoteBusinessAlertService.java index 39f16f0..4efeaad 100644 --- a/dk-api/api-business/src/main/java/org/dromara/business/api/RemoteBusinessAlertService.java +++ b/dk-api/api-business/src/main/java/org/dromara/business/api/RemoteBusinessAlertService.java @@ -16,8 +16,9 @@ public interface RemoteBusinessAlertService { /** * 生成预警,待验证状态 + * activeProfile :用于处理南通/丰县数据类型, default是原始处理流,如果非default就会将businessType处理为2 */ - Boolean saveBusinessAlert(List alertVoList); + Boolean saveBusinessAlert(List alertVoList,String activeProfile); /** * 更新此条预警审批时候的状态 * @param businessId 业务id(预警、工单) diff --git a/dk-api/api-business/src/main/java/org/dromara/business/api/domain/vo/RemoteBusinessAlertConstructInfo.java b/dk-api/api-business/src/main/java/org/dromara/business/api/domain/vo/RemoteBusinessAlertConstructInfo.java new file mode 100644 index 0000000..193ff00 --- /dev/null +++ b/dk-api/api-business/src/main/java/org/dromara/business/api/domain/vo/RemoteBusinessAlertConstructInfo.java @@ -0,0 +1,85 @@ +package org.dromara.business.api.domain.vo; + +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; + +/** + * 预警任务-施工信息对象 business_alert_construct_info + * + * @author szs + * @date 2025-05-21 + */ +@Data +public class RemoteBusinessAlertConstructInfo implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + + /** + * + */ + private Long id; + + private String tenantId; + + + /** + * 1:图片比对预警 2:AI实时预警 + */ + private Long businessType; + + /** + * job任务id + */ + private String jobId; + + /** + * 预警名称 + */ + private String jobName; + + /** + * 预警任务id + */ + private Long businessAlertId; + + /** + * 施工名称 + */ + private String constructName; + + /** + * 施工单位 + */ + private String constructDept; + + /** + * 施工单位负责人 + */ + private String constructLeader; + + /** + * 联系电话 + */ + private String phonenumber; + + /** + * 施工地址 + */ + private String address; + + /** + * 所属管道 + */ + private String pipeline; + + /** + * 备注 + */ + private String remark; + + +} diff --git a/dk-api/api-business/src/main/java/org/dromara/business/api/domain/vo/RemoteBusinessAlertVo.java b/dk-api/api-business/src/main/java/org/dromara/business/api/domain/vo/RemoteBusinessAlertVo.java index f75e6a4..37958aa 100644 --- a/dk-api/api-business/src/main/java/org/dromara/business/api/domain/vo/RemoteBusinessAlertVo.java +++ b/dk-api/api-business/src/main/java/org/dromara/business/api/domain/vo/RemoteBusinessAlertVo.java @@ -189,5 +189,9 @@ public class RemoteBusinessAlertVo implements Serializable { */ private Integer handleSource; + //预警扩展施工信息 + private RemoteBusinessAlertConstructInfo remoteAlertConstructInfo; +// private Map infoMap; + } diff --git a/dk-modules/business/src/main/java/org/dromara/business/controller/BusinessAlertConstructInfoController.java b/dk-modules/business/src/main/java/org/dromara/business/controller/BusinessAlertConstructInfoController.java new file mode 100644 index 0000000..df059f2 --- /dev/null +++ b/dk-modules/business/src/main/java/org/dromara/business/controller/BusinessAlertConstructInfoController.java @@ -0,0 +1,106 @@ +package org.dromara.business.controller; + +import java.util.List; + +import lombok.RequiredArgsConstructor; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.validation.constraints.*; +import cn.dev33.satoken.annotation.SaCheckPermission; +import org.springframework.web.bind.annotation.*; +import org.springframework.validation.annotation.Validated; +import org.dromara.common.idempotent.annotation.RepeatSubmit; +import org.dromara.common.log.annotation.Log; +import org.dromara.common.web.core.BaseController; +import org.dromara.common.mybatis.core.page.PageQuery; +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.log.enums.BusinessType; +import org.dromara.common.excel.utils.ExcelUtil; +import org.dromara.business.domain.vo.BusinessAlertConstructInfoVo; +import org.dromara.business.domain.bo.BusinessAlertConstructInfoBo; +import org.dromara.business.service.IBusinessAlertConstructInfoService; +import org.dromara.common.mybatis.core.page.TableDataInfo; + +/** + * 预警任务-施工信息 + * 前端访问路由地址为:/business/alertConstructInfo + * + * @author szs + * @date 2025-05-21 + */ +@Validated +@RequiredArgsConstructor +@RestController +@RequestMapping("/alertConstructInfo") +public class BusinessAlertConstructInfoController extends BaseController { + + private final IBusinessAlertConstructInfoService businessAlertConstructInfoService; + + /** + * 查询预警任务-施工信息列表 + */ + @SaCheckPermission("business:businessAlertConstructInfo:list") + @GetMapping("/list") + public TableDataInfo list(BusinessAlertConstructInfoBo bo, PageQuery pageQuery) { + return businessAlertConstructInfoService.queryPageList(bo, pageQuery); + } + + /** + * 导出预警任务-施工信息列表 + */ + @SaCheckPermission("business:businessAlertConstructInfo:export") + @Log(title = "预警任务-施工信息", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(BusinessAlertConstructInfoBo bo, HttpServletResponse response) { + List list = businessAlertConstructInfoService.queryList(bo); + ExcelUtil.exportExcel(list, "预警任务-施工信息", BusinessAlertConstructInfoVo.class, response); + } + + /** + * 获取预警任务-施工信息详细信息 + * + * @param id 主键 + */ + @SaCheckPermission("business:businessAlertConstructInfo:query") + @GetMapping("/{id}") + public R getInfo(@NotNull(message = "主键不能为空") + @PathVariable Long id) { + return R.ok(businessAlertConstructInfoService.queryById(id)); + } + + /** + * 新增预警任务-施工信息 + */ + @SaCheckPermission("business:businessAlertConstructInfo:add") + @Log(title = "预警任务-施工信息", businessType = BusinessType.INSERT) + @RepeatSubmit() + @PostMapping() + public R add(@Validated(AddGroup.class) @RequestBody BusinessAlertConstructInfoBo bo) { + return toAjax(businessAlertConstructInfoService.insertByBo(bo)); + } + + /** + * 修改预警任务-施工信息 + */ + @SaCheckPermission("business:businessAlertConstructInfo:edit") + @Log(title = "预警任务-施工信息", businessType = BusinessType.UPDATE) + @RepeatSubmit() + @PutMapping() + public R edit(@Validated(EditGroup.class) @RequestBody BusinessAlertConstructInfoBo bo) { + return toAjax(businessAlertConstructInfoService.updateByBo(bo)); + } + + /** + * 删除预警任务-施工信息 + * + * @param ids 主键串 + */ + @SaCheckPermission("business:businessAlertConstructInfo:remove") + @Log(title = "预警任务-施工信息", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public R remove(@NotEmpty(message = "主键不能为空") + @PathVariable Long[] ids) { + return toAjax(businessAlertConstructInfoService.deleteWithValidByIds(List.of(ids), true)); + } +} 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 fa6109c..aa6233a 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 @@ -187,4 +187,33 @@ public class BusinessAlertController extends BaseController { + + @Operation(summary ="ai实时流预警保存-用于演示",description = "ai实时流预警保存-用于演示") + @PostMapping("/saveAlert") + public R selectAlert(@RequestBody BusinessAlertVo vo) { + vo.setBusinessType(2); + BusinessAlert businessAlert = businessAlertService.addBusinessAlert(vo); + 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.setNoticeType("3"); + remoteNoticeBo.setNoticeContent(vo.getDeptName()+"产生预警,预警类型["+vo.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()); + } + remoteNoticeBo.setDeviceSn(vo.getDeviceSn()); + businessAlert.setDeviceSn(vo.getDeviceSn()); + remoteNoticeBo.setParam(JSON.toJSONString(businessAlert)); + remoteNoticeService.saveNotice(remoteNoticeBo); + remoteSubmailConfigService.remoteCmdSend("smsMultixsend", JSON.toJSONString(vo)); + return R.ok(); + } } 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 84d7ef2..e98774b 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 @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; +import org.dromara.business.domain.vo.BusinessAlertConstructInfoVo; import org.dromara.common.translation.annotation.Translation; import org.dromara.common.translation.constant.TransConstant; @@ -252,4 +253,8 @@ public class BusinessAlert { @TableField(exist = false) private String deviceSn; + + //预警扩展施工信息 + @TableField(exist = false) + private BusinessAlertConstructInfoVo alertConstructInfoVo; } diff --git a/dk-modules/business/src/main/java/org/dromara/business/domain/BusinessAlertConstructInfo.java b/dk-modules/business/src/main/java/org/dromara/business/domain/BusinessAlertConstructInfo.java new file mode 100644 index 0000000..4c349fc --- /dev/null +++ b/dk-modules/business/src/main/java/org/dromara/business/domain/BusinessAlertConstructInfo.java @@ -0,0 +1,86 @@ +package org.dromara.business.domain; + +import org.dromara.common.tenant.core.TenantEntity; +import com.baomidou.mybatisplus.annotation.*; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serial; + +/** + * 预警任务-施工信息对象 business_alert_construct_info + * + * @author szs + * @date 2025-05-21 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@TableName("business_alert_construct_info") +public class BusinessAlertConstructInfo extends TenantEntity { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * + */ + @TableId(value = "id") + private Long id; + + /** + * 1:图片比对预警 2:AI实时预警 + */ + private Long businessType; + + /** + * job任务id + */ + private String jobId; + + /** + * 预警名称 + */ + private String jobName; + + /** + * 预警任务id + */ + private Long businessAlertId; + + /** + * 施工名称 + */ + private String constructName; + + /** + * 施工单位 + */ + private String constructDept; + + /** + * 施工单位负责人 + */ + private String constructLeader; + + /** + * 联系电话 + */ + private String phonenumber; + + /** + * 施工地址 + */ + private String address; + + /** + * 所属管道 + */ + private String pipeline; + + /** + * 备注 + */ + private String remark; + + +} diff --git a/dk-modules/business/src/main/java/org/dromara/business/domain/bo/BusinessAlertConstructInfoBo.java b/dk-modules/business/src/main/java/org/dromara/business/domain/bo/BusinessAlertConstructInfoBo.java new file mode 100644 index 0000000..377c543 --- /dev/null +++ b/dk-modules/business/src/main/java/org/dromara/business/domain/bo/BusinessAlertConstructInfoBo.java @@ -0,0 +1,87 @@ +package org.dromara.business.domain.bo; + +import org.dromara.business.domain.BusinessAlertConstructInfo; +import org.dromara.common.mybatis.core.domain.BaseEntity; +import org.dromara.common.core.validate.AddGroup; +import org.dromara.common.core.validate.EditGroup; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; +import lombok.EqualsAndHashCode; +import jakarta.validation.constraints.*; + +/** + * 预警任务-施工信息业务对象 business_alert_construct_info + * + * @author szs + * @date 2025-05-21 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = BusinessAlertConstructInfo.class, reverseConvertGenerate = false) +public class BusinessAlertConstructInfoBo extends BaseEntity { + + /** + * + */ + @NotNull(message = "不能为空", groups = { EditGroup.class }) + private Long id; + + /** + * 1:图片比对预警 2:AI实时预警 + */ + private Long businessType; + + /** + * job任务id + */ + private String jobId; + + /** + * 预警名称 + */ + private String jobName; + + /** + * 预警任务id + */ + @NotNull(message = "预警任务id不能为空", groups = { AddGroup.class, EditGroup.class }) + private Long businessAlertId; + + /** + * 施工名称 + */ + @NotBlank(message = "施工名称不能为空", groups = { AddGroup.class, EditGroup.class }) + private String constructName; + + /** + * 施工单位 + */ + private String constructDept; + + /** + * 施工单位负责人 + */ + private String constructLeader; + + /** + * 联系电话 + */ + private String phonenumber; + + /** + * 施工地址 + */ + private String address; + + /** + * 所属管道 + */ + private String pipeline; + + /** + * 备注 + */ + private String remark; + + +} diff --git a/dk-modules/business/src/main/java/org/dromara/business/domain/vo/BusinessAlertConstructInfoVo.java b/dk-modules/business/src/main/java/org/dromara/business/domain/vo/BusinessAlertConstructInfoVo.java new file mode 100644 index 0000000..b4d48af --- /dev/null +++ b/dk-modules/business/src/main/java/org/dromara/business/domain/vo/BusinessAlertConstructInfoVo.java @@ -0,0 +1,104 @@ +package org.dromara.business.domain.vo; + +import org.dromara.business.domain.BusinessAlertConstructInfo; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import org.dromara.common.excel.annotation.ExcelDictFormat; +import org.dromara.common.excel.convert.ExcelDictConvert; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; +import java.util.Date; + + + +/** + * 预警任务-施工信息视图对象 business_alert_construct_info + * + * @author szs + * @date 2025-05-21 + */ +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = BusinessAlertConstructInfo.class) +public class BusinessAlertConstructInfoVo implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * + */ + @ExcelProperty(value = "") + private Long id; + + /** + * 1:图片比对预警 2:AI实时预警 + */ + @ExcelProperty(value = "1:图片比对预警 2:AI实时预警") + private Long businessType; + + /** + * job任务id + */ + @ExcelProperty(value = "job任务id") + private String jobId; + + /** + * 预警名称 + */ + @ExcelProperty(value = "预警名称") + private String jobName; + + /** + * 预警任务id + */ + @ExcelProperty(value = "预警任务id") + private Long businessAlertId; + + /** + * 施工名称 + */ + @ExcelProperty(value = "施工名称") + private String constructName; + + /** + * 施工单位 + */ + @ExcelProperty(value = "施工单位") + private String constructDept; + + /** + * 施工单位负责人 + */ + @ExcelProperty(value = "施工单位负责人") + private String constructLeader; + + /** + * 联系电话 + */ + @ExcelProperty(value = "联系电话") + private String phonenumber; + + /** + * 施工地址 + */ + @ExcelProperty(value = "施工地址") + private String address; + + /** + * 所属管道 + */ + @ExcelProperty(value = "所属管道") + private String pipeline; + + /** + * 备注 + */ + @ExcelProperty(value = "备注") + private String remark; + + +} diff --git a/dk-modules/business/src/main/java/org/dromara/business/dubbo/RemoteBusinessAlertServiceImpl.java b/dk-modules/business/src/main/java/org/dromara/business/dubbo/RemoteBusinessAlertServiceImpl.java index b333a93..e139e1e 100644 --- a/dk-modules/business/src/main/java/org/dromara/business/dubbo/RemoteBusinessAlertServiceImpl.java +++ b/dk-modules/business/src/main/java/org/dromara/business/dubbo/RemoteBusinessAlertServiceImpl.java @@ -29,8 +29,8 @@ public class RemoteBusinessAlertServiceImpl implements RemoteBusinessAlertServic @Override - public Boolean saveBusinessAlert(List alertVoList) { - return businessAlertService.batchAddBusinessAlert(alertVoList); + public Boolean saveBusinessAlert(List alertVoList, String activeProfile) { + return businessAlertService.batchAddBusinessAlert(alertVoList, activeProfile); } /** diff --git a/dk-modules/business/src/main/java/org/dromara/business/mapper/BusinessAlertConstructInfoMapper.java b/dk-modules/business/src/main/java/org/dromara/business/mapper/BusinessAlertConstructInfoMapper.java new file mode 100644 index 0000000..748591a --- /dev/null +++ b/dk-modules/business/src/main/java/org/dromara/business/mapper/BusinessAlertConstructInfoMapper.java @@ -0,0 +1,15 @@ +package org.dromara.business.mapper; + +import org.dromara.business.domain.BusinessAlertConstructInfo; +import org.dromara.business.domain.vo.BusinessAlertConstructInfoVo; +import org.dromara.common.mybatis.core.mapper.BaseMapperPlus; + +/** + * 预警任务-施工信息Mapper接口 + * + * @author szs + * @date 2025-05-21 + */ +public interface BusinessAlertConstructInfoMapper extends BaseMapperPlus { + +} diff --git a/dk-modules/business/src/main/java/org/dromara/business/service/IBusinessAlertConstructInfoService.java b/dk-modules/business/src/main/java/org/dromara/business/service/IBusinessAlertConstructInfoService.java new file mode 100644 index 0000000..e766935 --- /dev/null +++ b/dk-modules/business/src/main/java/org/dromara/business/service/IBusinessAlertConstructInfoService.java @@ -0,0 +1,69 @@ +package org.dromara.business.service; + +import org.dromara.business.domain.BusinessAlertConstructInfo; +import org.dromara.business.domain.vo.BusinessAlertConstructInfoVo; +import org.dromara.business.domain.bo.BusinessAlertConstructInfoBo; +import org.dromara.common.mybatis.core.page.TableDataInfo; +import org.dromara.common.mybatis.core.page.PageQuery; + +import java.util.Collection; +import java.util.List; + +/** + * 预警任务-施工信息Service接口 + * + * @author szs + * @date 2025-05-21 + */ +public interface IBusinessAlertConstructInfoService { + + /** + * 查询预警任务-施工信息 + * + * @param id 主键 + * @return 预警任务-施工信息 + */ + BusinessAlertConstructInfoVo queryById(Long id); + + /** + * 分页查询预警任务-施工信息列表 + * + * @param bo 查询条件 + * @param pageQuery 分页参数 + * @return 预警任务-施工信息分页列表 + */ + TableDataInfo queryPageList(BusinessAlertConstructInfoBo bo, PageQuery pageQuery); + + /** + * 查询符合条件的预警任务-施工信息列表 + * + * @param bo 查询条件 + * @return 预警任务-施工信息列表 + */ + List queryList(BusinessAlertConstructInfoBo bo); + + /** + * 新增预警任务-施工信息 + * + * @param bo 预警任务-施工信息 + * @return 是否新增成功 + */ + Boolean insertByBo(BusinessAlertConstructInfoBo bo); + + /** + * 修改预警任务-施工信息 + * + * @param bo 预警任务-施工信息 + * @return 是否修改成功 + */ + Boolean updateByBo(BusinessAlertConstructInfoBo bo); + + /** + * 校验并批量删除预警任务-施工信息信息 + * + * @param ids 待删除的主键集合 + * @param isValid 是否进行有效性校验 + * @return 是否删除成功 + */ + Boolean deleteWithValidByIds(Collection ids, Boolean isValid); +} 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 2a82765..7b0fc80 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 @@ -47,7 +47,7 @@ public interface IBusinessAlertService { * @param alertVoList 预警任务 * @return 是否新增成功 */ - Boolean batchAddBusinessAlert(List alertVoList); + Boolean batchAddBusinessAlert(List alertVoList, String activeProfile); /** * 修改预警任务 diff --git a/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertConstructInfoServiceImpl.java b/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertConstructInfoServiceImpl.java new file mode 100644 index 0000000..e76ba1b --- /dev/null +++ b/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertConstructInfoServiceImpl.java @@ -0,0 +1,138 @@ +package org.dromara.business.service.impl; + +import org.dromara.common.core.utils.MapstructUtils; +import org.dromara.common.core.utils.StringUtils; +import org.dromara.common.mybatis.core.page.TableDataInfo; +import org.dromara.common.mybatis.core.page.PageQuery; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.dromara.business.domain.bo.BusinessAlertConstructInfoBo; +import org.dromara.business.domain.vo.BusinessAlertConstructInfoVo; +import org.dromara.business.domain.BusinessAlertConstructInfo; +import org.dromara.business.mapper.BusinessAlertConstructInfoMapper; +import org.dromara.business.service.IBusinessAlertConstructInfoService; + +import java.util.List; +import java.util.Map; +import java.util.Collection; + +/** + * 预警任务-施工信息Service业务层处理 + * + * @author szs + * @date 2025-05-21 + */ +@RequiredArgsConstructor +@Service +public class BusinessAlertConstructInfoServiceImpl implements IBusinessAlertConstructInfoService { + + private final BusinessAlertConstructInfoMapper baseMapper; + + /** + * 查询预警任务-施工信息 + * + * @param id 主键 + * @return 预警任务-施工信息 + */ + @Override + public BusinessAlertConstructInfoVo queryById(Long id){ + return baseMapper.selectVoById(id); + } + + /** + * 分页查询预警任务-施工信息列表 + * + * @param bo 查询条件 + * @param pageQuery 分页参数 + * @return 预警任务-施工信息分页列表 + */ + @Override + public TableDataInfo queryPageList(BusinessAlertConstructInfoBo bo, PageQuery pageQuery) { + LambdaQueryWrapper lqw = buildQueryWrapper(bo); + Page result = baseMapper.selectVoPage(pageQuery.build(), lqw); + return TableDataInfo.build(result); + } + + /** + * 查询符合条件的预警任务-施工信息列表 + * + * @param bo 查询条件 + * @return 预警任务-施工信息列表 + */ + @Override + public List queryList(BusinessAlertConstructInfoBo bo) { + LambdaQueryWrapper lqw = buildQueryWrapper(bo); + return baseMapper.selectVoList(lqw); + } + + private LambdaQueryWrapper buildQueryWrapper(BusinessAlertConstructInfoBo bo) { + Map params = bo.getParams(); + LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); + lqw.eq(bo.getBusinessType() != null, BusinessAlertConstructInfo::getBusinessType, bo.getBusinessType()); + lqw.eq(StringUtils.isNotBlank(bo.getJobId()), BusinessAlertConstructInfo::getJobId, bo.getJobId()); + lqw.like(StringUtils.isNotBlank(bo.getJobName()), BusinessAlertConstructInfo::getJobName, bo.getJobName()); + lqw.eq(bo.getBusinessAlertId() != null, BusinessAlertConstructInfo::getBusinessAlertId, bo.getBusinessAlertId()); + lqw.like(StringUtils.isNotBlank(bo.getConstructName()), BusinessAlertConstructInfo::getConstructName, bo.getConstructName()); + lqw.eq(StringUtils.isNotBlank(bo.getConstructDept()), BusinessAlertConstructInfo::getConstructDept, bo.getConstructDept()); + lqw.eq(StringUtils.isNotBlank(bo.getConstructLeader()), BusinessAlertConstructInfo::getConstructLeader, bo.getConstructLeader()); + lqw.eq(StringUtils.isNotBlank(bo.getPhonenumber()), BusinessAlertConstructInfo::getPhonenumber, bo.getPhonenumber()); + lqw.eq(StringUtils.isNotBlank(bo.getAddress()), BusinessAlertConstructInfo::getAddress, bo.getAddress()); + lqw.eq(StringUtils.isNotBlank(bo.getPipeline()), BusinessAlertConstructInfo::getPipeline, bo.getPipeline()); + return lqw; + } + + /** + * 新增预警任务-施工信息 + * + * @param bo 预警任务-施工信息 + * @return 是否新增成功 + */ + @Override + public Boolean insertByBo(BusinessAlertConstructInfoBo bo) { + BusinessAlertConstructInfo add = MapstructUtils.convert(bo, BusinessAlertConstructInfo.class); + validEntityBeforeSave(add); + boolean flag = baseMapper.insert(add) > 0; + if (flag) { + bo.setId(add.getId()); + } + return flag; + } + + /** + * 修改预警任务-施工信息 + * + * @param bo 预警任务-施工信息 + * @return 是否修改成功 + */ + @Override + public Boolean updateByBo(BusinessAlertConstructInfoBo bo) { + BusinessAlertConstructInfo update = MapstructUtils.convert(bo, BusinessAlertConstructInfo.class); + validEntityBeforeSave(update); + return baseMapper.updateById(update) > 0; + } + + /** + * 保存前的数据校验 + */ + private void validEntityBeforeSave(BusinessAlertConstructInfo entity){ + //TODO 做一些数据校验,如唯一约束 + } + + /** + * 校验并批量删除预警任务-施工信息信息 + * + * @param ids 待删除的主键集合 + * @param isValid 是否进行有效性校验 + * @return 是否删除成功 + */ + @Override + public Boolean deleteWithValidByIds(Collection ids, Boolean isValid) { + if(isValid){ + //TODO 做一些业务上的校验,判断是否需要校验 + } + return baseMapper.deleteByIds(ids) > 0; + } +} 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 61c4db4..d12fdd2 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 @@ -3,6 +3,7 @@ package org.dromara.business.service.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.ListUtil; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; @@ -12,11 +13,14 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.dubbo.config.annotation.DubboReference; import org.dromara.business.api.domain.bo.RemoteBusinessAlertBo; +import org.dromara.business.api.domain.vo.RemoteBusinessAlertConstructInfo; import org.dromara.business.api.domain.vo.RemoteBusinessAlertVo; import org.dromara.business.config.ProjectTablePrefixConfig; import org.dromara.business.domain.BusinessAlert; import org.dromara.business.domain.bo.BusinessAlertBo; +import org.dromara.business.domain.vo.BusinessAlertConstructInfoVo; import org.dromara.business.domain.vo.BusinessAlertVo; +import org.dromara.business.mapper.BusinessAlertConstructInfoMapper; import org.dromara.business.mapper.BusinessAlertMapper; import org.dromara.business.service.IBusinessAlertService; import org.dromara.business.utils.BatchProcessorUtil; @@ -30,6 +34,7 @@ import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.StreamUtils; import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.TableDataInfo; +import org.dromara.business.utils.MinioUtil; import org.dromara.common.satoken.utils.LoginHelper; import org.dromara.system.api.RemoteLabelPostService; import org.dromara.system.api.domain.vo.RemoteAiLabelPostVo; @@ -65,6 +70,9 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService { private final BusinessAlertMapper baseMapper; + @Autowired + private BusinessAlertConstructInfoMapper businessAlertConstructInfoMapper; + @DubboReference(timeout = 30000) RemoteWorkflowService remoteWorkflowService; @@ -103,14 +111,14 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService { alert.setDeptId("106"); alert.setDeptName("金山街道"); } - if(ObjectUtil.equals("车辆",alert.getLabelEn())){ + if(ObjectUtil.equals("车辆",alert.getLabelCn())){ alert.setLat("34.22403"); alert.setLng("117.13597"); - }else if(ObjectUtil.equals("烟雾",alert.getLabelEn())){ + }else if(ObjectUtil.equals("烟雾",alert.getLabelCn())){ alert.setLat("34.22825"); alert.setLng("117.14087"); - }else if(ObjectUtil.equals("垃圾",alert.getLabelEn())){ + }else if(ObjectUtil.equals("垃圾",alert.getLabelCn())){ alert.setLat("34.2264"); alert.setLng("117.13919"); } @@ -151,22 +159,38 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService { * @return */ @Override - public Boolean batchAddBusinessAlert(List alertVoList) { + public Boolean batchAddBusinessAlert(List alertVoList, String activeProfile) { List businessAlerts = alertVoList.stream().map(alert -> { BusinessAlert businessAlert = new BusinessAlert(); alert.setCreateTime(new Date()); alert.setHandleType(BusinessStatusEnum.VERIFY.getStatus()); + RemoteBusinessAlertConstructInfo remoteAlertConstructInfo = alert.getRemoteAlertConstructInfo(); + BusinessAlertConstructInfoVo alertConstructInfoVo = new BusinessAlertConstructInfoVo(); + BeanUtils.copyProperties(alert.getRemoteAlertConstructInfo(), alertConstructInfoVo); + businessAlert.setAlertConstructInfoVo(alertConstructInfoVo); BeanUtils.copyProperties(alert, businessAlert); + if(!StrUtil.equals("default", activeProfile)){ + businessAlert.setBusinessType(2); + } //查询历史预警 List businessAlertList = this.listHandleHistory(alert.getLng(), alert.getLat(), DateUtils.parseDateToStr(FormatsType.YYYY_MM_DD_HH_MM_SS, alert.getCreateTime())); - businessAlert.setHandleNum(businessAlertList.size()); return businessAlert; }).toList(); - return this.baseMapper.insertBatch(businessAlerts); + boolean b = this.baseMapper.insertBatch(businessAlerts); + /*List alertConstructInfoList = businessAlerts.stream().map(alert -> { + BusinessAlertConstructInfoVo alertConstructInfoVo = alert.getAlertConstructInfoVo(); + BusinessAlertConstructInfo businessAlertConstructInfo = new BusinessAlertConstructInfo(); + BeanUtils.copyProperties(alertConstructInfoVo, businessAlertConstructInfo); + businessAlertConstructInfo.setBusinessAlertId(alert.getId()); + return businessAlertConstructInfo; + }).collect(Collectors.toList()); + businessAlertConstructInfoMapper.insertBatch(alertConstructInfoList);*/ + + return b; } /** @@ -252,7 +276,7 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService { Page page = this.baseMapper.pageBusinessAlert(pageQuery.build(), wrapper, ptPrefix); - try { + try {//预警管理查询图片 page.getRecords().forEach(businessAlertVo->{ if (businessAlertVo.getBusinessType() == 2){ businessAlertVo.setImages(MinioUntil.getObjectUrlOne(MinIOConstants.BUCKET_DKCY, businessAlertVo.getImages(), 3600).toString()); @@ -871,6 +895,16 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService { LambdaUpdateWrapper wrapper = new LambdaUpdateWrapper<>(); wrapper.eq(BusinessAlert::getId, alertId); wrapper.set(BusinessAlert::getDelFlag,1); + BusinessAlert businessAlert = this.baseMapper.selectById(alertId); + + //删除minio多余数据 + try { + MinioUtil.deleteFile(businessAlert.getImages(), MinIOConstants.BUCKET_DKCY); + MinioUtil.deleteFile(businessAlert.getImages(), MinIOConstants.BUCKET_ALERT); + } catch (Exception e) { + throw new RuntimeException(e); + } + return this.baseMapper.update(wrapper) > 0; } diff --git a/dk-modules/business/src/main/java/org/dromara/business/utils/MinioUtil.java b/dk-modules/business/src/main/java/org/dromara/business/utils/MinioUtil.java new file mode 100644 index 0000000..648b49e --- /dev/null +++ b/dk-modules/business/src/main/java/org/dromara/business/utils/MinioUtil.java @@ -0,0 +1,183 @@ +package org.dromara.business.utils; + +import cn.hutool.core.io.IoUtil; +import cn.hutool.core.util.StrUtil; +import io.minio.*; +import io.minio.http.Method; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import java.io.InputStream; +import java.util.HashMap; + +@Component +public class MinioUtil { + // 指定MinIO服务的访问地址(包括协议、域名或IP以及端口) + private static String endpoint; + // MinIO的访问密钥(Access Key),用于身份验证 + private static String accessKey; + // MinIO的秘密密钥(Secret Key),与访问密钥配对使用,也是认证的一部分。 + private static String secretKey; + // 指定默认的存储桶(Bucket)名称,MinIO中用于组织和存储对象(文件)的基本容器。 + private static String bucket; + + @Value("${minio.endpoint:http://114.235.183.147:9090}") + public void setEndpoint(String endpoint) { + MinioUtil.endpoint = endpoint; + } + + @Value("${minio.accessKey:wuyuan@yf}") + public void setAccessKey(String accessKey) { + MinioUtil.accessKey = accessKey; + } + + @Value("${minio.secretKey:wuyuan@yf}") + public void setSecretKey(String secretKey) { + MinioUtil.secretKey = secretKey; + } + + @Value("${minio.bucket:dkcy}") + public void setBucket(String bucket) { + MinioUtil.bucket = bucket; + } + + /** + * 创建并返回一个配置好的MinioClient实例 + * 用于与MinIO服务器交互,上传文件、下载文件、删除文件 + * + * @return 配置 + */ + public static MinioClient getMinioClient() { + return MinioClient.builder() + .endpoint(endpoint) + .credentials(accessKey, secretKey) + .build(); + } + + /** + * 上传:将一个输入流中的文件上传到MinIO服务器上指定的存储桶(bucket)里 + * + * @param objectName .object(objectName)指定了上传后对象的名称。 + * @param inputStream 转换为 流 + * @param size 文件大小 + * @param contentType 内容类型 + * @throws Exception 异常 + */ + public static void uploadFile(String objectName, InputStream inputStream, long size, String contentType,String newBucket) throws Exception { + String bucketName = StrUtil.isEmpty(newBucket) ? bucket : newBucket; + + MinioClient minioClient = getMinioClient(); + minioClient.putObject( + // .bucket(bucket) 指定了目标存储桶的名称。.object(objectName)指定了上传后对象的名称。 + PutObjectArgs.builder().bucket(bucketName).object(objectName).stream(inputStream, size, -1) + // .contentType(contentType)指定了上传文件的内容类型。 + .contentType(contentType) + .build()); + } + + + /** + * 下载:从MinIO服务器下载指定存储桶(bucket)中的文件 + * + * @param objectName 指定要从MinIO下载的文件对象名称(即文件路径和文件名)。 + * @return 流 对象 + * @throws Exception 异常 + */ + public static InputStream downloadFile(String objectName,String newBucket) throws Exception { + String bucketName = StrUtil.isEmpty(newBucket) ? bucket : newBucket; + + MinioClient minioClient = getMinioClient(); + return minioClient.getObject( + GetObjectArgs.builder() + // .bucket(bucket)指定了文件所在的存储桶名称。 + .bucket(bucketName) + // .object(objectName)指定了要下载的对象名称。 + .object(objectName) + .build()); + } + + + /** + * 预览:生成一个预签名的URL,允许用户通过浏览器或其他HTTP客户端以GET方法访问MinIO存储桶中指定对象(文件)的临时链接 + * + * @param objectName 指定需要获取预览链接的文件对象名称(包括路径)。 + * @return 对象 + * @throws Exception .method(Method.GET)指定了请求的方法为GET,这是预览文件时的标准HTTP方法。 + * .bucket(bucket)指定了存储桶的名称。 + * .object(objectName)指定了对象(文件)的名称。 + */ + public static String getPreviewUrl(String objectName,String newBucket) throws Exception { + String bucketName = StrUtil.isEmpty(newBucket) ? bucket : newBucket; + + MinioClient minioClient = getMinioClient(); + return minioClient.getPresignedObjectUrl( + GetPresignedObjectUrlArgs.builder() + .method(Method.GET) + .bucket(bucketName) + .object(objectName) + .build()); + } + + /** + * 删除:从MinIO服务器上的指定存储桶中删除一个文件 + * + * @param objectName 指定要删除的文件对象名称(包括路径和文件名) + * @throws Exception + */ + public static void deleteFile(String objectName,String newBucket) throws Exception { + String bucketName = StrUtil.isEmpty(newBucket) ? bucket : newBucket; + + MinioClient minioClient = getMinioClient(); + minioClient.removeObject( + RemoveObjectArgs.builder().bucket(bucketName).object(objectName).build()); + } + + //查询文件信息 + public static HashMap getFileAsMultipart(String objectName, String newBucket) throws Exception { + String bucketName = StrUtil.isEmpty(newBucket) ? bucket : newBucket; + MinioClient client = getMinioClient(); + + // 获取对象 + InputStream is = client.getObject(GetObjectArgs.builder() + .bucket(bucketName) + .object(objectName) + .build()); + + // 获取文件元信息(如 contentType) + StatObjectResponse stat = client.statObject(StatObjectArgs.builder() + .bucket(bucketName) + .object(objectName) + .build()); + + String contentType = stat.contentType(); + + // 将流读为 byte[] 以生成 MockMultipartFile + byte[] bytes = IoUtil.readBytes(is); // Hutool 工具类 + HashMap map = new HashMap<>(); + map.put("objectName",objectName); + map.put("contentType",contentType); + map.put("bytes",bytes); + + return map; + } + + + //文件复制 + public static void copyFile(String sourceObjectName, String targetObjectName, String sourceBucket, String targetBucket) throws Exception { + MinioClient client = getMinioClient(); + + // 使用服务器端复制,无需下载上传 + client.copyObject(CopyObjectArgs.builder() + .bucket(targetBucket) // 目标桶 + .object(targetObjectName) // 目标对象 + .source(CopySource.builder() + .bucket(sourceBucket) + .object(sourceObjectName) + .build()) + .build()); + } + + + + +} diff --git a/dk-modules/business/src/main/resources/mapper/business/BusinessAlertConstructInfoMapper.xml b/dk-modules/business/src/main/resources/mapper/business/BusinessAlertConstructInfoMapper.xml new file mode 100644 index 0000000..5d57f33 --- /dev/null +++ b/dk-modules/business/src/main/resources/mapper/business/BusinessAlertConstructInfoMapper.xml @@ -0,0 +1,7 @@ + + + + + diff --git a/dk-modules/sample/src/main/java/org/dromara/sample/manage/controller/SampleEngineRecordController.java b/dk-modules/sample/src/main/java/org/dromara/sample/manage/controller/SampleEngineRecordController.java new file mode 100644 index 0000000..3bf7485 --- /dev/null +++ b/dk-modules/sample/src/main/java/org/dromara/sample/manage/controller/SampleEngineRecordController.java @@ -0,0 +1,77 @@ +package org.dromara.sample.manage.controller; + +import com.alibaba.nacos.common.utils.CollectionUtils; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.dromara.common.sdk.common.HttpResultResponse; +import org.dromara.sample.manage.model.dto.CallBackDTO; +import org.dromara.sample.manage.model.dto.EventsDTO; +import org.dromara.sample.manage.model.entity.WarningRecordEntity; +import org.dromara.sample.manage.service.ISampleEngineRecordService; +import org.dromara.sample.manage.service.ISampleWarningRecordService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * @author sean.zhou + * @version 0.1 + * @date 2021/11/15 + */ +@RestController +@Slf4j +@RequestMapping("${url.manage.prefix}${url.manage.version}/saEngineRecord") +@Tag(name = "无人机设备模块") +public class SampleEngineRecordController { + + @Autowired + private ISampleEngineRecordService sampleEngineRecordService; + + @Autowired + private ISampleWarningRecordService sampleWarningRecordService; + + /** + * 启动星罗引擎。 + * Get the topology list of all online devices in one workspace. + * @return + */ + @PostMapping("/startEngine") + @Operation(summary = "启动星罗引擎。", description = "启动星罗引擎") + public HttpResultResponse> startEngine(@RequestBody Map objectMap) { + return HttpResultResponse.success(sampleEngineRecordService.startEngine(objectMap)); + } + + @PostMapping("/closeEngine") + @Operation(summary = "关闭星罗引擎。", description = "关闭星罗引擎") + public HttpResultResponse closeEngine(@RequestBody Map objectMap) { + sampleEngineRecordService.closeEngine(objectMap); + return HttpResultResponse.success(); + } + + @PostMapping("/some") + @Operation(summary = "存储推流的预警(对外接口)。", description = "存储推流的预警(对外接口)。") + public void some(@RequestBody CallBackDTO callBackVo){ + WarningRecordEntity warningRecord = new WarningRecordEntity(); + List list = new ArrayList<>(); + if (CollectionUtils.isNotEmpty(callBackVo.getEvents())){ + for (EventsDTO eventsVo :callBackVo.getEvents()){ + warningRecord.setTaskId(callBackVo.getTaskId()); + warningRecord.setAlgoId(eventsVo.getAlgoId()); + warningRecord.setEventId(eventsVo.getEventId()); + warningRecord.setExtraType(eventsVo.getExtraType()); + warningRecord.setPicUrl(eventsVo.getPicUrl()); + warningRecord.setTimestamp(eventsVo.getTimestamp()); + list.add(warningRecord); + } + sampleWarningRecordService.saveBatch(list); + System.out.println(callBackVo); + } + } +} diff --git a/dk-modules/sample/src/main/java/org/dromara/sample/manage/mapper/ISampleEngineRecordMapper.java b/dk-modules/sample/src/main/java/org/dromara/sample/manage/mapper/ISampleEngineRecordMapper.java new file mode 100644 index 0000000..7d2fdf2 --- /dev/null +++ b/dk-modules/sample/src/main/java/org/dromara/sample/manage/mapper/ISampleEngineRecordMapper.java @@ -0,0 +1,9 @@ +package org.dromara.sample.manage.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.dromara.sample.manage.model.entity.EngineRecordEntity; +import org.mapstruct.Mapper; + + +public interface ISampleEngineRecordMapper extends BaseMapper { +} diff --git a/dk-modules/sample/src/main/java/org/dromara/sample/manage/mapper/ITaskJobMapper.java b/dk-modules/sample/src/main/java/org/dromara/sample/manage/mapper/ITaskJobMapper.java new file mode 100644 index 0000000..5fc2e61 --- /dev/null +++ b/dk-modules/sample/src/main/java/org/dromara/sample/manage/mapper/ITaskJobMapper.java @@ -0,0 +1,15 @@ +package org.dromara.sample.manage.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.dromara.sample.manage.model.entity.PlayTextEntity; +import org.dromara.sample.manage.model.entity.TaskJobEntity; + +/** + * + * @author sean.zhou + * @date 2021/11/10 + * @version 0.1 + */ +public interface ITaskJobMapper extends BaseMapper { + +} diff --git a/dk-modules/sample/src/main/java/org/dromara/sample/manage/mapper/SampleWarningRecordMapper.java b/dk-modules/sample/src/main/java/org/dromara/sample/manage/mapper/SampleWarningRecordMapper.java new file mode 100644 index 0000000..9a22f83 --- /dev/null +++ b/dk-modules/sample/src/main/java/org/dromara/sample/manage/mapper/SampleWarningRecordMapper.java @@ -0,0 +1,18 @@ +package org.dromara.sample.manage.mapper; + + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import org.dromara.sample.manage.model.entity.WarningRecordEntity; + +/** + * 设备对象-》用于存储设备Mapper接口 + * + * @author wuyuan + * @date 2022-10-25 + */ +@Mapper +public interface SampleWarningRecordMapper extends BaseMapper { + +} + diff --git a/dk-modules/sample/src/main/java/org/dromara/sample/manage/model/dto/BusinessAlertVo.java b/dk-modules/sample/src/main/java/org/dromara/sample/manage/model/dto/BusinessAlertVo.java new file mode 100644 index 0000000..0126918 --- /dev/null +++ b/dk-modules/sample/src/main/java/org/dromara/sample/manage/model/dto/BusinessAlertVo.java @@ -0,0 +1,212 @@ +package org.dromara.sample.manage.model.dto; + +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; +import java.util.Date; + + +/** + * 预警任务视图对象 wayline_alert + * + * @author LionLi + * @date 2025-02-27 + */ +@Data +@ExcelIgnoreUnannotated +public class BusinessAlertVo implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + + /** + * + */ + private Long id; + + /** + * job任务id + */ + private String jobId; + + /** + * 预警名称 + */ + private String jobName; + + /** + * 图片id 对应的media_file 的fileId + */ + private String taskImageId; + + /** + * 处理原因 + */ + private String reason; + + /** + * 是否指派 + */ + private Boolean assign; + + /** + * 图片文件 + */ + private String images; + + /** + * 纬度 + */ + private String lat; + + /** + * 精度 + */ + private String lng; + + /** + * 标签名-中 + */ + private String labelCn; + + /** + * 标签名-英 + */ + private String labelEn; + + /** + * 任务内容 + */ + private String taskContent; + + /** + * 删除 0 正常 1已删除 + */ + private Integer delFlag; + + /** + * 模板图片 + */ + private String mateSourceImgUrl; + + + /** + * 放大模板违建区域图片 + */ + private String maxMateSourceImgUrl; + + /** + * 预警类型 + */ + private String alertType; + + /** + * 放大违建区域图片 + */ + private String maxImages; + + /** + * 面积 + */ + private Long area; + + /** + * 面积:长 + */ + private Long areaL; + + /** + * 面积:宽 + */ + private Long areaW; + + /** + * 流程处置状态(verify:验证,cancel:已撤销,draft:草稿,waiting:待审核,finish:已完成,invalid:已作废,back:已退回,termination:已终止) + */ + private String handleType; + + /** + * 指派人员 + */ + private String assignUserId; + + /** + * 指派时间 + */ + private Date assignDate; + + /** + * 完成时间 + */ + private Date completeDate; + + /** + * 是否违建 0:否,1:是 + */ + private Boolean isIllegal; + + /** + * 部门id + */ + private String deptId; + + /** + * 部门名称 + */ + private String deptName; + + /** + * 处理时间 + */ + private Date handleTime; + + /** + * 其他:内容 + */ + private String taskHandle; + + /** + * 像素坐标 + */ + private String pixelCoordinate; + + /** + * 当前位置预警数量 + */ + private Integer handleNum; + + /** + * 地类信息数据 + */ + private String landCategories; + + /** + * 忽略原因 + */ + private String ignoringCause; + private Integer value; + + /** + * 来源:0:平台 1:小程序 + */ + private Integer handleSource; + + /** + * 指派人员名称 + */ + private String assignUserName; + + private Date createTime; + //1:图片比对预警 2:AI实时预警 + private Integer businessType; + private String deviceSn; + + /** + * 案件号 + */ + private String caseNumber; +} diff --git a/dk-modules/sample/src/main/java/org/dromara/sample/manage/model/dto/EngineType.java b/dk-modules/sample/src/main/java/org/dromara/sample/manage/model/dto/EngineType.java new file mode 100644 index 0000000..71f928a --- /dev/null +++ b/dk-modules/sample/src/main/java/org/dromara/sample/manage/model/dto/EngineType.java @@ -0,0 +1,30 @@ +package org.dromara.sample.manage.model.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * The entity class of the device + * + * @author sean.zhou + * @version 0.1 + * @date 2021/11/10 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class EngineType implements Serializable { + + private String scene; + + private int id; + + + + +} diff --git a/dk-modules/sample/src/main/java/org/dromara/sample/manage/model/dto/EngineTypeResponse.java b/dk-modules/sample/src/main/java/org/dromara/sample/manage/model/dto/EngineTypeResponse.java new file mode 100644 index 0000000..0f693f7 --- /dev/null +++ b/dk-modules/sample/src/main/java/org/dromara/sample/manage/model/dto/EngineTypeResponse.java @@ -0,0 +1,30 @@ +package org.dromara.sample.manage.model.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * The entity class of the device + * + * @author sean.zhou + * @version 0.1 + * @date 2021/11/10 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class EngineTypeResponse implements Serializable { + + private Long code; + + private String message; + + private EngineType data; + + +} diff --git a/dk-modules/sample/src/main/java/org/dromara/sample/manage/model/entity/TaskJobEntity.java b/dk-modules/sample/src/main/java/org/dromara/sample/manage/model/entity/TaskJobEntity.java new file mode 100644 index 0000000..6c56af2 --- /dev/null +++ b/dk-modules/sample/src/main/java/org/dromara/sample/manage/model/entity/TaskJobEntity.java @@ -0,0 +1,33 @@ +package org.dromara.sample.manage.model.entity; + +import com.baomidou.mybatisplus.annotation.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.util.Date; + +/** + * The entity class of the device + * + * @author sean.zhou + * @version 0.1 + * @date 2021/11/10 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@TableName(value = "task_job") +public class TaskJobEntity implements Serializable { + + @TableId(type = IdType.AUTO) + private Integer id; + + private String taskId; + + private String jobId; + +} diff --git a/dk-modules/sample/src/main/java/org/dromara/sample/manage/model/entity/WarningRecordEntity.java b/dk-modules/sample/src/main/java/org/dromara/sample/manage/model/entity/WarningRecordEntity.java index 70f8e17..5791d73 100644 --- a/dk-modules/sample/src/main/java/org/dromara/sample/manage/model/entity/WarningRecordEntity.java +++ b/dk-modules/sample/src/main/java/org/dromara/sample/manage/model/entity/WarningRecordEntity.java @@ -30,26 +30,18 @@ public class WarningRecordEntity implements Serializable { private String taskId; @TableField(value = "algo_id") - //算法 id") - private Integer algoId; + private Integer algoId; //算法 id") @TableField(value = "extra_type") - //算法类型字符串") - private String extraType; + private String extraType; //算法类型字符串") @TableField(value = "event_id") - //分配的事件 id") - private String eventId; + private String eventId;//分配的事件 id") @TableField(value = "pic_url") - //保存后图片的 url") - private String picUrl; + private String picUrl;//保存后图片的 url") @TableField(value = "timestamp") - //事件时间戳,单位:毫秒") - private Integer timestamp; - - - + private Integer timestamp;//事件时间戳,单位:毫秒") } diff --git a/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/ISampleEngineRecordService.java b/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/ISampleEngineRecordService.java new file mode 100644 index 0000000..fba8e46 --- /dev/null +++ b/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/ISampleEngineRecordService.java @@ -0,0 +1,9 @@ +package org.dromara.sample.manage.service; + +import java.util.Map; + +public interface ISampleEngineRecordService { + Map startEngine(Map objectMap); + + void closeEngine(Map objectMap); +} diff --git a/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/ISampleWarningRecordService.java b/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/ISampleWarningRecordService.java new file mode 100644 index 0000000..2b06e74 --- /dev/null +++ b/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/ISampleWarningRecordService.java @@ -0,0 +1,8 @@ +package org.dromara.sample.manage.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import org.dromara.sample.manage.model.entity.WarningRecordEntity; + + +public interface ISampleWarningRecordService extends IService { +} diff --git a/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/ITaskJobService.java b/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/ITaskJobService.java new file mode 100644 index 0000000..6ba3849 --- /dev/null +++ b/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/ITaskJobService.java @@ -0,0 +1,15 @@ +package org.dromara.sample.manage.service; + +import org.dromara.common.sdk.common.HttpResultResponse; +import org.dromara.common.sdk.common.PaginationData; +import org.dromara.sample.manage.model.entity.PlayTextEntity; + +import java.util.Map; + +/** + * @author sean.zhou + * @date 2021/11/10 + * @version 0.1 + */ +public interface ITaskJobService { +} diff --git a/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/impl/SampleEngineRecordServiceImpl.java b/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/impl/SampleEngineRecordServiceImpl.java new file mode 100644 index 0000000..47b08fe --- /dev/null +++ b/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/impl/SampleEngineRecordServiceImpl.java @@ -0,0 +1,250 @@ +package org.dromara.sample.manage.service.impl; + +import cn.hutool.core.map.MapUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.seata.common.util.StringUtils; +import lombok.extern.slf4j.Slf4j; +import org.apache.dubbo.config.annotation.DubboReference; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.utils.URIBuilder; +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 org.dromara.sample.common.util.Md5Utils; +import org.dromara.sample.manage.mapper.ISampleEngineRecordMapper; +import org.dromara.sample.manage.mapper.ITaskJobMapper; +import org.dromara.sample.manage.model.dto.*; +import org.dromara.sample.manage.model.entity.EngineRecordEntity; +import org.dromara.sample.manage.model.entity.TaskJobEntity; +import org.dromara.sample.manage.service.ISampleEngineRecordService; +import org.dromara.system.api.RemoteConfigService; +import org.json.JSONArray; +import org.json.JSONObject; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.*; + +import static org.apache.commons.compress.utils.ArchiveUtils.sanitize; + +@Service +@Slf4j +@Transactional +public class SampleEngineRecordServiceImpl implements ISampleEngineRecordService { + @Resource + ISampleEngineRecordMapper mapper; + + @Resource + ITaskJobMapper taskJobMapper; + + @DubboReference + private RemoteConfigService remoteConfigService; + @Override + public Map startEngine(Map objectMap){ + EngineRecordEntity record = new EngineRecordEntity(); + String ip = remoteConfigService.selectStreamIp(); + //获取token + //设置请求Header和Body(如JSON) + String md5 = Md5Utils.hash("xuzhou_ai"); + JSONObject jsonObj = new JSONObject(); + jsonObj.put("username", sanitize("xuzhou_ai")); // sanitize函数见下文 + jsonObj.put("password", sanitize(md5)); + String responseBody = PostRequest(jsonObj, "http://60.204.247.65:8100/Third/Login",""); + JSONObject jsonObject = new JSONObject(responseBody); + // 逐层获取 data -> token + JSONObject data = jsonObject.getJSONObject("data"); + String token = data.getString("token"); + String sceneResponseBody = null; + String algorithmResponseBody = null; + //查询用户开通的场景 + if (StringUtils.isNotEmpty(token)){ +// try { +// URI uri = new URIBuilder("http://60.204.247.65:8100/V2/AI/WX/User/Scene") +// .build(); +// sceneResponseBody = GetRequest(uri, token); +// } catch (URISyntaxException e) { +// throw new RuntimeException(e); +// } +// EngineTypeResponse engineTypeResponse = null; +// try { +// ObjectMapper mapper = new ObjectMapper(); +// engineTypeResponse = mapper.readValue(sceneResponseBody, EngineTypeResponse.class); +// } catch (JsonProcessingException e) { +// throw new RuntimeException(e); +// } +//// JSONObject jsonObject1 = new JSONObject(sceneResponseBody); +// // 逐层获取 data -> token +//// JSONObject data1 = jsonObject1.getJSONObject("data"); +// String scene = engineTypeResponse.getData().getScene(); +// +// //查询场景算法 +// List extra_type_list = new ArrayList<>(); +// try { +// URI uri = new URIBuilder("http://60.204.247.65:8100/V2/AI/WX/User/ExtraType/Get") +// .addParameter("scene",scene) +// .addParameter("if_open","1") +// .build(); +// algorithmResponseBody = GetRequest(uri, token); +// ObjectMapper mapper = new ObjectMapper(); +// ExtraTypeResponse response = mapper.readValue(algorithmResponseBody,ExtraTypeResponse.class); +// List list = response.getData(); +// for (ExtraType extraType : list) { +// extra_type_list.add(extraType.getExtra_type()); +// break; +// } +// } catch (URISyntaxException | JsonProcessingException e) { +// throw new RuntimeException(e); +// } + + JSONObject jsonObj2 = new JSONObject(); + String type = objectMap.get("type").toString(); + if (StringUtils.isNotEmpty(type)){ + List list = Arrays.asList(type.split(",")); + jsonObj2.put("scene", "可见光"); // sanitize函数见下文 + jsonObj2.put("callback_url", "http://114.235.183.162:9888/ces/iot/deviceLog/some"); + jsonObj2.put("extra_type_list",new JSONArray(list)); + jsonObj2.put("input_url","http://"+ip+":19008/live/livesteam/"+objectMap.get("rtmpUrl")+".flv"); + jsonObj2.put("push_url", "rtmp://"+ip+"/live/livesteam/"+objectMap.get("rtmpUrl")+"ai1"); +// jsonObj2.put("play_url", objectMap.get("play_url")); + String responseBody2 = PostRequest(jsonObj2, "http://60.204.247.65:8100/Third/Engine/Start",token); + ObjectMapper mapper1 = new ObjectMapper(); + EngineResponse response = null; + try { + response = mapper1.readValue(responseBody2, EngineResponse.class); + if (response.getCode() != 200){ + throw new RuntimeException("第三方接口调用失败!"); + } + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + objectMap.put("task_id",response.getData().getTask_id()); + record.setPushUrl(objectMap.get("rtmpUrl").toString()); + record.setTaskId(MapUtil.getStr(objectMap,"task_id","")); + record.setDeviceSn(MapUtil.getStr(objectMap,"deviceSn","")); + record.setTaskId(response.getData().getTask_id()); + record.setExtraType(objectMap.get("type").toString()); + System.out.print(objectMap); + } + + } + Map map = new HashMap(); + + map.put("push_url", "http://"+ip+":1985/rtc/v1/whep/?app=live/livesteam&stream="+objectMap.get("rtmpUrl")+"ai1"); + + map.put("task_id", objectMap.get("task_id")); + //添加启动引擎记录 + mapper.insert(record); + + //添加任务id和jobid关联关系 + TaskJobEntity taskJobEntity = new TaskJobEntity(); + taskJobEntity.setJobId(objectMap.get("jobId").toString()); + taskJobEntity.setTaskId(objectMap.get("task_id").toString()); + taskJobMapper.insert(taskJobEntity); + return map; + } + + @Override + public void closeEngine(Map objectMap) { + JSONObject jsonObj2 = new JSONObject(); + EngineRecordEntity record = mapper.selectOne(new LambdaQueryWrapper().eq(EngineRecordEntity::getDeviceSn, objectMap.get("deviceSn"))); + if (record == null){ +// throw new RuntimeException("关闭引擎失败!"); + }else { + //获取token + //设置请求Header和Body(如JSON) + String md5 = Md5Utils.hash("xuzhou_ai"); + JSONObject jsonObj = new JSONObject(); + jsonObj.put("username", sanitize("xuzhou_ai")); // sanitize函数见下文 + jsonObj.put("password", sanitize(md5)); + String responseBody = PostRequest(jsonObj, "http://60.204.247.65:8100/Third/Login",""); + JSONObject jsonObject = new JSONObject(responseBody); + // 逐层获取 data -> token + JSONObject data = jsonObject.getJSONObject("data"); + String token = data.getString("token"); + + + jsonObj2.put("task_id", record.getTaskId()); // sanitize函数见下文 + String responseBody2 = PostRequest(jsonObj2, "http://60.204.247.65:8100/Third/Engine/Stop",token); + JSONObject json = new JSONObject(responseBody2); + // 方式2:安全获取(先判空再转换) + Object dataObj = json.get("data"); + if(dataObj != null && dataObj instanceof Integer) { + int data1 = (Integer) dataObj; + if (data1 ==1){ + mapper.delete(new LambdaQueryWrapper().eq(EngineRecordEntity::getDeviceSn, objectMap.get("deviceSn"))); + }else { + throw new RuntimeException("关闭引擎失败!"); + } + } else { + throw new RuntimeException("关闭引擎失败!"); + } + } + + + + } + + + public String PostRequest( JSONObject jsonObj, String url, String token + ) { + try (CloseableHttpClient httpClient = HttpClients.createDefault()) { + // 1. 创建POST请求对象 + HttpPost post = new HttpPost(url); + StringEntity requestEntity = new StringEntity(jsonObj.toString(), "UTF-8"); + requestEntity.setContentType("application/json"); + post.setEntity(requestEntity); + post.setHeader("Accept", "application/json"); + post.setHeader("token", token); + // 3. 执行请求并获取响应 + try (CloseableHttpResponse response = httpClient.execute(post)) { + String responseBody = EntityUtils.toString(response.getEntity()); + if (response.getStatusLine().getStatusCode() == 200) { + return responseBody; + } else { + throw new RuntimeException("第三方接口调用失败!"); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + + } + + public String GetRequest(URI uri, String token + ) { + try (CloseableHttpClient httpClient = HttpClients.createDefault()) { +// URI uri = new URIBuilder("https://api.example.com/data") +// .addParameter("param1", "value1") +// .addParameter("param2", "value2") +// .build(); + HttpGet httpGet = new HttpGet(uri); + if (StringUtils.isNotEmpty(token)){ + httpGet.setHeader("token",token); + } + try (CloseableHttpResponse response = httpClient.execute(httpGet)) { + // 处理响应 + String responseBody = EntityUtils.toString(response.getEntity()); + if (response.getStatusLine().getStatusCode() == 200){ + return responseBody; + }else { + throw new RuntimeException("第三方接口调用失败!"); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + + } + + +} diff --git a/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/impl/SampleWarningRecordServiceImpl.java b/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/impl/SampleWarningRecordServiceImpl.java new file mode 100644 index 0000000..44b1485 --- /dev/null +++ b/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/impl/SampleWarningRecordServiceImpl.java @@ -0,0 +1,15 @@ +package org.dromara.sample.manage.service.impl; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import lombok.extern.slf4j.Slf4j; +import org.dromara.sample.manage.mapper.SampleWarningRecordMapper; +import org.dromara.sample.manage.mapper.WarningRecordMapper; +import org.dromara.sample.manage.model.entity.WarningRecordEntity; +import org.dromara.sample.manage.service.ISampleWarningRecordService; +import org.springframework.stereotype.Service; + +@Service +@Slf4j +public class SampleWarningRecordServiceImpl extends ServiceImpl implements ISampleWarningRecordService { +} diff --git a/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/impl/TaskJobServiceImpl.java b/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/impl/TaskJobServiceImpl.java new file mode 100644 index 0000000..f8cdbc0 --- /dev/null +++ b/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/impl/TaskJobServiceImpl.java @@ -0,0 +1,44 @@ +package org.dromara.sample.manage.service.impl; + +import cn.hutool.core.convert.Convert; +import cn.hutool.crypto.SecureUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections.CollectionUtils; +import org.apache.dubbo.config.annotation.DubboReference; +import org.dromara.common.sdk.common.HttpResultResponse; +import org.dromara.common.sdk.common.Pagination; +import org.dromara.common.sdk.common.PaginationData; +import org.dromara.common.sdk.mqtt.CommonTopicRequest; +import org.dromara.common.sdk.mqtt.MqttGatewayPublish; +import org.dromara.sample.feign.RemoteSystemFeign; +import org.dromara.sample.manage.mapper.IPlayTextMapper; +import org.dromara.sample.manage.model.dto.StreamTypeDTO; +import org.dromara.sample.manage.model.entity.PlayTextEntity; +import org.dromara.sample.manage.service.IPlayTextService; +import org.dromara.sample.manage.service.ITaskJobService; +import org.dromara.system.api.RemoteConfigService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.UUID; + +/** + * + * @author sean.zhou + * @version 0.1 + * @date 2021/11/10 + */ +@Service +@Slf4j +@Transactional +public class TaskJobServiceImpl implements ITaskJobService { + +} diff --git a/dk-modules/sample/src/main/java/org/dromara/sample/media/service/IFileService.java b/dk-modules/sample/src/main/java/org/dromara/sample/media/service/IFileService.java index 5980e9d..6ece33f 100644 --- a/dk-modules/sample/src/main/java/org/dromara/sample/media/service/IFileService.java +++ b/dk-modules/sample/src/main/java/org/dromara/sample/media/service/IFileService.java @@ -86,4 +86,6 @@ public interface IFileService { * @param fileType 图片类型 ("jpeg,mp4") * */ List getMediaFileDTO( String jobId,String fileType); + + String copyFile(String sourceBucket, String originFileUrl, String targetBucket); } diff --git a/dk-modules/sample/src/main/java/org/dromara/sample/media/service/impl/FileServiceImpl.java b/dk-modules/sample/src/main/java/org/dromara/sample/media/service/impl/FileServiceImpl.java index c2b62fa..437abc1 100644 --- a/dk-modules/sample/src/main/java/org/dromara/sample/media/service/impl/FileServiceImpl.java +++ b/dk-modules/sample/src/main/java/org/dromara/sample/media/service/impl/FileServiceImpl.java @@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.dromara.common.oss.core.OssClient; import org.dromara.common.oss.factory.OssFactory; +import org.dromara.common.redis.utils.RedisOpsUtils; import org.dromara.common.satoken.utils.LoginHelper; import org.dromara.common.sdk.cloudapi.device.DeviceEnum; import org.dromara.common.sdk.cloudapi.media.FlightTask; @@ -22,6 +23,7 @@ import org.dromara.sample.media.mapper.IFileMapper; import org.dromara.sample.media.model.MediaFileDTO; import org.dromara.sample.media.model.MediaFileEntity; import org.dromara.sample.media.service.IFileService; +import org.dromara.sample.utils.MinioUtil; import org.dromara.system.api.model.LoginUser; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -50,6 +52,7 @@ public class FileServiceImpl implements IFileService { @Autowired private IDeviceProService deviceProService; + private Optional getMediaByFingerprint(String workspaceId, String fingerprint) { MediaFileEntity fileEntity = mapper.selectOne(new LambdaQueryWrapper() .eq(MediaFileEntity::getWorkspaceId, workspaceId) @@ -72,6 +75,10 @@ public class FileServiceImpl implements IFileService { @Override public Integer saveFile(String workspaceId, MediaUploadCallbackRequest file, FlightTask flightTask,Integer proId) { MediaFileEntity fileEntity = this.fileUploadConvertToEntity(file,flightTask); + if(RedisOpsUtils.checkExist("jobId-media:"+fileEntity.getJobId()+fileEntity.getFileName())) { + return 1; + } + RedisOpsUtils.setWithExpire("jobId-media:"+fileEntity.getJobId()+fileEntity.getFileName(),fileEntity.getObjectKey(),10800); fileEntity.setWorkspaceId(workspaceId); fileEntity.setFileId(UUID.randomUUID().toString()); fileEntity.setProId(proId); @@ -178,6 +185,22 @@ public class FileServiceImpl implements IFileService { } + + //文件从 mediafile 复制到 alert库,文件保持相同目录 + @Override + public String copyFile(String sourceBucket, String originFileUrl, String targetBucket) { + String fileUrl = ""; + try { +// String originalfileName = FileUtil.getName(originFileUrl); + MinioUtil.copyFile(originFileUrl,originFileUrl,sourceBucket,targetBucket);//列表图片 + MinioUtil.copyFile(originFileUrl,originFileUrl,sourceBucket,MinIOConstants.BUCKET_ALERT);//预览图片 + } catch (Exception e) { + throw new RuntimeException(e); + } + + + return fileUrl; + } /** * Convert the received file object into a database entity object. * @param file diff --git a/dk-modules/sample/src/main/java/org/dromara/sample/utils/MinioUtil.java b/dk-modules/sample/src/main/java/org/dromara/sample/utils/MinioUtil.java new file mode 100644 index 0000000..b520693 --- /dev/null +++ b/dk-modules/sample/src/main/java/org/dromara/sample/utils/MinioUtil.java @@ -0,0 +1,183 @@ +package org.dromara.sample.utils; + +import cn.hutool.core.io.IoUtil; +import cn.hutool.core.util.StrUtil; +import io.minio.*; +import io.minio.http.Method; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import java.io.InputStream; +import java.util.HashMap; + +@Component +public class MinioUtil { + // 指定MinIO服务的访问地址(包括协议、域名或IP以及端口) + private static String endpoint; + // MinIO的访问密钥(Access Key),用于身份验证 + private static String accessKey; + // MinIO的秘密密钥(Secret Key),与访问密钥配对使用,也是认证的一部分。 + private static String secretKey; + // 指定默认的存储桶(Bucket)名称,MinIO中用于组织和存储对象(文件)的基本容器。 + private static String bucket; + + @Value("${minio.endpoint:http://114.235.183.147:9090}") + public void setEndpoint(String endpoint) { + MinioUtil.endpoint = endpoint; + } + + @Value("${minio.accessKey:wuyuan@yf}") + public void setAccessKey(String accessKey) { + MinioUtil.accessKey = accessKey; + } + + @Value("${minio.secretKey:wuyuan@yf}") + public void setSecretKey(String secretKey) { + MinioUtil.secretKey = secretKey; + } + + @Value("${minio.bucket:dkcy}") + public void setBucket(String bucket) { + MinioUtil.bucket = bucket; + } + + /** + * 创建并返回一个配置好的MinioClient实例 + * 用于与MinIO服务器交互,上传文件、下载文件、删除文件 + * + * @return 配置 + */ + public static MinioClient getMinioClient() { + return MinioClient.builder() + .endpoint(endpoint) + .credentials(accessKey, secretKey) + .build(); + } + + /** + * 上传:将一个输入流中的文件上传到MinIO服务器上指定的存储桶(bucket)里 + * + * @param objectName .object(objectName)指定了上传后对象的名称。 + * @param inputStream 转换为 流 + * @param size 文件大小 + * @param contentType 内容类型 + * @throws Exception 异常 + */ + public static void uploadFile(String objectName, InputStream inputStream, long size, String contentType,String newBucket) throws Exception { + String bucketName = StrUtil.isEmpty(newBucket) ? bucket : newBucket; + + MinioClient minioClient = getMinioClient(); + minioClient.putObject( + // .bucket(bucket) 指定了目标存储桶的名称。.object(objectName)指定了上传后对象的名称。 + PutObjectArgs.builder().bucket(bucketName).object(objectName).stream(inputStream, size, -1) + // .contentType(contentType)指定了上传文件的内容类型。 + .contentType(contentType) + .build()); + } + + + /** + * 下载:从MinIO服务器下载指定存储桶(bucket)中的文件 + * + * @param objectName 指定要从MinIO下载的文件对象名称(即文件路径和文件名)。 + * @return 流 对象 + * @throws Exception 异常 + */ + public static InputStream downloadFile(String objectName,String newBucket) throws Exception { + String bucketName = StrUtil.isEmpty(newBucket) ? bucket : newBucket; + + MinioClient minioClient = getMinioClient(); + return minioClient.getObject( + GetObjectArgs.builder() + // .bucket(bucket)指定了文件所在的存储桶名称。 + .bucket(bucketName) + // .object(objectName)指定了要下载的对象名称。 + .object(objectName) + .build()); + } + + + /** + * 预览:生成一个预签名的URL,允许用户通过浏览器或其他HTTP客户端以GET方法访问MinIO存储桶中指定对象(文件)的临时链接 + * + * @param objectName 指定需要获取预览链接的文件对象名称(包括路径)。 + * @return 对象 + * @throws Exception .method(Method.GET)指定了请求的方法为GET,这是预览文件时的标准HTTP方法。 + * .bucket(bucket)指定了存储桶的名称。 + * .object(objectName)指定了对象(文件)的名称。 + */ + public static String getPreviewUrl(String objectName,String newBucket) throws Exception { + String bucketName = StrUtil.isEmpty(newBucket) ? bucket : newBucket; + + MinioClient minioClient = getMinioClient(); + return minioClient.getPresignedObjectUrl( + GetPresignedObjectUrlArgs.builder() + .method(Method.GET) + .bucket(bucketName) + .object(objectName) + .build()); + } + + /** + * 删除:从MinIO服务器上的指定存储桶中删除一个文件 + * + * @param objectName 指定要删除的文件对象名称(包括路径和文件名) + * @throws Exception + */ + public static void deleteFile(String objectName,String newBucket) throws Exception { + String bucketName = StrUtil.isEmpty(newBucket) ? bucket : newBucket; + + MinioClient minioClient = getMinioClient(); + minioClient.removeObject( + RemoveObjectArgs.builder().bucket(bucketName).object(objectName).build()); + } + + //查询文件信息 + public static HashMap getFileAsMultipart(String objectName, String newBucket) throws Exception { + String bucketName = StrUtil.isEmpty(newBucket) ? bucket : newBucket; + MinioClient client = getMinioClient(); + + // 获取对象 + InputStream is = client.getObject(GetObjectArgs.builder() + .bucket(bucketName) + .object(objectName) + .build()); + + // 获取文件元信息(如 contentType) + StatObjectResponse stat = client.statObject(StatObjectArgs.builder() + .bucket(bucketName) + .object(objectName) + .build()); + + String contentType = stat.contentType(); + + // 将流读为 byte[] 以生成 MockMultipartFile + byte[] bytes = IoUtil.readBytes(is); // Hutool 工具类 + HashMap map = new HashMap<>(); + map.put("objectName",objectName); + map.put("contentType",contentType); + map.put("bytes",bytes); + + return map; + } + + + //文件复制 + public static void copyFile(String sourceObjectName, String targetObjectName, String sourceBucket, String targetBucket) throws Exception { + MinioClient client = getMinioClient(); + + // 使用服务器端复制,无需下载上传 + client.copyObject(CopyObjectArgs.builder() + .bucket(targetBucket) // 目标桶 + .object(targetObjectName) // 目标对象 + .source(CopySource.builder() + .bucket(sourceBucket) + .object(sourceObjectName) + .build()) + .build()); + } + + + + +} diff --git a/dk-modules/sample/src/main/java/org/dromara/sample/wayline/service/impl/AiCompareServiceImpl.java b/dk-modules/sample/src/main/java/org/dromara/sample/wayline/service/impl/AiCompareServiceImpl.java index 3a04257..21ec388 100644 --- a/dk-modules/sample/src/main/java/org/dromara/sample/wayline/service/impl/AiCompareServiceImpl.java +++ b/dk-modules/sample/src/main/java/org/dromara/sample/wayline/service/impl/AiCompareServiceImpl.java @@ -1,25 +1,26 @@ package org.dromara.sample.wayline.service.impl; import cn.hutool.core.convert.Convert; +import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; -import com.alibaba.fastjson.JSON; +import cn.hutool.json.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import io.minio.MinioClient; +import io.minio.StatObjectArgs; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.dubbo.config.annotation.DubboReference; -import org.apache.ibatis.executor.BatchResult; import org.dromara.business.api.RemoteBusinessAlertService; import org.dromara.business.api.domain.bo.RemoteBusinessAlertBo; +import org.dromara.business.api.domain.vo.RemoteBusinessAlertConstructInfo; import org.dromara.business.api.domain.vo.RemoteBusinessAlertVo; import org.dromara.common.core.constant.AiCompareStatusConstants; -import org.dromara.common.core.constant.BusinessConstants; import org.dromara.common.core.exception.ServiceException; -import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.TableDataInfo; @@ -28,10 +29,7 @@ import org.dromara.common.sdk.mqtt.CommonTopicRequest; import org.dromara.common.sdk.mqtt.MqttGatewayPublish; import org.dromara.common.sdk.mqtt.TopicConst; import org.dromara.sample.media.constant.MinIOConstants; -import org.dromara.sample.media.mapper.IFileMapper; -import org.dromara.sample.media.model.MediaFileEntity; import org.dromara.sample.media.service.IFileService; -import org.dromara.sample.media.service.IMediaService; import org.dromara.sample.wayline.mapper.IAiCompareMapper; import org.dromara.sample.wayline.mapper.IAiComparePlateMapper; import org.dromara.sample.wayline.mapper.IWaylineJobMapper; @@ -45,13 +43,11 @@ import org.dromara.sample.wayline.service.IAiCompareService; import org.dromara.system.api.model.LoginUser; import org.dromara.workflow.api.RemoteWorkflowService; import org.dromara.workflow.api.domain.RemoteStartProcess; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; /** @@ -206,21 +202,116 @@ public class AiCompareServiceImpl implements IAiCompareService { AiCompareEntity aiCompareEntity = aiCompareMapper.selectById(id); return listMediaFile(aiCompareEntity.getJobId(),aiCompareEntity.getId(),3600,true); } + +// @Value("${spring.profiles.active}") +// private String activeProfile; + @Override - public Boolean pictureFrame(MapobjectMap) { + public Boolean pictureFrame(Map objectMap) { FrameDTO frameDTO = Convert.convert(FrameDTO.class, objectMap); AiCompareEntity aiCompareEntity = aiCompareMapper.selectById(frameDTO.getCompareId()); aiCompareEntity.setStatus(AiCompareStatusConstants.COMPARE_STATUS_3); aiCompareEntity.setId(frameDTO.getCompareId()); aiCompareMapper.updateById(aiCompareEntity); frameDTO.setJobName(aiCompareEntity.getJobName()); - frameDTO.setFileUrl(fileService.getObjectUrlOne(MinIOConstants.BUCKET_MEDIAFILE,frameDTO.getFileUrl(),3600).toString()); - frameDTO.setMateFileUrl(fileService.getObjectUrlOne(MinIOConstants.BUCKET_MEDIAFILE,frameDTO.getMateFileUrl(),3600).toString()); + String originFileUrl = frameDTO.getFileUrl(); + String fileUrl = fileService.getObjectUrlOne(MinIOConstants.BUCKET_MEDIAFILE, originFileUrl, 3600).toString(); + frameDTO.setFileUrl(fileUrl); + String originMateFileUrl = frameDTO.getMateFileUrl(); + String mateFileUrl = fileService.getObjectUrlOne(MinIOConstants.BUCKET_MEDIAFILE, originMateFileUrl, 3600).toString(); + frameDTO.setMateFileUrl(mateFileUrl); String topic = TopicConst.IMAGE +TopicConst.FRAME; - mqttGatewayPublish.publish(topic,new CommonTopicRequest().setData(frameDTO),1); + + +// if(StrUtil.equals(activeProfile,"w_fengxianranqi")) +// activeProfile="w_fengxianranqi" + String activeProfile = MapUtil.getStr(objectMap, "activeProfile", "default"); + if (StrUtil.equals("default", activeProfile)) { + //发送mqtt给算法,处理完 + mqttGatewayPublish.publish(topic, new CommonTopicRequest().setData(frameDTO), 1); + } else { + + //图片处理 +// fileService.get(MinIOConstants.BUCKET_MEDIAFILE, originMateFileUrl, 3600); + + //复制原图到指定bucket + String copyFileUrl = fileService.copyFile(MinIOConstants.BUCKET_MEDIAFILE, originMateFileUrl, MinIOConstants.BUCKET_DKCY); +// String copyFileUrl = fileService.copyFile(MinIOConstants.BUCKET_MEDIAFILE, originFileUrl, MinIOConstants.BUCKET_ALERT); + ArrayList alertVoList = new ArrayList<>(); + //手动简化逻辑,上传图片 + int frameCount =0; + for (Map alertMap : frameDTO.getFrameList()) { + if(frameCount >= 1 ){continue;} //暂时只保存一个文件 + //businessAlert数据 + RemoteBusinessAlertVo remoteBusinessAlertVo = new RemoteBusinessAlertVo(); +// remoteBusinessAlertVo.setAlertType("1"); //1:图片比对预警 2:AI实时预警 + remoteBusinessAlertVo.setJobId(aiCompareEntity.getJobId()); + remoteBusinessAlertVo.setJobName(aiCompareEntity.getJobName()); + remoteBusinessAlertVo.setAssign(false); + + remoteBusinessAlertVo.setImages(originMateFileUrl);//fileUrl + remoteBusinessAlertVo.setMaxImages(originMateFileUrl);//mateFileUrl + remoteBusinessAlertVo.setMateSourceImgUrl(originFileUrl);//mateFileUrl + remoteBusinessAlertVo.setLat("34.20912175973148"); + remoteBusinessAlertVo.setLng("117.2260332850499"); + remoteBusinessAlertVo.setLabelCn(MapUtil.getStr(alertMap,"labelCn","")); + remoteBusinessAlertVo.setLabelEn(MapUtil.getStr(alertMap,"labelEn","")); + remoteBusinessAlertVo.setTaskContent(""); + //面积计算 + setupArea(alertMap, remoteBusinessAlertVo); + + remoteBusinessAlertVo.setHandleType("waiting"); + remoteBusinessAlertVo.setDeptId(aiCompareEntity.getCreateDept()+""); + remoteBusinessAlertVo.setDeptName(aiCompareEntity.getDeptName()); + remoteBusinessAlertVo.setHandleNum(0); + + //businessAlertConstructInfo数据 + + RemoteBusinessAlertConstructInfo acInfo = new RemoteBusinessAlertConstructInfo(); + acInfo.setBusinessType(2l); + acInfo.setJobId(aiCompareEntity.getJobId()); + acInfo.setJobName(aiCompareEntity.getJobName()); + + acInfo.setConstructName(MapUtil.getStr(alertMap,"constructName","")); + acInfo.setConstructDept(MapUtil.getStr(alertMap,"constructDept","")); + acInfo.setConstructLeader(MapUtil.getStr(alertMap,"constructLeader","")); + acInfo.setPhonenumber(MapUtil.getStr(alertMap,"phonenumber","")); + acInfo.setAddress(MapUtil.getStr(alertMap,"address","")); + acInfo.setPipeline(MapUtil.getStr(alertMap,"pipeline","")); + acInfo.setRemark(MapUtil.getStr(alertMap,"remark","")); + + remoteBusinessAlertVo.setRemoteAlertConstructInfo(acInfo); + alertVoList.add(remoteBusinessAlertVo); + frameCount +=1; + } + businessAlertService.saveBusinessAlert(alertVoList,activeProfile); + } + return true; } + private static void setupArea(Map alertMap, RemoteBusinessAlertVo remoteBusinessAlertVo) { + double lx = MapUtil.getInt(alertMap,"lx",0); + double ly = MapUtil.getInt(alertMap,"ly",0); + double rx = MapUtil.getInt(alertMap,"rx",0); + double ry = MapUtil.getInt(alertMap,"ry",0); + + double areaw = Math.abs(rx - lx); + double areal = Math.abs(ry - ly); + double area = areaw * areal; + remoteBusinessAlertVo.setArea((long)area); + remoteBusinessAlertVo.setAreaL((long)areal); + remoteBusinessAlertVo.setAreaW((long)areaw); + + JSONObject entries = new JSONObject(); + entries.set("lef_x", lx); + entries.set("lef_y", ly); + entries.set("right_x", rx); + entries.set("right_y", ry); + remoteBusinessAlertVo.setPixelCoordinate(entries.toString()); + } + + @Override public Boolean expose(List> mapList) { if(!mapList.isEmpty()){ @@ -246,7 +337,7 @@ public class AiCompareServiceImpl implements IAiCompareService { AiCompareAlertDTO compareAlertDTO = Convert.convert(AiCompareAlertDTO.class,map); aiComparePlateMapper.update(new LambdaUpdateWrapper().eq(AiComparePlateEntity::getFileId,compareAlertDTO.getFileId()).set(AiComparePlateEntity::getPatternName,compareAlertDTO.getDiscernImgUrl())); List handleList = compareAlertDTO.getHandleList(); - return businessAlertService.saveBusinessAlert(handleList); + return businessAlertService.saveBusinessAlert(handleList,"default"); } @Override diff --git a/dk-modules/sample/src/main/java/org/dromara/sample/wayline/service/impl/SDKWaylineService.java b/dk-modules/sample/src/main/java/org/dromara/sample/wayline/service/impl/SDKWaylineService.java index 4e18381..40b3939 100644 --- a/dk-modules/sample/src/main/java/org/dromara/sample/wayline/service/impl/SDKWaylineService.java +++ b/dk-modules/sample/src/main/java/org/dromara/sample/wayline/service/impl/SDKWaylineService.java @@ -111,14 +111,16 @@ public class SDKWaylineService extends AbstractWaylineService { .completedTime(LocalDateTime.now()) .mediaCount(output.getExt().getMediaCount()) .build(); - Optional deviceOsd = deviceRedisService.getDeviceOsd(deviceOpt.get().getChildDeviceSn(), OsdDockDrone.class); - Integer totalFlightSorties = deviceOsd.get().getTotalFlightSorties(); - Float totalFlightTime = deviceOsd.get().getTotalFlightTime(); - DeviceFlightRecordsEntity deviceFlightRecords = new DeviceFlightRecordsEntity(); - deviceFlightRecords.setDeviceSn(response.getGateway()); - deviceFlightRecords.setFlyCount(totalFlightSorties); - deviceFlightRecords.setFlyAccTime(totalFlightTime.intValue()); - deviceFlightRecordsService.saveDeviceFlight(deviceFlightRecords); + //Optional deviceOsd = deviceRedisService.getDeviceOsd(deviceOpt.get().getChildDeviceSn(), OsdDockDrone.class); + +// Integer totalFlightSorties = deviceOsd.get().getTotalFlightSorties(); +// Float totalFlightTime = deviceOsd.get().getTotalFlightTime(); +// DeviceFlightRecordsEntity deviceFlightRecords = new DeviceFlightRecordsEntity(); +// deviceFlightRecords.setDeviceSn(response.getGateway()); +// deviceFlightRecords.setFlyCount(totalFlightSorties); +// deviceFlightRecords.setFlyAccTime(totalFlightTime.intValue()); +// deviceFlightRecordsService.saveDeviceFlight(deviceFlightRecords); + // record the update of the media count. if (Objects.nonNull(job.getMediaCount()) && job.getMediaCount() != 0) { mediaRedisService.setMediaCount(response.getGateway(), job.getJobId(),