| | |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-freemarker</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.docx4j</groupId> |
| | | <artifactId>docx4j-core</artifactId> |
| | | <version>8.3.10</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.docx4j</groupId> |
| | | <artifactId>docx4j-JAXB-Internal</artifactId> |
| | | <version>8.3.10</version> |
| | | <exclusions> |
| | | <exclusion> |
| | | <groupId>javax.xml.bind</groupId> |
| | | <artifactId>jaxb-api</artifactId> |
| | | </exclusion> |
| | | </exclusions> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.docx4j</groupId> |
| | | <artifactId>docx4j-JAXB-ReferenceImpl</artifactId> |
| | | <version>8.3.10</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.glassfish.jaxb</groupId> |
| | | <artifactId>jaxb-runtime</artifactId> |
| | | <version>2.3.1</version> |
| | | </dependency> |
| | | <!-- Apache POI ç¨äºå¤çdocxæä»¶ --> |
| | | <!--<dependency> |
| | | <groupId>org.apache.poi</groupId> |
| | | <artifactId>poi-ooxml</artifactId> |
| | | </dependency>--> |
| | | |
| | | <!-- å
å«OpenXMLæ ¼å¼ç宿´ schema å®ä¹ --> |
| | | <!--<dependency> |
| | | <groupId>org.apache.poi</groupId> |
| | | <artifactId>poi-ooxml-full</artifactId> |
| | | <version>5.4.0</version> |
| | | </dependency>--> |
| | | </dependencies> |
| | | <build> |
| | | <plugins> |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | |
| | | package org.springblade.mdm.commons.service; |
| | | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.mdm.flow.constants.FlowContants; |
| | | import org.springblade.system.feign.ISysClient; |
| | | import org.springblade.system.feign.IUserClient; |
| | | import org.springblade.system.pojo.entity.User; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * ç³»ç»åæ°è·åæå¡ |
| | | * |
| | | * @author yangys |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class UserCommonService { |
| | | @Autowired |
| | | private IUserClient userClient; |
| | | /** |
| | | * è·åç¨æ·å§å |
| | | * @return |
| | | */ |
| | | public String getUserNameById(Long programmerId){ |
| | | R<User> programmerResult = userClient.userInfoById(programmerId); |
| | | if(programmerResult.isSuccess()) { |
| | | return programmerResult.getData().getName(); |
| | | }else{ |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | |
| | | private FlowCommonService flowCommonService; |
| | | @Autowired |
| | | private HistoryService historyService; |
| | | @Autowired |
| | | private ApproveTableService approveTableService; |
| | | |
| | | @Autowired |
| | | private ProgramConfirmTableService programConfirmTableService; |
| | | @Autowired |
| | |
| | | return R.success(); |
| | | } |
| | | |
| | | @PostMapping("/export-approve-table") |
| | | @Operation(summary = "导åºå®¡æ¹è¡¨", description = "导åºå®¡æ¹è¡¨pdf") |
| | | public void exportApproveTable(String processInstanceId, HttpServletResponse response) { |
| | | |
| | | try { |
| | | FlowProgramProperties props = flowCommonService.getProgramPropertiesFromHis(processInstanceId); |
| | | String progName = props.getDrawingNo()+"-"+props.getProcessNo()+"-"+props.getProcessEdition(); |
| | | //String filename = URLEncoder.encode("æ°æ§ç¨åºç¼å¶å®¡æ¹å", StandardCharsets.UTF_8)+ DateUtil.format(DateUtil.now(), "yyyyMMddHHmm")+".pdf"; |
| | | String filename = UrlUtil.encode("æ°æ§ç¨åºç¼å¶å®¡æ¹å"+progName)+".pdf"; |
| | | response.setHeader("Content-Disposition", "attachment; filename="+filename); |
| | | response.setContentType("application/octet-stream"); |
| | | approveTableService.exportApproveTable(processInstanceId,response.getOutputStream()); |
| | | } catch (Exception e) { |
| | | log.error("导åºå®¡æ¹è¡¨å¼å¸¸", e); |
| | | throw new RuntimeException(e); |
| | | } |
| | | |
| | | } |
| | | |
| | | @PostMapping("/export-confirm-table") |
| | | @Operation(summary = "导åºç¡®è®¤è¡¨", description = "å¯¼åºæ°æ§ç¨åºç¡®è®¤è¡¨pdf") |
| | |
| | | * éè¯¯ä¿¡æ¯ |
| | | */ |
| | | private String errMsg; |
| | | |
| | | /** |
| | | * ç¨åºç¼å· |
| | | */ |
| | | private String programNo; |
| | | } |
| | |
| | | ncNodeService.updateById(curedProgramPackage); |
| | | } |
| | | |
| | | |
| | | return inst.getProcessInstanceId(); |
| | | } |
| | | |
| | |
| | | import org.springblade.mdm.basesetting.machine.entity.Machine; |
| | | import org.springblade.mdm.basesetting.producedivision.entity.ProduceDivision; |
| | | import org.springblade.mdm.basesetting.producedivision.service.ProduceDivisionService; |
| | | import org.springblade.mdm.commons.service.UserCommonService; |
| | | import org.springblade.mdm.flow.constants.FlowContants; |
| | | import org.springblade.mdm.flow.constants.FlowVariableContants; |
| | | import org.springblade.mdm.program.entity.NcNode; |
| | |
| | | private final ProduceDivisionService produceDivisionService; |
| | | private final NodeDeptQueryService nodeDeptQueryService; |
| | | private final MachineService machineService; |
| | | private final IUserClient userClient; |
| | | private final UserCommonService userCommonService; |
| | | /** |
| | | * æ ¹æ®æµç¨å®ä¾idè·ådefinitionKey |
| | | * @param processInstanceId |
| | |
| | | vars.put(FlowContants.ASSIGNEE, defaultAssignee);//第ä¸ä¸ªå®¡æ¹ç¨æ·ï¼ç»é¿ |
| | | } |
| | | |
| | | R<User> programmerResult = userClient.userInfoById(div.getProgrammerId()); |
| | | if(programmerResult.isSuccess()) { |
| | | vars.put(FlowContants.PROGRAMMER_NAME, programmerResult.getData().getName()); |
| | | } |
| | | vars.put(FlowContants.PROGRAMMER_NAME, userCommonService.getUserNameById(div.getProgrammerId())); |
| | | return div; |
| | | } |
| | | |
| | |
| | | |
| | | //é¶ç»ä»¶åç§° |
| | | data.put("drawingName",getDrawingName(props.getDrawingNo())); |
| | | data.put("deviation",props.getDeviation()); |
| | | data.put("deviation",props.getDeviation()!=null?props.getDeviation():StringUtils.EMPTY); |
| | | |
| | | |
| | | |
| | |
| | | data.put("fuheY","Y");//TODO æ æ£éªå å符å |
| | | data.put("keyongY","Y");//TODO æ æ£éªå å符å |
| | | |
| | | data.put("jly","æ¥æºMES/2025-1-1"); |
| | | data.put("jln","æ¥æºMES/2025-1-1"); |
| | | ApproveTableInfo approveInfo = approveInfoQueryService.getApproveInfo(props); |
| | | data.put("programmerName",approveInfo.getProgrammerName()); |
| | | data.put("checkerName",approveInfo.getCheckerName()); |
| | |
| | | import org.flowable.engine.RuntimeService; |
| | | import org.flowable.engine.TaskService; |
| | | import org.flowable.task.api.Task; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.mdm.flow.constants.FlowContants; |
| | | import org.springblade.mdm.flow.service.ApproveRecordService; |
| | | import org.springblade.system.feign.IUserClient; |
| | | import org.springblade.system.pojo.entity.User; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | protected RuntimeService runtimeService; |
| | | @Autowired |
| | | protected ApproveRecordService approveRecordService; |
| | | |
| | | @Transactional |
| | | public abstract void completeTask(String taskId, String processInstanceId, String comment, @Parameter(name = "variables", description = "æµç¨åé") @RequestBody Map<String, Object> variables); |
| | | |
| | |
| | | String operateResult = variables.get("approve")+""; |
| | | approveRecordService.saveApproveRecords(currentTask(taskId),operateResult,comment); |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | import org.flowable.task.api.Task; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.core.tool.support.Kv; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | | import org.springblade.mdm.commons.service.UserCommonService; |
| | | import org.springblade.mdm.flow.constants.FlowContants; |
| | | import org.springblade.mdm.flow.constants.FlowVariableContants; |
| | | import org.springblade.mdm.flow.service.ApproveRecordService; |
| | |
| | | private RuntimeService runtimeService; |
| | | @Autowired |
| | | private FlowCommonService flowCommonService; |
| | | @Autowired |
| | | private UserCommonService userCommonService; |
| | | @Transactional |
| | | public void batchDispatchTask(BatchDispatchVO batchDispatchVO) { |
| | | //String[] taskIds, String[] processInstanceIds, String comment, String assignee |
| | |
| | | taskId = taskIds[i]; |
| | | processInstanceId = batchDispatchVO.getProcessInstanceIds()[i]; |
| | | |
| | | runtimeService.setVariable(processInstanceId,FlowContants.PROGRAMMER_NAME,userCommonService.getUserNameById(Func.toLong(batchDispatchVO.getAssignee()))); |
| | | |
| | | Task task = getTask(taskId); |
| | | |
| | | if(!task.getTaskDefinitionKey().equals("teamLeaderTask")){ |
| | | throw new ServiceException("é[ä»»å¡åæ´¾]èç¹çä»»å¡ä¸è½æ¹é派工"); |
| | | } |
| | | if (StringUtil.isNoneBlank(processInstanceId, comment)) { |
| | | taskService.addComment(taskId, processInstanceId, comment); |
| | | } |
| | |
| | | taskId = taskIds[i]; |
| | | processInstanceId = batchDispatchVO.getProcessInstanceIds()[i]; |
| | | |
| | | variables.put("assignee", getAutoProgrammer(processInstanceId)); |
| | | |
| | | Task task = getTask(taskId); |
| | | if(!task.getTaskDefinitionKey().equals("teamLeaderTask")){ |
| | | throw new ServiceException("é[ä»»å¡åæ´¾]èç¹çä»»å¡ä¸è½æ¹é派工"); |
| | | } |
| | | |
| | | Object programmerId = getAutoProgrammer(processInstanceId); |
| | | variables.put("assignee", programmerId); |
| | | |
| | | runtimeService.setVariable(processInstanceId,FlowContants.PROGRAMMER_NAME,userCommonService.getUserNameById(Func.toLong(programmerId))); |
| | | |
| | | |
| | | if (StringUtil.isNoneBlank(processInstanceId, batchDispatchVO.getComment())) { |
| | | taskService.addComment(taskId, processInstanceId, batchDispatchVO.getComment()); |
| | |
| | | import org.flowable.task.api.Task; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.support.Kv; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | | import org.springblade.mdm.basesetting.machine.entity.Machine; |
| | | import org.springblade.mdm.basesetting.machine.service.MachineService; |
| | | import org.springblade.mdm.commons.service.ParamService; |
| | | import org.springblade.mdm.commons.service.UserCommonService; |
| | | import org.springblade.mdm.flow.constants.FlowContants; |
| | | import org.springblade.mdm.flow.constants.FlowVariableContants; |
| | | import org.springblade.mdm.flow.service.FlowCommonService; |
| | | import org.springblade.mdm.flow.service.FlowProgramFileService; |
| | | import org.springblade.mdm.flow.service.FlowProgramProperties; |
| | | import org.springblade.system.feign.IUserClient; |
| | | import org.springblade.system.pojo.entity.User; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | @Autowired |
| | | private FlowCommonService flowCommonService; |
| | | @Autowired |
| | | private UserCommonService userCommonService; |
| | | @Autowired |
| | | private MachineService machineService; |
| | | |
| | | @Transactional |
| | |
| | | throw new ServiceException("请æå®æµç¨ä¸ä¸æ¥å¤ç人"); |
| | | } |
| | | |
| | | // éç©ºå¤æ |
| | | if (Func.isEmpty(variables)) { |
| | | variables = Kv.create(); |
| | | } |
| | | |
| | | if(task.getTaskDefinitionKey().equals("programmingTask") ) {//ç¼å¶èç¹ |
| | | //è®°å½å®é
ç¼ç¨å |
| | | variables.put(FlowVariableContants.ACT_PROGRAMMER,Func.toStr(AuthUtil.getUserId())); |
| | |
| | | if(this.needUploadProgramFile(props.getMachineCode())) { |
| | | flowProgramFileService.checkProgramFiles(processInstanceId, FlowContants.Y.equals(operateResult)); |
| | | } |
| | | }else if(task.getTaskDefinitionKey().equals("teamLeaderTask")){ |
| | | if(FlowContants.Y.equals(operateResult)) { |
| | | runtimeService.setVariable(task.getExecutionId(),FlowContants.PROGRAMMER_NAME,userCommonService.getUserNameById(Func.toLong(variables.get("assignee")))); |
| | | } |
| | | |
| | | } |
| | | if (StringUtil.isNoneBlank(processInstanceId, comment)) { |
| | | taskService.addComment(taskId, processInstanceId, comment); |
| | | } |
| | | // éç©ºå¤æ |
| | | if (Func.isEmpty(variables)) { |
| | | variables = Kv.create(); |
| | | } |
| | | |
| | | variables.put(FlowContants.LAST_STEP_USER_NICKNAME, AuthUtil.getNickName()); |
| | | |
| | | |
| | |
| | | variables.remove(FlowContants.PROCESS_EDITION);//ä¸è¦åçäº |
| | | |
| | | if("confirmIsUseableTask".equals(task.getTaskDefinitionKey())){ |
| | | |
| | | variables.put(FlowContants.CURE_PROGRAM_USEABLE,operateResult); |
| | | |
| | | } |
| | | taskService.complete(taskId, variables); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * æ¯å¦éè¦ä¸ä¼ æä»¶ï¼è½¦åºä¸éè¦ï¼ |
| | | * @param machineCode æºåºç¼ç |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.springblade.mdm.statreport.controller; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.poi.ss.usermodel.DateUtil; |
| | | import org.flowable.engine.RuntimeService; |
| | | import org.flowable.engine.TaskService; |
| | | import org.springblade.core.mp.support.Condition; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.core.tool.utils.UrlUtil; |
| | | import org.springblade.mdm.flow.entity.TaskDispatch; |
| | | import org.springblade.mdm.flow.excution.StartDispatcher; |
| | | import org.springblade.mdm.flow.service.FlowCommonService; |
| | | import org.springblade.mdm.flow.service.FlowProgramFileService; |
| | | import org.springblade.mdm.flow.service.FlowProgramProperties; |
| | | import org.springblade.mdm.flow.service.TaskDispatchService; |
| | | import org.springblade.mdm.flow.service.execute.DefaultFlowCompleteService; |
| | | import org.springblade.mdm.flow.service.execute.TryFlowCompleteService; |
| | | import org.springblade.mdm.flow.vo.DispathTaskQueryVO; |
| | | import org.springblade.mdm.flow.vo.TaskAssignVO; |
| | | import org.springblade.mdm.statreport.service.ApproveTableService; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody; |
| | | |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.time.LocalDateTime; |
| | | |
| | | @Slf4j |
| | | @RestController |
| | | @AllArgsConstructor |
| | | @RequestMapping("/statreport/tableprint") |
| | | @Tag(name = "è¡¨æ ¼æå°", description = "è¡¨æ ¼æå°") |
| | | public class ApproveTablePrintController { |
| | | |
| | | @Autowired |
| | | private FlowCommonService flowCommonService; |
| | | @Autowired |
| | | private ApproveTableService approveTableService; |
| | | private final TaskDispatchService taskDispatchService; |
| | | @Operation(summary = "ä»»å¡å®¡æ¹è¡¨", description = "ä»»å¡å®¡æ¹è¡¨") |
| | | @GetMapping("/dispatch-page") |
| | | public R<IPage<TaskDispatch>> dispatchPatch(DispathTaskQueryVO queryVO) { |
| | | LocalDateTime end = null; |
| | | if(queryVO.getCreateTimeEnd()!=null){ |
| | | end = DateUtil.toLocalDateTime(queryVO.getCreateTimeEnd()).plusDays(1); |
| | | } |
| | | return R.data(taskDispatchService.lambdaQuery() |
| | | .like(StringUtils.isNotBlank(queryVO.getDrawingNo()), TaskDispatch::getDrawingNo,queryVO.getDrawingNo()) |
| | | .eq(TaskDispatch::getStatus,TaskDispatch.STATUS_STARTED) |
| | | .ge(queryVO.getCreateTimeBegin()!=null, TaskDispatch::getCreateTime,queryVO.getCreateTimeBegin()) |
| | | .le(queryVO.getCreateTimeEnd()!=null, TaskDispatch::getCreateTime,end).orderByDesc(TaskDispatch::getCreateTime) |
| | | .page(Condition.getPage(queryVO))); |
| | | } |
| | | |
| | | @PostMapping("/export-approve-table") |
| | | @Operation(summary = "导åºå®¡æ¹è¡¨", description = "导åºå®¡æ¹è¡¨pdf") |
| | | public void exportApproveTable(String id,HttpServletResponse response) throws IOException { |
| | | |
| | | TaskDispatch dispatch = taskDispatchService.getById(id); |
| | | FlowProgramProperties props = flowCommonService.getProgramPropertiesFromHis(dispatch.getProcessInstanceId()); |
| | | |
| | | String progName = props.getDrawingNo()+"-"+props.getProcessNo()+"-"+props.getProcessEdition(); |
| | | |
| | | String filename = UrlUtil.encode("æ°æ§ç¨åºç¼å¶å®¡æ¹å"+progName)+".docx"; |
| | | |
| | | |
| | | ByteArrayOutputStream outputStream = approveTableService.exportApproveTableDoc(dispatch,props); |
| | | |
| | | byte[] fileBytes = outputStream.toByteArray(); |
| | | |
| | | response.setHeader("Content-Disposition", "attachment; filename="+filename); |
| | | response.setContentType("application/octet-stream"); |
| | | response.getOutputStream().write(fileBytes); |
| | | |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.springblade.mdm.statreport.controller; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.Parameter; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.poi.ss.usermodel.DateUtil; |
| | | import org.flowable.engine.HistoryService; |
| | | import org.flowable.engine.RuntimeService; |
| | | import org.flowable.engine.history.HistoricProcessInstance; |
| | | import org.springblade.core.mp.support.Condition; |
| | | import org.springblade.core.mp.support.Query; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.utils.UrlUtil; |
| | | import org.springblade.mdm.flow.entity.TaskDispatch; |
| | | import org.springblade.mdm.flow.service.FlowCommonService; |
| | | import org.springblade.mdm.flow.service.FlowProgramProperties; |
| | | import org.springblade.mdm.flow.service.TaskDispatchService; |
| | | import org.springblade.mdm.flow.vo.DispathTaskQueryVO; |
| | | import org.springblade.mdm.flow.vo.FlowVO; |
| | | import org.springblade.mdm.statreport.service.ApproveTableService; |
| | | import org.springblade.mdm.statreport.service.ConfirmTablePrintService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.IOException; |
| | | import java.time.LocalDateTime; |
| | | |
| | | @Slf4j |
| | | @RestController |
| | | @AllArgsConstructor |
| | | @RequestMapping("/statreport/tableprint") |
| | | @Tag(name = "è¡¨æ ¼æå°", description = "è¡¨æ ¼æå°") |
| | | public class ConfirmTablePrintController { |
| | | |
| | | private FlowCommonService flowCommonService; |
| | | private ConfirmTablePrintService confirmTablePrintService; |
| | | private final TaskDispatchService taskDispatchService; |
| | | private final HistoryService hisService; |
| | | |
| | | @GetMapping("/confirm-page") |
| | | @ApiOperationSupport(order = 3) |
| | | @Operation(summary = "确认åå表", description = "确认åå表") |
| | | public R<IPage<FlowVO>> finishedList(@Parameter(description = "æµç¨åç§°")String myProcessName, @Parameter(description = "æµç¨å建æ¶é´å¼å§") LocalDateTime createTimeBegin, @Parameter(description = "æµç¨å建æ¶é´æªæ¢") LocalDateTime createTimeEnd, @Parameter(description = "å
³é®å") String keyword, Query query) { |
| | | IPage<FlowVO> pages = confirmTablePrintService.confirmTablePage(Condition.getPage(query), myProcessName,keyword,createTimeBegin,createTimeEnd); |
| | | return R.data(pages); |
| | | } |
| | | |
| | | |
| | | @PostMapping("/export-confirm-table") |
| | | @Operation(summary = "å¯¼åºæ°æ§ç¨åºç¡®è®¤è¡¨", description = "æ°æ§ç¨åºç¡®è®¤è¡¨") |
| | | public void exportConfirmTable(String processInstanceId,HttpServletResponse response) throws IOException { |
| | | |
| | | HistoricProcessInstance his = hisService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); |
| | | String taskDispatchId = his.getBusinessKey(); |
| | | TaskDispatch dispatch = taskDispatchService.getById(taskDispatchId); |
| | | FlowProgramProperties props = flowCommonService.getProgramPropertiesFromHis(processInstanceId); |
| | | |
| | | String progName = props.getDrawingNo()+"-"+props.getProcessNo()+"-"+props.getProcessEdition(); |
| | | |
| | | String filename = UrlUtil.encode("æ°æ§ç¨åºç¡®è®¤è¡¨"+progName)+".docx"; |
| | | |
| | | ByteArrayOutputStream outputStream = confirmTablePrintService.exportConfirmTableDoc(dispatch,props); |
| | | |
| | | byte[] fileBytes = outputStream.toByteArray(); |
| | | |
| | | response.setHeader("Content-Disposition", "attachment; filename="+filename); |
| | | response.setContentType("application/octet-stream"); |
| | | response.getOutputStream().write(fileBytes); |
| | | |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | |
| | | package org.springblade.mdm.statreport.service; |
| | | |
| | | import com.itextpdf.text.DocumentException; |
| | | import freemarker.template.Template; |
| | | import freemarker.template.TemplateException; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springblade.core.oss.OssTemplate; |
| | | import org.springblade.core.tool.utils.DateUtil; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.mdm.basesetting.machine.entity.Machine; |
| | | import org.springblade.mdm.basesetting.machine.service.MachineService; |
| | | import org.springblade.mdm.commons.service.ParamService; |
| | | import org.springblade.mdm.commons.support.TemplatedPdfWriter; |
| | | import org.springblade.mdm.flow.constants.FlowContants; |
| | | import org.springblade.mdm.flow.entity.TaskDispatch; |
| | | import org.springblade.mdm.flow.service.ApproveInfoQueryService; |
| | | import org.springblade.mdm.flow.service.FlowCommonService; |
| | | import org.springblade.mdm.flow.service.FlowProgramProperties; |
| | | import org.springblade.mdm.flow.service.TaskDispatchService; |
| | | import org.springblade.mdm.flow.vo.ApproveTableInfo; |
| | | import org.springblade.mdm.program.service.NcNodeService; |
| | | import org.springblade.mdm.statreport.utils.WordReplaceUtil; |
| | | import org.springblade.system.feign.IUserClient; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; |
| | | |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.OutputStream; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 审æ¹è®°å½ï¼ç¨äºæ¥è¯¢æ§è¡è½¨è¿¹ |
| | | * |
| | | * @author yangys |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class ApproveTableService { |
| | | @Autowired |
| | | private NcNodeService ncNodeService; |
| | | @Autowired |
| | | private MachineService machineService; |
| | | @Autowired |
| | | private IUserClient useClient; |
| | | @Autowired |
| | | private OssTemplate ossTemplate; |
| | | |
| | | @Autowired |
| | | private ApproveInfoQueryService approveInfoQueryService; |
| | | |
| | | @Autowired |
| | | private ParamService paramService; |
| | | /** |
| | | * 导åºwordå²¸æ¬ |
| | | * @param dispatch ä»»å¡åæ´¾ |
| | | * @param props æµç¨å±æ§ |
| | | */ |
| | | public ByteArrayOutputStream exportApproveTableDoc(TaskDispatch dispatch,FlowProgramProperties props) throws IOException { |
| | | ByteArrayOutputStream os= new ByteArrayOutputStream(); |
| | | String tplOssName = paramService.approveTableTemplateOssFileName(); |
| | | try(InputStream tplInputStream = ossTemplate.statFileStream(tplOssName);) { |
| | | WordReplaceUtil.convert(getData(dispatch, props), tplInputStream, os); |
| | | } |
| | | return os; |
| | | } |
| | | |
| | | /** |
| | | * è·åå¡«å
æ°æ® |
| | | */ |
| | | |
| | | Map<String,String> getData(TaskDispatch dispatch,FlowProgramProperties props){ |
| | | ApproveTableInfo approveInfo = approveInfoQueryService.getApproveInfo(props); |
| | | Machine machine; |
| | | String machineCode = props.getMachineCode(); |
| | | machine = machineService.getByCode(machineCode); |
| | | |
| | | Map<String,String> dataMap = new HashMap<>(); |
| | | dataMap.put("drawingNo",props.getDrawingNo()); |
| | | dataMap.put("processNo",props.getProcessNo()); |
| | | dataMap.put("craftEdition",props.getCraftEdition()); |
| | | dataMap.put("processEdition",props.getProcessEdition()); |
| | | dataMap.put("machineMode",machine.getName()); |
| | | |
| | | String DATE_PATTERN = "yyyy-M-d"; |
| | | |
| | | String dispatchDateStr = " "; |
| | | if (approveInfo.getDispatchDate() != null) { |
| | | dispatchDateStr = DateUtil.format(approveInfo.getDispatchDate(), DATE_PATTERN); |
| | | } |
| | | |
| | | dataMap.put("teamLeader",approveInfo.getTeamLeaderName()+"/"+dispatchDateStr); |
| | | dataMap.put("fuzeren",approveInfo.getProgrammerName());//è´è´£äºº |
| | | int isProgram = 0; |
| | | if(StringUtils.equals(props.getHasCuredProgram(),FlowContants.Y)){ |
| | | //æ ¡å¯¹ä»»å¡ |
| | | dataMap.put("jd", WordReplaceUtil.CHECKED); |
| | | dataMap.put("bc", WordReplaceUtil.UNCHECKED); |
| | | |
| | | }else{ |
| | | //ç¼ç¨ä»»å¡ |
| | | dataMap.put("jd", WordReplaceUtil.UNCHECKED); |
| | | dataMap.put("bc", WordReplaceUtil.CHECKED); |
| | | } |
| | | |
| | | dataMap.put("programNo",dispatch.getProgramNo()); |
| | | dataMap.put("fzy",WordReplaceUtil.CHECKED); |
| | | dataMap.put("fzn",WordReplaceUtil.UNCHECKED); |
| | | Date programDate = approveInfo.getCheckDate(); |
| | | Date checkDate = approveInfo.getCheckDate(); |
| | | |
| | | String bianzhiDateStr = DateUtil.format(dispatch.getCreateTime(), DATE_PATTERN); |
| | | |
| | | String checkDateStr = " "; |
| | | if (checkDate != null) { |
| | | checkDateStr = DateUtil.format(programDate, DATE_PATTERN); |
| | | } |
| | | |
| | | String approveDateStr = " "; |
| | | if (approveInfo.getApproveDate() != null) { |
| | | approveDateStr = DateUtil.format(approveInfo.getApproveDate(), DATE_PATTERN); |
| | | } |
| | | |
| | | dataMap.put("programmer",approveInfo.getProgrammerName()+"/"+bianzhiDateStr); |
| | | dataMap.put("jiaodui",approveInfo.getTeamLeaderName()+"/æ¶é´ä¸ç¡®å®"); |
| | | dataMap.put("shenpi",approveInfo.getSeniorName()+"/æ¶é´ä¸ç¡®å®"); |
| | | |
| | | dataMap.put("sendPath",machine.getProgSendDir()!=null?machine.getProgSendDir():""); |
| | | |
| | | return dataMap; |
| | | } |
| | | |
| | | /* |
| | | public void exportApproveTableOld(String processInstanceId, OutputStream os) throws DocumentException, IOException { |
| | | |
| | | BaseFont bfChinese = getBaseFont(); |
| | | |
| | | Document document = new Document(PageSize.B5.rotate()); |
| | | PdfWriter.getInstance(document, os); |
| | | |
| | | document.open(); |
| | | |
| | | FlowProgramProperties props = flowCommonService.getProgramPropertiesFromHis(processInstanceId); |
| | | |
| | | ApproveTableInfo appInfo = getApproveInfo(props); |
| | | Machine machine; |
| | | String machineCode = props.getMachineCode(); |
| | | machine = machineService.getByCode(machineCode); |
| | | |
| | | int flag = props.getProcessDefinitionKey().equals(FlowContants.TRY_PROCESS_KEY)?1:2; |
| | | printPage(document, bfChinese, props, machine, flag, appInfo); |
| | | //document.newPage(); |
| | | |
| | | |
| | | //printPage(document, bfChinese, props, machine, 2, appInfo); |
| | | |
| | | document.close(); |
| | | } |
| | | */ |
| | | |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | |
| | | package org.springblade.mdm.statreport.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import lombok.AllArgsConstructor; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.flowable.engine.HistoryService; |
| | | import org.flowable.engine.RuntimeService; |
| | | import org.flowable.engine.TaskService; |
| | | import org.flowable.engine.history.HistoricProcessInstance; |
| | | import org.flowable.engine.history.HistoricProcessInstanceQuery; |
| | | import org.flowable.engine.task.Comment; |
| | | import org.flowable.task.api.Task; |
| | | import org.flowable.task.api.TaskInfoQuery; |
| | | import org.flowable.task.api.TaskQuery; |
| | | import org.flowable.task.api.history.HistoricTaskInstance; |
| | | import org.flowable.task.api.history.HistoricTaskInstanceQuery; |
| | | import org.springblade.core.oss.OssTemplate; |
| | | 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.Func; |
| | | import org.springblade.mdm.basesetting.machine.entity.Machine; |
| | | import org.springblade.mdm.basesetting.machine.service.MachineService; |
| | | import org.springblade.mdm.commons.contants.DictBizConstants; |
| | | import org.springblade.mdm.commons.service.ParamService; |
| | | import org.springblade.mdm.flow.constants.FlowContants; |
| | | import org.springblade.mdm.flow.entity.FlowProgramFile; |
| | | import org.springblade.mdm.flow.entity.MdmFlowProcess; |
| | | import org.springblade.mdm.flow.entity.TaskDispatch; |
| | | import org.springblade.mdm.flow.service.FlowProgramFileService; |
| | | import org.springblade.mdm.flow.service.FlowProgramProperties; |
| | | import org.springblade.mdm.flow.util.MdmFlowCache; |
| | | import org.springblade.mdm.flow.vo.ApproveTableInfo; |
| | | import org.springblade.mdm.flow.vo.FlowVO; |
| | | import org.springblade.mdm.statreport.utils.WordReplaceUtil; |
| | | import org.springblade.system.feign.IDictBizClient; |
| | | import org.springblade.system.feign.IUserClient; |
| | | import org.springblade.system.pojo.entity.User; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * æµç¨ä¸å¡å®ç°ç±» |
| | | * |
| | | * @author Chill |
| | | */ |
| | | @Service |
| | | @AllArgsConstructor |
| | | public class ConfirmTablePrintService { |
| | | private final RuntimeService runtimeService; |
| | | private final IDictBizClient dictBizClient; |
| | | private final HistoryService historyService; |
| | | private final IUserClient userClient; |
| | | private final FlowProgramFileService flowProgramFileService; |
| | | @Autowired |
| | | private MachineService machineService; |
| | | @Autowired |
| | | private ParamService paramService; |
| | | @Autowired |
| | | private OssTemplate ossTemplate; |
| | | /** |
| | | * 导åºwordå²¸æ¬ |
| | | * @param dispatch ä»»å¡åæ´¾ |
| | | * @param props æµç¨å±æ§ |
| | | */ |
| | | public ByteArrayOutputStream exportConfirmTableDoc(TaskDispatch dispatch, FlowProgramProperties props) throws IOException { |
| | | ByteArrayOutputStream os= new ByteArrayOutputStream(); |
| | | String tplOssName = paramService.confirmTableTemplateOssFileName(); |
| | | try(InputStream tplInputStream = ossTemplate.statFileStream(tplOssName);) { |
| | | WordReplaceUtil.convert(getData(dispatch, props), tplInputStream, os); |
| | | } |
| | | return os; |
| | | } |
| | | |
| | | /** |
| | | * è·åå¡«å
æ°æ® |
| | | */ |
| | | |
| | | Map<String,String> getData(TaskDispatch dispatch,FlowProgramProperties props){ |
| | | //ApproveTableInfo approveInfo = approveInfoQueryService.getApproveInfo(props); |
| | | Machine machine; |
| | | String machineCode = props.getMachineCode(); |
| | | machine = machineService.getByCode(machineCode); |
| | | |
| | | if(dispatch == null){ |
| | | dispatch = new TaskDispatch();//TODO åé¢å»æ |
| | | } |
| | | |
| | | Map<String,String> dataMap = new HashMap<>(); |
| | | |
| | | dataMap.put("bh","ä¸æç¡®"); |
| | | |
| | | dataMap.put("drawingNo",props.getDrawingNo()); |
| | | dataMap.put("processNo",props.getProcessNo()); |
| | | dataMap.put("craftEdition",props.getCraftEdition()); |
| | | dataMap.put("processEdition",props.getProcessEdition()); |
| | | dataMap.put("machineMode",machine.getName()); |
| | | |
| | | String DATE_PATTERN = "yyyy-M-d"; |
| | | |
| | | String dispatchDateStr = " "; |
| | | |
| | | String ctlSystem = ""; |
| | | R<String> ctmR = dictBizClient.getValue(DictBizConstants.CONTROL_SYSTEM,machine.getControlSystem()); |
| | | if(ctmR.isSuccess()){ |
| | | ctlSystem = ctmR.getData(); |
| | | } |
| | | dataMap.put("deviation",dispatch.getDeviation()==null?"":dispatch.getDeviation()); |
| | | dataMap.put("controlSystem",ctlSystem); |
| | | dataMap.put("czz","æä½è
"); |
| | | dataMap.put("jyy","æ£éªå"); |
| | | |
| | | |
| | | dataMap.put("programNo",dispatch.getProgramNo()); |
| | | dataMap.put("fuhey",WordReplaceUtil.CHECKED); |
| | | dataMap.put("fuhen",WordReplaceUtil.UNCHECKED); |
| | | dataMap.put("jly",WordReplaceUtil.CHECKED); |
| | | dataMap.put("jln",WordReplaceUtil.UNCHECKED); |
| | | |
| | | String bianzhiDateStr = "";//DateUtil.format(dispatch.getCreateTime(), DATE_PATTERN); |
| | | |
| | | |
| | | dataMap.put("bianzhi","ç¼ç¨åï¼/"+bianzhiDateStr); |
| | | dataMap.put("jiaodui","å·¥èºæ ¡å¯¹ï¼/æ¶é´ä¸ç¡®å®"); |
| | | dataMap.put("shenhe","é«å¸ï¼/æ¶é´ä¸ç¡®å®"); |
| | | |
| | | dataMap.put("sendPath",machine.getProgSendDir()!=null?machine.getProgSendDir():""); |
| | | |
| | | return dataMap; |
| | | } |
| | | |
| | | /** |
| | | * å·²å®ç»çæµç¨å页å表 |
| | | * @param page åé¡µä¿¡æ¯ |
| | | * @param createTimeBegin |
| | | * @param createTimeEnd |
| | | * @param keyword å
³é®å |
| | | * @return |
| | | */ |
| | | public IPage<FlowVO> confirmTablePage(IPage<FlowVO> page, String drawingNo, String keyword,LocalDateTime createTimeBegin, LocalDateTime createTimeEnd) { |
| | | //åºåéè·¯æå® |
| | | HistoricProcessInstanceQuery query = this.historyService.createHistoricProcessInstanceQuery().finished().processDefinitionKey(FlowContants.CURE_PROCESS_KEY).includeProcessVariables(); |
| | | //.finished() // åªæ¥è¯¢å·²å®æçæµç¨.unfinished() // æ¥è¯¢æªå®æçæµç¨ |
| | | query.variableNotExists(FlowContants.EXCEPTION);//éå¼å¸¸æµç¨ |
| | | if(createTimeBegin!=null) { |
| | | query.startedAfter(DateUtil.toDate(createTimeBegin)); |
| | | } |
| | | if(createTimeEnd!=null) { |
| | | query.startedBefore(DateUtil.toDate(createTimeEnd)); |
| | | } |
| | | if(Func.isNotEmpty(drawingNo)) { |
| | | String likeVal = "%" + drawingNo + "%"; |
| | | query.variableValueLike(FlowContants.DRAWING_NO,likeVal); |
| | | } |
| | | |
| | | |
| | | query.orderByProcessInstanceEndTime().desc(); // æç»ææ¶é´éåºæå |
| | | page.setTotal(query.count()); |
| | | |
| | | long firstResult = (page.getCurrent()-1) * page.getSize(); |
| | | List<HistoricProcessInstance> processes = query |
| | | .listPage((int)firstResult, (int)page.getSize()); |
| | | |
| | | List<FlowVO> records = new LinkedList<>(); |
| | | |
| | | for(HistoricProcessInstance processInstance : processes) { |
| | | FlowVO vo = new FlowVO(); |
| | | vo.setProcessDefinitionKey(processInstance.getProcessDefinitionKey()); |
| | | vo.setProcessInstanceId(processInstance.getId()); |
| | | vo.setProcessDefinitionName(processInstance.getProcessDefinitionName()); |
| | | vo.setVariables(processInstance.getProcessVariables()); |
| | | |
| | | vo.setProcessCreateTime(processInstance.getStartTime()); |
| | | vo.setHistoryTaskEndTime(processInstance.getEndTime()); |
| | | |
| | | |
| | | vo.setFile(getFileString(processInstance.getId())); |
| | | records.add(vo); |
| | | } |
| | | |
| | | page.setRecords(records); |
| | | |
| | | return page; |
| | | } |
| | | /** |
| | | è·åå表ä¸çæä»¶å |
| | | */ |
| | | String getFileString(String processInstanceId){ |
| | | String result = ""; |
| | | List<FlowProgramFile> fileList = flowProgramFileService.lambdaQuery().eq(FlowProgramFile::getProcessInstanceId, processInstanceId).list(); |
| | | |
| | | result = String.join(",",fileList.stream().map(FlowProgramFile::getName).toList()); |
| | | |
| | | return result; |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.springblade.mdm.statreport.utils; |
| | | |
| | | import org.apache.poi.xwpf.usermodel.*; |
| | | import java.io.*; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | public class WordReplaceUtil { |
| | | public static final String CHECKED = "â"; |
| | | public static final String UNCHECKED = "â¡"; |
| | | |
| | | |
| | | public static void convert(Map<String, String> data,InputStream inputStream,OutputStream outputSteam ) { |
| | | try { |
| | | // 读å Word æ¨¡æ¿æä»¶ |
| | | //FileInputStream fis = new FileInputStream("d:/spd.docx"); |
| | | XWPFDocument document = new XWPFDocument(inputStream); |
| | | |
| | | // æ¿æ¢ææ¡£ä¸çå ä½ç¬¦ |
| | | replacePlaceholders(document, data); |
| | | |
| | | // ä¿å为æ°ç Word ææ¡£ |
| | | //FileOutputStream fos = new FileOutputStream("d:/poioutput.docx"); |
| | | document.write(outputSteam); |
| | | |
| | | //System.out.println("æ°ç Word ææ¡£çææåï¼"); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | //System.out.println("çææ°ç Word ææ¡£å¤±è´¥ï¼" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | private static void replacePlaceholders(XWPFDocument document, Map<String, String> data) { |
| | | // éåææ¡£ä¸çæ¯ä¸ªæ®µè½ |
| | | document.getTables().forEach(table -> { |
| | | List<XWPFTableRow> rows = table.getRows(); |
| | | //éåè¡¨æ ¼,å¹¶æ¿æ¢æ¨¡æ¿ |
| | | replaceTableRow(rows, data); |
| | | |
| | | table.getBody().getParagraphs().forEach(paragraph -> { |
| | | replaceTextInPhoto(paragraph,data); |
| | | }); |
| | | }); |
| | | for (XWPFParagraph paragraph : document.getParagraphs()) { |
| | | // éåæ®µè½ä¸çæ¯ä¸ªææ¬è¿è¡å¯¹è±¡ |
| | | for (XWPFRun run : paragraph.getRuns()) { |
| | | String text = run.getText(0); |
| | | if (text != null) { |
| | | // éåæ°æ®æ å°ï¼æ¿æ¢å ä½ç¬¦ |
| | | for (Map.Entry<String, String> entry : data.entrySet()) { |
| | | String placeholder = entry.getKey(); |
| | | String replacement = entry.getValue(); |
| | | if (text.contains(placeholder)) { |
| | | text = text.replace(placeholder, replacement); |
| | | run.setText(text, 0); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | static void replaceTextInPhoto(XWPFParagraph paragraph,Map<String,String> data) { |
| | | for (XWPFRun run : paragraph.getRuns()) { |
| | | String text = run.getText(0); |
| | | if (text != null) { |
| | | // éåæ°æ®æ å°ï¼æ¿æ¢å ä½ç¬¦ |
| | | for (Map.Entry<String, String> entry : data.entrySet()) { |
| | | String placeholder = entry.getKey(); |
| | | String replacement = entry.getValue(); |
| | | if(replacement!=null) { |
| | | if (text.contains(placeholder)) { |
| | | text = text.replace(placeholder, replacement); |
| | | run.setText(text, 0); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | public static void replaceTableRow(List<XWPFTableRow> rows , Map<String, String> data){ |
| | | for (XWPFTableRow row : rows) { |
| | | //å¾å°è¡¨æ ¼æ¯ä¸è¡çææè¡¨æ ¼ |
| | | List<XWPFTableCell> cells = row.getTableCells(); |
| | | for (XWPFTableCell cell : cells) { |
| | | //夿åå
æ ¼æ¯å¦éè¦æ¿æ¢ |
| | | |
| | | List<XWPFParagraph> paragraphs = cell.getParagraphs(); |
| | | for (XWPFParagraph paragraph : paragraphs) { |
| | | List<XWPFRun> runs = paragraph.getRuns(); |
| | | for (XWPFRun run : runs) { |
| | | String text = run.getText(0); |
| | | if (text != null) { |
| | | // éåæ°æ®æ å°ï¼æ¿æ¢å ä½ç¬¦ |
| | | for (Map.Entry<String, String> entry : data.entrySet()) { |
| | | String placeholder = entry.getKey(); |
| | | String replacement = entry.getValue(); |
| | | if(replacement!=null) { |
| | | if (text.contains(placeholder)) { |
| | | text = text.replace(placeholder, replacement); |
| | | run.setText(text, 0); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.springblade.mdm.statreport.utils; |
| | | import org.apache.commons.io.FileUtils; |
| | | import org.docx4j.openpackaging.contenttype.ContentType; |
| | | import org.docx4j.openpackaging.packages.WordprocessingMLPackage; |
| | | import org.docx4j.openpackaging.parts.WordprocessingML.AltChunkType; |
| | | import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart; |
| | | import org.docx4j.openpackaging.parts.WordprocessingML.AlternativeFormatInputPart; |
| | | import org.docx4j.openpackaging.parts.PartName; |
| | | import org.docx4j.wml.ObjectFactory; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | |
| | | public class XmlToDocxWithPOI { |
| | | public static void convertXmlToDocx(String xmlFilePath, String outputFilePath) throws Exception { |
| | | |
| | | // å建 Word ææ¡£å¯¹è±¡ |
| | | WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); |
| | | MainDocumentPart mainDocumentPart = wordMLPackage.getMainDocumentPart(); |
| | | |
| | | mainDocumentPart.addAltChunk(AltChunkType.Xml,new FileInputStream(xmlFilePath)); |
| | | |
| | | wordMLPackage.save(new File(outputFilePath)); |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.springblade.mdm.statreport.utils; |
| | | |
| | | import org.apache.poi.xwpf.usermodel.*; |
| | | import org.apache.xmlbeans.XmlException; |
| | | import org.docx4j.Docx4J; |
| | | import org.docx4j.TraversalUtil; |
| | | import org.docx4j.openpackaging.packages.WordprocessingMLPackage; |
| | | import org.docx4j.openpackaging.exceptions.Docx4JException; |
| | | import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart; |
| | | import org.docx4j.wml.ContentAccessor; |
| | | import org.docx4j.wml.P; |
| | | import org.docx4j.wml.R; |
| | | import org.docx4j.wml.Text; |
| | | import org.junit.jupiter.api.Test; |
| | | import javax.xml.bind.JAXBElement; |
| | | import java.io.*; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Paths; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import org.docx4j.XmlUtils; |
| | | import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBody; |
| | | import org.openxmlformats.schemas.wordprocessingml.x2006.main.DocumentDocument; |
| | | |
| | | public class XmlToDocxWithPOITest { |
| | | private String checked = "â"; |
| | | private String unchecked = "â¡"; |
| | | //@Test |
| | | public void test() throws Exception { |
| | | |
| | | convert(); |
| | | } |
| | | |
| | | public void convert() { |
| | | try { |
| | | // 读å Word æ¨¡æ¿æä»¶ |
| | | FileInputStream fis = new FileInputStream("d:/spd.docx"); |
| | | XWPFDocument document = new XWPFDocument(fis); |
| | | |
| | | // åå¤è¦æ¿æ¢çæ°æ® |
| | | Map<String, String> data = new HashMap<>(); |
| | | data.put("processNo","bh01"); |
| | | data.put("bz",checked); |
| | | data.put("jd",unchecked); |
| | | data.put("fzy",checked); |
| | | data.put("fzn",unchecked); |
| | | |
| | | // æ¿æ¢ææ¡£ä¸çå ä½ç¬¦ |
| | | replacePlaceholders(document, data); |
| | | |
| | | // ä¿å为æ°ç Word ææ¡£ |
| | | FileOutputStream fos = new FileOutputStream("d:/poioutput.docx"); |
| | | document.write(fos); |
| | | fos.close(); |
| | | fis.close(); |
| | | |
| | | System.out.println("æ°ç Word ææ¡£çææåï¼"); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | System.out.println("çææ°ç Word ææ¡£å¤±è´¥ï¼" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | private void replacePlaceholders(XWPFDocument document, Map<String, String> data) { |
| | | // éåææ¡£ä¸çæ¯ä¸ªæ®µè½ |
| | | document.getTables().forEach(table -> { |
| | | List<XWPFTableRow> rows = table.getRows(); |
| | | //éåè¡¨æ ¼,å¹¶æ¿æ¢æ¨¡æ¿ |
| | | eachTable(rows, data); |
| | | |
| | | table.getBody().getParagraphs().forEach(paragraph -> { |
| | | replaceTextInPhoto(paragraph,data); |
| | | }); |
| | | }); |
| | | for (XWPFParagraph paragraph : document.getParagraphs()) { |
| | | // éåæ®µè½ä¸çæ¯ä¸ªææ¬è¿è¡å¯¹è±¡ |
| | | for (XWPFRun run : paragraph.getRuns()) { |
| | | String text = run.getText(0); |
| | | if (text != null) { |
| | | // éåæ°æ®æ å°ï¼æ¿æ¢å ä½ç¬¦ |
| | | for (Map.Entry<String, String> entry : data.entrySet()) { |
| | | String placeholder = entry.getKey(); |
| | | String replacement = entry.getValue(); |
| | | if (text.contains(placeholder)) { |
| | | text = text.replace(placeholder, replacement); |
| | | run.setText(text, 0); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | void replaceTextInPhoto(XWPFParagraph paragraph,Map<String,String> data) { |
| | | for (XWPFRun run : paragraph.getRuns()) { |
| | | String text = run.getText(0); |
| | | if (text != null) { |
| | | // éåæ°æ®æ å°ï¼æ¿æ¢å ä½ç¬¦ |
| | | for (Map.Entry<String, String> entry : data.entrySet()) { |
| | | String placeholder = entry.getKey(); |
| | | String replacement = entry.getValue(); |
| | | if (text.contains(placeholder)) { |
| | | text = text.replace(placeholder, replacement); |
| | | run.setText(text, 0); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | public static void eachTable(List<XWPFTableRow> rows , Map<String, String> data){ |
| | | for (XWPFTableRow row : rows) { |
| | | //å¾å°è¡¨æ ¼æ¯ä¸è¡çææè¡¨æ ¼ |
| | | List<XWPFTableCell> cells = row.getTableCells(); |
| | | for (XWPFTableCell cell : cells) { |
| | | //夿åå
æ ¼æ¯å¦éè¦æ¿æ¢ |
| | | |
| | | List<XWPFParagraph> paragraphs = cell.getParagraphs(); |
| | | for (XWPFParagraph paragraph : paragraphs) { |
| | | List<XWPFRun> runs = paragraph.getRuns(); |
| | | for (XWPFRun run : runs) { |
| | | String text = run.getText(0); |
| | | if (text != null) { |
| | | // éåæ°æ®æ å°ï¼æ¿æ¢å ä½ç¬¦ |
| | | for (Map.Entry<String, String> entry : data.entrySet()) { |
| | | String placeholder = entry.getKey(); |
| | | String replacement = entry.getValue(); |
| | | if (text.contains(placeholder)) { |
| | | text = text.replace(placeholder, replacement); |
| | | run.setText(text, 0); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | } |