| | |
| | | package com.zy.third.task.handler; |
| | | |
| | | 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.DocType; |
| | | import com.zy.asrs.entity.Mat; |
| | | import com.zy.asrs.entity.Order; |
| | | import com.zy.asrs.entity.OrderDetl; |
| | | import com.zy.asrs.service.DocTypeService; |
| | | import com.zy.asrs.service.MatService; |
| | | import com.zy.asrs.service.OrderDetlService; |
| | | import com.zy.asrs.service.OrderService; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.task.AbstractHandler; |
| | | import com.zy.asrs.task.core.ReturnT; |
| | | import com.zy.common.model.DetlDto; |
| | | import com.zy.third.entity.ExdInstockSource; |
| | | import com.zy.third.entity.ExdOutstockSource; |
| | | import com.zy.third.entity.ExdStock; |
| | | import com.zy.third.service.ExdStockService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | @Autowired |
| | | private MatService matService; |
| | | |
| | | @Autowired |
| | | private ExdStockService exdStockService; |
| | | @Autowired |
| | | private Order1Service order1Service; |
| | | @Autowired |
| | | private OrderDetl1Service orderDetl1Service; |
| | | |
| | | |
| | | @Transactional |
| | | public ReturnT<String> readInOrder(List<ExdInstockSource> exdInstockSource) { |
| | |
| | | Integer ftrantype = exdInstockSource.get(0).getFtrantype(); |
| | | Order order = orderService.selectByNo(fbillno); |
| | | if (!Cools.isEmpty(order)) { |
| | | throw new CoolException(fbillno + "单据已存在,请勿重复提交"); |
| | | if (order.getSettle() > 1L) { |
| | | throw new CoolException(fbillno + "单据作业中,请勿重复提交"); |
| | | } |
| | | orderService.remove(order.getId()); |
| | | //删除入库子单 |
| | | Order1 order1 = order1Service.selectByNo(fbillno); |
| | | if (!Cools.isEmpty(order1)) { |
| | | order1Service.remove(order1.getId()); |
| | | } |
| | | } |
| | | DocType docType = docTypeService.selectById(ftrantype); |
| | | if (docType == null) { |
| | |
| | | order = new Order( |
| | | String.valueOf(snowflakeIdWorker.nextId()), // 编号[非空] |
| | | fbillno, // 订单编号 |
| | | DateUtils.convert(now), // 单据日期 |
| | | DateUtils.convert(exdInstockSource.get(0).getFdate()), // 单据日期 |
| | | docType.getDocId(), // 单据类型 |
| | | null, // 项目编号 |
| | | null, // |
| | |
| | | if (!orderService.insert(order)) { |
| | | throw new CoolException("生成单据主档失败,请联系管理员"); |
| | | } |
| | | |
| | | //生成子单主表 |
| | | Order1 order1 = new Order1( |
| | | String.valueOf(snowflakeIdWorker.nextId()), // 编号[非空] |
| | | fbillno, // 订单编号 |
| | | DateUtils.convert(exdInstockSource.get(0).getFdate()), // 单据日期 |
| | | docType.getDocId(), // 单据类型 |
| | | 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, // 状态 |
| | | 9527L, // 添加人员 |
| | | now, // 添加时间 |
| | | 9527L, // 修改人员 |
| | | now, // 修改时间 |
| | | null // 备注 |
| | | ); |
| | | if (!order1Service.insert(order1)) { |
| | | throw new CoolException("生成子单据主档失败,请联系管理员"); |
| | | } |
| | | |
| | | // 单据明细档 |
| | | List<DetlDto> list = new ArrayList<>(); |
| | | for (ExdInstockSource detail : exdInstockSource) { |
| | | DetlDto dto = new DetlDto(detail.getFitemid() + "", detail.getFbatchno(), detail.getFqty()); |
| | | dto.setFrob(detail.getFrob()); |
| | | dto.setFInterID(detail.getFinterid()); |
| | | dto.setProdInKind(detail.getFdcstockid()+""); |
| | | if (DetlDto.has(list, dto)) { |
| | | DetlDto detlDto = DetlDto.find(list, dto.getMatnr(), dto.getBatch()); |
| | | assert detlDto != null; |
| | |
| | | } |
| | | } |
| | | for (DetlDto detlDto : list) { |
| | | Mat mat = matService.selectByMatnr(detlDto.getMatnr()); |
| | | Mat mat = matService.selectBySku(detlDto.getMatnr()); |
| | | if (Cools.isEmpty(mat)) { |
| | | throw new CoolException(detlDto.getMatnr() + "编号商品检索失败,请先添加商品"); |
| | | } |
| | | OrderDetl orderDetl = new OrderDetl(); |
| | | orderDetl.sync(mat); |
| | | orderDetl.setBatch(detlDto.getBatch()); |
| | | if(detlDto.getAnfme() <0) { |
| | | detlDto.setAnfme(-detlDto.getAnfme()); |
| | | } |
| | | orderDetl.setAnfme(detlDto.getAnfme()); |
| | | orderDetl.setOrderId(order.getId()); |
| | | orderDetl.setOrderNo(order.getOrderNo()); |
| | |
| | | orderDetl.setUpdateTime(now); |
| | | orderDetl.setStatus(1); |
| | | orderDetl.setQty(0.0D); |
| | | orderDetl.setDeadWarn(detlDto.getFInterID()); |
| | | orderDetl.setBeBatch(detlDto.getFrob()); |
| | | ExdStock id = exdStockService.selectOne(new EntityWrapper<ExdStock>().eq("ID", detlDto.getProdInKind())); |
| | | orderDetl.setBrand(id.getFname());//仓库 |
| | | if (!orderDetlService.insert(orderDetl)) { |
| | | throw new CoolException("生成单据明细失败,请联系管理员"); |
| | | } |
| | | |
| | | //生成子单明细 |
| | | OrderDetl1 orderDetl1 = new OrderDetl1(); |
| | | orderDetl1.sync(orderDetl); |
| | | orderDetl1.setOrderId(order1.getId()); |
| | | if (!orderDetl1Service.insert(orderDetl1)) { |
| | | throw new CoolException("生成单据明细失败,请联系管理员"); |
| | | } |
| | | } |
| | | return SUCCESS; |
| | | } |
| | | |
| | | @Transactional |
| | | public ReturnT<String> deletereadInOrder(ExdInstockSource exdInstockSource) { |
| | | String fbillno = exdInstockSource.getFbillno(); |
| | | Order order = orderService.selectByNo(fbillno); |
| | | if (!Cools.isEmpty(order)) { |
| | | if (order.getSettle() > 1L) { |
| | | throw new CoolException(fbillno + "单据正在作业中,无法删除"); |
| | | } |
| | | Mat mat = matService.selectBySku(exdInstockSource.getFitemid() + ""); |
| | | boolean delete = orderDetlService.delete(new EntityWrapper<OrderDetl>() |
| | | .eq("order_no", order.getOrderNo()) |
| | | .eq("matnr", mat.getMatnr()) |
| | | .eq("batch", exdInstockSource.getFbatchno()) |
| | | .eq("anfme", exdInstockSource.getFqty())); |
| | | if (delete) { |
| | | log.info("删除订单明细成功,订单号={},物料号={},批号={},数量={}成功",order.getOrderNo(),exdInstockSource.getFitemid(),exdInstockSource.getFbatchno(),exdInstockSource.getFqty()); |
| | | }else { |
| | | log.error("删除订单明细失败,订单号={},物料号={},批号={},数量={}",order.getOrderNo(),exdInstockSource.getFitemid(),exdInstockSource.getFbatchno(),exdInstockSource.getFqty()); |
| | | throw new CoolException(fbillno + "单据明细删除失败"); |
| | | } |
| | | int orderNo = orderDetlService.selectCount(new EntityWrapper<OrderDetl>().eq("order_no", order.getOrderNo())); |
| | | if(orderNo==0){ |
| | | orderService.remove(order.getId()); |
| | | log.info("删除订单主表成功,订单={}",order.getOrderNo()); |
| | | } |
| | | }else if(Cools.isEmpty(order)){ |
| | | throw new CoolException(fbillno + "单据为在WMS中找到"); |
| | | } |
| | | return SUCCESS; |
| | | } |
| | | |
| | | @Transactional |
| | | public ReturnT<String> readOutOrder(List<ExdOutstockSource> exdOutstockSource) { |
| | |
| | | // 如果单据不存在则添加;如果单据存在,作业中无法修改,反之则修改单据 |
| | | if (!Cools.isEmpty(order)) { |
| | | if (order.getSettle() > 1L) { |
| | | throw new CoolException(fbillno + "正在出库,无法修改单据"); |
| | | throw new CoolException(fbillno + "单据正在作业中,请勿重复提交"); |
| | | } |
| | | orderService.remove(order.getId()); |
| | | } |
| | | if(ftrantype == 41){ |
| | | ftrantype = 42; |
| | | }else if(ftrantype == 24){ |
| | | ftrantype = 25; |
| | | }else if(ftrantype == 1){ |
| | | ftrantype = 3; |
| | | } |
| | | DocType docType = docTypeService.selectById(ftrantype); |
| | | Date now = new Date(); |
| | |
| | | List<DetlDto> list = new ArrayList<>(); |
| | | for (ExdOutstockSource detail : exdOutstockSource) { |
| | | DetlDto dto = new DetlDto(detail.getFitemid()+"", detail.getFbatchno(), detail.getFqty()); |
| | | dto.setFInterID(detail.getFinterid()); |
| | | if (DetlDto.has(list, dto)) { |
| | | DetlDto detlDto = DetlDto.find(list, dto.getMatnr(), dto.getBatch()); |
| | | assert detlDto != null; |
| | | detlDto.setAnfme(detlDto.getAnfme() + detail.getFqty()); |
| | | |
| | | } else { |
| | | list.add(dto); |
| | | } |
| | | } |
| | | for (DetlDto detlDto : list) { |
| | | Mat mat = matService.selectByMatnr(detlDto.getMatnr()); |
| | | Mat mat = matService.selectBySku(detlDto.getMatnr()); |
| | | if (Cools.isEmpty(mat)) { |
| | | throw new CoolException(detlDto.getMatnr() + "编号商品检索失败,请先添加商品"); |
| | | } |
| | | OrderDetl orderDetl = new OrderDetl(); |
| | | orderDetl.sync(mat); |
| | | orderDetl.setBatch(detlDto.getBatch()); |
| | | if(detlDto.getAnfme() <0) { |
| | | detlDto.setAnfme(-detlDto.getAnfme()); |
| | | } |
| | | orderDetl.setAnfme(detlDto.getAnfme()); |
| | | orderDetl.setOrderId(order.getId()); |
| | | orderDetl.setOrderNo(order.getOrderNo()); |
| | |
| | | orderDetl.setCreateTime(now); |
| | | orderDetl.setUpdateBy(9527L); |
| | | orderDetl.setUpdateTime(now); |
| | | orderDetl.setDeadWarn(detlDto.getFInterID());//订单内码 |
| | | orderDetl.setStatus(1); |
| | | orderDetl.setQty(0.0D); |
| | | if (!orderDetlService.insert(orderDetl)) { |
| | |
| | | return SUCCESS; |
| | | } |
| | | |
| | | @Transactional |
| | | public ReturnT<String> deletereadOutOrder(ExdOutstockSource exdInstockSource) { |
| | | String fbillno = exdInstockSource.getFbillno(); |
| | | Order order = orderService.selectByNo(fbillno); |
| | | if (!Cools.isEmpty(order)) { |
| | | if (order.getSettle() > 1L) { |
| | | throw new CoolException(fbillno + "单据正在作业中,无法删除"); |
| | | } |
| | | Mat mat = matService.selectBySku(exdInstockSource.getFitemid() + ""); |
| | | boolean delete = orderDetlService.delete(new EntityWrapper<OrderDetl>() |
| | | .eq("order_no", order.getOrderNo()) |
| | | .eq("matnr", mat.getMatnr()) |
| | | .eq("batch", exdInstockSource.getFbatchno()) |
| | | .eq("anfme", exdInstockSource.getFqty())); |
| | | if (delete) { |
| | | log.info("删除订单明细成功,订单号={},物料号={},批号={},数量={}成功",order.getOrderNo(),exdInstockSource.getFitemid(),exdInstockSource.getFbatchno(),exdInstockSource.getFqty()); |
| | | }else { |
| | | log.error("删除订单明细失败,订单号={},物料号={},批号={},数量={}",order.getOrderNo(),exdInstockSource.getFitemid(),exdInstockSource.getFbatchno(),exdInstockSource.getFqty()); |
| | | throw new CoolException(fbillno + "单据明细删除失败"); |
| | | } |
| | | int orderNo = orderDetlService.selectCount(new EntityWrapper<OrderDetl>().eq("order_no", order.getOrderNo())); |
| | | if(orderNo==0){ |
| | | orderService.remove(order.getId()); |
| | | log.info("删除订单主表成功,订单={}",order.getOrderNo()); |
| | | } |
| | | |
| | | |
| | | }else if (Cools.isEmpty(order)) { |
| | | throw new CoolException(fbillno + "单据未在WMS中找到"); |
| | | } |
| | | return SUCCESS; |
| | | } |
| | | |
| | | } |