AccountTask.java 4.17 KB
Newer Older
manxiaoqiang committed
1 2 3 4 5 6 7 8
package tkio.task;

import common.model.Account4Web;
import common.repository.Account4WebRepository;
import org.springframework.beans.factory.annotation.Autowired;
import tkio.model.Account;
import tkio.model.AccountRestrict4Web;
import tkio.model.PackageType;
manxiaoqiang committed
9
import tkio.model.SalesManLeader;
manxiaoqiang committed
10 11
import tkio.repository.AccountRepository;
import tkio.repository.PackageTypeRepository;
manxiaoqiang committed
12
import tkio.repository.SalesManLeaderRepository;
manxiaoqiang committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
import tkio.service.AccountFlowRestrictService;
import util.DateUtil;
import util.ValidateUtil;

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 {

    @Autowired
    AccountRepository accountRepository;

    @Autowired
    Account4WebRepository account4WebRepository;

    @Autowired
    AccountFlowRestrictService accountFlowRestrictService;

    @Autowired
    private PackageTypeRepository packageTypeRepository;

manxiaoqiang committed
39 40 41
    @Autowired
    SalesManLeaderRepository salesManLeaderRepository;

manxiaoqiang committed
42
    public void task(){
manxiaoqiang committed
43 44
        //清空前一天数据
        account4WebRepository.deleteAll();
manxiaoqiang committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
        List<Account4Web> list = new ArrayList<>();
        //未过期的查询是否流量到期
        List<Account> accountValidList = accountRepository.findRootParentsUnPast(DateUtil.getBeforeDays(1));
        if(ValidateUtil.isValid(accountValidList)){
            for(Account ac : accountValidList){
                AccountRestrict4Web restrict4Web = accountFlowRestrictService.findRestrictByAccount(ac.getId());
                Account4Web account4Web = new Account4Web();
                account4Web.setEmail(ac.getEmail());
                account4Web.setCompany(ac.getCompany());
                account4Web.setCreateDate(ac.getCreateTime());
                account4Web.setStatus(null == restrict4Web.getIOFlowNotified() ? "已激活" : (restrict4Web.getIOFlowNotified() ? "已激活" : "流量用尽"));
                account4Web.setPackageType(restrict4Web.getPackageName());
                account4Web.setPastDate(ac.getPastDate());
                if (ac.getPricelevel().equals(7L) || ac.getPricelevel().equals(8L) || ac.getPricelevel().equals(5L)){
                    account4Web.setIo(restrict4Web.getThisMonthIOFlow().toString());
                    account4Web.setTrack(restrict4Web.getTrackTotalFlow().toString());
                }else{
                    account4Web.setIo(restrict4Web.getThisMonthIOFlow() + "/" + restrict4Web.getIOLimit());
                    account4Web.setTrack(restrict4Web.getTrackTotalFlow() + "/" + restrict4Web.getTrackLimit());
                }
                account4Web.setIoStatus(restrict4Web.getAllowBehavior());
                account4Web.setTrackStatus(restrict4Web.getTrackFlowNotified());
manxiaoqiang committed
67 68
                account4Web.setUser(ac.getName());
                account4Web.setTell(ac.getPhone());
manxiaoqiang committed
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
                list.add(account4Web);
            }
        }
        //已过期的直接设置成过期
        List<Account> pastAccountList = accountRepository.findRootParentsPast(DateUtil.getBeforeDays(0));
        List<PackageType> packageTypeList = packageTypeRepository.findAll();
        Map<Long, String> map = new HashMap<>();
        for(PackageType pt : packageTypeList){
            map.put(pt.getId(), pt.getPackageName());
        }
        if(ValidateUtil.isValid(pastAccountList)){
            for(Account ac : pastAccountList){
                Account4Web account4Web = new Account4Web();
                account4Web.setEmail(ac.getEmail());
                account4Web.setCompany(ac.getCompany());
                account4Web.setCreateDate(ac.getCreateTime());
                account4Web.setStatus("已过期");
                account4Web.setPackageType(map.get(ac.getPricelevel()));
                account4Web.setPastDate(ac.getPastDate());
                account4Web.setIo("----");
                account4Web.setTrack("----");
                account4Web.setIoStatus(false);
                account4Web.setTrackStatus(false);
92 93
                account4Web.setUser(ac.getName());
                account4Web.setTell(ac.getPhone());
manxiaoqiang committed
94 95 96 97 98 99
                list.add(account4Web);
            }
        }
        account4WebRepository.save(list);
    }
}