AccountTask.java 8.79 KB
Newer Older
manxiaoqiang committed
1 2 3 4
package tkio.task;

import common.model.Account4Web;
import common.repository.Account4WebRepository;
manxiaoqiang committed
5 6
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
manxiaoqiang committed
7 8 9 10
import org.springframework.beans.factory.annotation.Autowired;
import tkio.model.Account;
import tkio.model.AccountRestrict4Web;
import tkio.model.PackageType;
manxiaoqiang committed
11
import tkio.model.SalesManLeader;
manxiaoqiang committed
12 13
import tkio.repository.AccountRepository;
import tkio.repository.PackageTypeRepository;
manxiaoqiang committed
14
import tkio.repository.SalesManLeaderRepository;
manxiaoqiang committed
15 16 17 18
import tkio.service.AccountFlowRestrictService;
import util.DateUtil;
import util.ValidateUtil;

manxiaoqiang committed
19
import java.math.BigInteger;
manxiaoqiang committed
20 21 22 23 24 25 26 27 28
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by mxq on 2017/12/25.
 */
public class AccountTask {
manxiaoqiang committed
29
    private static Logger logger = LoggerFactory.getLogger(AccountTask.class);
manxiaoqiang committed
30 31 32 33 34 35 36 37 38 39 40 41 42

    @Autowired
    AccountRepository accountRepository;

    @Autowired
    Account4WebRepository account4WebRepository;

    @Autowired
    AccountFlowRestrictService accountFlowRestrictService;

