Commit e189e008 by lzxry

tkio分摊计算2.0

parent 787093b6
......@@ -74,7 +74,6 @@ public class Contract {
private List<String> customBodyNames;
/**
* 新增字段 20190427
*/
......@@ -97,6 +96,11 @@ public class Contract {
private Double trackFlow;//流量,tkio的,万单位
private Double unitPrice;//单价,tkio
private Double clickFlow;//区间点击数,tkio
private String nextSignedDate;//绑定下一份合同的日期
private String nextSignedContractCode;//绑定的下一份合同编号
private String signedDate;//合同签订日:补充协议才有值
private double historyTkioFlow;//万单位,保留四位
private BigDecimal unitPriceAccurate;//16位的单价
@Id
@GeneratedValue
......@@ -606,6 +610,48 @@ public class Contract {
this.incomeGross = incomeGross;
}
public String getNextSignedDate() {
return nextSignedDate;
}
public void setNextSignedDate(String nextSignedDate) {
this.nextSignedDate = nextSignedDate;
}
public String getNextSignedContractCode() {
return nextSignedContractCode;
}
public void setNextSignedContractCode(String nextSignedContractCode) {
this.nextSignedContractCode = nextSignedContractCode;
}
public String getSignedDate() {
return signedDate;
}
public void setSignedDate(String signedDate) {
this.signedDate = signedDate;
}
@Transient
public double getHistoryTkioFlow() {
return historyTkioFlow;
}
public void setHistoryTkioFlow(double historyTkioFlow) {
this.historyTkioFlow = historyTkioFlow;
}
@Transient
public BigDecimal getUnitPriceAccurate() {
return unitPriceAccurate;
}
public void setUnitPriceAccurate(BigDecimal unitPriceAccurate) {
this.unitPriceAccurate = unitPriceAccurate;
}
@Override
public String toString() {
return "Contract{" +
......@@ -650,6 +696,7 @@ public class Contract {
", incomeExcludingTax=" + incomeExcludingTax +
", intervaIncomeShare=" + intervaIncomeShare +
", incomeShareAll=" + incomeShareAll +
", incomeGross=" + incomeGross +
", shareSign=" + shareSign +
", searchName='" + searchName + '\'' +
", customBodyNames=" + customBodyNames +
......@@ -664,7 +711,16 @@ public class Contract {
", erroMessage='" + erroMessage + '\'' +
", tradeName='" + tradeName + '\'' +
", barrioId=" + barrioId +
", barrioName='" + barrioName + '\'' +
", belongGroup='" + belongGroup + '\'' +
", trackFlow=" + trackFlow +
", unitPrice=" + unitPrice +
", clickFlow=" + clickFlow +
", nextSignedDate='" + nextSignedDate + '\'' +
", nextSignedContractCode='" + nextSignedContractCode + '\'' +
", signedDate='" + signedDate + '\'' +
", historyTkioFlow=" + historyTkioFlow +
", unitPriceAccurate=" + unitPriceAccurate +
'}';
}
}
package common.model;
import java.util.List;
/**
* @author liyin
* @description
* @date
*/
public class ContractVO {
private Contract master;
private List<Contract> sideLette;
public Contract getMaster() {
return master;
}
public void setMaster(Contract master) {
this.master = master;
}
public List<Contract> getSideLette() {
return sideLette;
}
public void setSideLette(List<Contract> sideLette) {
this.sideLette = sideLette;
}
@Override
public String toString() {
return "ContractVO{" +
"master=" + master +
", sideLette=" + sideLette +
'}';
}
}
......@@ -9,6 +9,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.math.BigInteger;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
......@@ -57,7 +58,7 @@ public interface ContractRepository extends JpaRepository<Contract, Long> {
@Query(value = "select new map( c.id as id, c.contractCode as contractCode ) from Contract c where c.platform in ?1 and c.contractCode is not null and c.contractCode <> 'null' and c.status <>'del'")
List<Map> contractCodePlatform(List<String> platform);
@Query(value = "select * from contract where platform = ?1 and contract_code = ?2", nativeQuery = true)
@Query(value = "select * from contract where platform = ?2 and contract_code = ?1", nativeQuery = true)
Contract findByCodePlatform(String contractCode, String platform);
@Query(value = "select * from contract where start_date >= ?1 and start_date <= ?2 and platform in ?3 and id in ?4 and status!='del' order by ds desc", nativeQuery = true)
......@@ -128,4 +129,10 @@ public interface ContractRepository extends JpaRepository<Contract, Long> {
@Query(value = "SELECT * from contract where platform = ?1 and email = ?2", nativeQuery = true)
List<Contract> findByPlatformAndEmail(String platform, String email);
@Query(value = "SELECT * from contract where (contract_code = ?1 or relation_code = ?1) and create_time <= ?2 and id<> ?3 and contract_type <> '1'", nativeQuery = true)
List<Contract> findByCreateTimeAndCodeNotOwn(String contractCode, String createTime,Long id);
@Query(value = "select * from contract where next_signed_contract_code=?1 limit 1 ",nativeQuery = true)
Contract findByNextSignedContractCode(String contractCode);
}
......@@ -7,6 +7,7 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.ArrayList;
public interface TkioFlowRepository extends JpaRepository<TkioFlow, Long> {
......@@ -20,4 +21,7 @@ public interface TkioFlowRepository extends JpaRepository<TkioFlow, Long> {
@Query(value = "select sum(flow) from tkio_flow where contract_code = ?1 and ds >= ?2 and ds <= ?3", nativeQuery = true)
BigDecimal sumFlowByContractCodeAndDs(String code, String startDate, String endDate);
@Query(value = "select sum(flow) from tkio_flow where contract_code in ?3 and ds >= ?1 and ds <= ?2", nativeQuery = true)
BigDecimal sumFlowByDsAndContractCodes(String startDate, String endDate, ArrayList<String> contractCode);
}
......@@ -588,9 +588,39 @@ public class ContractServiceImpl implements ContractService {
}
}
calculationFlowRepository.save(calculationFlow);
//补充协议:后端逻辑顺序绑定
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());
}
String relationCode = resource.getRelationCode();
String platform = resource.getPlatform();
while(true){
Contract contract = contractRepository.findByCodePlatform(relationCode, platform);
if(StringUtils.isEmpty(contract.getNextSignedDate())){
if(ContractStatusEnum.LATE.getKey().equals(resource.getStatus())){//如果晚录则设置绑定下一份合同的日期为签订月的最后一天
contract.setNextSignedDate(dateTime.dayOfMonth().withMaximumValue().toString("yyyy-MM-dd"));
}else{
contract.setNextSignedDate(dateTime.plusDays(-1).toString("yyyy-MM-dd"));//签订日的前一天
}
contract.setNextSignedContractCode(resource.getContractCode());
contractRepository.save(contract);
break;
}else{
relationCode = contract.getNextSignedContractCode();
}
}
}
}
resource = contractRepository.save(resource);
this.saveContractRelations(resource, resource.getId());
......@@ -888,32 +918,63 @@ public class ContractServiceImpl implements ContractService {
}
resource.setStatus(contract.getStatus());
if (ContractStatusEnum.NFORMAL.getKey().equals(contract.getStatus()) || ContractStatusEnum.LATE.getKey().equals(contract.getStatus())) {
if (shareIncomeService.checkLateContract(new DateTime(resource.getStartDate()),
new DateTime(new DateTime(resource.getCreateTime()).toString("yyyy-MM-dd")))) {
resource.setStatus(ContractStatusEnum.LATE.getKey());
}else{
resource.setStatus(ContractStatusEnum.NFORMAL.getKey());
}
}
//this.calculateShareIncome(resource);
resource.setId(contract.getId());
//判断库里是否已有合同的主账号
if ("tkio".equals(resource.getPlatform()) && (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());
calculationFlow.setContractCode(resource.getContractCode());
calculationFlow.setStatus(0);
calculationFlow.setTriggerType("编辑");
calculationFlow.setCreateTime(DateUtil.getCurrentDateStr(DateUtil.C_TIME_PATTON_DEFAULT));
calculationFlow.setIsAll(false);
if (contracts == null || contracts.size() > 0) {
for (Contract contract1 : contracts) {
if (contract1.getId() != contract.getId()) {
if (intersection(contract1, resource) || intersection(contract1, contract)) {//有交集
calculationFlow.setIsAll(true);
break;
if ("tkio".equals(resource.getPlatform())) {
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());
calculationFlow.setContractCode(resource.getContractCode());
calculationFlow.setStatus(0);
calculationFlow.setTriggerType("编辑");
calculationFlow.setCreateTime(DateUtil.getCurrentDateStr(DateUtil.C_TIME_PATTON_DEFAULT));
calculationFlow.setIsAll(false);
if (contracts == null || contracts.size() > 0) {
for (Contract contract1 : contracts) {
if (contract1.getId() != contract.getId()) {
if (intersection(contract1, resource) || intersection(contract1, contract)) {//有交集
calculationFlow.setIsAll(true);
break;
}
}
}
}
calculationFlowRepository.save(calculationFlow);
}
//补充协议
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{
resource.setStatus(ContractStatusEnum.NFORMAL.getKey());
}
}
Contract bindContract = contractRepository.findByNextSignedContractCode(resource.getContractCode());
if(ContractStatusEnum.LATE.getKey().equals(resource.getStatus())){//如果晚录则设置绑定下一份合同的日期为签订月的最后一天
bindContract.setNextSignedDate(dateTime.dayOfMonth().withMaximumValue().toString("yyyy-MM-dd"));
}else{
bindContract.setNextSignedDate(dateTime.plusDays(-1).toString("yyyy-MM-dd"));//签订日的前一天
}
contractRepository.save(bindContract);
}
calculationFlowRepository.save(calculationFlow);
}
return contractRepository.save(resource);
......
......@@ -35,6 +35,7 @@ public class Constant {
public static String dbusername = resourceBundle.getString("db.username");
public static String dbpassword = resourceBundle.getString("db.password");
public static String dbdriver = resourceBundle.getString("db.driver");
public static Long tkioPriceLevelNotLimit = 20L;
......
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