package com.gk.firework.Scheduls.AssessTask;
|
|
import com.gk.firework.Domain.AccessAssessApply;
|
import com.gk.firework.Domain.AssessApply;
|
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 java.util.Calendar;
|
import java.util.Date;
|
import java.util.List;
|
/**
|
* @Description: 0点执行从处罚中恢复
|
* @date 2021/7/12 15:42
|
*/
|
@Component
|
@EnableScheduling
|
public class RecoverFromPunishmentTask {
|
|
@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 RecoverFromPunishment() {
|
|
if (switchBtn) {
|
Date currentTime = new Date();
|
|
//1.获取销售评定处罚中的单子
|
List<AssessApply> allPunishingSaleList = assessApplyService.selectAllPunishingSaleAssessApply();
|
if (allPunishingSaleList.size() > 0) {
|
for (AssessApply assessApply : allPunishingSaleList) {
|
//企业信息检查
|
Enterprise enterprise = enterpriseService.selectEnterpriseByNumber(assessApply.getEnterprisenumber());
|
if (enterprise == null) throw new BusinessException("单位编号:" + assessApply.getEnterprisenumber() + ",企业信息为空");
|
//用户检查 处罚中的企业状态都为1
|
List<UserInfo> userInfos = userService.selectByCompanyId(enterprise.getId(), (byte) 1);
|
if (userInfos.size() != 2) throw new BusinessException("数据异常:用户对象个数不匹配");
|
|
switch (assessApply.getPunishmentmeasure()) {
|
case M0:
|
throw new BusinessException("数据异常,处罚中没有吊销");
|
case M1:
|
this.recoverUserAndEndPunishment(userInfos,1,currentTime,assessApply);
|
break;
|
case M2:
|
this.recoverUserAndEndPunishment(userInfos,3,currentTime,assessApply);
|
break;
|
case M3:
|
this.recoverUserAndEndPunishment(userInfos,6,currentTime,assessApply);
|
break;
|
}
|
}
|
}
|
|
|
//2.获取准入评定处罚中的单子
|
List<AccessAssessApply> allPunishingAccessList = accessAssessApplyService.selectAllPunishingAccessAssessApply();
|
if (allPunishingAccessList.size() > 0) {
|
for (AccessAssessApply accessAssessApply : allPunishingAccessList) {
|
//企业信息检查
|
Enterprise enterprise = enterpriseService.selectEnterpriseByNumber(accessAssessApply.getEnterprisenumber());
|
if (enterprise == null) throw new BusinessException("单位编号:" + accessAssessApply.getEnterprisenumber() + ",企业信息为空");
|
//用户检查 处罚中的企业状态都为1
|
List<UserInfo> userInfos = userService.selectByCompanyId(enterprise.getId(), (byte) 1);
|
if (userInfos.size() != 2) throw new BusinessException("数据异常:用户对象个数不匹配");
|
|
switch (accessAssessApply.getPunishmentmeasure()) {
|
case M0:
|
throw new BusinessException("数据异常,处罚中没有吊销");
|
case M1:
|
this.recoverUserAndEndPunishment(userInfos, 1, currentTime, accessAssessApply);
|
break;
|
case M2:
|
this.recoverUserAndEndPunishment(userInfos, 3, currentTime, accessAssessApply);
|
break;
|
case M3:
|
this.recoverUserAndEndPunishment(userInfos, 6, currentTime, accessAssessApply);
|
break;
|
}
|
}
|
}
|
}
|
|
}
|
|
|
//停用企业
|
private void activateEnterprise(Enterprise enterprise,List<UserInfo> userInfos) {
|
//停用企业
|
enterpriseService.setEnterpriseStatus(EnterpriseStatus.ON, enterprise.getId());
|
//停用用户
|
for (UserInfo user : userInfos) {
|
userService.recoverOneById(user.getId());
|
}
|
}
|
|
|
//评定恢复
|
private void recoverUserAndEndPunishment(List<UserInfo> userInfos,int num,Date currentTime,AccessAssessApply accessAssessApply) {
|
|
if (addMonth(accessAssessApply.getDeadline(), num).after(currentTime)) {
|
//用户恢复
|
for (UserInfo user : userInfos) {
|
userService.recoverOneById(user.getId());
|
}
|
//单子处罚结束
|
accessAssessApply.setPunishstatus(PunishStatus.END);
|
accessAssessApplyService.updateById(accessAssessApply);
|
}
|
}
|
|
//销售恢复
|
private void recoverUserAndEndPunishment(List<UserInfo> userInfos,int num,Date currentTime,AssessApply assessApply) {
|
|
if (addMonth(assessApply.getApprovetime(), num).after(currentTime)) {
|
//用户恢复
|
for (UserInfo user : userInfos) {
|
userService.recoverOneById(user.getId());
|
}
|
//单子处罚结束
|
assessApply.setPunishstatus(PunishStatus.END);
|
assessApplyService.updateById(assessApply);
|
}
|
}
|
|
|
//往后推n个月
|
private Date addMonth(Date date,int n) {
|
Calendar calendar = Calendar.getInstance();
|
calendar.setTime(date);
|
calendar.add(Calendar.MONTH, n);
|
return calendar.getTime();
|
}
|
|
}
|