| | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springblade.core.mp.base.BaseServiceImpl; |
| | | import org.springblade.core.oss.model.BladeFile; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.utils.DateUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.sxkj.common.constant.WordOrderConstant; |
| | | import org.sxkj.common.utils.OrderNumUtils; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.constant.BladeConstant; |
| | | import org.springblade.core.tool.utils.FileUtil; |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | | import org.sxkj.gd.workorder.entity.GdPatrolTaskEntity; |
| | | import org.sxkj.gd.workorder.entity.GdTaskResultEntity; |
| | | import org.sxkj.gd.workorder.entity.GdWorkOrderEntity; |
| | | import org.sxkj.gd.workorder.entity.GdWorkOrderFlowEntity; |
| | | import org.sxkj.gd.workorder.enums.PatrolTaskStatusEnum; |
| | |
| | | import org.sxkj.gd.workorder.param.GdPatrolTaskAuditParam; |
| | | import org.sxkj.gd.workorder.param.GdPatrolTaskPageParam; |
| | | import org.sxkj.gd.workorder.service.IGdPatrolTaskService; |
| | | import org.sxkj.gd.workorder.service.IGdTaskResultService; |
| | | import org.sxkj.gd.workorder.service.IGdWorkOrderFlowService; |
| | | import org.sxkj.gd.workorder.utils.GdPatrolReportWordUtil; |
| | | import org.sxkj.gd.workorder.vo.GdPatrolTaskVO; |
| | | import org.sxkj.gd.common.GdMultipartFileUtil; |
| | | import org.sxkj.resource.entity.Attach; |
| | | import org.sxkj.resource.feign.IAttachClient; |
| | | import org.sxkj.system.entity.Dept; |
| | | import org.sxkj.system.entity.User; |
| | | import org.sxkj.system.feign.ISysClient; |
| | | import org.sxkj.system.feign.IUserClient; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | |
| | | |
| | | // @Autowired |
| | | // private IGdWorkOrderService gdWorkOrderService; |
| | | |
| | | @Autowired |
| | | private ISysClient sysClient; |
| | | @Autowired |
| | | private IUserClient userClient; |
| | | @Autowired |
| | | private IAttachClient attachClient; |
| | | @Autowired |
| | | private IGdTaskResultService gdTaskResultService; |
| | | @Override |
| | | public IPage<GdPatrolTaskVO> selectGdPatrolTaskPage(IPage<GdPatrolTaskVO> page, GdPatrolTaskPageParam gdPatrolTask, List<Long> deptIdList) { |
| | | return page.setRecords(baseMapper.selectGdPatrolTaskPage(page, gdPatrolTask, deptIdList)); |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean republishPatrolTask(GdPatrolTaskEntity taskEntity) { |
| | | public boolean republishPatrolTask(GdPatrolTaskEntity taskEntity) { |
| | | if (taskEntity == null || taskEntity.getId() == null) { |
| | | throw new RuntimeException("任务信息或ID不能为空"); |
| | | } |
| | | } |
| | | |
| | | // 1. 验证任务是否存在 |
| | | GdPatrolTaskEntity existingTask = getById(taskEntity.getId()); |
| | |
| | | |
| | | return gdWorkOrderFlowService.save(flowEntity); |
| | | } |
| | | |
| | | @Override |
| | | public File exportPatrolReport(Long patrolTaskId) { |
| | | if (patrolTaskId == null) { |
| | | throw new RuntimeException("巡查任务主键不能为空"); |
| | | } |
| | | GdPatrolTaskEntity taskEntity = getById(patrolTaskId); |
| | | if (taskEntity == null) { |
| | | throw new RuntimeException("巡查任务不存在"); |
| | | } |
| | | List<GdTaskResultEntity> resultList = gdTaskResultService.list(Wrappers.<GdTaskResultEntity>lambdaQuery() |
| | | .eq(GdTaskResultEntity::getPatrolTaskId, patrolTaskId) |
| | | .eq(GdTaskResultEntity::getIsDeleted, BladeConstant.DB_NOT_DELETED)); |
| | | String creatorName = getUserName(taskEntity.getCreateUser()); |
| | | String deptName = getDeptName(taskEntity.getCreateDept()); |
| | | try { |
| | | File reportFile = GdPatrolReportWordUtil.generateReportFile(taskEntity, resultList, creatorName, deptName); |
| | | saveAttachFile(reportFile, taskEntity); |
| | | return reportFile; |
| | | } catch (Exception e) { |
| | | throw new RuntimeException("生成巡查报告失败", e); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | |
| | | return baseDesc + newStatus.getDesc(); |
| | | } |
| | | |
| | | private String getDeptName(Long deptId) { |
| | | if (deptId == null) { |
| | | return "/"; |
| | | } |
| | | R<Dept> deptResult = sysClient.getDept(deptId); |
| | | Dept dept = deptResult != null ? deptResult.getData() : null; |
| | | if (dept == null || StringUtil.isBlank(dept.getDeptName())) { |
| | | return "/"; |
| | | } |
| | | return dept.getDeptName(); |
| | | } |
| | | |
| | | private String getUserName(Long userId) { |
| | | if (userId == null) { |
| | | return "/"; |
| | | } |
| | | R<User> userResult = userClient.userInfoById(userId); |
| | | User user = userResult != null ? userResult.getData() : null; |
| | | if (user == null) { |
| | | return "/"; |
| | | } |
| | | String realName = user.getRealName(); |
| | | if (StringUtil.isBlank(realName)) { |
| | | realName = user.getName(); |
| | | } |
| | | return StringUtil.isBlank(realName) ? "/" : realName; |
| | | } |
| | | |
| | | private BladeFile saveAttachFile(File reportFile, GdPatrolTaskEntity taskEntity) throws IOException { |
| | | if (reportFile == null || !reportFile.exists()) { |
| | | throw new RuntimeException("巡查报告文件不存在"); |
| | | } |
| | | String fileName = reportFile.getName(); |
| | | BladeFile bladeFile = attachClient.putFile( |
| | | GdMultipartFileUtil.fromFile(reportFile, |
| | | "application/vnd.openxmlformats-officedocument.wordprocessingml.document"), |
| | | fileName |
| | | ); |
| | | if (bladeFile == null || StringUtil.isBlank(bladeFile.getLink())) { |
| | | throw new RuntimeException("附件上传失败"); |
| | | } |
| | | Integer resultType = parseResultType(taskEntity != null ? taskEntity.getPatrolTaskType() : null); |
| | | Attach attach = buildAttachInfo(taskEntity, reportFile, bladeFile, resultType); |
| | | Boolean saved = attachClient.saveAttachInfo(attach); |
| | | if (!Boolean.TRUE.equals(saved)) { |
| | | log.error("附件信息保存失败,报告文件:"+fileName); |
| | | } |
| | | return bladeFile; |
| | | } |
| | | |
| | | private Attach buildAttachInfo(GdPatrolTaskEntity taskEntity, File reportFile, BladeFile bladeFile, Integer resultType) { |
| | | Attach attach = new Attach(); |
| | | attach.setDomainUrl(bladeFile.getDomain()); |
| | | attach.setLink(bladeFile.getLink()); |
| | | attach.setName(bladeFile.getName()); |
| | | attach.setOriginalName(StringUtil.isBlank(bladeFile.getOriginalName()) ? reportFile.getName() : bladeFile.getOriginalName()); |
| | | attach.setAttachSize(reportFile.length()); |
| | | attach.setExtension(FileUtil.getFileExtension(reportFile.getName())); |
| | | attach.setResultType(resultType); |
| | | Long createUser = taskEntity != null ? taskEntity.getCreateUser() : null; |
| | | Long updateUser = taskEntity != null ? taskEntity.getUpdateUser() : null; |
| | | Long createDept = taskEntity != null ? taskEntity.getCreateDept() : null; |
| | | if (createUser == null) { |
| | | createUser = AuthUtil.getUserId(); |
| | | } |
| | | if (updateUser == null) { |
| | | updateUser = createUser; |
| | | } |
| | | if (createDept == null) { |
| | | createDept = Long.valueOf(AuthUtil.getDeptId()); |
| | | } |
| | | Date now = new Date(); |
| | | attach.setCreateUser(createUser); |
| | | attach.setUpdateUser(updateUser); |
| | | attach.setCreateDept(createDept); |
| | | attach.setCreateTime(now); |
| | | attach.setUpdateTime(now); |
| | | return attach; |
| | | } |
| | | |
| | | private Integer parseResultType(String patrolTaskType) { |
| | | if (StringUtil.isBlank(patrolTaskType)) { |
| | | return null; |
| | | } |
| | | try { |
| | | Integer type = Integer.valueOf(patrolTaskType); |
| | | if (type < 1 || type > 5) { |
| | | return null; |
| | | } |
| | | return type; |
| | | } catch (NumberFormatException ex) { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | } |