Commit f34710fb by liyanlin

fix

parent 97cd1386
...@@ -65,15 +65,15 @@ public class CostPlanServiceFactory { ...@@ -65,15 +65,15 @@ public class CostPlanServiceFactory {
*/ */
private static final Integer BORROW = 0b0010; private static final Integer BORROW = 0b0010;
private static CostTypeService getCostTypeService(){ private static CostTypeService getCostTypeService() {
return SpringContextUtil.getBean(CostTypeServiceImpl.class); return SpringContextUtil.getBean(CostTypeServiceImpl.class);
} }
private static CostCompanyService getCostCompanyService(){ private static CostCompanyService getCostCompanyService() {
return SpringContextUtil.getBean(CostCompanyServiceImpl.class); return SpringContextUtil.getBean(CostCompanyServiceImpl.class);
} }
private static CostPlanTempService getCostPlanTempService(){ private static CostPlanTempService getCostPlanTempService() {
return SpringContextUtil.getBean(CostPlanTempServiceImpl.class); return SpringContextUtil.getBean(CostPlanTempServiceImpl.class);
} }
...@@ -114,7 +114,7 @@ public class CostPlanServiceFactory { ...@@ -114,7 +114,7 @@ public class CostPlanServiceFactory {
* @param zip * @param zip
* @return * @return
*/ */
public static Map<CostPlanService, List<CostPlanDomain>> getCostPlanService(File zip,String userCode) throws Exception { public static Map<CostPlanService, List<CostPlanDomain>> getCostPlanService(File zip, String userCode) throws Exception {
Map<CostPlanService, List<CostPlanDomain>> costPlanServiceListMap = new HashMap<>(); Map<CostPlanService, List<CostPlanDomain>> costPlanServiceListMap = new HashMap<>();
Map<String, File> fileMap = new HashMap<>(); Map<String, File> fileMap = new HashMap<>();
List<String> createdPlanNos = new ArrayList<>(); List<String> createdPlanNos = new ArrayList<>();
...@@ -122,23 +122,23 @@ public class CostPlanServiceFactory { ...@@ -122,23 +122,23 @@ public class CostPlanServiceFactory {
ZipArchiveEntry entry; ZipArchiveEntry entry;
while ((entry = inputStream.getNextZipEntry()) != null) { while ((entry = inputStream.getNextZipEntry()) != null) {
if (!entry.isDirectory()) { if (!entry.isDirectory()) {
File tempFile = File.createTempFile(UidUtils.VM_ID,entry.getName()); File tempFile = File.createTempFile(UidUtils.VM_ID, entry.getName());
OutputStream outputStream = new FileOutputStream(tempFile); OutputStream outputStream = new FileOutputStream(tempFile);
IOUtils.copy(inputStream,outputStream); IOUtils.copy(inputStream, outputStream);
outputStream.close(); outputStream.close();
fileMap.put(entry.getName(),tempFile); fileMap.put(entry.getName(), tempFile);
} }
} }
File feeExcel = fileMap.get("costPlan.xlsx"); File feeExcel = fileMap.get("costPlan.xlsx");
if(feeExcel == null){ if (feeExcel == null) {
throw new Exception("缺少文件【costPlan.xlsx】"); throw new Exception("缺少文件【costPlan.xlsx】");
} }
InputStream feeIn = new FileInputStream(feeExcel); InputStream feeIn = new FileInputStream(feeExcel);
Workbook wb = new XSSFWorkbook(feeIn); Workbook wb = new XSSFWorkbook(feeIn);
for(int sheetIndex=0;sheetIndex<=3;sheetIndex++){ for (int sheetIndex = 0; sheetIndex <= 3; sheetIndex++) {
Sheet sheet = wb.getSheetAt(sheetIndex); Sheet sheet = wb.getSheetAt(sheetIndex);
if (sheet != null && sheet.getLastRowNum() > 0) { if (sheet != null && sheet.getLastRowNum() > 0) {
costPlanServiceListMap.putAll(getCostPlan(sheet,fileMap,userCode,createdPlanNos)); costPlanServiceListMap.putAll(getCostPlan(sheet, fileMap, userCode, createdPlanNos));
} }
} }
...@@ -158,19 +158,20 @@ public class CostPlanServiceFactory { ...@@ -158,19 +158,20 @@ public class CostPlanServiceFactory {
/** /**
* 获取费用计划 * 获取费用计划
*
* @param sheet * @param sheet
* @param fileMap * @param fileMap
* @param userCode * @param userCode
* @return * @return
* @throws Exception * @throws Exception
*/ */
private static Map<CostPlanService, List<CostPlanDomain>> getCostPlan(Sheet sheet,Map<String, File> fileMap,String userCode,List<String> createdPlanNos) throws Exception { private static Map<CostPlanService, List<CostPlanDomain>> getCostPlan(Sheet sheet, Map<String, File> fileMap, String userCode, List<String> createdPlanNos) throws Exception {
Row firstRow = sheet.getRow(0); Row firstRow = sheet.getRow(0);
String sheetName = sheet.getSheetName(); String sheetName = sheet.getSheetName();
Map<CostPlanService, List<CostPlanDomain>> costPlanServiceListMap = new HashMap<>(); Map<CostPlanService, List<CostPlanDomain>> costPlanServiceListMap = new HashMap<>();
List<CostPlanDomain> costPlanDomainList = new ArrayList<>(); List<CostPlanDomain> costPlanDomainList = new ArrayList<>();
Map<String, CostTypeResult> costTypeResultMap = new HashMap<>(); Map<String, CostTypeResult> costTypeResultMap = new HashMap<>();
Map<Integer, Map<CostPlanDomain,List<AddItemReq>>> costPlanAndItemMap = new HashMap<>(); Map<Integer, Map<CostPlanDomain, List<AddItemReq>>> costPlanAndItemMap = new HashMap<>();
//公司主体映射 //公司主体映射
Map<String, CostCompanyDomain> costCompanyDomainMap = getCostCompanyService().costCompanyMap(); Map<String, CostCompanyDomain> costCompanyDomainMap = getCostCompanyService().costCompanyMap();
for (int i = 1; i <= sheet.getLastRowNum(); i++) { for (int i = 1; i <= sheet.getLastRowNum(); i++) {
...@@ -180,14 +181,13 @@ public class CostPlanServiceFactory { ...@@ -180,14 +181,13 @@ public class CostPlanServiceFactory {
for (int j = 0; j < firstRow.getLastCellNum(); j++) { for (int j = 0; j < firstRow.getLastCellNum(); j++) {
String costPlanField = CostPlanEnumVo.getCostPlanField(sheetName, firstRow.getCell(j).toString()); String costPlanField = CostPlanEnumVo.getCostPlanField(sheetName, firstRow.getCell(j).toString());
if (!costPlanField.equals("")) { if (!costPlanField.equals("")) {
if((!costPlanField.equals("costRemark") && !costPlanField.equals("customerNum")) && (row.getCell(j) == null || row.getCell(j).toString().trim().equals(""))){ if ((!costPlanField.equals("costRemark") && !costPlanField.equals("customerNum")) && (row.getCell(j) == null || row.getCell(j).toString().trim().equals(""))) {
throw new BizException("请填写必填项"); throw new BizException("请填写必填项");
} }
if(costPlanField.equals("costRemark") && sheetName.equals("付款") && (row.getCell(j) == null || row.getCell(j).toString().trim().equals(""))) if (costPlanField.equals("costRemark") && sheetName.equals("付款") && (row.getCell(j) == null || row.getCell(j).toString().trim().equals(""))) {
{
throw new BizException("付款单备注为必填项"); throw new BizException("付款单备注为必填项");
} }
jsonObject.put(costPlanField, row.getCell(j).toString()); jsonObject.put(costPlanField, row.getCell(j) == null ? null : row.getCell(j).toString());
} }
} }
CostPlanDomain costPlanDomain = jsonObject.toJavaObject(CostPlanDomain.class); CostPlanDomain costPlanDomain = jsonObject.toJavaObject(CostPlanDomain.class);
...@@ -196,8 +196,8 @@ public class CostPlanServiceFactory { ...@@ -196,8 +196,8 @@ public class CostPlanServiceFactory {
//上传文件 //上传文件
File currentFile = fileMap.get(costPlanDomain.getFilePath()); File currentFile = fileMap.get(costPlanDomain.getFilePath());
if(currentFile == null){ if (currentFile == null) {
throw new BizException("找不到文件:"+ costPlanDomain.getFilePath()); throw new BizException("找不到文件:" + costPlanDomain.getFilePath());
} }
String path = CostFileUtil.qiniuUpload(currentFile); String path = CostFileUtil.qiniuUpload(currentFile);
currentFile.deleteOnExit(); currentFile.deleteOnExit();
...@@ -220,7 +220,7 @@ public class CostPlanServiceFactory { ...@@ -220,7 +220,7 @@ public class CostPlanServiceFactory {
costPlanDomain.setCompanyNo(costCompanyDomain.getCompanyNo()); costPlanDomain.setCompanyNo(costCompanyDomain.getCompanyNo());
costPlanDomain.setCompanyValue(costCompanyDomain.getValue()); costPlanDomain.setCompanyValue(costCompanyDomain.getValue());
if (!sheetName.equals("付款")) { if (!sheetName.equals("付款")) {
if(sheetName.equals("借还")){ if (sheetName.equals("借还")) {
//借还的lendType = 借支的借支类别 //借还的lendType = 借支的借支类别
CostTypeResult lendTypeCostTypeResult = costTypeResultMap.get("借支" + costPlanDomain.getLendType()); CostTypeResult lendTypeCostTypeResult = costTypeResultMap.get("借支" + costPlanDomain.getLendType());
if (lendTypeCostTypeResult == null) { if (lendTypeCostTypeResult == null) {
...@@ -229,8 +229,8 @@ public class CostPlanServiceFactory { ...@@ -229,8 +229,8 @@ public class CostPlanServiceFactory {
} }
//借支信息 //借支信息
CostDomain supCost = getCostService().getCostByCostNo(costPlanDomain.getSupCostNo()); CostDomain supCost = getCostService().getCostByCostNo(costPlanDomain.getSupCostNo());
if(supCost == null || !supCost.getCreateUsercode().equalsIgnoreCase(userCode) || !(supCost.getCostForm().equals(3) && supCost.getIsLend().equals(1))){ if (supCost == null || !supCost.getCreateUsercode().equalsIgnoreCase(userCode) || !(supCost.getCostForm().equals(3) && supCost.getIsLend().equals(1))) {
throw new BizRuntimeException("费用单"+costPlanDomain.getSupCostNo()+"无法作为借还单的关联借支单,请检查是否填写正确"); throw new BizRuntimeException("费用单" + costPlanDomain.getSupCostNo() + "无法作为借还单的关联借支单,请检查是否填写正确");
} }
//借支 //借支
costPlanDomain.setCounteract(supCost.getCounteract()); costPlanDomain.setCounteract(supCost.getCounteract());
...@@ -249,7 +249,7 @@ public class CostPlanServiceFactory { ...@@ -249,7 +249,7 @@ public class CostPlanServiceFactory {
} }
//计划单号 //计划单号
String planNo = getCostPlanService().createNo(); String planNo = getCostPlanService().createNo();
while (createdPlanNos.contains(planNo)){ while (createdPlanNos.contains(planNo)) {
planNo = getCostPlanService().createNo(); planNo = getCostPlanService().createNo();
} }
createdPlanNos.add(planNo); createdPlanNos.add(planNo);
...@@ -266,7 +266,7 @@ public class CostPlanServiceFactory { ...@@ -266,7 +266,7 @@ public class CostPlanServiceFactory {
costPlanDomainList.add(costPlanDomain); costPlanDomainList.add(costPlanDomain);
//log.info(costPlanDomain.toString()); //log.info(costPlanDomain.toString());
}else{ } else {
//付款,需要保存 //付款,需要保存
//AddItemReq //AddItemReq
AddItemReq itemReq = jsonObject.toJavaObject(AddItemReq.class); AddItemReq itemReq = jsonObject.toJavaObject(AddItemReq.class);
...@@ -276,11 +276,11 @@ public class CostPlanServiceFactory { ...@@ -276,11 +276,11 @@ public class CostPlanServiceFactory {
costPlanDomain.setFilePath(null); costPlanDomain.setFilePath(null);
Integer costPlanHash = (costPlanDomain.getCompanyValue() + costPlanDomain.getBankCard() Integer costPlanHash = (costPlanDomain.getCompanyValue() + costPlanDomain.getBankCard()
+ costPlanDomain.getBankCompany() + costPlanDomain.getBankName()).hashCode(); + costPlanDomain.getBankCompany() + costPlanDomain.getBankName()).hashCode();
Map<CostPlanDomain,List<AddItemReq>> planItemMap = costPlanAndItemMap.get(costPlanHash); Map<CostPlanDomain, List<AddItemReq>> planItemMap = costPlanAndItemMap.get(costPlanHash);
if(planItemMap == null){ if (planItemMap == null) {
//计划单号 //计划单号
String planNo = getCostPlanService().createNo(); String planNo = getCostPlanService().createNo();
while (createdPlanNos.contains(planNo)){ while (createdPlanNos.contains(planNo)) {
planNo = getCostPlanService().createNo(); planNo = getCostPlanService().createNo();
} }
createdPlanNos.add(planNo); createdPlanNos.add(planNo);
...@@ -292,24 +292,23 @@ public class CostPlanServiceFactory { ...@@ -292,24 +292,23 @@ public class CostPlanServiceFactory {
add(itemReq); add(itemReq);
} }
}); });
costPlanAndItemMap.put(costPlanHash,planItemMap); costPlanAndItemMap.put(costPlanHash, planItemMap);
} } else {
else{
String currentCostPlanNo = planItemMap.keySet().stream().map(x -> x.getCostPlanNo()).findFirst().get(); String currentCostPlanNo = planItemMap.keySet().stream().map(x -> x.getCostPlanNo()).findFirst().get();
itemReq.setCostPlanNo(currentCostPlanNo); itemReq.setCostPlanNo(currentCostPlanNo);
planItemMap.values().stream().findFirst().get().add(itemReq); planItemMap.values().stream().findFirst().get().add(itemReq);
} }
} }
} }
if(costPlanAndItemMap.size() > 0){ if (costPlanAndItemMap.size() > 0) {
costPlanAndItemMap.values().forEach(x ->{ costPlanAndItemMap.values().forEach(x -> {
x.entrySet().forEach(y -> { x.entrySet().forEach(y -> {
y.getValue().forEach(v ->{ y.getValue().forEach(v -> {
}); });
y.getValue().forEach(throwingConsumerWrapper(v ->{ y.getValue().forEach(throwingConsumerWrapper(v -> {
AddItemResp resp = getCostPlanTempService().doSave(v); AddItemResp resp = getCostPlanTempService().doSave(v);
if (!resp.getSuccess()){ if (!resp.getSuccess()) {
throw new Exception("保存item异常"); throw new Exception("保存item异常");
} }
})); }));
...@@ -319,14 +318,20 @@ public class CostPlanServiceFactory { ...@@ -319,14 +318,20 @@ public class CostPlanServiceFactory {
}); });
}); });
} }
switch (sheetName){ switch (sheetName) {
case "付款": case "付款":
costPlanDomainList.forEach(x -> {x.setCostForm(1);x.setCostTemplateId(3);}); costPlanDomainList.forEach(x -> {
costPlanServiceListMap.put(SpringContextUtil.getBean(CostPlanNewPayServiceImpl.class),costPlanDomainList); x.setCostForm(1);
x.setCostTemplateId(3);
});
costPlanServiceListMap.put(SpringContextUtil.getBean(CostPlanNewPayServiceImpl.class), costPlanDomainList);
break; break;
case "收款": case "收款":
costPlanDomainList.forEach(x -> {x.setCostForm(2);x.setCostTemplateId(5);}); costPlanDomainList.forEach(x -> {
costPlanServiceListMap.put(SpringContextUtil.getBean(CostPlanNewReceiptServiceImpl.class),costPlanDomainList); x.setCostForm(2);
x.setCostTemplateId(5);
});
costPlanServiceListMap.put(SpringContextUtil.getBean(CostPlanNewReceiptServiceImpl.class), costPlanDomainList);
break; break;
case "借支": case "借支":
costPlanDomainList.forEach(x -> { costPlanDomainList.forEach(x -> {
...@@ -334,7 +339,7 @@ public class CostPlanServiceFactory { ...@@ -334,7 +339,7 @@ public class CostPlanServiceFactory {
x.setIsLend(1); x.setIsLend(1);
x.setCostTemplateId(6); x.setCostTemplateId(6);
}); });
costPlanServiceListMap.put(SpringContextUtil.getBean(CostPlanNewLend1ServiceImpl.class),costPlanDomainList); costPlanServiceListMap.put(SpringContextUtil.getBean(CostPlanNewLend1ServiceImpl.class), costPlanDomainList);
break; break;
case "借还": case "借还":
costPlanDomainList.forEach(x -> { costPlanDomainList.forEach(x -> {
...@@ -342,13 +347,13 @@ public class CostPlanServiceFactory { ...@@ -342,13 +347,13 @@ public class CostPlanServiceFactory {
x.setIsLend(2); x.setIsLend(2);
x.setCostTemplateId(7); x.setCostTemplateId(7);
}); });
costPlanServiceListMap.put(SpringContextUtil.getBean(CostPlanNewLend2ServiceImpl.class),costPlanDomainList); costPlanServiceListMap.put(SpringContextUtil.getBean(CostPlanNewLend2ServiceImpl.class), costPlanDomainList);
break; break;
} }
return costPlanServiceListMap; return costPlanServiceListMap;
} }
private static CostTypeResult getCostType(String sheetName,String typeName) throws Exception { private static CostTypeResult getCostType(String sheetName, String typeName) throws Exception {
Integer feeType = 0; Integer feeType = 0;
switch (sheetName) { switch (sheetName) {
case "付款": case "付款":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment