/* * 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 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.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.service.IGdClueEventService; import org.sxkj.gd.workorder.service.IGdTaskResultService; import org.sxkj.gd.workorder.vo.GdClueEventCountVO; import org.sxkj.gd.workorder.vo.GdClueEventListVO; import org.sxkj.gd.workorder.vo.GdClueEventVO; import org.sxkj.gd.utils.GdGeoAddressUtil; 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 lw * @since 2026-01-14 */ @Slf4j @Service @AllArgsConstructor public class GdClueEventServiceImpl extends BaseServiceImpl implements IGdClueEventService { private final IGdTaskResultService gdTaskResultService; @Override public IPage selectGdClueEventPage(IPage page, GdClueEventVO gdClueEvent) { return page.setRecords(baseMapper.selectGdClueEventPage(page, gdClueEvent)); } @Override public IPage selectGdClueEventList(IPage page, Wrapper queryWrapper) { return page.setRecords(baseMapper.selectGdClueEventList(page, queryWrapper)); } @Override public List listGdClueEventByDept(Integer onlyMine, String keyword) { Long deptId = Long.valueOf(AuthUtil.getDeptId()); Long userId = AuthUtil.getUserId(); Integer mine = onlyMine == null ? 0 : onlyMine; return baseMapper.selectGdClueEventSimpleList(deptId, userId, mine, keyword); } @Override public GdClueEventVO getGdClueEventDetail(Long id) { if (id == null) { throw new RuntimeException("事件ID不能为空"); } Long deptId = Long.valueOf(AuthUtil.getDeptId()); GdClueEventVO detail = baseMapper.selectGdClueEventDetailById(id, deptId); if (detail == null) { throw new RuntimeException("事件不存在"); } String address = GdGeoAddressUtil.getFormattedAddress(detail.getLongitude(), detail.getLatitude()); log.info("地址:{}", address); if (StringUtil.isNotBlank(address)) { detail.setEventLocation(address); } return detail; } @Override public GdClueEventCountVO getGdClueEventCount(String keyword) { Long deptId = Long.valueOf(AuthUtil.getDeptId()); Long userId = AuthUtil.getUserId(); GdClueEventCountVO countVO = baseMapper.selectGdClueEventCount(deptId, userId, keyword); if (countVO == null) { GdClueEventCountVO empty = new GdClueEventCountVO(); empty.setTotalCount(0L); empty.setMyCount(0L); return empty; } return countVO; } @Override @Transactional(rollbackFor = Exception.class) public boolean distributeClueEvent(GdClueEventDistributeParam distributeParam) { GdTaskResultEntity taskResult = gdTaskResultService.getById(distributeParam.getResultId()); if (taskResult == null || (taskResult.getIsDeleted() != null && taskResult.getIsDeleted() != 0)) { throw new RuntimeException("成果不存在"); } if (taskResult.getDistributeStatus() != null && taskResult.getDistributeStatus() == 1) { throw new RuntimeException("成果已分发,无法再次分发"); } GdClueEventEntity clueEvent = new GdClueEventEntity(); clueEvent.setResultId(distributeParam.getResultId()); clueEvent.setWorkOrderId(distributeParam.getWorkOrderId()); clueEvent.setDisposeUser(distributeParam.getDisposeUser()); clueEvent.setDisposeDept(distributeParam.getDisposeDept()); 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.setAreaCode(distributeParam.getAreaCode()); } 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.updateTaskResultById(taskResult)) { throw new RuntimeException("成果状态更新失败"); } return true; } @Override @Transactional(rollbackFor = Exception.class) 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("事件当前状态无法处理"); } 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("事件处理失败"); } GdTaskResultEntity taskResult = gdTaskResultService.getById(clueEvent.getResultId()); if (taskResult == null || (taskResult.getIsDeleted() != null && taskResult.getIsDeleted() != 0)) { throw new RuntimeException("成果不存在"); } // 使用XML方式更新成果信息(更新所有字段) taskResult.setDistributeStatus(targetStatus); taskResult.setUpdateUser(AuthUtil.getUserId()); taskResult.setUpdateTime(new Date()); if (!gdTaskResultService.updateTaskResultById(taskResult)) { throw new RuntimeException("成果状态更新失败"); } return true; } @Override public List exportGdClueEvent(Wrapper queryWrapper) { List gdClueEventList = baseMapper.exportGdClueEvent(queryWrapper); //gdClueEventList.forEach(gdClueEvent -> { // gdClueEvent.setTypeName(DictCache.getValue(DictEnum.YES_NO, GdClueEvent.getType())); //}); return gdClueEventList; } /** * 对外接口新增或修改事件 *

* 步骤: * 1. 生成事件编号(使用SJ前缀) * 2. 设置事件编号到实体 * 3. 保存或更新事件信息 *

* * @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()); // 3. 保存或更新 return saveOrUpdate(gdClueEvent); } }