Commit a73907ae by lzxry

Merge branch '1608_from_1619'

parents 7cfb3ab5 1e35b579
......@@ -148,7 +148,7 @@
<!--<report.url>http://localhost:9010</report.url>-->
<report.url>http://10.3.20.41:11010</report.url>
<report.url>http://10.3.20.41:9010</report.url>
<import.temp.url>http://10.3.20.41:9001</import.temp.url>
<contract.uppath></contract.uppath>
<!--Redis setting-->
......
......@@ -135,9 +135,11 @@ public class ContractController {
//创建工作表的行
HSSFRow row = sheet.createRow(0);
List<String> title = Arrays.asList("录入时间,合同编号,客户账号,我方签约主体,签约方,行业分类,销售,开始日期,结束日期,套餐类型,合同金额,签约类型,合同状态,回款状态,关联合同"
List<String> title = Arrays.asList("录入时间,合同编号,客户账号,我方签约主体,签约方,行政区域,隶属集团,行业分类,销售,开始日期,结束日期,套餐类型,合同金额,签约类型,合同状态,回款状态,关联合同"
.split(","));
if(platform.equals("tkio")){
title.add("总点击次数(万次)");
}
int lineSize = title.size();
for (int i = 0; i < lineSize; i++) {
row.createCell(i).setCellValue(title.get(i));
......@@ -151,16 +153,22 @@ public class ContractController {
rowBody.createCell(2).setCellValue(contract.getEmail() == null ? "无" : contract.getEmail());
rowBody.createCell(3).setCellValue(contract.getMyBodyName());
rowBody.createCell(4).setCellValue(contract.getCustomerBody());
rowBody.createCell(5).setCellValue(contract.getTradeName());
rowBody.createCell(6).setCellValue(contract.getSaleName());
rowBody.createCell(7).setCellValue(contract.getStartDate());
rowBody.createCell(8).setCellValue(contract.getEndDate());
rowBody.createCell(9).setCellValue(contract.getPriceLevelName());
rowBody.createCell(10).setCellValue(contract.getMoney());
rowBody.createCell(11).setCellValue(CONTRACT_STATUS.get(contract.getContractType()));
rowBody.createCell(12).setCellValue(CONTRACT_STATUS.get(contract.getStatus()));
rowBody.createCell(13).setCellValue(CONTRACT_STATUS.get(contract.getBackStatus() + "_back"));
rowBody.createCell(14).setCellValue(contract.getRelationCode() == null ? "" : contract.getRelationCode());
rowBody.createCell(5).setCellValue(contract.getBarrioName());
rowBody.createCell(6).setCellValue(contract.getBelongGroup());
rowBody.createCell(7).setCellValue(contract.getTradeName());
rowBody.createCell(8).setCellValue(contract.getSaleName());
rowBody.createCell(9).setCellValue(contract.getStartDate());
rowBody.createCell(10).setCellValue(contract.getEndDate());
rowBody.createCell(11).setCellValue(contract.getPriceLevelName());
rowBody.createCell(12).setCellValue(contract.getMoney());
rowBody.createCell(13).setCellValue(CONTRACT_STATUS.get(contract.getContractType()));
rowBody.createCell(14).setCellValue(CONTRACT_STATUS.get(contract.getStatus()));
rowBody.createCell(15).setCellValue(CONTRACT_STATUS.get(contract.getBackStatus() + "_back"));
rowBody.createCell(16).setCellValue(contract.getRelationCode() == null ? "" : contract.getRelationCode());
if(platform.equals("tkio")){
rowBody.createCell(17).setCellValue(contract.getTrackFlow());
}
}
......@@ -484,42 +492,17 @@ public class ContractController {
List<Contract> contracts = shareIncomeService.shareIncomeList(loginAccount, startDate, endDate, platform, bodyCode, serchName);
//byte[] content = new byte[0];
DecimalFormat df = new DecimalFormat("##,##0.00");
//StringBuilder sb = new StringBuilder();
/*sb.append("我方签约主体,签约方,合同编号,合同金额,不含税收入,合同开始时间,合同截止时间,区间使用天数,区间分摊收入,调整额,分摊总收入\r\n");*/
//sb.append("我方签约主体,签约方,合同编号,合同状态,合同金额,不含税收入,合同开始日期,合同截止日期,区间使用天数,区间分摊收入,调整额,分摊总收入\r\n");
//创建工作薄对象
HSSFWorkbook workbook = new HSSFWorkbook();//这里也可以设置sheet的Name
//创建工作表对象
HSSFSheet sheet = workbook.createSheet();
//创建工作表的行
HSSFRow row = sheet.createRow(0);
List<String> title = Arrays.asList("我方签约主体,签约方,合同编号,合同状态,合同金额,不含税收入,合同开始日期,合同截止日期,区间使用天数,区间分摊收入,调整额,分摊总收入"
.split(","));
int lineSize = title.size();
for (int i = 0; i < lineSize; i++) {
row.createCell(i).setCellValue(title.get(i));
HSSFWorkbook workbook;
if(platform.equals("tkio")){
workbook = createTKIOExcel(contracts);
}else{
workbook = createCommonExcel(contracts);
}
for (int i = 0; i < contracts.size(); i++) {
Contract contract = contracts.get(i);
HSSFRow rowBody = sheet.createRow(i + 1);
rowBody.createCell(0).setCellValue(contract.getMyBodyName());
rowBody.createCell(1).setCellValue(contract.getCustomerBody());
rowBody.createCell(2).setCellValue(contract.getContractCode());
rowBody.createCell(3).setCellValue(CONTRACT_STATUS.get(contract.getStatus()));
rowBody.createCell(4).setCellValue(df.format(contract.getMoney()));
rowBody.createCell(5).setCellValue(df.format(contract.getIncomeExcludingTax() * 1.0 / 100));
rowBody.createCell(6).setCellValue(contract.getStartDate());
rowBody.createCell(7).setCellValue(contract.getEndDate());
rowBody.createCell(8).setCellValue(contract.getIntervalUseDays());
rowBody.createCell(9).setCellValue(df.format(contract.getIntervaIncomeShare() * 1.0 / 100));
rowBody.createCell(10).setCellValue(df.format(contract.getAdjustmentFund() * 1.0 / 100));
rowBody.createCell(11).setCellValue(df.format(contract.getIncomeShareAll() * 1.0 / 100));
}
String fileName = "分摊收入报表_" + new DateTime(startDate).toString("yyyyMMdd")
+ "_" + new DateTime(endDate).toString("yyyyMMdd") + ".xls";
......@@ -550,6 +533,85 @@ public class ContractController {
}
private HSSFWorkbook createCommonExcel(List<Contract> contracts){
DecimalFormat df = new DecimalFormat("##,##0.00");
//创建工作薄对象
HSSFWorkbook workbook = new HSSFWorkbook();//这里也可以设置sheet的Name
//创建工作表对象
HSSFSheet sheet = workbook.createSheet();
//创建工作表的行
HSSFRow row = sheet.createRow(0);
List<String> title = Arrays.asList("我方签约主体,签约方,合同编号,行政区域,隶属集团,合同状态,合同金额,不含税收入,合同开始日期,合同截止日期,区间使用天数,区间分摊收入,调整额,分摊总收入"
.split(","));
int lineSize = title.size();
for (int i = 0; i < lineSize; i++) {
row.createCell(i).setCellValue(title.get(i));
}
for (int i = 0; i < contracts.size(); i++) {
Contract contract = contracts.get(i);
HSSFRow rowBody = sheet.createRow(i + 1);
rowBody.createCell(0).setCellValue(contract.getMyBodyName());
rowBody.createCell(1).setCellValue(contract.getCustomerBody());
rowBody.createCell(2).setCellValue(contract.getContractCode());
rowBody.createCell(3).setCellValue(contract.getBarrioName());
rowBody.createCell(4).setCellValue(contract.getBelongGroup());
rowBody.createCell(5).setCellValue(CONTRACT_STATUS.get(contract.getStatus()));
rowBody.createCell(6).setCellValue(df.format(contract.getMoney()));
rowBody.createCell(7).setCellValue(df.format(contract.getIncomeExcludingTax() * 1.0 / 100));
rowBody.createCell(8).setCellValue(contract.getStartDate());
rowBody.createCell(9).setCellValue(contract.getEndDate());
rowBody.createCell(10).setCellValue(contract.getIntervalUseDays());
rowBody.createCell(11).setCellValue(df.format(contract.getIntervaIncomeShare() * 1.0 / 100));
rowBody.createCell(12).setCellValue(df.format(contract.getAdjustmentFund() * 1.0 / 100));
rowBody.createCell(13).setCellValue(df.format(contract.getIncomeShareAll() * 1.0 / 100));
}
return workbook;
}
private HSSFWorkbook createTKIOExcel(List<Contract> contracts){
DecimalFormat df = new DecimalFormat("##,##0.00");
DecimalFormat df2 = new DecimalFormat("##,##0.0000");
//创建工作薄对象
HSSFWorkbook workbook = new HSSFWorkbook();//这里也可以设置sheet的Name
//创建工作表对象
HSSFSheet sheet = workbook.createSheet();
//创建工作表的行
HSSFRow row = sheet.createRow(0);
List<String> title = Arrays.asList("我方签约主体,签约方,合同编号,行政区域,隶属集团,合同开始日期,合同截止日期,合同状态,合同金额(元),总点击次数(万次),单价(元/万次),区间点击数(万次),区间分摊收入(元),区间调整金额(元),区间总收入(元),累计总收入(元),赠送点击量(万次)"
.split(","));
int lineSize = title.size();
for (int i = 0; i < lineSize; i++) {
row.createCell(i).setCellValue(title.get(i));
}
for (int i = 0; i < contracts.size(); i++) {
Contract contract = contracts.get(i);
HSSFRow rowBody = sheet.createRow(i + 1);
rowBody.createCell(0).setCellValue(contract.getMyBodyName());
rowBody.createCell(1).setCellValue(contract.getCustomerBody());
rowBody.createCell(2).setCellValue(contract.getContractCode());
rowBody.createCell(3).setCellValue(contract.getBarrioName());
rowBody.createCell(4).setCellValue(contract.getBelongGroup());
rowBody.createCell(5).setCellValue(contract.getStartDate());
rowBody.createCell(6).setCellValue(contract.getEndDate());
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());
rowBody.createCell(11).setCellValue(contract.getClickFlow());
rowBody.createCell(12).setCellValue(df.format(contract.getIntervaIncomeShare() / 100.0));
rowBody.createCell(13).setCellValue(df.format(contract.getAdjustmentFund() / 100.0));
rowBody.createCell(14).setCellValue(df.format(contract.getIncomeShareAll() / 100.0));
rowBody.createCell(15).setCellValue(df.format(contract.getIncomeGross() / 100.0));
rowBody.createCell(16).setCellValue(df2.format(contract.getExtraFlow() / 10000.0));
}
return workbook;
}
private void exportWrite(String fileName, HSSFWorkbook workbook, String exportName, HttpServletResponse response) {
OutputStream os = null;
try {
......@@ -603,4 +665,17 @@ public class ContractController {
}
}
/**
* 功能描述:新建合同回显、获取行政区域列表
* @author liyin
* @date 2020/9/23
*/
@GetMapping("/getBarrioCities")
@ResponseBody
public ResultModel getBarrioCities(){
return ResultModel.OK(service.getBarrioCities());
}
}
......@@ -5,7 +5,7 @@ import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
//@Entity
public class AuthDic {
private Long id;
......@@ -14,8 +14,8 @@ public class AuthDic {
private int type;
@Id
@GeneratedValue
//@Id
//@GeneratedValue
public Long getId() {
return id;
}
......
package common.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
/**
* @author liyin
* @description
* @date
*/
@Entity
public class BarrioCity {
private Long id;
private String name;
private Long parentId;
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Long getParentId() {
return parentId;
}
public void setParentId(Long parentId) {
this.parentId = parentId;
}
}
package common.model;
import java.util.List;
/**
* @author liyin
* @description
* @date
*/
public class BarrioCityVO {
private BarrioCity parentCity;
private List<BarrioCity> cities;
public BarrioCity getParentCity() {
return parentCity;
}
public void setParentCity(BarrioCity parentCity) {
this.parentCity = parentCity;
}
public List<BarrioCity> getCities() {
return cities;
}
public void setCitys(List<BarrioCity> cities) {
this.cities = cities;
}
}
......@@ -63,9 +63,13 @@ public class Contract {
private Long incomeExcludingTax; //不含税收入 (*100的结果)
private Long intervaIncomeShare;//区间分摊收入(*100的结果)
private Long incomeShareAll;//分摊总收入(*100的结果)
private Long incomeGross;//累计总收入(*100的结果)合同自开始至选择的结束日期(分摊收入+调整金额)
private Integer shareSign;//标记是否计算分摊收入 1 计算 0 不计算
private String searchName;
private List<String> customBodyNames;
......@@ -86,6 +90,13 @@ public class Contract {
private String erroMessage;
private String tradeName;
private Long barrioId;//行政区域id
private String barrioName;//行政区域名称
private String belongGroup;//隶属集团
private Double trackFlow;//流量,tkio的
private Double unitPrice;//单价,tkio
private Double clickFlow;//区间点击数,tkio
@Id
@GeneratedValue
......@@ -501,32 +512,20 @@ public class Contract {
this.adjustmentFundForm = adjustmentFundForm;
}
public Long getBarrioId() {
return barrioId;
}
@Override
public String toString() {
return "Contract{" +
"id=" + id +
", product='" + product + '\'' +
", myBodyName='" + myBodyName + '\'' +
", myBodyCode='" + myBodyCode + '\'' +
", customerBody='" + customerBody + '\'' +
", email='" + email + '\'' +
", contractCode='" + contractCode + '\'' +
", contractType='" + contractType + '\'' +
", startDate='" + startDate + '\'' +
", endDate='" + endDate + '\'' +
", priceLevel=" + priceLevel +
", money=" + money +
", rebate=" + rebate +
", sale=" + sale +
", platform='" + platform + '\'' +
", status='" + status + '\'' +
", modifyAccount=" + modifyAccount +
", createAccount=" + createAccount +
", modifyTime=" + modifyTime +
", createTime=" + createTime +
", ds='" + ds + '\'' +
'}';
public void setBarrioId(Long barrioId) {
this.barrioId = barrioId;
}
public String getBelongGroup() {
return belongGroup;
}
public void setBelongGroup(String belongGroup) {
this.belongGroup = belongGroup;
}
public Integer getBackStatus() {
......@@ -563,4 +562,109 @@ public class Contract {
public void setShareSign(Integer shareSign) {
this.shareSign = shareSign;
}
@Transient
public String getBarrioName() {
return barrioName;
}
public void setBarrioName(String barrioName) {
this.barrioName = barrioName;
}
public Double getTrackFlow() {
return trackFlow;
}
public void setTrackFlow(Double trackFlow) {
this.trackFlow = trackFlow;
}
@Transient
public Double getUnitPrice() {
return unitPrice;
}
public void setUnitPrice(Double unitPrice) {
this.unitPrice = unitPrice;
}
@Transient
public Double getClickFlow() {
return clickFlow;
}
public void setClickFlow(Double clickFlow) {
this.clickFlow = clickFlow;
}
@Transient
public Long getIncomeGross() {
return incomeGross;
}
public void setIncomeGross(Long incomeGross) {
this.incomeGross = incomeGross;
}
@Override
public String toString() {
return "Contract{" +
"id=" + id +
", product='" + product + '\'' +
", myBodyName='" + myBodyName + '\'' +
", myBodyCode='" + myBodyCode + '\'' +
", customerBody='" + customerBody + '\'' +
", email='" + email + '\'' +
", contractCode='" + contractCode + '\'' +
", codeNum=" + codeNum +
", contractType='" + contractType + '\'' +
", startDate='" + startDate + '\'' +
", endDate='" + endDate + '\'' +
", priceLevel=" + priceLevel +
", priceLevelName='" + priceLevelName + '\'' +
", money=" + money +
", rebate=" + rebate +
", sale=" + sale +
", platform='" + platform + '\'' +
", status='" + status + '\'' +
", saleName='" + saleName + '\'' +
", payMoney=" + payMoney +
", backStatus=" + backStatus +
", invoice=" + invoice +
", invoiceMoney=" + invoiceMoney +
", createName='" + createName + '\'' +
", type='" + type + '\'' +
", priceName=" + priceName +
", old=" + old +
", extraFlow=" + extraFlow +
", modifyAccount=" + modifyAccount +
", createAccount=" + createAccount +
", modifyTime=" + modifyTime +
", createTime=" + createTime +
", ds='" + ds + '\'' +
", virtual=" + virtual +
", firstBackId=" + firstBackId +
", adjustmentFund=" + adjustmentFund +
", adjustmentFundForm='" + adjustmentFundForm + '\'' +
", intervalUseDays=" + intervalUseDays +
", incomeExcludingTax=" + incomeExcludingTax +
", intervaIncomeShare=" + intervaIncomeShare +
", incomeShareAll=" + incomeShareAll +
", shareSign=" + shareSign +
", searchName='" + searchName + '\'' +
", customBodyNames=" + customBodyNames +
", discountTimeLong=" + discountTimeLong +
", customerShort='" + customerShort + '\'' +
", customerThird='" + customerThird + '\'' +
", tradeType=" + tradeType +
", relationContract=" + relationContract +
", relationCode='" + relationCode + '\'' +
", hasDiscount='" + hasDiscount + '\'' +
", typeId='" + typeId + '\'' +
", erroMessage='" + erroMessage + '\'' +
", tradeName='" + tradeName + '\'' +
", barrioId=" + barrioId +
", belongGroup='" + belongGroup + '\'' +
'}';
}
}
package common.repository;
import common.model.BarrioCity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Transactional
public interface BarrioCityRepository extends JpaRepository<BarrioCity, Long> {
@Query(value = "select * from barrio_city where parent_id = ?1",nativeQuery = true)
List<BarrioCity> findByParentId(long parentId);
}
......@@ -99,22 +99,22 @@ 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 * 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 <> 0 ", 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);
@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 my_body_code = ?4 and status!='del' and share_sign <> 0 ", 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 my_body_code = ?4 and status!='del' and (share_sign = 1 or share_sign is null) ", nativeQuery = true)
List<Contract> findShareContranctByDate2(String startDate, String endDate, String platform, String bodyCode);
@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 (my_body_name like %?4% or customer_body like %?4% or contract_code like %?4%) and status!='del' and share_sign <> 0 ", 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 (my_body_name like %?4% or customer_body like %?4% or contract_code like %?4%) and status!='del' and (share_sign = 1 or share_sign is null) ", nativeQuery = true)
List<Contract> findShareContranctByDateSerche(String startDate, String endDate, String platform, String serchName);
@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 my_body_code = ?4 and (my_body_name like %?5% or customer_body like %?5% or contract_code like %?5%) and status!='del' and share_sign <> 0 ", 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 my_body_code = ?4 and (my_body_name like %?5% or customer_body like %?5% or contract_code like %?5%) and status!='del' and (share_sign = 1 or share_sign is null) ", nativeQuery = true)
List<Contract> findShareContranctByDate1(String startDate, String endDate, String platform, String bodyCode, String serchName);
@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 (my_body_name like %?4% or customer_body like %?4% or contract_code like %?5%) and my_body_code in ?5 and status!='del' and share_sign <> 0 ", 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 (my_body_name like %?4% or customer_body like %?4% or contract_code like %?5%) and my_body_code in ?5 and status!='del' and (share_sign = 1 or share_sign is null) ", nativeQuery = true)
List<Contract> findShareContranctByDateSercheFinace(String startDate, String endDate, String platform, String serchName, List<String> financeBodies);
@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 my_body_code in ?4 and status!='del' and share_sign <> 0 ", 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 my_body_code in ?4 and status!='del' and (share_sign = 1 or share_sign is null) ", nativeQuery = true)
List<Contract> findShareContranctByDateFinace(String startDate, String endDate, String platform, List<String> financeBodies);
@Query(value = "select contract_code from contract where customer_body =?1 and contract_code <> ?2 and status in ('backfirst','normal','late') limit 3 ", nativeQuery = true)
......
......@@ -77,4 +77,5 @@ public interface ContractService {
ResultModel uploadBatchInfo(MultipartFile file, String platform);
Object getBarrioCities();
}
\ No newline at end of file
......@@ -50,6 +50,7 @@ import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
......@@ -81,8 +82,11 @@ public class ContractServiceImpl implements ContractService {
private static final Map<String, String> SHEET_TITLE = new HashMap() {{
put("我方签约主体", "my_body_name");
put("客户签约主体", "customer_body");
put("行政区域", "barrio_id");
put("隶属集团", "belong_group");
put("行业分类", "trade_type");
put("合同金额", "money");
put("总点击次数", "track_flow");
put("客户主账号", "email");
put("合同编号", "contract_code");
put("签约类型", "contract_type");
......@@ -96,8 +100,11 @@ public class ContractServiceImpl implements ContractService {
private static final Map<String, String> SHEET_TITLE_RESERVE = new HashMap() {{
put("my_body_name", "我方签约主体");
put("customer_body", "客户签约主体");
put("barrio_id", "行政区域");
put("belong_group", "隶属集团");
put("trade_type", "行业分类");
put("money", "合同金额");
put("track_flow", "总点击次数");
put("email", "客户主账号");
put("contract_code", "合同编号");
put("contract_type", "签约类型");
......@@ -210,6 +217,9 @@ public class ContractServiceImpl implements ContractService {
@Autowired
QcloudAccountRepository qcloudAccountRepository;
@Autowired
private BarrioCityRepository barrioCityRepository;
@Override
public Map<String, Object> checkAccount(String email, String platfrom) {
......@@ -421,7 +431,7 @@ public class ContractServiceImpl implements ContractService {
List list = new ArrayList();
if ("tkio".equals(platform) || "io".equals(platform)) {
if ( "io".equals(platform)) {
List<PackageType> packageTypeList = packageTypeRepository.findIsNewAll();
for (PackageType p : packageTypeList) {
p.setType("main");
......@@ -1349,11 +1359,14 @@ public class ContractServiceImpl implements ContractService {
Map<String, String> tradeTypeMap = tradeTypeRepsitory.findAll().stream().collect(Collectors.toMap(v -> v.getId().toString(), v -> v.getName()));
if (ValidateUtil.isValid(contractList)) {
List<BarrioCity> barrioCities = barrioCityRepository.findAll();
Map<Long, BarrioCity> barrioCitiesNameMap = barrioCities.stream().collect(Collectors.toMap(BarrioCity::getId, Function.identity(), (v1, v2) -> v1));
for (Contract c : contractList) {
c.setMyBodyName(bodyMap.get(c.getMyBodyCode()));
c.setTradeName(tradeTypeMap.get(c.getTradeType() + ""));
c.setDs(new DateTime(c.getCreateTime()).toString("yyyy-MM-dd"));
if(c.getBarrioId()!=null)
c.setBarrioName(barrioCitiesNameMap.get(barrioCitiesNameMap.get(c.getBarrioId()).getParentId()).getName());
if ((c.getExtraFlow() != null && c.getExtraFlow() > 0) ||
(c.getDiscountTimeLong() != null && c.getDiscountTimeLong() > 0)) {
......@@ -1382,12 +1395,12 @@ public class ContractServiceImpl implements ContractService {
c.setSaleName(saleMap.containsKey(c.getSale()) ? saleMap.get(c.getSale()) : "");
if ("tkio".equals(platform)) {
c.setPriceLevelName(typeMap.containsKey(c.getPriceLevel()) ? typeMap.get(c.getPriceLevel()).getPackageName() : "");
} else {
//if ("tkio".equals(platform)) {
// c.setPriceLevelName(typeMap.containsKey(c.getPriceLevel()) ? typeMap.get(c.getPriceLevel()).getPackageName() : "");
//} else {
c.setPriceLevelName(packageBaseMap.get(c.getPriceLevel()) == null ? "" : packageBaseMap.get(c.getPriceLevel()).getPackageName());
}
//}
// c.setCreateName(saleMap.containsKey(c.getCreateAccount()) ? saleMap.get(c.getCreateAccount()) : "");
......@@ -1410,14 +1423,14 @@ public class ContractServiceImpl implements ContractService {
}
}
if (typeMap != null) {
/*if (typeMap != null) {
List<PackageType> typeList = packageTypeRepository.findAll();
if (ValidateUtil.isValid(typeList)) {
for (PackageType s : typeList) {
typeMap.put(s.getId(), s);
}
}
}
}*/
if (incremenMap != null) {
List<ContractIncrement> incrementList = contractIncrementRepository.findAll();
......@@ -1465,12 +1478,12 @@ public class ContractServiceImpl implements ContractService {
this.getDicMapDatas(saleMap, typeMap, null, null, packageBaseMap, platform);
contract.setSaleName(saleMap.containsKey(contract.getSale()) ? saleMap.get(contract.getSale()) : "");
if ("tkio".equals(platform)) {
contract.setPriceLevelName(typeMap.containsKey(contract.getPriceLevel()) ? typeMap.get(contract.getPriceLevel()).getPackageName() : "");
} else {
//if ("tkio".equals(platform)) {
// contract.setPriceLevelName(typeMap.containsKey(contract.getPriceLevel()) ? typeMap.get(contract.getPriceLevel()).getPackageName() : "");
//} else {
contract.setPriceLevelName(packageBaseMap.get(contract.getPriceLevel()) == null ? "" : packageBaseMap.get(contract.getPriceLevel()).getPackageName());
}
//}
contract.setCreateName(saleMap.containsKey(contract.getCreateAccount()) ? saleMap.get(contract.getCreateAccount()) : "");
......@@ -2016,7 +2029,7 @@ public class ContractServiceImpl implements ContractService {
cm.setSalseName(saleMap.get(cm.getSalse()));
if ("tkio".equals(platfrom)) {
/*if ("tkio".equals(platfrom)) {
PackageType packageType = packageTypeMap.get(cm.getPriceLevel());
......@@ -2029,9 +2042,9 @@ public class ContractServiceImpl implements ContractService {
cm.setPackageName("");
}
} else {
} else {*/
cm.setPackageName(packageBaseMap.get(cm.getPriceLevel()) == null ? "" : packageBaseMap.get(cm.getPriceLevel()).getPackageName());
}
//}
}
}
......@@ -2212,7 +2225,12 @@ public class ContractServiceImpl implements ContractService {
public ResultModel uploadBatchInfo(MultipartFile file, String platform) {
InputStream stream = null;
try {
int row_length = 11;
int row_length;
if(platform.equals("tkio")){
row_length = 14;
}else{
row_length = 13;
}
stream = file.getInputStream();
Workbook workbook = WorkbookFactory.create(stream);
// Iterator<Sheet> sheetIter = workbook.sheetIterator();
......@@ -2227,6 +2245,19 @@ public class ContractServiceImpl implements ContractService {
}
}
@Override
public Object getBarrioCities() {
List<BarrioCity> barrioCities = barrioCityRepository.findByParentId(0L);
ArrayList<BarrioCityVO> objects = new ArrayList<>();
for (BarrioCity barrioCity : barrioCities) {
BarrioCityVO barrioCityVO = new BarrioCityVO();
barrioCityVO.setParentCity(barrioCity);
barrioCityVO.setCitys(barrioCityRepository.findByParentId(barrioCity.getId()));
objects.add(barrioCityVO);
}
return objects;
}
public ResultModel saveDataBySheet(Sheet sheet, int row_length, String platformexcl) {
String sheetName = sheet.getSheetName();
......@@ -2243,7 +2274,13 @@ public class ContractServiceImpl implements ContractService {
.stream().collect(Collectors.toMap(TradeType::getName, TradeType::getId));
Map<String, Long> salseMap = salesRepository.findSaleByStatus(0)
.stream().collect(Collectors.toMap(Sales::getName, Sales::getId));
Map<String, Long> packageMap = null;
Map<String, Long> packageMap = packageBaseRepository.findByPlatAndStatus(platform, 1)
.stream().collect(Collectors.toMap(PackageBase::getPackageName, PackageBase::getId));
Map<Long, BarrioCity> barrioCityMap = barrioCityRepository.findAll()
.stream().collect(Collectors.toMap(BarrioCity::getId, Function.identity()));
/*Map<String, Long> packageMap = null;
if ("tkio".equals(platform) || "io".equals(platform)) {
packageMap = packageTypeRepository.findIsNewAll()
......@@ -2251,7 +2288,7 @@ public class ContractServiceImpl implements ContractService {
} else {
packageMap = packageBaseRepository.findByPlatAndStatus(platform, 1)
.stream().collect(Collectors.toMap(PackageBase::getPackageName, PackageBase::getId));
}
}*/
Map<String, String> cBodyMap = null;
if ("abtest".equals(platform) || "ads".equals(platform)) {
......@@ -2267,6 +2304,10 @@ public class ContractServiceImpl implements ContractService {
if (!parseRowData(row, row_length, null, titleKey)) {
return ResultModel.ERROR(ResultStatus.FORMAT_FILE_ERRO);
}
if(!platform.equals("tkio")){
titleKey.remove("总点击次数");
titleKey.remove("track_flow");
}
int row_already = titleKey.size();
String extend_row_sql = "platform,product,my_body_code,create_time,code_num,type,status,back_status,ds," +
......@@ -2285,6 +2326,7 @@ public class ContractServiceImpl implements ContractService {
Object[] s_data = new Object[titleKey.size() + extend_size];
String bodyCode = null;
String ds = null;
Date createTime = null;
if (row_data == null) {
continue;
}
......@@ -2341,11 +2383,15 @@ public class ContractServiceImpl implements ContractService {
s_data[w] = CONTRACT_TYPE_NAME.get(dataSTR);
}
} else if ("price_level".equals(sheetTitle)) {
if (packageMap != null && !packageMap.containsKey(dataSTR)) {
if (packageMap != null && (!packageMap.containsKey(dataSTR) && !packageMap.containsValue(Long.parseLong(dataSTR)))) {
return ResultModel.ERROR("第" + line_num + "行【套餐】错误");
} else {
if(platform.equals("tkio")){
s_data[w] = dataSTR;
}else{
s_data[w] = packageMap.get(dataSTR);
}
}
} else if ("start_date".equals(sheetTitle) || "end_date".equals(sheetTitle)) {
String dfmate = cell.getCellStyle().getDataFormatString();
......@@ -2362,6 +2408,9 @@ public class ContractServiceImpl implements ContractService {
if (org.apache.poi.ss.usermodel.DateUtil.isCellDateFormatted(cell)) {
// 用于转化为日期格式
Date d = cell.getDateCellValue();
if("start_date".equals(sheetTitle) ){
createTime = d;
}
DateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
s_data[w] = formater.format(d);
} else {
......@@ -2375,6 +2424,12 @@ public class ContractServiceImpl implements ContractService {
} else if ("money".equals(sheetTitle)) {
s_data[w] = dataSTR.replace(",", "");
} else if ("barrio_id".equals(sheetTitle)) {
if(barrioCityMap.containsKey(Long.parseLong(dataSTR))){
s_data[w] = dataSTR;
}else{
return ResultModel.ERROR("第" + line_num + "行【行政区域】code错误");
}
} else {
s_data[w] = dataSTR;
......@@ -2417,7 +2472,7 @@ public class ContractServiceImpl implements ContractService {
s_data[row_already] = platform;
s_data[row_already + 1] = platform;
s_data[row_already + 2] = bodyCode;
s_data[row_already + 3] = new Date();
s_data[row_already + 3] = createTime;
s_data[row_already + 4] = 0;
s_data[row_already + 5] = "main";
s_data[row_already + 6] = ContractStatusEnum.NFORMAL.getKey(); //常规合同
......
package common.service.impl;
import com.amazonaws.services.dynamodbv2.xspec.B;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import common.model.*;
import common.repository.AuthRepository;
import common.repository.ContractBodyRepository;
import common.repository.ContractChangeRepository;
import common.repository.ContractRepository;
import common.repository.*;
import common.service.ShareIncomeService;
import dic.ContractStatusEnum;
import dic.RoleEnum;
import net.sf.json.JSONArray;
import org.joda.time.DateTime;
import org.joda.time.DateTimeUtils;
import org.joda.time.Days;
import org.joda.time.Months;
import org.joda.time.format.DateTimeFormatter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import tkio.model.Account;
import tkio.repository.AccountRepository;
import tkio.repository.AppRepository;
import tkio.service.AccountFlowRestrictService;
import util.ContractBranchUtil;
import util.DateUtil;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
......@@ -40,6 +46,14 @@ public class ShareIncomeServiceImpl implements ShareIncomeService {
private ContractBodyRepository contractBodyRepository;
@Autowired
private ContractChangeRepository contractChangeRepository;
@Autowired
private BarrioCityRepository barrioCityRepository;
@Autowired
private AppRepository appRepository;
@Autowired
private AccountRepository accountRepository;
@Autowired
private AccountFlowRestrictService accountFlowRestrictService;
@Override
public List<Contract> shareIncomeList(User loginAccount, String startDate, String endDate, String platform, String bodyCode, String serchName) {
......@@ -93,6 +107,10 @@ public class ShareIncomeServiceImpl implements ShareIncomeService {
Map<String, String> bodiesNameMap = bodies.stream().collect(
Collectors.toMap(ContractBody::getCode, ContractBody::getName, (v1, v2) -> v1));
List<BarrioCity> barrioCities = barrioCityRepository.findAll();
Map<Long, BarrioCity> barrioCitiesNameMap = barrioCities.stream().collect(Collectors.toMap(BarrioCity::getId, Function.identity(), (v1, v2) -> v1));
DateTime start = new DateTime(startDate);
DateTime end = new DateTime(endDate);
......@@ -104,20 +122,329 @@ public class ShareIncomeServiceImpl implements ShareIncomeService {
try (Stream<Contract> streamContract = contracts.parallelStream()) {
streamContract.forEachOrdered(v -> {
switch (ContractBranchUtil.getValue(platform)){
case "type_one":this.shareIncome4Contract(v, start, end);break;
case "type_two":
if(v.getPriceLevel()==18){
//TKIO不限量套餐
this.shareIncome4Contract(v, start, end);
}else{
//TKIO普通流量套餐
this.shareIncome4ContractTwo(v, start, end);
}
break;
default:this.shareIncome4Contract(v, start, end);break;
}
v.setMyBodyName(bodiesNameMap.get(v.getMyBodyCode()));
if(v.getBarrioId()!=null)
v.setBarrioName(barrioCitiesNameMap.get(barrioCitiesNameMap.get(v.getBarrioId()).getParentId()).getName());
});
}
logger.info("计算分摊收入耗时:{}", (System.currentTimeMillis() - start_));
return contracts;
}
//需求禅道 1608
public void shareIncome4ContractTwo(Contract contract, DateTime start, DateTime end) {
DateTime[] selected = new DateTime[]{
start,
end};//用户筛选开始/结束日期
DateTime[] contractPart = new DateTime[]{
new DateTime(contract.getStartDate()),
new DateTime(contract.getEndDate())};//合同开始结束 时间
DateTime[] usePart = new DateTime[]{
selected[0].compareTo(contractPart[0]) <= 0 ? contractPart[0] : selected[0],
selected[1].compareTo(contractPart[1]) >= 0 ? contractPart[1] : selected[1]
};
usePart[0] = usePart[0].compareTo(usePart[1]) >= 0 ? usePart[1] : usePart[0];
Long excludTax = new BigDecimal(contract.getMoney() / 1.06)
.setScale(2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100L)).longValue();//不含税收入*100
contract.setIncomeExcludingTax(excludTax);
//计算单价,精准保留16位数
BigDecimal unitPriceAccurate = new BigDecimal(contract.getMoney()/1.06/contract.getTrackFlow())
.setScale(16, BigDecimal.ROUND_HALF_UP);
//四舍五入单价
double unitPrice = unitPriceAccurate.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
//不限量套餐会在方法里面重新赋值单价
contract.setUnitPrice(unitPrice);
//查询用户下所有appkey
Account account = accountRepository.findByEmail(contract.getEmail());
List<Account> accountList = accountRepository.findByRootParent(account.getRootParent());
List<Long> idList = new ArrayList<>();
for (Account ac : accountList) {
idList.add(ac.getId());
}
List<String> appkeys = appRepository.findAppkeysNotDebug(idList);
String appkeyStr = String.join("','", appkeys);
appkeyStr= "'"+appkeyStr+"'";
//作废合同 累计收入= 0
//中止合同 累计收入= 如果中止日期在选择日期之内,【合同开始日期-中止日期】,否则【合同开始日期-选择结束日期】,不需要考虑调整金
//晚录合同 累计收入= 同下
//正常合同 累计收入= 如果合同结束日期在选择日期之内,则直接取 [合同金额/1.06]得到总金额 ,否则 【合同开始日期-选择结束日期】
//作废合同处理
Contract cancleContract = this.cancledShareTKIO(contract, appkeyStr, unitPriceAccurate, usePart);
if (cancleContract != null) {
return;
}
//中止合同处理
Contract suspendContract = this.suspendShareTKIO(contract, appkeyStr, unitPriceAccurate,contractPart, usePart, selected);
if (suspendContract != null) {
return;
}
//晚录合同处理//正常合同处理
DateTime create = new DateTime(new DateTime(contract.getCreateTime()).toString("yyyy-MM-dd")); //录入时间点
DateTime[] creatPoints = new DateTime[]{
create, //录入日
create.dayOfMonth().withMinimumValue() //录入月1日
};
this.afterContractTKIO(contract, appkeyStr,unitPriceAccurate, contractPart, usePart, selected, creatPoints);
}
private void afterContractTKIO(Contract contract, String appkeyStr,BigDecimal unitPriceAccurate, DateTime[] contractPart,DateTime[] usePart, DateTime[] selected, DateTime[] creatPoints) {
Long adjustmentFund = 0L;//调整金
contract.setClickFlow(0.0);
boolean isLateContract = false; // 是否为晚录合同(为了兼容历史数据 此处做冗余判断)
if (ContractStatusEnum.LATE.getKey().equals(contract.getStatus())) {
isLateContract = true;
} else if (checkLateContract(contractPart[0], creatPoints[0])) {
isLateContract = true;
contract.setStatus(ContractStatusEnum.LATE.getKey());
}
boolean isLater = true;
if (!isLateContract) {
//非合同晚录
BigInteger clickNum = accountFlowRestrictService.getTotalNum(usePart[0].toString("yyyy-MM-dd"), usePart[1].toString("yyyy-MM-dd"), appkeyStr, "account_track_flow_restrict", "click_sum");
int clickFlow = clickNum==null?0:clickNum.intValue();
BigDecimal clickTenThousand = new BigDecimal(0);
if(clickFlow!=0){
clickTenThousand = new BigDecimal(clickFlow / 10000.0 * 100);
//区间点击数
contract.setClickFlow(new BigDecimal(clickFlow / 10000.0).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue());
}
//区间分摊收入
contract.setIntervaIncomeShare(unitPriceAccurate.multiply(clickTenThousand).setScale(0, BigDecimal.ROUND_HALF_UP).longValue());
contract.setAdjustmentFund(0L);
contract.setIncomeShareAll(contract.getIntervaIncomeShare());
if(checkTwoTime(selected[0],contractPart[1]) && checkTwoTime(contractPart[1],selected[1])){
contract.setIncomeGross(contract.getIncomeExcludingTax());
}else{
//累计总收入
clickNum = accountFlowRestrictService.getTotalNum(contractPart[0].toString("yyyy-MM-dd"), selected[1].toString("yyyy-MM-dd"), appkeyStr, "account_track_flow_restrict", "click_sum");
clickFlow = clickNum==null?0:clickNum.intValue();
contract.setIncomeGross(unitPriceAccurate.multiply(new BigDecimal(clickFlow / 10000.0 * 100)).setScale(0, BigDecimal.ROUND_HALF_UP).longValue());
}
isLater = false;
} else if (selected[1].isBefore(creatPoints[1])) {
//录入月1号之前 调整金为 0 分摊为 0
contract.setIntervaIncomeShare(0L);
contract.setAdjustmentFund(0L);
contract.setIncomeShareAll(contract.getIntervaIncomeShare());
contract.setClickFlow(0.0);
contract.setIncomeGross(0L);
contract.setStatus(ContractStatusEnum.LATE.getKey());
} else {
contract.setStatus(ContractStatusEnum.LATE.getKey());
//合同晚录
//所选时间范围内的分摊收入(录入月1号 即creatPoints[1] 开始计算)
DateTime useStart = creatPoints[1].compareTo(selected[0]) >= 0 ? creatPoints[1] : selected[0];
BigInteger clickNum = accountFlowRestrictService.getTotalNum(useStart.toString("yyyy-MM-dd"), usePart[1].toString("yyyy-MM-dd"), appkeyStr, "account_track_flow_restrict", "click_sum");
int clickFlow = clickNum==null?0:clickNum.intValue();
BigDecimal clickTenThousand = new BigDecimal(0);
if(clickFlow!=0){
clickTenThousand = new BigDecimal(clickFlow / 10000.0 * 100);
//区间点击数
System.out.println(new BigDecimal(clickFlow / 10000.0));
contract.setClickFlow(new BigDecimal(clickFlow / 10000.0).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue());
}
//区间分摊收入
contract.setIntervaIncomeShare(unitPriceAccurate.multiply(clickTenThousand).setScale(0, BigDecimal.ROUND_HALF_UP).longValue());
if (checkTwoTime(selected[0], creatPoints[1]) && checkTwoTime(creatPoints[1], selected[1])) {
//所选时间范围包含 录入月 1 号 显示统计的调整金
//合同开始日期,合同录入日期的一号,-1就是上个月最后一天
//contractPart[0], creatPoints[1].plusDays(-1)
clickNum = accountFlowRestrictService.getTotalNum(contractPart[0].toString("yyyy-MM-dd"),creatPoints[1].plusDays(-1).toString("yyyy-MM-dd"), appkeyStr, "account_track_flow_restrict", "click_sum");
clickFlow = clickNum==null?0:clickNum.intValue();
clickTenThousand = new BigDecimal(0);
if(clickFlow!=0){
clickTenThousand = new BigDecimal(clickFlow / 10000.0 * 100);
//区间点击数
}
contract.setAdjustmentFund(unitPriceAccurate.multiply(clickTenThousand).setScale(0, BigDecimal.ROUND_HALF_UP).longValue());
} else {
contract.setAdjustmentFund(0L);
}
if(checkTwoTime(selected[0],contractPart[1]) && checkTwoTime(contractPart[1],selected[1])){
contract.setIncomeGross(contract.getIncomeExcludingTax());
}else{
//累计总收入
clickNum = accountFlowRestrictService.getTotalNum(contractPart[0].toString("yyyy-MM-dd"), selected[1].toString("yyyy-MM-dd"), appkeyStr, "account_track_flow_restrict", "click_sum");
clickFlow = clickNum==null?0:clickNum.intValue();
contract.setIncomeGross(unitPriceAccurate.multiply(new BigDecimal(clickFlow / 10000.0 * 100)).setScale(0, BigDecimal.ROUND_HALF_UP).longValue());
}
}
if (checkTwoTime(contractPart[1], selected[1])) {
//最后一日分摊收入计算处理(合同的最后一天,不管流量剩余多少,都算作做最后一天的收入)
Long lastDay;
DateTime lastDate[];
if (isLater) {
lastDate = new DateTime[]{creatPoints[1],contractPart[1].plusDays(-1)};
} else {
lastDate = new DateTime[]{contractPart[0],contractPart[1].plusDays(-1)};
}
//合同除去最后一天的流量
BigInteger clickNum = accountFlowRestrictService.getTotalNum(lastDate[0].toString("yyyy-MM-dd"), lastDate[1].toString("yyyy-MM-dd"), appkeyStr, "account_track_flow_restrict", "click_sum");
int clickFlow = clickNum==null?0:clickNum.intValue();
BigDecimal clickTenThousand = new BigDecimal(0);
if(clickFlow!=0){
clickTenThousand = new BigDecimal(clickFlow / 10000.0 * 100);
}
long beforeTheMoney = unitPriceAccurate.multiply(clickTenThousand).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
//最后一天的流量
clickNum = accountFlowRestrictService.getTotalNum(contractPart[1].toString("yyyy-MM-dd"), contractPart[1].toString("yyyy-MM-dd"), appkeyStr, "account_track_flow_restrict", "click_sum");
clickFlow = clickNum==null?0:clickNum.intValue();
clickTenThousand = new BigDecimal(0);
if(clickFlow!=0)clickTenThousand = new BigDecimal(clickFlow / 10000.0 * 100);
long lastDayTheMoney = unitPriceAccurate.multiply(clickTenThousand).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
//合同的税后总金额减去最后合同一日之前的钱和调整金
lastDay = contract.getIncomeExcludingTax() - contract.getAdjustmentFund() - beforeTheMoney;
//最后一日 或 包含最后一日 时
contract.setIntervaIncomeShare(contract.getIntervaIncomeShare() - lastDayTheMoney + lastDay);
}
contract.setIncomeShareAll(contract.getIntervaIncomeShare() + contract.getAdjustmentFund());
}
private Contract suspendShareTKIO(Contract contract, String appkeys, BigDecimal unitPriceAccurate,DateTime[] contractPart, DateTime[] usePart,DateTime[] selected) {
if (!ContractStatusEnum.SUSPEND.getKey().equals(contract.getStatus())) {
return null;
}
ContractChange contractChange = contractChangeRepository.findByContentCode(ContractStatusEnum.SUSPEND.getValue(),
contract.getContractCode());
if (contractChange == null) {
contract.setAdjustmentFund(0L);
contract.setIntervaIncomeShare(0L);
contract.setIncomeShareAll(0L);
contract.setClickFlow(0.0);
return contract;
}
// 合同中止日
DateTime cancelDate = new DateTime(contractChange.getDs());
//中止操作入库时间
DateTime suspendDate = new DateTime(new DateTime(contractChange.getCreateTime()).toString("yyyy-MM-dd"));
contract.setClickFlow(0.0);
//调整金
Long adjustmentFund = 0L;
if (checkTwoTime(suspendDate, cancelDate)) {
adjustmentFund = 0L;
} else {
//查询调整金的点击,日期开始结束时间注意不能颠倒
BigInteger clickNum = accountFlowRestrictService.getTotalNum(cancelDate.toString("yyyy-MM-dd"), suspendDate.toString("yyyy-MM-dd"), appkeys, "account_track_flow_restrict", "click_sum");
int clickFlow = clickNum==null?0:clickNum.intValue();
BigDecimal clickTenThousand = new BigDecimal(0);
if(clickFlow!=0){
clickTenThousand = new BigDecimal(clickFlow / 10000.0 * 100);
}
adjustmentFund = unitPriceAccurate.multiply(clickTenThousand.multiply(new BigDecimal(-1))).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
}
//调整金
contract.setAdjustmentFund(adjustmentFund);
DateTime usedEnd = usePart[1].compareTo(cancelDate) <= 0 ? usePart[1] : cancelDate;
//查询开始->中止日期的点击(有收入的点击),不包括调整金
BigInteger clickNum = accountFlowRestrictService.getTotalNum(usePart[0].toString("yyyy-MM-dd"), usedEnd.toString("yyyy-MM-dd"), appkeys, "account_track_flow_restrict", "click_sum");
int clickFlow = clickNum==null?0:clickNum.intValue();
BigDecimal clickTenThousand = new BigDecimal(0);
if(clickFlow!=0){
clickTenThousand = new BigDecimal(clickFlow / 10000.0 * 100);
//区间点击数
contract.setClickFlow(new BigDecimal(clickFlow / 10000.0).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue());
}
//区间分摊收入,乘以100,前端除以100
long share = unitPriceAccurate.multiply(clickTenThousand).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
contract.setIntervaIncomeShare(share);
contract.setIncomeShareAll(share+adjustmentFund);
if(checkTwoTime(selected[0],contractPart[1]) && checkTwoTime(contractPart[1],selected[1])){
contract.setIncomeGross(contract.getIncomeExcludingTax());
}else{
//累计总收入
clickNum = accountFlowRestrictService.getTotalNum(contractPart[0].toString("yyyy-MM-dd"), selected[1].toString("yyyy-MM-dd"), appkeys, "account_track_flow_restrict", "click_sum");
clickFlow = clickNum==null?0:clickNum.intValue();
contract.setIncomeGross(unitPriceAccurate.multiply(new BigDecimal(clickFlow / 10000.0 * 100)).setScale(0, BigDecimal.ROUND_HALF_UP).longValue());
}
return contract;
}
private Contract cancledShareTKIO(Contract contract, String appkeys, BigDecimal unitPriceAccurate,DateTime[] usePart) {
if (!ContractStatusEnum.CANCEL.getKey().equals(contract.getStatus())) {
return null;
}
ContractChange contractChange = contractChangeRepository.findByContentCode(ContractStatusEnum.CANCEL.getValue(), contract.getContractCode());
if (contractChange == null) {
contract.setAdjustmentFund(0L);
contract.setIntervaIncomeShare(0L);
contract.setIncomeShareAll(0L);
contract.setClickFlow(0.0);
return contract;
}
DateTime cancelDate = new DateTime(contractChange.getDs());//合同作废日
DateTime usedEnd = usePart[1].compareTo(cancelDate) <= 0 ? usePart[1] : cancelDate;
BigInteger clickNum = accountFlowRestrictService.getTotalNum(usePart[0].toString("yyyy-MM-dd"), usedEnd.toString("yyyy-MM-dd"), appkeys, "account_track_flow_restrict", "click_sum");
int clickFlow = clickNum==null?0:clickNum.intValue();
//区间点击数
contract.setClickFlow(0.0);
BigDecimal clickTenThousand = new BigDecimal(0);
if(clickFlow!=0){
clickTenThousand = new BigDecimal(clickFlow / 10000.0 * 100);
//区间点击数
contract.setClickFlow(new BigDecimal(clickFlow / 10000.0).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue());
}
//区间分摊收入,乘以100,前端除以100
long share = unitPriceAccurate.multiply(clickTenThousand).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
contract.setIntervaIncomeShare(share);
//调整金
contract.setAdjustmentFund(share*-1L);
//分摊总收入
contract.setIncomeShareAll(0L);
contract.setIncomeGross(0L);
return contract;
}
public void shareIncome4Contract(Contract contract, DateTime start, DateTime end) {
DateTime[] selected = new DateTime[]{
start,
end};
end};//用户筛选开始/结束日期
DateTime[] contractPart = new DateTime[]{
new DateTime(contract.getStartDate()),
new DateTime(contract.getEndDate())};//合同开始结束 时间
......@@ -274,6 +601,12 @@ public class ShareIncomeServiceImpl implements ShareIncomeService {
}
}
if (checkTwoTime(selected[0], contractPart[1]) && checkTwoTime(contractPart[1], selected[1])) {
contract.setIncomeGross(shareMultiply(new BigDecimal(getDayRange(contractPart[0], contractPart[1]) + 1), dayShareIncome, 0));
} else {
contract.setIncomeGross(shareMultiply(new BigDecimal(getDayRange(contractPart[0], selected[1]) + 1), dayShareIncome, 0));
}
if (checkTwoTime(contractPart[1], selected[1])) {
//最后一日分摊金计算处理
Long lastDay;
......@@ -322,7 +655,6 @@ public class ShareIncomeServiceImpl implements ShareIncomeService {
if (checkTwoTime(suspendDate, cancelDate)) {
adjustmentFund = 0L;
} else {
adjustmentFund = shareMultiply(new BigDecimal((getDayRange(cancelDate, suspendDate) + 1) * -1), dayShareIncome, 0);
}
......@@ -335,8 +667,10 @@ public class ShareIncomeServiceImpl implements ShareIncomeService {
if (checkTwoTime(selected[0], cancelDate) && checkTwoTime(cancelDate, selected[1])) {
contract.setAdjustmentFund(adjustmentFund);
contract.setIncomeGross(shareMultiply(new BigDecimal(getDayRange(contractPart[0], cancelDate) + 1), dayShareIncome, 0));
} else {
contract.setAdjustmentFund(0L);
contract.setIncomeGross(shareMultiply(new BigDecimal(getDayRange(contractPart[0], selected[1]) + 1), dayShareIncome, 0));
}
contract.setIncomeShareAll(contract.getIntervaIncomeShare() + contract.getAdjustmentFund());
......@@ -378,7 +712,7 @@ public class ShareIncomeServiceImpl implements ShareIncomeService {
} else {
contract.setAdjustmentFund(0L);
}
contract.setIncomeGross(0L);
contract.setIncomeShareAll(contract.getIntervaIncomeShare() + contract.getAdjustmentFund());
return contract;
}
......@@ -403,13 +737,7 @@ public class ShareIncomeServiceImpl implements ShareIncomeService {
}
public static void main(String[] args) {
//2019.7.24-2020.7.23
DateTime[] middlePoiont = new DateTime[]{new DateTime("2019-12-31"), new DateTime("2020-01-01")};
DateTime[] middlePoiont2 = new DateTime[]{new DateTime("2019-07-24"), new DateTime("2020-07-23")};
System.out.println(Days.daysBetween(middlePoiont2[1], middlePoiont2[0]).getDays());
System.out.println(Days.daysBetween(middlePoiont2[1], middlePoiont[0]).getDays());
System.out.println(Days.daysBetween(middlePoiont[1], middlePoiont2[0]).getDays());
System.out.println(new BigDecimal(34009003 / 10000.0));
}
......
......@@ -18,4 +18,7 @@ public interface AppRepository extends JpaRepository<App, Long> {
@Query(value = "select appkey from app where account in ?1", nativeQuery = true)
List<String> findAppkeys(List<Long> accountId);
@Query(value = "select appkey from app where account in ?1 and is_debug is not true", nativeQuery = true)
List<String> findAppkeysNotDebug(List<Long> accountId);
}
package util;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import java.util.HashMap;
import java.util.Map;
/**
* @author liyin
* @description
* @date
*/
public class ContractBranchUtil {
private static Map<String,String> map = new HashMap<>();
static {
map.put("dmp", "type_one");
map.put("fake", "type_one");
map.put("adi", "type_one");
map.put("ads", "type_one");
map.put("abtest", "type_one");
map.put("tkio", "type_two");
}
public static String getValue(String key){
return map.get(key);
}
}
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