Browse Source

添加表格填充功能

lwx_dev
erdanergou 3 years ago
parent
commit
ea3ba9ec83
  1. 6
      src/main/java/com/dreamchaser/depository_manage/controller/DepositoryRecordController.java
  2. 1
      src/main/java/com/dreamchaser/depository_manage/entity/ApplicationOutRecord.java
  3. 1
      src/main/java/com/dreamchaser/depository_manage/pojo/ApplicationOutRecordP.java
  4. 7
      src/main/java/com/dreamchaser/depository_manage/service/ExcelService.java
  5. 113
      src/main/java/com/dreamchaser/depository_manage/service/impl/ExcelServiceImpl.java
  6. 2
      src/test/java/com/dreamchaser/depository_manage/TestForOther.java

6
src/main/java/com/dreamchaser/depository_manage/controller/DepositoryRecordController.java

@ -541,7 +541,7 @@ public class DepositoryRecordController {
Map<String, Object> insert = new HashMap<>(); Map<String, Object> insert = new HashMap<>();
insert.put("applicantId", userToken.getId()); insert.put("applicantId", userToken.getId());
insert.put("mid", map.get("mid" + temp)); 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("applyRemark", map.get("applyRemark" + temp));
insert.put("code", map.get("code")); insert.put("code", map.get("code"));
insert.put("placeId", map.get("placeId")); insert.put("placeId", map.get("placeId"));
@ -1419,10 +1419,10 @@ public class DepositoryRecordController {
// 出库物料 // 出库物料
Integer mid = iids.get(i); Integer mid = iids.get(i);
// 出库数量 // 出库数量
Integer integer = ObjectFormatUtil.toInteger(quantitys.get(i)); Double integer = ObjectFormatUtil.toDouble(quantitys.get(i));
// 获取当前仓库编号 // 获取当前仓库编号
Integer depositoryId = depositoryIds.get(i); Integer depositoryId = depositoryIds.get(i);
String quantity = integer.toString(); String quantity = String.valueOf((int)(integer * 100));
// 获取库位 // 获取库位
String placeCode = placeCodes.get(i); String placeCode = placeCodes.get(i);

1
src/main/java/com/dreamchaser/depository_manage/entity/ApplicationOutRecord.java

@ -171,5 +171,4 @@ public class ApplicationOutRecord {
} }

1
src/main/java/com/dreamchaser/depository_manage/pojo/ApplicationOutRecordP.java

@ -171,6 +171,7 @@ public class ApplicationOutRecordP {
*/ */
private String outTime; private String outTime;
public ApplicationOutRecordP(ApplicationOutRecord aor) { public ApplicationOutRecordP(ApplicationOutRecord aor) {
this.id = aor.getId(); this.id = aor.getId();
this.mid = aor.getMid(); this.mid = aor.getMid();

7
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 com.dreamchaser.depository_manage.utils.ResultVo;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.util.List;
public interface ExcelService { public interface ExcelService {
/** /**
@ -32,9 +34,12 @@ public interface ExcelService {
/** /**
* 用于出库订单填充 * 用于出库订单填充
*
* @param id 待打印出库订单id * @param id 待打印出库订单id
* @param userToken 调用接口人员
* @param pageSize 一张最多打印条数
*/ */
String writeExcelForPrint(Integer id, UserByPort userToken); List<String> writeExcelForPrint(Integer id, Integer pageSize, UserByPort userToken);

113
src/main/java/com/dreamchaser/depository_manage/service/impl/ExcelServiceImpl.java

@ -429,33 +429,47 @@ 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,33 +477,102 @@ 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
) { ) {
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<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(); ExcelInfoByMinWrite excelInfoByMinWrite = new ExcelInfoByMinWrite();
// 获取出库物料信息
Material materialById = materialMapper.findMaterialById(recordMin.getMid()); Material materialById = materialMapper.findMaterialById(recordMin.getMid());
// 设置物料名称
excelInfoByMinWrite.setMname(materialById.getMname()); excelInfoByMinWrite.setMname(materialById.getMname());
// 设置物料编码
excelInfoByMinWrite.setMcode(materialById.getCode()); excelInfoByMinWrite.setMcode(materialById.getCode());
if ("-1".equals(recordMin.getUnit()) || materialById.getUnit().equals(recordMin.getUnit())) { if ("-1".equals(recordMin.getUnit()) || materialById.getUnit().equals(recordMin.getUnit())) {
// 如果申请出库的为基础单位
excelInfoByMinWrite.setMunit(materialById.getUnit()); excelInfoByMinWrite.setMunit(materialById.getUnit());
} else { } else {
// 如果为拆零单位
excelInfoByMinWrite.setMunit(recordMin.getUnit()); excelInfoByMinWrite.setMunit(recordMin.getUnit());
} }
// 设置物料型号
excelInfoByMinWrite.setMversion(materialById.getVersion()); excelInfoByMinWrite.setMversion(materialById.getVersion());
// 获取出库库位
Integer placeId = recordMin.getPlaceId(); Integer placeId = recordMin.getPlaceId();
// 定义库位编码
String pcode = ""; String pcode = "";
if (placeId != null) { if (placeId != null) {
Place placeById = placeService.findPlaceById(placeId); Place placeById = placeService.findPlaceById(placeId);
// 设置库存编码
pcode = placeById.getKingdeecode(); pcode = placeById.getKingdeecode();
} }
// 设置库位编码
excelInfoByMinWrite.setPcode(pcode); excelInfoByMinWrite.setPcode(pcode);
// 设置出库数量
excelInfoByMinWrite.setQuantity(String.valueOf(recordMin.getQuantity() / 100)); excelInfoByMinWrite.setQuantity(String.valueOf(recordMin.getQuantity() / 100));
// 添加到打印数据列表
dataMin.add(excelInfoByMinWrite); dataMin.add(excelInfoByMinWrite);
// 添加总数
total += (double) (recordMin.getQuantity() / 100); 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 {
excelInfoByWrite.setAdminorgName("");
}
if (record.getApplyRemark() != null) {
// 设置出库类别
excelInfoByWrite.setType(record.getApplyRemark());
} else {
excelInfoByWrite.setType("");
}
if (data.size() <= 0) {
data.add(excelInfoByWrite);
}
// 生成的表格
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();
@ -499,8 +582,12 @@ public class ExcelServiceImpl implements ExcelService {
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);
map.put("page", i);
map.put("pagesum", pagesum);
excelWriter.fill(map, writeSheet); excelWriter.fill(map, writeSheet);
} }
return fileName; fileNameList.add(fileName);
}
return fileNameList;
} }
} }

2
src/test/java/com/dreamchaser/depository_manage/TestForOther.java

@ -55,7 +55,7 @@ public class TestForOther {
// approvalInfo.setApprover(approver); // approvalInfo.setApprover(approver);
// depositoryRecordService.reviewByQyWxApprovalOut("1",approvalInfo,"460f46eaefb46bb0c171029f62e2cea6","2","202303180021", false,2); // depositoryRecordService.reviewByQyWxApprovalOut("1",approvalInfo,"460f46eaefb46bb0c171029f62e2cea6","2","202303180021", false,2);
UserByPort userByPort = LinkInterfaceUtil.FindUserById(78, null); UserByPort userByPort = LinkInterfaceUtil.FindUserById(78, null);
String s = excelService.writeExcelForPrint(1, userByPort); List<String> s = excelService.writeExcelForPrint(2, 4,userByPort);
} }

Loading…
Cancel
Save