/* * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the dreamlu.net developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ package org.sxkj.gd.workorder.service.impl; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.utils.Func; import org.sxkj.gd.workorder.entity.GdClueDisposeRecordEntity; import org.sxkj.gd.workorder.entity.GdClueEventEntity; import org.sxkj.gd.workorder.enums.EventStatusEnum; import org.sxkj.gd.workorder.mapper.GdClueDisposeRecordMapper; import org.sxkj.gd.workorder.param.GdClueDisposeRecordAddParam; import org.sxkj.gd.workorder.service.IGdClueDisposeRecordService; import org.sxkj.gd.workorder.service.IGdClueEventService; import org.sxkj.gd.workorder.service.IGdClueEventStatusFlowService; import org.sxkj.gd.workorder.vo.GdClueDisposeRecordVO; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springblade.core.mp.base.BaseServiceImpl; import java.util.Date; import java.util.List; /** * 事件处置流水记录表 服务实现类 * * @author system * @since 2026-07-29 */ @Slf4j @Service @AllArgsConstructor public class GdClueDisposeRecordServiceImpl extends BaseServiceImpl implements IGdClueDisposeRecordService { private final IGdClueEventService gdClueEventService; private final IGdClueEventStatusFlowService gdClueEventStatusFlowService; /** * 根据事件ID查询处置记录列表 *

* 步骤: * 1. 参数校验 * 2. 查询处置记录列表 * 3. 补充状态名称 *

* * @param eventId 事件ID * @return 处置记录列表 */ @Override public List getDisposeRecordsByEventId(Long eventId) { // 1. 参数校验 if (eventId == null) { throw new RuntimeException("事件ID不能为空"); } // 2. 查询处置记录列表 List records = baseMapper.selectDisposeRecordsByEventId(eventId); // 3. 补充状态名称和类型名称 if (Func.isNotEmpty(records)) { records.forEach(record -> { // 补充记录类型名称 if (record.getRecordType() != null) { record.setRecordTypeName(record.getRecordType() == 0 ? "核查记录" : "处置记录"); } // 补充处置状态名称 if (record.getDisposeStatus() != null) { record.setDisposeStatusName(EventStatusEnum.getNameByCode(record.getDisposeStatus())); } }); } return records; } /** * 新增处置记录 *

* 步骤: * 1. 参数校验 * 2. 查询事件信息 * 3. 如果需要同步更新事件状态,则更新事件状态 * 4. 构建处置记录实体 * 5. 保存处置记录 *

* * @param addParam 新增参数 * @return 是否成功 */ @Override @Transactional(rollbackFor = Exception.class) public boolean addDisposeRecord(GdClueDisposeRecordAddParam addParam) { // 1. 参数校验 if (addParam == null || addParam.getEventId() == null) { throw new RuntimeException("参数不能为空"); } if (addParam.getRecordType() == null) { throw new RuntimeException("记录类型不能为空"); } // 2. 查询事件信息 GdClueEventEntity eventEntity = gdClueEventService.getById(addParam.getEventId()); if (eventEntity == null || (eventEntity.getIsDeleted() != null && eventEntity.getIsDeleted() != 0)) { throw new RuntimeException("事件不存在"); } Integer oldStatus = eventEntity.getEventStatus(); // 3. 如果需要同步更新事件状态,则更新事件状态 if (addParam.getUpdateEventStatus() != null && addParam.getUpdateEventStatus() && addParam.getTargetEventStatus() != null) { // 校验目标状态合法性 if (!EventStatusEnum.isValidCode(addParam.getTargetEventStatus())) { throw new RuntimeException("目标状态编码无效"); } // 校验状态流转合法性 if (!EventStatusEnum.isValidTransition(oldStatus, addParam.getTargetEventStatus())) { String oldStatusName = EventStatusEnum.getNameByCode(oldStatus); String newStatusName = EventStatusEnum.getNameByCode(addParam.getTargetEventStatus()); throw new RuntimeException(String.format("状态流转非法:不允许从[%s]流转到[%s]", oldStatusName, newStatusName)); } // 更新事件状态 eventEntity.setEventStatus(addParam.getTargetEventStatus()); eventEntity.setUpdateUser(AuthUtil.getUserId()); eventEntity.setUpdateTime(new Date()); if (!gdClueEventService.updateById(eventEntity)) { throw new RuntimeException("更新事件状态失败"); } // 插入状态流转记录 gdClueEventStatusFlowService.insertStatusFlow( addParam.getEventId(), oldStatus, addParam.getTargetEventStatus(), addParam.getDisposeContent(), new Date() ); } // 4. 构建处置记录实体 GdClueDisposeRecordEntity recordEntity = new GdClueDisposeRecordEntity(); recordEntity.setEventId(addParam.getEventId()); recordEntity.setRecordType(addParam.getRecordType()); recordEntity.setDisposeContent(addParam.getDisposeContent()); recordEntity.setAttachUrl(addParam.getAttachUrl()); recordEntity.setOperateTime(new Date()); recordEntity.setDisposeStatus(eventEntity.getEventStatus()); recordEntity.setDisposeUser(AuthUtil.getUserId()); recordEntity.setDisposeDept(Long.valueOf(AuthUtil.getDeptId())); recordEntity.setCreateUser(AuthUtil.getUserId()); recordEntity.setCreateDept(Long.valueOf(AuthUtil.getDeptId())); recordEntity.setCreateTime(new Date()); // 5. 保存处置记录 return save(recordEntity); } }