Commit 78e3fc33 by manxiaoqiang

add flow

parent 4476f8d0
...@@ -70,6 +70,9 @@ public class LoginController ...@@ -70,6 +70,9 @@ public class LoginController
@Autowired @Autowired
AuthService authService; AuthService authService;
@Autowired
AccountFlowRestrictService accountFlowRestrictService;
@Autowired @Autowired
PackageTypeRepository packageTypeRepository; PackageTypeRepository packageTypeRepository;
...@@ -85,6 +88,24 @@ public class LoginController ...@@ -85,6 +88,24 @@ public class LoginController
Account account = loginService.login(email, password); Account account = loginService.login(email, password);
if (account != null) { if (account != null) {
if(!account.getRoleCategory().equals(5L)) {
Boolean trackAndIoBothExhaust = accountFlowRestrictService.isTrackAndIoBothExhaust(account.getId());
Long rootParent = accountRepository.findRootParentByAccountId(account.getId()).longValue();
Account rootAccount = accountRepository.findOne(rootParent);
if (trackAndIoBothExhaust) {
if (rootAccount.getAllowBehavior()) {
rtnMap.put("msg", "广告效果监控流量和行为分析流量均用尽!");
rtnMap.put("code", 211);
return ResultModel.OK(rtnMap);
} else {
rtnMap.put("msg", "广告效果监控流量已经用尽!");
rtnMap.put("code", 211);
return ResultModel.OK(rtnMap);
}
}
}
if (!account.getIsSuperUser()) { if (!account.getIsSuperUser()) {
//子账号 //子账号
if (account.getStatus() == 0) { if (account.getStatus() == 0) {
......
package com.reyun.controller.manage;
import com.reyun.model.AccountRestrict4Web;
import com.reyun.repository.AccountRepository;
import com.reyun.repository.AccountRestrict4WebRepository;
import com.reyun.service.AccountFlowRestrictService;
import com.reyun.util.ResultModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
/**
* Created by song on 2017/10/19.
*/
@Controller
@RequestMapping("/mng/accountRestrict")
public class MngAccountFlowController {
@Autowired
private AccountRestrict4WebRepository accountRestrict4WebRepository;
@Autowired
private AccountRepository accountRepository;
@Autowired
private AccountFlowRestrictService accountFlowRestrictService;
@RequestMapping(value = "find/{accountId}", method = RequestMethod.GET)
@ResponseBody
public ResultModel list(@PathVariable Long accountId) {
long superAccountId = accountRepository.findRootParentByAccountId(accountId).longValue();
AccountRestrict4Web byAccountId = accountRestrict4WebRepository.findByAccountId(superAccountId);
if(byAccountId==null){
byAccountId = accountFlowRestrictService.RestrictFlowByAccountTask(accountId);
}
return ResultModel.OK(byAccountId);
}
@RequestMapping(value = "confirm", method = RequestMethod.POST)
@ResponseBody
public ResultModel confirm(@RequestBody AccountRestrict4Web resource) {
long superAccountId = accountRepository.findRootParentByAccountId(resource.getAccountId()).longValue();
AccountRestrict4Web byAccountId1 = accountRestrict4WebRepository.findByAccountId(superAccountId);
if(resource.getTrackPastTime()!=null && resource.getTrackPastTime()){
byAccountId1.setTrackPastTimeNotified(false);
}
if(resource.getIoPastTime()!=null && resource.getIoPastTime()){
byAccountId1.setIOPastTimeNotified(false);
}
if(resource.getTrackFlow()!=null && resource.getTrackFlow()){
byAccountId1.setTrackFlowNotified(false);
}
if(resource.getIoFlow()!=null && resource.getIoFlow() ){
byAccountId1.setIOFlowNotified(false);
}
accountRestrict4WebRepository.save(byAccountId1);
return ResultModel.OK();
}
}
package com.reyun.model; package com.reyun.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Transient;
import java.math.BigInteger; import java.math.BigInteger;
@Entity
public class AccountRestrict4Web { public class AccountRestrict4Web {
private Long id;
private String packageName; private String packageName;
private String originalName; private String originalName;
private BigInteger IOLimit; private BigInteger IOLimit;
...@@ -24,6 +30,21 @@ public class AccountRestrict4Web { ...@@ -24,6 +30,21 @@ public class AccountRestrict4Web {
private Boolean isTrackFlowNotified; private Boolean isTrackFlowNotified;
private Boolean isIOFlowNotified; private Boolean isIOFlowNotified;
private Boolean allowBehavior; private Boolean allowBehavior;
private Boolean superLevel;
private Boolean ioPastTime;
private Boolean trackPastTime;
private Boolean ioFlow;
private Boolean trackFlow;
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getPackLevel() { public Long getPackLevel() {
return packLevel; return packLevel;
...@@ -192,4 +213,48 @@ public class AccountRestrict4Web { ...@@ -192,4 +213,48 @@ public class AccountRestrict4Web {
public void setAllowBehavior(Boolean allowBehavior) { public void setAllowBehavior(Boolean allowBehavior) {
this.allowBehavior = allowBehavior; this.allowBehavior = allowBehavior;
} }
public Boolean getSuperLevel() {
return superLevel;
}
public void setSuperLevel(Boolean superLevel) {
this.superLevel = superLevel;
}
@Transient
public Boolean getIoPastTime() {
return ioPastTime;
}
public void setIoPastTime(Boolean ioPastTime) {
this.ioPastTime = ioPastTime;
}
@Transient
public Boolean getTrackPastTime() {
return trackPastTime;
}
public void setTrackPastTime(Boolean trackPastTime) {
this.trackPastTime = trackPastTime;
}
@Transient
public Boolean getIoFlow() {
return ioFlow;
}
public void setIoFlow(Boolean ioFlow) {
this.ioFlow = ioFlow;
}
@Transient
public Boolean getTrackFlow() {
return trackFlow;
}
public void setTrackFlow(Boolean trackFlow) {
this.trackFlow = trackFlow;
}
} }
package com.reyun.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
public class IsNotified {
private Long id;
private String type;
private Long accountId;
private Boolean isTrackTwoMonthNotified;
private Boolean isTrackOneMonthNotified;
private Boolean isTrackTenDaysNotified;
private Boolean isTrackOneDaysNotified;
private Boolean isTrackExpireNotified;
private Boolean isIoTwoMonthNotified;
private Boolean isIoOneMonthNotified;
private Boolean isIoTenDaysNotified;
private Boolean isIoOneDaysNotified;
private Boolean isIoExpireNotified;
private Boolean isTrackThirtyPercentNotified;
private Boolean isTrackTwentyPercentNotified;
private Boolean isTrackTenPercentNotified;
private Boolean isTrackFivePercentNotified;
private Boolean isTrackExhaustPercentNotified;
private Boolean isIoThirtyPercentNotified;
private Boolean isIoTwentyPercentNotified;
private Boolean isIoTenPercentNotified;
private Boolean isIoFivePercentNotified;
private Boolean isIoExhaustPercentNotified;
private Long previousPackageLevel;
private String firstDayOfThisMonth;
private Boolean thisMonthUpgradeLevel;
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Long getAccountId() {
return accountId;
}
public void setAccountId(Long accountId) {
this.accountId = accountId;
}
public Boolean getTrackOneMonthNotified() {
return isTrackOneMonthNotified;
}
public void setTrackOneMonthNotified(Boolean trackOneMonthNotified) {
isTrackOneMonthNotified = trackOneMonthNotified;
}
public Boolean getTrackTenDaysNotified() {
return isTrackTenDaysNotified;
}
public void setTrackTenDaysNotified(Boolean trackTenDaysNotified) {
isTrackTenDaysNotified = trackTenDaysNotified;
}
public Boolean getTrackOneDaysNotified() {
return isTrackOneDaysNotified;
}
public void setTrackOneDaysNotified(Boolean trackOneDaysNotified) {
isTrackOneDaysNotified = trackOneDaysNotified;
}
public Boolean getTrackExpireNotified() {
return isTrackExpireNotified;
}
public void setTrackExpireNotified(Boolean trackExpireNotified) {
isTrackExpireNotified = trackExpireNotified;
}
public Boolean getIoOneMonthNotified() {
return isIoOneMonthNotified;
}
public void setIoOneMonthNotified(Boolean ioOneMonthNotified) {
isIoOneMonthNotified = ioOneMonthNotified;
}
public Boolean getIoTenDaysNotified() {
return isIoTenDaysNotified;
}
public void setIoTenDaysNotified(Boolean ioTenDaysNotified) {
isIoTenDaysNotified = ioTenDaysNotified;
}
public Boolean getIoOneDaysNotified() {
return isIoOneDaysNotified;
}
public void setIoOneDaysNotified(Boolean ioOneDaysNotified) {
isIoOneDaysNotified = ioOneDaysNotified;
}
public Boolean getIoExpireNotified() {
return isIoExpireNotified;
}
public void setIoExpireNotified(Boolean ioExpireNotified) {
isIoExpireNotified = ioExpireNotified;
}
public Boolean getTrackThirtyPercentNotified() {
return isTrackThirtyPercentNotified;
}
public void setTrackThirtyPercentNotified(Boolean trackThirtyPercentNotified) {
isTrackThirtyPercentNotified = trackThirtyPercentNotified;
}
public Boolean getTrackTwentyPercentNotified() {
return isTrackTwentyPercentNotified;
}
public void setTrackTwentyPercentNotified(Boolean trackTwentyPercentNotified) {
isTrackTwentyPercentNotified = trackTwentyPercentNotified;
}
public Boolean getTrackTenPercentNotified() {
return isTrackTenPercentNotified;
}
public void setTrackTenPercentNotified(Boolean trackTenPercentNotified) {
isTrackTenPercentNotified = trackTenPercentNotified;
}
public Boolean getTrackFivePercentNotified() {
return isTrackFivePercentNotified;
}
public void setTrackFivePercentNotified(Boolean trackFivePercentNotified) {
isTrackFivePercentNotified = trackFivePercentNotified;
}
public Boolean getTrackExhaustPercentNotified() {
return isTrackExhaustPercentNotified;
}
public void setTrackExhaustPercentNotified(Boolean trackExhaustPercentNotified) {
isTrackExhaustPercentNotified = trackExhaustPercentNotified;
}
public Boolean getIoThirtyPercentNotified() {
return isIoThirtyPercentNotified;
}
public void setIoThirtyPercentNotified(Boolean ioThirtyPercentNotified) {
isIoThirtyPercentNotified = ioThirtyPercentNotified;
}
public Boolean getIoTwentyPercentNotified() {
return isIoTwentyPercentNotified;
}
public void setIoTwentyPercentNotified(Boolean ioTwentyPercentNotified) {
isIoTwentyPercentNotified = ioTwentyPercentNotified;
}
public Boolean getIoTenPercentNotified() {
return isIoTenPercentNotified;
}
public void setIoTenPercentNotified(Boolean ioTenPercentNotified) {
isIoTenPercentNotified = ioTenPercentNotified;
}
public Boolean getIoFivePercentNotified() {
return isIoFivePercentNotified;
}
public void setIoFivePercentNotified(Boolean ioFivePercentNotified) {
isIoFivePercentNotified = ioFivePercentNotified;
}
public Boolean getIoExhaustPercentNotified() {
return isIoExhaustPercentNotified;
}
public void setIoExhaustPercentNotified(Boolean ioExhaustPercentNotified) {
isIoExhaustPercentNotified = ioExhaustPercentNotified;
}
public Boolean getTrackTwoMonthNotified() {
return isTrackTwoMonthNotified;
}
public void setTrackTwoMonthNotified(Boolean trackTwoMonthNotified) {
isTrackTwoMonthNotified = trackTwoMonthNotified;
}
public Boolean getIoTwoMonthNotified() {
return isIoTwoMonthNotified;
}
public void setIoTwoMonthNotified(Boolean ioTwoMonthNotified) {
isIoTwoMonthNotified = ioTwoMonthNotified;
}
public Long getPreviousPackageLevel() {
return previousPackageLevel;
}
public void setPreviousPackageLevel(Long previousPackageLevel) {
this.previousPackageLevel = previousPackageLevel;
}
public String getFirstDayOfThisMonth() {
return firstDayOfThisMonth;
}
public void setFirstDayOfThisMonth(String firstDayOfThisMonth) {
this.firstDayOfThisMonth = firstDayOfThisMonth;
}
public Boolean getThisMonthUpgradeLevel() {
return thisMonthUpgradeLevel;
}
public void setThisMonthUpgradeLevel(Boolean thisMonthUpgradeLevel) {
this.thisMonthUpgradeLevel = thisMonthUpgradeLevel;
}
}
...@@ -17,6 +17,7 @@ public class PackageType { ...@@ -17,6 +17,7 @@ public class PackageType {
private BigInteger trackFlow; private BigInteger trackFlow;
private BigInteger ioFlow; private BigInteger ioFlow;
private Integer appNum; private Integer appNum;
private Boolean superLevel;
/** /**
* 价格 * 价格
...@@ -375,4 +376,12 @@ public class PackageType { ...@@ -375,4 +376,12 @@ public class PackageType {
public void setPlatformCustomDataAnalysis(Boolean platformCustomDataAnalysis) { public void setPlatformCustomDataAnalysis(Boolean platformCustomDataAnalysis) {
this.platformCustomDataAnalysis = platformCustomDataAnalysis; this.platformCustomDataAnalysis = platformCustomDataAnalysis;
} }
public Boolean getSuperLevel() {
return superLevel;
}
public void setSuperLevel(Boolean superLevel) {
this.superLevel = superLevel;
}
} }
...@@ -72,6 +72,8 @@ public interface AccountRepository extends JpaRepository<Account, Long> { ...@@ -72,6 +72,8 @@ public interface AccountRepository extends JpaRepository<Account, Long> {
@Query(value = "select root_parent from account where id=?1", nativeQuery = true) @Query(value = "select root_parent from account where id=?1", nativeQuery = true)
BigInteger findRootParentByAccountId(Long accountId); BigInteger findRootParentByAccountId(Long accountId);
@Query(value = "select * from account where status=1 and flow_restrict is TRUE and is_super_user is TRUE;", nativeQuery = true)
List<Account> findSuperAccount();
@Transactional @Transactional
@Modifying @Modifying
......
package com.reyun.repository;
import com.reyun.model.AccountRestrict4Web;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
/**
* Created by song on 2018/2/12.
*/
@Transactional
public interface AccountRestrict4WebRepository extends JpaRepository<AccountRestrict4Web, Long> {
@Query(value = "select * from account_restrict4web where account_id=?1", nativeQuery = true)
AccountRestrict4Web findByAccountId(Long account);
}
package com.reyun.repository;
import com.reyun.model.IsNotified;
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;
@Transactional
public interface IsNotifiedRepository extends JpaRepository<IsNotified, Long> {
@Query(value = "select * from is_notified where account_id=?1", nativeQuery = true)
IsNotified findIsNotifiedByAccountId(Long accountId);
@Modifying
@Transactional
@Query(value = "delete from is_notified where account_id=?1", nativeQuery = true)
int deleteByAccountId(Long accountId);
}
package com.reyun.service;
import com.reyun.model.AccountRestrict4Web;
import java.math.BigInteger;
/**
* Created by song on 2017/10/19.
*/
public interface AccountFlowRestrictService {
AccountRestrict4Web findRestrictByAccount(Long accountId);
BigInteger getTotalNum(String createTime, String pastDate, String appids, String reportName, String sumType);
Boolean isTrackAndIoBothExhaust(Long accountId);
Boolean isTrackExhaust(Long accountId);
AccountRestrict4Web RestrictFlowByAccountTask(Long accountId);
}
package com.reyun.service.impl;
import com.reyun.model.*;
import com.reyun.repository.*;
import com.reyun.service.AccountFlowRestrictService;
import com.reyun.task.EmailThread;
import com.reyun.util.Constant;
import com.reyun.util.DateUtil;
import com.reyun.util.HttpClientUtil;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.*;
/**
* Created by song on 2017/10/19.
*/
@Service
public class AccountFlowRestrictServiceImpl implements AccountFlowRestrictService {
@Autowired
private AppRepository appRepository;
@Autowired
private AccountRepository accountRepository;
@Autowired
private PackageTypeRepository packageTypeRepository;
@Autowired
private IsNotifiedRepository isNotifiedRepository;
@Autowired
private SalesManLeaderRepository salesManLeaderRepository;
@Autowired
private AccountRestrict4WebRepository accountRestrict4WebRepository;
public static final String SUPER_USER_EMAIL_NOTIFY_SUBJECT = "客户包年套餐到期提醒";
public static final String SUPER_USER_TRACK_EMAIL_NOTIFY_CONTENT = "%s购买的“%s”中广告效果监测服务%s,请尽快跟进。";
public static final String SUPER_USER_IO_EMAIL_NOTIFY_CONTENT = "%s购买的“%s”中用户行为分析服务%s,请尽快跟进。";
public static final String ALREADY_EXPIRE = "已经到期";
@Override
public AccountRestrict4Web findRestrictByAccount(Long accountId) {
Long rootParent = accountRepository.findRootParentByAccountId(accountId).longValue();
AccountRestrict4Web accountRestrict4Web = new AccountRestrict4Web();
Account one = accountRepository.findOne(accountId);
Long roleCategory = one.getRoleCategory();
List<App> apps = appRepository.listAppByRootAccount(rootParent);
Account rootAccount = accountRepository.findOne(rootParent);
String companyOrEmail = rootAccount.getCompany() != null ? rootAccount.getCompany() : rootAccount.getEmail();
IsNotified isNotifiedObject = isNotifiedRepository.findIsNotifiedByAccountId(rootParent);
boolean isTrackProduct = true;
boolean isIOProduct = rootAccount.getAllowBehavior();
StringBuffer appsStr = new StringBuffer();
for (App app : apps) {
appsStr = appsStr.append("\'" + app.getAppkey() + "\'" + ",");
}
String appids = "";
if (apps.size() != 0) {
appids = appsStr.substring(0, appsStr.length() - 1);
}
PackageType packageType = packageTypeRepository.findPackageTypeByRootParent(rootParent);
Boolean flowRestrict = rootAccount.getFlowRestrict();
String pastDate = rootAccount.getPastDate();
String trackBeginTime;
Date rootCreateTime = rootAccount.getPubDate();
String createTime = DateUtil.format(rootCreateTime, "yyyy-MM-dd");
trackBeginTime = (rootAccount.getNewContract() != null && rootAccount.getNewContract()) ? rootAccount.getModifyPricelevelTime() : createTime;
Date currentDate = DateUtil.getCurrentDate();
String currentDateStr = DateUtil.getCurrentDateStr();
int remainingDays = DateUtil.daysBetween(currentDate, DateUtil.parseDate(pastDate)) + 1;
String salesManLeaderEmail = salesManLeaderRepository.findLeaderByBussinessMan(rootAccount.getBussinessman());
ArrayList<String> emailList = new ArrayList<>();
emailList.add(salesManLeaderEmail);
Date lastMonth = getLastMonth(1);
String firstDayOfLastMonth = DateUtil.getFirstDayOfMonth(lastMonth);
String lastDayOfLastMonth = DateUtil.getLastDayOfMonth(lastMonth);
String firstDayOfThisMonth = DateUtil.getFirstDayOfMonth(new Date());
BigInteger clickNum =new BigInteger("0");
BigInteger lastThreeDaysClickNum1=new BigInteger("0");
if(apps.size()>0) {
clickNum = getTotalNum(trackBeginTime, pastDate, appids, "account_track_flow_restrict", "click_sum");
lastThreeDaysClickNum1 = getTotalNum(trackBeginTime, currentDateStr, appids, "account_track_three_days_flow_restrict", "click_sum");
}
BigInteger lastThreeDaysClickNum = lastThreeDaysClickNum1.compareTo(new BigInteger("0")) != 0 ? lastThreeDaysClickNum1 : new BigInteger("1");
int trackRemainDays = (int) Math.floor((packageType.getTrackFlow().doubleValue() - clickNum.doubleValue()) / ((lastThreeDaysClickNum.doubleValue() / 3)));
double trackRemainPercent = 1.0 - clickNum.doubleValue() / packageType.getTrackFlow().doubleValue();
DecimalFormat decimalFormat = new DecimalFormat("0%");
String trackRemainPercent1 = decimalFormat.format(trackRemainPercent);
String IOBeginTime = (isNotifiedObject != null && isNotifiedObject.getThisMonthUpgradeLevel() != null && isNotifiedObject.getThisMonthUpgradeLevel()) ? rootAccount.getModifyPricelevelTime() : firstDayOfThisMonth;
BigInteger lastMonthEventNum=new BigInteger("0");
BigInteger thisMonthEventNum=new BigInteger("0");
BigInteger lastThreeDaysEventNum=new BigInteger("0");
if(apps.size()>0){
lastMonthEventNum = getTotalNum(firstDayOfLastMonth, lastDayOfLastMonth, appids, "account_io_flow_restrict", "event_sum");
thisMonthEventNum = getTotalNum(IOBeginTime, currentDateStr, appids, "account_io_flow_restrict", "event_sum");
lastThreeDaysEventNum = getTotalNum(IOBeginTime, currentDateStr, appids, "account_io_three_days_flow_restrict", "event_sum");
}
BigInteger lastMonthExceedNum = (lastMonthEventNum.subtract(packageType.getIoFlow()).compareTo(new BigInteger("0")) == 1) ? lastMonthEventNum.subtract(packageType.getIoFlow()) : new BigInteger("0");
if (isNotifiedObject != null && isNotifiedObject.getThisMonthUpgradeLevel() != null && isNotifiedObject.getThisMonthUpgradeLevel()) {
lastMonthExceedNum = new BigInteger("0");
}
double v = packageType.getIoFlow().doubleValue() * 1 - lastMonthExceedNum.doubleValue();
DecimalFormat decimalFormat1 = new DecimalFormat("0");
String format = decimalFormat1.format(v);
BigInteger thisMonthAvailableTotalFlow = new BigInteger(format);
BigInteger thisMonthRemainingFlow = thisMonthAvailableTotalFlow.subtract(thisMonthEventNum);
int IORemainDays = -1;
if (lastThreeDaysEventNum.compareTo(new BigInteger("1")) == 1) {
IORemainDays = (int) (Math.floor(Double.valueOf(thisMonthRemainingFlow.divide(lastThreeDaysEventNum.divide(new BigInteger("3"))).toString())));
}
double ioRemainPercent = thisMonthRemainingFlow.doubleValue() / thisMonthAvailableTotalFlow.doubleValue();
String ioRemainPercent1 = decimalFormat.format(ioRemainPercent);
accountRestrict4Web.setPastDate(pastDate);
accountRestrict4Web.setPackageName(packageType.getPackageName());
accountRestrict4Web.setOriginalName(packageType.getOriginalName());
accountRestrict4Web.setIOLimit(packageType.getIoFlow());
accountRestrict4Web.setTrackLimit(packageType.getTrackFlow());
accountRestrict4Web.setThisMonthIOFlow(thisMonthEventNum);
accountRestrict4Web.setTrackTotalFlow(clickNum);
accountRestrict4Web.setAccountId(rootParent);
accountRestrict4Web.setPriceLevel(rootAccount.getPricelevel().intValue());
accountRestrict4Web.setLastMonthIOFlow(lastMonthEventNum);
accountRestrict4Web.setIORemainPercent(ioRemainPercent);
accountRestrict4Web.setTrackRemainPercent(trackRemainPercent);
accountRestrict4Web.setiOremainingDays(IORemainDays);
accountRestrict4Web.setTrackRemainingDays(trackRemainDays);
accountRestrict4Web.setPackLevel(new Long(packageType.getId()));
accountRestrict4Web.setFlowRestrict(flowRestrict);
accountRestrict4Web.setAllowBehavior(isIOProduct);
accountRestrict4Web.setSuperLevel(packageType.getSuperLevel());
if (packageType.getSuperLevel()) {
accountRestrict4Web.setPackageName("包年套餐");
}
if (rootParent.equals(accountId) && rootAccount.getFlowRestrict()) {
/**
* 判断用户有没有变更过套餐
*/
if (isNotifiedObject != null && isNotifiedObject.getPreviousPackageLevel() != packageType.getId()) {
isNotifiedRepository.deleteByAccountId(rootAccount.getId());
IsNotified isNotified1 = new IsNotified();
isNotified1.setAccountId(rootParent);
isNotified1.setPreviousPackageLevel(packageType.getId());
isNotified1.setThisMonthUpgradeLevel(true);
isNotifiedRepository.save(isNotified1);
isNotifiedObject = isNotifiedRepository.findIsNotifiedByAccountId(rootParent);
}
if (isNotifiedObject == null) {
IsNotified isNotified1 = new IsNotified();
isNotified1.setAccountId(rootParent);
isNotified1.setPreviousPackageLevel(packageType.getId());
isNotified1.setFirstDayOfThisMonth(firstDayOfThisMonth);
isNotifiedRepository.save(isNotified1);
isNotifiedObject = isNotifiedRepository.findIsNotifiedByAccountId(rootParent);
} else if (isNotifiedObject != null && !packageType.getSuperLevel() && (DateUtil.compareDate(isNotifiedObject.getFirstDayOfThisMonth(), firstDayOfThisMonth) != 0)) {
isNotifiedObject.setIoThirtyPercentNotified(false);
isNotifiedObject.setIoTwentyPercentNotified(false);
isNotifiedObject.setIoTenPercentNotified(false);
isNotifiedObject.setIoFivePercentNotified(false);
isNotifiedObject.setIoExhaustPercentNotified(false);
isNotifiedObject.setThisMonthUpgradeLevel(false);
isNotifiedRepository.save(isNotifiedObject);
isNotifiedObject = isNotifiedRepository.findIsNotifiedByAccountId(rootParent);
}
if (isNotifiedObject != null && (DateUtil.compareDate(isNotifiedObject.getFirstDayOfThisMonth(), firstDayOfThisMonth) != 0)) {
isNotifiedObject.setThisMonthUpgradeLevel(false);
isNotifiedRepository.save(isNotifiedObject);
isNotifiedObject = isNotifiedRepository.findIsNotifiedByAccountId(rootParent);
}
if (flowRestrict) {
if (isTrackProduct) {
/**
* 是广告检测产品
*/
if (remainingDays > 1 && remainingDays <= 10 && (isNotifiedObject.getTrackTenDaysNotified() == null || !isNotifiedObject.getTrackTenDaysNotified())) {
isNotifiedObject.setTrackTenDaysNotified(true);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setTrackPastTimeNotified(true);
String contents = String.format(SUPER_USER_TRACK_EMAIL_NOTIFY_CONTENT,
companyOrEmail, packageType.getPackageName(), "还有" + remainingDays + "天即将到期");
try {
Thread emailThread = new EmailThread(SUPER_USER_EMAIL_NOTIFY_SUBJECT, contents, emailList);
emailThread.start();
} catch (Exception e) {
isNotifiedObject.setTrackTenDaysNotified(false);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setTrackPastTimeNotified(false);
e.printStackTrace();
}
} else if (remainingDays > 10 && remainingDays <= 30 && (isNotifiedObject.getTrackOneMonthNotified() == null || !isNotifiedObject.getTrackOneMonthNotified())) {
isNotifiedObject.setTrackOneMonthNotified(true);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setTrackPastTimeNotified(true);
String contents = String.format(SUPER_USER_TRACK_EMAIL_NOTIFY_CONTENT, companyOrEmail, packageType.getPackageName(), "还有" + remainingDays + "天即将到期");
try {
Thread emailThread = new EmailThread(SUPER_USER_EMAIL_NOTIFY_SUBJECT, contents, emailList);
emailThread.start();
} catch (Exception e) {
isNotifiedObject.setTrackOneMonthNotified(false);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setTrackPastTimeNotified(false);
e.printStackTrace();
}
} else if (remainingDays <= 0 && (isNotifiedObject.getTrackExpireNotified() == null || !isNotifiedObject.getTrackExpireNotified())) {
isNotifiedObject.setTrackExpireNotified(true);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setTrackPastTimeNotified(true);
String contents = String.format(SUPER_USER_TRACK_EMAIL_NOTIFY_CONTENT, companyOrEmail, packageType.getPackageName(), ALREADY_EXPIRE);
try {
Thread emailThread = new EmailThread(SUPER_USER_EMAIL_NOTIFY_SUBJECT, contents, emailList);
emailThread.start();
} catch (Exception e) {
isNotifiedObject.setTrackExpireNotified(false);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setTrackPastTimeNotified(false);
e.printStackTrace();
}
} else if (remainingDays == 1 && (isNotifiedObject.getTrackOneDaysNotified() == null || !isNotifiedObject.getTrackOneDaysNotified())) {
isNotifiedObject.setTrackOneDaysNotified(true);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setTrackPastTimeNotified(true);
String contents = String.format(SUPER_USER_TRACK_EMAIL_NOTIFY_CONTENT, companyOrEmail, packageType.getPackageName(), "还有1天到期");
try {
Thread emailThread = new EmailThread(SUPER_USER_EMAIL_NOTIFY_SUBJECT, contents, emailList);
emailThread.start();
} catch (Exception e) {
isNotifiedObject.setTrackOneDaysNotified(false);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setTrackPastTimeNotified(false);
e.printStackTrace();
}
} else if (remainingDays > 30 && remainingDays <= 60 && (isNotifiedObject.getTrackTwoMonthNotified() == null || !isNotifiedObject.getTrackTwoMonthNotified())) {
isNotifiedObject.setTrackTwoMonthNotified(true);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setTrackPastTimeNotified(true);
String contents = String.format(SUPER_USER_TRACK_EMAIL_NOTIFY_CONTENT, companyOrEmail, packageType.getPackageName(), "还有" + remainingDays + "天即将到期");
try {
Thread emailThread = new EmailThread(SUPER_USER_EMAIL_NOTIFY_SUBJECT, contents, emailList);
emailThread.start();
} catch (Exception e) {
isNotifiedObject.setTrackTwoMonthNotified(false);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setTrackPastTimeNotified(false);
e.printStackTrace();
}
}
}
if (isIOProduct) {
/**
* 是行为分析产品
*/
if (remainingDays > 1 && remainingDays <= 10 && (isNotifiedObject.getIoTenDaysNotified() == null || !isNotifiedObject.getIoTenDaysNotified())) {
isNotifiedObject.setIoTenDaysNotified(true);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setIOPastTimeNotified(true);
String contents = String.format(SUPER_USER_IO_EMAIL_NOTIFY_CONTENT,
companyOrEmail, packageType.getPackageName(), "还有" + remainingDays + "天即将到期");
try {
Thread emailThread = new EmailThread(SUPER_USER_EMAIL_NOTIFY_SUBJECT, contents, emailList);
emailThread.start();
} catch (Exception e) {
isNotifiedObject.setIoTenDaysNotified(false);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setIOPastTimeNotified(false);
e.printStackTrace();
}
} else if (remainingDays > 10 && remainingDays <= 30 && (isNotifiedObject.getIoOneMonthNotified() == null || !isNotifiedObject.getIoOneMonthNotified())) {
isNotifiedObject.setIoOneMonthNotified(true);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setIOPastTimeNotified(true);
String contents = String.format(SUPER_USER_IO_EMAIL_NOTIFY_CONTENT, companyOrEmail, packageType.getPackageName(), "还有" + remainingDays + "天即将到期");
try {
Thread emailThread = new EmailThread(SUPER_USER_EMAIL_NOTIFY_SUBJECT, contents, emailList);
emailThread.start();
} catch (Exception e) {
isNotifiedObject.setIoOneMonthNotified(false);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setIOPastTimeNotified(false);
e.printStackTrace();
}
} else if (remainingDays <= 0 && (isNotifiedObject.getIoExpireNotified() == null || !isNotifiedObject.getIoExpireNotified())) {
isNotifiedObject.setIoExpireNotified(true);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setIOPastTimeNotified(true);
String contents = String.format(SUPER_USER_IO_EMAIL_NOTIFY_CONTENT, companyOrEmail, packageType.getPackageName(), ALREADY_EXPIRE);
try {
Thread emailThread = new EmailThread(SUPER_USER_EMAIL_NOTIFY_SUBJECT, contents, emailList);
emailThread.start();
} catch (Exception e) {
isNotifiedObject.setIoExpireNotified(false);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setIOPastTimeNotified(false);
e.printStackTrace();
}
} else if (remainingDays == 1 && (isNotifiedObject.getIoOneDaysNotified() == null || !isNotifiedObject.getIoOneDaysNotified())) {
isNotifiedObject.setIoOneDaysNotified(true);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setIOPastTimeNotified(true);
String contents = String.format(SUPER_USER_IO_EMAIL_NOTIFY_CONTENT, companyOrEmail, packageType.getPackageName(), "还有1天到期");
try {
Thread emailThread = new EmailThread(SUPER_USER_EMAIL_NOTIFY_SUBJECT, contents, emailList);
emailThread.start();
} catch (Exception e) {
isNotifiedObject.setIoOneDaysNotified(false);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setIOPastTimeNotified(false);
e.printStackTrace();
}
} else if (remainingDays > 30 && remainingDays <= 60 && (isNotifiedObject.getIoTwoMonthNotified() == null || !isNotifiedObject.getIoTwoMonthNotified())) {
isNotifiedObject.setIoTwoMonthNotified(true);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setIOPastTimeNotified(true);
String contents = String.format(SUPER_USER_IO_EMAIL_NOTIFY_CONTENT, companyOrEmail, packageType.getPackageName(), "还有" + remainingDays + "天即将到期");
try {
Thread emailThread = new EmailThread(SUPER_USER_EMAIL_NOTIFY_SUBJECT, contents, emailList);
emailThread.start();
} catch (Exception e) {
isNotifiedObject.setIoTwoMonthNotified(false);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setIOPastTimeNotified(false);
e.printStackTrace();
}
}
}
}
if (!packageType.getSuperLevel() && flowRestrict) {
/**
* 不是超级用户,是包流量的用户
*/
if (isTrackProduct) {
boolean thirtyToTwenty = (packageType.getTrackFlow().doubleValue() * 0.7 <= clickNum.doubleValue()) && (packageType.getTrackFlow().doubleValue() * 0.8 > clickNum.doubleValue());
boolean twentyToTen = (packageType.getTrackFlow().doubleValue() * 0.8 <= clickNum.doubleValue()) && (packageType.getTrackFlow().doubleValue() * 0.9 > clickNum.doubleValue());
boolean tenPercent = (packageType.getTrackFlow().doubleValue() * 0.9 <= clickNum.doubleValue()) && (packageType.getTrackFlow().doubleValue() * 0.95 > clickNum.doubleValue());
boolean fivePercent = (packageType.getTrackFlow().doubleValue() * 0.95 <= clickNum.doubleValue()) && (packageType.getTrackFlow().doubleValue() * 1 > clickNum.doubleValue());
boolean exPercent = packageType.getTrackFlow().doubleValue() <= clickNum.doubleValue();
if (thirtyToTwenty && (isNotifiedObject.getTrackThirtyPercentNotified() == null || !isNotifiedObject.getTrackThirtyPercentNotified())) {
isNotifiedObject.setTrackThirtyPercentNotified(true);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setTrackRemainingDays(trackRemainDays);
accountRestrict4Web.setTrackFlowNotified(true);
String contents = companyOrEmail + "购买的" + packageType.getPackageName() + "中广告效果监控剩余流量不足" + trackRemainPercent1 + ",请尽快跟进。";
try {
Thread emailThread = new EmailThread("广告效果监控产品流量提醒", contents, emailList);
emailThread.start();
} catch (Exception e) {
isNotifiedObject.setTrackThirtyPercentNotified(false);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setTrackRemainingDays(trackRemainDays);
accountRestrict4Web.setTrackFlowNotified(false);
e.printStackTrace();
}
} else if (twentyToTen && (isNotifiedObject.getTrackTwentyPercentNotified() == null || !isNotifiedObject.getTrackTwentyPercentNotified())) {
isNotifiedObject.setTrackTwentyPercentNotified(true);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setTrackRemainingDays(trackRemainDays);
accountRestrict4Web.setTrackFlowNotified(true);
String contents = companyOrEmail + "购买的" + packageType.getPackageName() + "中广告效果监控剩余流量不足" + trackRemainPercent1 + ",请尽快跟进。";
try {
Thread emailThread = new EmailThread("广告效果监控产品流量提醒", contents, emailList);
emailThread.start();
} catch (Exception e) {
isNotifiedObject.setTrackTwentyPercentNotified(false);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setTrackRemainingDays(trackRemainDays);
accountRestrict4Web.setTrackFlowNotified(false);
e.printStackTrace();
}
} else if (tenPercent && (isNotifiedObject.getTrackTenPercentNotified() == null || !isNotifiedObject.getTrackTenPercentNotified())) {
isNotifiedObject.setTrackTenPercentNotified(true);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setTrackRemainingDays(trackRemainDays);
accountRestrict4Web.setTrackFlowNotified(true);
String contents = companyOrEmail + "购买的" + packageType.getPackageName() + "中广告效果监控剩余流量不足" + trackRemainPercent1 + ",请尽快跟进。";
try {
Thread emailThread = new EmailThread("广告效果监控产品流量提醒", contents, emailList);
emailThread.start();
} catch (Exception e) {
isNotifiedObject.setTrackTenPercentNotified(false);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setTrackRemainingDays(trackRemainDays);
accountRestrict4Web.setTrackFlowNotified(false);
e.printStackTrace();
}
} else if (fivePercent && (isNotifiedObject.getTrackFivePercentNotified() == null || !isNotifiedObject.getTrackFivePercentNotified())) {
isNotifiedObject.setTrackFivePercentNotified(true);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setTrackRemainingDays(trackRemainDays);
accountRestrict4Web.setTrackFlowNotified(true);
String contents = companyOrEmail + "购买的" + packageType.getPackageName() + "中广告效果监控剩余流量不足" + trackRemainPercent1 + ",请尽快跟进。";
try {
Thread emailThread = new EmailThread("广告效果监控产品流量提醒", contents, emailList);
emailThread.start();
} catch (Exception e) {
isNotifiedObject.setTrackFivePercentNotified(false);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setTrackRemainingDays(trackRemainDays);
accountRestrict4Web.setTrackFlowNotified(false);
e.printStackTrace();
}
} else if (exPercent && (isNotifiedObject.getTrackExhaustPercentNotified() == null || !isNotifiedObject.getTrackExhaustPercentNotified())) {
isNotifiedObject.setTrackExhaustPercentNotified(true);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setTrackRemainingDays(trackRemainDays);
accountRestrict4Web.setTrackFlowNotified(true);
String contents = companyOrEmail + "购买的" + packageType.getPackageName() + "中广告效果监控流量已用尽,请尽快跟进。";
try {
Thread emailThread = new EmailThread("广告效果监控产品流量提醒", contents, emailList);
emailThread.start();
} catch (Exception e) {
isNotifiedObject.setTrackExhaustPercentNotified(false);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setTrackRemainingDays(trackRemainDays);
accountRestrict4Web.setTrackFlowNotified(false);
e.printStackTrace();
}
}
}
if (isIOProduct) {
boolean thirtyToTwenty = (thisMonthAvailableTotalFlow.doubleValue() * 0.7 <= thisMonthEventNum.doubleValue()) && (thisMonthAvailableTotalFlow.doubleValue() * 0.8 > thisMonthEventNum.doubleValue());
boolean twentyToTen = (thisMonthAvailableTotalFlow.doubleValue() * 0.8 <= thisMonthEventNum.doubleValue()) && (thisMonthAvailableTotalFlow.doubleValue() * 0.9 > thisMonthEventNum.doubleValue());
boolean tenPercent = (thisMonthAvailableTotalFlow.doubleValue() * 0.9 <= thisMonthEventNum.doubleValue()) && (thisMonthAvailableTotalFlow.doubleValue() * 0.95 > thisMonthEventNum.doubleValue());
boolean fivePercent = (thisMonthAvailableTotalFlow.doubleValue() * 0.95 <= thisMonthEventNum.doubleValue()) && (thisMonthAvailableTotalFlow.doubleValue() * 1 > thisMonthEventNum.doubleValue());
boolean exPercent = thisMonthAvailableTotalFlow.doubleValue() * 1 <= thisMonthEventNum.doubleValue();
if (thirtyToTwenty && (isNotifiedObject.getIoThirtyPercentNotified() == null || !isNotifiedObject.getIoThirtyPercentNotified())) {
isNotifiedObject.setIoThirtyPercentNotified(true);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setIOFlowNotified(true);
String contents = companyOrEmail + "购买的" + packageType.getPackageName() + "用户行为分析当月剩余流量不足" + ioRemainPercent1 + ",请尽快跟进。";
try {
Thread emailThread = new EmailThread("用户行为分析产品流量提醒", contents, emailList);
emailThread.start();
} catch (Exception e) {
isNotifiedObject.setIoThirtyPercentNotified(false);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setIOFlowNotified(false);
e.printStackTrace();
}
} else if (twentyToTen && (isNotifiedObject.getIoTwentyPercentNotified() == null || !isNotifiedObject.getIoTwentyPercentNotified())) {
isNotifiedObject.setIoTwentyPercentNotified(true);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setIOFlowNotified(true);
String contents = companyOrEmail + "购买的" + packageType.getPackageName() + "用户行为分析当月剩余流量不足" + ioRemainPercent1 + ",请尽快跟进。";
try {
Thread emailThread = new EmailThread("用户行为分析产品流量提醒", contents, emailList);
emailThread.start();
} catch (Exception e) {
isNotifiedObject.setIoTwentyPercentNotified(false);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setIOFlowNotified(false);
e.printStackTrace();
}
} else if (tenPercent && (isNotifiedObject.getIoTenPercentNotified() == null || !isNotifiedObject.getIoTenPercentNotified())) {
isNotifiedObject.setIoTenPercentNotified(true);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setIOFlowNotified(true);
String contents = companyOrEmail + "购买的" + packageType.getPackageName() + "用户行为分析当月剩余流量不足" + ioRemainPercent1 + ",请尽快跟进。";
try {
Thread emailThread = new EmailThread("用户行为分析产品流量提醒", contents, emailList);
emailThread.start();
} catch (Exception e) {
isNotifiedObject.setIoTenPercentNotified(false);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setIOFlowNotified(false);
e.printStackTrace();
}
} else if (fivePercent && (isNotifiedObject.getIoFivePercentNotified() == null || !isNotifiedObject.getIoFivePercentNotified())) {
isNotifiedObject.setIoFivePercentNotified(true);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setIOFlowNotified(true);
String contents = companyOrEmail + "购买的" + packageType.getPackageName() + "用户行为分析当月剩余流量不足" + ioRemainPercent1 + ",请尽快跟进。";
try {
Thread emailThread = new EmailThread("用户行为分析产品流量提醒", contents, emailList);
emailThread.start();
} catch (Exception e) {
isNotifiedObject.setIoFivePercentNotified(false);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setIOFlowNotified(false);
e.printStackTrace();
}
} else if (exPercent && (isNotifiedObject.getIoExhaustPercentNotified() == null || !isNotifiedObject.getIoExhaustPercentNotified())) {
isNotifiedObject.setIoExhaustPercentNotified(true);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setIOFlowNotified(true);
String contents = companyOrEmail + "购买的" + packageType.getPackageName() + "中用户行为分析当月流量已用尽,请尽快跟进。";
try {
Thread emailThread = new EmailThread("用户行为分析产品流量提醒", contents, emailList);
emailThread.start();
} catch (Exception e) {
isNotifiedObject.setIoExhaustPercentNotified(false);
isNotifiedRepository.save(isNotifiedObject);
accountRestrict4Web.setIOFlowNotified(false);
e.printStackTrace();
}
}
}
}
isNotifiedObject.setFirstDayOfThisMonth(firstDayOfThisMonth);
isNotifiedRepository.save(isNotifiedObject);
}
return accountRestrict4Web;
}
/**
* 查询广告效果监控产品的点击量和行为分析产品的点击量的方法
*/
@Override
public BigInteger getTotalNum(String createTime, String pastDate, String appids, String reportName, String
sumType) {
Long appId = 1218L;
Map<String, String> conditions = new HashMap<String, String>();
conditions.put("appids", appids);
conditions.put("startdate", createTime);
conditions.put("enddate", pastDate);
conditions.put("datatype", "list");
conditions.put("iscache", Constant.iscache);
String url = Constant.reportUrl + "/api/trackingio/" + reportName + "/" + appId;
String responseJson = HttpClientUtil.doHttpPostRequest(url, "trackingio", conditions);
HashMap<String, String> resultValMap = new HashMap<>();
String click_sum = "";
String s = "0";
if(responseJson!=null) {
try {
JSONObject jsonObject = new JSONObject(responseJson);
Iterator keys = jsonObject.keys();
while (keys.hasNext()) {
String key = (String) keys.next();
String value = jsonObject.getString(key);
resultValMap.put(key, value);
}
String val = resultValMap.get("val");
JSONArray jsonArray = new JSONArray(val);
JSONObject jsonObject1 = jsonArray.getJSONObject(0);
click_sum = jsonObject1.getString(sumType);
if (StringUtils.isEmpty(click_sum) || "0".equals(click_sum)) {
click_sum = "0";
}
Double aDouble = Double.valueOf(click_sum);
BigDecimal bigDecimal = new BigDecimal(aDouble);
s = bigDecimal.toPlainString();
} catch (JSONException e) {
e.printStackTrace();
}
}
return new BigInteger(s);
}
@Override
public Boolean isTrackAndIoBothExhaust(Long accountId) {
Long rootParent = accountRepository.findRootParentByAccountId(accountId).longValue();
List<App> apps = appRepository.listAppByRootAccount(rootParent);
Boolean isBothExhaust = false;
if (apps.size() != 0) {
Account rootAccount = accountRepository.findOne(rootParent);
StringBuffer appsStr = new StringBuffer();
for (App app : apps) {
appsStr = appsStr.append("\'" + app.getAppkey() + "\'" + ",");
}
String appids = appsStr.substring(0, appsStr.length() - 1);
/**
* 1.根据母帐号获取用户等级
*/
PackageType packageType = packageTypeRepository.findPackageTypeByRootParent(rootParent);
Boolean flowRestrict = rootAccount.getFlowRestrict();
String pastDate = rootAccount.getPastDate();
String trackBeginTime;
Date rootCreateTime = rootAccount.getCreateTime();
String createTime = DateUtil.format(rootCreateTime, "yyyy-MM-dd");
trackBeginTime = (rootAccount.getNewContract() != null && rootAccount.getNewContract()) ? rootAccount.getModifyPricelevelTime() : createTime;
String currentDateStr = DateUtil.getCurrentDateStr();
Date lastMonth = getLastMonth(1);
String firstDayOfLastMonth = DateUtil.getFirstDayOfMonth(lastMonth);
String lastDayOfLastMonth = DateUtil.getLastDayOfMonth(lastMonth);
String firstDayOfThisMonth = DateUtil.getFirstDayOfMonth(new Date());
BigInteger clickNum = getTotalNum(trackBeginTime, pastDate, appids, "account_track_flow_restrict", "click_sum");
IsNotified isNotifiedObject = isNotifiedRepository.findIsNotifiedByAccountId(rootParent);
String IOBeginTime = (isNotifiedObject != null && isNotifiedObject.getThisMonthUpgradeLevel() != null && isNotifiedObject.getThisMonthUpgradeLevel()) ? rootAccount.getModifyPricelevelTime() : firstDayOfThisMonth;
BigInteger lastMonthEventNum = getTotalNum(firstDayOfLastMonth, lastDayOfLastMonth, appids, "account_io_flow_restrict", "event_sum");
BigInteger thisMonthEventNum = getTotalNum(IOBeginTime, currentDateStr, appids, "account_io_flow_restrict", "event_sum");
BigInteger lastMonthExceedNum = (lastMonthEventNum.subtract(packageType.getIoFlow()).compareTo(new BigInteger("0")) == 1) ? lastMonthEventNum.subtract(packageType.getIoFlow()) : new BigInteger("0");
if (isNotifiedObject != null && isNotifiedObject.getThisMonthUpgradeLevel() != null && isNotifiedObject.getThisMonthUpgradeLevel()) {
lastMonthExceedNum = new BigInteger("0");
}
double v = packageType.getIoFlow().doubleValue() * 1 - lastMonthExceedNum.doubleValue();
DecimalFormat decimalFormat1 = new DecimalFormat("0");
String format = decimalFormat1.format(v);
BigInteger thisMonthAvailableTotalFlow = new BigInteger(format);
BigInteger thisMonthRemainingFlow = thisMonthAvailableTotalFlow.subtract(thisMonthEventNum);
if (!packageType.getSuperLevel() && flowRestrict) {
if (rootAccount.getAllowBehavior()) {
isBothExhaust = (packageType.getTrackFlow().doubleValue() - clickNum.doubleValue() < 0) && thisMonthRemainingFlow.doubleValue() < 0;
} else {
isBothExhaust = (packageType.getTrackFlow().doubleValue() - clickNum.doubleValue() < 0);
}
}
}
return isBothExhaust;
}
@Override
public Boolean isTrackExhaust(Long accountId) {
Long rootParent = accountRepository.findRootParentByAccountId(accountId).longValue();
List<App> apps = appRepository.listAppByRootAccount(rootParent);
Boolean isBothExhaust = false;
if (apps.size() != 0) {
Account rootAccount = accountRepository.findOne(rootParent);
StringBuffer appsStr = new StringBuffer();
for (App app : apps) {
appsStr = appsStr.append("\'" + app.getAppkey() + "\'" + ",");
}
String appids = appsStr.substring(0, appsStr.length() - 1);
/**
* 1.根据母帐号获取用户等级
*/
PackageType packageType = packageTypeRepository.findPackageTypeByRootParent(rootParent);
Boolean flowRestrict = rootAccount.getFlowRestrict();
String pastDate = rootAccount.getPastDate();
String trackBeginTime;
Date rootCreateTime = rootAccount.getCreateTime();
String createTime = DateUtil.format(rootCreateTime, "yyyy-MM-dd");
trackBeginTime = (rootAccount.getNewContract() != null && rootAccount.getNewContract()) ? rootAccount.getModifyPricelevelTime() : createTime;
BigInteger clickNum = getTotalNum(trackBeginTime, pastDate, appids, "account_track_flow_restrict", "click_sum");
if (!packageType.getSuperLevel() && flowRestrict) {
isBothExhaust = (packageType.getTrackFlow().doubleValue() - clickNum.doubleValue() < 0);
}
}
return isBothExhaust;
}
@Override
public AccountRestrict4Web RestrictFlowByAccountTask(Long accountId) {
AccountRestrict4Web flowRestrict = findRestrictByAccount(accountId);
AccountRestrict4Web byAccountId = accountRestrict4WebRepository.findByAccountId(flowRestrict.getAccountId());
if(byAccountId!=null){
Boolean ioFlowNotified = byAccountId.getIOFlowNotified()!=null?byAccountId.getIOFlowNotified():false;
Boolean ioPastTimeNotified = byAccountId.getIOPastTimeNotified()!=null?byAccountId.getIOPastTimeNotified():false;
Boolean trackFlowNotified = byAccountId.getTrackFlowNotified()!=null?byAccountId.getTrackFlowNotified():false;
Boolean trackPastTimeNotified = byAccountId.getTrackPastTimeNotified()!=null?byAccountId.getTrackPastTimeNotified():false;
accountRestrict4WebRepository.delete(byAccountId.getId());
if(flowRestrict.getTrackPastTimeNotified()==null || !flowRestrict.getTrackPastTimeNotified()){
flowRestrict.setTrackPastTimeNotified(trackPastTimeNotified);
}
if(flowRestrict.getIOPastTimeNotified()==null || !flowRestrict.getIOPastTimeNotified()){
flowRestrict.setIOPastTimeNotified(ioPastTimeNotified);
}
if(flowRestrict.getTrackFlowNotified()==null || !flowRestrict.getTrackFlowNotified()){
flowRestrict.setTrackFlowNotified(trackFlowNotified);
}
if(flowRestrict.getIOFlowNotified()==null || !flowRestrict.getIOFlowNotified()){
flowRestrict.setIOFlowNotified(ioFlowNotified);
}
accountRestrict4WebRepository.save(flowRestrict);
}else{
accountRestrict4WebRepository.save(flowRestrict);
}
return flowRestrict;
}
public Date getLastMonth(int i) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.add(Calendar.MONTH, -i);
Date time = calendar.getTime();
calendar.setTime(new Date());
return time;
}
}
package com.reyun.task;
import com.reyun.model.Account;
import com.reyun.repository.AccountRepository;
import com.reyun.service.AccountFlowRestrictService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* Created by song on 2018/2/12.
*/
@Service
public class AutoCalculateFlow {
private static Logger logger = LoggerFactory.getLogger(AutoCalculateFlow.class);
@Autowired
AccountFlowRestrictService accountFlowRestrictService;
@Autowired
AccountRepository accountRepository;
public void run(){
try{
List<Account> superAccount = accountRepository.findSuperAccount();
for(Account account:superAccount){
//System.out.println("**********************************************\n\n");
accountFlowRestrictService.RestrictFlowByAccountTask(account.getId());
//System.out.println("**********************************************\n\n");
}
}catch(Exception e){
e.printStackTrace();
logger.info(e.getMessage());
}
}
}
...@@ -32,6 +32,16 @@ public class Constant { ...@@ -32,6 +32,16 @@ public class Constant {
public static String eventTable = commonBundle.getString("event.table"); public static String eventTable = commonBundle.getString("event.table");
public static String usergroupTable = commonBundle.getString("usergroup.table"); public static String usergroupTable = commonBundle.getString("usergroup.table");
public static String accountCheckUrl = commonBundle.getString("account.check.url"); public static String accountCheckUrl = commonBundle.getString("account.check.url");
public static String reportUrl = commonBundle.getString("report.url");
public static String adminUrl = commonBundle.getString("admin.url");
public static String iscache = commonBundle.getString("iscache");
public static String receiverHost = commonBundle.getString("receiver.host");
public static String receiverPort = commonBundle.getString("receiver.port");
public static String reportExportTask = commonBundle.getString("report.export.task");
public static String appDebugTask = commonBundle.getString("app.debug.task");
public static String tkioUrl = commonBundle.getString("tkio.url");
public static String awsAccessKey = commonBundle.getString("aws.accesskey");
public static String awsSecretKey = commonBundle.getString("aws.secret");
......
package com.reyun.util;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class HttpClientUtil {
/**
* 日志处理类
*/
private static final Log log = LogFactory.getLog(HttpClientUtil.class);
// 读取超时
private final static int SOCKET_TIMEOUT = 60000;
// 连接超时
private final static int CONNECTION_TIMEOUT = 60000;
// 每个HOST的最大连接数量
private final static int MAX_CONN_PRE_HOST = 20;
// 连接池的最大连接数
private final static int MAX_CONN = 100;
// 连接池
private final static HttpConnectionManager httpConnectionManager;
static {
httpConnectionManager = new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams params = httpConnectionManager.getParams();
params.setConnectionTimeout(CONNECTION_TIMEOUT);
params.setSoTimeout(SOCKET_TIMEOUT);
params.setDefaultMaxConnectionsPerHost(MAX_CONN_PRE_HOST);
params.setMaxTotalConnections(MAX_CONN);
}
/**
* Http get请求,获取结果.
* @param url
* @param ip
* @return
*/
public static String doHttpGetRequest(String url, String ip) {
HttpClient httpClient = new HttpClient(httpConnectionManager);
resetRequestHeader(httpClient, ip);
HttpMethod method = new GetMethod(url);
String response = null;
try {
httpClient.executeMethod(method);
if (method.getStatusCode() == HttpStatus.SC_OK) {
response = method.getResponseBodyAsString();
}
} catch (IOException e) {
log.error("执行HTTP Get请求" + url + "时,发生异常!", e);
} finally {
method.releaseConnection();
}
return response;
}
public static String doHttpGetRequest4Mobile(String url, String ip) {
HttpClient httpClient = new HttpClient(httpConnectionManager);
resetRequestHeader4Mobile(httpClient, ip);
HttpMethod method = new GetMethod(url);
String response = null;
try {
httpClient.executeMethod(method);
if (method.getStatusCode() == HttpStatus.SC_OK) {
response = method.getResponseBodyAsString();
}
} catch (IOException e) {
log.error("执行HTTP Get请求" + url + "时,发生异常!", e);
} finally {
method.releaseConnection();
}
return response;
}
/**
* Http post请求,获取结果.
* @param url
* @param ip
* @return
*/
public static String doHttpPostRequest(String url, String ip, Map<String, String> params) {
long start = System.currentTimeMillis();
HttpClient httpClient = new HttpClient(httpConnectionManager);
httpClient.getHttpConnectionManager().getParams()
.setConnectionTimeout(300000);
httpClient.getHttpConnectionManager().getParams().setSoTimeout(300000);
resetRequestHeader(httpClient, ip);
PostMethod method = new PostMethod(url);
List<NameValuePair> list = new ArrayList<NameValuePair>();
for (String key : params.keySet()) {
NameValuePair pair = new NameValuePair(key, params.get(key));
list.add(pair);
}
method.setRequestBody(list.toArray(new NameValuePair[list.size()]));
String response = null;
try {
int status = httpClient.executeMethod(method);
response = method.getResponseBodyAsString();
} catch (IOException e) {
log.error("执行HTTP Post请求" + url + "时,发生异常!", e);
} finally {
method.releaseConnection();
}
long end = System.currentTimeMillis();
log.debug("---------------http's time to get data from report-------------------");
log.debug(start-end + "ms");
log.debug("---------------------------------------------------------------------");
return response;
}
/**
* Http post请求,获取结果.
* @param url
* @param ip
* @return
*/
public static String doHttpPostRequest(String url, String ip) {
long start = System.currentTimeMillis();
HttpClient httpClient = new HttpClient(httpConnectionManager);
httpClient.getHttpConnectionManager().getParams()
.setConnectionTimeout(300000);
httpClient.getHttpConnectionManager().getParams().setSoTimeout(300000);
resetRequestHeader(httpClient, ip);
PostMethod method = new PostMethod(url);
List<NameValuePair> list = new ArrayList<NameValuePair>();
String response = null;
try {
int status = httpClient.executeMethod(method);
response = method.getResponseBodyAsString();
} catch (IOException e) {
log.error("执行HTTP Post请求" + url + "时,发生异常!", e);
} finally {
method.releaseConnection();
}
long end = System.currentTimeMillis();
log.debug("---------------http's time to get data from report-------------------");
log.debug(start-end + "ms");
log.debug("---------------------------------------------------------------------");
return response;
}
/**
* 设置一下返回错误的通用提示,可以自定义格式.
* @param reason
* @return
*/
public static String returnError(String reason) {
StringBuffer buffer = new StringBuffer();
buffer.append("<?xml version=\"1.0\" encoding=\"GBK\"?>");
buffer.append("<Response>");
buffer.append("<Success>false</Success>");
buffer.append("<reason>");
buffer.append(reason);
buffer.append("</reason>");
buffer.append("</Response>");
return buffer.toString();
}
public final static String REQUEST_HEADER = "x-forwarded-for";
/**
* 将客户IP写入请求头
* 这个设置可以伪装IP请求,注意使用
* @param client
* @param ip
* @return
*/
public static void resetRequestHeader(HttpClient client, String ip) {
List<Header> headers = new ArrayList<Header>();
headers.add(new Header(REQUEST_HEADER, ip));
client.getHostConfiguration().getParams().setParameter(
"http.default-headers", headers);
client.getHostConfiguration().getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,"utf-8");
}
public static void resetRequestHeader4Mobile(HttpClient client, String ip) {
List<Header> headers = new ArrayList<Header>();
headers.add(new Header(REQUEST_HEADER, ip));
client.getHostConfiguration().getParams().setParameter(
"http.default-headers", headers);
client.getHostConfiguration().getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,"GBK");
}
// public static boolean httpAWS(Map<String, String> args, String ip, String surl, String url) throws Exception {
// String response = "";
// for (int i=0; i<3; i++) {
// response = HttpClientUtil.doHttpPostRequest(url, ip, args);
// if (!StringUtil.isEmpty(response)) {
// ObjectMapper objectMapper = new ObjectMapper();
// Map res = objectMapper.readValue(response, Map.class);
// if (res.containsKey("result") && res.get("result").equals("true")) {
// log.info("success to "+args.get("method")+" AWS redis campaigninfo by surl:" + surl);
// return true;
// }
// }
// }
//
// if (StringUtil.isEmpty(response)) {
// MailUtils.sendSimpleEmail("Fail to "+args.get("method")+" AWS redis campaigninfo by surl:" + surl, new ObjectMapper().writeValueAsString(args), Constant.mlist);
// return false;
// }
// return false;
// }
public static void resetRequestHeader(HttpClient client, String ip, String cookie) {
List<Header> headers = new ArrayList<Header>();
headers.add(new Header(REQUEST_HEADER, ip));
headers.add(new Header("Cookie", cookie));
client.getHostConfiguration().getParams().setParameter(
"http.default-headers", headers);
// client.getHostConfiguration().getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,"utf-8");
}
public static ByteArrayOutputStream doHttpGetStreamRequest(String url, String ip, String cookie)
{
HttpClient httpClient = new HttpClient(httpConnectionManager);
resetRequestHeader(httpClient, ip, cookie);
HttpMethod method = new GetMethod(url);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream response = null;
try {
httpClient.executeMethod(method);
if (method.getStatusCode() == HttpStatus.SC_OK) {
response = method.getResponseBodyAsStream();
byte[] buffer = new byte[1024];
int len;
while ((len = response.read(buffer)) > -1 ) {
baos.write(buffer, 0, len);
}
baos.flush();
}
} catch (IOException e) {
log.error("执行HTTP Get请求" + url + "时,发生异常!", e);
} finally {
method.releaseConnection();
}
return baos;
}
public static Map<String,Object> doHttpGetHeaderAndBody(String url, String ip, String cookie)
{
HttpClient httpClient = new HttpClient(httpConnectionManager);
resetRequestHeader(httpClient, ip, cookie);
HttpMethod method = new GetMethod(url);
ByteArrayOutputStream baosHeader = new ByteArrayOutputStream();
ByteArrayOutputStream baosBody = new ByteArrayOutputStream();
InputStream responseBody = null;
InputStream responseHeader = null;
Map<String,Object> result = new HashMap<>();
try {
httpClient.executeMethod(method);
if (method.getStatusCode() == HttpStatus.SC_OK) {
responseBody = method.getResponseBodyAsStream();
byte[] buffer = new byte[1024];
int len;
while ((len = responseBody.read(buffer)) > -1 ) {
baosBody.write(buffer, 0, len);
}
baosBody.flush();
result.put("body",baosBody);
Header headers = method.getResponseHeader("Set-Cookie");
String value = headers.getValue();
result.put("cookie", value);
}
} catch (IOException e) {
log.error("执行HTTP Get请求" + url + "时,发生异常!", e);
} finally {
method.releaseConnection();
}
return result;
}
public static String doHttpPostRequest(String url, String ip, Map<String, String> params, String cookie) {
long start = System.currentTimeMillis();
HttpClient httpClient = new HttpClient(httpConnectionManager);
httpClient.getHttpConnectionManager().getParams()
.setConnectionTimeout(300000);
httpClient.getHttpConnectionManager().getParams().setSoTimeout(300000);
resetRequestHeader(httpClient, ip, cookie);
PostMethod method = new PostMethod(url);
List<NameValuePair> list = new ArrayList<NameValuePair>();
for (String key : params.keySet()) {
NameValuePair pair = new NameValuePair(key, params.get(key));
list.add(pair);
}
method.setRequestBody(list.toArray(new NameValuePair[list.size()]));
String response = null;
try {
int status = httpClient.executeMethod(method);
response = method.getResponseBodyAsString();
} catch (IOException e) {
log.error("执行HTTP Post请求" + url + "时,发生异常!", e);
} finally {
method.releaseConnection();
}
long end = System.currentTimeMillis();
log.debug("---------------http's time to get data from report-------------------");
log.debug(start-end + "ms");
log.debug("---------------------------------------------------------------------");
return response;
}
}
...@@ -9,4 +9,9 @@ ...@@ -9,4 +9,9 @@
<description>调度配置</description> <description>调度配置</description>
<bean id="autoCalculateFlow" class="com.reyun.task.AutoCalculateFlow"></bean>
<task:scheduled-tasks>
<task:scheduled ref="autoCalculateFlow" method="run" cron="0 */10 * * * ?"/>
</task:scheduled-tasks>
</beans> </beans>
...@@ -2,3 +2,15 @@ profile.table=${profile.table} ...@@ -2,3 +2,15 @@ profile.table=${profile.table}
event.table=${event.table} event.table=${event.table}
usergroup.table=${usergroup.table} usergroup.table=${usergroup.table}
account.check.url=${account.check.url} account.check.url=${account.check.url}
receiver.host=${receiver.host}
receiver.port=${receiver.port}
report.url=${report.url}
awsneed=${awsneed}
iscache=${iscache}
admin.url=${admin.url}
report.export.task=${report.export.task}
app.debug.task=${app.debug.task}
tkio.url=${tkio.url}
aws.accesskey=${aws.accesskey}
aws.secret=${aws.secret}
\ No newline at end of file
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