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 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 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 userInfos) { //停用企业 enterpriseService.setEnterpriseStatus(EnterpriseStatus.OFF, enterprise.getId()); //停用用户 for (UserInfo user : userInfos) { userService.deleteById(user.getId()); } } //用户过期 private void deactivateUser(List userInfos) { for (UserInfo user : userInfos) { userService.deleteById(user.getId()); } } }