    @Autowired
    private PackageTypeRepository packageTypeRepository;

manxiaoqiang committed
43 44 45
    @Autowired
    SalesManLeaderRepository salesManLeaderRepository;

manxiaoqiang committed
46
    public void task(){
manxiaoqiang committed
47
        logger.info("tkio task start :" + System.currentTimeMillis());
manxiaoqiang committed
48 49 50 51 52
        List<SalesManLeader> SalesManLeader = salesManLeaderRepository.findAll();
        Map<Long, String> saleMap = new HashMap<>();
        for(SalesManLeader pt : SalesManLeader){
            saleMap.put((long)pt.getId(), pt.getEmail());
        }
manxiaoqiang committed
53 54 55 56 57
        List<PackageType> packageTypeList = packageTypeRepository.findAll();
        Map<Long, String> map = new HashMap<>();
        for(PackageType pt : packageTypeList){
            map.put(pt.getId(), pt.getPackageName());
        }
manxiaoqiang committed
58 59
        //清空前一天数据
        account4WebRepository.deleteAll();
manxiaoqiang committed
60 61 62 63 64
        List<Account4Web> list = new ArrayList<>();
        //未过期的查询是否流量到期
        List<Account> accountValidList = accountRepository.findRootParentsUnPast(DateUtil.getBeforeDays(1));
        if(ValidateUtil.isValid(accountValidList)){
            for(Account ac : accountValidList){
manxiaoqiang committed
65 66
                Account4Web account4Web = new Account4Web();
                account4Web.setAccountId(ac.getId());
2  
manxiaoqiang committed
67
                account4Web.setPackageTypeId(ac.getPricelevel());
manxiaoqiang committed
68 69 70 71 72 73 74 75
                account4Web.setEmail(ac.getEmail());
                account4Web.setCompany(ac.getCompany());
                account4Web.setCreateDate(ac.getPubDate());
                account4Web.setCreateDs(DateUtil.getFormatDate(ac.getPubDate()));
                account4Web.setPastDate(ac.getPastDate());
                account4Web.setUser(ac.getName());
                account4Web.setTell(ac.getPhone());
                account4Web.setBussinessMan(ac.getBussinessman());
manxiaoqiang committed
76 77 78
                if(saleMap.containsKey(ac.getBussinessman())){
                    account4Web.setSaleEamil(saleMap.get(ac.getBussinessman()));
                }
manxiaoqiang committed
79 80
                try{
                    AccountRestrict4Web restrict4Web = accountFlowRestrictService.findRestrictByAccount(ac.getId());
2  
manxiaoqiang committed
81
                    account4Web.setStatus(null == restrict4Web.getTrackFlowNotified() ? "已激活" : (restrict4Web.getTrackFlowNotified() ? "已激活" : "流量用尽"));
manxiaoqiang committed
82 83 84 85 86 87 88 89 90
                    account4Web.setPackageType(restrict4Web.getPackageName());
                    if (ac.getPricelevel().equals(7L) || ac.getPricelevel().equals(8L) || ac.getPricelevel().equals(5L) || ac.getPricelevel().equals(6L)){
                        account4Web.setIo(restrict4Web.getThisMonthIOFlow());
                        account4Web.setTrack(restrict4Web.getTrackTotalFlow());
                    }else{
                        account4Web.setIo(restrict4Web.getThisMonthIOFlow());
                        account4Web.setTrack(restrict4Web.getTrackTotalFlow());
                        account4Web.setIoLimit(restrict4Web.getIOLimit());
                        account4Web.setTrackLimit(restrict4Web.getTrackLimit());
2  
manxiaoqiang committed
91
                        account4Web.setIoStatus(true);
manxiaoqiang committed
92
                        account4Web.setTrackStatus(restrict4Web.getTrackFlowNotified());
manxiaoqiang committed
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
//                        double f = 1.0;
//                        if((account4Web.getIo().doubleValue() != 0) && (null != account4Web.getIoLimit())){
//                            if(account4Web.getIo().doubleValue() > account4Web.getIoLimit().doubleValue()){
//                                account4Web.setIoStatus(false);
//                                account4Web.setStatus("流量用尽");
//                            }else{
//                                account4Web.setIoStatus(true);
//                            }
//                        }else {
//                            account4Web.setIoStatus(true);
//                        }
//                        if(account4Web.getIoLimit().doubleValue() == -1){
//                            account4Web.setIoStatus(true);
//                            account4Web.setStatus("已激活");
//
//                        }
2  
manxiaoqiang committed
109
                        if(account4Web.getTrackLimit().doubleValue() <= 0){
manxiaoqiang committed
110 111
                            account4Web.setTrackStatus(true);
                            account4Web.setStatus("已激活");
manxiaoqiang committed
112
                        }
2  
manxiaoqiang committed
113 114 115 116 117 118 119
//                              else {
//                            if(account4Web.getTrack().doubleValue() < account4Web.getTrackLimit().doubleValue()){
//                                account4Web.setStatus("已激活");
//                            } else{
//                                account4Web.setStatus("流量用尽");
//                            }
//                        }
2  
manxiaoqiang committed
120
                        account4Web.setIoStatus(true);
2  
manxiaoqiang committed
121

manxiaoqiang committed
122
                    }
manxiaoqiang committed
123 124
                    list.add(account4Web);
                } catch (Exception e){
manxiaoqiang committed
125 126 127 128 129 130 131
                    account4Web.setPackageType(map.get(ac.getPricelevel()));
                    account4Web.setIoStatus(true);
                    account4Web.setTrackStatus(true);
                    account4Web.setStatus("已激活");
                    account4Web.setIo(new BigInteger("0"));
                    account4Web.setTrack(new BigInteger("0"));
                    list.add(account4Web);
manxiaoqiang committed
132
                    logger.error("tkio task error :" + ac.getEmail());
manxiaoqiang committed
133
                }
manxiaoqiang committed
134

manxiaoqiang committed
135 136 137 138
            }
        }
        //已过期的直接设置成过期
        List<Account> pastAccountList = accountRepository.findRootParentsPast(DateUtil.getBeforeDays(0));
manxiaoqiang committed
139

manxiaoqiang committed
140 141 142
        if(ValidateUtil.isValid(pastAccountList)){
            for(Account ac : pastAccountList){
                Account4Web account4Web = new Account4Web();
2  
manxiaoqiang committed
143
                account4Web.setPackageTypeId(ac.getPricelevel());
144
                account4Web.setAccountId(ac.getId());
manxiaoqiang committed
145 146
                account4Web.setEmail(ac.getEmail());
                account4Web.setCompany(ac.getCompany());
147
                account4Web.setCreateDate(ac.getPubDate());
manxiaoqiang committed
148 149 150 151 152
                account4Web.setStatus("已过期");
                account4Web.setPackageType(map.get(ac.getPricelevel()));
                account4Web.setPastDate(ac.getPastDate());
                account4Web.setIoStatus(false);
                account4Web.setTrackStatus(false);
153 154
                account4Web.setUser(ac.getName());
                account4Web.setTell(ac.getPhone());
manxiaoqiang committed
155
                account4Web.setBussinessMan(ac.getBussinessman());
manxiaoqiang committed
156 157 158 159 160 161 162 163 164 165 166 167
                if(saleMap.containsKey(ac.getBussinessman())){
                    account4Web.setSaleEamil(saleMap.get(ac.getBussinessman()));
                }
                list.add(account4Web);
            }
        }

        //禁用账号
        List<Account> accountList = accountRepository.findRootParentsForbiden();
        if(ValidateUtil.isValid(accountList)){
            for(Account ac : accountList){
                Account4Web account4Web = new Account4Web();
2  
manxiaoqiang committed
168
                account4Web.setPackageTypeId(ac.getPricelevel());
manxiaoqiang committed
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
                account4Web.setAccountId(ac.getId());
                account4Web.setEmail(ac.getEmail());
                account4Web.setCompany(ac.getCompany());
                account4Web.setCreateDate(ac.getPubDate());
                account4Web.setStatus("已禁用");
                account4Web.setPackageType(map.get(ac.getPricelevel()));
                account4Web.setPastDate(ac.getPastDate());
                account4Web.setIoStatus(false);
                account4Web.setTrackStatus(false);
                account4Web.setUser(ac.getName());
                account4Web.setTell(ac.getPhone());
                account4Web.setBussinessMan(ac.getBussinessman());
                if(saleMap.containsKey(ac.getBussinessman())){
                    account4Web.setSaleEamil(saleMap.get(ac.getBussinessman()));
                }
manxiaoqiang committed
184 185 186 187
                list.add(account4Web);
            }
        }
        account4WebRepository.save(list);
manxiaoqiang committed
188
        logger.info("tkio task end :" + System.currentTimeMillis());
manxiaoqiang committed
189 190
    }
}