package com.zy.asrs.task; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.mapper.Wrapper; import com.zy.asrs.entity.InOut; import com.zy.asrs.entity.LocDetl; import com.zy.asrs.entity.Mat; import com.zy.asrs.service.InOutService; import com.zy.asrs.service.LocDetlService; import com.zy.asrs.service.MatService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import java.util.List; @Component @Slf4j @Transactional public class InOutSyncScheduler { @Autowired private LocDetlService locDetlService; @Autowired private InOutService inOutService; @Autowired private MatService matService; @Scheduled(cron = "0/30 * * * * ? ") private void syncInOut(){ // List locDetlList = locDetlService.selectList(new EntityWrapper().ne("length",1).last("top 100")); List locDetlList = locDetlService.select100(); if (locDetlList.size() == 0){ log.info("商品信息更新完毕"); return; } for (LocDetl locDetl : locDetlList) { InOut inOut = inOutService.selectByMatnr(locDetl.getMatnr()); Mat mat = matService.selectByMatnr(locDetl.getMatnr()); inOut.setBrand(locDetl.getZpallet());//托盘条码 inOut.setTemp3(locDetl.getLocNo());//库位号 inOut.setTemp1("在库");//是否在库 inOut.setTemp2(mat.getName());//套号 locDetl.setLength(1.0);//标记 if (!inOutService.update(inOut, new EntityWrapper().eq("matnr",inOut.getMatnr()))){ log.error("更新商品信息失败"); } if (!locDetlService.update(locDetl,new EntityWrapper().eq("matnr",locDetl.getMatnr()))){ log.error("更新库存标记失败"); } } log.info("更新" + locDetlList.size() + "条商品信息成功"); } }