|
|
@ -428,34 +428,48 @@ public class ExcelServiceImpl implements ExcelService { |
|
|
/** |
|
|
/** |
|
|
* 用于出库订单填充 |
|
|
* 用于出库订单填充 |
|
|
* |
|
|
* |
|
|
* @param id 待打印出库订单id |
|
|
* @param id 待打印出库订单id |
|
|
|
|
|
* @param userToken 调用接口人员 |
|
|
|
|
|
* @param pageSize 一张最多打印条数 |
|
|
*/ |
|
|
*/ |
|
|
@Override |
|
|
@Override |
|
|
public String writeExcelForPrint(Integer id, UserByPort userToken) { |
|
|
public List<String> writeExcelForPrint(Integer id, Integer pageSize, UserByPort userToken) { |
|
|
|
|
|
// 生成的表格名称列表
|
|
|
|
|
|
List<String> fileNameList = new ArrayList<>(); |
|
|
// 获取要打印的出库主单
|
|
|
// 获取要打印的出库主单
|
|
|
ApplicationOutRecord record = depositoryRecordMapper.findApplicationOutRecordPById(id); |
|
|
ApplicationOutRecord record = depositoryRecordMapper.findApplicationOutRecordPById(id); |
|
|
|
|
|
// 获取要打印的所有子单
|
|
|
List<ApplicationOutRecordMin> recordMinList = depositoryRecordMapper.findApplicationOutRecordMinByParent(id); |
|
|
List<ApplicationOutRecordMin> 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 templateFileName = "D://PrintTemplate.xlsx"; |
|
|
// 生成的表格
|
|
|
|
|
|
String fileName = "D://PrintTemplate" + System.currentTimeMillis() + ".xlsx"; |
|
|
|
|
|
// 待打印主数据列表
|
|
|
// 待打印主数据列表
|
|
|
List<ExcelInfoByWrite> data = ListUtils.newArrayList(); |
|
|
List<ExcelInfoByWrite> data = ListUtils.newArrayList(); |
|
|
List<ExcelInfoByMinWrite> dataMin = ListUtils.newArrayList(); |
|
|
|
|
|
// 主数据
|
|
|
// 主数据
|
|
|
ExcelInfoByWrite excelInfoByWrite = new ExcelInfoByWrite(); |
|
|
ExcelInfoByWrite excelInfoByWrite = new ExcelInfoByWrite(); |
|
|
|
|
|
// 获取出库时间
|
|
|
String outTime = record.getOutTime(); |
|
|
String outTime = record.getOutTime(); |
|
|
if (outTime == null || "".equals(outTime)) { |
|
|
if (outTime == null || "".equals(outTime)) { |
|
|
excelInfoByWrite.setOutTime(""); |
|
|
excelInfoByWrite.setOutTime(""); |
|
|
} else { |
|
|
} else { |
|
|
excelInfoByWrite.setOutTime(DateUtil.TimeStampToDateTimeForDay(Long.valueOf(outTime))); |
|
|
excelInfoByWrite.setOutTime(DateUtil.TimeStampToDateTimeForDay(Long.valueOf(outTime))); |
|
|
} |
|
|
} |
|
|
|
|
|
// 设置仓库名称
|
|
|
excelInfoByWrite.setDname(record.getDepositoryName()); |
|
|
excelInfoByWrite.setDname(record.getDepositoryName()); |
|
|
|
|
|
// 设置单号
|
|
|
excelInfoByWrite.setCode(record.getCode()); |
|
|
excelInfoByWrite.setCode(record.getCode()); |
|
|
|
|
|
// 获取当前出库单申请人
|
|
|
UserByPort applicanter = LinkInterfaceUtil.FindUserById(record.getApplicantId(), userToken); |
|
|
UserByPort applicanter = LinkInterfaceUtil.FindUserById(record.getApplicantId(), userToken); |
|
|
Administration company = LinkInterfaceUtil.getCompany(record.getAdminorgId(), userToken); |
|
|
// 设置申请人名称
|
|
|
excelInfoByWrite.setApplicantName(applicanter.getName()); |
|
|
excelInfoByWrite.setApplicantName(applicanter.getName()); |
|
|
excelInfoByWrite.setAdminorgName(company.getName()); |
|
|
// 获取施工单位Id
|
|
|
Integer unitId = record.getConstructionUnitId(); |
|
|
Integer unitId = record.getConstructionUnitId(); |
|
|
if (unitId != null) { |
|
|
if (unitId != null) { |
|
|
ConstructionUnit constructionUnitById = constructionUnitMapper.findConstructionUnitById(unitId); |
|
|
ConstructionUnit constructionUnitById = constructionUnitMapper.findConstructionUnitById(unitId); |
|
|
@ -463,44 +477,117 @@ public class ExcelServiceImpl implements ExcelService { |
|
|
} else { |
|
|
} else { |
|
|
excelInfoByWrite.setConstructionUnitName(""); |
|
|
excelInfoByWrite.setConstructionUnitName(""); |
|
|
} |
|
|
} |
|
|
UserByPort checker = LinkInterfaceUtil.FindUserById(record.getDepositoryId(), userToken); |
|
|
// 获取审核人id
|
|
|
excelInfoByWrite.setCheckerName(checker.getName()); |
|
|
String recordDepartmenthead = record.getDepartmenthead(); |
|
|
data.add(excelInfoByWrite); |
|
|
if (recordDepartmenthead != null) { |
|
|
double total = 0; |
|
|
StringBuilder sb = new StringBuilder(); |
|
|
for (ApplicationOutRecordMin recordMin : recordMinList |
|
|
String[] split = recordDepartmenthead.split(","); |
|
|
) { |
|
|
for (String s : split |
|
|
ExcelInfoByMinWrite excelInfoByMinWrite = new ExcelInfoByMinWrite(); |
|
|
) { |
|
|
Material materialById = materialMapper.findMaterialById(recordMin.getMid()); |
|
|
if ("".equals(s)) { |
|
|
excelInfoByMinWrite.setMname(materialById.getMname()); |
|
|
continue; |
|
|
excelInfoByMinWrite.setMcode(materialById.getCode()); |
|
|
} |
|
|
if ("-1".equals(recordMin.getUnit()) || materialById.getUnit().equals(recordMin.getUnit())) { |
|
|
UserByPort checker = LinkInterfaceUtil.FindUserById(ObjectFormatUtil.toInteger(s), userToken); |
|
|
excelInfoByMinWrite.setMunit(materialById.getUnit()); |
|
|
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<ExcelInfoByMinWrite> 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 { |
|
|
} else { |
|
|
excelInfoByMinWrite.setMunit(recordMin.getUnit()); |
|
|
excelInfoByWrite.setAdminorgName(""); |
|
|
} |
|
|
} |
|
|
excelInfoByMinWrite.setMversion(materialById.getVersion()); |
|
|
if (record.getApplyRemark() != null) { |
|
|
Integer placeId = recordMin.getPlaceId(); |
|
|
// 设置出库类别
|
|
|
String pcode = ""; |
|
|
excelInfoByWrite.setType(record.getApplyRemark()); |
|
|
if (placeId != null) { |
|
|
} else { |
|
|
Place placeById = placeService.findPlaceById(placeId); |
|
|
excelInfoByWrite.setType(""); |
|
|
pcode = placeById.getKingdeecode(); |
|
|
|
|
|
} |
|
|
} |
|
|
excelInfoByMinWrite.setPcode(pcode); |
|
|
if (data.size() <= 0) { |
|
|
excelInfoByMinWrite.setQuantity(String.valueOf(recordMin.getQuantity() / 100)); |
|
|
data.add(excelInfoByWrite); |
|
|
dataMin.add(excelInfoByMinWrite); |
|
|
} |
|
|
total += (double) (recordMin.getQuantity() / 100); |
|
|
// 生成的表格
|
|
|
} |
|
|
String fileName = "D://PrintTemplate" + System.currentTimeMillis() + ".xlsx"; |
|
|
try (ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build()) { |
|
|
try (ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build()) { |
|
|
WriteSheet writeSheet = EasyExcel.writerSheet().build(); |
|
|
WriteSheet writeSheet = EasyExcel.writerSheet().build(); |
|
|
FillConfig fillConfig = FillConfig.builder().direction(WriteDirectionEnum.HORIZONTAL).build(); |
|
|
FillConfig fillConfig = FillConfig.builder().direction(WriteDirectionEnum.HORIZONTAL).build(); |
|
|
// 如果有多个list 模板上必须有{前缀.} 这里的前缀就是 data1,然后多个list必须用 FillWrapper包裹
|
|
|
// 如果有多个list 模板上必须有{前缀.} 这里的前缀就是 data1,然后多个list必须用 FillWrapper包裹
|
|
|
excelWriter.fill(new FillWrapper("data", data), fillConfig, writeSheet); |
|
|
excelWriter.fill(new FillWrapper("data", data), fillConfig, writeSheet); |
|
|
excelWriter.fill(new FillWrapper("mindata", dataMin), writeSheet); |
|
|
excelWriter.fill(new FillWrapper("mindata", dataMin), writeSheet); |
|
|
Map<String, Object> map = new HashMap<String, Object>(); |
|
|
Map<String, Object> map = new HashMap<String, Object>(); |
|
|
map.put("date", DateUtil.TimeStampToDateTime(System.currentTimeMillis())); |
|
|
map.put("date", DateUtil.TimeStampToDateTime(System.currentTimeMillis())); |
|
|
map.put("total", total); |
|
|
map.put("total", total); |
|
|
excelWriter.fill(map, writeSheet); |
|
|
map.put("page", i); |
|
|
|
|
|
map.put("pagesum", pagesum); |
|
|
|
|
|
excelWriter.fill(map, writeSheet); |
|
|
|
|
|
} |
|
|
|
|
|
fileNameList.add(fileName); |
|
|
} |
|
|
} |
|
|
return fileName; |
|
|
return fileNameList; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|