Commit f34710fb by liyanlin

fix

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