| | |
| | | package com.zy.common.service.erp.task; |
| | | |
| | | import com.zy.asrs.entity.AllLocDetl; |
| | | import com.zy.asrs.entity.InventoryVariance; |
| | | import com.zy.asrs.service.AllLocDetlService; |
| | | import com.zy.asrs.service.InventoryVarianceService; |
| | | import com.zy.asrs.service.MatService; |
| | | import com.zy.asrs.service.TagService; |
| | | import com.zy.asrs.task.AbstractHandler; |
| | | import com.zy.common.service.erp.ErpService; |
| | | import lombok.Synchronized; |
| | | import com.zy.common.service.erp.entity.WlzhVStRd; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * erp任务控制器 |
| | |
| | | |
| | | @Autowired |
| | | private ErpService erpService; |
| | | @Autowired |
| | | private TagService tagService; |
| | | @Autowired |
| | | private MatService matService; |
| | | @Autowired |
| | | private AllLocDetlService allLocDetlService; |
| | | @Autowired |
| | | private InventoryVarianceService inventoryVarianceService; |
| | | |
| | | @Scheduled(cron = "0/30 * * * * ? ") |
| | | @Synchronized |
| | | public void syncMat() { |
| | | |
| | | //@Scheduled(cron = "0 0 2 * * ? ") |
| | | public void syncLocDetl(){ |
| | | log.info("库存差异信息清除"); |
| | | inventoryVarianceService.deleteAll(); |
| | | |
| | | log.info("与ERP比对开始"); |
| | | int pageSize = 500; |
| | | int pageNumber = 0; |
| | | while (true){ |
| | | List<InventoryVariance> inventoryVariances = new ArrayList<>(); |
| | | List<WlzhVStRd> wlzhVStRds = erpService.selectPage(pageSize, pageNumber); |
| | | if(wlzhVStRds.size() < pageSize){ |
| | | break; |
| | | } |
| | | |
| | | //ERP库存与立库库存比对 |
| | | compileStock(wlzhVStRds,inventoryVariances); |
| | | pageNumber ++; |
| | | inventoryVarianceService.insertBatch(inventoryVariances); |
| | | } |
| | | |
| | | } |
| | | |
| | | private void compileStock(List<WlzhVStRd> wlzhVStRds, List<InventoryVariance> inventoryVariances){ |
| | | wlzhVStRds.forEach(wlzhVStRd -> { |
| | | String matnr = wlzhVStRd.getCinvcode(); |
| | | String csocode = wlzhVStRd.getCsocode(); |
| | | String isoseq = wlzhVStRd.getIsoseq(); |
| | | Double iQuantity = wlzhVStRd.getIquantity(); |
| | | |
| | | Double anfme = 0.0; |
| | | |
| | | List<AllLocDetl> allLocDetlList = allLocDetlService.getByMatnrAndCsocodeAndIsoseq(matnr, csocode, isoseq); |
| | | for(AllLocDetl allLocDetl : allLocDetlList){ |
| | | anfme += allLocDetl.getAnfme(); |
| | | } |
| | | |
| | | int compare = Double.compare(iQuantity, anfme); |
| | | if(compare != 0){ |
| | | InventoryVariance inventoryVarianceParam = new InventoryVariance(matnr,csocode,isoseq,iQuantity,anfme); |
| | | inventoryVariances.add(inventoryVarianceParam); |
| | | } |
| | | |
| | | }); |
| | | } |
| | | |
| | | |
| | | } |