From 9d5840091834ab10868bc43bad55a4a8434227e7 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Wed, 7 Jun 2023 11:01:08 +0800 Subject: [PATCH] =?UTF-8?q?#=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E6=8A=BD?= =?UTF-8?q?=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ticket/WorkTicketService.java | 3 + .../service/ticket/impl/TicketServiceImpl.java | 1 + .../service/ticket/impl/WorkTicketServiceImpl.java | 1086 +------------------- 3 files changed, 10 insertions(+), 1080 deletions(-) diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/ticket/WorkTicketService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/ticket/WorkTicketService.java index 536b410..0117669 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/ticket/WorkTicketService.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/ticket/WorkTicketService.java @@ -3,5 +3,8 @@ package com.hnac.hzims.scheduled.service.ticket; import com.hnac.hzims.ticket.workTicket.entity.WorkTicketInfoEntity; import org.springblade.core.mp.base.BaseService; +/** + * @author ysj + */ public interface WorkTicketService extends BaseService { } diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/ticket/impl/TicketServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/ticket/impl/TicketServiceImpl.java index 204a17b..1ef4c4d 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/ticket/impl/TicketServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/ticket/impl/TicketServiceImpl.java @@ -31,6 +31,7 @@ import java.util.stream.Collectors; public class TicketServiceImpl extends BaseServiceImpl implements TicketService { private final WorkTicketService workTicketService; + private final TicketEvaluateService ticketEvaluateService; /** diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/ticket/impl/WorkTicketServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/ticket/impl/WorkTicketServiceImpl.java index 13dbc45..8c13e28 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/ticket/impl/WorkTicketServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/ticket/impl/WorkTicketServiceImpl.java @@ -1,1093 +1,19 @@ package com.hnac.hzims.scheduled.service.ticket.impl; -import cn.afterturn.easypoi.excel.entity.TemplateExportParams; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; -import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.google.common.collect.Lists; -import com.hnac.hzims.common.logs.utils.StringUtils; -import com.hnac.hzims.operational.access.constants.AccessConstants; -import com.hnac.hzims.operational.access.entity.OperAccessTaskEntity; -import com.hnac.hzims.operational.access.feign.IOperAccessTaskClient; -import com.hnac.hzims.operational.maintenance.dto.OperMaintenanceTaskDTO; -import com.hnac.hzims.operational.maintenance.feign.ITaskClient; -import com.hnac.hzims.ticket.allTicket.entity.TicketInfoEvaluateEntity; -import com.hnac.hzims.ticket.allTicket.service.TicketInfoEvaluateService; -import com.hnac.hzims.ticket.areamonthly.vo.StandardTicketWithAreaVo; -import com.hnac.hzims.ticket.areamonthly.vo.StandardWorkVo; -import com.hnac.hzims.ticket.aspect.AroundFlow; -import com.hnac.hzims.ticket.constants.TicketConstants; -import com.hnac.hzims.ticket.twoTicket.entity.TicketInfoDanger; -import com.hnac.hzims.ticket.twoTicket.entity.WorkTicketFinish; -import com.hnac.hzims.ticket.twoTicket.service.TicketInfoDangerService; -import com.hnac.hzims.ticket.twoTicket.service.impl.WorkTicketFinishServiceImpl; -import com.hnac.hzims.ticket.twoTicket.vo.process.WorkTicketVo; -import com.hnac.hzims.ticket.utils.ExcelUtil; -import com.hnac.hzims.ticket.utils.PdfUtils; -import com.hnac.hzims.ticket.workTicket.entity.*; -import com.hnac.hzims.ticket.workTicket.mapper.WorkDelayNoScopeMapper; -import com.hnac.hzims.ticket.workTicket.mapper.WorkTicketInfoMapper; -import com.hnac.hzims.ticket.workTicket.wrapper.WorkTicketDelayWrapper; -import com.hnac.hzims.ticket.workTicket.wrapper.WorkTicketInfoWrapper; -import com.hnac.hzims.vo.SafeCheckStatisticVO; +import com.hnac.hzims.scheduled.mapper.ticket.WorkTicketMapper; +import com.hnac.hzims.scheduled.service.ticket.WorkTicketService; +import com.hnac.hzims.ticket.workTicket.entity.WorkTicketInfoEntity; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.collections.map.HashedMap; -import org.apache.poi.ss.usermodel.Workbook; -import org.springblade.core.log.exception.ServiceException; import org.springblade.core.mp.base.BaseServiceImpl; -import org.springblade.core.mp.support.BladePage; -import org.springblade.core.mp.support.Condition; -import org.springblade.core.mp.support.Query; -import org.springblade.core.secure.utils.AuthUtil; -import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springblade.core.tool.utils.DateUtil; -import org.springblade.core.tool.utils.Func; -import org.springblade.core.tool.utils.ObjectUtil; -import org.springblade.flow.core.entity.BladeFlow; -import org.springblade.flow.core.feign.IFlowClient; -import org.springblade.flow.core.vo.ComleteTask; -import org.springblade.system.user.cache.UserCache; -import org.springblade.system.user.entity.User; -import org.springblade.system.user.feign.IUserClient; -import org.springframework.beans.BeanUtils; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Propagation; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.Assert; - -import javax.servlet.http.HttpServletResponse; -import java.time.LocalDateTime; -import java.time.YearMonth; -import java.time.format.DateTimeFormatter; -import java.time.temporal.TemporalAdjusters; -import java.util.*; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; -import java.util.stream.Collectors; /** - *

- * 工作票 服务实现类 - *

