Pu Zhibing
84 分钟以前 b293f932d31971dfff8769f61ad39de50fd28c43
1
2
3
4
5
6
7
8
9
10
11
12
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package com.supersavedriving.user.modular.system.util;
 
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.supersavedriving.user.modular.system.model.*;
import com.supersavedriving.user.modular.system.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.List;
import java.util.Objects;
 
 
/**
 * 定时任务工具类
 */
@Component
public class TaskUtil {
 
    @Autowired
    private IUserToCouponService userToCouponService;
    @Resource
    private ICompanyFundFlowService companyFundFlowService;
 
    @Autowired
    private IBranchOfficeService branchOfficeService;
    @Autowired
    private IDriverService driverService;
    @Autowired
    private ISystemConfigService systemConfigService;
    @Autowired
    private IAccountChangeDetailService accountChangeDetailService;
    @Autowired
    private IRevenueService revenueService;
    /**
     * 每隔一分钟去处理的定时任务
     */
    @Scheduled(fixedRate = 1000 * 60)
    public void taskMinute(){
        try {
 
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
 
    /**
     * 每天的凌晨执行的任务
     */
    @Scheduled(cron = "0 0 0 * * *")
    public void taskDay(){
        try {
            userToCouponService.delUserCoupon();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
 
 
    /**
     * 每月1日凌晨执行的任务
     */
    @Scheduled(cron = "0 0 0 1 * *")
    public void taskMonth1(){
        try {
            List<Driver> drivers = driverService.selectList(new EntityWrapper<Driver>().eq("status", 1));
            for (Driver driver : drivers) {
                SystemConfig systemConfig3= systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 3)
                        .eq("companyType",1)
                        .eq("companyId",1)
                        .eq("branchOfficeId",driver.getBranchOfficeId())
                        .last("LIMIT 1"));
                if(Objects.isNull(systemConfig3)){
                    continue;
                }
                JSONObject jsonObject3 = JSON.parseObject(systemConfig3.getContent());
                // 按单分佣
                Double nu2 = jsonObject3.getDouble("num2");
                Double nu4 = jsonObject3.getDouble("num4");
                //处理平台抽佣
                if(Objects.nonNull(nu2) && nu2 > 0 && nu4 == 1){
                    //先平台抽佣
//                        num4_ = (num3 >= num4_ ? num4_ : num3);
                    Revenue revenue = new Revenue();
                    revenue.setType(2);
                    revenue.setUserType(4);
                    revenue.setUserId(1);
//                    revenue.setOrderId(order.getId());
                    revenue.setAmount(nu2);
                    revenue.setCreateTime(new Date());
                    revenueService.insert(revenue);
                    Double balance = revenueService.queryCompanyBalance();
                    //记录企业流水
                    CompanyFundFlow companyFundFlow = new CompanyFundFlow();
                    companyFundFlow.setType(3);
                    companyFundFlow.setObjectType(1);
                    companyFundFlow.setObjectId(null);
                    companyFundFlow.setBalance(new BigDecimal(balance));
                    companyFundFlow.setMoney(new BigDecimal(nu2));
                    companyFundFlow.setCreateTime(new Date());
                    companyFundFlowService.insert(companyFundFlow);
 
                }
                SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 3)
                        .eq("companyType",2)
                        .eq("companyId",driver.getBranchOfficeId())
                        .last("LIMIT 1"));
                if(Objects.nonNull(systemConfig)){
                    JSONObject jsonObject = JSON.parseObject(systemConfig.getContent());
                    Double num2 = jsonObject.getDouble("num2");
                    Double num4 = jsonObject.getDouble("num4");
                    //分公司分佣
                    if(Objects.nonNull(num2) && num2 > 0 && num4 == 1){
                        Revenue revenue = new Revenue();
                        revenue.setType(2);
                        revenue.setUserType(5);
                        revenue.setUserId(driver.getBranchOfficeId());
//                        revenue.setOrderId(order.getId());
                        revenue.setAmount(num2);
                        revenue.setCreateTime(new Date());
                        revenueService.insert(revenue);
                        Double balance = revenueService.queryBranchOfficeBalance(driver.getAgentId());
 
                        //记录企业流水
                        CompanyFundFlow companyFundFlow = new CompanyFundFlow();
                        companyFundFlow.setType(3);
                        companyFundFlow.setObjectType(3);
                        companyFundFlow.setObjectId(driver.getBranchOfficeId());
                        companyFundFlow.setBalance(new BigDecimal(balance));
                        companyFundFlow.setMoney(new BigDecimal(num2));
                        companyFundFlow.setCreateTime(new Date());
                        companyFundFlowService.insert(companyFundFlow);
 
                        Driver driver1 = driverService.selectById(driver.getId());
 
                        if (driver1.getVipEndDate()==null||new Date().after(driver1.getVipEndDate())) {
                            AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
                            accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(5));
                            accountChangeDetail.setUserType(2);
                            accountChangeDetail.setUserId(driver.getId());
                            accountChangeDetail.setType(1);
                            accountChangeDetail.setChangeType(9);
                            accountChangeDetail.setOldData(new BigDecimal(driver.getBalance()).add(new BigDecimal(driver.getBackgroundBalance())).setScale(2, RoundingMode.HALF_EVEN).doubleValue());
                            driver.setBalance(driver.getBalance() - num2);
                            accountChangeDetail.setNewData(new BigDecimal(driver.getBalance()).add(new BigDecimal(driver.getBackgroundBalance())).setScale(2, RoundingMode.HALF_EVEN).doubleValue());
                            accountChangeDetail.setExplain("分公司抽成");
                            accountChangeDetail.setCreateTime(new Date());
                            accountChangeDetailService.insert(accountChangeDetail);
                            driverService.updateById(driver);
                        }
                    }
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
 
 
    /**
     * 每月16日凌晨执行的任务
     */
    @Scheduled(cron = "0 0 0 16 * *")
    public void taskMonth16(){
        try {
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}