package com.gk.hotwork.Service.ServiceImpl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.gk.hotwork.Domain.*; import com.gk.hotwork.Domain.Enum.TaskType; import com.gk.hotwork.Domain.Exception.BusinessException; import com.gk.hotwork.Domain.Utils.*; import com.gk.hotwork.Domain.Vo.TaskVo; import com.gk.hotwork.Domain.Vo.TaskWorkerVo; import com.gk.hotwork.Domain.Vo.WorkShowTaskVo; import com.gk.hotwork.Domain.Vo.specTask.ActiveTaskInfo; import com.gk.hotwork.Domain.Vo.specTask.ActiveTaskLocationDto; import com.gk.hotwork.Domain.Vo.specTask.TaskLocation; import com.gk.hotwork.Mapper.TaskInfoMapper; import com.gk.hotwork.Mapper.TaskReviewMapper; import com.gk.hotwork.Service.*; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.xmlbeans.XmlException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.*; import java.util.stream.Collectors; /** * @author : jingjy * @date : 2021/8/19 17:08 */ @Service("TaskService") public class TaskServiceImpl extends ServiceImpl implements TaskService { @Autowired private TaskInfoMapper taskInfoMapper; @Autowired private TaskReviewMapper taskReviewMapper; @Autowired private CompanyService companyService; @Autowired private TaskLogService taskLogService; @Autowired private TaskAnalysisService taskAnalysisService; @Autowired private TaskSecurityService taskSecurityService; @Autowired private TaskWorkerService taskWorkerService; @Autowired private TaskEnclosureService taskEnclosureService; @Autowired private TaskEquipmentService taskEquipmentService; @Autowired private TaskRiskService taskRiskService; @Autowired private UserService userService; @Autowired private WordService wordService; @Autowired private TaskInvolveDepService taskInvolveDepService; @Autowired private InvolveDepService involveDepService; @Autowired private DepartmentService departmentService; @Autowired private EquipmentService equipmentService; @Autowired private WarningService warningService; @Autowired private SubTaskService subTaskService; @Autowired private TaskLocationService taskLocationService; @Autowired private TaskReviewService taskReviewService; @Value("${workCode}") private String workCode; @Value("${taskPath}") private String taskPath; @Value("${task}") private String task; @Override public void selectDataGrid(PageInfo pageInfo) { Page page = PageUtil.getPage(pageInfo,"createdat"); if (StringUtils.isBlank(pageInfo.getSort())){ pageInfo.setSort("createdat"); } if (StringUtils.isBlank(pageInfo.getOrder())){ pageInfo.setOrder("desc"); } List taskInfos = taskInfoMapper.selectTaskDataGrid(pageInfo.getCondition(),page); pageInfo.setResult(taskInfos); pageInfo.setTotalCount(page.getTotal()); } @Override public void selectStatisticsData(PageInfo pageInfo) { Page page = PageUtil.getPage(pageInfo,"createdat"); if (StringUtils.isBlank(pageInfo.getSort())){ pageInfo.setSort("createdat"); } if (StringUtils.isBlank(pageInfo.getOrder())){ pageInfo.setOrder("desc"); } List taskInfos = taskInfoMapper.selectStatisticsData(pageInfo.getCondition(),page); pageInfo.setResult(taskInfos); pageInfo.setTotalCount(page.getTotal()); } @Override public List getWorkShowTaskList(UserInfo user) { //主表 List doingTask = taskInfoMapper.getDoingTask(); //加上作业类型 if (doingTask.size() > 0) { for (TaskVo taskVo : doingTask) { String taskCode = taskVo.getCode(); List subTasks = subTaskService.getSubTasksByCode(taskCode); taskVo.setSubTaskInfos(subTasks); } } return doingTask; } @Override public List getWorkShowPersonList(UserInfo user) { //主表 List doingTask = taskInfoMapper.getDoingTask(); //加上人员列表 if (doingTask.size() > 0) { for (TaskVo taskVo : doingTask) { String taskCode = taskVo.getCode(); List workers = taskWorkerService.getVoByTaskCode(taskCode); ListequipmentInfos = equipmentService.selectByTaskAndWorker(taskVo.getCode(),taskVo.getApproversupervisor()); taskVo.setTaskWorkers(workers); taskVo.setSupervisorEquipments(equipmentInfos); } } return doingTask; } @Override public void selectDataGridTesting(PageInfo pageInfo) { Page page = PageUtil.getPage(pageInfo,"createdat"); if (StringUtils.isBlank(pageInfo.getSort())){ pageInfo.setSort("createdat"); } if (StringUtils.isBlank(pageInfo.getOrder())){ pageInfo.setOrder("desc"); } List taskInfos = taskInfoMapper.selectDataGridTesting(pageInfo.getCondition(),page); ListtaskVos = new ArrayList<>(); for (TaskInfo taskInfo : taskInfos){ TaskVo taskVo = BeanUtils.copy(taskInfo,TaskVo.class); List workers = taskWorkerService.getVoByTaskCode(taskVo.getCode()); Listsecurities = taskSecurityService.getListByTaskCode(taskVo.getCode()); Listanalyses = taskAnalysisService.getListByTaskCode(taskVo.getCode()); List enclosures = taskEnclosureService.getListByTaskCode(taskVo.getCode()); Listequipments = taskEquipmentService.getListByTaskCode(taskVo.getCode()); List departments = taskInvolveDepService.getListByTaskCode(taskVo.getCode()); ListequipmentInfos = equipmentService.selectByTaskAndWorker(taskInfo.getCode(),taskInfo.getApproversupervisor()); TaskRisk taskRisk = taskRiskService.getTaskRiskByCode(taskVo.getCode()); List reviews = taskReviewService.getListByTaskCode(taskVo.getCode()); taskVo.setTaskReviews(reviews); taskVo.setTaskWorkers(workers); taskVo.setTaskSecurities(securities); taskVo.setTaskAnalyses(analyses); taskVo.setTaskEquipments(equipments); taskVo.setTaskRisk(taskRisk); taskVo.setResources(enclosures); taskVo.setDepartments(departments); taskVo.setSupervisorEquipments(equipmentInfos); List subTaskInfos = subTaskService.getSubTasksByCode(taskVo.getCode()); taskVo.setSubTaskInfos(subTaskInfos); taskVos.add(taskVo); } pageInfo.setResult(taskVos); pageInfo.setTotalCount(page.getTotal()); } /** * 获取进行中的作业 * @return */ @Override public List selectActiveTaskLocation(Date time,Byte type) { List activeTaskDtoList = null; if(time == null) time = new Date(); List activeTaskList = taskInfoMapper.selectActiveTaskList(time,type); if(activeTaskList != null && activeTaskList.size() > 0){ activeTaskDtoList = new ArrayList<>(); //1、包装作业代码作为查询条件 List codeIdList = new ArrayList<>(); for(ActiveTaskInfo info : activeTaskList){ //包装位置查询参数 codeIdList.add(info.getId()); } //2、查询全部坐标信息 List taskLocationList = taskReviewMapper.getTaskLocationListByTaskCodes(codeIdList); //3、数据匹配 if(taskLocationList!=null && taskLocationList.size()>0){ for (TaskLocation l:taskLocationList){ for(ActiveTaskInfo info : activeTaskList){ if(l.getTaskId() != null && info.getId() != null && info.getId().longValue() == l.getTaskId().longValue()){ ActiveTaskLocationDto activeTaskLocationDto = new ActiveTaskLocationDto(); activeTaskLocationDto.setId(info.getId()); activeTaskLocationDto.setCode(info.getCode()); activeTaskLocationDto.setLon(l.getLon()); activeTaskLocationDto.setLat(l.getLat()); activeTaskDtoList.add(activeTaskLocationDto); } } } } //4、获取子作业 for(ActiveTaskLocationDto activeTaskLocationDto:activeTaskDtoList){ List subTaskInfoList = subTaskService.getSubTasksByCode(activeTaskLocationDto.getCode()); if(subTaskInfoList != null && subTaskInfoList.size() > 0){ List taskTypeList = new ArrayList<>(); for(SubTaskInfo subTaskInfo:subTaskInfoList){ if(subTaskInfo.getType() != null && !subTaskInfo.getType().isEmpty()){ taskTypeList.add(subTaskInfo.getType()); } } activeTaskLocationDto.setTaskTypeList(taskTypeList); } //打包子作业类型数据 } } return activeTaskDtoList; } @Override @Transactional public void saveTaskForAnalysis(TaskVo taskVo, UserInfo userInfo) { Date now = new Date(); String realName = userInfo.getRealname(); String taskCode = this.generateCode(userInfo,workCode); taskVo.setStatus(TaskInfo.TEST_COMMITTED); taskVo.setCode(taskCode); taskVo.setCreatedat(now); taskVo.setCreatedby(realName); if (StringUtils.isBlank(taskVo.getAnalysisarea()) || StringUtils.isBlank(taskVo.getAnalysismedium())){ throw new BusinessException("需要气体检测分析时必须填写分析点名称和分析介质"); } { List subTaskInfos = taskVo.getSubTaskInfos(); if (subTaskInfos == null || subTaskInfos.size() == 0) {throw new BusinessException("请选择涉及的作业信息");} subTaskInfos.forEach(item-> item.setTaskcode(taskVo.getCode())); subTaskService.saveBatch(subTaskInfos); } this.save(taskVo); TaskLog taskLog = new TaskLog(taskVo.getCode(), "创建任务信息,提交检测中心", realName, new Date(), userInfo.getCompany()); taskLogService.save(taskLog); } @Override public void updateTaskByApp(TaskVo taskVo, UserInfo userInfo) { Date now = new Date(); TaskInfo taskInfo = BeanUtils.copy(taskVo,TaskInfo.class); taskSecurityService.removeByTaskCode(taskVo.getCode()); taskEquipmentService.removeByTaskCode(taskVo.getCode()); taskRiskService.removeByCode(taskVo.getCode()); taskEnclosureService.removeByTaskCode(taskVo.getCode()); List taskSecurities = taskVo.getTaskSecurities(); Byte level = taskVo.getLevel(); List depInfos = involveDepService.list(); Listdepartments = new ArrayList<>(); ListdepartmentsExist = taskInvolveDepService.getListByTaskCode(taskVo.getCode()); if (departmentsExist == null || departmentsExist.size() == 0){ if (taskVo.getIsholiday().equals((byte)1)){ level++; } if (!level.equals(TaskInfo.LEVEL_SECOND)){ for (InvolveDepInfo depInfo : depInfos){ TaskInvolveDepartment department = new TaskInvolveDepartment(); department.setDepartment(depInfo.getDepartment()); department.setTaskcode(taskVo.getCode()); department.setCreatedat(new Date()); department.setCreatedby(userInfo.getRealname()); departments.add(department); } taskInvolveDepService.saveBatch(departments); } } DepartmentInfo departmentInfo = departmentService.selectSafetyDepartment(); if (departmentInfo == null && !level.equals(TaskInfo.LEVEL_SECOND)){ throw new BusinessException("安全部门信息不能为空"); } if (departmentInfo != null && !level.equals(TaskInfo.LEVEL_SECOND) && StringUtils.isBlank(taskInfo.getSecuritydep())){ taskInfo.setSecuritydep(departmentInfo.getDepartment()); } TaskReview taskReview = taskVo.getTaskReviews().get(0); taskReview.setCreatedat(new Date()); taskReview.setCreatedby(userInfo.getRealname()); taskReviewService.saveReview(taskReview); taskSecurities.forEach(item->{ item.setTaskcode(taskVo.getCode()); item.setCreatedat(now); item.setCreatedby(userInfo.getRealname()); }); taskSecurityService.saveBatch(taskSecurities); List resources = taskVo.getResources(); if (resources != null && resources.size() > 0){ resources.forEach(item->{ item.setTaskcode(taskVo.getCode()); item.setCreatedat(now); item.setCreatedby(userInfo.getRealname()); }); taskEnclosureService.saveBatch(resources); } List taskEquipments = taskVo.getTaskEquipments(); taskEquipments.forEach(item->{ item.setTaskcode(taskVo.getCode()); item.setCreatedat(now); item.setCreatedby(userInfo.getRealname()); }); taskEquipmentService.saveBatch(taskEquipments); TaskRisk risk = taskVo.getTaskRisk(); risk.setTaskcode(taskVo.getCode()); risk.setCreatedat(now); risk.setCreatedby(userInfo.getRealname()); taskRiskService.save(risk); taskInfo.setStatus(TaskInfo.COMMITTED); taskInfo.setModifiedat(new Date()); taskInfo.setModifiedby(userInfo.getRealname()); updateById(taskInfo); String content = "任务提交"; TaskLog taskLog = new TaskLog(taskInfo.getCode(),content,userInfo.getRealname(),new Date(),userInfo.getCompany()); taskLogService.save(taskLog); } @Override public void updateTaskByAppForAnalysis(TaskVo taskVo, UserInfo userInfo) { if (StringUtils.isBlank(taskVo.getAnalysisarea()) || StringUtils.isBlank(taskVo.getAnalysismedium())){ throw new BusinessException("需要气体检测分析时必须填写分析点名称和分析介质"); } taskVo.setStatus(TaskInfo.TEST_COMMITTED); taskVo.setModifiedby(userInfo.getRealname()); taskVo.setModifiedat(new Date()); TaskInfo taskInfo = BeanUtils.copy(taskVo,TaskInfo.class); updateById(taskInfo); } @Override public String generateCode(UserInfo userInfo, String workCode) { UserInfo user = userService.getById(userInfo); CompanyInfo companyInfo = companyService.selectByName(user.getCompany()); Calendar calendar = Calendar.getInstance(); Integer year = calendar.get(Calendar.YEAR); Integer total = taskInfoMapper.getTotalByYear(year); total++; String sn; int maxSn = 999; if (total > maxSn){ sn = total.toString(); }else { sn = String.format("%03d",total); } String code = companyInfo.getCode()+"-"+workCode+"-"+year+"-"+sn; TaskInfo taskInfo = getTaskByCode(code); while (taskInfo != null){ total ++; if (total > maxSn){ sn = total.toString(); }else { sn = String.format("%03d",total); } code = companyInfo.getCode()+"-"+workCode+"-"+year+"-"+sn; taskInfo = getTaskByCode(code); } return code; } /** * @Description: 创建任务-app端 注意:app端 新建就等于提交 * @date 2021/8/23 14:13 */ @Override @Transactional public void saveTaskByApp(TaskVo taskVo, UserInfo user) { //时间 Date now = new Date(); String realName = user.getRealname(); //任务 task { //任务编号 String taskCode = this.generateCode(user,workCode); taskVo.setStatus(TaskInfo.COMMITTED); taskVo.setCode(taskCode); taskVo.setCreatedat(now); taskVo.setCreatedby(realName); if (taskVo.getIsanalysis() .equals((byte)1)){ if (StringUtils.isBlank(taskVo.getAnalysisarea()) || StringUtils.isBlank(taskVo.getAnalysismedium())){ throw new BusinessException("需要气体检测分析时必须填写分析点名称和分析介质"); } } //任务为一级特级时,要添加相关部门审核流程 List depInfos = involveDepService.list(); Listdepartments = new ArrayList<>(); Byte level = taskVo.getLevel(); if (taskVo.getIsholiday().equals((byte)1)){ level++; } if (!level.equals(TaskInfo.LEVEL_SECOND)){ for (InvolveDepInfo depInfo : depInfos){ TaskInvolveDepartment department = new TaskInvolveDepartment(); department.setDepartment(depInfo.getDepartment()); department.setTaskcode(taskCode); department.setCreatedat(new Date()); department.setCreatedby(user.getRealname()); departments.add(department); } taskInvolveDepService.saveBatch(departments); } DepartmentInfo departmentInfo = departmentService.selectSafetyDepartment(); if (departmentInfo == null && !level.equals(TaskInfo.LEVEL_SECOND)){ throw new BusinessException("安全部门信息不能为空"); } if (departmentInfo != null && !level.equals(TaskInfo.LEVEL_SECOND)){ taskVo.setSecuritydep(departmentInfo.getDepartment()); } this.save(taskVo); } //审核信息 { if (taskVo.getIsanalysis() .equals((byte)0)){ if (taskVo.getTaskReviews() == null || taskVo.getTaskReviews().size() < 1 || taskVo.getTaskReviews().get(0) ==null){ throw new BusinessException("审核信息不能为空"); } TaskReview taskReview = taskVo.getTaskReviews().get(0); taskReview.setTaskId(taskVo.getId()); taskReview.setTaskcode(taskVo.getCode()); taskReview.setCreatedat(new Date()); taskReview.setCreatedby(user.getRealname()); taskReviewService.saveReview(taskReview); } } //安全措施 { List taskSecurities = taskVo.getTaskSecurities(); if (taskSecurities == null || taskSecurities.size() == 0) throw new BusinessException("请填写安全措施"); taskSecurities.forEach(item->{ item.setTaskcode(taskVo.getCode()); item.setCreatedat(now); item.setCreatedby(realName); item.setConfirmedby(realName); }); taskSecurityService.saveBatch(taskSecurities); } //pdf或图片 { List resources = taskVo.getResources(); if (resources != null && resources.size() > 0){ resources.forEach(item->{ item.setTaskcode(taskVo.getCode()); item.setCreatedat(now); item.setCreatedby(realName); }); taskEnclosureService.saveBatch(resources); } } //安全设备 { List taskEquipments = taskVo.getTaskEquipments(); if (taskEquipments == null || taskEquipments.size() == 0) throw new BusinessException("请选择安全设备"); taskEquipments.forEach(item->{ item.setTaskcode(taskVo.getCode()); item.setCreatedat(now); item.setCreatedby(realName); }); taskEquipmentService.saveBatch(taskEquipments); } //安全风险 { TaskRisk risk = taskVo.getTaskRisk(); if (risk == null) throw new BusinessException("请填写安全风险"); risk.setTaskcode(taskVo.getCode()); risk.setCreatedat(now); risk.setCreatedby(realName); taskRiskService.save(risk); } { List subTaskInfos = taskVo.getSubTaskInfos(); if (subTaskInfos == null || subTaskInfos.size() == 0) {throw new BusinessException("请选择涉及的作业信息");} subTaskInfos.forEach(item-> item.setTaskcode(taskVo.getCode())); subTaskService.saveBatch(subTaskInfos); } TaskLog taskLog = new TaskLog(taskVo.getCode(), "", realName, new Date(), user.getCompany()); taskLogService.save(taskLog); } @Override public void selectDataGridByDep(PageInfo pageInfo) { Page page = PageUtil.getPage(pageInfo,"createdat"); if (StringUtils.isBlank(pageInfo.getSort())){ pageInfo.setSort("createdat"); } if (StringUtils.isBlank(pageInfo.getOrder())){ pageInfo.setOrder("desc"); } List taskInfos = taskInfoMapper.selectTaskDataGridByDep(pageInfo.getCondition(),page); pageInfo.setResult(taskInfos); pageInfo.setTotalCount(page.getTotal()); } @Override public void selectDataGridViewable(PageInfo pageInfo) { Page page = PageUtil.getPage(pageInfo,"createdat"); if (StringUtils.isBlank(pageInfo.getSort())){ pageInfo.setSort("createdat"); } if (StringUtils.isBlank(pageInfo.getOrder())){ pageInfo.setOrder("desc"); } List taskInfos = taskInfoMapper.selectDataGridViewable(pageInfo.getCondition(),page); ListtaskVos = new ArrayList<>(); for (TaskInfo taskInfo : taskInfos){ TaskVo taskVo = BeanUtils.copy(taskInfo,TaskVo.class); List workers = taskWorkerService.getVoByTaskCode(taskVo.getCode()); Listsecurities = taskSecurityService.getListByTaskCode(taskVo.getCode()); Listanalyses = taskAnalysisService.getListByTaskCode(taskVo.getCode()); List enclosures = taskEnclosureService.getListByTaskCode(taskVo.getCode()); Listequipments = taskEquipmentService.getListByTaskCode(taskVo.getCode()); List departments = taskInvolveDepService.getListByTaskCode(taskVo.getCode()); ListequipmentInfos = equipmentService.selectByTaskAndWorker(taskInfo.getCode(),taskInfo.getApproversupervisor()); TaskRisk taskRisk = taskRiskService.getTaskRiskByCode(taskVo.getCode()); List reviews = taskReviewService.getListByTaskCode(taskVo.getCode()); taskVo.setTaskReviews(reviews); taskVo.setTaskWorkers(workers); taskVo.setTaskSecurities(securities); taskVo.setTaskAnalyses(analyses); taskVo.setTaskEquipments(equipments); taskVo.setTaskRisk(taskRisk); taskVo.setResources(enclosures); taskVo.setDepartments(departments); taskVo.setSupervisorEquipments(equipmentInfos); List subTaskInfos = subTaskService.getSubTasksByCode(taskVo.getCode()); taskVo.setSubTaskInfos(subTaskInfos); taskVos.add(taskVo); } pageInfo.setResult(taskVos); pageInfo.setTotalCount(page.getTotal()); } @Override public void getWaitReviewDataGrid(PageInfo pageInfo) { Page page = PageUtil.getPage(pageInfo,"createdat"); if (StringUtils.isBlank(pageInfo.getSort())){ pageInfo.setSort("createdat"); } if (StringUtils.isBlank(pageInfo.getOrder())){ pageInfo.setOrder("desc"); } List taskInfos = taskInfoMapper.getWaitReviewDataGrid(pageInfo.getCondition(),page); ListtaskVos = new ArrayList<>(); for (TaskInfo taskInfo : taskInfos){ TaskVo taskVo = BeanUtils.copy(taskInfo,TaskVo.class); List workers = taskWorkerService.getVoByTaskCode(taskVo.getCode()); Listsecurities = taskSecurityService.getListByTaskCode(taskVo.getCode()); Listanalyses = taskAnalysisService.getListByTaskCode(taskVo.getCode()); List enclosures = taskEnclosureService.getListByTaskCode(taskVo.getCode()); Listequipments = taskEquipmentService.getListByTaskCode(taskVo.getCode()); List departments = taskInvolveDepService.getListByTaskCode(taskVo.getCode()); TaskRisk taskRisk = taskRiskService.getTaskRiskByCode(taskVo.getCode()); List reviews = taskReviewService.getListByTaskCode(taskVo.getCode()); taskVo.setTaskReviews(reviews); taskVo.setTaskWorkers(workers); taskVo.setTaskSecurities(securities); taskVo.setTaskAnalyses(analyses); taskVo.setTaskEquipments(equipments); taskVo.setTaskRisk(taskRisk); taskVo.setResources(enclosures); taskVo.setDepartments(departments); List subTaskInfos = subTaskService.getSubTasksByCode(taskVo.getCode()); taskVo.setSubTaskInfos(subTaskInfos); taskVos.add(taskVo); } pageInfo.setResult(taskVos); pageInfo.setTotalCount(page.getTotal()); } @Override public TaskInfo getTaskByCode(String code) { LambdaQueryWrapperwrapper = new LambdaQueryWrapper<>(); wrapper.eq(TaskInfo::getCode,code); return baseMapper.selectOne(wrapper); } @Override public List getPendingTask(String type, String name) { List taskVos = taskInfoMapper.getPendingTask(type,name); for (TaskVo taskVo : taskVos){ List workers = taskWorkerService.getVoByTaskCode(taskVo.getCode()); Listsecurities = taskSecurityService.getListByTaskCode(taskVo.getCode()); Listanalyses = taskAnalysisService.getListByTaskCode(taskVo.getCode()); List enclosures = taskEnclosureService.getListByTaskCode(taskVo.getCode()); Listequipments = taskEquipmentService.getListByTaskCode(taskVo.getCode()); List departments = taskInvolveDepService.getListByTaskCode(taskVo.getCode()); ListequipmentInfos = equipmentService.selectByTaskAndWorker(taskVo.getCode(),taskVo.getApproversupervisor()); TaskRisk taskRisk = taskRiskService.getTaskRiskByCode(taskVo.getCode()); List reviews = taskReviewService.getListByTaskCode(taskVo.getCode()); taskVo.setTaskReviews(reviews); taskVo.setTaskWorkers(workers); taskVo.setTaskSecurities(securities); taskVo.setTaskAnalyses(analyses); taskVo.setTaskEquipments(equipments); taskVo.setTaskRisk(taskRisk); taskVo.setResources(enclosures); taskVo.setDepartments(departments); taskVo.setSupervisorEquipments(equipmentInfos); List subTaskInfos = subTaskService.getSubTasksByCode(taskVo.getCode()); taskVo.setSubTaskInfos(subTaskInfos); } return taskVos; } /** * @Description: 生成pdf文件 * @date 2021/8/26 12:23 */ @Override public List selectAllWorkCertUndone() { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.select(TaskInfo::getId, TaskInfo::getCode) .eq(TaskInfo::getStatus, TaskInfo.APPROVED) .isNull(TaskInfo::getPath); return taskInfoMapper.selectList(queryWrapper); } @Override public List getDoingTask() { List taskVos = taskInfoMapper.getDoingTask(); for (TaskVo taskVo : taskVos){ List workers = taskWorkerService.getVoByTaskCode(taskVo.getCode()); Listsecurities = taskSecurityService.getListByTaskCode(taskVo.getCode()); Listanalyses = taskAnalysisService.getListByTaskCode(taskVo.getCode()); List enclosures = taskEnclosureService.getListByTaskCode(taskVo.getCode()); Listequipments = taskEquipmentService.getListByTaskCode(taskVo.getCode()); List departments = taskInvolveDepService.getListByTaskCode(taskVo.getCode()); ListequipmentInfos = equipmentService.selectByTaskAndWorker(taskVo.getCode(),taskVo.getApproversupervisor()); TaskRisk taskRisk = taskRiskService.getTaskRiskByCode(taskVo.getCode()); List reviews = taskReviewService.getListByTaskCode(taskVo.getCode()); taskVo.setTaskReviews(reviews); taskVo.setTaskWorkers(workers); taskVo.setTaskSecurities(securities); taskVo.setTaskAnalyses(analyses); taskVo.setTaskEquipments(equipments); taskVo.setTaskRisk(taskRisk); taskVo.setResources(enclosures); taskVo.setDepartments(departments); taskVo.setSupervisorEquipments(equipmentInfos); } return taskVos; } @Override public List getWorkToday() { List data = new ArrayList<>(8); //动火 Map map1 = new HashMap<>(); map1.put("num", taskInfoMapper.selectCountWorkToday(TaskInfo.DOING)); map1.put("name", "动火作业"); data.add(map1); //吊装作业 Map map2 = new HashMap<>(); map2.put("num", 0); map2.put("name", "吊装作业"); data.add(map2); //动土作业 Map map3 = new HashMap<>(); map3.put("num", 0); map3.put("name", "动土作业"); data.add(map3); //断路作业 Map map4 = new HashMap<>(); map4.put("num", 0); map4.put("name", "断路作业"); data.add(map4); //高处作业 Map map5 = new HashMap<>(); map5.put("num", 0); map5.put("name", "高处作业"); data.add(map5); //临时用电作业 Map map6 = new HashMap<>(); map6.put("num", 0); map6.put("name", "临时用电作业"); data.add(map6); //盲板抽堵作业 Map map7 = new HashMap<>(); map7.put("num", 0); map7.put("name", "盲板抽堵作业"); data.add(map7); Map map = new HashMap<>(); //受限空间作业 Map map8 = new HashMap<>(); map8.put("num", 0); map8.put("name", "受限空间作业"); data.add(map8); return data; } @Override public IPage getWorkTodayDetail(Page page, Map filter) { Map params = new HashMap<>(); params.put("flag", TaskInfo.DOING); List data = taskInfoMapper.selectPageWorkTodayDetail(page,params); return page.setRecords(data); } @Override public List getSpecialCompareInPeriod(String period) { Calendar instance = Calendar.getInstance(); if ("year".equals(period)) { instance.clear(Calendar.MONTH); instance.set(Calendar.DAY_OF_MONTH,1); instance.set(Calendar.HOUR_OF_DAY,0); } if ("month".equals(period)) { instance.add(Calendar.MONTH, -1); } Date startTime = instance.getTime(); List data = new ArrayList<>(8); //动火 Map map1 = new HashMap<>(); map1.put("num", taskInfoMapper.selectCountDoneInPeriod(startTime,TaskInfo.APPROVED)); map1.put("name", "动火作业"); data.add(map1); //吊装作业 Map map2 = new HashMap<>(); map2.put("num", 0); map2.put("name", "吊装作业"); data.add(map2); //动土作业 Map map3 = new HashMap<>(); map3.put("num", 0); map3.put("name", "动土作业"); data.add(map3); //断路作业 Map map4 = new HashMap<>(); map4.put("num", 0); map4.put("name", "断路作业"); data.add(map4); //高处作业 Map map5 = new HashMap<>(); map5.put("num", 0); map5.put("name", "高处作业"); data.add(map5); //临时用电作业 Map map6 = new HashMap<>(); map6.put("num", 0); map6.put("name", "临时用电作业"); data.add(map6); //盲板抽堵作业 Map map7 = new HashMap<>(); map7.put("num", 0); map7.put("name", "盲板抽堵作业"); data.add(map7); //受限空间作业 Map map8 = new HashMap<>(); map8.put("num", 0); map8.put("name", "受限空间作业"); data.add(map8); return data; } @Override public Map getWorkEverydayInMonth() { Calendar calendar = new GregorianCalendar(); calendar.setTime(new Date()); //当前日期往前推days天 calendar.add(Calendar.DATE, -30); Date startTime = calendar.getTime(); int[] index = new int[30]; for (int i = 0; i < 30; i++) { index[i] = i + 1; } //所有 Map map = new HashMap<>(); map.put("everyday", taskInfoMapper.selectCountWorkEverydayInMonth(index,startTime,TaskInfo.APPROVED)); return map; } @Override public Map getFourTotal() { Map map = new HashMap<>(); List workToday = this.getWorkToday(); //今日作业总数 Integer sum = workToday.stream().map(item -> (int) item.get("num")).reduce(0, Integer::sum); map.put("num0", sum); //今日预警总数 map.put("num1", warningService.getCount(WarningInfo.EARLY_WARNING)); //今日报警总数 map.put("num2", warningService.getCount(WarningInfo.WARNING)); //今日设备故障总数 map.put("num3", warningService.getCount(WarningInfo.FAULT)); return map; } @Override public IPage selectTaskInPeriod(Page page, Map filter, UserInfo user) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); //flag = 4 作业中 queryWrapper.select(TaskInfo::getId,TaskInfo::getCode,TaskInfo::getArea,TaskInfo::getStarttime,TaskInfo::getEndtime,TaskInfo::getDirector) .eq(TaskInfo::getFlag,4) .like(TaskInfo::getCode,filter.get("taskcode")) .orderByDesc(TaskInfo::getCreatedat); return taskInfoMapper.selectPage(page,queryWrapper); } @Override public TaskVo getTaskVoByCode(String code) { TaskInfo taskInfo = getTaskByCode(code); TaskVo taskVo = BeanUtils.copy(taskInfo,TaskVo.class); List workers = taskWorkerService.getVoByTaskCode(taskVo.getCode()); Listsecurities = taskSecurityService.getListByTaskCode(taskVo.getCode()); Listanalyses = taskAnalysisService.getListByTaskCode(taskVo.getCode()); List enclosures = taskEnclosureService.getListByTaskCode(taskVo.getCode()); Listequipments = taskEquipmentService.getListByTaskCode(taskVo.getCode()); List departments = taskInvolveDepService.getListByTaskCode(taskVo.getCode()); ListequipmentInfos = equipmentService.selectByTaskAndWorker(taskVo.getCode(),taskVo.getApproversupervisor()); TaskRisk taskRisk = taskRiskService.getTaskRiskByCode(taskVo.getCode()); List reviews = taskReviewService.getListByTaskCode(taskVo.getCode()); taskVo.setTaskReviews(reviews); taskVo.setTaskWorkers(workers); taskVo.setTaskSecurities(securities); taskVo.setTaskAnalyses(analyses); taskVo.setTaskEquipments(equipments); taskVo.setTaskRisk(taskRisk); taskVo.setResources(enclosures); taskVo.setDepartments(departments); taskVo.setSupervisorEquipments(equipmentInfos); ListsubTaskInfos = subTaskService.getSubTasksByCode(code); taskVo.setSubTaskInfos(subTaskInfos); return taskVo; } @Override public String generateAllWorkCert(String code) { String fileDocxUrl = taskPath + code + "-apply.doc"; String fileReturn = task + code + "-apply.doc"; TaskVo taskInfo = this.getTaskVoByCode(code); //1.word文档替换 try { ClassPathResource classPathResource = new ClassPathResource("printTemplate/allworkcert.doc"); InputStream inputStream = classPathResource.getInputStream(); WordTemplate template = new WordTemplate(); template.loadTemplate(null, inputStream); //数据准备 Map simpleData = new HashMap<>(); Map tables = new HashMap<>(); Map mergeTables = new HashMap<>(); Map> tasktypesMergeMap = new HashMap<>(); Map> ownAttr =new HashMap<>(); Map nameMapGraph = new HashMap<>(); { //基础信息 {simpleData.put("unit", taskInfo.getUnit()); simpleData.put("applicant", taskInfo.getApplicant()); simpleData.put("code", taskInfo.getCode()); simpleData.put("area", taskInfo.getArea()); simpleData.put("description", taskInfo.getDescription()); simpleData.put("analysisarea", taskInfo.getAnalysisarea()); simpleData.put("analysismedium", taskInfo.getAnalysismedium()); simpleData.put("mode", taskInfo.getMode()); simpleData.put("director", taskInfo.getDirector()); simpleData.put("starttime", WordTemplate.formatTime(taskInfo.getStarttime(),WordTemplate.sdf)); simpleData.put("endtime", WordTemplate.formatTime(taskInfo.getEndtime(), WordTemplate.sdf)); simpleData.put("othertask", taskInfo.getOthertask()); simpleData.put("hazard", taskInfo.getHazard()); simpleData.put("supervisor", taskInfo.getSupervisor()); simpleData.put("profession", taskInfo.getProfession()); simpleData.put("partdirector", taskInfo.getPartdirector()); simpleData.put("approversupervisor", taskInfo.getApproversupervisor()); simpleData.put("approverprofession", taskInfo.getApproverprofession()); simpleData.put("applyunittime", WordTemplate.formatTime(taskInfo.getApplyunittime(),WordTemplate.sdf)); simpleData.put("constructionunit", taskInfo.getConstructionunit()); simpleData.put("constructiontime", WordTemplate.formatTime(taskInfo.getConstructiontime(), WordTemplate.sdf)); simpleData.put("securitytime", WordTemplate.formatTime(taskInfo.getSecuritytime(), WordTemplate.sdf)); simpleData.put("enterprisetime", WordTemplate.formatTime(taskInfo.getEnterprisetime(), WordTemplate.sdf));} //基础信息签名照 { List taskReviews = taskInfo.getTaskReviews(); String blank = ""; nameMapGraph.put("applyunitname", blank); simpleData.put("applyunitopinion", blank); nameMapGraph.put("constructionname", blank); simpleData.put("constructionopinion", blank); nameMapGraph.put("securityname", blank); simpleData.put("securityopinion",blank); nameMapGraph.put("enterprisename", blank); simpleData.put("enterpriseopinion", blank); taskReviews.forEach(taskReview -> { String autograph = taskReview.getAutograph(); String level = taskReview.getLevel(); String opinion = taskReview.getOpinion(); if (("申请部门审批").equals(level)) { nameMapGraph.put("applyunitname", autograph); simpleData.put("applyunitopinion", opinion); } if (("施工单位补充确认").equals(level)) { nameMapGraph.put("constructionname", autograph); simpleData.put("constructionopinion", opinion); } if (("安全部门审批").equals(level)) { nameMapGraph.put("securityname", autograph); simpleData.put("securityopinion",opinion); } if (("单位负责人审批").equals(level)) { nameMapGraph.put("enterprisename", autograph); simpleData.put("enterpriseopinion", opinion); } }); //enterprisename 单位负责人审批 } //动火等级判断 switch (taskInfo.getLevel()) { case (byte)0: simpleData.put("level", "二级");break; case (byte)1: simpleData.put("level", "一级");break; case (byte)2: simpleData.put("level", "特级");break; default: simpleData.put("level", null); } //安全部门 simpleData.put("securitydep", taskInfo.getSecuritydep()); //作业人 { List taskWorkersList = taskInfo.getTaskWorkers(); //作业人员 String workersname = taskWorkersList.stream().map(TaskWorker::getWorker).distinct().collect(Collectors.joining(",")); simpleData.put("workersname", workersname); String[] workerFields = {"worker", "branch", "number"}; List workers= new ArrayList(){{ taskWorkersList.forEach(item->{ add(new String[]{item.getWorker(), item.getBranch(), item.getNumber()}); }); }}; WordTemplate.Table workerTable = new WordTemplate.Table(workerFields, workers); tables.put("workerTable", workerTable); } //分析介质 { List taskAnalyses = taskInfo.getTaskAnalyses(); String[] analysisFields = {"mediumname", "mediumvalue", "analysisat","analyst"}; List taskAnalysis = new ArrayList(){{ taskAnalyses.forEach(item-> add(new String[]{item.getMediumname(), item.getMediumvalue(), WordTemplate.formatTime(item.getAnalysisat(),WordTemplate.sdf_dhms), item.getAnalyst()})); }}; WordTemplate.Table analysisTable = new WordTemplate.Table(analysisFields, taskAnalysis); tables.put("mediumTable", analysisTable); } //安全措施 { List taskSecurityList = taskInfo.getTaskSecurities(); Map> parentGroupData = new HashMap<>(); taskSecurityList.forEach(item->{ String tasktype = item.getTasktype(); if (parentGroupData.containsKey(tasktype)) { parentGroupData.get(tasktype).add(item); }else{ parentGroupData.put(tasktype, new ArrayList<>(Collections.singletonList(item))); } }); //遍历分组后内容 for (Map.Entry> parent : parentGroupData.entrySet()) { Map> groupByDataMap = new HashMap<>(); String[] taskSecurityFields = {"order", "content", "checked", "createby"}; String[] taskSecurityMergeFields = {"createby"}; //根据创建人分组 parent.getValue().forEach(item -> { String confirmedby = ""; if(item.getConfirmedby() != null) confirmedby = item.getConfirmedby(); if (!groupByDataMap.containsKey(confirmedby)) { groupByDataMap.put(confirmedby, new ArrayList<>(Collections.singletonList(item))); } else { groupByDataMap.get(confirmedby).add(item); } }); int lastOrder = 0; //记录上一个合并表格的最大序号 int mergeTableSeq = 1; //word合并表后缀序号 for (Map.Entry> entry : groupByDataMap.entrySet()) { String confirmedby = entry.getKey(); List mappingList = entry.getValue(); List taskSecurities = new ArrayList<>(); for (int i = mappingList.size() - 1; i >= 0; i--) { TaskSecurity taskSecurity = mappingList.get(i); taskSecurities.add(new String[]{ lastOrder + i + 1 + "", taskSecurity.getContent().replace("_",taskSecurity.getNum()+""), taskSecurity.getChecked() == (byte) 1 ? "√" : "/", confirmedby}); if (i == 0) { lastOrder = mappingList.size(); } } WordTemplate.MergeTable mergeTable = new WordTemplate.MergeTable(taskSecurityFields, taskSecurityMergeFields, taskSecurities); String mergeTableFlag = parent.getKey() + "mergeTable" + mergeTableSeq; mergeTables.put(mergeTableFlag, mergeTable); if (tasktypesMergeMap.get(parent.getKey()) == null) { tasktypesMergeMap.put(parent.getKey(), new ArrayList<>(Collections.singletonList(mergeTableFlag))); }else{ tasktypesMergeMap.get(parent.getKey()).add(mergeTableFlag); } mergeTableSeq++; } } } //相关部门 { //时间降序吗,最新为第一条 List departments = taskInfo.getDepartments(); if (departments.size() > 0) { simpleData.put("involvedep",departments.stream().map(TaskInvolveDepartment::getDepartment).collect(Collectors.joining("、"))); simpleData.put("departmentconent", departments.get(0).getContent()); simpleData.put("reviewedbys",departments.stream().map(TaskInvolveDepartment::getReviewedby).collect(Collectors.joining("、"))); simpleData.put("reviewedtime", WordTemplate.formatTime(departments.get(0).getCreatedat(), WordTemplate.sdf)); }else{ simpleData.put("involvedep",null); simpleData.put("departmentconent", null); simpleData.put("reviewedbys",null); simpleData.put("reviewedtime",null); } } //作业类型 { List subTaskInfos = taskInfo.getSubTaskInfos(); String collectType = subTaskInfos.stream().map(subTaskInfo -> "☑ " + subTaskInfo.getType()).collect(Collectors.joining(" ")); simpleData.put("type", collectType); //8个作业 List attrList; for (SubTaskInfo subTask : subTaskInfos) { if (TaskType.HOT.msg.equals(subTask.getType())) { attrList = new ArrayList<>(); String level = ""; switch (subTask.getLevel()){ case (byte)0: level = "二级"; case (byte)1: level = "一级"; case (byte)2: level = "特级"; } attrList.add(new WordTemplate.Attribute("动火作业级别", level)); attrList.add(new WordTemplate.Attribute("动火作业方式", subTask.getFiretype() +"")); ownAttr.put(subTask.getType(), attrList); } if (TaskType.SPACE.msg.equals(subTask.getType())) { attrList = new ArrayList<>(); attrList.add(new WordTemplate.Attribute("受限空间分类", subTask.getSpacecategory() +"")); attrList.add(new WordTemplate.Attribute("受限空间名称", subTask.getSpacename() +"")); attrList.add(new WordTemplate.Attribute("受限空间介质名称", subTask.getSpacemedium() +"")); attrList.add(new WordTemplate.Attribute("是否酸碱腐蚀",subTask.getAcibase())); ownAttr.put(subTask.getType(), attrList); } if (TaskType.HIGH.msg.equals(subTask.getType())) { attrList = new ArrayList<>(); attrList.add(new WordTemplate.Attribute("高度作业等级", subTask.getHeightlevel() +"")); attrList.add(new WordTemplate.Attribute("高处作业作业高度", subTask.getWorkheight() +"")); ownAttr.put(subTask.getType(), attrList); } if (TaskType.HOISTING.msg.equals(subTask.getType())) { attrList = new ArrayList<>(); attrList.add(new WordTemplate.Attribute("吊装作业等级", subTask.getHoistinglevel() + "")); attrList.add(new WordTemplate.Attribute("吊装作业重量", subTask.getHoistingweight() + "")); ownAttr.put(subTask.getType(), attrList); } if (TaskType.BLIND.msg.equals(subTask.getType())) { attrList = new ArrayList<>(); attrList.add(new WordTemplate.Attribute("盲板材质", subTask.getBlindboardmaterial() +"")); attrList.add(new WordTemplate.Attribute("盲板规格", subTask.getBlindboardspecification()+"")); attrList.add(new WordTemplate.Attribute("盲板编号", subTask.getBlindboardnumber() + "")); attrList.add(new WordTemplate.Attribute("生产单位作业指挥", subTask.getCommander() + "")); attrList.add(new WordTemplate.Attribute("设备管道名称", subTask.getPipename() + "")); attrList.add(new WordTemplate.Attribute("设备管道介质", subTask.getPipemedium() + "")); attrList.add(new WordTemplate.Attribute("设备管道温度", subTask.getPipetemperature() + "")); attrList.add(new WordTemplate.Attribute("设备管道压力", subTask.getPipepressure() + "")); //位置图没有 ownAttr.put(subTask.getType(), attrList); } if (TaskType.BREAK.msg.equals(subTask.getType())) { attrList = new ArrayList<>(); attrList.add(new WordTemplate.Attribute("断路原因", subTask.getBreakreason() +"")); //断路地段示意图无 ownAttr.put(subTask.getType(), attrList); } if (TaskType.ELECTRIC.msg.equals(subTask.getType())) { attrList = new ArrayList<>(); attrList.add(new WordTemplate.Attribute("电源接入点", subTask.getElectricityarea() +"")); attrList.add(new WordTemplate.Attribute("工作电压", subTask.getVoltage() +"")); attrList.add(new WordTemplate.Attribute("功率", subTask.getPower() +"")); //断路地段示意图无 ownAttr.put(subTask.getType(), attrList); } if (TaskType.SOILD.msg.equals(subTask.getType())) { attrList = new ArrayList<>(); attrList.add(new WordTemplate.Attribute("动土作业深度(单位:m)", subTask.getSoildepth() +"")); attrList.add(new WordTemplate.Attribute("动土作业面积(单位:㎡)", subTask.getSoilarea() +"")); //动土文件地址无 ownAttr.put(subTask.getType(), attrList); } } } //安全交底和风险 { TaskRisk taskRisk = taskInfo.getTaskRisk(); simpleData.put("environment", taskRisk.getEnvironment()); simpleData.put("preventive", taskRisk.getPreventive()); simpleData.put("emergency", taskRisk.getEmergency()); simpleData.put("other", taskRisk.getOther()); simpleData.put("taskrisk-director", taskRisk.getDirector()); simpleData.put("taskrisk-taskdirector", taskRisk.getTaskdirector()); simpleData.put("confirmat", WordTemplate.formatTime(taskRisk.getConfirmat(),WordTemplate.sdf)); simpleData.put("contents", taskRisk.getContent()); } } wordService.generateAllTaskCert( new HashMap>>(){{put("tasktype",tasktypesMergeMap);}}, new HashMap>>(){{put("typeAndOwnAttr",ownAttr);}}, tables, mergeTables, simpleData, nameMapGraph, template); template.saveFile(fileDocxUrl); } catch (FileNotFoundException e) { e.printStackTrace(); throw new BusinessException("找不到模板文件路径"); } catch (IOException | XmlException | InvalidFormatException | InterruptedException e) { e.printStackTrace(); } return fileReturn; } }