Administrator
2023-06-19 49588f5a462ae7425e7eb030438a35fd80c246fa
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
package com.gk.firework.Scheduls.AssessTask;
 
import com.gk.firework.Domain.AccessAssessApply;
import com.gk.firework.Domain.Enterprise;
import com.gk.firework.Domain.Enum.AssessPunishment;
import com.gk.firework.Domain.Enum.EnterpriseStatus;
import com.gk.firework.Domain.Enum.PunishStatus;
import com.gk.firework.Domain.Exception.BusinessException;
import com.gk.firework.Domain.UserInfo;
import com.gk.firework.Service.AccessAssessApplyService;
import com.gk.firework.Service.AssessApplyService;
import com.gk.firework.Service.EnterpriseService;
import com.gk.firework.Service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
* @Description: 0点执行处罚
* @date 2021/7/12 9:51
*/
@Component
@EnableScheduling
public class EnforcePunishmentTask {
 
 
    @Value("${com.gk.firework.schedules.all.switch}")
    private Boolean switchBtn;
    //销售评定
    @Autowired
    private AssessApplyService assessApplyService;
    //准入评定
    @Autowired
    private AccessAssessApplyService accessAssessApplyService;
    @Autowired
    private EnterpriseService enterpriseService;
    @Autowired
    private UserService userService;
 
    @Scheduled(cron = "0 0 0 * * ?")
    public void EnforcePunishment() {
        if (switchBtn) {
            Date currentTime = new Date();
 
            //1.销售评定审批结束已经处罚
 
            //2.准入评定 公示14天处罚,获取截止日期大于等于当日的准入评定进行相对应的处罚
            List<AccessAssessApply> allOverTimeData = accessAssessApplyService.selectAllOverTimeAccessAssessApply();
            if (allOverTimeData.size() > 0) {
                for (AccessAssessApply accessAssessApply : allOverTimeData) {
                    //企业信息检查
                    Enterprise enterprise = enterpriseService.selectEnterpriseByNumber(accessAssessApply.getEnterprisenumber());
                    if (enterprise == null)  throw new BusinessException("单位编号:" + accessAssessApply.getEnterprisenumber() + ",企业信息为空");
                    //用户检查
                    List<UserInfo> userInfos = userService.selectByCompanyId(enterprise.getId(), (byte) 0);
                    if (userInfos.size() != 2) throw new BusinessException("数据异常:用户对象个数不匹配");
                    //除了吊销,都是过期
                    if (accessAssessApply.getPunishmentmeasure() == AssessPunishment.M0) {
                        this.deactivateEnterprise(enterprise, userInfos);
                        accessAssessApply.setPunishstatus(PunishStatus.PUNISHING);
                        accessAssessApplyService.updateById(accessAssessApply);
                    }
 
                    if (accessAssessApply.getPunishmentmeasure() != AssessPunishment.M0)
                        this.deactivateUser(userInfos);
                        accessAssessApply.setPunishstatus(PunishStatus.PUNISHING);
                        accessAssessApplyService.updateById(accessAssessApply);
 
                }
            }
        }
    }
 
    //停用企业
    private void deactivateEnterprise(Enterprise enterprise,List<UserInfo> userInfos) {
        //停用企业
        enterpriseService.setEnterpriseStatus(EnterpriseStatus.OFF, enterprise.getId());
        //停用用户
        for (UserInfo user : userInfos) {
            userService.deleteById(user.getId());
        }
    }
 
 
    //用户过期
    private void deactivateUser(List<UserInfo> userInfos) {
        for (UserInfo user : userInfos) {
            userService.deleteById(user.getId());
        }
    }
 
 
 
 
}