diff --git a/src/main/java/com/dreamchaser/depository_manage/controller/DepositoryRecordController.java b/src/main/java/com/dreamchaser/depository_manage/controller/DepositoryRecordController.java index 1701bf85..7e10f6cc 100644 --- a/src/main/java/com/dreamchaser/depository_manage/controller/DepositoryRecordController.java +++ b/src/main/java/com/dreamchaser/depository_manage/controller/DepositoryRecordController.java @@ -541,7 +541,7 @@ public class DepositoryRecordController { Map insert = new HashMap<>(); insert.put("applicantId", userToken.getId()); insert.put("mid", map.get("mid" + temp)); - insert.put("quantity", map.get("quantity" + temp)); + insert.put("quantity",(int)(ObjectFormatUtil.toDouble(map.get("quantity" + temp)) * 100)); insert.put("applyRemark", map.get("applyRemark" + temp)); insert.put("code", map.get("code")); insert.put("placeId", map.get("placeId")); @@ -1419,10 +1419,10 @@ public class DepositoryRecordController { // 出库物料 Integer mid = iids.get(i); // 出库数量 - Integer integer = ObjectFormatUtil.toInteger(quantitys.get(i)); + Double integer = ObjectFormatUtil.toDouble(quantitys.get(i)); // 获取当前仓库编号 Integer depositoryId = depositoryIds.get(i); - String quantity = integer.toString(); + String quantity = String.valueOf((int)(integer * 100)); // 获取库位 String placeCode = placeCodes.get(i); 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 e560f8aa..35f4b6dc 100644 --- a/src/main/java/com/dreamchaser/depository_manage/entity/ApplicationOutRecord.java +++ b/src/main/java/com/dreamchaser/depository_manage/entity/ApplicationOutRecord.java @@ -40,7 +40,7 @@ public class ApplicationOutRecord { private String applicantName; /** - * 申请时间 + * 申请时间 */ private String applicantTime; @@ -48,7 +48,7 @@ public class ApplicationOutRecord { /** * 备注 */ - private String applyRemark; + private String applyRemark; /** * 出货单号 @@ -171,5 +171,4 @@ public class ApplicationOutRecord { - } 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 2bd40859..4ce068cc 100644 --- a/src/main/java/com/dreamchaser/depository_manage/pojo/ApplicationOutRecordP.java +++ b/src/main/java/com/dreamchaser/depository_manage/pojo/ApplicationOutRecordP.java @@ -42,7 +42,7 @@ public class ApplicationOutRecordP { private String applicantName; /** - * 申请时间 + * 申请时间 */ private String applicantTime; @@ -50,7 +50,7 @@ public class ApplicationOutRecordP { /** * 备注 */ - private String applyRemark; + private String applyRemark; /** * 出货单号 @@ -171,6 +171,7 @@ public class ApplicationOutRecordP { */ private String outTime; + public ApplicationOutRecordP(ApplicationOutRecord aor) { this.id = aor.getId(); this.mid = aor.getMid(); @@ -183,7 +184,7 @@ public class ApplicationOutRecordP { this.applyRemark = aor.getApplyRemark(); this.code = aor.getCode(); this.price = aor.getPrice(); - this.quantity = (double)aor.getQuantity() / 100; + this.quantity = (double) aor.getQuantity() / 100; this.departmenthead = aor.getDepartmenthead(); this.departmentheadName = aor.getDepartmentheadName(); this.departmentheadPass = aor.getDepartmentheadPass(); @@ -204,6 +205,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())); + 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 2367ae10..2a2bc69e 100644 --- a/src/main/java/com/dreamchaser/depository_manage/service/ExcelService.java +++ b/src/main/java/com/dreamchaser/depository_manage/service/ExcelService.java @@ -5,6 +5,8 @@ import com.dreamchaser.depository_manage.exception.MyException; import com.dreamchaser.depository_manage.utils.ResultVo; import org.springframework.web.multipart.MultipartFile; +import java.util.List; + public interface ExcelService { /** @@ -32,9 +34,12 @@ public interface ExcelService { /** * 用于出库订单填充 + * * @param id 待打印出库订单id + * @param userToken 调用接口人员 + * @param pageSize 一张最多打印条数 */ - String writeExcelForPrint(Integer id, UserByPort userToken); + List writeExcelForPrint(Integer id, Integer pageSize, UserByPort userToken); 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 c621d820..fe2bc184 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 @@ -428,34 +428,48 @@ public class ExcelServiceImpl implements ExcelService { /** * 用于出库订单填充 * - * @param id 待打印出库订单id + * @param id 待打印出库订单id + * @param userToken 调用接口人员 + * @param pageSize 一张最多打印条数 */ @Override - public String writeExcelForPrint(Integer id, UserByPort userToken) { + public List writeExcelForPrint(Integer id, Integer pageSize, UserByPort userToken) { + // 生成的表格名称列表 + List fileNameList = new ArrayList<>(); // 获取要打印的出库主单 ApplicationOutRecord record = depositoryRecordMapper.findApplicationOutRecordPById(id); + // 获取要打印的所有子单 List recordMinList = depositoryRecordMapper.findApplicationOutRecordMinByParent(id); - // 表格模板 + // 定义打印页数 + int pagesum = 1; + // 计算新页数 + if (recordMinList.size() > pageSize) { + pagesum = (int) Math.ceil(recordMinList.size() / (double) pageSize); + } + // 读取表格模板 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()); + // 获取施工单位Id Integer unitId = record.getConstructionUnitId(); if (unitId != null) { ConstructionUnit constructionUnitById = constructionUnitMapper.findConstructionUnitById(unitId); @@ -463,44 +477,117 @@ public class ExcelServiceImpl implements ExcelService { } 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()); + // 获取审核人id + String recordDepartmenthead = record.getDepartmenthead(); + if (recordDepartmenthead != null) { + StringBuilder sb = new StringBuilder(); + String[] split = recordDepartmenthead.split(","); + for (String s : split + ) { + if ("".equals(s)) { + continue; + } + UserByPort checker = LinkInterfaceUtil.FindUserById(ObjectFormatUtil.toInteger(s), userToken); + sb.append(checker.getName()); + } + // 设置审核人名称 + excelInfoByWrite.setCheckerName(sb.toString()); + } else { + excelInfoByWrite.setCheckerName(""); + } + // 设置制单人名称 + excelInfoByWrite.setProducerName(userToken.getName()); + // 定义部门id + Integer adminorgId = null; + // 定义部门 + Administration company = null; + for (int i = 1; i <= pagesum; i++) { + // 定义打印子单数据 + List dataMin = ListUtils.newArrayList(); + // 定义当前出库总数 + double total = 0; + // 定义最多数 + int ceil = i * pageSize; + if (ceil > recordMinList.size()) { + ceil = recordMinList.size(); + } + // 循环打印 + for (int j = (i - 1) * pageSize; j < ceil; j++) { + // 获取当前待打印的子数据 + ApplicationOutRecordMin recordMin = recordMinList.get(j); + // 定义打印数据 + 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); + if (adminorgId == null) { + // 如果没有选择部门 + adminorgId = recordMin.getAdminorgId(); + } + } + if (adminorgId != null && company == null) { + company = LinkInterfaceUtil.getCompany(adminorgId, userToken); + // 设置部门名称 + excelInfoByWrite.setAdminorgName(company.getName()); } else { - excelInfoByMinWrite.setMunit(recordMin.getUnit()); + excelInfoByWrite.setAdminorgName(""); } - excelInfoByMinWrite.setMversion(materialById.getVersion()); - Integer placeId = recordMin.getPlaceId(); - String pcode = ""; - if (placeId != null) { - Place placeById = placeService.findPlaceById(placeId); - pcode = placeById.getKingdeecode(); + if (record.getApplyRemark() != null) { + // 设置出库类别 + excelInfoByWrite.setType(record.getApplyRemark()); + } else { + excelInfoByWrite.setType(""); + } - 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); + if (data.size() <= 0) { + data.add(excelInfoByWrite); + } + // 生成的表格 + String fileName = "D://PrintTemplate" + System.currentTimeMillis() + ".xlsx"; + 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); + map.put("page", i); + map.put("pagesum", pagesum); + excelWriter.fill(map, writeSheet); + } + fileNameList.add(fileName); } - return fileName; + return fileNameList; } } diff --git a/src/test/java/com/dreamchaser/depository_manage/TestForOther.java b/src/test/java/com/dreamchaser/depository_manage/TestForOther.java index 8e9ad043..ccc896d6 100644 --- a/src/test/java/com/dreamchaser/depository_manage/TestForOther.java +++ b/src/test/java/com/dreamchaser/depository_manage/TestForOther.java @@ -55,7 +55,7 @@ public class TestForOther { // approvalInfo.setApprover(approver); // depositoryRecordService.reviewByQyWxApprovalOut("1",approvalInfo,"460f46eaefb46bb0c171029f62e2cea6","2","202303180021", false,2); UserByPort userByPort = LinkInterfaceUtil.FindUserById(78, null); - String s = excelService.writeExcelForPrint(1, userByPort); + List s = excelService.writeExcelForPrint(2, 4,userByPort); }