| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.vincent.rsf.framework.exception.CoolException; |
| | | import com.vincent.rsf.server.common.utils.DateUtils; |
| | | import com.vincent.rsf.server.manager.entity.*; |
| | | import com.vincent.rsf.server.manager.service.*; |
| | | 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.Collection; |
| | | import java.util.Collections; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * @author Ryan |
| | |
| | | * @description |
| | | * @create 2025/3/3 15:38 |
| | | */ |
| | | @Component |
| | | public class ScheduleJobs { |
| | | |
| | | @Autowired |
| | |
| | | private AsnOrderItemService asnOrderItemService; |
| | | /** |
| | | * @author Ryan |
| | | * @description 根据PO单据生成ASN单 |
| | | * @description 根据PO单据生成ASN单,自动生成ASN单为全量生成 |
| | | * @throws |
| | | * @return |
| | | * @time 2025/3/3 15:44 |
| | | */ |
| | | @Scheduled(cron = "0/10 * * * * ? ") |
| | | @Scheduled(cron = "0 0/30 * * * ? ") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void genAsnOrder() { |
| | | //获取未生成ASN单据 |
| | | List<Purchase> purchases = purchaseService.list(new LambdaQueryWrapper<Purchase>().eq(Purchase::getStatus, 2)); |
| | | List<Purchase> purchases = purchaseService.list(new LambdaQueryWrapper<Purchase>().eq(Purchase::getStatus, 0)); |
| | | //采购单为空,直接跳出当前任务 |
| | | if (purchases.isEmpty()) { |
| | | return; |
| | | } |
| | | //生成ASN单据 |
| | | purchases.forEach(purchase -> { |
| | | if (!Objects.isNull(purchase.getStartTime())) { |
| | | //判断起始时间是否大于当前时间 |
| | | if (DateUtils.compareDate(new Date(), purchase.getStartTime())) { |
| | | return; |
| | | } |
| | | } |
| | | List<PurchaseItem> items = purchaseItemService.list(new LambdaQueryWrapper<PurchaseItem>().eq(PurchaseItem::getPurchaseId, purchase.getId())); |
| | | //子列表为空数据,直接跳出 |
| | | if (items.isEmpty()) { |
| | | return; |
| | | throw new CoolException("子列表数据为空,请查询PO单是否正确录入!!"); |
| | | } |
| | | AsnOrder order = new AsnOrder(); |
| | | order.setAnfme(purchase.getAnfme()) |
| | |
| | | orderItem.setAnfme(item.getAnfme()) |
| | | .setAsnId(purchase.getId()) |
| | | .setQty(item.getQty()) |
| | | .setSplrName(item.getPulrName()) |
| | | .setSplrCode(item.getPulrCode()) |
| | | .setSplrName(item.getSplrName()) |
| | | .setSplrCode(item.getSplrCode()) |
| | | .setMatnk(item.getMatnrName()) |
| | | .setPoDetlId(item.getId() + "") |
| | | .setPurQty(item.getAnfme()) |
| | |
| | | throw new CoolException(("Asn单据明细保存失败!!")); |
| | | } |
| | | |
| | | //任务执行完成,修改已完成数量和PO单执行状态 |
| | | purchase.setQty(purchase.getAnfme()).setStatus(1); |
| | | |
| | | if (!purchaseService.save(purchase)) { |
| | | throw new CoolException("PO单执行完成后,保存失败!!"); |
| | | } |
| | | |
| | | }); |
| | | } |
| | | |