forked from sfms3.0/sfms3.0
4 changed files with 73 additions and 7 deletions
@ -0,0 +1,47 @@ |
|||||
|
package com.win.module.wms.job; |
||||
|
|
||||
|
import com.win.framework.quartz.core.handler.JobHandler; |
||||
|
import com.win.framework.quartz.core.util.CronUtils; |
||||
|
import com.win.framework.tenant.core.context.TenantContextHolder; |
||||
|
import com.win.module.wms.dal.dataobject.countPlan.CountPlanMainDO; |
||||
|
import com.win.module.wms.dal.mysql.countPlan.CountPlanMainMapper; |
||||
|
import com.win.module.wms.service.countPlan.CountPlanMainService; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
import java.time.LocalDateTime; |
||||
|
import java.util.List; |
||||
|
|
||||
|
@Component |
||||
|
public class CountPlanCycleJob implements JobHandler { |
||||
|
|
||||
|
@Resource |
||||
|
private CountPlanMainService countPlanMainService; |
||||
|
@Resource |
||||
|
private CountPlanMainMapper countPlanMainMapper; |
||||
|
|
||||
|
@Override |
||||
|
public String execute(String param) { |
||||
|
StringBuilder message = new StringBuilder(); |
||||
|
TenantContextHolder.setIgnore(true); |
||||
|
List<CountPlanMainDO> countPlanMainDOList = countPlanMainService.getCountPlanCycle(); |
||||
|
TenantContextHolder.setIgnore(false); |
||||
|
for(CountPlanMainDO countPlanMainDO : countPlanMainDOList) { |
||||
|
TenantContextHolder.setTenantId(countPlanMainDO.getTenantId()); |
||||
|
LocalDateTime now = LocalDateTime.now(); |
||||
|
if(now.isAfter(countPlanMainDO.getNextTime())) { |
||||
|
countPlanMainService.generateRequest(countPlanMainDO); |
||||
|
countPlanMainDO.setNextTime(null); |
||||
|
// 计算下一个执行时间
|
||||
|
List<LocalDateTime> nextTimes = CronUtils.getNextTimes(countPlanMainDO.getCrontab(), 1); |
||||
|
if(!nextTimes.isEmpty()) { |
||||
|
countPlanMainDO.setNextTime(nextTimes.get(0)); |
||||
|
} |
||||
|
countPlanMainMapper.updateById(countPlanMainDO); |
||||
|
message.append("盘点计划 ").append(countPlanMainDO.getNumber()).append(" 生成了盘点申请"); |
||||
|
} |
||||
|
} |
||||
|
return message.toString(); |
||||
|
} |
||||
|
|
||||
|
} |
Loading…
Reference in new issue