Commit f106616f by lzxry

流量同步

parent ed285c85
package common.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
/**
* @author liyin
* @description
* @date
*/
@Entity
public class CalculationFlow {
private Long id;
private String email;
private String contractCode;
private String triggerType;
private Boolean isAll;
private Integer status;
private String createTime;
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getContractCode() {
return contractCode;
}
public void setContractCode(String contractCode) {
this.contractCode = contractCode;
}
public String getTriggerType() {
return triggerType;
}
public void setTriggerType(String triggerType) {
this.triggerType = triggerType;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Boolean getIsAll() {
return isAll;
}
public void setIsAll(Boolean isAll) {
this.isAll = isAll;
}
public String getCreateTime() {
return createTime;
}
public void setCreateTime(String createTime) {
this.createTime = createTime;
}
}
......@@ -94,7 +94,7 @@ public class Contract {
private String barrioName;//行政区域名称
private String belongGroup;//隶属集团
private Double trackFlow;//流量,tkio的
private Double trackFlow;//流量,tkio的,万单位
private Double unitPrice;//单价,tkio
private Double clickFlow;//区间点击数,tkio
......
package common.model;
import javax.persistence.Entity;
import javax.persistence.Id;
/**
* @author liyin
* @description
* @date
*/
@Entity
public class TkioFlow {
@Id
private String ds;
private String email;
private String contractCode;
private Long flow;
private Long costFlow;
public String getDs() {
return ds;
}
public void setDs(String ds) {
this.ds = ds;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getContractCode() {
return contractCode;
}
public void setContractCode(String contractCode) {
this.contractCode = contractCode;
}
public Long getFlow() {
return flow;
}
public void setFlow(Long flow) {
this.flow = flow;
}
public Long getCostFlow() {
return costFlow;
}
public void setCostFlow(Long costFlow) {
this.costFlow = costFlow;
}
}
package common.repository;
import common.model.CalculationFlow;
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 CalculationFlowRepository extends JpaRepository<CalculationFlow,Long> {
@Query(value = "select * from calculation_flow where status = ?1",nativeQuery = true)
List<CalculationFlow> findByStatus(int status);
}
......@@ -122,4 +122,10 @@ public interface ContractRepository extends JpaRepository<Contract, Long> {
@Query(value = "select * from contract where contract_code=?1 limit 1 ", nativeQuery = true)
Contract checkByCode(String code);
@Query(value = "select distinct email from contract where platform = ?1", nativeQuery = true)
List<String> findDistinctEmailByPlatform(String platform);
@Query(value = "SELECT * from contract where platform = ?1 and email = ?2", nativeQuery = true)
List<Contract> findByPlatformAndEmail(String platform, String email);
}
package common.repository;
import common.model.TkioFlow;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
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);
@Transactional
@Modifying
@Query(value = "delete from tkio_flow where email = ?1", nativeQuery = true)
void deleteByEmail(String email);
}
......@@ -220,6 +220,9 @@ public class ContractServiceImpl implements ContractService {
@Autowired
private BarrioCityRepository barrioCityRepository;
@Autowired
private CalculationFlowRepository calculationFlowRepository;
@Override
public Map<String, Object> checkAccount(String email, String platfrom) {
......@@ -564,11 +567,33 @@ public class ContractServiceImpl implements ContractService {
//this.calculateShareIncome(resource);//判断是否计算调整金
//判断库里是否已有合同的主账号
if("tkio".equals(resource.getPlatform())){
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());
calculationFlow.setIsAll(false);
if(contracts==null || contracts.size()>0){
for (Contract contract : contracts) {
if(intersection(contract,resource)){//有交集
calculationFlow.setIsAll(true);
break;
}
}
}
calculationFlowRepository.save(calculationFlow);
}
resource = contractRepository.save(resource);
this.saveContractRelations(resource, resource.getId());
List<String> codes = contractRepository.findContractBodyNames(resource.getCustomerBody(), resource.getContractCode());
if (!codes.isEmpty()) {
// 合同编号已存在
......@@ -866,9 +891,40 @@ public class ContractServiceImpl implements ContractService {
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;
}
}
}
}
calculationFlowRepository.save(calculationFlow);
}
return contractRepository.save(resource);
}
public Boolean intersection(Contract contract1 ,Contract contract2 ){
return (DateUtil.getDate(contract1.getStartDate()).getTime()<=DateUtil.getDate(contract2.getStartDate()).getTime()&&
DateUtil.getDate(contract1.getEndDate()).getTime()>=DateUtil.getDate(contract2.getStartDate()).getTime() )||
(DateUtil.getDate(contract1.getStartDate()).getTime()<=DateUtil.getDate(contract2.getEndDate()).getTime()&&
DateUtil.getDate(contract1.getEndDate()).getTime()>=DateUtil.getDate(contract2.getEndDate()).getTime()) ||
(DateUtil.getDate(contract2.getStartDate()).getTime()<=DateUtil.getDate(contract1.getStartDate()).getTime()&&
DateUtil.getDate(contract2.getEndDate()).getTime()>=DateUtil.getDate(contract1.getEndDate()).getTime());
}
private List<ChangeDelDetail> changeDelInfoForContract(Contract byfind, Contract resource, Long pid, String ip) {
......@@ -1679,6 +1735,28 @@ public class ContractServiceImpl implements ContractService {
resource.setContent(ContractStatusEnum.SUSPEND.getValue());
contract.setStatus(ContractStatusEnum.SUSPEND.getKey());
showTip = true;
//判断库里是否已有合同的主账号
if("tkio".equals(resource.getPlatform())){
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());
calculationFlow.setIsAll(false);
if(contracts==null || contracts.size()>0){
for (Contract contract1 : contracts) {
if(contract1.getId()!=contract.getId()){
if(intersection(contract1,contract)){//有交集
calculationFlow.setIsAll(true);
break;
}
}
}
}
calculationFlowRepository.save(calculationFlow);
}
}
}
......@@ -2321,6 +2399,7 @@ public class ContractServiceImpl implements ContractService {
Map<String, String> codeUniqueDic = new HashMap<>();
List<String> accountsEmail = new ArrayList<>();
List<String> moreEmail = new ArrayList<>();
for (int j = 1; j <= rowNumber; j++) {
Row row_data = sheet.getRow(j);
Object[] s_data = new Object[titleKey.size() + extend_size];
......@@ -2434,6 +2513,9 @@ public class ContractServiceImpl implements ContractService {
s_data[w] = dataSTR;
if ("email".equals(sheetTitle) && !StringUtils.isEmpty(dataSTR) && "tkio".equals(platformexcl)) {
if(!accountsEmail.contains(dataSTR.trim())){
moreEmail.add(dataSTR.trim());
}
accountsEmail.add(dataSTR.trim());
}
}
......@@ -2509,7 +2591,17 @@ public class ContractServiceImpl implements ContractService {
// TransactionStatus transactionStatus = transactionUtils.begin();
jdbcTemplate.batchUpdate(sql.toString(), args_data);
// transactionUtils.commit(transactionStatus);
if("tkio".equals(platform)){
for (String email : moreEmail) {
CalculationFlow calculationFlow = new CalculationFlow();
calculationFlow.setEmail(email);
calculationFlow.setStatus(0);
calculationFlow.setTriggerType("导入");
calculationFlow.setCreateTime(DateUtil.getCurrentDateStr());
calculationFlow.setIsAll(true);
calculationFlowRepository.save(calculationFlow);
}
}
return ResultModel.OK();
}
......
package track.task;
import common.model.Account4Web;
import common.model.TrackAccount4Web;
import common.repository.TrackAccount4WebRepository;
import org.jsoup.helper.DataUtil;
import org.springframework.beans.factory.annotation.Autowired;
import track.model.Account;
import track.repository.TrackAccountRepository;
......
......@@ -63,4 +63,16 @@
<!--<task:scheduled ref="accountTaskCheck" method="task" cron="0 10 8 * * ?"/>-->
<!--</task:scheduled-tasks>-->
<bean id="syncTrackingFlowTask" class="track.task.TrackingFlowTask"></bean>
<task:scheduled-tasks>
<!--定时同步昨日流量(每天10点执行一次)-->
<task:scheduled ref="syncTrackingFlowTask" method="task" cron="* * 10 * * ?"/>
</task:scheduled-tasks>
<bean id="syncCalculationFlowTask" class="track.task.TrackingFlowTask"></bean>
<task:scheduled-tasks>
<!--定时同步流量(每7分钟执行一次)-->
<task:scheduled ref="syncCalculationFlowTask" method="syncFlow" cron="* 0/7 * * * ? "/>
</task:scheduled-tasks>
</beans>
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