Commit 37ebb5dc by kangxiaoshan

dmp 收入上传

parent 1395b186
......@@ -2,6 +2,7 @@ package common.controller;
import common.model.*;
import common.service.ContractService;
import common.service.DmpIncomeService;
import common.service.ShareIncomeService;
import dic.AuthMenuEnmm;
import dic.ContractStatusEnum;
......@@ -75,6 +76,9 @@ public class ContractController {
@Autowired
private ShareIncomeService shareIncomeService;
@Autowired
private DmpIncomeService dmpIncomeService;
@RequestMapping(value = "find", method = RequestMethod.GET)
@ResponseBody
@AuthKey(AuthMenuEnmm.CONTRACTMNG_V)
......@@ -134,13 +138,13 @@ public class ContractController {
HSSFRow row = sheet.createRow(0);
List<String> title;
if(platform.equals("tkio")){
if (platform.equals("tkio")) {
title = Arrays.asList("录入时间,合同编号,客户账号,我方签约主体,签约方,行政区域,隶属集团,行业分类,销售,开始日期,结束日期,套餐类型,合同流量(万次),赠送流量(万次),合同金额,签约类型,合同状态,回款状态,关联合同,关联合同编号,补充协议签订日期"
.split(","));
}else if(platform.equals("cas")){
} else if (platform.equals("cas")) {
title = Arrays.asList("录入时间,合同编号,客户账号,我方签约主体,签约方,行政区域,隶属集团,行业分类,销售,开始日期,结束日期,套餐类型,有效期开始日有效期结束日,合同金额,签约类型,合同状态,回款状态,关联合同"
.split(","));
}else{
} else {
title = Arrays.asList("录入时间,合同编号,客户账号,我方签约主体,签约方,行政区域,隶属集团,行业分类,销售,开始日期,结束日期,套餐类型,合同金额,签约类型,合同状态,回款状态,关联合同"
.split(","));
}
......@@ -165,7 +169,7 @@ public class ContractController {
rowBody.createCell(10).setCellValue(contract.getEndDate());
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(13).setCellValue(contract.getExtraFlow() == null ? 0 : contract.getExtraFlow());
rowBody.createCell(14).setCellValue(contract.getMoney() == null ? 0 : contract.getMoney());
......@@ -175,8 +179,8 @@ public class ContractController {
rowBody.createCell(18).setCellValue(contract.getRelationCode() == null ? "无" : "有");
rowBody.createCell(19).setCellValue(contract.getRelationCode() == null ? "" : contract.getRelationCode());
rowBody.createCell(20).setCellValue(contract.getSignedDate() == null ? "" : contract.getSignedDate());
}else{
if(platform.equals("cas")){
} else {
if (platform.equals("cas")) {
rowBody.createCell(12).setCellValue(contract.getValidStartDate());
rowBody.createCell(13).setCellValue(contract.getValidEndDate());
rowBody.createCell(14).setCellValue(contract.getMoney() == null ? 0 : contract.getMoney());
......@@ -184,7 +188,7 @@ public class ContractController {
rowBody.createCell(16).setCellValue(CONTRACT_STATUS.get(contract.getStatus()));
rowBody.createCell(17).setCellValue(CONTRACT_STATUS.get(contract.getBackStatus() + "_back"));
rowBody.createCell(18).setCellValue(contract.getRelationCode() == null ? "" : contract.getRelationCode());
}else{
} else {
rowBody.createCell(12).setCellValue(contract.getMoney() == null ? 0 : contract.getMoney());
rowBody.createCell(13).setCellValue(CONTRACT_STATUS.get(contract.getContractType()));
rowBody.createCell(14).setCellValue(CONTRACT_STATUS.get(contract.getStatus()));
......@@ -476,9 +480,12 @@ public class ContractController {
@RequestMapping(value = "/upload", method = RequestMethod.POST)
@ResponseBody
public ResultModel fileUpload2(@RequestParam("file") MultipartFile file, @PathVariable String platform,@CurrentAccount User loginAccount) {
//return service.uploadBatchInfo(file, platform,loginAccount);
return ResultModel.ERROR("导入功能暂时关闭");
public ResultModel fileUpload2(@RequestParam("file") MultipartFile file, @PathVariable String platform, @CurrentAccount User loginAccount) {
//
if (!"dmp".equals(platform)) {
return ResultModel.ERROR("导入功能暂时关闭");
}
return service.uploadBatchInfo(file, platform, loginAccount);
}
@RequestMapping(value = "/upload/tempurl", method = RequestMethod.GET)
......@@ -504,6 +511,11 @@ public class ContractController {
@RequestParam String startDate, @RequestParam String endDate,
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));
}
......@@ -515,52 +527,30 @@ public class ContractController {
@RequestParam String startDate, @RequestParam String endDate,
String bodyCode, String serchName, HttpServletResponse response, HttpServletRequest request) {
List<Contract> contracts = shareIncomeService.shareIncomeList(loginAccount, startDate, endDate, platform, bodyCode, serchName);
//byte[] content = new byte[0];
String fileName = "分摊收入报表_" + new DateTime(startDate).toString("yyyyMMdd")
+ "_" + new DateTime(endDate).toString("yyyyMMdd") + ".xls";
//StringBuilder sb = new StringBuilder();
/*sb.append("我方签约主体,签约方,合同编号,合同金额,不含税收入,合同开始时间,合同截止时间,区间使用天数,区间分摊收入,调整额,分摊总收入\r\n");*/
//sb.append("我方签约主体,签约方,合同编号,合同状态,合同金额,不含税收入,合同开始日期,合同截止日期,区间使用天数,区间分摊收入,调整额,分摊总收入\r\n");
if (platform.equals("dmp")) {
//dmp 分摊报表导出
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;
if(platform.equals("tkio")){
if (platform.equals("tkio")) {
workbook = createTKIOExcel(contracts);
}else if(platform.equals("adi")){
} else if (platform.equals("adi")) {
workbook = createADIExcel(contracts);
}else if(platform.equals("cas")){
} else if (platform.equals("cas")) {
workbook = createCASExcel(contracts);
}else{
} else {
workbook = createCommonExcel(contracts);
}
String fileName = "分摊收入报表_" + new DateTime(startDate).toString("yyyyMMdd")
+ "_" + new DateTime(endDate).toString("yyyyMMdd") + ".xls";
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) {
DecimalFormat df = new DecimalFormat("##,##0.00");
//创建工作薄对象
......@@ -602,6 +592,7 @@ public class ContractController {
}
return workbook;
}
private HSSFWorkbook createADIExcel(List<Contract> contracts) {
DecimalFormat df = new DecimalFormat("##,##0.00");
//创建工作薄对象
......@@ -641,7 +632,7 @@ public class ContractController {
return workbook;
}
private HSSFWorkbook createCommonExcel(List<Contract> contracts){
private HSSFWorkbook createCommonExcel(List<Contract> contracts) {
DecimalFormat df = new DecimalFormat("##,##0.00");
//创建工作薄对象
HSSFWorkbook workbook = new HSSFWorkbook();//这里也可以设置sheet的Name
......@@ -678,7 +669,8 @@ public class ContractController {
}
return workbook;
}
private HSSFWorkbook createTKIOExcel(List<Contract> contracts){
private HSSFWorkbook createTKIOExcel(List<Contract> contracts) {
DecimalFormat df = new DecimalFormat("##,##0.00");
DecimalFormat df2 = new DecimalFormat("##,##0.0000");
//创建工作薄对象
......@@ -709,13 +701,13 @@ public class ContractController {
rowBody.createCell(7).setCellValue(CONTRACT_STATUS.get(contract.getStatus()));
rowBody.createCell(8).setCellValue(df.format(contract.getMoney()));
rowBody.createCell(9).setCellValue(contract.getTrackFlow());
rowBody.createCell(10).setCellValue(contract.getUnitPrice()==null?0:contract.getUnitPrice());
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(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(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(10).setCellValue(contract.getUnitPrice() == null ? 0 : contract.getUnitPrice());
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(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(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(17).setCellValue(contract.getRelationCode() == null ? "" : contract.getRelationCode());
rowBody.createCell(18).setCellValue(contract.getSignedDate() == null ? "" : contract.getSignedDate());
}
......@@ -777,30 +769,32 @@ public class ContractController {
/**
* 功能描述:新建合同回显、获取行政区域列表
*
* @author liyin
* @date 2020/9/23
*/
@GetMapping("/getBarrioCities")
@ResponseBody
public ResultModel getBarrioCities(){
public ResultModel getBarrioCities() {
return ResultModel.OK(service.getBarrioCities());
}
@GetMapping("/getDate")
@ResponseBody
public ResultModel getDate(){
public ResultModel getDate() {
HashMap<String, Object> map = new HashMap<>();
map.put("new date",new Date().getTime());
map.put("getBeforeDays(1)",DateUtil.getBeforeDays(1));
map.put("getBeforeDays(0)",DateUtil.getBeforeDays(0));
map.put("getCurrentDateStr",DateUtil.getCurrentDateStr());
map.put("new date", new Date().getTime());
map.put("getBeforeDays(1)", DateUtil.getBeforeDays(1));
map.put("getBeforeDays(0)", DateUtil.getBeforeDays(0));
map.put("getCurrentDateStr", DateUtil.getCurrentDateStr());
return ResultModel.OK(map);
}
/**
* 试用流量
* 试用流量
*/
@GetMapping(value = "/trialFlow")
@ResponseBody
......@@ -809,7 +803,7 @@ public class ContractController {
@RequestParam String startDate, @RequestParam String endDate,
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 {
@GetMapping(value = "trialFlowExport", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@AuthKey(AuthMenuEnmm.CONTRACTMNG_EX)
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<String> title = Arrays.asList("主账号,流量(万次)".split(","));
HSSFWorkbook workbook = new HSSFWorkbook();
......@@ -836,7 +830,7 @@ public class ContractController {
rowBody.createCell(0).setCellValue(flow.getEmail());
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);
}
}
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 contractCode) {
//按合同查询
return ResultModel.OK(dmpIncomeService.listByCode(contractCode));
}
@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/{platform}")
public ResultModel uploadList(@RequestParam("file") MultipartFile file, @PathVariable String platform, @CurrentAccount User loginAccount) {
//上传收入数据
dmpIncomeService.uploadFile(file,platform,loginAccount);
return ResultModel.OK();
}
}
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;
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;
}
}
......@@ -100,6 +100,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)
List<Object[]> findByContractCode(List<String> codesList);
@Query(value = "select contract_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)
List<Contract> findShareContranctByDate3(String startDate, String endDate, 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);
}
......@@ -36,6 +36,7 @@ import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
......@@ -93,6 +94,8 @@ public class ContractServiceImpl implements ContractService {
put("关联合同编号", "relation_code");
put("补充协议签订日期", "signed_date");
put("是否计算一次性收入", "one_time");
put("业务类型", "business_type");
put("协议类型", "agreement_type");
}};
private static final Map<String, String> SHEET_TITLE_RESERVE = new HashMap() {{
......@@ -115,6 +118,8 @@ public class ContractServiceImpl implements ContractService {
put("relation_code", "关联合同编号");
put("signed_date", "补充协议签订日期");
put("one_time", "是否计算一次性收入");
put("business_type", "业务类型");
put("agreement_type", "协议类型");
}};
public static final String UPLOAD_TITLE = "我方签约主体,客户签约主体,行业分类,合同开始日期,合同结束日期," +
......@@ -254,17 +259,17 @@ public class ContractServiceImpl implements ContractService {
} else if ("io".equals(platfrom)) {
ioAccount4Web = ioAccount4WebRepository.findByEmail(email);
} else if ("adi".equals(platfrom) || "cas".equals(platfrom) ) {
adiUser = adiAccountService.findOne(email,"国内");
} else if ("adi".equals(platfrom) || "cas".equals(platfrom)) {
adiUser = adiAccountService.findOne(email, "国内");
}
if (null == account && null == ioAccount4Web && null == adiUser ) {
if (null == account && null == ioAccount4Web && null == adiUser) {
map.put("result", 0);
} else {
BigInteger integer = contractRepository.countNumByEmail(email, platfrom);
map.put("result", 1);
if (platfrom.equals("adi")) {
map.put("company", adiUser.getCompany());
}else if (platfrom.equals("cas")) {
} else if (platfrom.equals("cas")) {
map.put("company", adiUser.getCompany());
map.put("validStartDate", adiUser.getSendTime());
} else {
......@@ -505,9 +510,9 @@ public class ContractServiceImpl implements ContractService {
}
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();
contractExist.setId(-100L);
contractExist.setErroMessage("关联合同为必填项");
......@@ -515,7 +520,7 @@ public class ContractServiceImpl implements ContractService {
}
//补充协议开始日期不能晚于原始合同的结束日期
Contract relationContract = contractRepository.findOne(resource.getRelationContract());
if(relationContract.getEndDate().compareTo(resource.getSignedDate())<0){
if (relationContract.getEndDate().compareTo(resource.getSignedDate()) < 0) {
Contract contractExist = new Contract();
contractExist.setId(-100L);
contractExist.setErroMessage("补充协议开始日期不能晚于原始合同的结束日期");
......@@ -615,12 +620,12 @@ public class ContractServiceImpl implements ContractService {
calculationFlowRepository.save(calculationFlow);
//补充协议:后端逻辑顺序绑定
if("2".equals(resource.getContractType())){
if ("2".equals(resource.getContractType())) {
DateTime dateTime = new DateTime(resource.getSignedDate());//补充协议晚录判断
if (shareIncomeService.checkLateContract(dateTime,
new DateTime(new DateTime().toString("yyyy-MM-dd")))) {
resource.setStatus(ContractStatusEnum.LATE.getKey());
}else{
} else {
resource.setStatus(ContractStatusEnum.NFORMAL.getKey());
}
Long relationContract = resource.getRelationContract();
......@@ -629,35 +634,35 @@ public class ContractServiceImpl implements ContractService {
String relationCode = resource.getRelationCode();
resource.setStartDate(one.getStartDate());
String platform = resource.getPlatform();
while(true){
while (true) {
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"));
}else{
} else {
contract.setNextSignedDate(dateTime.plusDays(-1).toString("yyyy-MM-dd"));//签订日的前一天
}
contract.setNextSignedContractCode(resource.getContractCode());
contractRepository.save(contract);
break;
}else{
} else {
relationCode = contract.getNextSignedContractCode();
}
}
}
}else if("cas".equals(resource.getPlatform())){
} else if ("cas".equals(resource.getPlatform())) {
PackageBase one = packageBaseRepository.findOne(resource.getPriceLevel());
ADIUser adiUser = adiAccountService.findOne(resource.getEmail(),one.getPackageName());
if(adiUser==null || StringUtils.isEmpty(adiUser.getSendTime())){
ADIUser adiUser = adiAccountService.findOne(resource.getEmail(), one.getPackageName());
if (adiUser == null || StringUtils.isEmpty(adiUser.getSendTime())) {
resource.setShareSign(0);
}else{
} else {
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());
if(sendTime.isBefore(startDate)){
if (sendTime.isBefore(startDate)) {
sendTime = startDate;
}
DateTime endDate = new DateTime(resource.getEndDate());
......@@ -669,14 +674,13 @@ public class ContractServiceImpl implements ContractService {
if (shareIncomeService.checkLateContract(new DateTime(validStartDateStr),
new DateTime(new DateTime().toString("yyyy-MM-dd")))) {
resource.setStatus(ContractStatusEnum.LATE.getKey());
}else{
} else {
resource.setStatus(ContractStatusEnum.NFORMAL.getKey());
}
}
}
resource = contractRepository.save(resource);
this.saveContractRelations(resource, resource.getId());
......@@ -914,9 +918,9 @@ public class ContractServiceImpl implements ContractService {
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();
contractExist.setId(-100L);
contractExist.setErroMessage("关联合同为必填项");
......@@ -924,7 +928,7 @@ public class ContractServiceImpl implements ContractService {
}
//补充协议开始日期不能晚于原始合同的结束日期
Contract relationContract = contractRepository.findOne(resource.getRelationContract());
if(relationContract.getEndDate().compareTo(resource.getSignedDate())<0){
if (relationContract.getEndDate().compareTo(resource.getSignedDate()) < 0) {
Contract contractExist = new Contract();
contractExist.setId(-100L);
contractExist.setErroMessage("补充协议开始日期不能晚于原始合同的结束日期");
......@@ -997,20 +1001,19 @@ public class ContractServiceImpl implements ContractService {
if (shareIncomeService.checkLateContract(new DateTime(resource.getStartDate()),
new DateTime(new DateTime(resource.getCreateTime()).toString("yyyy-MM-dd")))) {
resource.setStatus(ContractStatusEnum.LATE.getKey());
}else{
} else {
resource.setStatus(ContractStatusEnum.NFORMAL.getKey());
}
}
//this.calculateShareIncome(resource);
resource.setId(contract.getId());
//判断库里是否已有合同的主账号
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());
CalculationFlow calculationFlow = new CalculationFlow();
calculationFlow.setEmail(resource.getEmail());
......@@ -1032,35 +1035,35 @@ public class ContractServiceImpl implements ContractService {
calculationFlowRepository.save(calculationFlow);
}
//补充协议
if("2".equals(resource.getContractType())){
if ("2".equals(resource.getContractType())) {
DateTime dateTime = new DateTime(resource.getSignedDate());//补充协议晚录判断
if (ContractStatusEnum.NFORMAL.getKey().equals(contract.getStatus()) || ContractStatusEnum.LATE.getKey().equals(contract.getStatus())) {
if (shareIncomeService.checkLateContract(dateTime,
new DateTime(new DateTime(resource.getCreateTime()).toString("yyyy-MM-dd")))) {
resource.setStatus(ContractStatusEnum.LATE.getKey());
}else{
} else {
resource.setStatus(ContractStatusEnum.NFORMAL.getKey());
}
}
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"));
}else{
} else {
bindContract.setNextSignedDate(dateTime.plusDays(-1).toString("yyyy-MM-dd"));//签订日的前一天
}
contractRepository.save(bindContract);
}
}else if("cas".equals(resource.getPlatform())){
} else if ("cas".equals(resource.getPlatform())) {
PackageBase one = packageBaseRepository.findOne(resource.getPriceLevel());
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);
}else{
} else {
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());
if(sendTime.isBefore(startDate)){
if (sendTime.isBefore(startDate)) {
sendTime = startDate;
}
DateTime endDate = new DateTime(resource.getEndDate());
......@@ -1072,7 +1075,7 @@ public class ContractServiceImpl implements ContractService {
if (shareIncomeService.checkLateContract(new DateTime(validStartDateStr),
new DateTime(new DateTime().toString("yyyy-MM-dd")))) {
resource.setStatus(ContractStatusEnum.LATE.getKey());
}else{
} else {
resource.setStatus(ContractStatusEnum.NFORMAL.getKey());
}
}
......@@ -1630,15 +1633,15 @@ public class ContractServiceImpl implements ContractService {
}
//对结果二次加工
if("tkio".equals(platform)){
if ("tkio".equals(platform)) {
List<Long> relationContracts = contractRepository.findRelationContractBySideAgre();//查询被补充协议关联的合同
for(Contract contract:result){
if(null ==contract.getContractType() || !"2".equals(contract.getContractType())){ //非补充协议
if(relationContracts.contains(BigInteger.valueOf(contract.getId()))){
for (Contract contract : result) {
if (null == contract.getContractType() || !"2".equals(contract.getContractType())) { //非补充协议
if (relationContracts.contains(BigInteger.valueOf(contract.getId()))) {
contract.setOperate(false);//如果合同 被补充协议关联
}
}else {
if(contract.getRelationContract()!=null && contract.getRelationContract()>0){ //补充协议
} else {
if (contract.getRelationContract() != null && contract.getRelationContract() > 0) { //补充协议
contract.setOperate(false);//如果补充协议被关联
}
}
......@@ -2489,7 +2492,9 @@ public class ContractServiceImpl implements ContractService {
int row_length;
if (platform.equals("tkio")) {
row_length = 17;
}if (platform.equals("cas")) {
} else if (platform.equals("dmp")) {
row_length = 17;
} else if (platform.equals("cas")) {
row_length = 14;
} else {
row_length = 13;
......@@ -2500,11 +2505,19 @@ public class ContractServiceImpl implements ContractService {
// while (sheetIter.hasNext()) {
// 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) {
logger.error("批量上传合同错误", ex);
return ResultModel.ERROR(ResultStatus.UPLOAD_ERRO);
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
logger.error("", e);
}
}
}
}
......@@ -2576,7 +2589,7 @@ public class ContractServiceImpl implements ContractService {
titleKey.remove("signed_date");
titleKey.remove("关联合同编号");
titleKey.remove("relation_code");
}else if(!platform.equals("cas")){
} else if (!platform.equals("cas")) {
titleKey.remove("有效开始日");
titleKey.remove("valid_start_date");
titleKey.remove("有效结束日");
......@@ -2589,10 +2602,10 @@ public class ContractServiceImpl implements ContractService {
if ("tkio".equals(platform)) {
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";
}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," +
"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," +
"create_account,create_name,extra_flow,relation_contract,invoice_money,first_back_id";
}
......@@ -2618,7 +2631,7 @@ public class ContractServiceImpl implements ContractService {
}
Map<String, String> filter = new HashMap<>();
filter.put("rowIndex",j+"");
filter.put("rowIndex", j + "");
for (int w = 0; w < titleKey.size(); w++) {
String sheetTitle = titleKey.get(w);
......@@ -2631,24 +2644,24 @@ public class ContractServiceImpl implements ContractService {
s_data[w] = dataSTR;
moreEmail.add(dataSTR.trim());
accountsEmail.add(dataSTR.trim());
}else{
} else {
//非主账号 按照之前逻辑不变
//return ResultModel.ERROR("第" + line_num + "行【" + SHEET_TITLE_RESERVE.get(sheetTitle) + "】不能为空,请重新上传");
}
} else {
String dataSTR = formatter.formatCellValue(cell).trim();
String dataSTR = formatter.formatCellValue(cell).trim();
//校验合同编号
if ("contract_code".equals(sheetTitle)) {
if (!codeUniqueDic.containsKey(dataSTR)) {
codeUniqueDic.put(dataSTR, "1");
filter.put("contractCode",dataSTR);
filter.put("contractCode", dataSTR);
} else {
return ResultModel.ERROR(ResultStatus.CCODE_EXITS.getCode(),"合同编号【" + dataSTR + "】已存在,请重新上传");
return ResultModel.ERROR(ResultStatus.CCODE_EXITS.getCode(), "合同编号【" + dataSTR + "】已存在,请重新上传");
}
Contract contractExist = contractRepository.checkByCode(dataSTR);
if (contractExist != null) {
return ResultModel.ERROR(ResultStatus.CCODE_EXITS.getCode(),"合同编号【" + dataSTR + "】已存在,请重新上传");
return ResultModel.ERROR(ResultStatus.CCODE_EXITS.getCode(), "合同编号【" + dataSTR + "】已存在,请重新上传");
}
}
......@@ -2677,10 +2690,10 @@ public class ContractServiceImpl implements ContractService {
return ResultModel.ERROR("第" + line_num + "行【签约类型】错误");
} else {
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)) {
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 + "行【套餐】错误");
} else {
if (platform.equals("tkio")) {
......@@ -2708,19 +2721,19 @@ public class ContractServiceImpl implements ContractService {
Date d = cell.getDateCellValue();
DateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
s_data[w] = formater.format(d);
if("tkio".equals(platform)){
if("signed_date".equals(sheetTitle)){
if ("tkio".equals(platform)) {
if ("signed_date".equals(sheetTitle)) {
createTime = d;
filter.put("signedDate",formater.format(d));
filter.put("signedDate", formater.format(d));
}
if ("start_date".equals(sheetTitle)) {
filter.put("w",String.valueOf(w));
filter.put("w", String.valueOf(w));
}
}else if("cas".equals(platform)){
if ("start_date".equals(sheetTitle) || "end_date".equals(sheetTitle) ) {
filter.put(sheetTitle,String.valueOf(s_data[w]));
} else if ("cas".equals(platform)) {
if ("start_date".equals(sheetTitle) || "end_date".equals(sheetTitle)) {
filter.put(sheetTitle, String.valueOf(s_data[w]));
}
}else{
} else {
if ("start_date".equals(sheetTitle)) {
createTime = d;
}
......@@ -2743,24 +2756,24 @@ public class ContractServiceImpl implements ContractService {
} else {
return ResultModel.ERROR("第" + line_num + "行【行政区域】code错误");
}
}else if ("barrio_id".equals(sheetTitle)) {
} else if ("barrio_id".equals(sheetTitle)) {
if (barrioCityMap.containsKey(Long.parseLong(dataSTR))) {
s_data[w] = dataSTR;
} else {
return ResultModel.ERROR("第" + line_num + "行【行政区域】code错误");
}
}else if("relation_code".equals(sheetTitle)){
} else if ("relation_code".equals(sheetTitle)) {
s_data[w] = dataSTR;
filter.put("relation_code",dataSTR);
}else if("one_time".equals(sheetTitle)){
if(dataSTR.equals("否")){
filter.put("relation_code", dataSTR);
} else if ("one_time".equals(sheetTitle)) {
if (dataSTR.equals("否")) {
s_data[w] = false;
}else{
} else {
s_data[w] = true;
}
filter.put("validStartDate",formatter.formatCellValue(row_data.getCell(14)).trim());
filter.put("one_time",dataSTR);
}else {
filter.put("validStartDate", formatter.formatCellValue(row_data.getCell(14)).trim());
filter.put("one_time", dataSTR);
} else {
//主账号不为空,按照之前逻辑不变
s_data[w] = dataSTR;
if ("email".equals(sheetTitle) && !StringUtils.isEmpty(dataSTR) && "tkio".equals(platformexcl)) {
......@@ -2768,43 +2781,43 @@ public class ContractServiceImpl implements ContractService {
moreEmail.add(dataSTR.trim());
}
accountsEmail.add(dataSTR.trim());
}else if("email".equals(sheetTitle)&&"cas".equals(platform)){
filter.put(sheetTitle,dataSTR.trim());
} else if ("email".equals(sheetTitle) && "cas".equals(platform)) {
filter.put(sheetTitle, dataSTR.trim());
}
}
}
}
if("tkio".equals(platform)&&"2".equals(filter.get("contractType"))){
if(filter.get("relation_code")==null){
if ("tkio".equals(platform) && "2".equals(filter.get("contractType"))) {
if (filter.get("relation_code") == null) {
return ResultModel.ERROR("第" + filter.get("rowIndex") + "行【关联合同编号】为空");
}else{
} else {
String relation_code = filter.get("relation_code");
Contract masterContract = contractRepository.findByCodePlatform(relation_code, "tkio");
if(masterContract==null){
if (masterContract == null) {
return ResultModel.ERROR("第" + filter.get("rowIndex") + "行【关联合同编号】不存在");
}else{
} else {
String endDate = masterContract.getEndDate();
String signedDate = filter.get("signedDate");
if(signedDate==null){
if (signedDate == null) {
return ResultModel.ERROR("第" + filter.get("rowIndex") + "行【补充协议签订日期】为空");
}else{
} else {
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") + "行【补充协议签订日期】不能晚于关联合同的结束日期");
}
DateTime dateTime = new DateTime(signedDate);//补充协议晚录判断
String relationCode = relation_code;
while(true){
while (true) {
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.setNextSignedContractCode(filter.get("contractCode"));
masterContracts.add(contract);
break;
}else{
} else {
relationCode = contract.getNextSignedContractCode();
}
}
......@@ -2812,7 +2825,7 @@ public class ContractServiceImpl implements ContractService {
}
}
}
}else if("cas".equals(platform)){
} else if ("cas".equals(platform)) {
String email = filter.get("email");
String start_date = filter.get("start_date");
String end_date = filter.get("end_date");
......@@ -2820,24 +2833,24 @@ public class ContractServiceImpl implements ContractService {
String validStartDateStr = filter.get("validStartDate");
//if(filter.get("one_time").equals("否")){
if(!StringUtils.isEmpty(validStartDateStr)){
DateTime dateTime = new DateTime(validStartDateStr);
DateTime startDate = new DateTime(start_date);
if(dateTime.isBefore(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发送");
if (!StringUtils.isEmpty(validStartDateStr)) {
DateTime dateTime = new DateTime(validStartDateStr);
DateTime startDate = new DateTime(start_date);
if (dateTime.isBefore(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发送");
}
// }
/*else{
Map<String, Object> adiAccount = checkAccount( email,platform);
if(adiAccount!=null){
......@@ -2890,7 +2903,7 @@ public class ContractServiceImpl implements ContractService {
String e = accountsEmail.get(i);
if ("tkio".equals(platformexcl) && "null".equals(e)) {
// tiko允许主账号email是空
}else{
} else {
//按照之前逻辑
if (!emailDic.containsKey(e)) {
return ResultModel.ERROR("第" + (i + 1) + "行 客户主账号【" + e + "】在Office运营后台未找到,请重新上传");
......@@ -2921,7 +2934,7 @@ public class ContractServiceImpl implements ContractService {
s_data[row_already + 12] = -1;
s_data[row_already + 13] = 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 + 16] = filter.get("valid_end_date");
}
......@@ -3001,7 +3014,7 @@ public class ContractServiceImpl implements ContractService {
DateTime startDate = new DateTime("2020-01-01");
DateTime endDate = new DateTime("2020-01-20");
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.DmpIncome;
import common.model.User;
import common.repository.ContractRepository;
import common.repository.DmpIncomeRepository;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
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 javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.Map;
import java.util.List;
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
@Qualifier("dataSource")
DataSource dataSource;
@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);
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));
for (DmpIncome dmpIncome : dmpIncomes) {
Object[] nameItem = names.get(dmpIncome.getCreateTime());
//my_body_name, customer_body, customer_short, business_type, agreement_type
if (nameItem != null) {
dmpIncome.setMyBodyName(nameItem[1] + "");
dmpIncome.setCustomerBody(nameItem[2] + "");
dmpIncome.setCustomerShort(nameItem[3] + "");
dmpIncome.setBusinessType(nameItem[4] + "");
dmpIncome.setAgreementType(nameItem[5] + "");
}
}
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) && bodyCode.equals(v.getMyBodyName()))
.filter(v -> StringUtils.isEmpty(serchName) && (v.getContractCode().contains(serchName) || v.getCustomerBody().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[] dataItem = new String[]{
income.getMyBodyName(), income.getIncomeMonth(), income.getCustomerBody(),
income.getCustomerShort(), income.getContractCode(), bussinesName[Integer.parseInt(income.getBusinessType())],
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) {
InputStream stream = null;
Workbook workbook = null;
try {
stream = file.getInputStream();
workbook = WorkbookFactory.create(stream);
} catch (Exception e) {
logger.error("", e);
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
logger.error("", e);
}
}
}
if (workbook == null) {
return ResultModel.ERROR("获取上传文件错误");
}
Sheet sheet = workbook.getSheetAt(0);
Row row = sheet.getRow(0);
String sheetTitle = "合同编号\t收入月份\t结算周期\t系统结算\t按月结算\t税率\t确认收入";
int titleLength = sheetTitle.split("\t").length;
StringBuffer titleUp = new StringBuffer();
for (int i = 0; i < titleLength; i++) {
if (i > 0) titleUp.append("\t");
titleUp.append(row.getCell(i));
}
if (!titleUp.toString().equals(sheetTitle)) {
return ResultModel.ERROR("模板表头错误");
}
int rowNumber = sheet.getLastRowNum();
if (rowNumber <= 1) {
return ResultModel.ERROR("文件为空");
}
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(
() -> saveDmpIncomeItem(sheet, index, loginAccount), 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();
}
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(getCellStringValue(rowItem, 1));
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;
}
DmpIncome one = dmpIncomeRepository.findByCodeMonth(income.getContractCode(), income.getIncomeMonth());
if (one != null) {
// 同一合同同一月份不重复保存
return null;
}
dmpIncomeRepository.save(income);
return income;
}
private String getCellStringValue(Row row, int index) {
Cell cell = row.getCell(index);
return cell == null ? "" : cell.toString();
}
}
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