|
|
|
@ -1,38 +1,45 @@
|
|
|
|
|
package com.hnac.hzims.ticket.repair.service.impl; |
|
|
|
|
|
|
|
|
|
import cn.afterturn.easypoi.excel.entity.TemplateExportParams; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.alibaba.fastjson.TypeReference; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse; |
|
|
|
|
import com.hnac.hzims.ticket.repair.entity.WorkTaskEntity; |
|
|
|
|
import com.hnac.hzims.ticket.repair.mapper.WorkTaskMapper; |
|
|
|
|
import com.hnac.hzims.ticket.repair.service.IWorkTaskService; |
|
|
|
|
import com.hnac.hzims.ticket.repair.vo.WorkTaskContentVO; |
|
|
|
|
import com.hnac.hzims.ticket.repair.vo.WorkTaskPreviewVO; |
|
|
|
|
import com.hnac.hzims.ticket.repair.vo.WorkTaskVO; |
|
|
|
|
import com.hnac.hzims.ticket.utils.ExcelUtil; |
|
|
|
|
import com.hnac.hzims.ticket.utils.PdfUtils; |
|
|
|
|
import com.hnac.hzims.ticket.workTicket.entity.WorkTicketInfoEntity; |
|
|
|
|
import com.hnac.hzims.ticket.workTicket.service.IWorkTicketInfoService; |
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
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.Condition; |
|
|
|
|
import org.springblade.core.secure.utils.AuthUtil; |
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
|
import org.springblade.core.tool.utils.DateUtil; |
|
|
|
|
import org.springblade.core.tool.utils.ObjectUtil; |
|
|
|
|
import org.springblade.core.tool.utils.StringUtil; |
|
|
|
|
import org.springblade.core.tool.utils.*; |
|
|
|
|
import org.springblade.flow.core.entity.BladeFlow; |
|
|
|
|
import org.springblade.flow.core.feign.IFlowClient; |
|
|
|
|
import org.springblade.flow.core.utils.FlowUtil; |
|
|
|
|
import org.springblade.flow.core.utils.TaskUtil; |
|
|
|
|
import org.springblade.system.entity.Dept; |
|
|
|
|
import org.springblade.system.feign.ISysClient; |
|
|
|
|
import org.springblade.system.user.entity.User; |
|
|
|
|
import org.springblade.system.user.feign.IUserClient; |
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.web.context.request.RequestContextHolder; |
|
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes; |
|
|
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @author ysj |
|
|
|
@ -48,43 +55,14 @@ public class WorkTaskServiceImpl extends BaseServiceImpl<WorkTaskMapper, WorkTas
|
|
|
|
|
|
|
|
|
|
private final ISysClient sysClient; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 工作任务单-分页查询 |
|
|
|
|
* @param page |
|
|
|
|
* @param workTask |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public IPage<WorkTaskEntity> workTaskService(IPage<WorkTaskEntity> page, WorkTaskVO workTask) { |
|
|
|
|
QueryWrapper wrapper = Condition.getQueryWrapper(workTask); |
|
|
|
|
if(StringUtil.isNotBlank(workTask.getStartTime())){ |
|
|
|
|
wrapper.ge("CREATE_TIME",workTask.getStartTime()); |
|
|
|
|
} |
|
|
|
|
if(StringUtil.isNotBlank(workTask.getEndTime())){ |
|
|
|
|
wrapper.le("CREATE_TIME",workTask.getEndTime()); |
|
|
|
|
} |
|
|
|
|
if(ObjectUtil.isNotEmpty(workTask.getGroupId())){ |
|
|
|
|
wrapper.eq("GROUP_ID",workTask.getGroupId()); |
|
|
|
|
} |
|
|
|
|
if(ObjectUtil.isNotEmpty(workTask.getGroupId())){ |
|
|
|
|
wrapper.eq("CREATE_DEPT",workTask.getDeptId()); |
|
|
|
|
} |
|
|
|
|
return super.page(page, wrapper); |
|
|
|
|
} |
|
|
|
|
private final IUserClient userClient; |
|
|
|
|
|
|
|
|
|
@Value("${hzims.ticket.workTask.saveWrokTask.xlsx}") |
|
|
|
|
private String saveWrokTaskXlsxPath; |
|
|
|
|
|
|
|
|
|
@Value("${hzims.ticket.workTask.saveWrokTask.pdf}") |
|
|
|
|
private String saveWrokTaskPdfPath; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 查询工作票数据 |
|
|
|
|
* @param ticketCode |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public List<WorkTicketInfoEntity> workTicketList(String ticketCode) { |
|
|
|
|
if(StringUtil.isEmpty(ticketCode)){ |
|
|
|
|
return workTicketInfoService.list(); |
|
|
|
|
} |
|
|
|
|
return workTicketInfoService.list(Wrappers.<WorkTicketInfoEntity>lambdaQuery() |
|
|
|
|
.like(WorkTicketInfoEntity::getCode,ticketCode)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 工作任务单-开启流程 |
|
|
|
@ -106,8 +84,12 @@ public class WorkTaskServiceImpl extends BaseServiceImpl<WorkTaskMapper, WorkTas
|
|
|
|
|
variables.put("head", TaskUtil.getTaskUser(String.valueOf(workTask.getHead()))); |
|
|
|
|
// 班组成员
|
|
|
|
|
String[] member = workTask.getMember().split(","); |
|
|
|
|
for(int i = 1;i <= member.length ; i++){ |
|
|
|
|
variables.put("duty" + i, TaskUtil.getTaskUser(member[i-1])); |
|
|
|
|
for(int i = 1;i <= 5 ; i++){ |
|
|
|
|
if(i > member.length){ |
|
|
|
|
variables.put("duty" + i, ""); |
|
|
|
|
}else{ |
|
|
|
|
variables.put("duty" + i, TaskUtil.getTaskUser(member[i-1])); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
R<BladeFlow> result = flowClient.startProcessInstanceContainNameByKey("work_task", FlowUtil.getBusinessKey("work_task_v4",String.valueOf(workTask.getId())), workTask.getCode(), variables); |
|
|
|
|
log.error("work_task_start_process_result :{}",result); |
|
|
|
@ -142,14 +124,206 @@ public class WorkTaskServiceImpl extends BaseServiceImpl<WorkTaskMapper, WorkTas
|
|
|
|
|
@Override |
|
|
|
|
public boolean listener(ProcessWorkFlowResponse processWorkFlowResponse) { |
|
|
|
|
Map<String, Object> variables = (Map<String, Object>) processWorkFlowResponse.getVariables(); |
|
|
|
|
log.error("work_task_listener_variables : {}",variables); |
|
|
|
|
Object head = variables.get("head"); |
|
|
|
|
if(ObjectUtil.isNotEmpty(head)){ |
|
|
|
|
variables.put("head",head.toString().replaceAll("taskUser_","")); |
|
|
|
|
} |
|
|
|
|
WorkTaskVO entity = JSONObject.parseObject(JSONObject.toJSONString(variables), new TypeReference<WorkTaskVO>(){}); |
|
|
|
|
// 当前流程名称
|
|
|
|
|
entity.setTaskName(processWorkFlowResponse.getTaskName()); |
|
|
|
|
// 流程阶段执行人员名称
|
|
|
|
|
entity.setNextStepOperator(processWorkFlowResponse.getNextStepOperator()); |
|
|
|
|
|
|
|
|
|
if(ObjectUtil.isNotEmpty(entity.getWorkTicketId())){ |
|
|
|
|
entity.setHeadHandleTime(new Date()); |
|
|
|
|
} |
|
|
|
|
if(ObjectUtil.isNotEmpty(entity.getTerminator())){ |
|
|
|
|
entity.setWorkEndTime(new Date()); |
|
|
|
|
} |
|
|
|
|
if(StringUtil.isNotBlank(entity.getLicensorName())){ |
|
|
|
|
entity.setLicensorTime(new Date()); |
|
|
|
|
} |
|
|
|
|
// 更新工作任务单信息
|
|
|
|
|
this.updateById(entity); |
|
|
|
|
return false; |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 工作任务单-分页查询 |
|
|
|
|
* @param page |
|
|
|
|
* @param workTask |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public IPage<WorkTaskEntity> workTaskService(IPage<WorkTaskEntity> page, WorkTaskVO workTask) { |
|
|
|
|
QueryWrapper wrapper = Condition.getQueryWrapper(workTask); |
|
|
|
|
if(StringUtil.isNotBlank(workTask.getStartTime())){ |
|
|
|
|
wrapper.ge("CREATE_TIME",workTask.getStartTime()); |
|
|
|
|
} |
|
|
|
|
if(StringUtil.isNotBlank(workTask.getEndTime())){ |
|
|
|
|
wrapper.le("CREATE_TIME",workTask.getEndTime()); |
|
|
|
|
} |
|
|
|
|
if(ObjectUtil.isNotEmpty(workTask.getGroupId())){ |
|
|
|
|
wrapper.eq("GROUP_ID",workTask.getGroupId()); |
|
|
|
|
} |
|
|
|
|
if(ObjectUtil.isNotEmpty(workTask.getGroupId())){ |
|
|
|
|
wrapper.eq("CREATE_DEPT",workTask.getDeptId()); |
|
|
|
|
} |
|
|
|
|
return super.page(page, wrapper); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 工作任务单预览 |
|
|
|
|
* @param id |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public void preview(Long id) { |
|
|
|
|
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); |
|
|
|
|
HttpServletResponse response = servletRequestAttributes.getResponse(); |
|
|
|
|
//准备数据
|
|
|
|
|
WorkTaskPreviewVO preview = this.workTaskExport(id); |
|
|
|
|
if(ObjectUtil.isEmpty(preview)){ |
|
|
|
|
throw new ServiceException("查询应急抢修单失败"); |
|
|
|
|
} |
|
|
|
|
Map<String,Object> params = new HashMap<>(); |
|
|
|
|
try { |
|
|
|
|
params = PdfUtils.objectToMap(preview); |
|
|
|
|
}catch (Exception e) { |
|
|
|
|
log.error("转换对象失败!"); |
|
|
|
|
} |
|
|
|
|
TemplateExportParams templateExportParams = new TemplateExportParams("template/excel/work_task_template.xlsx", true); |
|
|
|
|
Workbook workbook = null; |
|
|
|
|
try { |
|
|
|
|
workbook = ExcelUtil.getWorkbook(templateExportParams,params); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
//上传xlsx至服务器
|
|
|
|
|
String fileName = preview.getCode() + "_工作任务单" + PdfUtils.XLSX_SUFFIX; |
|
|
|
|
try { |
|
|
|
|
ExcelUtil.upload(workbook,saveWrokTaskXlsxPath,fileName); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
//将docx文件转换为pdf并保存
|
|
|
|
|
String pdfFileName = preview.getCode() + "_工作任务单" + PdfUtils.PDF_SUFFIX; |
|
|
|
|
String xlsxFileName = preview.getCode() + "_工作任务单" + PdfUtils.XLSX_SUFFIX; |
|
|
|
|
PdfUtils.convertPdf(saveWrokTaskPdfPath, xlsxFileName, saveWrokTaskPdfPath, pdfFileName); |
|
|
|
|
String savePath = saveWrokTaskPdfPath + pdfFileName; |
|
|
|
|
// 设置response参数,可以打开下载页面
|
|
|
|
|
PdfUtils.readPdf(response,savePath); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 转换工作任务单预览对象 |
|
|
|
|
* @param id |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private WorkTaskPreviewVO workTaskExport(Long id) { |
|
|
|
|
// 查询工作任务单对象
|
|
|
|
|
WorkTaskEntity workTask = this.getById(id); |
|
|
|
|
if(ObjectUtil.isEmpty(workTask)){ |
|
|
|
|
throw new ServiceException("未查询到工作任务单数据!"); |
|
|
|
|
} |
|
|
|
|
// 对象属性拷贝
|
|
|
|
|
WorkTaskPreviewVO preview = new WorkTaskPreviewVO(); |
|
|
|
|
BeanUtil.copyProperties(preview,workTask); |
|
|
|
|
// 机构名称
|
|
|
|
|
R<Dept> result = sysClient.getDept(workTask.getCreateDept()); |
|
|
|
|
if(result.isSuccess() && ObjectUtil.isNotEmpty(result.getData())){ |
|
|
|
|
preview.setDeptName(result.getData().getDeptName()); |
|
|
|
|
} |
|
|
|
|
// 班组数量
|
|
|
|
|
if(StringUtil.isNotBlank(workTask.getMember())){ |
|
|
|
|
preview.setGroupCount(workTask.getMember().split(",").length); |
|
|
|
|
} |
|
|
|
|
// 工作地点 、工作内容
|
|
|
|
|
if(StringUtil.isNotBlank(workTask.getWorkTask())){ |
|
|
|
|
List<WorkTaskContentVO> contents = JSONObject.parseObject(workTask.getWorkTask(), new TypeReference<List<WorkTaskContentVO>>() {}); |
|
|
|
|
if(CollectionUtil.isNotEmpty(contents)){ |
|
|
|
|
StringBuilder location = new StringBuilder(),content = new StringBuilder(); |
|
|
|
|
for(WorkTaskContentVO item : contents){ |
|
|
|
|
location.append(item.getLocation()).append("\n"); |
|
|
|
|
content.append(item.getContent()).append("\n"); |
|
|
|
|
} |
|
|
|
|
preview.setLocation(location.substring(0,location.toString().length() - 1)); |
|
|
|
|
preview.setContent(content.substring(0,location.toString().length() - 1)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 计划工作时间
|
|
|
|
|
if(ObjectUtil.isNotEmpty(workTask.getPlanStartTime()) && ObjectUtil.isNotEmpty(workTask.getPlanEndTime())){ |
|
|
|
|
Calendar start = Calendar.getInstance(); |
|
|
|
|
start.setTime(workTask.getPlanStartTime()); |
|
|
|
|
StringBuilder planTimeInterval = new StringBuilder(); |
|
|
|
|
|
|
|
|
|
planTimeInterval.append(start.get(Calendar.YEAR)).append("年").append(start.get(Calendar.MONTH)).append("月").append(start.get(Calendar.DAY_OF_MONTH)) |
|
|
|
|
.append("日").append(start.get(Calendar.HOUR_OF_DAY)).append("时").append(start.get(Calendar.MINUTE)).append("分").append("至"); |
|
|
|
|
Calendar end = Calendar.getInstance(); |
|
|
|
|
end.setTime(workTask.getPlanStartTime()); |
|
|
|
|
planTimeInterval.append(end.get(Calendar.YEAR)).append("年").append(end.get(Calendar.MONTH)).append("月").append(end.get(Calendar.DAY_OF_MONTH)) |
|
|
|
|
.append("日").append(end.get(Calendar.HOUR_OF_DAY)).append("时").append(end.get(Calendar.MINUTE)).append("分"); |
|
|
|
|
preview.setPlanTimeInterval(planTimeInterval.toString()); |
|
|
|
|
} |
|
|
|
|
// 工作派工单签发人
|
|
|
|
|
R<User> user = userClient.userInfoById(workTask.getCreateUser()); |
|
|
|
|
if(user.isSuccess() && ObjectUtil.isNotEmpty(user.getData())){ |
|
|
|
|
preview.setCreateName(user.getData().getName()); |
|
|
|
|
} |
|
|
|
|
// 工作派工单签发时间
|
|
|
|
|
if(ObjectUtil.isNotEmpty(workTask.getCreateTime())){ |
|
|
|
|
Calendar createTime = Calendar.getInstance(); |
|
|
|
|
createTime.setTime(workTask.getCreateTime()); |
|
|
|
|
preview.setCreateYear(createTime.get(Calendar.YEAR)); |
|
|
|
|
preview.setCreateMon(createTime.get(Calendar.MONTH)); |
|
|
|
|
preview.setCreateDay(createTime.get(Calendar.DAY_OF_MONTH)); |
|
|
|
|
preview.setCreateHour(createTime.get(Calendar.HOUR_OF_DAY)); |
|
|
|
|
preview.setCreateMin(createTime.get(Calendar.MINUTE)); |
|
|
|
|
} |
|
|
|
|
// 开票处理时间
|
|
|
|
|
if(ObjectUtil.isNotEmpty(workTask.getHeadHandleTime())){ |
|
|
|
|
Calendar headTime = Calendar.getInstance(); |
|
|
|
|
headTime.setTime(workTask.getHeadHandleTime()); |
|
|
|
|
preview.setHeadYear(headTime.get(Calendar.YEAR)); |
|
|
|
|
preview.setHeadMon(headTime.get(Calendar.MONTH)); |
|
|
|
|
preview.setHeadDay(headTime.get(Calendar.DAY_OF_MONTH)); |
|
|
|
|
preview.setHeadHour(headTime.get(Calendar.HOUR_OF_DAY)); |
|
|
|
|
preview.setHeadMin(headTime.get(Calendar.MINUTE)); |
|
|
|
|
} |
|
|
|
|
// 工单结束时间
|
|
|
|
|
if(ObjectUtil.isNotEmpty(workTask.getWorkEndTime())){ |
|
|
|
|
Calendar entTime = Calendar.getInstance(); |
|
|
|
|
entTime.setTime(workTask.getWorkEndTime()); |
|
|
|
|
preview.setEndYear(entTime.get(Calendar.YEAR)); |
|
|
|
|
preview.setEndMon(entTime.get(Calendar.MONTH)); |
|
|
|
|
preview.setEndDay(entTime.get(Calendar.DAY_OF_MONTH)); |
|
|
|
|
preview.setEndHour(entTime.get(Calendar.HOUR_OF_DAY)); |
|
|
|
|
preview.setEndMin(entTime.get(Calendar.MINUTE)); |
|
|
|
|
} |
|
|
|
|
// 许可时间
|
|
|
|
|
if(ObjectUtil.isNotEmpty(workTask.getLicensorTime())){ |
|
|
|
|
Calendar licensorTime = Calendar.getInstance(); |
|
|
|
|
licensorTime.setTime(workTask.getLicensorTime()); |
|
|
|
|
String licensorExportTime = licensorTime.get(Calendar.YEAR) + "年" + licensorTime.get(Calendar.MONTH) + "月" + licensorTime.get(Calendar.DAY_OF_MONTH) + |
|
|
|
|
"日" + licensorTime.get(Calendar.HOUR_OF_DAY) + "时" + licensorTime.get(Calendar.MINUTE) + "分"; |
|
|
|
|
preview.setLicensorExportTime(licensorExportTime); |
|
|
|
|
} |
|
|
|
|
return preview; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 查询工作票数据 |
|
|
|
|
* @param ticketCode |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public List<WorkTicketInfoEntity> workTicketList(String ticketCode) { |
|
|
|
|
QueryWrapper<WorkTicketInfoEntity> queryWrapper = new QueryWrapper(); |
|
|
|
|
queryWrapper.lambda().orderByDesc(WorkTicketInfoEntity::getCreateTime); |
|
|
|
|
if(StringUtil.isEmpty(ticketCode)){ |
|
|
|
|
return workTicketInfoService.list(queryWrapper); |
|
|
|
|
} |
|
|
|
|
queryWrapper.lambda().like(WorkTicketInfoEntity::getCode,ticketCode); |
|
|
|
|
return workTicketInfoService.list(queryWrapper); |
|
|
|
|
} |
|
|
|
|
} |