From 86b8273226c7aa87e7c346659ed9e76278dcc471 Mon Sep 17 00:00:00 2001 From: zyx <zyx123456> Date: 星期日, 15 十月 2023 11:28:01 +0800 Subject: [PATCH] AGV工作档取消和完成 --- src/main/java/com/zy/common/service/erp/task/ErpScheduler.java | 187 ++++++++++++++-------------------------------- 1 files changed, 56 insertions(+), 131 deletions(-) diff --git a/src/main/java/com/zy/common/service/erp/task/ErpScheduler.java b/src/main/java/com/zy/common/service/erp/task/ErpScheduler.java index c09b5b8..0b38dcd 100644 --- a/src/main/java/com/zy/common/service/erp/task/ErpScheduler.java +++ b/src/main/java/com/zy/common/service/erp/task/ErpScheduler.java @@ -2,33 +2,35 @@ import com.core.common.Cools; import com.core.common.DateUtils; -import com.core.common.SnowflakeIdWorker; import com.core.exception.CoolException; -import com.zy.asrs.entity.*; -import com.zy.asrs.service.*; +import com.zy.asrs.entity.AllLocDetl; +import com.zy.asrs.entity.InventoryVariance; +import com.zy.asrs.entity.Mat; +import com.zy.asrs.entity.Tag; +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 com.zy.common.service.erp.dto.VoucherDto; import com.zy.common.service.erp.entity.Goods; -import com.zy.common.service.erp.entity.Voucher; -import com.zy.common.service.erp.entity.VoucherDetail; +import com.zy.common.service.erp.entity.WlzhVStRd; import lombok.Synchronized; 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.ArrayList; import java.util.Date; import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; /** * erp浠诲姟鎺у埗鍣� * Created by vincent on 2020/11/27 */ @Slf4j -//@Component +@Component public class ErpScheduler extends AbstractHandler<Exception> { @Autowired @@ -38,15 +40,11 @@ @Autowired private MatService matService; @Autowired - private OrderService orderService; + private AllLocDetlService allLocDetlService; @Autowired - private DocTypeService docTypeService; - @Autowired - private OrderDetlService orderDetlService; - @Autowired - private SnowflakeIdWorker snowflakeIdWorker; + private InventoryVarianceService inventoryVarianceService; - @Scheduled(cron = "0/5 * * * * ? ") + //@Scheduled(cron = "0/5 * * * * ? ") @Synchronized @Transactional public synchronized void syncMat() { @@ -85,126 +83,53 @@ } } - @Scheduled(cron = "0/5 * * * * ? ") + //@Scheduled(cron = "0/5 * * * * ? ") @Synchronized @Transactional - public synchronized void syncOrder() { - List<VoucherDto> list = erpService.selectOrder(0); - for (VoucherDto dto : list) { - Voucher voucher = dto.getVoucher(); - Order order = orderService.selectByNo(voucher.getVoucherID()); - if (Cools.isEmpty(order)) { + public void syncLocDetl(){ - String regEx = "[^0-9]"; - Pattern compile = Pattern.compile(regEx); - Matcher matcher = compile.matcher(voucher.getMT()); - String docTypeVal = matcher.replaceAll("").trim(); + List<InventoryVariance> inventoryVariances = new ArrayList<>(); - DocType docType = docTypeService.selectOrAdd(docTypeVal, null); - Date now = new Date(); - // 鍗曟嵁涓绘。 - order = new Order( - String.valueOf(snowflakeIdWorker.nextId()), // 缂栧彿[闈炵┖] - voucher.getVoucherID(), // 璁㈠崟缂栧彿 - DateUtils.convert(now), // 鍗曟嵁鏃ユ湡 - docType.getDocId(), // 鍗曟嵁绫诲瀷 - null, // 椤圭洰缂栧彿 - null, // - null, // 璋冩嫧椤圭洰缂栧彿 - voucher.getBatch(), // 鍒濆绁ㄦ嵁鍙� - voucher.getMaterialNO(), // 绁ㄦ嵁鍙� - null, // 瀹㈡埛缂栧彿 - voucher.getCustomer(), // 瀹㈡埛 - voucher.getCenterID(), // 鑱旂郴鏂瑰紡 - voucher.getPlant(), // 鎿嶄綔浜哄憳 - voucher.getTotalNum(), // 鍚堣閲戦 ******************** - null, // 浼樻儬鐜� - null, // 浼樻儬閲戦 - null, // 閿�鍞垨閲囪喘璐圭敤鍚堣 - null, // 瀹炰粯閲戦 - null, // 浠樻绫诲瀷 - voucher.getLoc(), // 涓氬姟鍛� - voucher.getTotalCount(), // 缁撶畻澶╂暟 ******************** - null, // 閭垂鏀粯绫诲瀷 - voucher.getExpectedWeight(), // 閭垂 - null, // 浠樻鏃堕棿 - null, // 鍙戣揣鏃堕棿 - null, // 鐗╂祦鍚嶇О - null, // 鐗╂祦鍗曞彿 - 1L, // 璁㈠崟鐘舵�� - 1, // 鐘舵�� - 9527L, // 娣诲姞浜哄憳 - now, // 娣诲姞鏃堕棿 - 9527L, // 淇敼浜哄憳 - now, // 淇敼鏃堕棿 - null // 澶囨敞 - ); - if (!orderService.insert(order)) { - throw new CoolException(order.getOrderNo() + "鐢熸垚鍗曟嵁涓绘。澶辫触锛岃鑱旂郴绠$悊鍛�"); - } - - Mat mat = matService.selectByMatnr(voucher.getMaterialNO()); - if (mat == null) { - throw new CoolException(voucher.getMaterialNO() + "鐗╂枡鍙蜂笉瀛樺湪"); - } - - // 绻冲韩鍠� - if (docType.getPakin() == 1) { - for (VoucherDetail detail : dto.getDetails()) { - OrderDetl orderDetl = new OrderDetl(); - orderDetl.sync(mat); - - orderDetl.setBatch(detail.getBarcode()); - orderDetl.setAnfme(mat.getWeight()); - - orderDetl.setOrderId(order.getId()); - orderDetl.setOrderNo(order.getOrderNo()); - orderDetl.setCreateBy(9527L); - orderDetl.setCreateTime(now); - orderDetl.setUpdateBy(9527L); - orderDetl.setUpdateTime(now); - orderDetl.setStatus(1); - orderDetl.setQty(0.0D); - if (!orderDetlService.insert(orderDetl)) { - throw new CoolException(order.getOrderNo() + "鐢熸垚鍗曟嵁鏄庣粏澶辫触锛岃鑱旂郴绠$悊鍛�"); - } - } - } else { - OrderDetl orderDetl = new OrderDetl(); - orderDetl.sync(mat); - StringBuilder sb = new StringBuilder(); - if (!Cools.isEmpty(dto.getDetails())) { - for (VoucherDetail detail : dto.getDetails()) { - sb.append(detail.getBarcode()).append(","); - } - orderDetl.setBatch(sb.toString()); - } - orderDetl.setAnfme(voucher.getExpectedWeight()); - orderDetl.setOrderId(order.getId()); - orderDetl.setOrderNo(order.getOrderNo()); - orderDetl.setCreateBy(9527L); - orderDetl.setCreateTime(now); - orderDetl.setUpdateBy(9527L); - orderDetl.setUpdateTime(now); - orderDetl.setStatus(1); - orderDetl.setQty(0.0D); - if (!orderDetlService.insert(orderDetl)) { - throw new CoolException(order.getOrderNo() + "鐢熸垚鍗曟嵁鏄庣粏澶辫触锛岃鑱旂郴绠$悊鍛�"); - } - } - - // erp 鍚屾 - int state = 1; - if (!erpService.updateStateForVoucher(voucher.getVoucherID(), state)) { - throw new CoolException(voucher.getVoucherID() + "璁㈠崟淇敼State涓�"+state+"澶辫触"); - } else { - erpService.updateTimeForVoucherDetail(voucher.getVoucherID()); - } - - } else { - log.warn("{}璁㈠崟宸插瓨鍦�", voucher.getVoucherID()); + int pageSize = 500; + int pageNumber = 0; + while (true){ + 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); + } + + }); + } + + } -- Gitblit v1.9.1