[add] 添加 AI工单 识别记录模块相关逻辑,添加项目与部门关联

This commit is contained in:
lcj
2025-06-25 09:08:06 +08:00
parent 8bf9f47d62
commit e492c08eef
24 changed files with 889 additions and 27 deletions

2
drone/.gitignore vendored
View File

@ -45,3 +45,5 @@ nbdist/
!*/build/*.java
!*/build/*.html
!*/build/*.xml
*.lck

View File

@ -75,6 +75,7 @@ public class IncSyncYs7DeviceCapturePicData {
if (presets != null && !presets.isEmpty()) {
for (OthDevicePreset preset : presets) {
OthYs7DeviceImgCreateByCapture img = new OthYs7DeviceImgCreateByCapture();
img.setProjectId(ys7Device.getProjectId());
img.setDeviceSerial(deviceSerial);
img.setDeviceName(ys7Device.getDeviceName());
int channelNo = preset.getChannelNo();
@ -105,6 +106,7 @@ public class IncSyncYs7DeviceCapturePicData {
} else {
// 如果没有预置位,则直接对默认通道抓图
OthYs7DeviceImgCreateByCapture img = new OthYs7DeviceImgCreateByCapture();
img.setProjectId(ys7Device.getProjectId());
img.setDeviceSerial(deviceSerial);
img.setDeviceName(ys7Device.getDeviceName());
try {

View File

@ -25,7 +25,8 @@ public class IncSyncYs7DeviceData {
private IOthYs7DeviceService ys7DeviceService;
// 每 5 分钟执行一次
@Scheduled(cron = "0 */5 * * * ?")
// todo 修改为 5 分钟
@Scheduled(cron = "0 */10 * * * ?")
public void run() {
log.info("定时同步摄像头设备数据");
List<Ys7QueryDeviceResponseVo> ys7QueryDeviceList = ys7Manager.queryAllDeviceList();

View File

@ -12,30 +12,37 @@ import java.util.stream.Collectors;
@Getter
public enum SpartaRecTypeEnum {
HAT("安全帽识别", "hat"),
HEAD("不戴安全帽识别", "head"),
SMOKE("吸烟识别", "smoke"),
BELT("安全带识别", "belt"),
WASTE("工程垃圾识别(暂无)", "waste"),
EXCAVATOR("挖掘机", "excavator"),
ROLLER("压路机", "Roller"),
TRUCK_CRANE("汽车吊", "Truck_crane"),
LOADER("装载机", "Loader"),
SUBMERSIBLE_DRILLING_RIG("潜挖钻机", "Submersible_drilling_rig"),
SPRINKLER("洒水车", "Sprinkler"),
TRUCK_MOUNTED_CRANE("随车吊", "Truck_mounted_crane"),
TRUCK("货车", "Truck"),
PHO("光伏板", "pho"),
HOLE("", "hole"),
SHELVES("架子", "shelves"),
PILE("", "pile");
HAT("安全帽识别", "hat", ""),
HEAD("不戴安全帽识别", "head", "1"),
SMOKE("吸烟识别", "smoke", "3"),
BELT("安全带识别", "belt", "2"),
WASTE("工程垃圾识别(暂无)", "waste", ""),
EXCAVATOR("挖掘机", "excavator", ""),
ROLLER("压路机", "Roller", ""),
TRUCK_CRANE("汽车吊", "Truck_crane", ""),
LOADER("装载机", "Loader", ""),
SUBMERSIBLE_DRILLING_RIG("潜挖钻机", "Submersible_drilling_rig", ""),
SPRINKLER("洒水车", "Sprinkler", ""),
TRUCK_MOUNTED_CRANE("随车吊", "Truck_mounted_crane", ""),
TRUCK("货车", "Truck", ""),
PHO("光伏板", "pho", ""),
HOLE("", "hole", ""),
SHELVES("架子", "shelves", ""),
PILE("", "pile", "");
private final String text;
private final String value;
SpartaRecTypeEnum(String text, String value) {
/**
* 描述对应字典violation_level_type
*/
private final String code;
SpartaRecTypeEnum(String text, String value, String code) {
this.text = text;
this.value = value;
this.code = code;
}
public static SpartaRecTypeEnum fromValue(String value) {

View File

@ -16,6 +16,11 @@ public class OthYs7DeviceImgCreateByCapture implements Serializable {
@Serial
private static final long serialVersionUID = 9152300524686055187L;
/**
* 项目id
*/
private Long projectId;
/**
* 设备序列号
*/

View File

@ -27,6 +27,9 @@ import org.dromara.other.domain.dto.ys7deviceimg.OthYs7DeviceImgQueryReq;
import org.dromara.other.domain.vo.ys7deviceimg.OthYs7DeviceImgVo;
import org.dromara.other.mapper.OthYs7DeviceImgMapper;
import org.dromara.other.service.IOthYs7DeviceImgService;
import org.dromara.safety.domain.dto.recognizerecord.HseRecognizeRecordCreateDto;
import org.dromara.safety.domain.enums.HseRecordCategoryEnum;
import org.dromara.safety.service.IHseRecognizeRecordService;
import org.dromara.system.domain.vo.SysOssUploadVo;
import org.dromara.system.service.ISysOssService;
import org.springframework.beans.BeanUtils;
@ -56,6 +59,9 @@ public class OthYs7DeviceImgServiceImpl extends ServiceImpl<OthYs7DeviceImgMappe
@Resource
private SpartaManager spartaManager;
@Resource
private IHseRecognizeRecordService recognizeRecordService;
/**
* 查询萤石摄像头图片
*
@ -189,6 +195,7 @@ public class OthYs7DeviceImgServiceImpl extends ServiceImpl<OthYs7DeviceImgMappe
@Transactional(rollbackFor = Exception.class)
public void saveCapturePic(List<OthYs7DeviceImgCreateByCapture> imgList) {
List<OthYs7DeviceImg> saveList = new ArrayList<>();
List<HseRecognizeRecordCreateDto> recordList = new ArrayList<>();
for (OthYs7DeviceImgCreateByCapture img : imgList) {
OthYs7DeviceImg othYs7DeviceImg = new OthYs7DeviceImg();
String url = img.getUrl();
@ -206,12 +213,16 @@ public class OthYs7DeviceImgServiceImpl extends ServiceImpl<OthYs7DeviceImgMappe
List<SpartaRecTypeEnum> recTypes = List.of(SpartaRecTypeEnum.HEAD, SpartaRecTypeEnum.SMOKE);
SpartaRecognizeVo recognizeVo = spartaManager.recognize(ossUrl, recTypes);
if (recognizeVo != null && recognizeVo.getHasTarget().equals(SpartaHasTargetEnum.YES.getValue())) {
// 记录识别信息
HseRecognizeRecordCreateDto record = new HseRecognizeRecordCreateDto();
record.setCreateTime(new Date());
List<SpartaTargetVo> targets = recognizeVo.getTargets();
othYs7DeviceImg.setTargets(JSONUtil.toJsonStr(targets));
othYs7DeviceImg.setImgSize(JSONUtil.toJsonStr(recognizeVo.getOriginalImgSize()));
othYs7DeviceImg.setIsRecognize(SpartaHasTargetEnum.YES.getValue());
List<String> recTypeList = targets.stream().map(SpartaTargetVo::getType).distinct().toList();
othYs7DeviceImg.setRecType(JSONUtil.toJsonStr(recTypeList));
String targetUrl = null;
try {
ImageStreamResult imageStreamResult = spartaManager.drawImageToStream(url, targets);
InputStream inputStream = imageStreamResult.getInputStream();
@ -219,13 +230,20 @@ public class OthYs7DeviceImgServiceImpl extends ServiceImpl<OthYs7DeviceImgMappe
long length = imageStreamResult.getLength();
String targetImgPath = Ys7DeviceImgConstant.getTargetImgOssPath(originalFilename, deviceSerial);
SysOssUploadVo drawImageUploadVo = ossService.uploadFileUrlWithNoSave(inputStream, targetImgPath, contentType, length);
String targetUrl = drawImageUploadVo.getUrl();
targetUrl = drawImageUploadVo.getUrl();
if (StringUtils.isNotBlank(targetUrl)) {
othYs7DeviceImg.setRecognizeUrl(targetUrl);
}
} catch (Exception e) {
log.error("图片识别失败", e);
}
record.setTargets(targets);
record.setDeviceSerial(deviceSerial);
record.setDeviceName(img.getDeviceName());
record.setPicture(targetUrl);
record.setRecordCategory(HseRecordCategoryEnum.MONITOR.getValue());
record.setProjectId(img.getProjectId());
recordList.add(record);
}
saveList.add(othYs7DeviceImg);
}
@ -236,6 +254,9 @@ public class OthYs7DeviceImgServiceImpl extends ServiceImpl<OthYs7DeviceImgMappe
throw new ServiceException("批量新增图片失败,数据库异常", HttpStatus.ERROR);
}
}
if (CollUtil.isNotEmpty(recordList)) {
recognizeRecordService.saveByMonitor(recordList);
}
}
/**

View File

@ -22,8 +22,8 @@ public interface BusProjectConstant {
String PROJECT_CACHE_REDIS_KEY_PREFIX = "project";
/**
* 父级项目id
* 父级id
*/
Long PARENT_PROJECT_ID = 0L;
Long PARENT_ID = 0L;
}

View File

@ -45,6 +45,11 @@ public class BusProject extends BaseEntity {
*/
private Long pId;
/**
* 部门id
*/
private Long deptId;
/**
* 状态0正常 1停用
*/

View File

@ -16,6 +16,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.constant.HttpStatus;
import org.dromara.common.core.constant.SystemConstants;
import org.dromara.common.core.domain.vo.IdAndNameVO;
@ -46,6 +47,9 @@ import org.dromara.project.service.IBusContractorService;
import org.dromara.project.service.IBusProjectFileService;
import org.dromara.project.service.IBusProjectService;
import org.dromara.project.service.IBusUserProjectRelevancyService;
import org.dromara.system.domain.bo.SysDeptBo;
import org.dromara.system.domain.vo.SysDeptVo;
import org.dromara.system.service.ISysDeptService;
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.redis.core.StringRedisTemplate;
@ -63,6 +67,7 @@ import java.util.stream.Collectors;
* @author lcj
* @date 2025-03-04
*/
@Slf4j
@Service
public class BusProjectServiceImpl extends ServiceImpl<BusProjectMapper, BusProject>
implements IBusProjectService {
@ -89,6 +94,9 @@ public class BusProjectServiceImpl extends ServiceImpl<BusProjectMapper, BusProj
@Resource
private IFacMatrixService matrixService;
@Resource
private ISysDeptService deptService;
private final Cache<String, String> WEATHER_CACHE =
Caffeine.newBuilder().initialCapacity(1024)
.maximumSize(10000L)
@ -282,10 +290,32 @@ public class BusProjectServiceImpl extends ServiceImpl<BusProjectMapper, BusProj
project.setPunchRange(punchRange);
// 数据校验
validEntityBeforeSave(project, true);
Long count = this.lambdaQuery().eq(BusProject::getProjectName, req.getProjectName()).count();
if (count > 0) {
if (this.lambdaQuery().eq(BusProject::getProjectName, req.getProjectName()).count() > 0) {
throw new ServiceException("项目名称已存在", HttpStatus.BAD_REQUEST);
}
if (this.lambdaQuery().eq(BusProject::getShortName, req.getShortName()).count() > 0) {
throw new ServiceException("项目简称已存在", HttpStatus.BAD_REQUEST);
}
// 添加新部门
SysDeptBo queryBo = new SysDeptBo();
queryBo.setParentId(BusProjectConstant.PARENT_ID);
// 查询父节点部门
SysDeptVo deptVo = deptService.selectDeptList(queryBo).getFirst();
Long deptId = deptVo.getDeptId();
SysDeptBo createBo = new SysDeptBo();
createBo.setParentId(deptId);
String shortName = req.getShortName();
createBo.setDeptName(shortName != null ? shortName : req.getProjectName());
if (!deptService.checkDeptNameUnique(createBo)) {
throw new ServiceException("新增项目部门'" + createBo.getDeptName() + "'失败,项目名称已存在");
}
// 新增部门
int dept = deptService.insertDept(createBo);
if (dept <= 0) {
throw new ServiceException("新增项目部门'" + createBo.getDeptName() + "'失败");
}
Long newDeptId = deptService.selectIdByDeptName(createBo.getDeptName());
project.setDeptId(newDeptId);
// 写入数据库
boolean save = this.save(project);
if (!save) {

View File

@ -212,7 +212,7 @@ public class BusUserProjectRelevancyServiceImpl extends ServiceImpl<BusUserProje
Map<Long, List<BusProject>> projectMap = projectService.lambdaQuery()
.select(BusProject::getId, BusProject::getPId, BusProject::getProjectName, BusProject::getShortName)
.in(BusProject::getId, projectIdList)
.eq(BusProject::getPId, BusProjectConstant.PARENT_PROJECT_ID)
.eq(BusProject::getPId, BusProjectConstant.PARENT_ID)
.list()
.stream().collect(Collectors.groupingBy(BusProject::getId));
// 获取封装
@ -223,7 +223,7 @@ public class BusUserProjectRelevancyServiceImpl extends ServiceImpl<BusUserProje
if (projectMap.containsKey(projectId)) {
project = projectMap.get(projectId).getFirst();
}
if (project != null && project.getPId().equals(BusProjectConstant.PARENT_PROJECT_ID)) {
if (project != null && project.getPId().equals(BusProjectConstant.PARENT_ID)) {
BusLoginUserProjectRelevancyVo loginUserProjectRelevancy = new BusLoginUserProjectRelevancyVo();
loginUserProjectRelevancy.setId(userProjectRelevancy.getId());
loginUserProjectRelevancy.setUserId(userProjectRelevancy.getUserId());

View File

@ -0,0 +1,81 @@
package org.dromara.safety.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import org.dromara.common.core.domain.R;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.safety.domain.dto.recognizerecord.HseRecognizeRecordQueryReq;
import org.dromara.safety.domain.vo.recognizerecord.HseRecognizeRecordVo;
import org.dromara.safety.service.IHseRecognizeRecordService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 识别记录
*
* @author lcj
* @date 2025-06-24
*/
@Validated
@RestController
@RequestMapping("/safety/recognizeRecord")
public class HseRecognizeRecordController extends BaseController {
@Resource
private IHseRecognizeRecordService recognizeRecordService;
/**
* 查询识别记录列表
*/
@SaCheckPermission("safety:recognizeRecord:list")
@GetMapping("/list")
public TableDataInfo<HseRecognizeRecordVo> list(HseRecognizeRecordQueryReq req, PageQuery pageQuery) {
return recognizeRecordService.queryPageList(req, pageQuery);
}
/**
* 导出识别记录列表
*/
@SaCheckPermission("safety:recognizeRecord:export")
@Log(title = "识别记录", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HseRecognizeRecordQueryReq req, HttpServletResponse response) {
List<HseRecognizeRecordVo> list = recognizeRecordService.queryList(req);
ExcelUtil.exportExcel(list, "识别记录", HseRecognizeRecordVo.class, response);
}
/**
* 获取识别记录详细信息
*
* @param id 主键
*/
@SaCheckPermission("safety:recognizeRecord:query")
@GetMapping("/{id}")
public R<HseRecognizeRecordVo> getInfo(@NotNull(message = "主键不能为空")
@PathVariable Long id) {
return R.ok(recognizeRecordService.queryById(id));
}
/**
* 删除识别记录
*
* @param id 主键
*/
@SaCheckPermission("safety:recognizeRecord:remove")
@Log(title = "识别记录", businessType = BusinessType.DELETE)
@DeleteMapping("/{id}")
public R<Void> remove(@NotEmpty(message = "主键不能为空")
@PathVariable Long id) {
return toAjax(recognizeRecordService.deleteById(id));
}
}

View File

@ -0,0 +1,97 @@
package org.dromara.safety.domain;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
/**
* 识别记录对象 hse_recognize_record
*
* @author lcj
* @date 2025-06-24
*/
@Data
@TableName("hse_recognize_record")
public class HseRecognizeRecord implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 主键id
*/
@TableId(value = "id")
private Long id;
/**
* 项目id
*/
private Long projectId;
/**
* 设备序列号
*/
private String deviceSerial;
/**
* 设备名称
*/
private String deviceName;
/**
* 识别类别1无人机识别 2监控拍摄
*/
private String recordCategory;
/**
* 违章类型(多个逗号分隔)
*/
private String violationType;
/**
* 图片路径
*/
private String picture;
/**
* 违规数量
*/
private Integer num;
/**
* 故障描述
*/
private String description;
/**
* 备注
*/
private String remark;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
/**
* 删除时间
*/
private Date deletedAt;
/**
* 是否删除0正常 1删除
*/
@TableLogic
private Long isDelete;
}

View File

@ -0,0 +1,55 @@
package org.dromara.safety.domain.dto.recognizerecord;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.dromara.manager.spartamanager.vo.SpartaTargetVo;
import java.util.Date;
import java.util.List;
/**
* @author lcj
* @date 2025/6/24 11:48
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class HseRecognizeRecordCreateDto {
/**
* 项目id
*/
private Long projectId;
/**
* 设备序列号
*/
private String deviceSerial;
/**
* 设备名称
*/
private String deviceName;
/**
* 识别类别1无人机识别 2监控拍摄
*/
private String recordCategory;
/**
* 图片路径
*/
private String picture;
/**
* 创建时间
*/
private Date createTime;
/**
* 目标信息
*/
private List<SpartaTargetVo> targets;
}

View File

@ -0,0 +1,48 @@
package org.dromara.safety.domain.dto.recognizerecord;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
/**
* @author lcj
* @date 2025/6/24 11:05
*/
@Data
public class HseRecognizeRecordQueryReq implements Serializable {
@Serial
private static final long serialVersionUID = 8542182388042031320L;
/**
* 项目id
*/
private Long projectId;
/**
* 识别类别1无人机识别 2监控拍摄
*/
private String recordCategory;
/**
* 违章类型(多个逗号分隔)
*/
private String violationType;
/**
* 故障描述
*/
private String description;
/**
* 创建时间
*/
@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
private Date createTime;
}

View File

@ -0,0 +1,24 @@
package org.dromara.safety.domain.enums;
import lombok.Getter;
/**
* @author lcj
* @date 2025/6/24 14:37
*/
@Getter
public enum HseRecordCategoryEnum {
DRONE("无人机识别", "1"),
MONITOR("监控设备识别", "2");
private final String text;
private final String value;
HseRecordCategoryEnum(String text, String value) {
this.text = text;
this.value = value;
}
}

View File

@ -0,0 +1,87 @@
package org.dromara.safety.domain.vo.recognizerecord;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.TableId;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import org.dromara.common.excel.annotation.ExcelDictFormat;
import org.dromara.common.excel.convert.ExcelDictConvert;
import org.dromara.safety.domain.HseRecognizeRecord;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
/**
* 识别记录视图对象 hse_recognize_record
*
* @author lcj
* @date 2025-06-24
*/
@Data
@ExcelIgnoreUnannotated
@AutoMapper(target = HseRecognizeRecord.class)
public class HseRecognizeRecordVo implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 主键id
*/
@TableId(value = "主键id")
private Long id;
/**
* 项目id
*/
@ExcelProperty(value = "项目id")
private Long projectId;
/**
* 设备序列号
*/
@ExcelProperty(value = "设备序列号")
private String deviceSerial;
/**
* 设备名称
*/
@ExcelProperty(value = "设备名称")
private String deviceName;
/**
* 识别类别1无人机识别 2监控拍摄
*/
@ExcelProperty(value = "识别类别", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "1=无人机识别,2=监控拍摄")
private String recordCategory;
/**
* 违章类型(多个逗号分隔)
*/
@ExcelProperty(value = "违章类型", converter = ExcelDictConvert.class)
@ExcelDictFormat(dictType = "violation_level_type")
private String violationType;
/**
* 图片路径
*/
@ExcelProperty(value = "图片路径")
private String picture;
/**
* 故障描述
*/
@ExcelProperty(value = "故障描述")
private String description;
/**
* 创建时间
*/
@ExcelProperty(value = "创建时间")
private Date createTime;
}

View File

@ -0,0 +1,15 @@
package org.dromara.safety.mapper;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
import org.dromara.safety.domain.HseRecognizeRecord;
import org.dromara.safety.domain.vo.recognizerecord.HseRecognizeRecordVo;
/**
* 识别记录Mapper接口
*
* @author lcj
* @date 2025-06-24
*/
public interface HseRecognizeRecordMapper extends BaseMapperPlus<HseRecognizeRecord, HseRecognizeRecordVo> {
}

View File

@ -0,0 +1,87 @@
package org.dromara.safety.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.safety.domain.HseRecognizeRecord;
import org.dromara.safety.domain.dto.recognizerecord.HseRecognizeRecordCreateDto;
import org.dromara.safety.domain.dto.recognizerecord.HseRecognizeRecordQueryReq;
import org.dromara.safety.domain.vo.recognizerecord.HseRecognizeRecordVo;
import java.util.List;
/**
* 识别记录Service接口
*
* @author lcj
* @date 2025-06-24
*/
public interface IHseRecognizeRecordService extends IService<HseRecognizeRecord> {
/**
* 查询识别记录
*
* @param id 主键
* @return 识别记录
*/
HseRecognizeRecordVo queryById(Long id);
/**
* 分页查询识别记录列表
*
* @param req 查询条件
* @param pageQuery 分页参数
* @return 识别记录分页列表
*/
TableDataInfo<HseRecognizeRecordVo> queryPageList(HseRecognizeRecordQueryReq req, PageQuery pageQuery);
/**
* 查询符合条件的识别记录列表
*
* @param req 查询条件
* @return 识别记录列表
*/
List<HseRecognizeRecordVo> queryList(HseRecognizeRecordQueryReq req);
/**
* 创建识别记录(摄像头)
*
* @param recordList 识别记录列表
*/
void saveByMonitor(List<HseRecognizeRecordCreateDto> recordList);
/**
* 删除识别记录信息
*
* @param id 待删除的主键
* @return 是否删除成功
*/
Boolean deleteById(Long id);
/**
* 获取识别记录视图对象
*
* @param recognizeRecord 识别记录对象
* @return 识别记录视图对象
*/
HseRecognizeRecordVo getVo(HseRecognizeRecord recognizeRecord);
/**
* 获取识别记录查询条件封装
*
* @param req 识别记录查询条件
* @return 识别记录查询条件封装
*/
LambdaQueryWrapper<HseRecognizeRecord> buildQueryWrapper(HseRecognizeRecordQueryReq req);
/**
* 获取识别记录分页对象视图
*
* @param recognizeRecordPage 识别记录分页对象
* @return 识别记录分页对象视图
*/
Page<HseRecognizeRecordVo> getVoPage(Page<HseRecognizeRecord> recognizeRecordPage);
}

View File

@ -0,0 +1,225 @@
package org.dromara.safety.service.impl;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.dromara.common.core.constant.HttpStatus;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.ObjectUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.manager.spartamanager.enums.SpartaRecTypeEnum;
import org.dromara.manager.spartamanager.vo.SpartaTargetVo;
import org.dromara.project.service.IBusProjectService;
import org.dromara.safety.domain.HseRecognizeRecord;
import org.dromara.safety.domain.dto.recognizerecord.HseRecognizeRecordCreateDto;
import org.dromara.safety.domain.dto.recognizerecord.HseRecognizeRecordQueryReq;
import org.dromara.safety.domain.vo.recognizerecord.HseRecognizeRecordVo;
import org.dromara.safety.mapper.HseRecognizeRecordMapper;
import org.dromara.safety.service.IHseRecognizeRecordService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
/**
* 识别记录Service业务层处理
*
* @author lcj
* @date 2025-06-24
*/
@Service
public class HseRecognizeRecordServiceImpl extends ServiceImpl<HseRecognizeRecordMapper, HseRecognizeRecord>
implements IHseRecognizeRecordService {
@Resource
private IBusProjectService projectService;
/**
* 查询识别记录
*
* @param id 主键
* @return 识别记录
*/
@Override
public HseRecognizeRecordVo queryById(Long id) {
HseRecognizeRecord recognizeRecord = this.getById(id);
if (recognizeRecord == null) {
throw new ServiceException("识别记录信息不存在", HttpStatus.NOT_FOUND);
}
return this.getVo(recognizeRecord);
}
/**
* 分页查询识别记录列表
*
* @param req 查询条件
* @param pageQuery 分页参数
* @return 识别记录分页列表
*/
@Override
public TableDataInfo<HseRecognizeRecordVo> queryPageList(HseRecognizeRecordQueryReq req, PageQuery pageQuery) {
LambdaQueryWrapper<HseRecognizeRecord> lqw = buildQueryWrapper(req);
Page<HseRecognizeRecord> result = this.page(pageQuery.build(), lqw);
return TableDataInfo.build(this.getVoPage(result));
}
/**
* 查询符合条件的识别记录列表
*
* @param req 查询条件
* @return 识别记录列表
*/
@Override
public List<HseRecognizeRecordVo> queryList(HseRecognizeRecordQueryReq req) {
LambdaQueryWrapper<HseRecognizeRecord> lqw = buildQueryWrapper(req);
return this.list(lqw).stream().map(this::getVo).toList();
}
/**
* 创建识别记录(摄像头)
*
* @param recordList 识别记录列表
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void saveByMonitor(List<HseRecognizeRecordCreateDto> recordList) {
List<HseRecognizeRecord> entityList = new ArrayList<>();
for (HseRecognizeRecordCreateDto record : recordList) {
HseRecognizeRecord entity = new HseRecognizeRecord();
entity.setDeviceSerial(record.getDeviceSerial());
entity.setDeviceName(record.getDeviceName());
entity.setRecordCategory(record.getRecordCategory());
entity.setPicture(record.getPicture());
entity.setCreateTime(record.getCreateTime());
Long projectId = record.getProjectId();
if (projectId == null) {
entity.setRemark("该摄像头暂未分配到项目中");
}
List<SpartaTargetVo> targets = record.getTargets();
List<String> codeList = targets.stream()
.map(SpartaTargetVo::getType).distinct()
.map(SpartaRecTypeEnum::fromValue).filter(Objects::nonNull)
.map(SpartaRecTypeEnum::getCode).filter(Objects::nonNull)
.toList();
String codeStr = String.join(",", codeList);
entity.setViolationType(codeStr);
entity.setNum(targets.size());
entityList.add(entity);
}
if (CollUtil.isNotEmpty(entityList)) {
boolean result = this.saveBatch(entityList);
if (!result) {
throw new ServiceException("保存识别记录失败");
}
}
}
/**
* 校验并批量删除识别记录信息
*
* @param id 待删除的主键集合
* @return 是否删除成功
*/
@Override
public Boolean deleteById(Long id) {
Long userId = LoginHelper.getUserId();
HseRecognizeRecord recognizeRecord = this.getById(id);
Long projectId = recognizeRecord.getProjectId();
projectService.validAuth(projectId, userId);
return this.removeById(id);
}
/**
* 获取识别记录视图对象
*
* @param recognizeRecord 识别记录对象
* @return 识别记录视图对象
*/
@Override
public HseRecognizeRecordVo getVo(HseRecognizeRecord recognizeRecord) {
HseRecognizeRecordVo recognizeRecordVo = new HseRecognizeRecordVo();
if (recognizeRecord == null) {
return recognizeRecordVo;
}
BeanUtils.copyProperties(recognizeRecord, recognizeRecordVo);
return recognizeRecordVo;
}
/**
* 获取识别记录查询条件封装
*
* @param req 识别记录查询条件
* @return 识别记录查询条件封装
*/
@Override
public LambdaQueryWrapper<HseRecognizeRecord> buildQueryWrapper(HseRecognizeRecordQueryReq req) {
LambdaQueryWrapper<HseRecognizeRecord> lqw = new LambdaQueryWrapper<>();
Long projectId = req.getProjectId();
String recordCategory = req.getRecordCategory();
String violationType = req.getViolationType();
String description = req.getDescription();
Date createTime = req.getCreateTime();
lqw.eq(ObjectUtils.isNotEmpty(projectId), HseRecognizeRecord::getProjectId, projectId);
lqw.eq(StringUtils.isNotBlank(recordCategory), HseRecognizeRecord::getRecordCategory, recordCategory);
if (StringUtils.isNotBlank(violationType)) {
lqw.likeRight(HseRecognizeRecord::getViolationType, violationType + ",")
.or()
.likeLeft(HseRecognizeRecord::getViolationType, "," + violationType)
.or()
.like(HseRecognizeRecord::getViolationType, "," + violationType + ",")
.or()
.eq(HseRecognizeRecord::getViolationType, violationType);
}
lqw.like(StringUtils.isNotBlank(description), HseRecognizeRecord::getDescription, description);
if (createTime != null) {
// 构造当天的起始和结束时间
LocalDate localDate = createTime.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDate();
LocalDateTime startOfDay = localDate.atStartOfDay();
LocalDateTime startOfNextDay = localDate.plusDays(1).atStartOfDay();
Date start = Date.from(startOfDay.atZone(ZoneId.systemDefault()).toInstant());
Date end = Date.from(startOfNextDay.atZone(ZoneId.systemDefault()).toInstant());
lqw.ge(HseRecognizeRecord::getCreateTime, start)
.lt(HseRecognizeRecord::getCreateTime, end);
}
return lqw;
}
/**
* 获取识别记录分页对象视图
*
* @param recognizeRecordPage 识别记录分页对象
* @return 识别记录分页对象视图
*/
@Override
public Page<HseRecognizeRecordVo> getVoPage(Page<HseRecognizeRecord> recognizeRecordPage) {
List<HseRecognizeRecord> recognizeRecordList = recognizeRecordPage.getRecords();
Page<HseRecognizeRecordVo> recognizeRecordVoPage = new Page<>(
recognizeRecordPage.getCurrent(),
recognizeRecordPage.getSize(),
recognizeRecordPage.getTotal());
if (CollUtil.isEmpty(recognizeRecordList)) {
return recognizeRecordVoPage;
}
List<HseRecognizeRecordVo> recognizeRecordVoList = recognizeRecordList.stream().map(violationLevel -> {
HseRecognizeRecordVo vo = new HseRecognizeRecordVo();
BeanUtils.copyProperties(violationLevel, vo);
return vo;
}).toList();
recognizeRecordVoPage.setRecords(recognizeRecordVoList);
return recognizeRecordVoPage;
}
}

View File

@ -52,6 +52,14 @@ public interface ISysDeptService {
*/
SysDeptVo selectDeptById(Long deptId);
/**
* 通过部门名称查询部门ID
*
* @param deptName 部门名称
* @return 部门ID
*/
Long selectIdByDeptName(String deptName);
/**
* 通过部门ID串查询部门
*

View File

@ -151,6 +151,20 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
return dept;
}
/**
* 通过部门名称查询部门ID
*
* @param deptName 部门名称
* @return 部门ID
*/
@Override
public Long selectIdByDeptName(String deptName) {
SysDept dept = baseMapper.selectOne(new LambdaQueryWrapper<SysDept>()
.select(SysDept::getDeptId)
.eq(SysDept::getDeptName, deptName));
return dept.getDeptId();
}
@Override
public List<SysDeptVo> selectDeptByIds(List<Long> deptIds) {
return baseMapper.selectDeptList(new LambdaQueryWrapper<SysDept>()

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.dromara.safety.mapper.HseRecognizeRecordMapper">
</mapper>

View File

@ -717,3 +717,23 @@ values(1937100268151767046, '进度类别删除', 1937100268151767042, '4', '#'
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark)
values(1937100268151767047, '进度类别导出', 1937100268151767042, '5', '#', '', 1, 0, 'F', '0', '0', 'progress:progressCategory:export', '#', 103, 1, sysdate(), null, null, '');
-- 菜单 SQL
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark)
values(1937338721300996098, '识别记录', '1935597155897143297', '1', 'recognizeRecord', 'safety/recognizeRecord/index', 1, 0, 'C', '0', '0', 'safety:recognizeRecord:list', '#', 103, 1, sysdate(), null, null, '识别记录菜单');
-- 按钮 SQL
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark)
values(1937338721300996099, '识别记录查询', 1937338721300996098, '1', '#', '', 1, 0, 'F', '0', '0', 'safety:recognizeRecord:query', '#', 103, 1, sysdate(), null, null, '');
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark)
values(1937338721300996100, '识别记录新增', 1937338721300996098, '2', '#', '', 1, 0, 'F', '0', '0', 'safety:recognizeRecord:add', '#', 103, 1, sysdate(), null, null, '');
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark)
values(1937338721300996101, '识别记录修改', 1937338721300996098, '3', '#', '', 1, 0, 'F', '0', '0', 'safety:recognizeRecord:edit', '#', 103, 1, sysdate(), null, null, '');
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark)
values(1937338721300996102, '识别记录删除', 1937338721300996098, '4', '#', '', 1, 0, 'F', '0', '0', 'safety:recognizeRecord:remove', '#', 103, 1, sysdate(), null, null, '');
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark)
values(1937338721300996103, '识别记录导出', 1937338721300996098, '5', '#', '', 1, 0, 'F', '0', '0', 'safety:recognizeRecord:export', '#', 103, 1, sysdate(), null, null, '');

View File

@ -1,4 +1,4 @@
use xinnengyuan;
use xinnengyuandev;
drop table if exists bus_project;
create table `bus_project`
@ -1144,3 +1144,24 @@ CREATE TABLE `hse_violation_level_post`
`post` bigint not null comment '岗位',
primary key (`level`, `post`) using btree
) comment = '等级与岗位关联' collate = utf8mb4_unicode_ci;
DROP TABLE IF EXISTS `hse_recognize_record`;
CREATE TABLE `hse_recognize_record`
(
`id` bigint not null auto_increment comment '主键id',
`project_id` bigint null comment '项目id',
`device_serial` varchar(255) null comment '设备序列号',
`device_name` varchar(255) null comment '设备名称',
`record_category` char(1) null comment '识别类别1无人机识别 2监控拍摄',
`violation_type` varchar(255) null comment '违章类型(多个逗号分隔)',
`picture` varchar(512) null comment '图片路径',
`num` int default 0 null comment '违规数量',
`description` varchar(512) null comment '故障描述',
`remark` varchar(512) null comment '备注',
`create_time` datetime default CURRENT_TIMESTAMP null comment '创建时间',
`update_time` datetime default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP comment '更新时间',
`deleted_at` datetime null comment '删除时间',
`is_delete` tinyint(4) default 0 not null comment '是否删除0正常 1删除',
primary key (`id`) using btree,
index `idx_project_id` (`project_id` asc) using btree comment '项目id'
) comment = '识别记录' COLLATE = utf8mb4_unicode_ci;