| | |
| | | <artifactId>spring-boot-starter-aop</artifactId> |
| | | </dependency> |
| | | <!--poi--> |
| | | <dependency> |
| | | <!--<dependency> |
| | | <groupId>org.apache.poi</groupId> |
| | | <artifactId>poi-ooxml</artifactId> |
| | | <version>3.10.1</version> |
| | | </dependency>--> |
| | | <dependency> |
| | | <groupId>com.deepoove</groupId> |
| | | <artifactId>poi-tl</artifactId> |
| | | <version>1.5.1</version> |
| | | </dependency> |
| | | <!--websocket--> |
| | | <dependency> |
| | |
| | | <dependency> |
| | | <groupId>com.aspose</groupId> |
| | | <artifactId>aspose-words</artifactId> |
| | | <version>22.3</version> |
| | | <version>15.8.0</version> |
| | | <scope>system</scope> |
| | | <systemPath>${pom.basedir}/src/main/resources/lib/aspose-words-22.3-jdk16.jar</systemPath> |
| | | <systemPath>${pom.basedir}/src/main/resources/lib/aspose-words-15.8.0-jdk16.jar</systemPath> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | |
| | | ProductBom(1,"产品Bom"), |
| | | Material(2,"散装件"), |
| | | MaterialProduct(3,"散装件-产品"), |
| | | ProductSoftware(4,"产品软件"); |
| | | ProductSoftware(4,"产品软件"), |
| | | |
| | | //追加流程卡,SOP |
| | | ProductProcedure(11,"产品流程卡"), |
| | | SOP(12,"标准操作指导书"); |
| | | |
| | | EnumWorksheetType(Integer type, String typeName) { |
| | | this.type = type; |
| | |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.io.IOException; |
| | | |
| | | @RestController |
| | | @RequestMapping("worksheetLink") |
| | |
| | | return new Response().setII(1,"审批完成"); |
| | | } |
| | | |
| | | @PutMapping("confirmProductProcedureAndSOP") |
| | | @ApiOperation(value = "流程卡及SOP确认",notes = "id; linkStatus:确认1,拒绝2; dealReason:拒绝时填写处理意见") |
| | | public Response confirmProductProcedureAndSOP(@RequestBody WorksheetLink link) throws IOException { |
| | | return service.confirmProductProcedureAndSOP(link); |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | package com.whyc.controller; |
| | | |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.whyc.config.EnumWorksheetType; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.dto.WorksheetMainDTO; |
| | | import com.whyc.dto.WorksheetMainDTO2; |
| | | import com.whyc.pojo.DocUser; |
| | | import com.whyc.pojo.ProcedureDocApproving; |
| | | import com.whyc.pojo.WorksheetMain; |
| | | import com.whyc.service.WorksheetMainService; |
| | | import com.whyc.util.ActionUtil; |
| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.mail.MessagingException; |
| | | import java.io.IOException; |
| | | import java.util.Map; |
| | | |
| | |
| | | return service.getMyList(pageNum,pageSize,user); |
| | | } |
| | | |
| | | /** |
| | | * {@link EnumWorksheetType#getType()} |
| | | * @param approving |
| | | * @return |
| | | * @throws IOException |
| | | * @throws MessagingException |
| | | */ |
| | | @PostMapping("productProcedureAndSOP") |
| | | @ApiOperation(value = "产品流程卡及SOP提交",notes = "type:1-流程卡,2-SOP") |
| | | public Response addProductProcedureAndSOP(@RequestBody ProcedureDocApproving approving) throws IOException, MessagingException { |
| | | DocUser user = ActionUtil.getUser(); |
| | | return service.addProductProcedureAndSOP(approving,user); |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.whyc.mapper; |
| | | |
| | | import com.whyc.pojo.ProcedureDocApproving; |
| | | |
| | | public interface ProcedureDocApprovingMapper extends CustomMapper<ProcedureDocApproving> { |
| | | } |
New file |
| | |
| | | package com.whyc.mapper; |
| | | |
| | | import com.whyc.pojo.ProcedureDoc; |
| | | |
| | | public interface ProcedureDocMapper extends CustomMapper<ProcedureDoc> { |
| | | } |
New file |
| | |
| | | package com.whyc.pojo; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import org.apache.ibatis.type.Alias; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.Date; |
| | | |
| | | @Alias("ProcedureDoc") |
| | | @TableName("tb_procedure_doc") |
| | | public class ProcedureDoc { |
| | | |
| | | private Integer id; |
| | | private String name; |
| | | private String version; |
| | | private Long fzr; |
| | | private Long bz; |
| | | private Long zz; |
| | | private Long pb; |
| | | private String description; |
| | | private String file; |
| | | private Integer type; |
| | | private Date createTime; |
| | | |
| | | @TableField(exist = false) |
| | | private MultipartFile multipartFile; |
| | | |
| | | public Integer getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(Integer id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public String getName() { |
| | | return name; |
| | | } |
| | | |
| | | public void setName(String name) { |
| | | this.name = name; |
| | | } |
| | | |
| | | public String getVersion() { |
| | | return version; |
| | | } |
| | | |
| | | public void setVersion(String version) { |
| | | this.version = version; |
| | | } |
| | | |
| | | public Long getFzr() { |
| | | return fzr; |
| | | } |
| | | |
| | | public void setFzr(Long fzr) { |
| | | this.fzr = fzr; |
| | | } |
| | | |
| | | public Long getBz() { |
| | | return bz; |
| | | } |
| | | |
| | | public void setBz(Long bz) { |
| | | this.bz = bz; |
| | | } |
| | | |
| | | public Long getZz() { |
| | | return zz; |
| | | } |
| | | |
| | | public void setZz(Long zz) { |
| | | this.zz = zz; |
| | | } |
| | | |
| | | public Long getPb() { |
| | | return pb; |
| | | } |
| | | |
| | | public void setPb(Long pb) { |
| | | this.pb = pb; |
| | | } |
| | | |
| | | public String getDescription() { |
| | | return description; |
| | | } |
| | | |
| | | public void setDescription(String description) { |
| | | this.description = description; |
| | | } |
| | | |
| | | public String getFile() { |
| | | return file; |
| | | } |
| | | |
| | | public void setFile(String file) { |
| | | this.file = file; |
| | | } |
| | | |
| | | public Integer getType() { |
| | | return type; |
| | | } |
| | | |
| | | public void setType(Integer type) { |
| | | this.type = type; |
| | | } |
| | | |
| | | public Date getCreateTime() { |
| | | return createTime; |
| | | } |
| | | |
| | | public void setCreateTime(Date createTime) { |
| | | this.createTime = createTime; |
| | | } |
| | | |
| | | public MultipartFile getMultipartFile() { |
| | | return multipartFile; |
| | | } |
| | | |
| | | public void setMultipartFile(MultipartFile multipartFile) { |
| | | this.multipartFile = multipartFile; |
| | | } |
| | | } |
New file |
| | |
| | | package com.whyc.pojo; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import org.apache.ibatis.type.Alias; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.Date; |
| | | |
| | | @Alias("ProcedureDocApproving") |
| | | @TableName("tb_procedure_doc_approving") |
| | | public class ProcedureDocApproving { |
| | | |
| | | private Integer id; |
| | | private Integer mainId; |
| | | private String name; |
| | | private String version; |
| | | private Long fzr; |
| | | private Long bz; |
| | | private Long zz; |
| | | private Long pb; |
| | | private String description; |
| | | private String file; |
| | | private Integer type; |
| | | private Date createTime; |
| | | |
| | | @TableField(exist = false) |
| | | private MultipartFile multipartFile; |
| | | |
| | | public Integer getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(Integer id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public Integer getMainId() { |
| | | return mainId; |
| | | } |
| | | |
| | | public void setMainId(Integer mainId) { |
| | | this.mainId = mainId; |
| | | } |
| | | |
| | | public String getName() { |
| | | return name; |
| | | } |
| | | |
| | | public void setName(String name) { |
| | | this.name = name; |
| | | } |
| | | |
| | | public String getVersion() { |
| | | return version; |
| | | } |
| | | |
| | | public void setVersion(String version) { |
| | | this.version = version; |
| | | } |
| | | |
| | | public Long getFzr() { |
| | | return fzr; |
| | | } |
| | | |
| | | public void setFzr(Long fzr) { |
| | | this.fzr = fzr; |
| | | } |
| | | |
| | | public Long getBz() { |
| | | return bz; |
| | | } |
| | | |
| | | public void setBz(Long bz) { |
| | | this.bz = bz; |
| | | } |
| | | |
| | | public Long getZz() { |
| | | return zz; |
| | | } |
| | | |
| | | public void setZz(Long zz) { |
| | | this.zz = zz; |
| | | } |
| | | |
| | | public Long getPb() { |
| | | return pb; |
| | | } |
| | | |
| | | public void setPb(Long pb) { |
| | | this.pb = pb; |
| | | } |
| | | |
| | | public String getDescription() { |
| | | return description; |
| | | } |
| | | |
| | | public void setDescription(String description) { |
| | | this.description = description; |
| | | } |
| | | |
| | | public String getFile() { |
| | | return file; |
| | | } |
| | | |
| | | public void setFile(String file) { |
| | | this.file = file; |
| | | } |
| | | |
| | | public Integer getType() { |
| | | return type; |
| | | } |
| | | |
| | | public void setType(Integer type) { |
| | | this.type = type; |
| | | } |
| | | |
| | | public Date getCreateTime() { |
| | | return createTime; |
| | | } |
| | | |
| | | public void setCreateTime(Date createTime) { |
| | | this.createTime = createTime; |
| | | } |
| | | |
| | | public MultipartFile getMultipartFile() { |
| | | return multipartFile; |
| | | } |
| | | |
| | | public void setMultipartFile(MultipartFile multipartFile) { |
| | | this.multipartFile = multipartFile; |
| | | } |
| | | } |
| | |
| | | * 1:已通过 |
| | | * 2:已驳回 |
| | | * |
| | | * -> |
| | | * 流程卡和SOP中: |
| | | * 0:待确认 |
| | | * 1:已确认 |
| | | * 2:已驳回 |
| | | * |
| | | * |
| | | * */ |
| | | private Integer linkStatus; |
| | | |
| | |
| | | * 1:经理处理中 |
| | | * 2:总经理处理中 |
| | | * 5:归档 |
| | | * |
| | | * ->在流程卡/SOP中 |
| | | * 0:驳回,完结 |
| | | * 1:处理中 |
| | | * 5:归档 |
| | | * */ |
| | | private Integer status; |
| | | @ApiModelProperty("工单结束意见") |
| | |
| | | /** |
| | | * {@link EnumWorksheetType#getType()} |
| | | */ |
| | | @ApiModelProperty("工单类型:1-bom,2-散装件,3-bom-散装件") |
| | | @ApiModelProperty("工单类型") |
| | | private Integer type; |
| | | |
| | | @ApiModelProperty("流程的下个处理人") |
| | |
| | | |
| | | @TableField(exist = false) |
| | | private List<MaterialProductApproving> mpApprovingList; |
| | | |
| | | @TableField(exist = false) |
| | | private ProcedureDoc procedureDoc; |
| | | |
| | | public Integer getId() { |
| | | return id; |
| | |
| | | public void setMpApprovingList(List<MaterialProductApproving> mpApprovingList) { |
| | | this.mpApprovingList = mpApprovingList; |
| | | } |
| | | |
| | | public ProcedureDoc getProcedureDoc() { |
| | | return procedureDoc; |
| | | } |
| | | |
| | | public void setProcedureDoc(ProcedureDoc procedureDoc) { |
| | | this.procedureDoc = procedureDoc; |
| | | } |
| | | } |
New file |
| | |
| | | package com.whyc.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.whyc.mapper.ProcedureDocApprovingMapper; |
| | | import com.whyc.pojo.ProcedureDocApproving; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | @Service |
| | | public class ProcedureDocApprovingService { |
| | | |
| | | @Resource |
| | | private ProcedureDocApprovingMapper mapper; |
| | | |
| | | public ProcedureDocApproving getByMainId(Integer mainId) { |
| | | QueryWrapper<ProcedureDocApproving> query = Wrappers.query(); |
| | | query.eq("main_id",mainId).last(" limit 1"); |
| | | return mapper.selectOne(query); |
| | | } |
| | | |
| | | public void insert(ProcedureDocApproving approving) { |
| | | mapper.insert(approving); |
| | | } |
| | | } |
New file |
| | |
| | | package com.whyc.service; |
| | | |
| | | import com.whyc.mapper.ProcedureDocMapper; |
| | | import com.whyc.pojo.ProcedureDoc; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | @Service |
| | | public class ProcedureDocService { |
| | | |
| | | @Resource |
| | | private ProcedureDocMapper mapper; |
| | | |
| | | public void insert(ProcedureDoc procedureDoc) { |
| | | mapper.insert(procedureDoc); |
| | | } |
| | | } |
| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.whyc.config.EnumWorksheetType; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.ProductBomApprovingMapper; |
| | | import com.whyc.mapper.WorksheetLinkMapper; |
| | | import com.whyc.pojo.*; |
| | | import com.whyc.util.CommonUtil; |
| | | import com.whyc.util.FileUtil; |
| | | import com.whyc.util.WordUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | |
| | | @Autowired |
| | | private ProductHistoryService phService; |
| | | |
| | | @Autowired |
| | | private ProcedureDocApprovingService procedureDocApprovingService; |
| | | |
| | | @Autowired |
| | | private ProcedureDocService procedureDocService; |
| | | |
| | | @Transactional |
| | | public void audit(WorksheetLink link) { |
| | |
| | | public DocUser getApprovingUser(Integer mainId) { |
| | | return linkMapper.getApprovingUser(mainId); |
| | | } |
| | | |
| | | @Transactional |
| | | public Response confirmProductProcedureAndSOP(WorksheetLink link) throws IOException { |
| | | Integer mainId = linkMapper.selectById(link.getId()).getMainId(); |
| | | //更新子表 |
| | | linkMapper.updateById(link); |
| | | if(link.getLinkStatus() ==1){ |
| | | //查询当前单据子表是否已经全部同意 |
| | | QueryWrapper<WorksheetLink> query = Wrappers.query(); |
| | | query.eq("main_id",mainId); |
| | | List<WorksheetLink> linkList = linkMapper.selectList(query); |
| | | List<WorksheetLink> rejectList = linkList.stream().filter(linkFilter -> linkFilter.getLinkStatus() != 1).collect(Collectors.toList()); |
| | | if(rejectList == null){ |
| | | //都为1,已确认 |
| | | mainService.updateEndStatusById(mainId,"已确认",5); |
| | | //文件转移到审批完成后的正式路径 文件保存在/doc_file/procedure/xxx.doc |
| | | ProcedureDocApproving approving = procedureDocApprovingService.getByMainId(mainId); |
| | | String fileRelativePath = approving.getFile(); |
| | | String projectDir = CommonUtil.getProjectDir(); |
| | | String inFilePath = projectDir + File.separator + fileRelativePath; |
| | | String outFilePath = (projectDir + File.separator + fileRelativePath).replace("_approving",""); |
| | | WordUtil.fillValue(inFilePath,outFilePath,Arrays.asList(approving.getFzr(),approving.getBz(),approving.getZz(),approving.getPb())); |
| | | //流程文件数据转移 |
| | | ProcedureDoc procedureDoc = new ProcedureDoc(); |
| | | procedureDoc.setName(approving.getName()); |
| | | procedureDoc.setDescription(approving.getDescription()); |
| | | procedureDoc.setVersion(approving.getVersion()); |
| | | procedureDoc.setFzr(approving.getFzr()); |
| | | procedureDoc.setBz(approving.getBz()); |
| | | procedureDoc.setType(approving.getType()); |
| | | procedureDoc.setCreateTime(new Date()); |
| | | procedureDoc.setFile(fileRelativePath.replace("_approving","")); |
| | | procedureDocService.insert(procedureDoc); |
| | | } |
| | | }else{ |
| | | mainService.updateEndStatusById(mainId,"已驳回",0); |
| | | } |
| | | return new Response().set(1); |
| | | } |
| | | } |
| | |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.whyc.config.EnumWorksheetType; |
| | | import com.whyc.dto.MailDTO; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.dto.WorksheetMainDTO; |
| | | import com.whyc.dto.WorksheetMainDTO2; |
| | |
| | | import com.whyc.util.CommonUtil; |
| | | import com.whyc.util.Zip4jUtil; |
| | | import org.aspectj.util.FileUtil; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.mail.MessagingException; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.text.SimpleDateFormat; |
| | |
| | | |
| | | @Autowired |
| | | private ProductHistoryService productHistoryService; |
| | | |
| | | @Autowired |
| | | private MailService mailService; |
| | | |
| | | @Autowired |
| | | private ProcedureDocApprovingService procedureDocApprovingService; |
| | | |
| | | @Transactional |
| | | public boolean submit(WorksheetMain main, DocUser user) throws IOException { |
| | |
| | | |
| | | } |
| | | |
| | | public Response addProductProcedureAndSOP(ProcedureDocApproving approving, DocUser user) throws IOException, MessagingException { |
| | | WorksheetMain main = new WorksheetMain(); |
| | | //存储上传信息到主表,节点表 |
| | | //文件保存在/doc_file/procedure_approving/xxx.doc |
| | | MultipartFile multipartFile = approving.getMultipartFile(); |
| | | String originalFilename = multipartFile.getOriginalFilename(); |
| | | String rootFile = CommonUtil.getRootFile(); |
| | | Date date = new Date(); |
| | | String suffixFilePath = "procedure_approving" + File.separator + date.getTime() + "_" + originalFilename; |
| | | String outFilePath = rootFile + suffixFilePath; |
| | | File outFile = new File(outFilePath); |
| | | multipartFile.transferTo(outFile); |
| | | |
| | | main.setTitle(approving.getName()); |
| | | main.setDescription(approving.getDescription()); |
| | | main.setCreateUserId(user.getId()); |
| | | main.setBeginTime(date); |
| | | main.setStatus(1); |
| | | if(approving.getType()==1){ |
| | | main.setType(EnumWorksheetType.ProductProcedure.getType()); |
| | | }else{ |
| | | main.setType(EnumWorksheetType.SOP.getType()); |
| | | } |
| | | mainMapper.insert(main); |
| | | |
| | | List<WorksheetLink> links = new LinkedList<>(); |
| | | WorksheetLink baseLink = new WorksheetLink(); |
| | | WorksheetLink linkFzr = new WorksheetLink(); |
| | | WorksheetLink linkBz = new WorksheetLink(); |
| | | WorksheetLink linkZz = new WorksheetLink(); |
| | | WorksheetLink linkPb = new WorksheetLink(); |
| | | |
| | | baseLink.setMainId(main.getId()); |
| | | baseLink.setLinkStatus(0); |
| | | baseLink.setCreateTime(date); |
| | | |
| | | BeanUtils.copyProperties(baseLink,linkFzr); |
| | | BeanUtils.copyProperties(baseLink,linkBz); |
| | | BeanUtils.copyProperties(baseLink,linkZz); |
| | | BeanUtils.copyProperties(baseLink,linkPb); |
| | | |
| | | linkFzr.setDealUserId(approving.getFzr()); |
| | | linkBz.setDealUserId(approving.getBz()); |
| | | linkZz.setDealUserId(approving.getZz()); |
| | | linkPb.setDealUserId(approving.getPb()); |
| | | links.add(linkFzr); |
| | | links.add(linkBz); |
| | | links.add(linkZz); |
| | | links.add(linkPb); |
| | | linkMapper.insertBatchSomeColumn(links); |
| | | |
| | | //流程文档审批子表存入 |
| | | approving.setFile("doc_file"+ File.separator + suffixFilePath); |
| | | approving.setMainId(main.getId()); |
| | | procedureDocApprovingService.insert(approving); |
| | | //发送邮件给四个确认人 |
| | | QueryWrapper<DocUser> query = Wrappers.query(); |
| | | query.select("mail").in("id",approving.getFzr(),approving.getBz(),approving.getZz(),approving.getPb()); |
| | | List<DocUser> docUsers = userMapper.selectList(query); |
| | | List<String> userMailList = docUsers.stream().map(DocUser::getMail).collect(Collectors.toList()); |
| | | |
| | | MailDTO mailDTO = new MailDTO(); |
| | | mailDTO.setMailList(userMailList); |
| | | if(approving.getType()==1){ |
| | | mailDTO.setTitle("【流程卡确认】"+main.getTitle()); |
| | | mailDTO.setContent(user.getName()+"在文档管理平台上传了产品流程卡,请及时确认"); |
| | | }else{ |
| | | mailDTO.setTitle("【SOP确认】"+main.getTitle()); |
| | | mailDTO.setContent(user.getName()+"在文档管理平台上传了SOP,请及时确认"); |
| | | } |
| | | mailService.sendMail(mailDTO); |
| | | |
| | | return new Response().setII(1,"上传完成"); |
| | | } |
| | | } |
| | |
| | | package com.whyc.util; |
| | | |
| | | import com.aspose.words.Document; |
| | | import com.aspose.words.SaveFormat; |
| | | import com.aspose.cad.internal.bouncycastle.util.test.Test; |
| | | import com.aspose.words.Shape; |
| | | import com.aspose.words.*; |
| | | |
| | | import java.awt.*; |
| | | import java.io.File; |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | |
| | | public class Word2PdfAsposeUtil { |
| | | |
| | | /**去除水印专用*/ |
| | | /*public static boolean getLicense() { |
| | | public static boolean getLicense() { |
| | | boolean result = false; |
| | | try { |
| | | InputStream is = Test.class.getClassLoader().getResourceAsStream("\\license.xml"); // license.xml应放在..\WebRoot\WEB-INF\classes路径下 |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | return result; |
| | | }*/ |
| | | } |
| | | |
| | | public static boolean doc2pdf(String inPath, String outPath) { |
| | | /*if (!getLicense()) { // 验证License 若不验证则转化出的pdf文档会有水印产生 |
| | |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | public static boolean doc2pdfWithWaterMark(String inPath, String outPath) { |
| | | if (!getLicense()) { // 验证License 若不验证则转化出的pdf文档会有水印产生 |
| | | return false; |
| | | } |
| | | FileOutputStream os = null; |
| | | try { |
| | | File file = new File(outPath); // 新建一个空白pdf文档 |
| | | os = new FileOutputStream(file); |
| | | Document doc = new Document(inPath); // Address是将要被转化的word文档 |
| | | insertWaterMark(doc,"无效签名"); |
| | | doc.save(os, SaveFormat.PDF);// 全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | }finally { |
| | | if (os != null) { |
| | | try { |
| | | os.flush(); |
| | | os.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | private static void insertWaterMark(Document doc, String watermarkText) throws Exception { |
| | | Shape watermark = new Shape(doc, ShapeType.TEXT_PLAIN_TEXT); |
| | | watermark.getTextPath().setText(watermarkText); |
| | | |
| | | //设置水印样式 |
| | | //watermark.getTextPath().setFontFamily("Arial");//设置字体 |
| | | watermark.getTextPath().setFontFamily("宋体");//设置字体 |
| | | watermark.setRotation(-40);//设置偏移角度 |
| | | watermark.setHeight(100);//水印高度 |
| | | watermark.setWidth(200);//水印宽度 |
| | | watermark.setFillColor(Color.pink);//设置填充颜色 |
| | | watermark.setStrokeColor(Color.pink);//设置描边颜色 |
| | | |
| | | //官方api给的解释 太官方了 (只插入一条水印 默认为这些数据) |
| | | watermark.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);//指定相对于水平放置的位置 |
| | | watermark.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);//指定相对于形状垂直定位的位置 |
| | | |
| | | //watermark.setWrapType(WrapType.TOP_BOTTOM);//定义水印的环绕模式 |
| | | watermark.setWrapType(WrapType.NONE);//定义水印的环绕模式 |
| | | watermark.setVerticalAlignment(VerticalAlignment.CENTER);// 指定形状垂直放置的方式 |
| | | watermark.setHorizontalAlignment(HorizontalAlignment.CENTER);// 指定形状如何水平放置 |
| | | |
| | | |
| | | Paragraph watermarkPara = new Paragraph(doc); |
| | | watermarkPara.appendChild(watermark); |
| | | |
| | | /*String text = watermarkPara.getText(); |
| | | System.out.println("++++++++++" + text); |
| | | System.out.println("______________" + watermarkPara); |
| | | NodeCollection childNodes = watermarkPara.getChildNodes(); |
| | | String text1 = childNodes.get(0).getText(); |
| | | System.out.println("111111" + text);*/ |
| | | for (Section section : doc.getSections()) { |
| | | InsertWatermarkIntoHeader(watermarkPara, section, HeaderFooterType.HEADER_PRIMARY); |
| | | InsertWatermarkIntoHeader(watermarkPara, section, HeaderFooterType.HEADER_FIRST); |
| | | InsertWatermarkIntoHeader(watermarkPara, section, HeaderFooterType.HEADER_EVEN); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 将水印插入图像头部 |
| | | * @param watermarkPara |
| | | * @param section |
| | | * @param headerType |
| | | */ |
| | | private static void InsertWatermarkIntoHeader(Paragraph watermarkPara, Section section, int headerType) throws Exception { |
| | | HeaderFooterCollection headerFooters = section.getHeadersFooters(); |
| | | HeaderFooter footer = headerFooters.getByHeaderFooterType(headerType); |
| | | if (footer == null) { |
| | | footer = new HeaderFooter(section.getDocument(), headerType); |
| | | section.getHeadersFooters().add(footer); |
| | | } |
| | | footer.appendChild(watermarkPara.deepClone(true)); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | doc2pdfWithWaterMark("C:\\Users\\29550\\Desktop\\当前项目\\202207图纸管理\\流程卡和SOP的doc审批注入\\新FBI系列流程卡签字2.doc", |
| | | "C:\\Users\\29550\\Desktop\\当前项目\\202207图纸管理\\流程卡和SOP的doc审批注入\\新FBI系列流程卡签字2-doc.pdf"); |
| | | } |
| | | } |
| | | |
New file |
| | |
| | | package com.whyc.util; |
| | | |
| | | import com.deepoove.poi.XWPFTemplate; |
| | | |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | |
| | | public class WordUtil { |
| | | |
| | | public static void fillValue(String inFilePath, String outFilePath, List valueList) throws IOException { |
| | | HashMap<String,Object> hashMap = new HashMap<>(); |
| | | hashMap.put("fzr", valueList.get(0)); |
| | | hashMap.put("bz", valueList.get(1)); |
| | | hashMap.put("zz", valueList.get(2)); |
| | | hashMap.put("pb", valueList.get(3)); |
| | | XWPFTemplate template = XWPFTemplate.compile(inFilePath).render(hashMap); |
| | | template.write(new FileOutputStream(outFilePath)); |
| | | |
| | | |
| | | /*//获取临时文件 |
| | | File file = new File(filePath); |
| | | HackLoopTableRenderPolicy policy = new HackLoopTableRenderPolicy(); |
| | | Configure config = Configure.newBuilder().bind("detailList", policy).build(); |
| | | XWPFTemplate template = XWPFTemplate.compile(filePath, config).render( |
| | | new HashMap<String, Object>() {{ |
| | | put("fzr", "负责人"); |
| | | put("bz", "编制"); |
| | | put("zz", "制造"); |
| | | put("pb", "品保"); |
| | | }} |
| | | ); |
| | | //生成文件名 |
| | | Long time = new Date().getTime(); |
| | | // 生成的word格式 |
| | | String fileName = time + ".docx"; |
| | | System.out.println("文件名:" + fileName); |
| | | //=================生成word到设置浏览默认下载地址================= |
| | | //解决文件下载名称变为 ____下划线的BUG |
| | | //针对IE或者以IE为内核的浏览器: |
| | | String userAgent = request.getHeader("User-Agent"); |
| | | if (userAgent.contains("MSIE") || userAgent.contains("Trident")) { |
| | | fileName = java.net.URLEncoder.encode(fileName, StandardCharsets.UTF_8.toString()); |
| | | } else { |
| | | //非IE浏览器: |
| | | fileName = new String(fileName.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1); |
| | | // 设置强制下载不打开 |
| | | response.setContentType("application/force-download"); |
| | | // 设置文件名 |
| | | response.addHeader("Content-Disposition", "attachment;fileName=" + fileName); |
| | | response.setCharacterEncoding("UTF-8"); |
| | | OutputStream out = response.getOutputStream(); |
| | | template.write(out); |
| | | out.flush(); |
| | | out.close(); |
| | | template.close(); |
| | | }*/ |
| | | } |
| | | } |