| | |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | | import org.sxkj.common.constant.WordOrderConstant; |
| | | import org.sxkj.common.utils.OrderNumUtils; |
| | | import org.sxkj.gd.workorder.entity.GdClueEventEntity; |
| | | import org.sxkj.gd.workorder.entity.GdTaskResultEntity; |
| | | import org.sxkj.gd.workorder.enums.EventStatusEnum; |
| | | import org.sxkj.gd.workorder.excel.GdClueEventExcel; |
| | | import org.sxkj.gd.workorder.mapper.GdClueEventMapper; |
| | | import org.sxkj.gd.workorder.param.GdClueEventDistributeParam; |
| | | import org.sxkj.gd.workorder.param.GdClueEventRejectParam; |
| | | import org.sxkj.gd.workorder.param.GdClueEventStatusUpdateParam; |
| | | import org.sxkj.gd.workorder.service.IGdClueEventService; |
| | | import org.sxkj.gd.workorder.service.IGdClueEventStatusFlowService; |
| | | import org.sxkj.gd.workorder.service.IGdTaskResultService; |
| | | import org.sxkj.gd.workorder.vo.GdClueEventCountVO; |
| | | import org.sxkj.gd.workorder.vo.GdClueEventListVO; |
| | |
| | | * @author lw |
| | | * @since 2026-01-14 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | @AllArgsConstructor |
| | | public class GdClueEventServiceImpl extends BaseServiceImpl<GdClueEventMapper, GdClueEventEntity> implements IGdClueEventService { |
| | | |
| | | private final IGdTaskResultService gdTaskResultService; |
| | | private final IGdClueEventStatusFlowService gdClueEventStatusFlowService; |
| | | |
| | | @Override |
| | | public IPage<GdClueEventVO> selectGdClueEventPage(IPage<GdClueEventVO> page, GdClueEventVO gdClueEvent) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<GdClueEventListVO> listGdClueEventByDept(Integer onlyMine) { |
| | | Long deptId = Long.valueOf(AuthUtil.getDeptId()); |
| | | Long userId = AuthUtil.getUserId(); |
| | | Integer mine = onlyMine == null ? 0 : onlyMine; |
| | | return baseMapper.selectGdClueEventSimpleList(deptId, userId, mine); |
| | | public List<GdClueEventListVO> listGdClueEventByDept(Integer onlyMine, String keyword) { |
| | | // 1. 获取当前用户部门ID和用户ID |
| | | Long deptId = null; |
| | | Long userId = null; |
| | | Integer mine = 0; |
| | | List<Integer> statusList; |
| | | |
| | | // 2. 判断是否为管理员 |
| | | boolean isAdmin = AuthUtil.isAdministrator() || AuthUtil.isAdmin(); |
| | | |
| | | if (!isAdmin) { |
| | | // 非管理员:获取部门ID和用户ID |
| | | deptId = Long.valueOf(AuthUtil.getDeptId()); |
| | | userId = AuthUtil.getUserId(); |
| | | mine = onlyMine == null ? 0 : onlyMine; |
| | | // 非管理员:排除已退回状态(状态2) |
| | | statusList = java.util.Arrays.asList(0, 1, 3, 4); |
| | | } else { |
| | | // 管理员:可以查询所有状态 |
| | | statusList = java.util.Arrays.asList(0, 1, 2, 3, 4); |
| | | } |
| | | |
| | | // 3. 查询事件列表 |
| | | return baseMapper.selectGdClueEventSimpleList(deptId, userId, mine, keyword, statusList); |
| | | } |
| | | |
| | | /** |
| | | * 列表查询(分页) |
| | | * <p> |
| | | * 步骤: |
| | | * 1. 获取当前用户部门ID和用户ID |
| | | * 2. 判断是否为管理员,设置状态列表 |
| | | * 3. 根据事件状态参数调整状态列表 |
| | | * 4. 查询分页数据 |
| | | * </p> |
| | | * |
| | | * @param page 分页对象 |
| | | * @param onlyMine 是否仅我的数据 |
| | | * @param keyword 事件编号关键字 |
| | | * @param eventStatus 事件状态 |
| | | * @param startTime 开始时间 |
| | | * @param endTime 结束时间 |
| | | * @return 分页数据 |
| | | */ |
| | | @Override |
| | | public IPage<GdClueEventListVO> pageGdClueEventByDept(IPage<GdClueEventListVO> page, Integer onlyMine, String keyword, |
| | | Integer eventStatus, String startTime, String endTime) { |
| | | // 1. 获取当前用户部门ID和用户ID |
| | | Long deptId = null; |
| | | Long userId = null; |
| | | Integer mine = 0; |
| | | List<Integer> statusList; |
| | | |
| | | // 2. 判断是否为管理员 |
| | | boolean isAdmin = AuthUtil.isAdministrator() || AuthUtil.isAdmin(); |
| | | |
| | | if (!isAdmin) { |
| | | // 非管理员:获取部门ID和用户ID |
| | | deptId = Long.valueOf(AuthUtil.getDeptId()); |
| | | userId = AuthUtil.getUserId(); |
| | | mine = onlyMine == null ? 0 : onlyMine; |
| | | // 非管理员:排除已退回状态(状态2) |
| | | statusList = java.util.Arrays.asList(0, 1, 3, 4); |
| | | } else { |
| | | // 管理员:可以查询所有状态 |
| | | statusList = java.util.Arrays.asList(0, 1, 2, 3, 4); |
| | | } |
| | | |
| | | // 3. 如果指定了事件状态,优先使用指定的状态 |
| | | if (eventStatus != null) { |
| | | // 检查指定的状态是否在允许的状态列表中 |
| | | if (statusList.contains(eventStatus)) { |
| | | statusList = java.util.Arrays.asList(eventStatus); |
| | | } else { |
| | | // 如果指定的状态不在允许列表中(如非管理员查询状态2),返回空结果 |
| | | statusList = java.util.Collections.emptyList(); |
| | | } |
| | | } |
| | | |
| | | // 4. 查询分页数据 |
| | | return page.setRecords(baseMapper.selectGdClueEventSimpleList(page, deptId, userId, mine, keyword, statusList, startTime, endTime)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | throw new RuntimeException("事件不存在"); |
| | | } |
| | | String address = GdGeoAddressUtil.getFormattedAddress(detail.getLongitude(), detail.getLatitude()); |
| | | log.info("地址:{}", address); |
| | | if (StringUtil.isNotBlank(address)) { |
| | | detail.setEventLocation(address); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public GdClueEventCountVO getGdClueEventCount() { |
| | | Long deptId = Long.valueOf(AuthUtil.getDeptId()); |
| | | Long userId = AuthUtil.getUserId(); |
| | | GdClueEventCountVO countVO = baseMapper.selectGdClueEventCount(deptId, userId); |
| | | public GdClueEventCountVO getGdClueEventCount(String keyword) { |
| | | // 1. 获取当前用户部门ID和用户ID |
| | | List<Integer> statusList; |
| | | Long deptId = null; |
| | | Long userId = null; |
| | | // 2. 判断是否为管理员 |
| | | boolean isAdmin = AuthUtil.isAdministrator() || AuthUtil.isAdmin(); |
| | | |
| | | if (isAdmin) { |
| | | // 管理员:可以查询所有状态 |
| | | statusList = java.util.Arrays.asList(0, 1, 2, 3, 4); |
| | | } else { |
| | | deptId = Long.valueOf(AuthUtil.getDeptId()); |
| | | userId = AuthUtil.getUserId(); |
| | | // 非管理员:排除已退回状态(状态2) |
| | | statusList = java.util.Arrays.asList(0, 1, 3, 4); |
| | | } |
| | | |
| | | // 3. 查询统计数据 |
| | | GdClueEventCountVO countVO = baseMapper.selectGdClueEventCount(deptId, userId, keyword, statusList); |
| | | |
| | | // 4. 处理空结果,返回默认值 |
| | | if (countVO == null) { |
| | | GdClueEventCountVO empty = new GdClueEventCountVO(); |
| | | empty.setTotalCount(0L); |
| | | empty.setMyCount(0L); |
| | | empty.setReturnedCount(0L); |
| | | empty.setDisposedCount(0L); |
| | | empty.setCompletedCount(0L); |
| | | return empty; |
| | | } |
| | | |
| | | // 5. 返回统计结果 |
| | | return countVO; |
| | | } |
| | | |
| | |
| | | clueEvent.setLongitude(distributeParam.getLongitude()); |
| | | clueEvent.setLatitude(distributeParam.getLatitude()); |
| | | clueEvent.setEventStatus(1); |
| | | String times = OrderNumUtils.initOrderNum(WordOrderConstant.EVENT_NUM_KEY); |
| | | String eventNum = WordOrderConstant.EVENT_NUM_PREFIX + times; |
| | | clueEvent.setEventNum(eventNum); |
| | | if (StringUtil.isBlank(distributeParam.getAreaCode())) { |
| | | clueEvent.setAreaCode(taskResult.getAreaCode()); |
| | | } else { |
| | |
| | | clueEvent.setCreateUser(AuthUtil.getUserId()); |
| | | clueEvent.setCreateDept(Long.valueOf(AuthUtil.getDeptId())); |
| | | clueEvent.setCreateTime(new Date()); |
| | | clueEvent.setEventName(distributeParam.getEventName()); |
| | | if (!save(clueEvent)) { |
| | | throw new RuntimeException("事件分发失败"); |
| | | } |
| | | taskResult.setDistributeStatus(1); |
| | | taskResult.setUpdateUser(AuthUtil.getUserId()); |
| | | taskResult.setUpdateTime(new Date()); |
| | | if (!gdTaskResultService.updateById(taskResult)) { |
| | | if (!gdTaskResultService.updateTaskResultById(taskResult)) { |
| | | throw new RuntimeException("成果状态更新失败"); |
| | | } |
| | | return true; |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean rejectClueEvent(GdClueEventRejectParam rejectParam) { |
| | | public boolean handleClueEvent(GdClueEventRejectParam rejectParam) { |
| | | GdClueEventEntity clueEvent = getById(rejectParam.getEventId()); |
| | | if (clueEvent == null || (clueEvent.getIsDeleted() != null && clueEvent.getIsDeleted() != 0)) { |
| | | throw new RuntimeException("事件不存在"); |
| | | } |
| | | if (clueEvent.getEventStatus() == null || clueEvent.getEventStatus() != 1) { |
| | | throw new RuntimeException("事件当前状态无法驳回"); |
| | | throw new RuntimeException("事件当前状态无法处理"); |
| | | } |
| | | clueEvent.setEventStatus(2); |
| | | Integer operateStatus = rejectParam.getEventStatus(); |
| | | if (operateStatus == null || (operateStatus != 0 && operateStatus != 1)) { |
| | | throw new RuntimeException("事件状态不正确"); |
| | | } |
| | | int targetStatus = operateStatus == 0 ? 2 : 3; |
| | | clueEvent.setEventStatus(targetStatus); |
| | | clueEvent.setUpdateUser(AuthUtil.getUserId()); |
| | | clueEvent.setUpdateTime(new Date()); |
| | | if (!updateById(clueEvent)) { |
| | | throw new RuntimeException("事件驳回失败"); |
| | | throw new RuntimeException("事件处理失败"); |
| | | } |
| | | GdTaskResultEntity taskResult = gdTaskResultService.getById(clueEvent.getResultId()); |
| | | if (taskResult == null || (taskResult.getIsDeleted() != null && taskResult.getIsDeleted() != 0)) { |
| | | throw new RuntimeException("成果不存在"); |
| | | } |
| | | taskResult.setDistributeStatus(2); |
| | | // 使用XML方式更新成果信息(更新所有字段) |
| | | taskResult.setDistributeStatus(targetStatus); |
| | | taskResult.setUpdateUser(AuthUtil.getUserId()); |
| | | taskResult.setUpdateTime(new Date()); |
| | | if (!gdTaskResultService.updateById(taskResult)) { |
| | | if (!gdTaskResultService.updateTaskResultById(taskResult)) { |
| | | throw new RuntimeException("成果状态更新失败"); |
| | | } |
| | | return true; |
| | |
| | | return gdClueEventList; |
| | | } |
| | | |
| | | /** |
| | | * 对外接口新增或修改事件 |
| | | * <p> |
| | | * 步骤: |
| | | * 1. 生成事件编号(使用SJ前缀) |
| | | * 2. 设置事件编号到实体 |
| | | * 3. 保存或更新事件信息 |
| | | * </p> |
| | | * |
| | | * @param gdClueEvent 事件实体 |
| | | * @return 是否操作成功 |
| | | */ |
| | | @Override |
| | | public boolean saveOrUpdateExternal(GdClueEventEntity gdClueEvent) { |
| | | // 1. 生成事件编号 |
| | | String times = OrderNumUtils.initOrderNum(WordOrderConstant.EVENT_NUM_KEY); |
| | | String eventNum = WordOrderConstant.SJ_EVENT_NUM_PREFIX + times; |
| | | // 2. 设置事件编号 |
| | | gdClueEvent.setEventNum(eventNum); |
| | | gdClueEvent.setCreateTime(new Date()); |
| | | gdClueEvent.setEventStatus(1); |
| | | // 3. 保存或更新 |
| | | return saveOrUpdate(gdClueEvent); |
| | | } |
| | | |
| | | /** |
| | | * 更新事件状态 |
| | | * <p> |
| | | * 步骤: |
| | | * 1. 参数校验 |
| | | * 2. 查询事件信息 |
| | | * 3. 校验状态流转合法性 |
| | | * 4. 更新事件状态 |
| | | * 5. 插入状态流转记录 |
| | | * </p> |
| | | * |
| | | * @param updateParam 状态更新参数 |
| | | * @return 是否操作成功 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean updateEventStatus(GdClueEventStatusUpdateParam updateParam) { |
| | | // 1. 参数校验 |
| | | if (updateParam == null || updateParam.getEventId() == null) { |
| | | throw new RuntimeException("参数不能为空"); |
| | | } |
| | | if (updateParam.getTargetStatus() == null) { |
| | | throw new RuntimeException("目标状态不能为空"); |
| | | } |
| | | |
| | | // 2. 查询事件信息 |
| | | GdClueEventEntity eventEntity = getById(updateParam.getEventId()); |
| | | if (eventEntity == null || (eventEntity.getIsDeleted() != null && eventEntity.getIsDeleted() != 0)) { |
| | | throw new RuntimeException("事件不存在"); |
| | | } |
| | | |
| | | Integer oldStatus = eventEntity.getEventStatus(); |
| | | Integer targetStatus = updateParam.getTargetStatus(); |
| | | |
| | | // 3. 校验状态流转合法性 |
| | | if (!EventStatusEnum.isValidCode(targetStatus)) { |
| | | throw new RuntimeException("目标状态编码无效"); |
| | | } |
| | | |
| | | if (!EventStatusEnum.isValidTransition(oldStatus, targetStatus)) { |
| | | String oldStatusName = EventStatusEnum.getNameByCode(oldStatus); |
| | | String newStatusName = EventStatusEnum.getNameByCode(targetStatus); |
| | | throw new RuntimeException(String.format("状态流转非法:不允许从[%s]流转到[%s]", oldStatusName, newStatusName)); |
| | | } |
| | | |
| | | // 4. 更新事件状态 |
| | | eventEntity.setEventStatus(targetStatus); |
| | | eventEntity.setUpdateUser(AuthUtil.getUserId()); |
| | | eventEntity.setUpdateTime(new Date()); |
| | | if (!updateById(eventEntity)) { |
| | | throw new RuntimeException("更新事件状态失败"); |
| | | } |
| | | |
| | | // 5. 插入状态流转记录 |
| | | gdClueEventStatusFlowService.insertStatusFlow( |
| | | updateParam.getEventId(), |
| | | oldStatus, |
| | | targetStatus, |
| | | updateParam.getOperateContent(), |
| | | updateParam.getOperateTime() != null ? updateParam.getOperateTime() : new Date() |
| | | ); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | } |