| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.vincent.rsf.framework.exception.CoolException; |
| | | import com.vincent.rsf.server.common.config.SysStockFlowProperties; |
| | | import com.vincent.rsf.server.common.config.SysStockProperties; |
| | | import com.vincent.rsf.server.common.utils.CommonUtil; |
| | | import com.vincent.rsf.server.common.utils.DateUtils; |
| | | import com.vincent.rsf.server.manager.entity.*; |
| | | import com.vincent.rsf.server.manager.service.*; |
| | | import com.vincent.rsf.server.system.constant.SerialRuleCode; |
| | | import com.vincent.rsf.server.system.utils.SerialRuleUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author Ryan |
| | |
| | | private AsnOrderItemService asnOrderItemService; |
| | | |
| | | @Resource |
| | | private SysStockFlowProperties flowProperties; |
| | | private SysStockProperties flowProperties; |
| | | @Autowired |
| | | private WaitPakinService waitPakinService; |
| | | @Autowired |
| | | private WaitPakinItemService waitPakinItemService; |
| | | @Autowired |
| | | private WaitPakinLogService waitPakinLogService; |
| | | @Autowired |
| | | private WaitPakinItemLogService waitPakinItemLogService; |
| | | |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @description 根据PO单据生成ASN单,自动生成ASN单为全量生成 |
| | |
| | | * @return |
| | | * @time 2025/3/3 15:44 |
| | | */ |
| | | @Scheduled(cron = "0 0/30 * * * ? ") |
| | | @Scheduled(cron = "0 0/05 * * * ? ") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void genAsnOrder() { |
| | | public synchronized void genAsnOrder() { |
| | | //判断是否开启自动生成ASN单据 |
| | | if (!flowProperties.getFlagAutoAsn()) { |
| | | return; |
| | | } |
| | | //获取未生成ASN单据 |
| | | List<Purchase> purchases = purchaseService.list(new LambdaQueryWrapper<Purchase>().eq(Purchase::getStatus, 0)); |
| | | //采购单为空,直接跳出当前任务 |
| | | //PO单为空,直接跳出当前任务 |
| | | if (purchases.isEmpty()) { |
| | | return; |
| | | } |
| | |
| | | List<AsnOrderItem> orderItems = new ArrayList<>(); |
| | | items.forEach(item -> { |
| | | AsnOrderItem orderItem = new AsnOrderItem(); |
| | | Matnr matnr = matnrService.getOne(new LambdaQueryWrapper<Matnr>().eq(Matnr::getId, item.getMatnrCode())); |
| | | Matnr matnr = matnrService.getOne(new LambdaQueryWrapper<Matnr>().eq(Matnr::getCode, item.getMatnrCode())); |
| | | if (Objects.isNull(matnr)) { |
| | | throw new CoolException("数据错误:当前物料不存在!!"); |
| | | } |
| | | String trackCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_LABEL_CODE, item); |
| | | if (StringUtils.isBlank(trackCode)) { |
| | | throw new CoolException("单据跟踪码生成失败:请检查「sys_asn_mantr_label」是否配置完成!!"); |
| | | } |
| | | // String barcode = code + matnr.getCode(); |
| | | orderItem.setAnfme(item.getAnfme()) |
| | | .setAsnId(purchase.getId()) |
| | | .setAsnId(order.getId()) |
| | | .setQty(item.getQty()) |
| | | .setSplrName(item.getSplrName()) |
| | | .setAsnCode(code) |
| | | .setSplrCode(item.getSplrCode()) |
| | | .setMatnk(item.getMatnrName()) |
| | | .setPoDetlId(item.getId() + "") |
| | | .setPoDetlId(item.getId()) |
| | | .setPlatItemId(item.getPlatItemId()) |
| | | .setTrackCode(trackCode) |
| | | .setPoCode(purchase.getCode()) |
| | | .setPurQty(item.getAnfme()) |
| | | .setPurUnit(item.getUnit()) |
| | | .setMatnk(matnr.getName()) |
| | | .setMatnrId(matnr.getId() + ""); |
| | | .setMatnrCode(matnr.getCode()) |
| | | .setMaktx(matnr.getName()) |
| | | .setMatnrId(matnr.getId()); |
| | | orderItems.add(orderItem); |
| | | }); |
| | | if (!asnOrderItemService.saveBatch(orderItems)) { |
| | |
| | | //任务执行完成,修改已完成数量和PO单执行状态 |
| | | purchase.setQty(purchase.getAnfme()).setStatus(1); |
| | | |
| | | if (!purchaseService.save(purchase)) { |
| | | if (!purchaseService.saveOrUpdate(purchase)) { |
| | | throw new CoolException("PO单执行完成后,保存失败!!"); |
| | | } |
| | | |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @description 生成物料标签 |
| | | * @param |
| | | * @return |
| | | * @time 2025/3/29 12:35 |
| | | */ |
| | | @Scheduled(cron = "0 0/05 * * * ? ") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void generateMatnrLabel() { |
| | | List<AsnOrderItem> list = asnOrderItemService.list(new LambdaQueryWrapper<AsnOrderItem>() |
| | | .isNull(AsnOrderItem::getTrackCode) |
| | | .select(AsnOrderItem::getId)); |
| | | if (Objects.isNull(list) || list.isEmpty()) { |
| | | return; |
| | | } |
| | | List<AsnOrderItem> items = new ArrayList<>(); |
| | | list.forEach(item -> { |
| | | String trackCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_LABEL_CODE, item); |
| | | if (StringUtils.isBlank(trackCode)) { |
| | | throw new CoolException("单据跟踪码生成失败:请检查「sys_asn_mantr_label」是否配置完成!!"); |
| | | } |
| | | item.setTrackCode(trackCode); |
| | | items.add(item); |
| | | }); |
| | | |
| | | if (!asnOrderItemService.updateBatchById(items)) { |
| | | throw new CoolException("生成编码失败!!"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @description 组拖历史档 |
| | | * @param |
| | | * @return |
| | | * @time 2025/3/29 12:36 |
| | | */ |
| | | @Scheduled(cron = "0/5 * * * * ?") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void pakinLog() { |
| | | List<WaitPakin> pakinIds = waitPakinService.list(new LambdaQueryWrapper<WaitPakin>().eq(WaitPakin::getIoStatus, 2).select(WaitPakin::getId)); |
| | | if (pakinIds.isEmpty()) { |
| | | return; |
| | | } |
| | | List<Long> list = pakinIds.stream().map(WaitPakin::getId).collect(Collectors.toList()); |
| | | List<WaitPakin> pakins = waitPakinService.list(new LambdaQueryWrapper<WaitPakin>().in(WaitPakin::getId, list)); |
| | | if (pakins.isEmpty()) { |
| | | throw new CoolException("组拖单为空!!"); |
| | | } |
| | | List<WaitPakinLog> pakinLogs = new ArrayList<>(); |
| | | pakins.forEach(pakin ->{ |
| | | WaitPakinLog log = new WaitPakinLog(); |
| | | BeanUtils.copyProperties(pakin, log); |
| | | log.setPakinId(pakin.getId()).setIoStatus(Short.parseShort("2")); |
| | | pakinLogs.add(log); |
| | | }); |
| | | if (!waitPakinLogService.saveBatch(pakinLogs)) { |
| | | throw new CoolException("历史档保存失败!!"); |
| | | } |
| | | List<WaitPakinItemLog> itemLogs = new ArrayList<>(); |
| | | List<WaitPakinItem> pakinItems = waitPakinItemService.list(new LambdaQueryWrapper<WaitPakinItem>().in(WaitPakinItem::getPakinId, list)); |
| | | if (pakinItems.isEmpty()) { |
| | | throw new CoolException("组拖明细为空!!"); |
| | | } |
| | | pakinItems.forEach(item -> { |
| | | WaitPakinItemLog itemLog = new WaitPakinItemLog(); |
| | | BeanUtils.copyProperties(item, itemLog); |
| | | itemLog.setPakinItemId(item.getId()) |
| | | .setPakinId(item.getPakinId()); |
| | | itemLogs.add(itemLog); |
| | | }); |
| | | |
| | | if (!waitPakinItemLogService.saveBatch(itemLogs)) { |
| | | throw new CoolException("历史明细档保存失败!!"); |
| | | } |
| | | if (!waitPakinService.removeByIds(pakins)) { |
| | | throw new CoolException("原单据删除失败!!"); |
| | | } |
| | | if (!waitPakinItemService.removeByIds(pakinItems)) { |
| | | throw new CoolException("原单据明细删除失败!!"); |
| | | } |
| | | } |
| | | |
| | | } |