diff --git a/src/main/java/com/dreamchaser/depository_manage/controller/DownLoadFileController.java b/src/main/java/com/dreamchaser/depository_manage/controller/DownLoadFileController.java index 09d51729..72f8df81 100644 --- a/src/main/java/com/dreamchaser/depository_manage/controller/DownLoadFileController.java +++ b/src/main/java/com/dreamchaser/depository_manage/controller/DownLoadFileController.java @@ -162,4 +162,7 @@ public class DownLoadFileController { + + + } diff --git a/src/main/java/com/dreamchaser/depository_manage/controller/ExcelController.java b/src/main/java/com/dreamchaser/depository_manage/controller/ExcelController.java index 74cac204..1d2a6692 100644 --- a/src/main/java/com/dreamchaser/depository_manage/controller/ExcelController.java +++ b/src/main/java/com/dreamchaser/depository_manage/controller/ExcelController.java @@ -46,4 +46,7 @@ public class ExcelController { public ResultVo importInventory(@RequestParam("file") MultipartFile excel){ return excelService.importExcelInventory(excel); } + + + } diff --git a/src/main/java/com/dreamchaser/depository_manage/entity/ApplicationOutRecord.java b/src/main/java/com/dreamchaser/depository_manage/entity/ApplicationOutRecord.java index 59709d84..e560f8aa 100644 --- a/src/main/java/com/dreamchaser/depository_manage/entity/ApplicationOutRecord.java +++ b/src/main/java/com/dreamchaser/depository_manage/entity/ApplicationOutRecord.java @@ -164,5 +164,12 @@ public class ApplicationOutRecord { private Integer adminorgId; + /** + * 出库时间 + */ + private String outTime; + + + } diff --git a/src/main/java/com/dreamchaser/depository_manage/entity/ExcelInfoByMinWrite.java b/src/main/java/com/dreamchaser/depository_manage/entity/ExcelInfoByMinWrite.java new file mode 100644 index 00000000..a1cf60ce --- /dev/null +++ b/src/main/java/com/dreamchaser/depository_manage/entity/ExcelInfoByMinWrite.java @@ -0,0 +1,44 @@ +package com.dreamchaser.depository_manage.entity; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 用于打印的类 + */ +@Data +@EqualsAndHashCode +public class ExcelInfoByMinWrite { + /** + * 物料编码: + */ + private String mcode; + /** + * 物料名称: + */ + private String mname; + /** + * 规格型号: + */ + private String mversion; + /** + * 单位: + */ + private String munit; + /** + * 库位 + */ + private String pcode; + /** + * 数量 : + */ + private String quantity; + + /** + * 项目 + */ + private String project; + + + +} diff --git a/src/main/java/com/dreamchaser/depository_manage/entity/ExcelInfoByWrite.java b/src/main/java/com/dreamchaser/depository_manage/entity/ExcelInfoByWrite.java new file mode 100644 index 00000000..e9613c72 --- /dev/null +++ b/src/main/java/com/dreamchaser/depository_manage/entity/ExcelInfoByWrite.java @@ -0,0 +1,51 @@ +package com.dreamchaser.depository_manage.entity; + +import com.dreamchaser.depository_manage.pojo.ApplicationOutRecordP; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 用于打印的类 + */ +@Data +@EqualsAndHashCode +public class ExcelInfoByWrite { + /** + * 出库单号: + */ + private String code; + /** + * 出库日期: + */ + private String outTime; + /** + * 出库类别: + */ + private String type; + /** + * 仓库: + */ + private String dname; + /** + * 部门: + */ + private String adminorgName; + /** + * 申请人: + */ + private String applicantName; + /** + * 施工单位: + */ + private String constructionUnitName; + /** + * 审核人: + */ + private String checkerName; + /** + * 制单人 + */ + private String producerName; + + +} diff --git a/src/main/java/com/dreamchaser/depository_manage/mapper/DepositoryRecordMapper.xml b/src/main/java/com/dreamchaser/depository_manage/mapper/DepositoryRecordMapper.xml index 02ac3d96..4947e298 100644 --- a/src/main/java/com/dreamchaser/depository_manage/mapper/DepositoryRecordMapper.xml +++ b/src/main/java/com/dreamchaser/depository_manage/mapper/DepositoryRecordMapper.xml @@ -115,6 +115,7 @@ + @@ -170,7 +171,7 @@ aorid,mid,mname,depositoryId,dname,applicantId,applicantTime,applyRemark,aorcode,aorpirce,aorquantity,departmenthead,departmentheadPass,departmentHeadTime,departmentheadMessage, depositoryManager,depositoryManagerPass,depositoryManagerTime,depositoryManagerMessage,aorstate,istransfer,mcode,placeId,pass,aormUnit,aormconstructionunitid,aormadminorgid,cuname, - cuintroduce,cuaddress + cuintroduce,cuaddress,outTime @@ -1444,6 +1445,9 @@ placeId = #{placeId}, + + outTime = #{outTime}, + pass = #{pass} diff --git a/src/main/java/com/dreamchaser/depository_manage/pojo/ApplicationOutRecordP.java b/src/main/java/com/dreamchaser/depository_manage/pojo/ApplicationOutRecordP.java index b2ab9833..2bd40859 100644 --- a/src/main/java/com/dreamchaser/depository_manage/pojo/ApplicationOutRecordP.java +++ b/src/main/java/com/dreamchaser/depository_manage/pojo/ApplicationOutRecordP.java @@ -1,6 +1,7 @@ package com.dreamchaser.depository_manage.pojo; import com.dreamchaser.depository_manage.entity.ApplicationOutRecord; +import com.dreamchaser.depository_manage.utils.DateUtil; import lombok.Data; @Data @@ -164,6 +165,12 @@ public class ApplicationOutRecordP { */ private Integer adminorgId; + + /** + * 出库时间 + */ + private String outTime; + public ApplicationOutRecordP(ApplicationOutRecord aor) { this.id = aor.getId(); this.mid = aor.getMid(); @@ -197,5 +204,6 @@ public class ApplicationOutRecordP { this.constructionUnitId = aor.getConstructionUnitId(); this.constructionUnitName = aor.getConstructionUnitName(); this.adminorgId = aor.getAdminorgId(); + this.outTime = aor.getOutTime() == null ? "": DateUtil.TimeStampToDateTime(Long.valueOf(aor.getOutTime())); } } diff --git a/src/main/java/com/dreamchaser/depository_manage/service/ExcelService.java b/src/main/java/com/dreamchaser/depository_manage/service/ExcelService.java index 0740c9e5..2367ae10 100644 --- a/src/main/java/com/dreamchaser/depository_manage/service/ExcelService.java +++ b/src/main/java/com/dreamchaser/depository_manage/service/ExcelService.java @@ -1,5 +1,6 @@ package com.dreamchaser.depository_manage.service; +import com.dreamchaser.depository_manage.entity.UserByPort; import com.dreamchaser.depository_manage.exception.MyException; import com.dreamchaser.depository_manage.utils.ResultVo; import org.springframework.web.multipart.MultipartFile; @@ -27,4 +28,14 @@ public interface ExcelService { * @return */ ResultVo importExcelInventory(MultipartFile file); + + + /** + * 用于出库订单填充 + * @param id 待打印出库订单id + */ + String writeExcelForPrint(Integer id, UserByPort userToken); + + + } diff --git a/src/main/java/com/dreamchaser/depository_manage/service/impl/DepositoryRecordServiceImpl.java b/src/main/java/com/dreamchaser/depository_manage/service/impl/DepositoryRecordServiceImpl.java index 68f8d809..467409bb 100644 --- a/src/main/java/com/dreamchaser/depository_manage/service/impl/DepositoryRecordServiceImpl.java +++ b/src/main/java/com/dreamchaser/depository_manage/service/impl/DepositoryRecordServiceImpl.java @@ -1785,6 +1785,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { Map map = new HashMap<>(); map.put("pass", pass); map.put("id", record.getId()); + map.put("outTime",System.currentTimeMillis()); // 修改状态为完成 depositoryRecordMapper.updateApplicationOutRecord(map); diff --git a/src/main/java/com/dreamchaser/depository_manage/service/impl/ExcelServiceImpl.java b/src/main/java/com/dreamchaser/depository_manage/service/impl/ExcelServiceImpl.java index 0cb4a8fc..c621d820 100644 --- a/src/main/java/com/dreamchaser/depository_manage/service/impl/ExcelServiceImpl.java +++ b/src/main/java/com/dreamchaser/depository_manage/service/impl/ExcelServiceImpl.java @@ -1,7 +1,15 @@ package com.dreamchaser.depository_manage.service.impl; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.ExcelWriter; +import com.alibaba.excel.enums.WriteDirectionEnum; +import com.alibaba.excel.util.ListUtils; +import com.alibaba.excel.write.metadata.WriteSheet; +import com.alibaba.excel.write.metadata.fill.FillConfig; +import com.alibaba.excel.write.metadata.fill.FillWrapper; import com.alibaba.fastjson.JSON; import com.dreamchaser.depository_manage.entity.*; +import com.dreamchaser.depository_manage.mapper.ConstructionUnitMapper; import com.dreamchaser.depository_manage.mapper.DepositoryRecordMapper; import com.dreamchaser.depository_manage.mapper.MaterialMapper; import com.dreamchaser.depository_manage.pojo.InventoryP; @@ -48,6 +56,10 @@ public class ExcelServiceImpl implements ExcelService { @Autowired DepositoryRecordMapper depositoryRecordMapper; + + @Autowired + ConstructionUnitMapper constructionUnitMapper; + /** * 用于导入物料名称 * @@ -317,7 +329,7 @@ public class ExcelServiceImpl implements ExcelService { String code = excelInfoByInventory.getCode(); if (code != null && !"".equals(code)) { material = materialService.findMaterialByCode(code); - }else{ + } else { material = materialMapper.findMaterialByCondition(insert).get(0); } } @@ -412,4 +424,83 @@ public class ExcelServiceImpl implements ExcelService { log.info("【导入Excel文件】删除临时文件成功,临时文件路径为:{}", filePath); return ResultVoUtil.returnResultVo(200, readResult, "结果"); } + + /** + * 用于出库订单填充 + * + * @param id 待打印出库订单id + */ + @Override + public String writeExcelForPrint(Integer id, UserByPort userToken) { + // 获取要打印的出库主单 + ApplicationOutRecord record = depositoryRecordMapper.findApplicationOutRecordPById(id); + List recordMinList = depositoryRecordMapper.findApplicationOutRecordMinByParent(id); + // 表格模板 + String templateFileName = "D://PrintTemplate.xlsx"; + // 生成的表格 + String fileName = "D://PrintTemplate" + System.currentTimeMillis() + ".xlsx"; + // 待打印主数据列表 + List data = ListUtils.newArrayList(); + List dataMin = ListUtils.newArrayList(); + // 主数据 + ExcelInfoByWrite excelInfoByWrite = new ExcelInfoByWrite(); + String outTime = record.getOutTime(); + if (outTime == null || "".equals(outTime)) { + excelInfoByWrite.setOutTime(""); + } else { + excelInfoByWrite.setOutTime(DateUtil.TimeStampToDateTimeForDay(Long.valueOf(outTime))); + } + excelInfoByWrite.setDname(record.getDepositoryName()); + excelInfoByWrite.setCode(record.getCode()); + UserByPort applicanter = LinkInterfaceUtil.FindUserById(record.getApplicantId(), userToken); + Administration company = LinkInterfaceUtil.getCompany(record.getAdminorgId(), userToken); + excelInfoByWrite.setApplicantName(applicanter.getName()); + excelInfoByWrite.setAdminorgName(company.getName()); + Integer unitId = record.getConstructionUnitId(); + if (unitId != null) { + ConstructionUnit constructionUnitById = constructionUnitMapper.findConstructionUnitById(unitId); + excelInfoByWrite.setConstructionUnitName(constructionUnitById.getName()); + } else { + excelInfoByWrite.setConstructionUnitName(""); + } + UserByPort checker = LinkInterfaceUtil.FindUserById(record.getDepositoryId(), userToken); + excelInfoByWrite.setCheckerName(checker.getName()); + data.add(excelInfoByWrite); + double total = 0; + for (ApplicationOutRecordMin recordMin : recordMinList + ) { + ExcelInfoByMinWrite excelInfoByMinWrite = new ExcelInfoByMinWrite(); + Material materialById = materialMapper.findMaterialById(recordMin.getMid()); + excelInfoByMinWrite.setMname(materialById.getMname()); + excelInfoByMinWrite.setMcode(materialById.getCode()); + if ("-1".equals(recordMin.getUnit()) || materialById.getUnit().equals(recordMin.getUnit())) { + excelInfoByMinWrite.setMunit(materialById.getUnit()); + } else { + excelInfoByMinWrite.setMunit(recordMin.getUnit()); + } + excelInfoByMinWrite.setMversion(materialById.getVersion()); + Integer placeId = recordMin.getPlaceId(); + String pcode = ""; + if (placeId != null) { + Place placeById = placeService.findPlaceById(placeId); + pcode = placeById.getKingdeecode(); + } + excelInfoByMinWrite.setPcode(pcode); + excelInfoByMinWrite.setQuantity(String.valueOf(recordMin.getQuantity() / 100)); + dataMin.add(excelInfoByMinWrite); + total += (double) (recordMin.getQuantity() / 100); + } + try (ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build()) { + WriteSheet writeSheet = EasyExcel.writerSheet().build(); + FillConfig fillConfig = FillConfig.builder().direction(WriteDirectionEnum.HORIZONTAL).build(); + // 如果有多个list 模板上必须有{前缀.} 这里的前缀就是 data1,然后多个list必须用 FillWrapper包裹 + excelWriter.fill(new FillWrapper("data", data), fillConfig, writeSheet); + excelWriter.fill(new FillWrapper("mindata", dataMin), writeSheet); + Map map = new HashMap(); + map.put("date", DateUtil.TimeStampToDateTime(System.currentTimeMillis())); + map.put("total", total); + excelWriter.fill(map, writeSheet); + } + return fileName; + } } diff --git a/src/main/resources/static/upload/PrintTemplate.xlsx b/src/main/resources/static/upload/PrintTemplate.xlsx new file mode 100644 index 00000000..3ba81511 Binary files /dev/null and b/src/main/resources/static/upload/PrintTemplate.xlsx differ diff --git a/src/test/java/com/dreamchaser/depository_manage/TestForOther.java b/src/test/java/com/dreamchaser/depository_manage/TestForOther.java index 766a7b98..8e9ad043 100644 --- a/src/test/java/com/dreamchaser/depository_manage/TestForOther.java +++ b/src/test/java/com/dreamchaser/depository_manage/TestForOther.java @@ -1,5 +1,12 @@ package com.dreamchaser.depository_manage; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.ExcelWriter; +import com.alibaba.excel.enums.WriteDirectionEnum; +import com.alibaba.excel.util.ListUtils; +import com.alibaba.excel.write.metadata.WriteSheet; +import com.alibaba.excel.write.metadata.fill.FillConfig; +import com.alibaba.excel.write.metadata.fill.FillWrapper; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONPObject; @@ -35,6 +42,9 @@ public class TestForOther { @Autowired DepositoryRecordService depositoryRecordService; + @Autowired + ExcelService excelService; + @Test @@ -44,11 +54,15 @@ public class TestForOther { // approver.setUserId("PangFuZhen"); // approvalInfo.setApprover(approver); // depositoryRecordService.reviewByQyWxApprovalOut("1",approvalInfo,"460f46eaefb46bb0c171029f62e2cea6","2","202303180021", false,2); - + UserByPort userByPort = LinkInterfaceUtil.FindUserById(78, null); + String s = excelService.writeExcelForPrint(1, userByPort); } + + + }