Commit 8b085178 by lzxry

流量同步bug

parent b8ceff10
package common.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
/**
......@@ -10,8 +11,9 @@ import javax.persistence.Id;
*/
@Entity
public class TkioFlow {
@Id
@GeneratedValue
private Long id;
private String ds;
private String email;
private String contractCode;
......@@ -57,4 +59,12 @@ public class TkioFlow {
public void setCostFlow(Long costFlow) {
this.costFlow = costFlow;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
......@@ -7,12 +7,11 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.math.BigInteger;
public interface TkioFlowRepository extends JpaRepository<TkioFlow, Long> {
@Query(value = "select sum(flow) from tkio_flow where email = ?1 and contract_code = ?2", nativeQuery = true)
Long sumFlowByEmailAndContractCode(String email, String contractCode);
BigDecimal sumFlowByEmailAndContractCode(String email, String contractCode);
@Transactional
@Modifying
......
......@@ -16,6 +16,7 @@ import tkio.repository.AppRepository;
import tkio.service.AccountFlowRestrictService;
import util.DateUtil;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.ParseException;
import java.util.ArrayList;
......@@ -92,6 +93,7 @@ public class TrackingFlowTask {
TkioFlow tkioFlow = getTkioFlow(clickNum, yesterday, contracts.get(0));
if (tkioFlow != null) {
tkioFlowList.add(tkioFlow);
tkioFlowRepository.save(tkioFlow);
}
} else {
//多个合同
......@@ -125,10 +127,14 @@ public class TrackingFlowTask {
if (tkioFlow != null && i < contractsArray.length - 1 && tkioFlow.getCostFlow() !=null && tkioFlow.getCostFlow() > 0L) {//处理成本流量,如果超出了,依次算在下一个合同上
clickNum = BigInteger.valueOf(tkioFlow.getCostFlow());
tkioFlow.setCostFlow(null);
tkioFlowList.add(tkioFlow);
if(tkioFlow.getFlow()>0){
tkioFlowList.add(tkioFlow);
tkioFlowRepository.save(tkioFlow);
}
} else {
if (tkioFlow != null) {
tkioFlowList.add(tkioFlow);
tkioFlowRepository.save(tkioFlow);
}
break;
}
......@@ -156,6 +162,7 @@ public class TrackingFlowTask {
TkioFlow tkioFlow = getTkioFlow(clickNum, yesterday, contractsArray[j]);
if (tkioFlow != null) {
tkioFlowList.add(tkioFlow);
tkioFlowRepository.save(tkioFlow);
}
break;
}
......@@ -164,6 +171,7 @@ public class TrackingFlowTask {
TkioFlow tkioFlow = getTkioFlow(clickNum, yesterday, correlationContract.get(0));
if (tkioFlow != null) {
tkioFlowList.add(tkioFlow);
tkioFlowRepository.save(tkioFlow);
}
}
......@@ -172,7 +180,7 @@ public class TrackingFlowTask {
}
}
if (tkioFlowList.size() > 0) {
tkioFlowRepository.save(tkioFlowList);
//tkioFlowRepository.save(tkioFlowList);
}
calculationFlow.setStatus(2);
calculationFlowRepository.save(calculationFlow);
......@@ -211,6 +219,7 @@ public class TrackingFlowTask {
TkioFlow tkioFlow = getTkioFlow(clickNum, yesterday, contracts.get(0));
if(tkioFlow!=null){
tkioFlowList.add(tkioFlow);
tkioFlowRepository.save(tkioFlow);
}
}else{//多个合同
//看昨日被哪几个合同包含了
......@@ -240,13 +249,17 @@ public class TrackingFlowTask {
for (int i = 0; i < contractsArray.length; i++) {
TkioFlow tkioFlow = getTkioFlow(clickNum, yesterday, contractsArray[i]);
if(tkioFlow!=null&& i<contractsArray.length-1 && tkioFlow.getCostFlow()>0L){//处理成本流量,如果超出了,依次算在下一个合同上
if(tkioFlow!=null&& i<contractsArray.length-1 && tkioFlow.getCostFlow()!=null && tkioFlow.getCostFlow()>0L){//处理成本流量,如果超出了,依次算在下一个合同上
clickNum = BigInteger.valueOf(tkioFlow.getCostFlow());
tkioFlow.setCostFlow(null);
tkioFlowList.add(tkioFlow);
if(tkioFlow.getFlow()>0) {
tkioFlowList.add(tkioFlow);
tkioFlowRepository.save(tkioFlow);
}
}else{
if(tkioFlow!=null){
tkioFlowList.add(tkioFlow);
tkioFlowRepository.save(tkioFlow);
}
break;
}
......@@ -274,6 +287,7 @@ public class TrackingFlowTask {
TkioFlow tkioFlow = getTkioFlow(clickNum, yesterday, contractsArray[j]);
if(tkioFlow!=null){
tkioFlowList.add(tkioFlow);
tkioFlowRepository.save(tkioFlow);
}
break;
}
......@@ -285,6 +299,7 @@ public class TrackingFlowTask {
TkioFlow tkioFlow = getTkioFlow(clickNum, yesterday, correlationContract.get(0));
if(tkioFlow!=null){
tkioFlowList.add(tkioFlow);
tkioFlowRepository.save(tkioFlow);
}
}
......@@ -296,7 +311,7 @@ public class TrackingFlowTask {
}
if(tkioFlowList.size()>0){
tkioFlowRepository.save(tkioFlowList);
//tkioFlowRepository.save(tkioFlowList);
}
}
......@@ -334,13 +349,13 @@ public class TrackingFlowTask {
tkioFlow.setCostFlow(clickNum.longValue());
}else{
//查看历史总消耗流量是否超出
Long totalFlow = tkioFlowRepository.sumFlowByEmailAndContractCode(contract.getEmail(),contract.getContractCode());
BigDecimal totalFlow = tkioFlowRepository.sumFlowByEmailAndContractCode(contract.getEmail(),contract.getContractCode());
if(totalFlow!=null){
Double contractTrackFlow = contract.getTrackFlow() * 4;
if(contractTrackFlow.longValue()-totalFlow-clickNum.longValue()>=0){
Double contractTrackFlow = contract.getTrackFlow() * 10000;
if(contractTrackFlow.longValue()-totalFlow.longValue()-clickNum.longValue()>=0){
tkioFlow.setFlow(clickNum.longValue());
}else{
tkioFlow.setFlow(contractTrackFlow.longValue() - totalFlow);
tkioFlow.setFlow(contractTrackFlow.longValue() - totalFlow.longValue());
tkioFlow.setCostFlow(clickNum.longValue()-tkioFlow.getFlow());
}
}else{
......
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