Commit c24c5ac8 by kangxiaoshan

DMP 收入导入

parent bd6da457
...@@ -3,6 +3,7 @@ package common.repository; ...@@ -3,6 +3,7 @@ package common.repository;
import common.model.Contract; import common.model.Contract;
import common.model.Role; import common.model.Role;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -153,4 +154,9 @@ public interface ContractRepository extends JpaRepository<Contract, Long> { ...@@ -153,4 +154,9 @@ public interface ContractRepository extends JpaRepository<Contract, Long> {
@Query(value = "select id from contract where contract_code = ?1 ", nativeQuery = true) @Query(value = "select id from contract where contract_code = ?1 ", nativeQuery = true)
List<Long> findIdByCode(String relationCode); List<Long> findIdByCode(String relationCode);
@Transactional
@Modifying
@Query(value = "delete from contract where contract_code = ?1 and platform=?2", nativeQuery = true)
void deleteByCode(String contractCode, String platform);
} }
...@@ -182,7 +182,7 @@ public class DmpIncomeServiceImpl implements DmpIncomeService { ...@@ -182,7 +182,7 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
if (workbook == null) { if (workbook == null) {
return ResultModel.ERROR("获取上传文件错误"); return ResultModel.ERROR("获取上传文件错误");
} }
int rowNumber = checkSheetTitle(workbook, "合同编号\t收入月份\t结算周期\t系统结算\t按月结算\t税率\t确认收入", "\t"); int rowNumber = checkSheetTitle(workbook, platform + "_income");
if (rowNumber == -1) { if (rowNumber == -1) {
return ResultModel.ERROR("模板表头错误"); return ResultModel.ERROR("模板表头错误");
} else if (rowNumber <= 1) { } else if (rowNumber <= 1) {
...@@ -220,7 +220,7 @@ public class DmpIncomeServiceImpl implements DmpIncomeService { ...@@ -220,7 +220,7 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
return ResultModel.ERROR("请上传对应项目模板处理的数据"); return ResultModel.ERROR("请上传对应项目模板处理的数据");
} }
int rowNumber = checkSheetTitle(workbook, "我方签约主体\t客户签约主体\t客户简称\t第三方签约主体\t行政区域\t隶属集团\t行业分类\t合同开始日期\t合同结束日期\t签约销售\t客户主账号\t合同编号\t签约类型\t业务类型\t协议类型\t合同金额\t关联合同编号", "\t"); int rowNumber = checkSheetTitle(workbook, platform);
if (rowNumber == -1) { if (rowNumber == -1) {
return ResultModel.ERROR("模板表头错误"); return ResultModel.ERROR("模板表头错误");
} else if (rowNumber <= 1) { } else if (rowNumber <= 1) {
...@@ -232,8 +232,8 @@ public class DmpIncomeServiceImpl implements DmpIncomeService { ...@@ -232,8 +232,8 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
.stream().collect(Collectors.toMap(TradeType::getName, TradeType::getId)); .stream().collect(Collectors.toMap(TradeType::getName, TradeType::getId));
Map<String, Long> salseMap = salesRepository.findSaleByStatus(0) Map<String, Long> salseMap = salesRepository.findSaleByStatus(0)
.stream().collect(Collectors.toMap(Sales::getName, Sales::getId)); .stream().collect(Collectors.toMap(Sales::getName, Sales::getId));
Map<String, Long> barrioCityMap = barrioCityRepository.findAll() Map<Long, String> barrioCityMap = barrioCityRepository.findAll()
.stream().collect(Collectors.toMap(BarrioCity::getName, BarrioCity::getId)); .stream().collect(Collectors.toMap(BarrioCity::getId, BarrioCity::getName));
Map<String, String> cBodyMap = contractBodyRepository.findAllDis() Map<String, String> cBodyMap = contractBodyRepository.findAllDis()
.stream().collect(Collectors.toMap(ContractBody::getName, ContractBody::getCode, (v1, v2) -> v1)); .stream().collect(Collectors.toMap(ContractBody::getName, ContractBody::getCode, (v1, v2) -> v1));
...@@ -250,7 +250,7 @@ public class DmpIncomeServiceImpl implements DmpIncomeService { ...@@ -250,7 +250,7 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
contract.setType("main"); contract.setType("main");
contract.setCreateAccount(loginAccount.getId()); contract.setCreateAccount(loginAccount.getId());
contract.setCreateName(loginAccount.getName()); contract.setCreateName(loginAccount.getName());
contract.setCreateTime(new Date());
contract.setDs(DateTime.now().toString("yyyy-MM-dd")); contract.setDs(DateTime.now().toString("yyyy-MM-dd"));
//填充数据 //填充数据
...@@ -274,16 +274,16 @@ public class DmpIncomeServiceImpl implements DmpIncomeService { ...@@ -274,16 +274,16 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
return erroValueTip(i, "客户签约主体"); return erroValueTip(i, "客户签约主体");
} }
if (!barrioCityMap.containsKey(contract.getBarrioName())) { if (!barrioCityMap.containsKey(contract.getBarrioId())) {
return erroValueTip(i, "行政区域"); return erroValueTip(i, "行政区域");
} else { } else {
contract.setBarrioId(barrioCityMap.get(contract.getBarrioName())); contract.setBarrioName(barrioCityMap.get(contract.getBarrioId()));
} }
if (!salseMap.containsKey(contract.getSaleName())) { if (!salseMap.containsKey(contract.getSaleName())) {
return erroValueTip(i, "签约销售"); return erroValueTip(i, "签约销售");
} else { } else {
contract.setSale(salseMap.get(contract.getMyBodyName())); contract.setSale(salseMap.get(contract.getSaleName()));
} }
if (StringUtils.isEmpty(contract.getEmail())) { if (StringUtils.isEmpty(contract.getEmail())) {
...@@ -293,7 +293,10 @@ public class DmpIncomeServiceImpl implements DmpIncomeService { ...@@ -293,7 +293,10 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
if (StringUtils.isEmpty(contract.getContractCode())) { if (StringUtils.isEmpty(contract.getContractCode())) {
return erroValueTip(i, "合同编号"); return erroValueTip(i, "合同编号");
} else { } else {
contract.setCodeNum(Integer.parseInt(contract.getContractCode().split("-")[3])); String[] codeArr = contract.getContractCode().split("-");
if (codeArr.length == 4) {
contract.setCodeNum(Integer.parseInt(codeArr[3]));
}
} }
if (!CONTRACT_TYPE_NAME.containsKey(contract.getContractType())) { if (!CONTRACT_TYPE_NAME.containsKey(contract.getContractType())) {
...@@ -329,7 +332,6 @@ public class DmpIncomeServiceImpl implements DmpIncomeService { ...@@ -329,7 +332,6 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
ExecutorService executorService = Executors.newFixedThreadPool(35); ExecutorService executorService = Executors.newFixedThreadPool(35);
CompletableFuture[] futures = allContracts.stream() CompletableFuture[] futures = allContracts.stream()
.map(contract -> CompletableFuture.runAsync(() -> { .map(contract -> CompletableFuture.runAsync(() -> {
if (!StringUtils.isEmpty(contract.getRelationCode())) { if (!StringUtils.isEmpty(contract.getRelationCode())) {
List<Long> idList = contractRepository.findIdByCode(contract.getRelationCode()); List<Long> idList = contractRepository.findIdByCode(contract.getRelationCode());
if (!idList.isEmpty()) { if (!idList.isEmpty()) {
...@@ -343,6 +345,10 @@ public class DmpIncomeServiceImpl implements DmpIncomeService { ...@@ -343,6 +345,10 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
if (contract.getRelationContract() < 0) { if (contract.getRelationContract() < 0) {
contract.setRelationCode(null); contract.setRelationCode(null);
} }
//删除已经重复的记录
contractRepository.deleteByCode(contract.getContractCode(), platform);
contract.setCreateTime(new Date());
contractRepository.save(contract); contractRepository.save(contract);
}, executorService).exceptionally((t) -> null) }, executorService).exceptionally((t) -> null)
...@@ -357,19 +363,35 @@ public class DmpIncomeServiceImpl implements DmpIncomeService { ...@@ -357,19 +363,35 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
return ResultModel.OK(); return ResultModel.OK();
} }
private int checkSheetTitle(Workbook workbook, String sheetTitle, String code) { private int checkSheetTitle(Workbook workbook, String platform) {
String sheetTitle = null;
String code = "\t";
if ("dmp".equals(platform)) {
//dmp 合同
sheetTitle = "我方签约主体\t客户签约主体\t客户简称\t第三方签约主体\t行政区域\t隶属集团\t行业分类\t合同开始日期\t合同结束日期\t签约销售\t客户主账号\t合同编号\t签约类型\t业务类型\t协议类型\t合同金额\t关联合同编号";
} else if ("dmp_income".equals(platform)) {
//dmp 收入
sheetTitle = "合同编号\t收入月份\t结算周期\t系统结算\t按月结算\t税率\t确认收入";
}
if (sheetTitle == null) {
return -1;
}
Sheet sheet = workbook.getSheetAt(0); Sheet sheet = workbook.getSheetAt(0);
Row row = sheet.getRow(0); Row row = sheet.getRow(0);
int titleLength = sheetTitle.split("\t").length; int sheLength = sheetTitle.split("\t").length;
StringBuffer titleUp = new StringBuffer(); StringBuffer titleUp = new StringBuffer();
for (int i = 0; i < titleLength; i++) { for (int i = 0; i < sheLength; i++) {
if (i > 0) titleUp.append(code); if (i > 0) titleUp.append(code);
titleUp.append(row.getCell(i)); titleUp.append(row.getCell(i));
} }
if (!titleUp.toString().equals(sheetTitle)) { if (!titleUp.toString().equals(sheetTitle)) {
return -1; return -1;
} }
return titleLength;
//总行数
sheLength = sheet.getLastRowNum() + 1;
return sheLength;
} }
private Workbook getWorkbook(MultipartFile excelfile) { private Workbook getWorkbook(MultipartFile excelfile) {
...@@ -399,7 +421,7 @@ public class DmpIncomeServiceImpl implements DmpIncomeService { ...@@ -399,7 +421,7 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
//合同编号 收入月份 结算周期 系统结算 按月结算 税率 确认收入 //合同编号 收入月份 结算周期 系统结算 按月结算 税率 确认收入
DmpIncome income = new DmpIncome(); DmpIncome income = new DmpIncome();
income.setContractCode(getCellStringValue(rowItem, 0)); income.setContractCode(getCellStringValue(rowItem, 0));
income.setIncomeMonth(getCellStringValue(rowItem, 1)); income.setIncomeMonth(getCellDateValue(rowItem, 1, "yyyy-MM"));
income.setPeriod(getCellStringValue(rowItem, 2)); income.setPeriod(getCellStringValue(rowItem, 2));
income.setSysSettlement(getCellStringValue(rowItem, 3)); income.setSysSettlement(getCellStringValue(rowItem, 3));
income.setMonthSettlement(getCellStringValue(rowItem, 4)); income.setMonthSettlement(getCellStringValue(rowItem, 4));
...@@ -411,6 +433,13 @@ public class DmpIncomeServiceImpl implements DmpIncomeService { ...@@ -411,6 +433,13 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
if (StringUtils.isEmpty(income.getContractCode())) { if (StringUtils.isEmpty(income.getContractCode())) {
return null; return null;
} }
//保留小数
income.setConfirmSettlement(new BigDecimal(income.getConfirmSettlement()).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
//
income.setTaxRate(Double.parseDouble(income.getTaxRate()) * 100 + "%");
if (StringUtils.isEmpty(income.getSysSettlement())) {
income.setSysSettlement("0");
}
DmpIncome one = dmpIncomeRepository.findByCodeMonth(income.getContractCode(), income.getIncomeMonth()); DmpIncome one = dmpIncomeRepository.findByCodeMonth(income.getContractCode(), income.getIncomeMonth());
if (one != null) { if (one != null) {
...@@ -423,6 +452,10 @@ public class DmpIncomeServiceImpl implements DmpIncomeService { ...@@ -423,6 +452,10 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
} }
private String getCellDateValue(Row row, int index) { private String getCellDateValue(Row row, int index) {
return getCellDateValue(row, index, null);
}
private String getCellDateValue(Row row, int index, String fm) {
Cell cell = row.getCell(index); Cell cell = row.getCell(index);
if (cell == null) { if (cell == null) {
...@@ -431,14 +464,19 @@ public class DmpIncomeServiceImpl implements DmpIncomeService { ...@@ -431,14 +464,19 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
String dfmate = cell.getCellStyle().getDataFormatString(); String dfmate = cell.getCellStyle().getDataFormatString();
if (!"yyyy/mm;@".equals(dfmate) && !"m/d/yy".equals(dfmate) && !"yy/m/d".equals(dfmate) && !"mm/dd/yy".equals(dfmate) && !"dd-mmm-yy".equals(dfmate) && !"yyyy/m/d".equals(dfmate) && !"yyyy/m/d;@".equals(dfmate)) { if (!"yyyy/mm;@".equals(dfmate) && !"m/d/yy".equals(dfmate) && !"yy/m/d".equals(dfmate) && !"mm/dd/yy".equals(dfmate) && !"dd-mmm-yy".equals(dfmate) && !"yyyy/m/d".equals(dfmate) && !"yyyy/m/d;@".equals(dfmate) && !"yyyy\"年\"m\"月\";@".equals(dfmate)) {
return "erro"; return "erro";
} }
if (fm == null) {
fm = "yyyy-MM-dd";
}
if (org.apache.poi.ss.usermodel.DateUtil.isCellDateFormatted(cell)) { if (org.apache.poi.ss.usermodel.DateUtil.isCellDateFormatted(cell)) {
// 用于转化为日期格式 // 用于转化为日期格式
Date d = cell.getDateCellValue(); Date d = cell.getDateCellValue();
DateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
DateFormat formater = new SimpleDateFormat(fm);
return formater.format(d); return formater.format(d);
} }
return cell.toString(); return cell.toString();
...@@ -446,7 +484,7 @@ public class DmpIncomeServiceImpl implements DmpIncomeService { ...@@ -446,7 +484,7 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
private String getCellStringValue(Row row, int index) { private String getCellStringValue(Row row, int index) {
Cell cell = row.getCell(index); Cell cell = row.getCell(index);
return cell == null ? "" : cell.toString(); return cell == null ? "" : cell.toString().trim();
} }
private String getCellStringValue(Row row, int index, String defaulValue) { private String getCellStringValue(Row row, int index, String defaulValue) {
...@@ -461,7 +499,7 @@ public class DmpIncomeServiceImpl implements DmpIncomeService { ...@@ -461,7 +499,7 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
contract.setCustomerShort(getCellStringValue(rowItem, 2)); contract.setCustomerShort(getCellStringValue(rowItem, 2));
// 第三方签约主体 行政区域 隶属集团 行业分类 // 第三方签约主体 行政区域 隶属集团 行业分类
contract.setCustomerThird(getCellStringValue(rowItem, 3)); contract.setCustomerThird(getCellStringValue(rowItem, 3));
contract.setBarrioName(getCellStringValue(rowItem, 4)); contract.setBarrioId(new BigDecimal(getCellStringValue(rowItem, 4, "0")).longValue());
contract.setBelongGroup(getCellStringValue(rowItem, 5)); contract.setBelongGroup(getCellStringValue(rowItem, 5));
contract.setTradeName(getCellStringValue(rowItem, 6)); contract.setTradeName(getCellStringValue(rowItem, 6));
// 合同开始日期 合同结束日期 签约销售 客户主账号 // 合同开始日期 合同结束日期 签约销售 客户主账号
......
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