|
|
|
@ -8,7 +8,6 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import com.google.common.collect.Lists; |
|
|
|
|
import com.hnac.hzims.message.entity.config.PushConfigEntity; |
|
|
|
|
import com.hnac.hzims.message.fegin.IMessageConfigClient; |
|
|
|
|
import com.hnac.hzims.operational.access.dto.OperAccessTaskDTO; |
|
|
|
@ -22,9 +21,12 @@ import com.hnac.hzims.ticket.allTicket.service.TicketInfoEvaluateService;
|
|
|
|
|
import com.hnac.hzims.ticket.allTicket.vo.TicketInfoStatisticVO; |
|
|
|
|
import com.hnac.hzims.ticket.constants.TicketConstants; |
|
|
|
|
import com.hnac.hzims.ticket.constants.WorkTicketConstants; |
|
|
|
|
import com.hnac.hzims.ticket.twoTicket.entity.WorkTicketFinish; |
|
|
|
|
import com.hnac.hzims.ticket.twoTicket.service.IFirstWorkTicketService; |
|
|
|
|
import com.hnac.hzims.ticket.twoTicket.service.IWorkTicketFinishService; |
|
|
|
|
import com.hnac.hzims.ticket.utils.AsposeUtil; |
|
|
|
|
import com.hnac.hzims.ticket.utils.ExcelUtil; |
|
|
|
|
import com.hnac.hzims.ticket.utils.ObjectUtils; |
|
|
|
|
import com.hnac.hzims.ticket.utils.PdfUtils; |
|
|
|
|
import com.hnac.hzims.ticket.workTicket.dto.*; |
|
|
|
|
import com.hnac.hzims.ticket.workTicket.entity.*; |
|
|
|
@ -59,13 +61,13 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.io.FileNotFoundException; |
|
|
|
|
import java.io.FileOutputStream; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
import java.util.stream.IntStream; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @author hx |
|
|
|
@ -90,6 +92,7 @@ public class FirstWorkTicketServiceImpl extends BaseServiceImpl<WorkTicketInfoMa
|
|
|
|
|
private final IWorkTicketInfoService ticketInfoService; |
|
|
|
|
private final TicketInfoEvaluateService evaluateService; |
|
|
|
|
private final IWorkTicketContentService contentService; |
|
|
|
|
private final IWorkTicketFinishService workTicketFinishService; |
|
|
|
|
|
|
|
|
|
/**工作票流程修改后的key**/ |
|
|
|
|
@Value("${hzims.ticket.first-work-flow-key-new}") |
|
|
|
@ -276,72 +279,114 @@ public class FirstWorkTicketServiceImpl extends BaseServiceImpl<WorkTicketInfoMa
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void preview(HttpServletResponse response,Long ticketId) { |
|
|
|
|
Map measure = new HashMap(3) {{ |
|
|
|
|
put("index",1); |
|
|
|
|
put("safetyMeasure","暗室逢灯你根本就发给你开始的那数据打你电话"); |
|
|
|
|
put("status","√"); |
|
|
|
|
}}; |
|
|
|
|
Map<String,Object> params = new HashMap(){{ |
|
|
|
|
put("projectName","海南三亚一级站"); |
|
|
|
|
put("code","GY-D2-2311--004"); |
|
|
|
|
put("principalName","杨汪洋"); |
|
|
|
|
put("classGroupName","白班"); |
|
|
|
|
put("classGroupMembersName","吴先强,唐钰,彭晨洋,黄兴,肖璐"); |
|
|
|
|
put("totalPerson","5"); |
|
|
|
|
put("addressEquName","#1变压器出线-三洪奇"); |
|
|
|
|
put("workContent","#29电池舱第四簇高压箱"); |
|
|
|
|
put("ps_year","2023"); |
|
|
|
|
put("ps_month","11"); |
|
|
|
|
put("ps_day","11"); |
|
|
|
|
put("ps_hour","16"); |
|
|
|
|
put("ps_minuter","45"); |
|
|
|
|
put("pe_year","2023"); |
|
|
|
|
put("pe_month","11"); |
|
|
|
|
put("pe_day","12"); |
|
|
|
|
put("pe_hour","11"); |
|
|
|
|
put("pe_minuter","13"); |
|
|
|
|
put("matterLibraryListOne", Lists.newArrayList(measure,measure,measure,measure,measure,measure,measure,measure)); |
|
|
|
|
put("signerName","杨汪洋"); |
|
|
|
|
put("s_year","2023"); |
|
|
|
|
put("s_month","11"); |
|
|
|
|
put("s_day","12"); |
|
|
|
|
put("s_hour","11"); |
|
|
|
|
put("s_minuter","13"); |
|
|
|
|
put("jobReceiver","杨汪洋"); |
|
|
|
|
put("r_year","2023"); |
|
|
|
|
put("r_month","11"); |
|
|
|
|
put("r_day","12"); |
|
|
|
|
put("r_hour","11"); |
|
|
|
|
put("r_minuter","13"); |
|
|
|
|
put("l_year","2023"); |
|
|
|
|
put("l_month","11"); |
|
|
|
|
put("l_day","12"); |
|
|
|
|
put("l_hour","11"); |
|
|
|
|
put("l_minuter","13"); |
|
|
|
|
put("licensorName","杨汪洋"); |
|
|
|
|
put("principalName1","杨汪洋"); |
|
|
|
|
put("groundNum","11"); |
|
|
|
|
put("dismantleNum","12"); |
|
|
|
|
put("retainNum","8"); |
|
|
|
|
put("brakeNumber","A7758258"); |
|
|
|
|
put("licensorName2","A7758258"); |
|
|
|
|
put("isSafety ","☑"); |
|
|
|
|
put("isHazard","☑"); |
|
|
|
|
put("isRailway","☑"); |
|
|
|
|
put("isLimited","☑"); |
|
|
|
|
}}; |
|
|
|
|
WorkTicketInfoEntity workTicketInfoEntity = this.getById(ticketId); |
|
|
|
|
Map params = this.getTicketParamById(ticketId,workTicketInfoEntity); |
|
|
|
|
String tempFileName = WorkTicketConstants.TicketSignageEnum.getTempFileNameByType(workTicketInfoEntity.getType()); |
|
|
|
|
Assert.isTrue(StringUtil.isNotBlank(tempFileName),() -> { |
|
|
|
|
throw new ServiceException("未找到模板文件,预览失败!"); |
|
|
|
|
}); |
|
|
|
|
String wordPath = this.getFileSavePath() + params.get("code") + "_" + params.get("addressEquName") +".docx"; |
|
|
|
|
this.exportTicketWord("template/"+tempFileName, wordPath, params); |
|
|
|
|
String pdfPath = this.getFileSavePath() + params.get("code") + "_" + params.get("addressEquName") +".pdf"; |
|
|
|
|
AsposeUtil.wordToPdf(wordPath,pdfPath); |
|
|
|
|
PdfUtils.readPdf(response,pdfPath); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private String getFileSavePath() { |
|
|
|
|
String os = System.getProperty("os.name").toLowerCase(); |
|
|
|
|
if("linux".equals(os)) { |
|
|
|
|
return pdfSavePath; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
return "E://template/"; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Map<String,Object> getTicketParamById(Long ticketId,WorkTicketInfoEntity workTicketInfoEntity) { |
|
|
|
|
Map params = ObjectUtils.obj2Map(workTicketInfoEntity); |
|
|
|
|
params.put("signerName",Optional.ofNullable(workTicketInfoEntity.getSigner()).map(UserCache::getUser).map(User::getName).orElse(null)); |
|
|
|
|
// 获取两票安措
|
|
|
|
|
List<WorkTicketSafetyMeasureEntity> measures = workTicketSafetyMeasureService.selectByTicketId(ticketId); |
|
|
|
|
if(CollectionUtil.isNotEmpty(measures)) { |
|
|
|
|
Map<String, List<Map>> measureMap = measures.stream().map(ObjectUtils::obj2Map).peek(m -> m.put("status", TicketConstants.SafetyMeasureStatusEnum.FINISH.getStatus().equals(m.get("status")) ? "√" : null)).collect(Collectors.groupingBy(m -> (String) m.get("type"))); |
|
|
|
|
Arrays.stream(WorkTicketConstants.WorkTicketMeasureTypeEnum.class.getEnumConstants()).forEach(e -> { |
|
|
|
|
if(ObjectUtil.isNotEmpty(measureMap.get(e.getType()))) { |
|
|
|
|
List<Map> list = measureMap.get(e.getType()); |
|
|
|
|
List<HashMap<String, Object>> measureList = IntStream.iterate(0, index -> index + 1).limit(list.size()> 4 ? list.size() : 4).mapToObj(index -> { |
|
|
|
|
if(list.size() != 0 && list.size() >= index + 1) { |
|
|
|
|
HashMap<String, Object> map = new HashMap<String, Object>() {{ |
|
|
|
|
putAll(list.get(index)); |
|
|
|
|
put("index", index + 1); |
|
|
|
|
}}; |
|
|
|
|
return map; |
|
|
|
|
} |
|
|
|
|
return new HashMap<String,Object>(); |
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
params.put(e.getConvertAttributes(),measureList); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
params.put(e.getConvertAttributes(),IntStream.iterate(0, index -> index + 1).limit(4).mapToObj(index -> new HashMap<String,Object>()).collect(Collectors.toList())); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
List<Map> addressList = measureMap.get(WorkTicketConstants.WorkTicketMeasureTypeEnum.Five.getType()); |
|
|
|
|
List<Map> fillList = measureMap.get(WorkTicketConstants.WorkTicketMeasureTypeEnum.Flow.getType()); |
|
|
|
|
List<Map<String, Object>> measureList = IntStream.iterate(0, index -> index + 1).limit(4).mapToObj(index -> { |
|
|
|
|
Map<String,Object> result = new HashMap(); |
|
|
|
|
if(CollectionUtil.isNotEmpty(addressList) && addressList.size() >= index + 1) { |
|
|
|
|
result.put("safetyMeasure",addressList.get(index).get("measure")); |
|
|
|
|
} |
|
|
|
|
if(CollectionUtil.isNotEmpty(fillList) && fillList.size() >= index + 1) { |
|
|
|
|
result.put("safetyMeasure1",fillList.get(index).get("measure")); |
|
|
|
|
} |
|
|
|
|
return result; |
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
params.put("matterLibraryList",measureList); |
|
|
|
|
} |
|
|
|
|
params.put("isSafety",workTicketInfoEntity.getIsSafety() ? "☑" : "□"); |
|
|
|
|
params.put("isHazard",workTicketInfoEntity.getIsHazard() ? "☑" : "□"); |
|
|
|
|
params.put("isRailway",workTicketInfoEntity.getIsRailway() ? "☑" : "□"); |
|
|
|
|
params.put("isLimited",workTicketInfoEntity.getIsLimited() ? "☑" : "□"); |
|
|
|
|
params.put("isStart",workTicketInfoEntity.getIsStart() ? "☑" : "□"); |
|
|
|
|
// 许可人许可环节
|
|
|
|
|
if(ObjectUtil.isNotEmpty(workTicketInfoEntity.getLicenseTime())) { |
|
|
|
|
params.put("licensorName",Optional.ofNullable(workTicketInfoEntity.getLicensor()).map(UserCache::getUser).map(User::getName).orElse(null)); |
|
|
|
|
params.put("principalName1",params.get("principalName")); |
|
|
|
|
} |
|
|
|
|
WorkTicketFinish finish = workTicketFinishService.selectByTicketId(ticketId); |
|
|
|
|
if(ObjectUtil.isNotEmpty(finish)) { |
|
|
|
|
if(Func.isNotEmpty(finish.getWorkEndTime())) { |
|
|
|
|
params.put("principalName3",params.get("principalName")); |
|
|
|
|
params.put("licensorName1",params.get("licensorName")); |
|
|
|
|
params.putAll(ObjectUtils.LocalDateConvertMap(finish.getWorkEndTime(),"f","_")); |
|
|
|
|
} |
|
|
|
|
if(Func.isNotEmpty(finish.getLicensorEndTime())) { |
|
|
|
|
params.put("licensorName2",params.get("licensorName")); |
|
|
|
|
params.put("groundNum",finish.getGroundNum()); |
|
|
|
|
params.put("dismantleNum",finish.getDismantleNum()); |
|
|
|
|
params.put("retainNum",finish.getRetainNum()); |
|
|
|
|
params.put("brakeNumber",finish.getBrakeNumber()); |
|
|
|
|
params.put("tellContent",finish.getTellContent()); |
|
|
|
|
params.putAll(ObjectUtils.LocalDateConvertMap(finish.getLicensorEndTime(),"e","_")); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return params; |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* word模板填充内容并将结果导出 |
|
|
|
|
* @param templatePath 模板路径 |
|
|
|
|
* @param savePath 结果导出路径 |
|
|
|
|
* @param params 填充对象 |
|
|
|
|
*/ |
|
|
|
|
private void exportTicketWord(String templatePath, String savePath, Map params) { |
|
|
|
|
XWPFDocument xwpfDocument = null; |
|
|
|
|
try { |
|
|
|
|
xwpfDocument = WordExportUtil.exportWord07("template/电气第一种工作票模版新.docx", params); |
|
|
|
|
xwpfDocument = WordExportUtil.exportWord07(templatePath, params); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
String wordPath = "E://template/" + params.get("code") + "_" + params.get("addressEquName") +".docx"; |
|
|
|
|
String pdfPath = "E://template/" + params.get("code") + "_" + params.get("addressEquName") +".pdf"; |
|
|
|
|
// String pdfPath = pdfSavePath + "/" + params.get("code") + "_" + params.get("addressEquName") +".pdf";
|
|
|
|
|
FileOutputStream outputStream = null; |
|
|
|
|
try { |
|
|
|
|
outputStream = new FileOutputStream(wordPath); |
|
|
|
|
outputStream = new FileOutputStream(savePath); |
|
|
|
|
} catch (FileNotFoundException e) { |
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
} |
|
|
|
@ -358,8 +403,6 @@ public class FirstWorkTicketServiceImpl extends BaseServiceImpl<WorkTicketInfoMa
|
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
AsposeUtil.wordToPdf(wordPath,pdfPath); |
|
|
|
|
PdfUtils.readPdf(response,pdfPath); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|