| | |
| | | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | 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 org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class AutoReplenishmentHandler extends AbstractHandler<String> { |
| | |
| | | private WrkDetlService wrkDetlService; |
| | | @Autowired |
| | | private OrderService orderService; |
| | | @Autowired |
| | | private SnowflakeIdWorker snowflakeIdWorker; |
| | | |
| | | |
| | | @Transactional |
| | | public ReturnT<String> create(Mat mat, double anfme) { |
| | | //创建一个新的自动补货单据 |
| | | Order order = createOrder(); |
| | | orderService.insert(order); |
| | | OrderDetl orderDetl = createOrderDetl(order); |
| | | orderDetl.setMatnr(mat.getMatnr()); |
| | | orderDetl.setMaktx(mat.getMaktx()); |
| | | orderDetl.setSpecs(mat.getSpecs()); |
| | | orderDetl.setAnfme(anfme); |
| | | orderDetl.setQty(0.0); |
| | | |
| | | |
| | | orderDetlService.insert(orderDetl); |
| | | |
| | | return SUCCESS; |
| | | } |
| | | |
| | | @Transactional |
| | | public ReturnT<String> start(Order order) { |
| | |
| | | order.setSettle(2L); |
| | | orderService.updateById(order); |
| | | |
| | | |
| | | return SUCCESS; |
| | | } |
| | | |
| | | private Order createOrder(){ |
| | | Date now = new Date(); |
| | | return new Order( |
| | | String.valueOf(snowflakeIdWorker.nextId()), // 编号[非空] |
| | | "AUTO" + snowflakeIdWorker.nextId(), // 订单编号 |
| | | DateUtils.convert(now), // 单据日期 |
| | | 21L, // 单据类型 21.自动补货单 |
| | | null, // 项目编号 |
| | | null, // |
| | | null, // 调拨项目编号 |
| | | null, // 初始票据号 |
| | | null, // 票据号 |
| | | null, // 客户编号 |
| | | null, // 客户 |
| | | null, // 联系方式 |
| | | null, // 操作人员 |
| | | null, // 合计金额 |
| | | null, // 优惠率 |
| | | null, // 优惠金额 |
| | | null, // 销售或采购费用合计 |
| | | null, // 实付金额 |
| | | null, // 付款类型 |
| | | null, // 业务员 |
| | | null, // 结算天数 |
| | | null, // 邮费支付类型 |
| | | null, // 邮费 |
| | | null, // 付款时间 |
| | | null, // 发货时间 |
| | | null, // 物流名称 |
| | | null, // 物流单号 |
| | | 1L, // 订单状态 |
| | | 1, // 状态 |
| | | 9999L, // 添加人员 |
| | | now, // 添加时间 |
| | | 9999L, // 修改人员 |
| | | now, // 修改时间 |
| | | null // 备注 |
| | | ); |
| | | |
| | | } |
| | | |
| | | private OrderDetl createOrderDetl(Order order){ |
| | | Date now = new Date(); |
| | | OrderDetl orderDetl = new OrderDetl(); |
| | | |
| | | orderDetl.setOrderId(order.getId()); |
| | | orderDetl.setOrderNo(order.getOrderNo()); |
| | | orderDetl.setCreateBy(order.getCreateBy()); |
| | | orderDetl.setCreateTime(now); |
| | | orderDetl.setUpdateBy(order.getCreateBy()); |
| | | orderDetl.setUpdateTime(now); |
| | | orderDetl.setStatus(1); |
| | | orderDetl.setQty(0.0D); |
| | | |
| | | return orderDetl; |
| | | } |
| | | |
| | | private Set<String> pakoutLoc(Order order){ |
| | |
| | | } |
| | | |
| | | String matnr = orderDetl.getMatnr(); |
| | | String batch = orderDetl.getBatch(); |
| | | String csocode = orderDetl.getThreeCode(); |
| | | String isocode = orderDetl.getDeadTime(); |
| | | |
| | | Double orderAnfme = orderDetl.getAnfme(); |
| | | double orderAnfme = orderDetl.getAnfme(); |
| | | |
| | | //List<String> locNosSearch = locDetlService.selectLocNo(matnr); |
| | | Set<String> locNosSearch = locDetlService.selectLocNo(matnr, batch, csocode, isocode); |
| | | Set<String> locNosSearch = locDetlService.selectLocNos(matnr); |
| | | |
| | | //重新排序 并且检测该库位是否含没有料箱码的物料,如有有则不允许出库 |
| | | //过滤库位货物为高货物 |
| | | locNosSearch = locNosSearch.stream().filter(locNo -> { |
| | | LocMast locMast = locMastService.selectByLoc(locNo); |
| | | if(locMast.getLocType1() == 3){ |
| | | return false; |
| | | }else { |
| | | //且检测该库位是否含没有料箱码的物料,如有有则不允许出库 |
| | | // LocDetl locDetl = locDetlService.selectOne(new EntityWrapper<LocDetl>().eq("loc_no", locNo) |
| | | // .andNew().eq("supp_code", "").or().isNull("supp_code")); |
| | | |
| | | if(Cools.isEmpty(locDetlService.selectByLocWithoutContainer(locNo))){ |
| | | return true; |
| | | }else { |
| | | return false; |
| | | } |
| | | } |
| | | }).collect(Collectors.toSet()); |
| | | |
| | | //重新排序 |
| | | Set<String> resort = resort(locNosSearch); |
| | | |
| | | for(String locNo : resort){ |
| | |
| | | for (LocDetl locDetl :locDetls){ |
| | | if(matnr.equals(locDetl.getMatnr())){ |
| | | orderAnfme -= locDetl.getAnfme(); |
| | | }else { |
| | | OrderDetl odNew = createOrderDetl(order); |
| | | odNew.setMatnr(locDetl.getMatnr()); |
| | | odNew.setMaktx(locDetl.getMaktx()); |
| | | odNew.setBatch(locDetl.getBatch()); |
| | | odNew.setThreeCode(locDetl.getThreeCode()); |
| | | odNew.setDeadTime(locDetl.getDeadTime()); |
| | | odNew.setSpecs(locDetl.getSpecs()); |
| | | odNew.setAnfme(0.0); |
| | | odNew.setQty(locDetl.getAnfme()); |
| | | orderDetlService.insert(odNew); |
| | | } |
| | | } |
| | | if(orderAnfme <= 0){ |
| | |
| | | orderDetlService.updateById(orderDetl); |
| | | break; |
| | | } |
| | | } |
| | | if(orderAnfme > 0){ |
| | | orderDetl.setAnfme(orderDetl.getAnfme() - orderAnfme); |
| | | orderDetl.setQty(orderDetl.getAnfme()); |
| | | orderDetlService.updateById(orderDetl); |
| | | } |
| | | } |
| | | |
| | |
| | | //wrkMast.setModiUser(userId); |
| | | wrkMast.setModiTime(now); |
| | | |
| | | //补货标识 |
| | | wrkMast.setMk("Y"); |
| | | if (!wrkMastService.insert(wrkMast)) { |
| | | throw new CoolException("保存工作档失败,出库库位号:"+locNo); |