- * - * @author hx - * @since 2021-10-22 + * @author ysj */ @Service @Slf4j @RequiredArgsConstructor -public class WorkTicketServiceImpl extends BaseServiceImpl implements IWorkTicketInfoService { - - private final IWorkTicketSafetyMeasureService workTicketSafetyMeasureService; - private final IWorkTicketPrincipalChangeService workTicketPrincipalChangeService; - private final IWorkTicketDelayService delayService; - private final IWorkTicketMembersChangeService workTicketMembersChangeService; - private final IWorkTicketOperateTimeService workTicketOperateTimeService; - private final IWorkTicketFlowService workTicketFlowService; - private final IFlowClient flowClient; - private final IUserClient userClient; - private final WorkDelayNoScopeMapper workDelayNoScopeMapper; - private final IOperAccessTaskClient operAccessTaskClient; - private final ITaskClient taskClient; - private final TicketInfoEvaluateService ticketInfoEvaluateService; - private final IWorkTicketContentService workTicketContentService; - private final WorkTicketFinishServiceImpl workTicketFinishService; - private final TicketInfoDangerService ticketInfoDangerService; - - /** 生成两票编号锁 **/ - private Lock lock = new ReentrantLock(); - - /** word模板预览导出保存路径 **/ - @Value("${hzims.ticket.path.xlsx.savePath}") - private String xlsSavePath; - - @Value("${hzims.ticket.first-work-flow-key}") - private String firstWorkTicketFlowKey; - - @Value("${hzims.tenantId}") - private String tenantId; - - @Value("${hzims.ticket.path.pdf.savePath}") - private String pdfSavePath; - - @Override - @Transactional - @AroundFlow - public R doSave(WorkTicketInfoDto req) { - req.setCode(this.getWorkTicketCode()); - req.setStatus(Func.isEmpty(req.getPrincipal()) || Func.isEmpty(req.getClassGroupMembers()) ? TicketConstants.FirstWorkTicketFlowStatusEnum.OFFLINE.getStatus() : TicketConstants.FirstWorkTicketFlowStatusEnum.SIGN.getStatus()); - boolean flag = this.save(req); - /**保存安全措施**/ - if (flag && CollectionUtil.isNotEmpty(req.getWorkTicketSafetyMeasureDtoList())) { - req.getWorkTicketSafetyMeasureDtoList().forEach(workTicketSafetyMeasureDto -> { - workTicketSafetyMeasureDto.setTicketId(req.getId()); - workTicketSafetyMeasureService.save(workTicketSafetyMeasureDto); - }); - } - if (Func.isEmpty(req.getPrincipal()) || Func.isEmpty(req.getClassGroupMembers())) { - //将票据ID会传至计划/任务内 - returnTicket(req); - return R.success("开票成功!该票走线下未开启流程"); - } - /**开启工作流**/ - BladeFlow bladeFlow = this.startProcessInstance(firstWorkTicketFlowKey, req); - this.update(Wrappers.lambdaUpdate().set(WorkTicketInfoEntity::getProcessInstanceId, bladeFlow.getProcessInstanceId()).eq(WorkTicketInfoEntity::getId, req.getId())); - //将票据ID会传至计划/任务内 - returnTicket(req); - return R.success("保存成功"); - } - - /** - * 工作票延期 进入许可人确认工作票延期 - * - * @param ticketId 工作票ID - * @param status 状态 - * @param completeTask 工作流进行 - */ - @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) - public void delay(Long ticketId, Integer status, ComleteTask completeTask) { - //新增延期信息 - Assert.notNull(completeTask.getVariables().get("delay"), "延期信息不能为空"); - WorkTicketDelayEntity delayEntity = (WorkTicketDelayEntity) completeTask.getVariables().get("delay"); - delayService.save(delayEntity); - //更新负责人确认执行情况流程 填充信息 - WorkTicketFlowEntity workTicketFlowEntity = workTicketFlowService.getOne(Wrappers.lambdaQuery().eq(WorkTicketFlowEntity::getTicketId, ticketId).eq(WorkTicketFlowEntity::getFlowCode, TicketConstants.FirstWorkTicketFlowStatusEnum.CONFIRM_WORK_FINISH.getStatus()).orderByDesc(WorkTicketFlowEntity::getCreateTime).last("limit 1;")); - workTicketFlowService.update(Wrappers.lambdaUpdate().set(WorkTicketFlowEntity::getExecutor, AuthUtil.getUserId().toString()).set(WorkTicketFlowEntity::getExecuteTime, LocalDateTime.now()).eq(WorkTicketFlowEntity::getId, workTicketFlowEntity.getId())); - //更新工作票状态 - this.update(Wrappers.lambdaUpdate().set(WorkTicketInfoEntity::getStatus, status).eq(WorkTicketInfoEntity::getId, ticketId)); - //创建延期流程 - WorkTicketInfoEntity infoEntity = this.getById(ticketId); - WorkTicketFlowEntity currentFlowEntity = new WorkTicketFlowEntity(); - currentFlowEntity.setTicketId(ticketId); - currentFlowEntity.setFlowCode(status.toString()); - currentFlowEntity.setExecutor(infoEntity.getLicensor().toString()); - currentFlowEntity.setProcTaskId((String) completeTask.getVariables().get("procTaskId")); - workTicketFlowService.save(workTicketFlowEntity); - //进入工作流下一步 - R result = flowClient.completeTask(completeTask); - if (!result.isSuccess()) { - throw new ServiceException("执行工作流失败"); - } - } - - @Override - public R detail(Long id) { - WorkTicketInfoEntity workTicketInfoEntity = this.getById(id); - if (ObjectUtil.isEmpty(workTicketInfoEntity)) { - return R.fail("未查询到该ID对应的记录"); - } else { - WorkTicketInfoVO workTicketInfoVO = WorkTicketInfoWrapper.build().entityVO(workTicketInfoEntity); - - /**获取工作票安全措施列表**/ - WorkTicketSafetyMeasureDto workTicketSafetyMeasureDto = new WorkTicketSafetyMeasureDto(); - workTicketSafetyMeasureDto.setTicketId(id); - List workTicketSafetyMeasureVOList = workTicketSafetyMeasureService.list(workTicketSafetyMeasureDto); - workTicketInfoVO.setWorkTicketSafetyMeasureVOList(workTicketSafetyMeasureVOList); - - /**获取工作票负责人变更**/ - WorkTicketPrincipalChangeDto workTicketPrincipalChangeDto = new WorkTicketPrincipalChangeDto(); - workTicketPrincipalChangeDto.setTicketId(id); - List workTicketPrincipalChangeVOList = workTicketPrincipalChangeService.list(workTicketPrincipalChangeDto); - workTicketInfoVO.setWorkTicketPrincipalChangeVOList(workTicketPrincipalChangeVOList); - - /**获取工作票工作组员变更**/ - WorkTicketMembersChangeDto workTicketMembersChangeDto = new WorkTicketMembersChangeDto(); - workTicketMembersChangeDto.setTicketId(id); - List workTicketMembersChangeVOList = workTicketMembersChangeService.list(workTicketMembersChangeDto); - workTicketInfoVO.setWorkTicketMembersChangeVOList(workTicketMembersChangeVOList); - - /**获取工作票跨日运行时间列表**/ - WorkTicketOperateTimeDto workTicketOperateTimeDto = new WorkTicketOperateTimeDto(); - workTicketOperateTimeDto.setTicketId(id); - List workTicketOperateTimeVOList = workTicketOperateTimeService.list(workTicketOperateTimeDto); - workTicketInfoVO.setWorkTicketOperateTimeVOList(workTicketOperateTimeVOList); - - /**获取工作票处理流程列表**/ - WorkTicketFlowDto workTicketFlowDto = new WorkTicketFlowDto(); - workTicketFlowDto.setTicketId(id); - List workTicketFlowVOList = workTicketFlowService.list(workTicketFlowDto); - workTicketInfoVO.setWorkTicketFlowVOList(workTicketFlowVOList); - - /**获取工作票延期列表**/ - WorkTicketDelayDto workTicketDelayDto = new WorkTicketDelayDto(); - workTicketDelayDto.setTicketId(id); - List workTicketDelayList = workDelayNoScopeMapper.selectList(new LambdaQueryWrapper() {{ - eq(WorkTicketDelayEntity::getTicketId, id); - eq(WorkTicketDelayEntity::getIsDeleted, 0L); - }}); - if (CollectionUtil.isNotEmpty(workTicketDelayList)) { - workTicketInfoVO.setWorkTicketDelayVOList(WorkTicketDelayWrapper.build().listVO(workTicketDelayList)); - } - - return R.data(workTicketInfoVO); - } - } - - @Override - public R> queryList(WorkTicketInfoDto req, Query query) { - LambdaQueryWrapper lqw = this.getQueryWrapper(req); - if (ObjectUtil.isNotEmpty(req.getCreateDept())) { - lqw.eq(WorkTicketInfoEntity::getCreateDept, req.getCreateDept()); - } - - lqw.orderByDesc(WorkTicketInfoEntity::getCreateTime).orderByDesc(WorkTicketInfoEntity::getUpdateTime); - IPage pages = this.page(Condition.getPage(query), lqw); - //数据转换 - IPage workTicketInfoVOIPage = new Page<>(pages.getCurrent(), pages.getSize()); - workTicketInfoVOIPage.setRecords(WorkTicketInfoWrapper.build().listVO(pages.getRecords())); - workTicketInfoVOIPage.setPages(pages.getPages()); - workTicketInfoVOIPage.setTotal(pages.getTotal()); - //获取创建人 - workTicketInfoVOIPage.getRecords().forEach(item -> { - User user = UserCache.getUser(item.getCreateUser()); - if (user != null) { - item.setCreateUserName(user.getName()); - } - }); - - - return R.data(workTicketInfoVOIPage); - } - - @Override - public List list(WorkTicketInfoDto req) { - LambdaQueryWrapper lqw = this.getQueryWrapper(req); - List workTicketInfoEntityList = this.list(lqw); - return CollectionUtil.isNotEmpty(workTicketInfoEntityList) ? WorkTicketInfoWrapper.build().listVO(workTicketInfoEntityList) : null; - } - - @Override - @Transactional - public R remove(Long id, String comment) { - WorkTicketInfoEntity entity = this.getById(id); - if (ObjectUtil.isEmpty(entity)) { - return R.fail(400, "删除失败!未查询到相关记录"); - } - - boolean flag = this.update(Wrappers.lambdaUpdate().set(WorkTicketInfoEntity::getStatus, TicketConstants.FirstWorkTicketFlowStatusEnum.TERMINATION.getStatus()).eq(WorkTicketInfoEntity::getId, id)); - - /**线下单独删除**/ - if (TicketConstants.FirstWorkTicketFlowStatusEnum.OFFLINE.getStatus().equals(entity.getStatus())) { - return R.status(flag); - } - /**终止工作流**/ - R r = flowClient.delProcessInstanceById(entity.getProcessInstanceId(), comment); - if (!r.isSuccess()) { - throw new ServiceException("终止工作流失败!"); - } - return R.success("删除成功!"); - } - - @Override - public void exportWorkTicketTemplate(Long id, HttpServletResponse response) { - exportWorkTicketInfoPdf(id, response); - } - - @Override - @SuppressWarnings("unchecked") - public void exportWorkTicketInfoPdf(Long id, HttpServletResponse response) { - R workTicketInfoVOR = this.detail(id); - if (!workTicketInfoVOR.isSuccess()) { - log.error("未查询到相关工作票记录!"); - return; - } - WorkTicketInfoVO workTicketInfoVO = workTicketInfoVOR.getData(); - //将workTicketInfoVO封装进Map,以便pdf导出 - Map workTicketInfoMap = new HashMap<>(); - try { - workTicketInfoMap = PdfUtils.objectToMap(workTicketInfoVO); - } catch (Exception e) { - log.info("转换对象失败!"); - } - //安全措施 - if (CollectionUtil.isNotEmpty(workTicketInfoVO.getWorkTicketSafetyMeasureVOList())) { - Map> measureMap = workTicketInfoVO.getWorkTicketSafetyMeasureVOList().stream().collect(Collectors.groupingBy(WorkTicketSafetyMeasureVO::getType)); - if (ObjectUtil.isNotEmpty(measureMap.get(TicketConstants.MEASURE_TYPE_ONE))) { - workTicketInfoMap.put("matterLibraryListOne", measureMap.get(TicketConstants.MEASURE_TYPE_ONE).stream().map(measure -> { - Map map = PdfUtils.objectToMap(measure); - map.put("safetyMeasure", ObjectUtil.isNotEmpty(map.get("measure")) ? map.get("measure") : null); - String status = TicketConstants.SafetyMeasureStatusEnum.FINISH.getStatus().equals(measure.getStatus()) ? TicketConstants.SafetyMeasureStatusEnum.FINISH.getDescribe() : " "; - map.put("status", status); - return map; - }).collect(Collectors.toList())); - } else { - workTicketInfoMap.put("matterLibraryListOne", new ArrayList>(1)); - } - if (ObjectUtil.isNotEmpty(measureMap.get(TicketConstants.MEASURE_TYPE_TWO))) { - workTicketInfoMap.put("matterLibraryListTwo", measureMap.get(TicketConstants.MEASURE_TYPE_TWO).stream().map(measure -> { - Map map = PdfUtils.objectToMap(measure); - map.put("safetyMeasure", ObjectUtil.isNotEmpty(map.get("measure")) ? map.get("measure") : null); - String status = TicketConstants.SafetyMeasureStatusEnum.FINISH.getStatus().equals(measure.getStatus()) ? TicketConstants.SafetyMeasureStatusEnum.FINISH.getDescribe() : " "; - map.put("status", status); - return map; - }).collect(Collectors.toList())); - } else { - workTicketInfoMap.put("matterLibraryListTwo", new ArrayList>(1)); - } - if (ObjectUtil.isNotEmpty(measureMap.get(TicketConstants.MEASURE_TYPE_THREE))) { - workTicketInfoMap.put("matterLibraryListThree", measureMap.get(TicketConstants.MEASURE_TYPE_THREE).stream().map(measure -> { - Map map = PdfUtils.objectToMap(measure); - map.put("safetyMeasure", ObjectUtil.isNotEmpty(map.get("measure")) ? map.get("measure") : null); - String status = TicketConstants.SafetyMeasureStatusEnum.FINISH.getStatus().equals(measure.getStatus()) ? TicketConstants.SafetyMeasureStatusEnum.FINISH.getDescribe() : " "; - map.put("status", status); - return map; - }).collect(Collectors.toList())); - } else { - workTicketInfoMap.put("matterLibraryListThree", new ArrayList>(1)); - } - } - //线下开票确认人为空 - workTicketInfoMap.put("membersConfirm", TicketConstants.FirstWorkTicketFlowStatusEnum.OFFLINE.getStatus().equals(workTicketInfoVO.getStatus()) ? "" : workTicketInfoVO.getMembersName()); - //获取工作票工作流处理信息 - List workTicketFlowVOList = workTicketInfoVO.getWorkTicketFlowVOList(); - //签发 - List signFlow = workTicketFlowVOList.stream().filter(f -> TicketConstants.FirstWorkTicketFlowStatusEnum.LICENSE.getStatus().equals(Integer.parseInt(f.getFlowCode()))).collect(Collectors.toList()); - if (CollectionUtil.isNotEmpty(signFlow)) { - workTicketInfoMap.put("signer", signFlow.get(0).getCreateUserName()); - workTicketInfoMap.put("signTime", DateUtil.format(signFlow.get(0).getCreateTime(), TicketConstants.TICKET_DATE_PATTERN)); - } else { - workTicketInfoMap.put("signer", ""); - workTicketInfoMap.put("signTime", ""); - } - //许可人许可 - if (Func.isNotEmpty(workTicketInfoVO.getLicenseTime())) { - workTicketInfoMap.put("licensorConfirm", workTicketInfoVO.getLicensorName()); - workTicketInfoMap.put("licenseTime", DateUtil.format(workTicketInfoVO.getLicenseTime(), TicketConstants.TICKET_DATE_PATTERN)); - } else { - workTicketInfoMap.put("licensorConfirm", ""); - workTicketInfoMap.put("licenseTime", ""); - } - - /**负责人收到工作票**/ - List receiveFlow = workTicketFlowVOList.stream().filter(f -> TicketConstants.FirstWorkTicketFlowStatusEnum.CONFIRM_MEASURE_PRINCIPAL.getStatus().equals(Integer.parseInt(f.getFlowCode()))).collect(Collectors.toList()); - if (CollectionUtil.isNotEmpty(receiveFlow)) { - workTicketInfoMap.put("receivePrincipal", receiveFlow.get(0).getCreateUserName()); - workTicketInfoMap.put("receiveTime", DateUtil.format(receiveFlow.get(0).getCreateTime(), TicketConstants.TICKET_DATE_PATTERN)); - workTicketInfoMap.put("principalConfirm", workTicketInfoVO.getPrincipalName()); - } else { - workTicketInfoMap.put("receivePrincipal", ""); - workTicketInfoMap.put("receiveTime", ""); - workTicketInfoMap.put("principalConfirm", ""); - } - /**负责人确认安全事项**/ - List confirmFlow = workTicketFlowVOList.stream().filter(f -> TicketConstants.FirstWorkTicketFlowStatusEnum.CONFIRM_MEASURE_MEMBERS.getStatus().equals(Integer.parseInt(f.getFlowCode()))).collect(Collectors.toList()); - if (CollectionUtil.isNotEmpty(confirmFlow)) { - workTicketInfoMap.put("confirmPrincipal", confirmFlow.get(0).getCreateUserName()); - workTicketInfoMap.put("confirmTime", DateUtil.format(confirmFlow.get(0).getCreateTime(), TicketConstants.TICKET_DATE_PATTERN)); - } else { - workTicketInfoMap.put("confirmPrincipal", ""); - workTicketInfoMap.put("confirmTime", ""); - } - /**工作结束**/ - List finishFlow = workTicketFlowVOList.stream().filter(f -> TicketConstants.FirstWorkTicketFlowStatusEnum.END.getStatus().equals(Integer.parseInt(f.getFlowCode()))).collect(Collectors.toList()); - if (CollectionUtil.isNotEmpty(finishFlow)) { - workTicketInfoMap.put("finisher", finishFlow.get(0).getCreateUserName()); - workTicketInfoMap.put("finishTime", DateUtil.format(finishFlow.get(0).getCreateTime(), TicketConstants.TICKET_DATE_PATTERN)); - workTicketInfoMap.put("principalFinish", workTicketInfoVO.getPrincipalName()); - } else { - workTicketInfoMap.put("finisher", ""); - workTicketInfoMap.put("finishTime", ""); - workTicketInfoMap.put("principalFinish", ""); - } - /**工作终结**/ - List endFlow = workTicketFlowVOList.stream().filter(f -> TicketConstants.FirstWorkTicketFlowStatusEnum.FINISH.getStatus().intValue() == Integer.parseInt(f.getFlowCode())).collect(Collectors.toList()); - if (CollectionUtil.isNotEmpty(endFlow)) { - workTicketInfoMap.put("endLicensor", endFlow.get(0).getCreateUserName()); - workTicketInfoMap.put("endTime", DateUtil.format(endFlow.get(0).getCreateTime(), TicketConstants.TICKET_DATE_PATTERN)); - workTicketInfoMap.put("groundSwitchCount", ObjectUtil.isNotEmpty(endFlow.get(0).getGroundSwitchCount()) ? endFlow.get(0).getGroundSwitchCount() : ""); - workTicketInfoMap.put("groundWireCode", ObjectUtil.isNotEmpty(endFlow.get(0).getGroundWireCode()) ? endFlow.get(0).getGroundWireCode() : ""); - workTicketInfoMap.put("groundWireCount", ObjectUtil.isNotEmpty(endFlow.get(0).getGroundWireCount()) ? endFlow.get(0).getGroundWireCount() : ""); - } else { - workTicketInfoMap.put("endLicensor", ""); - workTicketInfoMap.put("endTime", ""); - workTicketInfoMap.put("groundSwitchCount", ""); - workTicketInfoMap.put("groundWireCode", ""); - workTicketInfoMap.put("groundWireCount", ""); - } - /**负责人变更**/ - List workTicketPrincipalChangeVOList = workTicketInfoVO.getWorkTicketPrincipalChangeVOList(); - if (CollectionUtil.isNotEmpty(workTicketPrincipalChangeVOList)) { - workTicketInfoMap.put("initPrincipal", workTicketPrincipalChangeVOList.get(0).getInitialPrincipalName()); - workTicketInfoMap.put("changePrincipal", workTicketPrincipalChangeVOList.get(0).getChangePrincipalName()); - workTicketInfoMap.put("principalChangeSigner", workTicketPrincipalChangeVOList.get(0).getCreateUserName()); - workTicketInfoMap.put("principalChangeTime", DateUtil.format(workTicketPrincipalChangeVOList.get(0).getCreateTime(), TicketConstants.TICKET_DATE_PATTERN)); - } else { - workTicketInfoMap.put("initPrincipal", ""); - workTicketInfoMap.put("changePrincipal", ""); - workTicketInfoMap.put("principalChangeSigner", ""); - workTicketInfoMap.put("principalChangeTime", ""); - } - /**工作成员变更**/ - List membersChangeList = workTicketInfoVO.getWorkTicketMembersChangeVOList(); - if (CollectionUtil.isNotEmpty(membersChangeList)) { - /**工作成员变更详情**/ - String membersChangeSituation = membersChangeList.stream().map(mc -> DateUtil.format(mc.getCreateTime(), TicketConstants.TICKET_DATE_PATTERN).concat(":").concat(mc.getChangeMembersName())).collect(Collectors.joining(";")); - workTicketInfoMap.put("membersChangeSituation", membersChangeSituation); - workTicketInfoMap.put("memberChangePrincipal", membersChangeList.get(0).getCreateUserName()); - } else { - workTicketInfoMap.put("membersChangeSituation", ""); - workTicketInfoMap.put("memberChangePrincipal", ""); - } - /**工作票延期**/ - List workTicketDelayVOList = workTicketInfoVO.getWorkTicketDelayVOList(); - if (CollectionUtil.isNotEmpty(workTicketDelayVOList)) { - WorkTicketDelayVO workTicketDelayVO = workTicketDelayVOList.get(0); - workTicketInfoMap.put("delayTime", DateUtil.format(workTicketDelayVO.getChangeTime(), TicketConstants.TICKET_DATE_PATTERN)); - workTicketInfoMap.put("delayPrincipal", workTicketDelayVO.getCreateUserName()); - workTicketInfoMap.put("delayPrincipalTime", DateUtil.format(workTicketDelayVO.getCreateTime(), TicketConstants.TICKET_DATE_PATTERN)); - workTicketInfoMap.put("delayLicensor", workTicketDelayVO.getLicensorName()); - workTicketInfoMap.put("delayLicenseTime", DateUtil.format(workTicketDelayVO.getLicenseTime(), TicketConstants.TICKET_DATE_PATTERN)); - } else { - workTicketInfoMap.put("delayTime", ""); - workTicketInfoMap.put("delayPrincipal", ""); - workTicketInfoMap.put("delayPrincipalTime", ""); - workTicketInfoMap.put("delayLicensor", ""); - workTicketInfoMap.put("delayLicenseTime", ""); - } - - /**跨日工作时间**/ - List operateList = workTicketInfoVO.getWorkTicketOperateTimeVOList(); - if (CollectionUtil.isNotEmpty(operateList)) { - List> operateMapList = operateList.stream().map(operate -> { - Map map = new HashMap<>(4); - map.put("startTime", DateUtil.format(operate.getStartTime(), TicketConstants.TICKET_DATE_PATTERN)); - map.put("endTime", DateUtil.format(operate.getEndTime(), TicketConstants.TICKET_DATE_PATTERN)); - map.put("principal", operate.getPrincipalName()); - map.put("licensor", operate.getLicensorName()); - return map; - }).collect(Collectors.toList()); - workTicketInfoMap.put("operateMapList", operateMapList); - } else { - List> operateMapList = new ArrayList<>(); - Map map = new HashMap<>(4); - map.put("startTime", ""); - map.put("endTime", ""); - map.put("principal", ""); - map.put("licensor", ""); - operateMapList.add(map); - workTicketInfoMap.put("operateMapList", operateMapList); - } - - /**运行值班人员暂为空**/ - workTicketInfoMap.put("dutyPersonName", "/"); - - String fileName = TicketConstants.WordFileNameEnum.getFileNameByType(workTicketInfoVO.getType()) + PdfUtils.XLSX_SUFFIX; - log.info("工作票模板为:{}", fileName); - TemplateExportParams templateExportParams = new TemplateExportParams("template/" + fileName, true); - Workbook workbook = null; - try { - workbook = ExcelUtil.getWorkbook(templateExportParams, workTicketInfoMap); - } catch (Exception e) { - e.printStackTrace(); - } - //上传xlsx至服务器 - try { - ExcelUtil.upload(workbook, xlsSavePath, workTicketInfoVO.getWorkContent() + PdfUtils.XLSX_SUFFIX); - } catch (Exception e) { - e.printStackTrace(); - } - //将xlsx文件转换为pdf并保存 - String pdfFileName = workTicketInfoVO.getWorkContent() + PdfUtils.PDF_SUFFIX; - String xlsFileName = workTicketInfoVO.getWorkContent() + PdfUtils.XLSX_SUFFIX; - PdfUtils.convertPdf(xlsSavePath, xlsFileName, pdfSavePath, pdfFileName); - String savePath = pdfSavePath + pdfFileName; - // 设置response参数,可以打开下载页面 - PdfUtils.readPdf(response, savePath); - } - - @Override - @Transactional - public R completeTask(WorkTicketInfoDto req, BladeFlow flow) { - ComleteTask task = new ComleteTask(); - task.setTaskId(flow.getTaskId()); - task.setComment(flow.getComment()); - task.setAttachments(flow.getAttachments()); - task.setFlag(flow.getFlag()); - task.setProcessInstanceId(flow.getProcessInstanceId()); - task.setVariables(flow.getVariables()); - - //待许可时获取许可人角色下用户开启工作流 - if (TicketConstants.FirstWorkTicketFlowStatusEnum.LICENSE.getStatus().equals(req.getStatus())) { - R> userListR = userClient.relationUserListByRoleAlias(AuthUtil.getTenantId(), req.getCreateDept(), TicketConstants.LICENSOR_ROLE); - if (!userListR.isSuccess()) { - throw new ServiceException(userListR.getMsg()); - } - Map variables = CollectionUtil.isEmpty(flow.getVariables()) ? new HashMap<>() : flow.getVariables(); - String taskUser = userListR.getData().stream().map(u -> "taskUser_".concat(u.getId().toString())).collect(Collectors.joining(",")); - variables.put("licenseUserIds", taskUser); - task.setVariables(variables); - } - log.info("工作流对象为:{}", JSONObject.toJSONString(flow)); - - if (TicketConstants.FirstWorkTicketFlowStatusEnum.LICENSE.getStatus().equals(req.getStatus())) { - req.setSigner(AuthUtil.getUserId()); - } else if (TicketConstants.FirstWorkTicketFlowStatusEnum.CONFIRM_MEASURE_PRINCIPAL.getStatus().equals(req.getStatus())) { - req.setLicensor(AuthUtil.getUserId()); - } else if (TicketConstants.FirstWorkTicketFlowStatusEnum.INVALID.getStatus().equals(req.getStatus())) { - this.invalidTicket(req); - } - - //更新状态 - boolean flag = this.update(Wrappers.lambdaUpdate().set(WorkTicketInfoEntity::getStatus, req.getStatus()).set(WorkTicketInfoEntity::getPrincipal, req.getPrincipal()).set(WorkTicketInfoEntity::getLicensor, req.getLicensor()).set(WorkTicketInfoEntity::getLicenseTime, req.getLicenseTime()).set(WorkTicketInfoEntity::getLicenseEndTime, req.getLicenseEndTime()).eq(WorkTicketInfoEntity::getId, req.getId())); - - //新增流程信息 - WorkTicketFlowEntity workTicketFlowEntity = new WorkTicketFlowEntity(); - workTicketFlowEntity.setTicketId(req.getId()); - workTicketFlowEntity.setFlowCode(req.getStatus().toString()); - workTicketFlowEntity.setExecutor(AuthUtil.getUserId().toString()); - workTicketFlowEntity.setExecuteTime(LocalDateTime.now()); - workTicketFlowEntity.setRemark(Optional.ofNullable(flow.getVariables()).map(v -> v.get("remark")).map(s -> s.toString()).orElse("")); - workTicketFlowEntity.setSignImgPath(Optional.ofNullable(flow.getVariables()).map(v -> v.get("signImgPath")).map(s -> s.toString()).orElse("")); - workTicketFlowEntity.setGroundWireCount(Optional.ofNullable(flow.getVariables()).map(v -> v.get("groundWireCount")).map(s -> Integer.parseInt(s.toString())).orElse(null)); - workTicketFlowEntity.setGroundSwitchCount(Optional.ofNullable(flow.getVariables()).map(v -> v.get("groundSwitchCount")).map(s -> Integer.parseInt(s.toString())).orElse(null)); - workTicketFlowEntity.setStatus(req.getStatus()); - workTicketFlowService.save(workTicketFlowEntity); - //执行流程 - R flowResult = flowClient.completeTask(task); - //更新任务状态 - updateAccessStatus(req); - - if (!flowResult.isSuccess()) { - throw new ServiceException("执行工作流失败!"); - } - - return R.success("操作成功!"); - } - - @Transactional(rollbackFor = Exception.class) - public void updateAccessStatus(WorkTicketInfoDto req) { - if (TicketConstants.TaskTypeEnum.JXRW.getType().equals(req.getTaskType()) || TicketConstants.TaskTypeEnum.JXJH.getType().equals(req.getTaskType())) { - log.info("许可通过:{}", JSONObject.toJSONString(req)); - //许可人通过将检修任务状态设为执行中 - if (TicketConstants.FirstWorkTicketFlowStatusEnum.CONFIRM_MEASURE_PRINCIPAL.getStatus().equals(req.getStatus())) { - OperAccessTaskEntity taskEntity = new OperAccessTaskEntity(); - taskEntity.setId(req.getTaskId()); - taskEntity.setStatus(AccessConstants.ACCESS_TASK_STATUS_1); - //设置开始时间 - taskEntity.setActStartTime(DateUtil.now()); - operAccessTaskClient.updateById(taskEntity); - } - } - } - - /*** - * 票据作废时 对应任务ID应该置空 - * @param req - */ - public void invalidTicket(WorkTicketInfoDto req) { - if (TicketConstants.TaskTypeEnum.JXRW.getType().equals(req.getTaskType()) || TicketConstants.TaskTypeEnum.JXJH.getType().equals(req.getTaskType())) { - OperAccessTaskEntity taskEntity = new OperAccessTaskEntity(); - taskEntity.setId(req.getTaskId()); - taskEntity.setInvalid(true); - taskEntity.setTicketId(null); - operAccessTaskClient.updateById(taskEntity); - } - if (TicketConstants.TaskTypeEnum.RCWH.getType().equals(req.getTaskType())) { - OperMaintenanceTaskDTO dto = new OperMaintenanceTaskDTO(); - dto.setId(req.getTaskId()); - dto.setInvalid(true); - //dto.setTicketId(null); - taskClient.doUpdateTaskById(dto); - } - } - - /*** - * 回传票据ID - * @param req - */ - @Transactional(rollbackFor = Exception.class) - public void returnTicket(WorkTicketInfoDto req) { - if (TicketConstants.TaskTypeEnum.JXRW.getType().equals(req.getTaskType())) { - OperAccessTaskEntity taskEntity = new OperAccessTaskEntity(); - taskEntity.setId(req.getTaskId()); - taskEntity.setTicketId(req.getId()); - operAccessTaskClient.updateById(taskEntity); - } - if (TicketConstants.TaskTypeEnum.RCWH.getType().equals(req.getTaskType())) { - OperMaintenanceTaskDTO dto = new OperMaintenanceTaskDTO(); - dto.setId(req.getTaskId()); - dto.setTicketId(req.getId()); - taskClient.doUpdateTaskById(dto); - } - } - - /** - * 获取queryWrapper - * - * @param req - * @return - */ - private LambdaQueryWrapper getQueryWrapper(WorkTicketInfoDto req) { - LambdaQueryWrapper lqw = new LambdaQueryWrapper(); - if (Func.isNotBlank(req.getProcessInstanceId())) { - lqw.eq(WorkTicketInfoEntity::getProcessInstanceId, req.getProcessInstanceId()); - } - if (Func.isNotEmpty(req.getType())) { - lqw.eq(WorkTicketInfoEntity::getType, req.getType()); - } - if (Func.isNotEmpty(req.getTaskType())) { - lqw.eq(WorkTicketInfoEntity::getTaskType, req.getTaskType()); - } - if (Func.isNotEmpty(req.getCode())) { - lqw.like(WorkTicketInfoEntity::getCode, req.getCode()); - } - if (Func.isNotEmpty(req.getStatus())) { - lqw.eq(WorkTicketInfoEntity::getStatus, req.getStatus()); - } - if (Func.isNotEmpty(req.getCompany())) { - lqw.like(WorkTicketInfoEntity::getType, "%".concat(req.getCompany()).concat("%")); - } - if (Func.isNotEmpty(req.getClassGroup())) { - lqw.eq(WorkTicketInfoEntity::getClassGroup, req.getClassGroup()); - } - if (Func.isNotEmpty(req.getTaskId())) { - lqw.eq(WorkTicketInfoEntity::getTaskId, req.getTaskId()); - } - if (Func.isNotEmpty(req.getClassGroup())) { - lqw.eq(WorkTicketInfoEntity::getClassGroup, req.getClassGroup()); - } - if (Func.isNotEmpty(req.getClassGroupMembers())) { - lqw.like(WorkTicketInfoEntity::getClassGroupMembers, "%".concat(req.getClassGroupMembers()).concat("%")); - } - if (Func.isNotEmpty(req.getWorkContent())) { - lqw.like(WorkTicketInfoEntity::getWorkContent, "%".concat(req.getWorkContent()).concat("%")); - } - if (Func.isNotEmpty(req.getSigner())) { - lqw.eq(WorkTicketInfoEntity::getSigner, req.getSigner()); - } - if (Func.isNotEmpty(req.getLicensor())) { - lqw.eq(WorkTicketInfoEntity::getLicensor, req.getLicensor()); - } - if (Func.isNotEmpty(req.getStartTime())) { - lqw.ge(WorkTicketInfoEntity::getCreateTime, req.getStartTime()); - } - if (Func.isNotEmpty(req.getEndTime())) { - lqw.le(WorkTicketInfoEntity::getCreateTime, req.getEndTime()); - } - if (!CollectionUtil.isEmpty(req.getDeptIds())) { - lqw.in(WorkTicketInfoEntity::getCreateDept, req.getDeptIds()); - } - return lqw; - } - - /** - * 开启一个流程实例 - * - * @author hx - **/ - @Override - public BladeFlow startProcessInstance(String processDefinitionKey, WorkTicketInfoEntity workTicketInfoEntity) { - /**获取签发人角色下的人员**/ - R> listR = userClient.relationUserListByRoleAlias(tenantId, Long.parseLong(AuthUtil.getUser().getDeptId()), TicketConstants.SIGNER_ROLE); - if (!listR.isSuccess() || CollectionUtil.isEmpty(listR.getData())) { - throw new ServiceException("工作票签发人角色下未查询到相关人员"); - } - String signUserIds = listR.getData().stream().map(user -> "taskUser_".concat(user.getId().toString())).collect(Collectors.joining(",")); - - Map params = new HashMap(2) {{ - put("taskId", workTicketInfoEntity.getId()); - put("signUserIds", signUserIds); - }}; - - R r = flowClient.startProcessInstanceContainNameByKey(processDefinitionKey, "workTicket:task:" + workTicketInfoEntity.getId(), workTicketInfoEntity.getWorkContent(), params); - if (!r.isSuccess()) { - throw new ServiceException(r.getMsg()); - } - return r.getData(); - } - - /** - * 许可人通过线下工作票 - * - * @param req - * @return - */ - @Override - public R licenseOfflineTicket(WorkTicketInfoDto req) { - Long ticketId = req.getId(); - WorkTicketInfoEntity infoEntity = getById(ticketId); - //获取许可人角色下的人员 - R> listR = userClient.relationUserListByRoleAlias(tenantId, infoEntity.getCreateDept(), TicketConstants.LICENSOR_ROLE); - if (!listR.isSuccess() || CollectionUtil.isEmpty(listR.getData())) { - throw new ServiceException("工作票许可人角色下未查询到相关人员"); - } - List userId = listR.getData().stream().map(User::getId).distinct().collect(Collectors.toList()); - if (!userId.contains(AuthUtil.getUserId())) { - throw new ServiceException("当前操作人没有许可人角色,无法执行该操作"); - } - update(Wrappers.lambdaUpdate().set(WorkTicketInfoEntity::getStatus, TicketConstants.FirstWorkTicketFlowStatusEnum.OFFLINE_LICENSE.getStatus()).set(WorkTicketInfoEntity::getLicensor, AuthUtil.getUserId()).set(WorkTicketInfoEntity::getLicenseTime, LocalDateTime.now()).set(WorkTicketInfoEntity::getLicenseEndTime, req.getLicenseEndTime()).eq(WorkTicketInfoEntity::getId, ticketId)); - return R.success("操作成功"); - } - - /** - * 完成线下工作票 - * - * @param ticketAccessTaskDto - * @return - */ - @Override - public R finishOfflineTicket(TicketAccessTaskDto ticketAccessTaskDto) { - //更新工作票 - WorkTicketInfoDto infoDto = ticketAccessTaskDto.getWorkTicketInfoDto(); - update(Wrappers.lambdaUpdate().set(WorkTicketInfoEntity::getStatus, TicketConstants.FirstWorkTicketFlowStatusEnum.OFFLINE_END.getStatus()).eq(WorkTicketInfoEntity::getId, infoDto.getId())); - //获取工作票实体类 - WorkTicketInfoEntity infoEntity = getById(infoDto.getId()); - //根据任务类型执行任务 - if (ObjectUtil.isEmpty(infoEntity.getTaskType())) { - return R.success("操作成功"); - } - //FIXME 日常维护、检修任务暂时不形成闭环(因许可人无需填入任务结束完成所需参数,故选择由执行人手动闭环) ~2022--05-06 -// if(TicketConstants.TaskTypeEnum.JXRW.getType().equals(infoEntity.getTaskType()) -// || TicketConstants.TaskTypeEnum.JXJH.getType().equals(infoEntity.getTaskType())) { -// //执行检修任务 -// OperAccessTaskDTO accessTaskDTO = ticketAccessTaskDto.getAccessTaskDTO(); -// accessTaskDTO.setId(infoEntity.getTaskId()); -// if(ObjectUtil.isNotEmpty(accessTaskDTO) && ObjectUtil.isNotEmpty(accessTaskDTO.getId())){ -// log.info("线下检修任务执行调用传参为:{}",JSONObject.toJSONString(accessTaskDTO)); -// //operAccessTaskClient.finishAccessTask(accessTaskDTO); -// } -// } -// else if(TicketConstants.TaskTypeEnum.RCWH.getType().equals(infoEntity.getTaskType())) { -// //执行日常维护任务 -// OperMaintenanceTaskDTO operMaintenanceTaskDTO = new OperMaintenanceTaskDTO(); -// operMaintenanceTaskDTO.setId(infoEntity.getTaskId()); -// operMaintenanceTaskDTO.setStatus(MaintenanceConstant.TASK_STATUS_3); -// if(ObjectUtil.isNotEmpty(operMaintenanceTaskDTO) && ObjectUtil.isNotEmpty(operMaintenanceTaskDTO.getId()) ){ -// ComleteTask comleteTask = new ComleteTask(); -// comleteTask.setProcessInstanceId(operMaintenanceTaskDTO.getProcessInstanceId()); -// comleteTask.setFlag("ok"); -// comleteTask.setPass(true); -// comleteTask.setComment("执行完成"); -// TaskFlowDTO taskFlowDTO = TaskFlowDTO.builder().taskDTO(operMaintenanceTaskDTO).comleteTask(comleteTask).build(); -// log.info("线下日常维护任务执行调用传参为:{}",JSONObject.toJSONString(taskFlowDTO)); -// //R result = taskClient.updateTaskStatus(taskFlowDTO); -// } -// } - return R.success("操作成功"); - } - - /*** - * 获取工作票编号 - * @return - */ - @Override - public String getWorkTicketCode() { - String code = ""; - lock.lock(); - try { - /**获取当前时间**/ - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyMM"); - YearMonth yearMonth = YearMonth.now(); - String tym = yearMonth.format(formatter); - LocalDateTime date = LocalDateTime.now(); - LocalDateTime firstDay = date.with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0); - LocalDateTime lastDay = date.with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59); - log.info("当月第一天:{};当月最后一天{}", firstDay, lastDay); - /**获取当月工作票总条数**/ - List infoEntityList = this.list(new LambdaQueryWrapper() {{ - ge(WorkTicketInfoEntity::getCreateTime, firstDay); - le(WorkTicketInfoEntity::getCreateTime, lastDay); - }}); - if (CollectionUtil.isEmpty(infoEntityList)) { - code = TicketConstants.TicketCodePreEnum.DQ_WORK.getPrefix().concat("-").concat(tym).concat("-001"); - } else { - code = TicketConstants.TicketCodePreEnum.DQ_WORK.getPrefix().concat("-").concat(tym).concat("-").concat(String.format("%03d", infoEntityList.size() + 1)); - } - } catch (Exception e) { - e.printStackTrace(); - } finally { - lock.unlock(); - } - return code; - } - - /** - * 获取安全检查工作票项统计 - * - * @param startDate 开始时间 - * @param endDate 结束时间 - * @param dept 机构ID - * @return WorkTicketStatisticVO统计对象 - */ - @Override - public SafeCheckStatisticVO getWorkTicketStatistic(String startDate, String endDate, Long dept) { - return this.baseMapper.getWorkTicketStatistic(startDate, endDate, dept); - } - - /** - * 验证角色是否能查询到相关人员 - * - * @param deptId 机构ID - * @param roleAliasArray 角色 按逗号分隔 - * @return - */ - @Override - public R> verificationRole(Long deptId, String roleAliasArray) { - Map result = new HashedMap(2); - List failRoleAliasList = Lists.newArrayList(); - AtomicBoolean flag = new AtomicBoolean(true); - Arrays.stream(roleAliasArray.split(",")).forEach(roleAlias -> { - //查询机构下角色是否有对应人员列表 - R> listR = userClient.relationUserListByRoleAlias(tenantId, deptId, roleAlias); - if (!listR.isSuccess() || ObjectUtil.isEmpty(listR.getData())) { - failRoleAliasList.add(roleAlias); - flag.set(false); - } - }); - result.put("flag", flag.get()); - if (CollectionUtil.isNotEmpty(failRoleAliasList)) { - result.put("message", "验证失败,获取" + JSON.toJSONString(failRoleAliasList) + "角色下的人员失败"); - } - - return R.data(result); - } - - /** - * 根据月份和区域查询工作票列表详情 - * - * @param pageEntity - * @param areaVo - * @return - */ - @Override - public BladePage workTicketListByMonthAndArea(Page pageEntity, StandardTicketWithAreaVo areaVo) { - //1.查询 - QueryWrapper queryWrapper = new QueryWrapper<>(); - - //开票来源 - queryWrapper.eq(Func.isNotEmpty(areaVo.getTaskType()), "sti.task_type", areaVo.getTaskType()); - //编号 - queryWrapper.like(Func.isNotEmpty(areaVo.getCode()), "sti.code", areaVo.getCode()); - - //状态 - queryWrapper.eq(Func.isNotEmpty(areaVo.getStatus()), "sti.status", areaVo.getStatus()); - - //开始时间 - queryWrapper.lt(Func.isNotEmpty(areaVo.getStartTime()), "sti.create_time", areaVo.getStartTime()); - - //结束时间 - queryWrapper.le(Func.isNotEmpty(areaVo.getEndTime()), "sti.create_time", areaVo.getEndTime()); - - - queryWrapper.eq("sti.create_dept", areaVo.getAreaId()); - queryWrapper.eq(areaVo.getYearMonth() != null, "date_format(sti.create_time,'%Y-%m')", areaVo.getYearMonth()); - //如果为1为合格 - // queryWrapper.eq("tie.status",1); - Page workTicketInfoEntityPage = baseMapper.selectPages(pageEntity, queryWrapper); - //数据转换 - List standardWorkList = new ArrayList<>(); - if (CollectionUtil.isNotEmpty(workTicketInfoEntityPage.getRecords())) { - standardWorkList = workTicketInfoEntityPage.getRecords().stream().map(workTicketInfoEntity -> { - StandardWorkVo standardWorkVo = new StandardWorkVo(); - BeanUtils.copyProperties(workTicketInfoEntity, standardWorkVo); - return standardWorkVo; - }).collect(Collectors.toList()); - } - - IPage page = new Page<>(); - page.setRecords(standardWorkList); - page.setTotal(workTicketInfoEntityPage.getTotal()); - page.setCurrent(workTicketInfoEntityPage.getCurrent()); - page.setSize(workTicketInfoEntityPage.getSize()); - BladePage bladePage = BladePage.of(page); - return bladePage; - } - - - /** - * 判断是否存在合格率 如果存在返回true 否则为false - * - * @param item - * @return - */ - private boolean isTicketPercentById(WorkTicketInfoEntity item) { - LambdaQueryWrapper ticketInfoEvaluateEntityLambdaQueryWrapper = new LambdaQueryWrapper<>(); - ticketInfoEvaluateEntityLambdaQueryWrapper.eq(TicketInfoEvaluateEntity::getTicketId, item.getId()); - ticketInfoEvaluateEntityLambdaQueryWrapper.eq(TicketInfoEvaluateEntity::getStatus, TicketConstants.TicketQualifiedEnum.Qualified.getCode()); - // 查询合格评价 - int count = ticketInfoEvaluateService.count(ticketInfoEvaluateEntityLambdaQueryWrapper); - return count > 0; - } - - - /** - * 更新状态值 - * - * @param status - * @param description - * @param id - */ - @Override - public void updateFlowStatusById(Integer status, String description, Long id) { - LambdaUpdateWrapper queryWrapper = new LambdaUpdateWrapper<>(); - queryWrapper.set(WorkTicketInfoEntity::getFlowStatus, status); - queryWrapper.set(WorkTicketInfoEntity::getFlowDescription, description); - queryWrapper.eq(WorkTicketInfoEntity::getId, id); - } - - /** - * 获取工作详情 - * - * @param ticketId - * @return - */ - @Override - public WorkTicketVo selectDetailsById(Long ticketId) { - WorkTicketVo workTicketVo = new WorkTicketVo(); - - //1. 获取工作票详情数据 - WorkTicketInfoEntity workTicketInfo = this.getById(ticketId); - if (ObjectUtils.isEmpty(workTicketInfo)) { - throw new ServiceException("未查询到ticketId对应的信息"); - } - - //赋值签发人 - if (workTicketInfo.getSigner() != null) { - User user = UserCache.getUser(workTicketInfo.getSigner()); - workTicketInfo.setSignerName(user == null ? null : user.getName()); - } - - if (workTicketInfo.getSigner() != null && workTicketInfo.getSignerName() == null) { - User user = UserCache.getUser(workTicketInfo.getSigner()); - workTicketInfo.setSignerName(user == null ? null : user.getName()); - } - - //赋值许可人名称 - if (workTicketInfo.getLicensor() != null) { - User user = UserCache.getUser(workTicketInfo.getLicensor()); - workTicketInfo.setLicensorName(user == null ? null : user.getName()); - } - - if (workTicketInfo.getLicensor() != null && workTicketInfo.getLicensorName() == null) { - User user = UserCache.getUser(workTicketInfo.getLicensor()); - workTicketInfo.setLicensorName(user == null ? null : user.getName()); - } - - // 负责值班负责人 - if (workTicketInfo.getWatchPrincipal() != null) { - User user = UserCache.getUser(workTicketInfo.getWatchPrincipal()); - workTicketInfo.setWatchPrincipalName(user == null ? null : user.getName()); - } - - if (workTicketInfo.getWatchPrincipal() != null && workTicketInfo.getWatchPrincipalName() == null) { - User user = UserCache.getUser(workTicketInfo.getWatchPrincipal()); - workTicketInfo.setWatchPrincipalName(user == null ? null : user.getName()); - } - - - StringBuilder sb = new StringBuilder(); - String classGroupMembers = workTicketInfo.getClassGroupMembers(); - if (StringUtils.isNoneBlank(classGroupMembers)) { - // System.out.println("获取classGroupMembers ==> " + classGroupMembers); - String[] split = classGroupMembers.split(","); - for (String classGroupMember : split) { - System.out.println(classGroupMember); - if (StringUtils.isNoneBlank(classGroupMember)) { - boolean matches = classGroupMember.matches("[0-9]+"); - if (matches) { - User user = UserCache.getUser(Long.valueOf(classGroupMember)); - String name = user == null ? null : user.getName(); - if (StringUtils.isNotBlank(name)) { - sb.append(name).append(","); - } - } - } - } - - //统计人数 - if (workTicketInfo.getTotalPerson() == null) { - workTicketInfo.setTotalPerson(sb.toString().trim().split(",").length); - } - - //成员信息 - if (workTicketInfo.getClassGroupMembersName() == null) { - workTicketInfo.setClassGroupMembersName(sb.toString().endsWith(",") ? - sb.toString().substring(0, sb.length() - 1) : sb.toString()); - } - } - - - //负责人名称 - if (workTicketInfo.getPrincipalName() == null && workTicketInfo.getPrincipal() != null) { - User user = UserCache.getUser(workTicketInfo.getPrincipal()); - workTicketInfo.setPrincipalName(user == null ? "" : user.getName()); - } - - - workTicketVo.setWorkTicket(workTicketInfo); - - //2. 安全措施数组 - List workTicketSafetyMeasureEntity = workTicketSafetyMeasureService.selectByTicketId(ticketId); - if (CollectionUtils.isNotEmpty(workTicketSafetyMeasureEntity)) { - workTicketVo.setSafetyMeasuresList(workTicketSafetyMeasureEntity); - } - - //3. 工作票工作任务组 - List workTicketContentEntities = workTicketContentService.selectByTicketId(ticketId); - if (CollectionUtils.isNotEmpty(workTicketContentEntities)) { - workTicketVo.setWorkTicketContentDtoList(workTicketContentEntities); - } - - //4. 工作票延期 - WorkTicketDelayEntity workTicketDelayEntity = delayService.selectByTicketId(ticketId); - if (ObjectUtils.isNotEmpty(workTicketDelayEntity)) { - workTicketVo.setWorkTicketDelay(workTicketDelayEntity); - } - - - //5.工作结束 - WorkTicketFinish workTicketFinish = workTicketFinishService.selectByTicketId(ticketId); - if (ObjectUtils.isNotEmpty(workTicketFinish)) { - workTicketVo.setWorkTicketFinish(workTicketFinish); - } - - - //6.工作开始时间和结束时间 - List workTicketOperateTimeEntities = - workTicketOperateTimeService.selectByTicketId(ticketId); - if (CollectionUtils.isNotEmpty(workTicketOperateTimeEntities)) { - workTicketVo.setWorkTicketOperateTimeEntities(workTicketOperateTimeEntities); - } - - - //7. 工作票负责人变更 - WorkTicketPrincipalChangeEntity workTicketPrincipalChangeEntity = - workTicketPrincipalChangeService.selectByTicketId(ticketId); - if (ObjectUtils.isNotEmpty(workTicketPrincipalChangeEntity)) { - //原负责人 - if (workTicketPrincipalChangeEntity.getInitialPrincipal() != null) { - workTicketPrincipalChangeEntity.setInitialPrincipalName( - UserCache.getUser(workTicketPrincipalChangeEntity.getInitialPrincipal()).getName() - ); - } - //变更负责人 - if (workTicketPrincipalChangeEntity.getChangePrincipal() != null) { - workTicketPrincipalChangeEntity.setChangePrincipalName( - UserCache.getUser(workTicketPrincipalChangeEntity.getChangePrincipal()).getName() - ); - } - - workTicketVo.setWorkTicketPrincipalChange(workTicketPrincipalChangeEntity); - } - - - //7. 根据工作票Id查询工作票危险点分析及控制措施票 - List list = ticketInfoDangerService.selectAllByTicket(workTicketInfo.getId()); - if (CollectionUtils.isNotEmpty(list)) { - workTicketVo.setTicketInfoDangers(list); - } - return workTicketVo; - } -} +public class WorkTicketServiceImpl extends BaseServiceImpl implements WorkTicketService { +} \ No newline at end of file