Commit 81170a96 by kangxiaoshan

Merge branch '2578_bugfix'

parents 601bacca 84820006
...@@ -2,6 +2,7 @@ package common.controller; ...@@ -2,6 +2,7 @@ package common.controller;
import common.model.*; import common.model.*;
import common.service.ContractService; import common.service.ContractService;
import common.service.DmpIncomeService;
import common.service.ShareIncomeService; import common.service.ShareIncomeService;
import dic.AuthMenuEnmm; import dic.AuthMenuEnmm;
import dic.ContractStatusEnum; import dic.ContractStatusEnum;
...@@ -75,6 +76,9 @@ public class ContractController { ...@@ -75,6 +76,9 @@ public class ContractController {
@Autowired @Autowired
private ShareIncomeService shareIncomeService; private ShareIncomeService shareIncomeService;
@Autowired
private DmpIncomeService dmpIncomeService;
@RequestMapping(value = "find", method = RequestMethod.GET) @RequestMapping(value = "find", method = RequestMethod.GET)
@ResponseBody @ResponseBody
@AuthKey(AuthMenuEnmm.CONTRACTMNG_V) @AuthKey(AuthMenuEnmm.CONTRACTMNG_V)
...@@ -134,13 +138,13 @@ public class ContractController { ...@@ -134,13 +138,13 @@ public class ContractController {
HSSFRow row = sheet.createRow(0); HSSFRow row = sheet.createRow(0);
List<String> title; List<String> title;
if(platform.equals("tkio")){ if (platform.equals("tkio")) {
title = Arrays.asList("录入时间,合同编号,客户账号,我方签约主体,签约方,行政区域,隶属集团,行业分类,销售,开始日期,结束日期,套餐类型,合同流量(万次),赠送流量(万次),合同金额,签约类型,合同状态,回款状态,关联合同,关联合同编号,补充协议签订日期" title = Arrays.asList("录入时间,合同编号,客户账号,我方签约主体,签约方,行政区域,隶属集团,行业分类,销售,开始日期,结束日期,套餐类型,合同流量(万次),赠送流量(万次),合同金额,签约类型,合同状态,回款状态,关联合同,关联合同编号,补充协议签订日期"
.split(",")); .split(","));
}else if(platform.equals("cas")){ } else if (platform.equals("cas")) {
title = Arrays.asList("录入时间,合同编号,客户账号,我方签约主体,签约方,行政区域,隶属集团,行业分类,销售,开始日期,结束日期,套餐类型,有效期开始日有效期结束日,合同金额,签约类型,合同状态,回款状态,关联合同" title = Arrays.asList("录入时间,合同编号,客户账号,我方签约主体,签约方,行政区域,隶属集团,行业分类,销售,开始日期,结束日期,套餐类型,有效期开始日有效期结束日,合同金额,签约类型,合同状态,回款状态,关联合同"
.split(",")); .split(","));
}else{ } else {
title = Arrays.asList("录入时间,合同编号,客户账号,我方签约主体,签约方,行政区域,隶属集团,行业分类,销售,开始日期,结束日期,套餐类型,合同金额,签约类型,合同状态,回款状态,关联合同" title = Arrays.asList("录入时间,合同编号,客户账号,我方签约主体,签约方,行政区域,隶属集团,行业分类,销售,开始日期,结束日期,套餐类型,合同金额,签约类型,合同状态,回款状态,关联合同"
.split(",")); .split(","));
} }
...@@ -165,7 +169,7 @@ public class ContractController { ...@@ -165,7 +169,7 @@ public class ContractController {
rowBody.createCell(10).setCellValue(contract.getEndDate()); rowBody.createCell(10).setCellValue(contract.getEndDate());
rowBody.createCell(11).setCellValue(contract.getPriceLevelName()); rowBody.createCell(11).setCellValue(contract.getPriceLevelName());
if(platform.equals("tkio")){ if (platform.equals("tkio")) {
rowBody.createCell(12).setCellValue(contract.getTrackFlow() == null ? 0 : contract.getTrackFlow()); rowBody.createCell(12).setCellValue(contract.getTrackFlow() == null ? 0 : contract.getTrackFlow());
rowBody.createCell(13).setCellValue(contract.getExtraFlow() == null ? 0 : contract.getExtraFlow()); rowBody.createCell(13).setCellValue(contract.getExtraFlow() == null ? 0 : contract.getExtraFlow());
rowBody.createCell(14).setCellValue(contract.getMoney() == null ? 0 : contract.getMoney()); rowBody.createCell(14).setCellValue(contract.getMoney() == null ? 0 : contract.getMoney());
...@@ -175,8 +179,8 @@ public class ContractController { ...@@ -175,8 +179,8 @@ public class ContractController {
rowBody.createCell(18).setCellValue(contract.getRelationCode() == null ? "无" : "有"); rowBody.createCell(18).setCellValue(contract.getRelationCode() == null ? "无" : "有");
rowBody.createCell(19).setCellValue(contract.getRelationCode() == null ? "" : contract.getRelationCode()); rowBody.createCell(19).setCellValue(contract.getRelationCode() == null ? "" : contract.getRelationCode());
rowBody.createCell(20).setCellValue(contract.getSignedDate() == null ? "" : contract.getSignedDate()); rowBody.createCell(20).setCellValue(contract.getSignedDate() == null ? "" : contract.getSignedDate());
}else{ } else {
if(platform.equals("cas")){ if (platform.equals("cas")) {
rowBody.createCell(12).setCellValue(contract.getValidStartDate()); rowBody.createCell(12).setCellValue(contract.getValidStartDate());
rowBody.createCell(13).setCellValue(contract.getValidEndDate()); rowBody.createCell(13).setCellValue(contract.getValidEndDate());
rowBody.createCell(14).setCellValue(contract.getMoney() == null ? 0 : contract.getMoney()); rowBody.createCell(14).setCellValue(contract.getMoney() == null ? 0 : contract.getMoney());
...@@ -184,7 +188,7 @@ public class ContractController { ...@@ -184,7 +188,7 @@ public class ContractController {
rowBody.createCell(16).setCellValue(CONTRACT_STATUS.get(contract.getStatus())); rowBody.createCell(16).setCellValue(CONTRACT_STATUS.get(contract.getStatus()));
rowBody.createCell(17).setCellValue(CONTRACT_STATUS.get(contract.getBackStatus() + "_back")); rowBody.createCell(17).setCellValue(CONTRACT_STATUS.get(contract.getBackStatus() + "_back"));
rowBody.createCell(18).setCellValue(contract.getRelationCode() == null ? "" : contract.getRelationCode()); rowBody.createCell(18).setCellValue(contract.getRelationCode() == null ? "" : contract.getRelationCode());
}else{ } else {
rowBody.createCell(12).setCellValue(contract.getMoney() == null ? 0 : contract.getMoney()); rowBody.createCell(12).setCellValue(contract.getMoney() == null ? 0 : contract.getMoney());
rowBody.createCell(13).setCellValue(CONTRACT_STATUS.get(contract.getContractType())); rowBody.createCell(13).setCellValue(CONTRACT_STATUS.get(contract.getContractType()));
rowBody.createCell(14).setCellValue(CONTRACT_STATUS.get(contract.getStatus())); rowBody.createCell(14).setCellValue(CONTRACT_STATUS.get(contract.getStatus()));
...@@ -476,9 +480,12 @@ public class ContractController { ...@@ -476,9 +480,12 @@ public class ContractController {
@RequestMapping(value = "/upload", method = RequestMethod.POST) @RequestMapping(value = "/upload", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public ResultModel fileUpload2(@RequestParam("file") MultipartFile file, @PathVariable String platform,@CurrentAccount User loginAccount) { public ResultModel fileUpload2(@RequestParam("file") MultipartFile file, @PathVariable String platform, @CurrentAccount User loginAccount) {
//return service.uploadBatchInfo(file, platform,loginAccount); //
return ResultModel.ERROR("导入功能暂时关闭"); if (!"dmp".equals(platform)) {
return ResultModel.ERROR("导入功能暂时关闭");
}
return service.uploadBatchInfo(file, platform, loginAccount);
} }
@RequestMapping(value = "/upload/tempurl", method = RequestMethod.GET) @RequestMapping(value = "/upload/tempurl", method = RequestMethod.GET)
...@@ -504,6 +511,11 @@ public class ContractController { ...@@ -504,6 +511,11 @@ public class ContractController {
@RequestParam String startDate, @RequestParam String endDate, @RequestParam String startDate, @RequestParam String endDate,
String bodyCode, String serchName) { String bodyCode, String serchName) {
if (platform.equals("dmp")) {
//展示dmp上传的收入相关数据
return ResultModel.OK(dmpIncomeService.listByDs(startDate, endDate));
}
return ResultModel.OK(shareIncomeService.shareIncomeList(loginAccount, startDate, endDate, platform, bodyCode, serchName)); return ResultModel.OK(shareIncomeService.shareIncomeList(loginAccount, startDate, endDate, platform, bodyCode, serchName));
} }
...@@ -515,52 +527,30 @@ public class ContractController { ...@@ -515,52 +527,30 @@ public class ContractController {
@RequestParam String startDate, @RequestParam String endDate, @RequestParam String startDate, @RequestParam String endDate,
String bodyCode, String serchName, HttpServletResponse response, HttpServletRequest request) { String bodyCode, String serchName, HttpServletResponse response, HttpServletRequest request) {
List<Contract> contracts = shareIncomeService.shareIncomeList(loginAccount, startDate, endDate, platform, bodyCode, serchName); String fileName = "分摊收入报表_" + new DateTime(startDate).toString("yyyyMMdd")
//byte[] content = new byte[0]; + "_" + new DateTime(endDate).toString("yyyyMMdd") + ".xls";
//StringBuilder sb = new StringBuilder(); if (platform.equals("dmp")) {
/*sb.append("我方签约主体,签约方,合同编号,合同金额,不含税收入,合同开始时间,合同截止时间,区间使用天数,区间分摊收入,调整额,分摊总收入\r\n");*/ //dmp 分摊报表导出
//sb.append("我方签约主体,签约方,合同编号,合同状态,合同金额,不含税收入,合同开始日期,合同截止日期,区间使用天数,区间分摊收入,调整额,分摊总收入\r\n"); HSSFWorkbook workbook = dmpIncomeService.exportIncomeList(startDate,endDate,bodyCode,serchName);
this.exportWrite(fileName, workbook, "分摊收入报表", response);
}
List<Contract> contracts = shareIncomeService.shareIncomeList(loginAccount, startDate, endDate, platform, bodyCode, serchName);
HSSFWorkbook workbook; HSSFWorkbook workbook;
if(platform.equals("tkio")){ if (platform.equals("tkio")) {
workbook = createTKIOExcel(contracts); workbook = createTKIOExcel(contracts);
}else if(platform.equals("adi")){ } else if (platform.equals("adi")) {
workbook = createADIExcel(contracts); workbook = createADIExcel(contracts);
}else if(platform.equals("cas")){ } else if (platform.equals("cas")) {
workbook = createCASExcel(contracts); workbook = createCASExcel(contracts);
}else{ } else {
workbook = createCommonExcel(contracts); workbook = createCommonExcel(contracts);
} }
String fileName = "分摊收入报表_" + new DateTime(startDate).toString("yyyyMMdd")
+ "_" + new DateTime(endDate).toString("yyyyMMdd") + ".xls";
this.exportWrite(fileName, workbook, "分摊收入报表", response); this.exportWrite(fileName, workbook, "分摊收入报表", response);
/*if (ValidateUtil.isValid(contracts)) {
for (Contract c : contracts) {
sb.append(c.getMyBodyName()).append(",")
.append(c.getCustomerBody()).append(",")
.append(c.getContractCode()).append(",")
.append(CONTRACT_STATUS.get(c.getStatus())).append(",")
.append("\"").append(df.format(c.getMoney())).append("\",")
.append("\"").append(df.format(c.getIncomeExcludingTax() * 1.0 / 100)).append("\",")
.append(c.getStartDate()).append(",")
.append(c.getEndDate()).append(",")
.append(c.getIntervalUseDays()).append(",")
.append("\"").append(df.format(c.getIntervaIncomeShare() * 1.0 / 100)).append("\",")
.append("\"").append(df.format(c.getAdjustmentFund() * 1.0 / 100)).append("\",")
.append("\"").append(df.format(c.getIncomeShareAll() * 1.0 / 100)).append("\"")
.append("\r\n");
}
}
String fileName = "分摊收入报表_" + new DateTime(startDate).toString("yyyyMMdd")
+ "_" + new DateTime(endDate).toString("yyyyMMdd") + ".csv";
this.exportWrite(fileName, sb.toString(), "分摊收入报表", response);*/
} }
private HSSFWorkbook createCASExcel(List<Contract> contracts) { private HSSFWorkbook createCASExcel(List<Contract> contracts) {
DecimalFormat df = new DecimalFormat("##,##0.00"); DecimalFormat df = new DecimalFormat("##,##0.00");
//创建工作薄对象 //创建工作薄对象
...@@ -602,6 +592,7 @@ public class ContractController { ...@@ -602,6 +592,7 @@ public class ContractController {
} }
return workbook; return workbook;
} }
private HSSFWorkbook createADIExcel(List<Contract> contracts) { private HSSFWorkbook createADIExcel(List<Contract> contracts) {
DecimalFormat df = new DecimalFormat("##,##0.00"); DecimalFormat df = new DecimalFormat("##,##0.00");
//创建工作薄对象 //创建工作薄对象
...@@ -641,7 +632,7 @@ public class ContractController { ...@@ -641,7 +632,7 @@ public class ContractController {
return workbook; return workbook;
} }
private HSSFWorkbook createCommonExcel(List<Contract> contracts){ private HSSFWorkbook createCommonExcel(List<Contract> contracts) {
DecimalFormat df = new DecimalFormat("##,##0.00"); DecimalFormat df = new DecimalFormat("##,##0.00");
//创建工作薄对象 //创建工作薄对象
HSSFWorkbook workbook = new HSSFWorkbook();//这里也可以设置sheet的Name HSSFWorkbook workbook = new HSSFWorkbook();//这里也可以设置sheet的Name
...@@ -678,7 +669,8 @@ public class ContractController { ...@@ -678,7 +669,8 @@ public class ContractController {
} }
return workbook; return workbook;
} }
private HSSFWorkbook createTKIOExcel(List<Contract> contracts){
private HSSFWorkbook createTKIOExcel(List<Contract> contracts) {
DecimalFormat df = new DecimalFormat("##,##0.00"); DecimalFormat df = new DecimalFormat("##,##0.00");
DecimalFormat df2 = new DecimalFormat("##,##0.0000"); DecimalFormat df2 = new DecimalFormat("##,##0.0000");
//创建工作薄对象 //创建工作薄对象
...@@ -709,13 +701,13 @@ public class ContractController { ...@@ -709,13 +701,13 @@ public class ContractController {
rowBody.createCell(7).setCellValue(CONTRACT_STATUS.get(contract.getStatus())); rowBody.createCell(7).setCellValue(CONTRACT_STATUS.get(contract.getStatus()));
rowBody.createCell(8).setCellValue(df.format(contract.getMoney())); rowBody.createCell(8).setCellValue(df.format(contract.getMoney()));
rowBody.createCell(9).setCellValue(contract.getTrackFlow()); rowBody.createCell(9).setCellValue(contract.getTrackFlow());
rowBody.createCell(10).setCellValue(contract.getUnitPrice()==null?0:contract.getUnitPrice()); rowBody.createCell(10).setCellValue(contract.getUnitPrice() == null ? 0 : contract.getUnitPrice());
rowBody.createCell(11).setCellValue(contract.getClickFlow()==null?0.0:contract.getClickFlow()); rowBody.createCell(11).setCellValue(contract.getClickFlow() == null ? 0.0 : contract.getClickFlow());
rowBody.createCell(12).setCellValue(df.format(contract.getIntervaIncomeShare()==null?0:contract.getIntervaIncomeShare() / 100.0)); rowBody.createCell(12).setCellValue(df.format(contract.getIntervaIncomeShare() == null ? 0 : contract.getIntervaIncomeShare() / 100.0));
rowBody.createCell(13).setCellValue(df.format(contract.getAdjustmentFund()==null?0:contract.getAdjustmentFund() / 100.0)); rowBody.createCell(13).setCellValue(df.format(contract.getAdjustmentFund() == null ? 0 : contract.getAdjustmentFund() / 100.0));
rowBody.createCell(14).setCellValue(df.format(contract.getIncomeShareAll()==null?0:contract.getIncomeShareAll() / 100.0)); rowBody.createCell(14).setCellValue(df.format(contract.getIncomeShareAll() == null ? 0 : contract.getIncomeShareAll() / 100.0));
rowBody.createCell(15).setCellValue(df.format(contract.getIncomeGross()==null?0:contract.getIncomeGross() / 100.0)); rowBody.createCell(15).setCellValue(df.format(contract.getIncomeGross() == null ? 0 : contract.getIncomeGross() / 100.0));
rowBody.createCell(16).setCellValue(df2.format(contract.getExtraFlow()==null?0:contract.getExtraFlow() / 10000.0)); rowBody.createCell(16).setCellValue(df2.format(contract.getExtraFlow() == null ? 0 : contract.getExtraFlow() / 10000.0));
rowBody.createCell(17).setCellValue(contract.getRelationCode() == null ? "" : contract.getRelationCode()); rowBody.createCell(17).setCellValue(contract.getRelationCode() == null ? "" : contract.getRelationCode());
rowBody.createCell(18).setCellValue(contract.getSignedDate() == null ? "" : contract.getSignedDate()); rowBody.createCell(18).setCellValue(contract.getSignedDate() == null ? "" : contract.getSignedDate());
} }
...@@ -777,30 +769,32 @@ public class ContractController { ...@@ -777,30 +769,32 @@ public class ContractController {
/** /**
* 功能描述:新建合同回显、获取行政区域列表 * 功能描述:新建合同回显、获取行政区域列表
*
* @author liyin * @author liyin
* @date 2020/9/23 * @date 2020/9/23
*/ */
@GetMapping("/getBarrioCities") @GetMapping("/getBarrioCities")
@ResponseBody @ResponseBody
public ResultModel getBarrioCities(){ public ResultModel getBarrioCities() {
return ResultModel.OK(service.getBarrioCities()); return ResultModel.OK(service.getBarrioCities());
} }
@GetMapping("/getDate") @GetMapping("/getDate")
@ResponseBody @ResponseBody
public ResultModel getDate(){ public ResultModel getDate() {
HashMap<String, Object> map = new HashMap<>(); HashMap<String, Object> map = new HashMap<>();
map.put("new date",new Date().getTime()); map.put("new date", new Date().getTime());
map.put("getBeforeDays(1)",DateUtil.getBeforeDays(1)); map.put("getBeforeDays(1)", DateUtil.getBeforeDays(1));
map.put("getBeforeDays(0)",DateUtil.getBeforeDays(0)); map.put("getBeforeDays(0)", DateUtil.getBeforeDays(0));
map.put("getCurrentDateStr",DateUtil.getCurrentDateStr()); map.put("getCurrentDateStr", DateUtil.getCurrentDateStr());
return ResultModel.OK(map); return ResultModel.OK(map);
} }
/** /**
* 试用流量 * 试用流量
*/ */
@GetMapping(value = "/trialFlow") @GetMapping(value = "/trialFlow")
@ResponseBody @ResponseBody
...@@ -809,7 +803,7 @@ public class ContractController { ...@@ -809,7 +803,7 @@ public class ContractController {
@RequestParam String startDate, @RequestParam String endDate, @RequestParam String startDate, @RequestParam String endDate,
String email) { String email) {
return ResultModel.OK(shareIncomeService.trialFlow(loginAccount, startDate, endDate, platform,email)); return ResultModel.OK(shareIncomeService.trialFlow(loginAccount, startDate, endDate, platform, email));
} }
...@@ -820,7 +814,7 @@ public class ContractController { ...@@ -820,7 +814,7 @@ public class ContractController {
@GetMapping(value = "trialFlowExport", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) @GetMapping(value = "trialFlowExport", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@AuthKey(AuthMenuEnmm.CONTRACTMNG_EX) @AuthKey(AuthMenuEnmm.CONTRACTMNG_EX)
public void trialFlowExport(@CurrentAccount User loginAccount, @PathVariable String platform, public void trialFlowExport(@CurrentAccount User loginAccount, @PathVariable String platform,
@RequestParam String startDate, @RequestParam String endDate,String email, HttpServletRequest request, HttpServletResponse response) { @RequestParam String startDate, @RequestParam String endDate, String email, HttpServletRequest request, HttpServletResponse response) {
List<TrackFlowVO> list = shareIncomeService.trialFlow(loginAccount, startDate, endDate, platform, email); List<TrackFlowVO> list = shareIncomeService.trialFlow(loginAccount, startDate, endDate, platform, email);
List<String> title = Arrays.asList("主账号,流量(万次)".split(",")); List<String> title = Arrays.asList("主账号,流量(万次)".split(","));
HSSFWorkbook workbook = new HSSFWorkbook(); HSSFWorkbook workbook = new HSSFWorkbook();
...@@ -836,7 +830,7 @@ public class ContractController { ...@@ -836,7 +830,7 @@ public class ContractController {
rowBody.createCell(0).setCellValue(flow.getEmail()); rowBody.createCell(0).setCellValue(flow.getEmail());
rowBody.createCell(1).setCellValue(flow.getTrackFlow()); rowBody.createCell(1).setCellValue(flow.getTrackFlow());
} }
String fileName = "试用流量_" + new DateTime(startDate).toString("yyyyMMdd")+ "_" + new DateTime(endDate).toString("yyyyMMdd") + ".xls"; String fileName = "试用流量_" + new DateTime(startDate).toString("yyyyMMdd") + "_" + new DateTime(endDate).toString("yyyyMMdd") + ".xls";
this.exportWrite(fileName, workbook, "试用流量_", response); this.exportWrite(fileName, workbook, "试用流量_", response);
} }
} }
package common.controller;
import common.model.DmpIncome;
import common.model.User;
import common.service.DmpIncomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import security.annotation.CurrentAccount;
import util.ResultModel;
//DMP 收入管理
@RestController
@RequestMapping("dmp/income")
public class DmpIncomeController {
@Autowired
DmpIncomeService dmpIncomeService;
@GetMapping("/list/bycode")
public ResultModel listByContract(String code) {
//按合同查询
return ResultModel.OK(dmpIncomeService.listByCode(code));
}
@GetMapping("/list/byds")
public ResultModel listByDs(String start, String end) {
//按日期范围查询
return ResultModel.OK(dmpIncomeService.listByDs(start, end));
}
@PostMapping("/update")
public ResultModel updateItem(@RequestBody DmpIncome dmpIncome) {
//更新数据
return ResultModel.OK(dmpIncomeService.update(dmpIncome));
}
@PostMapping("/delete")
public ResultModel deleteItem(Long id) {
//删除数据
return ResultModel.OK(dmpIncomeService.delete(id));
}
@PostMapping("/upload")
public ResultModel uploadList(@RequestParam("file") MultipartFile file, @CurrentAccount User loginAccount) {
//上传收入数据
dmpIncomeService.uploadFile(file, "dmp", loginAccount);
return ResultModel.OK();
}
}
...@@ -107,6 +107,8 @@ public class Contract { ...@@ -107,6 +107,8 @@ public class Contract {
private int businessType; //业务类型 1 VIP 2 共管 private int businessType; //业务类型 1 VIP 2 共管
private int agreementType; //协议类型 1 普通协议 2 框架协议 private int agreementType; //协议类型 1 普通协议 2 框架协议
private String businessTypeName; //业务类型 1 VIP 2 共管
private String agreementTypeName; //协议类型 1 普通协议 2 框架协议
@Id @Id
@GeneratedValue @GeneratedValue
...@@ -791,4 +793,22 @@ public class Contract { ...@@ -791,4 +793,22 @@ public class Contract {
public void setAgreementType(int agreementType) { public void setAgreementType(int agreementType) {
this.agreementType = agreementType; this.agreementType = agreementType;
} }
@Transient
public String getBusinessTypeName() {
return businessTypeName;
}
public void setBusinessTypeName(String businessTypeName) {
this.businessTypeName = businessTypeName;
}
@Transient
public String getAgreementTypeName() {
return agreementTypeName;
}
public void setAgreementTypeName(String agreementTypeName) {
this.agreementTypeName = agreementTypeName;
}
} }
package common.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Transient;
import java.util.Date;
@Entity
public class DmpIncome {
private Long id;// ID
private String contractCode;//合同编号
private String incomeMonth;//收入月份
private String period;//结算周期
private String sysSettlement;//系统结算
private String monthSettlement;//按月结算
private String confirmSettlement;//确认结算
private String taxRate;//税率
private Date createTime;
private Date modifyTime;
private String uploadUser;
//contract_code, my_body_name, customer_body, customer_short, business_type, agreement_type
private String myBodyName,
customerBody,
customerShort,
businessType,
agreementType;
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getContractCode() {
return contractCode;
}
public void setContractCode(String contractCode) {
this.contractCode = contractCode;
}
public String getIncomeMonth() {
return incomeMonth;
}
public void setIncomeMonth(String incomeMonth) {
this.incomeMonth = incomeMonth;
}
public String getPeriod() {
return period;
}
public void setPeriod(String period) {
this.period = period;
}
public String getSysSettlement() {
return sysSettlement;
}
public void setSysSettlement(String sysSettlement) {
this.sysSettlement = sysSettlement;
}
public String getMonthSettlement() {
return monthSettlement;
}
public void setMonthSettlement(String monthSettlement) {
this.monthSettlement = monthSettlement;
}
public String getConfirmSettlement() {
return confirmSettlement;
}
public void setConfirmSettlement(String confirmSettlement) {
this.confirmSettlement = confirmSettlement;
}
public String getTaxRate() {
return taxRate;
}
public void setTaxRate(String taxRate) {
this.taxRate = taxRate;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getModifyTime() {
return modifyTime;
}
public void setModifyTime(Date modifyTime) {
this.modifyTime = modifyTime;
}
public String getUploadUser() {
return uploadUser;
}
public void setUploadUser(String uploadUser) {
this.uploadUser = uploadUser;
}
@Transient
public String getMyBodyName() {
return myBodyName;
}
public void setMyBodyName(String myBodyName) {
this.myBodyName = myBodyName;
}
@Transient
public String getCustomerBody() {
return customerBody;
}
public void setCustomerBody(String customerBody) {
this.customerBody = customerBody;
}
@Transient
public String getCustomerShort() {
return customerShort;
}
public void setCustomerShort(String customerShort) {
this.customerShort = customerShort;
}
@Transient
public String getBusinessType() {
return businessType;
}
public void setBusinessType(String businessType) {
this.businessType = businessType;
}
@Transient
public String getAgreementType() {
return agreementType;
}
public void setAgreementType(String agreementType) {
this.agreementType = agreementType;
}
}
...@@ -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;
...@@ -100,6 +101,9 @@ public interface ContractRepository extends JpaRepository<Contract, Long> { ...@@ -100,6 +101,9 @@ public interface ContractRepository extends JpaRepository<Contract, Long> {
@Query(value = "select contract_code,my_body_code,sale,platform from contract where contract_code in ?1", nativeQuery = true) @Query(value = "select contract_code,my_body_code,sale,platform from contract where contract_code in ?1", nativeQuery = true)
List<Object[]> findByContractCode(List<String> codesList); List<Object[]> findByContractCode(List<String> codesList);
@Query(value = "select contract_code,my_body_code, my_body_name, customer_body, customer_short, business_type, agreement_type from contract where platform = 'dmp' and contract_code in ?1", nativeQuery = true)
List<Object[]> findByDmpContractCode(List<String> codesList);
@Query(value = "select * from contract where ((start_date <= ?1 and end_date >= ?1) or (start_date <= ?2 and end_date >= ?2) or (start_date >= ?1 and end_date <= ?2) or (start_date <= ?1 and end_date >= ?2)) and platform=?3 and status!='del' and (share_sign = 1 or share_sign is null) ", nativeQuery = true) @Query(value = "select * from contract where ((start_date <= ?1 and end_date >= ?1) or (start_date <= ?2 and end_date >= ?2) or (start_date >= ?1 and end_date <= ?2) or (start_date <= ?1 and end_date >= ?2)) and platform=?3 and status!='del' and (share_sign = 1 or share_sign is null) ", nativeQuery = true)
List<Contract> findShareContranctByDate3(String startDate, String endDate, String platform); List<Contract> findShareContranctByDate3(String startDate, String endDate, String platform);
...@@ -137,12 +141,12 @@ public interface ContractRepository extends JpaRepository<Contract, Long> { ...@@ -137,12 +141,12 @@ public interface ContractRepository extends JpaRepository<Contract, Long> {
List<Long> findRelationContractBySideAgre(); List<Long> findRelationContractBySideAgre();
@Query(value = "SELECT * from contract where contract_code = ?1 UNION SELECT * from contract where relation_code = ?1 and create_time <= ?2 and id<> ?3 and contract_type = '2'", nativeQuery = true) @Query(value = "SELECT * from contract where contract_code = ?1 UNION SELECT * from contract where relation_code = ?1 and create_time <= ?2 and id<> ?3 and contract_type = '2'", nativeQuery = true)
List<Contract> findByCreateTimeAndCodeNotOwn(String contractCode, String createTime,Long id); List<Contract> findByCreateTimeAndCodeNotOwn(String contractCode, String createTime, Long id);
@Query(value = "select * from contract where next_signed_contract_code=?1 limit 1 ",nativeQuery = true) @Query(value = "select * from contract where next_signed_contract_code=?1 limit 1 ", nativeQuery = true)
Contract findByNextSignedContractCode(String contractCode); Contract findByNextSignedContractCode(String contractCode);
@Query(value = "select * from contract where platform=?1 and share_sign = ?2 ",nativeQuery = true) @Query(value = "select * from contract where platform=?1 and share_sign = ?2 ", nativeQuery = true)
List<Contract> findByPlatformAndShareSign(String platform, int share_sign); List<Contract> findByPlatformAndShareSign(String platform, int share_sign);
@Query(value = "select * from contract where contract_code = ?1 and status != 'del'", nativeQuery = true) @Query(value = "select * from contract where contract_code = ?1 and status != 'del'", nativeQuery = true)
...@@ -150,4 +154,12 @@ public interface ContractRepository extends JpaRepository<Contract, Long> { ...@@ -150,4 +154,12 @@ public interface ContractRepository extends JpaRepository<Contract, Long> {
@Query(value = "select * from contract where relation_code = ?1 and status != 'del'", nativeQuery = true) @Query(value = "select * from contract where relation_code = ?1 and status != 'del'", nativeQuery = true)
List<Contract> findByRelationCode(String contractCode); List<Contract> findByRelationCode(String contractCode);
@Query(value = "select id from contract where contract_code = ?1 ", nativeQuery = true)
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);
} }
package common.repository;
import common.model.DmpIncome;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
public interface DmpIncomeRepository extends JpaRepository<DmpIncome, Long> {
@Query(value = "select * from dmp_income where contract_code = ?1 order by income_month", nativeQuery = true)
List<DmpIncome> findByContractCode(String contractCode);
@Query(value = "select * from dmp_income where income_month >= ?1 and income_month <=?2 order by income_month", nativeQuery = true)
List<DmpIncome> findByContractDs(String start, String end);
@Query(value = "select * from dmp_income where contract_code = ?1 and income_month =?2 limit 1 ", nativeQuery = true)
DmpIncome findByCodeMonth(String contractCode, String incomeMonth);
}
package common.service;
import common.model.DmpIncome;
import common.model.User;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.web.multipart.MultipartFile;
import util.ResultModel;
import java.util.List;
public interface DmpIncomeService {
List<DmpIncome> listByCode(String contractCode);
List<DmpIncome> listByDs(String start, String end);
HSSFWorkbook exportIncomeList(String startDate, String endDate, String bodyCode, String serchName);
DmpIncome update(DmpIncome dmpIncome);
Long delete(Long id);
ResultModel uploadFile(MultipartFile file, String platform, User loginAccount);
ResultModel contractUploadFile(MultipartFile file, String platform, User loginAccount);
}
...@@ -36,6 +36,7 @@ import java.beans.BeanInfo; ...@@ -36,6 +36,7 @@ import java.beans.BeanInfo;
import java.beans.IntrospectionException; import java.beans.IntrospectionException;
import java.beans.Introspector; import java.beans.Introspector;
import java.beans.PropertyDescriptor; import java.beans.PropertyDescriptor;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
...@@ -93,6 +94,8 @@ public class ContractServiceImpl implements ContractService { ...@@ -93,6 +94,8 @@ public class ContractServiceImpl implements ContractService {
put("关联合同编号", "relation_code"); put("关联合同编号", "relation_code");
put("补充协议签订日期", "signed_date"); put("补充协议签订日期", "signed_date");
put("是否计算一次性收入", "one_time"); put("是否计算一次性收入", "one_time");
put("业务类型", "business_type");
put("协议类型", "agreement_type");
}}; }};
private static final Map<String, String> SHEET_TITLE_RESERVE = new HashMap() {{ private static final Map<String, String> SHEET_TITLE_RESERVE = new HashMap() {{
...@@ -115,6 +118,8 @@ public class ContractServiceImpl implements ContractService { ...@@ -115,6 +118,8 @@ public class ContractServiceImpl implements ContractService {
put("relation_code", "关联合同编号"); put("relation_code", "关联合同编号");
put("signed_date", "补充协议签订日期"); put("signed_date", "补充协议签订日期");
put("one_time", "是否计算一次性收入"); put("one_time", "是否计算一次性收入");
put("business_type", "业务类型");
put("agreement_type", "协议类型");
}}; }};
public static final String UPLOAD_TITLE = "我方签约主体,客户签约主体,行业分类,合同开始日期,合同结束日期," + public static final String UPLOAD_TITLE = "我方签约主体,客户签约主体,行业分类,合同开始日期,合同结束日期," +
...@@ -227,6 +232,9 @@ public class ContractServiceImpl implements ContractService { ...@@ -227,6 +232,9 @@ public class ContractServiceImpl implements ContractService {
@Autowired @Autowired
private CalculationFlowRepository calculationFlowRepository; private CalculationFlowRepository calculationFlowRepository;
@Autowired
private DmpIncomeService dmpIncomeService;
@Override @Override
public Map<String, Object> checkAccount(String email, String platfrom) { public Map<String, Object> checkAccount(String email, String platfrom) {
...@@ -254,17 +262,17 @@ public class ContractServiceImpl implements ContractService { ...@@ -254,17 +262,17 @@ public class ContractServiceImpl implements ContractService {
} else if ("io".equals(platfrom)) { } else if ("io".equals(platfrom)) {
ioAccount4Web = ioAccount4WebRepository.findByEmail(email); ioAccount4Web = ioAccount4WebRepository.findByEmail(email);
} else if ("adi".equals(platfrom) || "cas".equals(platfrom) ) { } else if ("adi".equals(platfrom) || "cas".equals(platfrom)) {
adiUser = adiAccountService.findOne(email,"国内"); adiUser = adiAccountService.findOne(email, "国内");
} }
if (null == account && null == ioAccount4Web && null == adiUser ) { if (null == account && null == ioAccount4Web && null == adiUser) {
map.put("result", 0); map.put("result", 0);
} else { } else {
BigInteger integer = contractRepository.countNumByEmail(email, platfrom); BigInteger integer = contractRepository.countNumByEmail(email, platfrom);
map.put("result", 1); map.put("result", 1);
if (platfrom.equals("adi")) { if (platfrom.equals("adi")) {
map.put("company", adiUser.getCompany()); map.put("company", adiUser.getCompany());
}else if (platfrom.equals("cas")) { } else if (platfrom.equals("cas")) {
map.put("company", adiUser.getCompany()); map.put("company", adiUser.getCompany());
map.put("validStartDate", adiUser.getSendTime()); map.put("validStartDate", adiUser.getSendTime());
} else { } else {
...@@ -505,9 +513,9 @@ public class ContractServiceImpl implements ContractService { ...@@ -505,9 +513,9 @@ public class ContractServiceImpl implements ContractService {
} }
resource.setOneTime(true); resource.setOneTime(true);
//补充协议 //补充协议
if("2".equals(resource.getContractType()) && "tkio".equals(resource.getPlatform())){ if ("2".equals(resource.getContractType()) && "tkio".equals(resource.getPlatform())) {
//关联合同不能为空 //关联合同不能为空
if(null == resource.getRelationContract() || "".equals(resource.getRelationContract())|| -1L == resource.getRelationContract()){ if (null == resource.getRelationContract() || "".equals(resource.getRelationContract()) || -1L == resource.getRelationContract()) {
Contract contractExist = new Contract(); Contract contractExist = new Contract();
contractExist.setId(-100L); contractExist.setId(-100L);
contractExist.setErroMessage("关联合同为必填项"); contractExist.setErroMessage("关联合同为必填项");
...@@ -515,7 +523,7 @@ public class ContractServiceImpl implements ContractService { ...@@ -515,7 +523,7 @@ public class ContractServiceImpl implements ContractService {
} }
//补充协议开始日期不能晚于原始合同的结束日期 //补充协议开始日期不能晚于原始合同的结束日期
Contract relationContract = contractRepository.findOne(resource.getRelationContract()); Contract relationContract = contractRepository.findOne(resource.getRelationContract());
if(relationContract.getEndDate().compareTo(resource.getSignedDate())<0){ if (relationContract.getEndDate().compareTo(resource.getSignedDate()) < 0) {
Contract contractExist = new Contract(); Contract contractExist = new Contract();
contractExist.setId(-100L); contractExist.setId(-100L);
contractExist.setErroMessage("补充协议开始日期不能晚于原始合同的结束日期"); contractExist.setErroMessage("补充协议开始日期不能晚于原始合同的结束日期");
...@@ -615,12 +623,12 @@ public class ContractServiceImpl implements ContractService { ...@@ -615,12 +623,12 @@ public class ContractServiceImpl implements ContractService {
calculationFlowRepository.save(calculationFlow); calculationFlowRepository.save(calculationFlow);
//补充协议:后端逻辑顺序绑定 //补充协议:后端逻辑顺序绑定
if("2".equals(resource.getContractType())){ if ("2".equals(resource.getContractType())) {
DateTime dateTime = new DateTime(resource.getSignedDate());//补充协议晚录判断 DateTime dateTime = new DateTime(resource.getSignedDate());//补充协议晚录判断
if (shareIncomeService.checkLateContract(dateTime, if (shareIncomeService.checkLateContract(dateTime,
new DateTime(new DateTime().toString("yyyy-MM-dd")))) { new DateTime(new DateTime().toString("yyyy-MM-dd")))) {
resource.setStatus(ContractStatusEnum.LATE.getKey()); resource.setStatus(ContractStatusEnum.LATE.getKey());
}else{ } else {
resource.setStatus(ContractStatusEnum.NFORMAL.getKey()); resource.setStatus(ContractStatusEnum.NFORMAL.getKey());
} }
Long relationContract = resource.getRelationContract(); Long relationContract = resource.getRelationContract();
...@@ -629,35 +637,35 @@ public class ContractServiceImpl implements ContractService { ...@@ -629,35 +637,35 @@ public class ContractServiceImpl implements ContractService {
String relationCode = resource.getRelationCode(); String relationCode = resource.getRelationCode();
resource.setStartDate(one.getStartDate()); resource.setStartDate(one.getStartDate());
String platform = resource.getPlatform(); String platform = resource.getPlatform();
while(true){ while (true) {
Contract contract = contractRepository.findByCodePlatform(relationCode, platform); Contract contract = contractRepository.findByCodePlatform(relationCode, platform);
if(StringUtils.isEmpty(contract.getNextSignedDate())){ if (StringUtils.isEmpty(contract.getNextSignedDate())) {
if(ContractStatusEnum.LATE.getKey().equals(resource.getStatus())){//如果晚录则设置绑定下一份合同的日期为签订月的最后一天 if (ContractStatusEnum.LATE.getKey().equals(resource.getStatus())) {//如果晚录则设置绑定下一份合同的日期为签订月的最后一天
contract.setNextSignedDate(dateTime.dayOfMonth().withMaximumValue().toString("yyyy-MM-dd")); contract.setNextSignedDate(dateTime.dayOfMonth().withMaximumValue().toString("yyyy-MM-dd"));
}else{ } else {
contract.setNextSignedDate(dateTime.plusDays(-1).toString("yyyy-MM-dd"));//签订日的前一天 contract.setNextSignedDate(dateTime.plusDays(-1).toString("yyyy-MM-dd"));//签订日的前一天
} }
contract.setNextSignedContractCode(resource.getContractCode()); contract.setNextSignedContractCode(resource.getContractCode());
contractRepository.save(contract); contractRepository.save(contract);
break; break;
}else{ } else {
relationCode = contract.getNextSignedContractCode(); relationCode = contract.getNextSignedContractCode();
} }
} }
} }
}else if("cas".equals(resource.getPlatform())){ } else if ("cas".equals(resource.getPlatform())) {
PackageBase one = packageBaseRepository.findOne(resource.getPriceLevel()); PackageBase one = packageBaseRepository.findOne(resource.getPriceLevel());
ADIUser adiUser = adiAccountService.findOne(resource.getEmail(),one.getPackageName()); ADIUser adiUser = adiAccountService.findOne(resource.getEmail(), one.getPackageName());
if(adiUser==null || StringUtils.isEmpty(adiUser.getSendTime())){ if (adiUser == null || StringUtils.isEmpty(adiUser.getSendTime())) {
resource.setShareSign(0); resource.setShareSign(0);
}else{ } else {
resource.setShareSign(1); resource.setShareSign(1);
DateTime sendTime = new DateTime(DateUtil.parseDate(DateUtil.C_TIME_PATTON_DEFAULT,adiUser.getSendTime())); DateTime sendTime = new DateTime(DateUtil.parseDate(DateUtil.C_TIME_PATTON_DEFAULT, adiUser.getSendTime()));
DateTime startDate = new DateTime(resource.getStartDate()); DateTime startDate = new DateTime(resource.getStartDate());
if(sendTime.isBefore(startDate)){ if (sendTime.isBefore(startDate)) {
sendTime = startDate; sendTime = startDate;
} }
DateTime endDate = new DateTime(resource.getEndDate()); DateTime endDate = new DateTime(resource.getEndDate());
...@@ -669,14 +677,13 @@ public class ContractServiceImpl implements ContractService { ...@@ -669,14 +677,13 @@ public class ContractServiceImpl implements ContractService {
if (shareIncomeService.checkLateContract(new DateTime(validStartDateStr), if (shareIncomeService.checkLateContract(new DateTime(validStartDateStr),
new DateTime(new DateTime().toString("yyyy-MM-dd")))) { new DateTime(new DateTime().toString("yyyy-MM-dd")))) {
resource.setStatus(ContractStatusEnum.LATE.getKey()); resource.setStatus(ContractStatusEnum.LATE.getKey());
}else{ } else {
resource.setStatus(ContractStatusEnum.NFORMAL.getKey()); resource.setStatus(ContractStatusEnum.NFORMAL.getKey());
} }
} }
} }
resource = contractRepository.save(resource); resource = contractRepository.save(resource);
this.saveContractRelations(resource, resource.getId()); this.saveContractRelations(resource, resource.getId());
...@@ -914,9 +921,9 @@ public class ContractServiceImpl implements ContractService { ...@@ -914,9 +921,9 @@ public class ContractServiceImpl implements ContractService {
Contract contract = contractRepository.findOne(resource.getId()); Contract contract = contractRepository.findOne(resource.getId());
//补充协议 //补充协议
if("2".equals(resource.getContractType()) && "tkio".equals(resource.getPlatform())){ if ("2".equals(resource.getContractType()) && "tkio".equals(resource.getPlatform())) {
//关联合同不能为空 //关联合同不能为空
if(null == resource.getRelationContract() || "".equals(resource.getRelationContract())|| -1L == resource.getRelationContract()){ if (null == resource.getRelationContract() || "".equals(resource.getRelationContract()) || -1L == resource.getRelationContract()) {
Contract contractExist = new Contract(); Contract contractExist = new Contract();
contractExist.setId(-100L); contractExist.setId(-100L);
contractExist.setErroMessage("关联合同为必填项"); contractExist.setErroMessage("关联合同为必填项");
...@@ -924,7 +931,7 @@ public class ContractServiceImpl implements ContractService { ...@@ -924,7 +931,7 @@ public class ContractServiceImpl implements ContractService {
} }
//补充协议开始日期不能晚于原始合同的结束日期 //补充协议开始日期不能晚于原始合同的结束日期
Contract relationContract = contractRepository.findOne(resource.getRelationContract()); Contract relationContract = contractRepository.findOne(resource.getRelationContract());
if(relationContract.getEndDate().compareTo(resource.getSignedDate())<0){ if (relationContract.getEndDate().compareTo(resource.getSignedDate()) < 0) {
Contract contractExist = new Contract(); Contract contractExist = new Contract();
contractExist.setId(-100L); contractExist.setId(-100L);
contractExist.setErroMessage("补充协议开始日期不能晚于原始合同的结束日期"); contractExist.setErroMessage("补充协议开始日期不能晚于原始合同的结束日期");
...@@ -997,20 +1004,19 @@ public class ContractServiceImpl implements ContractService { ...@@ -997,20 +1004,19 @@ public class ContractServiceImpl implements ContractService {
if (shareIncomeService.checkLateContract(new DateTime(resource.getStartDate()), if (shareIncomeService.checkLateContract(new DateTime(resource.getStartDate()),
new DateTime(new DateTime(resource.getCreateTime()).toString("yyyy-MM-dd")))) { new DateTime(new DateTime(resource.getCreateTime()).toString("yyyy-MM-dd")))) {
resource.setStatus(ContractStatusEnum.LATE.getKey()); resource.setStatus(ContractStatusEnum.LATE.getKey());
}else{ } else {
resource.setStatus(ContractStatusEnum.NFORMAL.getKey()); resource.setStatus(ContractStatusEnum.NFORMAL.getKey());
} }
} }
//this.calculateShareIncome(resource); //this.calculateShareIncome(resource);
resource.setId(contract.getId()); resource.setId(contract.getId());
//判断库里是否已有合同的主账号 //判断库里是否已有合同的主账号
if ("tkio".equals(resource.getPlatform())) { if ("tkio".equals(resource.getPlatform())) {
if(contract.getStartDate() != resource.getStartDate() && contract.getEndDate() != resource.getEndDate()) { if (contract.getStartDate() != resource.getStartDate() && contract.getEndDate() != resource.getEndDate()) {
List<Contract> contracts = contractRepository.findByPlatformAndEmail(resource.getPlatform(), resource.getEmail()); List<Contract> contracts = contractRepository.findByPlatformAndEmail(resource.getPlatform(), resource.getEmail());
CalculationFlow calculationFlow = new CalculationFlow(); CalculationFlow calculationFlow = new CalculationFlow();
calculationFlow.setEmail(resource.getEmail()); calculationFlow.setEmail(resource.getEmail());
...@@ -1032,35 +1038,35 @@ public class ContractServiceImpl implements ContractService { ...@@ -1032,35 +1038,35 @@ public class ContractServiceImpl implements ContractService {
calculationFlowRepository.save(calculationFlow); calculationFlowRepository.save(calculationFlow);
} }
//补充协议 //补充协议
if("2".equals(resource.getContractType())){ if ("2".equals(resource.getContractType())) {
DateTime dateTime = new DateTime(resource.getSignedDate());//补充协议晚录判断 DateTime dateTime = new DateTime(resource.getSignedDate());//补充协议晚录判断
if (ContractStatusEnum.NFORMAL.getKey().equals(contract.getStatus()) || ContractStatusEnum.LATE.getKey().equals(contract.getStatus())) { if (ContractStatusEnum.NFORMAL.getKey().equals(contract.getStatus()) || ContractStatusEnum.LATE.getKey().equals(contract.getStatus())) {
if (shareIncomeService.checkLateContract(dateTime, if (shareIncomeService.checkLateContract(dateTime,
new DateTime(new DateTime(resource.getCreateTime()).toString("yyyy-MM-dd")))) { new DateTime(new DateTime(resource.getCreateTime()).toString("yyyy-MM-dd")))) {
resource.setStatus(ContractStatusEnum.LATE.getKey()); resource.setStatus(ContractStatusEnum.LATE.getKey());
}else{ } else {
resource.setStatus(ContractStatusEnum.NFORMAL.getKey()); resource.setStatus(ContractStatusEnum.NFORMAL.getKey());
} }
} }
Contract bindContract = contractRepository.findByNextSignedContractCode(resource.getContractCode()); Contract bindContract = contractRepository.findByNextSignedContractCode(resource.getContractCode());
if(ContractStatusEnum.LATE.getKey().equals(resource.getStatus())){//如果晚录则设置绑定下一份合同的日期为签订月的最后一天 if (ContractStatusEnum.LATE.getKey().equals(resource.getStatus())) {//如果晚录则设置绑定下一份合同的日期为签订月的最后一天
bindContract.setNextSignedDate(dateTime.dayOfMonth().withMaximumValue().toString("yyyy-MM-dd")); bindContract.setNextSignedDate(dateTime.dayOfMonth().withMaximumValue().toString("yyyy-MM-dd"));
}else{ } else {
bindContract.setNextSignedDate(dateTime.plusDays(-1).toString("yyyy-MM-dd"));//签订日的前一天 bindContract.setNextSignedDate(dateTime.plusDays(-1).toString("yyyy-MM-dd"));//签订日的前一天
} }
contractRepository.save(bindContract); contractRepository.save(bindContract);
} }
}else if("cas".equals(resource.getPlatform())){ } else if ("cas".equals(resource.getPlatform())) {
PackageBase one = packageBaseRepository.findOne(resource.getPriceLevel()); PackageBase one = packageBaseRepository.findOne(resource.getPriceLevel());
ADIUser adiUser = adiAccountService.findOne(resource.getEmail(), one.getPackageName()); ADIUser adiUser = adiAccountService.findOne(resource.getEmail(), one.getPackageName());
if(adiUser==null || StringUtils.isEmpty(adiUser.getSendTime())){ if (adiUser == null || StringUtils.isEmpty(adiUser.getSendTime())) {
resource.setShareSign(0); resource.setShareSign(0);
}else{ } else {
resource.setShareSign(1); resource.setShareSign(1);
DateTime sendTime = new DateTime(DateUtil.parseDate(DateUtil.C_TIME_PATTON_DEFAULT,adiUser.getSendTime())); DateTime sendTime = new DateTime(DateUtil.parseDate(DateUtil.C_TIME_PATTON_DEFAULT, adiUser.getSendTime()));
DateTime startDate = new DateTime(resource.getStartDate()); DateTime startDate = new DateTime(resource.getStartDate());
if(sendTime.isBefore(startDate)){ if (sendTime.isBefore(startDate)) {
sendTime = startDate; sendTime = startDate;
} }
DateTime endDate = new DateTime(resource.getEndDate()); DateTime endDate = new DateTime(resource.getEndDate());
...@@ -1072,7 +1078,7 @@ public class ContractServiceImpl implements ContractService { ...@@ -1072,7 +1078,7 @@ public class ContractServiceImpl implements ContractService {
if (shareIncomeService.checkLateContract(new DateTime(validStartDateStr), if (shareIncomeService.checkLateContract(new DateTime(validStartDateStr),
new DateTime(new DateTime().toString("yyyy-MM-dd")))) { new DateTime(new DateTime().toString("yyyy-MM-dd")))) {
resource.setStatus(ContractStatusEnum.LATE.getKey()); resource.setStatus(ContractStatusEnum.LATE.getKey());
}else{ } else {
resource.setStatus(ContractStatusEnum.NFORMAL.getKey()); resource.setStatus(ContractStatusEnum.NFORMAL.getKey());
} }
} }
...@@ -1630,15 +1636,15 @@ public class ContractServiceImpl implements ContractService { ...@@ -1630,15 +1636,15 @@ public class ContractServiceImpl implements ContractService {
} }
//对结果二次加工 //对结果二次加工
if("tkio".equals(platform)){ if ("tkio".equals(platform)) {
List<Long> relationContracts = contractRepository.findRelationContractBySideAgre();//查询被补充协议关联的合同 List<Long> relationContracts = contractRepository.findRelationContractBySideAgre();//查询被补充协议关联的合同
for(Contract contract:result){ for (Contract contract : result) {
if(null ==contract.getContractType() || !"2".equals(contract.getContractType())){ //非补充协议 if (null == contract.getContractType() || !"2".equals(contract.getContractType())) { //非补充协议
if(relationContracts.contains(BigInteger.valueOf(contract.getId()))){ if (relationContracts.contains(BigInteger.valueOf(contract.getId()))) {
contract.setOperate(false);//如果合同 被补充协议关联 contract.setOperate(false);//如果合同 被补充协议关联
} }
}else { } else {
if(contract.getRelationContract()!=null && contract.getRelationContract()>0){ //补充协议 if (contract.getRelationContract() != null && contract.getRelationContract() > 0) { //补充协议
contract.setOperate(false);//如果补充协议被关联 contract.setOperate(false);//如果补充协议被关联
} }
} }
...@@ -2484,12 +2490,20 @@ public class ContractServiceImpl implements ContractService { ...@@ -2484,12 +2490,20 @@ public class ContractServiceImpl implements ContractService {
@Override @Override
public ResultModel uploadBatchInfo(MultipartFile file, String platform, User loginAccount) { public ResultModel uploadBatchInfo(MultipartFile file, String platform, User loginAccount) {
if ("dmp".equals(platform)) {
return dmpIncomeService.contractUploadFile(file, platform, loginAccount);
}
InputStream stream = null; InputStream stream = null;
try { try {
int row_length; int row_length;
if (platform.equals("tkio")) { if (platform.equals("tkio")) {
row_length = 17; row_length = 17;
}if (platform.equals("cas")) { } else if (platform.equals("dmp")) {
row_length = 17;
} else if (platform.equals("cas")) {
row_length = 14; row_length = 14;
} else { } else {
row_length = 13; row_length = 13;
...@@ -2500,11 +2514,19 @@ public class ContractServiceImpl implements ContractService { ...@@ -2500,11 +2514,19 @@ public class ContractServiceImpl implements ContractService {
// while (sheetIter.hasNext()) { // while (sheetIter.hasNext()) {
// Sheet sheet = sheetIter.next(); // Sheet sheet = sheetIter.next();
// } // }
return saveDataBySheet(workbook.getSheetAt(0), row_length, platform,loginAccount); return saveDataBySheet(workbook.getSheetAt(0), row_length, platform, loginAccount);
} catch (Exception ex) { } catch (Exception ex) {
logger.error("批量上传合同错误", ex); logger.error("批量上传合同错误", ex);
return ResultModel.ERROR(ResultStatus.UPLOAD_ERRO); return ResultModel.ERROR(ResultStatus.UPLOAD_ERRO);
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
logger.error("", e);
}
}
} }
} }
...@@ -2576,7 +2598,7 @@ public class ContractServiceImpl implements ContractService { ...@@ -2576,7 +2598,7 @@ public class ContractServiceImpl implements ContractService {
titleKey.remove("signed_date"); titleKey.remove("signed_date");
titleKey.remove("关联合同编号"); titleKey.remove("关联合同编号");
titleKey.remove("relation_code"); titleKey.remove("relation_code");
}else if(!platform.equals("cas")){ } else if (!platform.equals("cas")) {
titleKey.remove("有效开始日"); titleKey.remove("有效开始日");
titleKey.remove("valid_start_date"); titleKey.remove("valid_start_date");
titleKey.remove("有效结束日"); titleKey.remove("有效结束日");
...@@ -2589,10 +2611,10 @@ public class ContractServiceImpl implements ContractService { ...@@ -2589,10 +2611,10 @@ public class ContractServiceImpl implements ContractService {
if ("tkio".equals(platform)) { if ("tkio".equals(platform)) {
extend_row_sql = "platform,product,my_body_code,create_time,code_num,type,status,back_status,ds," + extend_row_sql = "platform,product,my_body_code,create_time,code_num,type,status,back_status,ds," +
"create_account,create_name,relation_contract,invoice_money,first_back_id"; "create_account,create_name,relation_contract,invoice_money,first_back_id";
}else if("cas".equals(platform)){ } else if ("cas".equals(platform)) {
extend_row_sql = "platform,product,my_body_code,create_time,code_num,type,status,back_status,ds," + extend_row_sql = "platform,product,my_body_code,create_time,code_num,type,status,back_status,ds," +
"create_account,create_name,extra_flow,relation_contract,invoice_money,first_back_id,valid_start_date,valid_end_date"; "create_account,create_name,extra_flow,relation_contract,invoice_money,first_back_id,valid_start_date,valid_end_date";
} else{ } else {
extend_row_sql = "platform,product,my_body_code,create_time,code_num,type,status,back_status,ds," + extend_row_sql = "platform,product,my_body_code,create_time,code_num,type,status,back_status,ds," +
"create_account,create_name,extra_flow,relation_contract,invoice_money,first_back_id"; "create_account,create_name,extra_flow,relation_contract,invoice_money,first_back_id";
} }
...@@ -2618,7 +2640,7 @@ public class ContractServiceImpl implements ContractService { ...@@ -2618,7 +2640,7 @@ public class ContractServiceImpl implements ContractService {
} }
Map<String, String> filter = new HashMap<>(); Map<String, String> filter = new HashMap<>();
filter.put("rowIndex",j+""); filter.put("rowIndex", j + "");
for (int w = 0; w < titleKey.size(); w++) { for (int w = 0; w < titleKey.size(); w++) {
String sheetTitle = titleKey.get(w); String sheetTitle = titleKey.get(w);
...@@ -2631,24 +2653,24 @@ public class ContractServiceImpl implements ContractService { ...@@ -2631,24 +2653,24 @@ public class ContractServiceImpl implements ContractService {
s_data[w] = dataSTR; s_data[w] = dataSTR;
moreEmail.add(dataSTR.trim()); moreEmail.add(dataSTR.trim());
accountsEmail.add(dataSTR.trim()); accountsEmail.add(dataSTR.trim());
}else{ } else {
//非主账号 按照之前逻辑不变 //非主账号 按照之前逻辑不变
//return ResultModel.ERROR("第" + line_num + "行【" + SHEET_TITLE_RESERVE.get(sheetTitle) + "】不能为空,请重新上传"); //return ResultModel.ERROR("第" + line_num + "行【" + SHEET_TITLE_RESERVE.get(sheetTitle) + "】不能为空,请重新上传");
} }
} else { } else {
String dataSTR = formatter.formatCellValue(cell).trim(); String dataSTR = formatter.formatCellValue(cell).trim();
//校验合同编号 //校验合同编号
if ("contract_code".equals(sheetTitle)) { if ("contract_code".equals(sheetTitle)) {
if (!codeUniqueDic.containsKey(dataSTR)) { if (!codeUniqueDic.containsKey(dataSTR)) {
codeUniqueDic.put(dataSTR, "1"); codeUniqueDic.put(dataSTR, "1");
filter.put("contractCode",dataSTR); filter.put("contractCode", dataSTR);
} else { } else {
return ResultModel.ERROR(ResultStatus.CCODE_EXITS.getCode(),"合同编号【" + dataSTR + "】已存在,请重新上传"); return ResultModel.ERROR(ResultStatus.CCODE_EXITS.getCode(), "合同编号【" + dataSTR + "】已存在,请重新上传");
} }
Contract contractExist = contractRepository.checkByCode(dataSTR); Contract contractExist = contractRepository.checkByCode(dataSTR);
if (contractExist != null) { if (contractExist != null) {
return ResultModel.ERROR(ResultStatus.CCODE_EXITS.getCode(),"合同编号【" + dataSTR + "】已存在,请重新上传"); return ResultModel.ERROR(ResultStatus.CCODE_EXITS.getCode(), "合同编号【" + dataSTR + "】已存在,请重新上传");
} }
} }
...@@ -2677,10 +2699,10 @@ public class ContractServiceImpl implements ContractService { ...@@ -2677,10 +2699,10 @@ public class ContractServiceImpl implements ContractService {
return ResultModel.ERROR("第" + line_num + "行【签约类型】错误"); return ResultModel.ERROR("第" + line_num + "行【签约类型】错误");
} else { } else {
s_data[w] = CONTRACT_TYPE_NAME.get(dataSTR); s_data[w] = CONTRACT_TYPE_NAME.get(dataSTR);
filter.put("contractType",CONTRACT_TYPE_NAME.get(dataSTR)); filter.put("contractType", CONTRACT_TYPE_NAME.get(dataSTR));
} }
} else if ("price_level".equals(sheetTitle)) { } else if ("price_level".equals(sheetTitle)) {
if (packageMap != null && !packageMap.containsKey(dataSTR) && !(platform.equals("tkio")&&packageMap.containsValue(Long.parseLong(dataSTR)))) { if (packageMap != null && !packageMap.containsKey(dataSTR) && !(platform.equals("tkio") && packageMap.containsValue(Long.parseLong(dataSTR)))) {
return ResultModel.ERROR("第" + line_num + "行【套餐】错误"); return ResultModel.ERROR("第" + line_num + "行【套餐】错误");
} else { } else {
if (platform.equals("tkio")) { if (platform.equals("tkio")) {
...@@ -2708,19 +2730,19 @@ public class ContractServiceImpl implements ContractService { ...@@ -2708,19 +2730,19 @@ public class ContractServiceImpl implements ContractService {
Date d = cell.getDateCellValue(); Date d = cell.getDateCellValue();
DateFormat formater = new SimpleDateFormat("yyyy-MM-dd"); DateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
s_data[w] = formater.format(d); s_data[w] = formater.format(d);
if("tkio".equals(platform)){ if ("tkio".equals(platform)) {
if("signed_date".equals(sheetTitle)){ if ("signed_date".equals(sheetTitle)) {
createTime = d; createTime = d;
filter.put("signedDate",formater.format(d)); filter.put("signedDate", formater.format(d));
} }
if ("start_date".equals(sheetTitle)) { if ("start_date".equals(sheetTitle)) {
filter.put("w",String.valueOf(w)); filter.put("w", String.valueOf(w));
} }
}else if("cas".equals(platform)){ } else if ("cas".equals(platform)) {
if ("start_date".equals(sheetTitle) || "end_date".equals(sheetTitle) ) { if ("start_date".equals(sheetTitle) || "end_date".equals(sheetTitle)) {
filter.put(sheetTitle,String.valueOf(s_data[w])); filter.put(sheetTitle, String.valueOf(s_data[w]));
} }
}else{ } else {
if ("start_date".equals(sheetTitle)) { if ("start_date".equals(sheetTitle)) {
createTime = d; createTime = d;
} }
...@@ -2743,24 +2765,24 @@ public class ContractServiceImpl implements ContractService { ...@@ -2743,24 +2765,24 @@ public class ContractServiceImpl implements ContractService {
} else { } else {
return ResultModel.ERROR("第" + line_num + "行【行政区域】code错误"); return ResultModel.ERROR("第" + line_num + "行【行政区域】code错误");
} }
}else if ("barrio_id".equals(sheetTitle)) { } else if ("barrio_id".equals(sheetTitle)) {
if (barrioCityMap.containsKey(Long.parseLong(dataSTR))) { if (barrioCityMap.containsKey(Long.parseLong(dataSTR))) {
s_data[w] = dataSTR; s_data[w] = dataSTR;
} else { } else {
return ResultModel.ERROR("第" + line_num + "行【行政区域】code错误"); return ResultModel.ERROR("第" + line_num + "行【行政区域】code错误");
} }
}else if("relation_code".equals(sheetTitle)){ } else if ("relation_code".equals(sheetTitle)) {
s_data[w] = dataSTR; s_data[w] = dataSTR;
filter.put("relation_code",dataSTR); filter.put("relation_code", dataSTR);
}else if("one_time".equals(sheetTitle)){ } else if ("one_time".equals(sheetTitle)) {
if(dataSTR.equals("否")){ if (dataSTR.equals("否")) {
s_data[w] = false; s_data[w] = false;
}else{ } else {
s_data[w] = true; s_data[w] = true;
} }
filter.put("validStartDate",formatter.formatCellValue(row_data.getCell(14)).trim()); filter.put("validStartDate", formatter.formatCellValue(row_data.getCell(14)).trim());
filter.put("one_time",dataSTR); filter.put("one_time", dataSTR);
}else { } else {
//主账号不为空,按照之前逻辑不变 //主账号不为空,按照之前逻辑不变
s_data[w] = dataSTR; s_data[w] = dataSTR;
if ("email".equals(sheetTitle) && !StringUtils.isEmpty(dataSTR) && "tkio".equals(platformexcl)) { if ("email".equals(sheetTitle) && !StringUtils.isEmpty(dataSTR) && "tkio".equals(platformexcl)) {
...@@ -2768,43 +2790,43 @@ public class ContractServiceImpl implements ContractService { ...@@ -2768,43 +2790,43 @@ public class ContractServiceImpl implements ContractService {
moreEmail.add(dataSTR.trim()); moreEmail.add(dataSTR.trim());
} }
accountsEmail.add(dataSTR.trim()); accountsEmail.add(dataSTR.trim());
}else if("email".equals(sheetTitle)&&"cas".equals(platform)){ } else if ("email".equals(sheetTitle) && "cas".equals(platform)) {
filter.put(sheetTitle,dataSTR.trim()); filter.put(sheetTitle, dataSTR.trim());
} }
} }
} }
} }
if("tkio".equals(platform)&&"2".equals(filter.get("contractType"))){ if ("tkio".equals(platform) && "2".equals(filter.get("contractType"))) {
if(filter.get("relation_code")==null){ if (filter.get("relation_code") == null) {
return ResultModel.ERROR("第" + filter.get("rowIndex") + "行【关联合同编号】为空"); return ResultModel.ERROR("第" + filter.get("rowIndex") + "行【关联合同编号】为空");
}else{ } else {
String relation_code = filter.get("relation_code"); String relation_code = filter.get("relation_code");
Contract masterContract = contractRepository.findByCodePlatform(relation_code, "tkio"); Contract masterContract = contractRepository.findByCodePlatform(relation_code, "tkio");
if(masterContract==null){ if (masterContract == null) {
return ResultModel.ERROR("第" + filter.get("rowIndex") + "行【关联合同编号】不存在"); return ResultModel.ERROR("第" + filter.get("rowIndex") + "行【关联合同编号】不存在");
}else{ } else {
String endDate = masterContract.getEndDate(); String endDate = masterContract.getEndDate();
String signedDate = filter.get("signedDate"); String signedDate = filter.get("signedDate");
if(signedDate==null){ if (signedDate == null) {
return ResultModel.ERROR("第" + filter.get("rowIndex") + "行【补充协议签订日期】为空"); return ResultModel.ERROR("第" + filter.get("rowIndex") + "行【补充协议签订日期】为空");
}else{ } else {
s_data[Integer.valueOf(filter.get("w"))] = masterContract.getStartDate(); s_data[Integer.valueOf(filter.get("w"))] = masterContract.getStartDate();
if(endDate.compareTo(signedDate)<0){ if (endDate.compareTo(signedDate) < 0) {
return ResultModel.ERROR("第" + filter.get("rowIndex") + "行【补充协议签订日期】不能晚于关联合同的结束日期"); return ResultModel.ERROR("第" + filter.get("rowIndex") + "行【补充协议签订日期】不能晚于关联合同的结束日期");
} }
DateTime dateTime = new DateTime(signedDate);//补充协议晚录判断 DateTime dateTime = new DateTime(signedDate);//补充协议晚录判断
String relationCode = relation_code; String relationCode = relation_code;
while(true){ while (true) {
Contract contract = contractRepository.findByCodePlatform(relationCode, platform); Contract contract = contractRepository.findByCodePlatform(relationCode, platform);
if(StringUtils.isEmpty(contract.getNextSignedDate())){ if (StringUtils.isEmpty(contract.getNextSignedDate())) {
contract.setNextSignedDate(dateTime.plusDays(-1).toString("yyyy-MM-dd"));//签订日的前一天 contract.setNextSignedDate(dateTime.plusDays(-1).toString("yyyy-MM-dd"));//签订日的前一天
contract.setNextSignedContractCode(filter.get("contractCode")); contract.setNextSignedContractCode(filter.get("contractCode"));
masterContracts.add(contract); masterContracts.add(contract);
break; break;
}else{ } else {
relationCode = contract.getNextSignedContractCode(); relationCode = contract.getNextSignedContractCode();
} }
} }
...@@ -2812,7 +2834,7 @@ public class ContractServiceImpl implements ContractService { ...@@ -2812,7 +2834,7 @@ public class ContractServiceImpl implements ContractService {
} }
} }
} }
}else if("cas".equals(platform)){ } else if ("cas".equals(platform)) {
String email = filter.get("email"); String email = filter.get("email");
String start_date = filter.get("start_date"); String start_date = filter.get("start_date");
String end_date = filter.get("end_date"); String end_date = filter.get("end_date");
...@@ -2820,24 +2842,24 @@ public class ContractServiceImpl implements ContractService { ...@@ -2820,24 +2842,24 @@ public class ContractServiceImpl implements ContractService {
String validStartDateStr = filter.get("validStartDate"); String validStartDateStr = filter.get("validStartDate");
//if(filter.get("one_time").equals("否")){ //if(filter.get("one_time").equals("否")){
if(!StringUtils.isEmpty(validStartDateStr)){ if (!StringUtils.isEmpty(validStartDateStr)) {
DateTime dateTime = new DateTime(validStartDateStr); DateTime dateTime = new DateTime(validStartDateStr);
DateTime startDate = new DateTime(start_date); DateTime startDate = new DateTime(start_date);
if(dateTime.isBefore(startDate)){ if (dateTime.isBefore(startDate)) {
dateTime = startDate; dateTime = startDate;
}
DateTime endDate = new DateTime(end_date);
filter.put("valid_start_date",dateTime.toString("yyyy-MM-dd"));
if(filter.get("one_time").equals("否")){
filter.put("valid_end_date",end_date);
}else{
int contractAllDay = Days.daysBetween(startDate, endDate).getDays();//合同总天数-1 ,用于计算结束日期
filter.put("valid_end_date",dateTime.plusDays(contractAllDay).toString("yyyy-MM-dd"));
}
}else{
return ResultModel.ERROR("第" + rowIndex + "行主账号【" + email + "】未填写IP发送");
} }
// } DateTime endDate = new DateTime(end_date);
filter.put("valid_start_date", dateTime.toString("yyyy-MM-dd"));
if (filter.get("one_time").equals("否")) {
filter.put("valid_end_date", end_date);
} else {
int contractAllDay = Days.daysBetween(startDate, endDate).getDays();//合同总天数-1 ,用于计算结束日期
filter.put("valid_end_date", dateTime.plusDays(contractAllDay).toString("yyyy-MM-dd"));
}
} else {
return ResultModel.ERROR("第" + rowIndex + "行主账号【" + email + "】未填写IP发送");
}
// }
/*else{ /*else{
Map<String, Object> adiAccount = checkAccount( email,platform); Map<String, Object> adiAccount = checkAccount( email,platform);
if(adiAccount!=null){ if(adiAccount!=null){
...@@ -2890,7 +2912,7 @@ public class ContractServiceImpl implements ContractService { ...@@ -2890,7 +2912,7 @@ public class ContractServiceImpl implements ContractService {
String e = accountsEmail.get(i); String e = accountsEmail.get(i);
if ("tkio".equals(platformexcl) && "null".equals(e)) { if ("tkio".equals(platformexcl) && "null".equals(e)) {
// tiko允许主账号email是空 // tiko允许主账号email是空
}else{ } else {
//按照之前逻辑 //按照之前逻辑
if (!emailDic.containsKey(e)) { if (!emailDic.containsKey(e)) {
return ResultModel.ERROR("第" + (i + 1) + "行 客户主账号【" + e + "】在Office运营后台未找到,请重新上传"); return ResultModel.ERROR("第" + (i + 1) + "行 客户主账号【" + e + "】在Office运营后台未找到,请重新上传");
...@@ -2921,7 +2943,7 @@ public class ContractServiceImpl implements ContractService { ...@@ -2921,7 +2943,7 @@ public class ContractServiceImpl implements ContractService {
s_data[row_already + 12] = -1; s_data[row_already + 12] = -1;
s_data[row_already + 13] = 0; s_data[row_already + 13] = 0;
s_data[row_already + 14] = 0; s_data[row_already + 14] = 0;
if("cas".equals(platform)){ if ("cas".equals(platform)) {
s_data[row_already + 15] = filter.get("valid_start_date"); s_data[row_already + 15] = filter.get("valid_start_date");
s_data[row_already + 16] = filter.get("valid_end_date"); s_data[row_already + 16] = filter.get("valid_end_date");
} }
...@@ -3001,7 +3023,7 @@ public class ContractServiceImpl implements ContractService { ...@@ -3001,7 +3023,7 @@ public class ContractServiceImpl implements ContractService {
DateTime startDate = new DateTime("2020-01-01"); DateTime startDate = new DateTime("2020-01-01");
DateTime endDate = new DateTime("2020-01-20"); DateTime endDate = new DateTime("2020-01-20");
int contractAllDay = Days.daysBetween(startDate, endDate).getDays();//合同总天数 int contractAllDay = Days.daysBetween(startDate, endDate).getDays();//合同总天数
System.out.println(contractAllDay+" | "+startDate.plusDays(contractAllDay).toString("yyyy-MM-dd")); System.out.println(contractAllDay + " | " + startDate.plusDays(contractAllDay).toString("yyyy-MM-dd"));
} }
} }
package common.service.impl;
import common.model.*;
import common.repository.*;
import common.service.DmpIncomeService;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StopWatch;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import util.ResultModel;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Service
public class DmpIncomeServiceImpl implements DmpIncomeService {
Logger logger = LoggerFactory.getLogger(DmpIncomeServiceImpl.class);
@Autowired
DmpIncomeRepository dmpIncomeRepository;
@Autowired
ContractRepository contractRepository;
@Autowired
TradeTypeRepsitory tradeTypeRepsitory;
@Autowired
SalesRepository salesRepository;
@Autowired
PackageBaseRepository packageBaseRepository;
@Autowired
BarrioCityRepository barrioCityRepository;
@Autowired
ContractBodyRepository contractBodyRepository;
public static final Map<String, String> SHEET_NAMES = new HashMap();
private static final Map<String, String> CONTRACT_TYPE_NAME = new HashMap();
private static final Map<String, String> BUSINESS_TYPE_NAME = new HashMap();
private static final Map<String, String> SETAGREEMENT_TYPE_NAME = new HashMap();
static {
SHEET_NAMES.put("tkio", "TrackingIO");
SHEET_NAMES.put("dmp", "DMP");
SHEET_NAMES.put("fake", "防作弊卫士");
SHEET_NAMES.put("adi", "ADI");
SHEET_NAMES.put("ads", "ADS");
SHEET_NAMES.put("abtest", "ABTEST");
SHEET_NAMES.put("cas", "CAS");
CONTRACT_TYPE_NAME.put("首次签约", "0");
CONTRACT_TYPE_NAME.put("续约", "1");
CONTRACT_TYPE_NAME.put("补充协议", "2");
BUSINESS_TYPE_NAME.put("VIP", "1");//业务类型 1 VIP 2 共管
BUSINESS_TYPE_NAME.put("共管", "2");
SETAGREEMENT_TYPE_NAME.put("普通协议", "1");//协议类型 1 普通协议 2 框架协议
SETAGREEMENT_TYPE_NAME.put("框架协议", "2");
}
@Override
public List<DmpIncome> listByCode(String contractCode) {
List<DmpIncome> dmpIncomes = dmpIncomeRepository.findByContractCode(contractCode);
return dmpIncomes;
}
@Override
public List<DmpIncome> listByDs(String start, String end) {
List<DmpIncome> dmpIncomes = dmpIncomeRepository.findByContractDs(start, end);
if (dmpIncomes.isEmpty()) {
return dmpIncomes;
}
List<String> codes = dmpIncomes.stream().map(v -> v.getContractCode()).collect(Collectors.toList());
List<Object[]> contracts = contractRepository.findByDmpContractCode(codes);
Map<String, Object[]> names = contracts.stream().collect(Collectors.toMap(v -> v[0] + "", v -> v, (v1, v2) -> v1));
Map<String, String> cBodyMap = contractBodyRepository.findAllDis()
.stream().collect(Collectors.toMap(ContractBody::getCode, ContractBody::getName, (v1, v2) -> v1));
for (DmpIncome dmpIncome : dmpIncomes) {
Object[] nameItem = names.get(dmpIncome.getContractCode());
//my_body_name, customer_body, customer_short, business_type, agreement_type
if (nameItem != null) {
dmpIncome.setMyBodyName(nameItem[2] + "");
dmpIncome.setCustomerBody(nameItem[3] + "");
dmpIncome.setCustomerShort(nameItem[4] + "");
dmpIncome.setBusinessType(nameItem[5] + "");
dmpIncome.setAgreementType(nameItem[6] + "");
if (StringUtils.isEmpty(dmpIncome.getMyBodyName()) || dmpIncome.getMyBodyName().equals("null")) {
dmpIncome.setMyBodyName(cBodyMap.get(nameItem[1]));
}
}
}
return dmpIncomes;
}
@Override
public HSSFWorkbook exportIncomeList(String startDate, String endDate, String bodyCode, String serchName) {
List<DmpIncome> dmpIncomes = this.listByDs(startDate, endDate);
dmpIncomes = dmpIncomes.stream()
.filter(v -> StringUtils.isEmpty(bodyCode) || "all".equals(bodyCode) || bodyCode.equals(v.getMyBodyName()))
.filter(v -> StringUtils.isEmpty(serchName) || (v.getContractCode().contains(serchName) || v.getCustomerBody().contains(serchName) || v.getMyBodyName().contains(serchName)))
.collect(Collectors.toList());
DecimalFormat df = new DecimalFormat("##,##0.00");
//创建工作薄对象
HSSFWorkbook workbook = new HSSFWorkbook();//这里也可以设置sheet的Name
//创建工作表对象
HSSFSheet sheet = workbook.createSheet();
//创建工作表的行
HSSFRow row = sheet.createRow(0);
//表头
String[] title = "我方签约主体,收入月份,签约方,客户简称,合同编号,业务类型,结算周期,系统结算,按月结算,税率,确认收入".split(",");
for (int i = 0; i < title.length; i++) {
row.createCell(i).setCellValue(title[i]);
}
String[] bussinesName = new String[]{"", "VIP", "共管"};
for (int j = 0; j < dmpIncomes.size(); j++) {
HSSFRow rowBody = sheet.createRow(j + 1);
DmpIncome income = dmpIncomes.get(j);
String bussinesTypeName = income.getBusinessType() == null ? "" : bussinesName[Integer.parseInt(income.getBusinessType())];
String[] dataItem = new String[]{
income.getMyBodyName(), income.getIncomeMonth(), income.getCustomerBody(),
income.getCustomerShort(), income.getContractCode(), bussinesTypeName,
income.getPeriod(), income.getSysSettlement(), income.getMonthSettlement(),
income.getTaxRate(), income.getConfirmSettlement()
};
for (int w = 0; w < dataItem.length; w++) {
rowBody.createCell(w).setCellValue(dataItem[w]);
}
}
return workbook;
}
@Override
public DmpIncome update(DmpIncome dmpIncome) {
if (dmpIncome.getId() == null) {
return null;
}
DmpIncome dbItem = dmpIncomeRepository.findOne(dmpIncome.getId());
dbItem.setIncomeMonth(dmpIncome.getIncomeMonth());
dbItem.setPeriod(dmpIncome.getPeriod());
dbItem.setSysSettlement(dmpIncome.getSysSettlement());
dbItem.setMonthSettlement(dmpIncome.getMonthSettlement());
dbItem.setTaxRate(dmpIncome.getTaxRate());
dbItem.setConfirmSettlement(dmpIncome.getConfirmSettlement());
dmpIncomeRepository.save(dbItem);
return dbItem;
}
@Override
public Long delete(Long id) {
if (id == null) {
return null;
}
dmpIncomeRepository.delete(id);
return id;
}
@Override
public ResultModel uploadFile(MultipartFile file, String platform, User loginAccount) {
Workbook workbook = getWorkbook(file);
if (workbook == null) {
return ResultModel.ERROR("获取上传文件错误");
}
int rowNumber = checkSheetTitle(workbook, platform + "_income");
if (rowNumber == -1) {
return ResultModel.ERROR("模板表头错误");
} else if (rowNumber <= 1) {
return ResultModel.ERROR("文件为空");
}
Sheet sheet = workbook.getSheetAt(0);
DecimalFormat df = new DecimalFormat("##,##0.00");
CompletableFuture.runAsync(() -> {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
ExecutorService executorService = Executors.newFixedThreadPool(30);
CompletableFuture[] futures = Stream.iterate(1, n -> n + 1).limit(rowNumber - 1).map(index ->
CompletableFuture.runAsync(
() -> {
DmpIncome income = saveDmpIncomeItem(sheet, index, loginAccount);
if (income != null) {
income.setConfirmSettlement(new BigDecimal(income.getConfirmSettlement()).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
dmpIncomeRepository.save(income);
}
}, executorService)
.exceptionally((t) -> null)
).toArray(size -> new CompletableFuture[size]);
CompletableFuture.allOf(futures).join();
executorService.shutdownNow();
stopWatch.stop();
logger.info("dmp income upload {} line data use all {}s ", rowNumber - 1, stopWatch.getTotalTimeSeconds());
});
return ResultModel.OK();
}
@Override
public ResultModel contractUploadFile(MultipartFile file, String platform, User loginAccount) {
Workbook workbook = getWorkbook(file);
if (workbook == null) {
return ResultModel.ERROR("获取上传文件错误");
}
Sheet sheet = workbook.getSheetAt(0);
String sheetName = sheet.getSheetName();
if (!sheetName.equalsIgnoreCase(SHEET_NAMES.get(platform))) {
return ResultModel.ERROR("请上传对应项目模板处理的数据");
}
int rowNumber = checkSheetTitle(workbook, platform);
if (rowNumber == -1) {
return ResultModel.ERROR("模板表头错误");
} else if (rowNumber <= 1) {
return ResultModel.ERROR("文件为空");
}
List<Contract> allContracts = new ArrayList<>();
Map<String, Long> tradTypeMap = tradeTypeRepsitory.findAll()
.stream().collect(Collectors.toMap(TradeType::getName, TradeType::getId));
Map<String, Long> salseMap = salesRepository.findSaleByStatus(0)
.stream().collect(Collectors.toMap(Sales::getName, Sales::getId));
Map<Long, String> barrioCityMap = barrioCityRepository.findAll()
.stream().collect(Collectors.toMap(BarrioCity::getId, BarrioCity::getName));
Map<String, String> cBodyMap = contractBodyRepository.findAllDis()
.stream().collect(Collectors.toMap(ContractBody::getName, ContractBody::getCode, (v1, v2) -> v1));
for (int i = 1; i < rowNumber; i++) {
Row rowItem = sheet.getRow(i);
if (rowItem == null) {
break;
}
Contract contract = new Contract();
contract.setPlatform(platform);
contract.setProduct(platform);
contract.setStatus("normal");
contract.setType("main");
contract.setCreateAccount(loginAccount.getId());
contract.setCreateName(loginAccount.getName());
contract.setDs(DateTime.now().toString("yyyy-MM-dd"));
//填充数据
fillDataByRow(contract, rowItem);
//校验数据有效性
if ("erro".equals(contract.getStartDate()) || "erro".equals(contract.getEndDate())) {
return erroValueTip(i, "开始时间或结束时间");
}
if (!tradTypeMap.containsKey(contract.getTradeName())) {
return erroValueTip(i, "行业分类");
} else {
contract.setTradeType(Integer.parseInt(tradTypeMap.get(contract.getTradeName()) + ""));
}
if (!cBodyMap.containsKey(contract.getMyBodyName())) {
return erroValueTip(i, "我方签约主体");
} else {
contract.setMyBodyCode(cBodyMap.get(contract.getMyBodyName()));
}
if (StringUtils.isEmpty(contract.getCustomerBody())) {
return erroValueTip(i, "客户签约主体");
}
if (!barrioCityMap.containsKey(contract.getBarrioId())) {
return erroValueTip(i, "行政区域");
} else {
contract.setBarrioName(barrioCityMap.get(contract.getBarrioId()));
}
if (!salseMap.containsKey(contract.getSaleName())) {
return erroValueTip(i, "签约销售");
} else {
contract.setSale(salseMap.get(contract.getSaleName()));
}
/*if (StringUtils.isEmpty(contract.getEmail())) {
return erroValueTip(i, "客户主账号");
}*/
if (StringUtils.isEmpty(contract.getContractCode())) {
return erroValueTip(i, "合同编号");
} else {
String[] codeArr = contract.getContractCode().split("-");
if (codeArr.length == 4) {
contract.setCodeNum(Integer.parseInt(codeArr[3]));
}
}
if (!CONTRACT_TYPE_NAME.containsKey(contract.getContractType())) {
return erroValueTip(i, "签约类型");
} else {
contract.setContractType(CONTRACT_TYPE_NAME.get(contract.getContractType()));
}
if (!BUSINESS_TYPE_NAME.containsKey(contract.getBusinessTypeName())) {
return erroValueTip(i, "业务类型");
} else {
contract.setBusinessType(Integer.parseInt(BUSINESS_TYPE_NAME.get(contract.getBusinessTypeName())));
}
if (!SETAGREEMENT_TYPE_NAME.containsKey(contract.getAgreementTypeName())) {
return erroValueTip(i, "协议类型");
} else {
contract.setAgreementType(Integer.parseInt(SETAGREEMENT_TYPE_NAME.get(contract.getAgreementTypeName())));
}
allContracts.add(contract);
}
if (allContracts.isEmpty()) {
return ResultModel.ERROR("上传内容为空");
}
//allContracts.stream().map(v->v.getRelationCode()).collect(Collectors.toList())
CompletableFuture.runAsync(() -> {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
ExecutorService executorService = Executors.newFixedThreadPool(35);
CompletableFuture[] futures = allContracts.stream()
.map(contract -> CompletableFuture.runAsync(() -> {
if (!StringUtils.isEmpty(contract.getRelationCode())) {
List<Long> idList = contractRepository.findIdByCode(contract.getRelationCode());
if (!idList.isEmpty()) {
contract.setRelationContract(idList.get(0));
} else {
contract.setRelationContract(-1L);
}
} else {
contract.setRelationContract(-1L);
}
if (contract.getRelationContract() < 0) {
contract.setRelationCode(null);
}
//删除已经重复的记录
contractRepository.deleteByCode(contract.getContractCode(), platform);
contract.setCreateTime(new Date());
contractRepository.save(contract);
}, executorService).exceptionally((t) -> null)
).toArray(size -> new CompletableFuture[size]);
CompletableFuture.allOf(futures).join();
executorService.shutdownNow();
stopWatch.stop();
logger.info("{} contract upload {} line data use all {}s ", platform, allContracts.size(), stopWatch.getTotalTimeSeconds());
});
return ResultModel.OK();
}
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);
Row row = sheet.getRow(0);
int sheLength = sheetTitle.split("\t").length;
StringBuffer titleUp = new StringBuffer();
for (int i = 0; i < sheLength; i++) {
if (i > 0) titleUp.append(code);
titleUp.append(row.getCell(i));
}
if (!titleUp.toString().equals(sheetTitle)) {
return -1;
}
//总行数
sheLength = sheet.getLastRowNum() + 1;
return sheLength;
}
private Workbook getWorkbook(MultipartFile excelfile) {
InputStream stream = null;
Workbook workbook = null;
try {
stream = excelfile.getInputStream();
workbook = WorkbookFactory.create(stream);
} catch (Exception e) {
logger.error("", e);
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
logger.error("", e);
}
}
}
return workbook;
}
private DmpIncome saveDmpIncomeItem(Sheet sheet, int index, User user) {
//logger.info(" line index {}", index);
Row rowItem = sheet.getRow(index);
//合同编号 收入月份 结算周期 系统结算 按月结算 税率 确认收入
DmpIncome income = new DmpIncome();
income.setContractCode(getCellStringValue(rowItem, 0));
income.setIncomeMonth(getCellDateValue(rowItem, 1, "yyyy-MM"));
income.setPeriod(getCellStringValue(rowItem, 2));
income.setSysSettlement(getCellStringValue(rowItem, 3));
income.setMonthSettlement(getCellStringValue(rowItem, 4));
income.setTaxRate(getCellStringValue(rowItem, 5));
income.setConfirmSettlement(getCellStringValue(rowItem, 6));
// 时间 上传人
income.setCreateTime(new Date());
income.setUploadUser(user.getName());
if (StringUtils.isEmpty(income.getContractCode())) {
return null;
}
Double drate = StringUtils.isEmpty(income.getTaxRate()) ? 0 : Double.parseDouble(income.getTaxRate());
drate = new BigDecimal(drate * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
income.setTaxRate(drate + "%");
if (StringUtils.isEmpty(income.getSysSettlement())) {
income.setSysSettlement("0");
}
DmpIncome one = dmpIncomeRepository.findByCodeMonth(income.getContractCode(), income.getIncomeMonth());
if (one != null) {
// 同一合同同一月份不重复保存
return null;
}
return income;
}
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);
if (cell == null) {
return "erro";
}
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) && !"yyyy\"年\"m\"月\";@".equals(dfmate)) {
return "erro";
}
if (fm == null) {
fm = "yyyy-MM-dd";
}
if (org.apache.poi.ss.usermodel.DateUtil.isCellDateFormatted(cell)) {
// 用于转化为日期格式
Date d = cell.getDateCellValue();
DateFormat formater = new SimpleDateFormat(fm);
return formater.format(d);
}
return cell.toString();
}
private String getCellStringValue(Row row, int index) {
Cell cell = row.getCell(index);
return cell == null ? "" : cell.toString().trim();
}
private String getCellStringValue(Row row, int index, String defaulValue) {
Cell cell = row.getCell(index);
return cell == null ? defaulValue : cell.toString();
}
private void fillDataByRow(Contract contract, Row rowItem) {
//我方签约主体 客户签约主体 客户简称
contract.setMyBodyName(getCellStringValue(rowItem, 0));
contract.setCustomerBody(getCellStringValue(rowItem, 1));
contract.setCustomerShort(getCellStringValue(rowItem, 2));
// 第三方签约主体 行政区域 隶属集团 行业分类
contract.setCustomerThird(getCellStringValue(rowItem, 3));
contract.setBarrioId(new BigDecimal(getCellStringValue(rowItem, 4, "0")).longValue());
contract.setBelongGroup(getCellStringValue(rowItem, 5));
contract.setTradeName(getCellStringValue(rowItem, 6));
// 合同开始日期 合同结束日期 签约销售 客户主账号
contract.setStartDate(getCellDateValue(rowItem, 7));
contract.setEndDate(getCellDateValue(rowItem, 8));
contract.setSaleName(getCellStringValue(rowItem, 9));
contract.setEmail(getCellStringValue(rowItem, 10));
// 合同编号 签约类型 业务类型 协议类型 合同金额 关联合同编号
contract.setContractCode(getCellStringValue(rowItem, 11));
contract.setContractType(getCellStringValue(rowItem, 12));
contract.setBusinessTypeName(getCellStringValue(rowItem, 13));
contract.setAgreementTypeName(getCellStringValue(rowItem, 14));
contract.setMoney(Double.parseDouble(getCellStringValue(rowItem, 15, "0")));
contract.setRelationCode(getCellStringValue(rowItem, 16));
}
private ResultModel erroValueTip(int line, String title) {
return ResultModel.ERROR("第" + line + "行,[" + title + "]错误");
}
}
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