| | |
| | | package zy.cloud.wms.manager.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.*; |
| | | import com.core.common.Cools; |
| | | import com.core.common.R; |
| | | import com.core.common.SnowflakeIdWorker; |
| | | import com.core.exception.CoolException; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import zy.cloud.wms.common.config.CodeCoolException; |
| | | import zy.cloud.wms.common.model.BillDto; |
| | | import zy.cloud.wms.common.model.MatnrDto; |
| | | import zy.cloud.wms.common.model.OrderStoDto; |
| | | import zy.cloud.wms.common.service.MainService; |
| | | import zy.cloud.wms.common.service.asrs.AsrsService; |
| | | import zy.cloud.wms.common.service.asrs.entity.Result1; |
| | | import zy.cloud.wms.common.service.erp.ErpService; |
| | | import zy.cloud.wms.common.utils.VersionUtils; |
| | | import zy.cloud.wms.manager.entity.*; |
| | |
| | | /** |
| | | * Created by vincent on 2021/2/25 |
| | | */ |
| | | @Slf4j |
| | | @Service("workService") |
| | | public class WorkServiceImpl implements WorkService { |
| | | |
| | |
| | | @Autowired |
| | | private MatService matService; |
| | | @Autowired |
| | | private AsrsService asrsService; |
| | | @Autowired |
| | | private ErpService erpService; |
| | | @Autowired |
| | | private CheckService checkService; |
| | | @Autowired |
| | | private OrderService orderService; |
| | | @Autowired |
| | | private OrderDetlService orderDetlService; |
| | | @Autowired |
| | | private ItemService itemService; |
| | | @Autowired |
| | | private CstmrService cstmrService; |
| | | |
| | | @Override |
| | | @Transactional |
| | |
| | | @Override |
| | | @Transactional |
| | | public R initOrder(InitOrderParam param, Long userId) { |
| | | if (custOrderService.selectCount(new EntityWrapper<CustOrder>().eq("number", param.getNumber()).ne("bType_id", param.getCustomerTypeId())) > 0) { |
| | | Order order = orderService.selectByOrderNo(param.getOrderNo()); |
| | | if (order != null) { |
| | | return R.error("抱歉单号已存在,请修改单号"); |
| | | } |
| | | Date now = new Date(); |
| | | for (PakinMatDto dto : param.getList()){ |
| | | Item item = itemService.selectByName(param.getItem()); |
| | | Cstmr cstmr = cstmrService.selectByName(param.getCstmr()); |
| | | // 新增订单表头 |
| | | order = new Order( |
| | | String.valueOf(snowflakeIdWorker.nextId()), // 编号[非空] |
| | | param.getOrderNo(), // 订单编号 |
| | | param.getOrderTime(), // 单据日期 |
| | | param.getDocType(), // 单据类型 |
| | | item==null?null:item.getId(), // 项目编号 |
| | | param.getItem(), // 项目名称 |
| | | null, // 调拨项目编号 |
| | | null, // 初始票据号 |
| | | null, // 票据号 |
| | | cstmr==null?null:cstmr.getId(), // 客户编号 |
| | | param.getCstmr(), // 客户 |
| | | null, // 联系方式 |
| | | null, // 操作人员 |
| | | null, // 合计金额 |
| | | null, // 优惠率 |
| | | null, // 优惠金额 |
| | | null, // 销售或采购费用合计 |
| | | null, // 实付金额 |
| | | null, // 付款类型 |
| | | null, // 业务员 |
| | | null, // 结算天数 |
| | | null, // 邮费支付类型 |
| | | null, // 邮费 |
| | | null, // 付款时间 |
| | | null, // 发货时间 |
| | | null, // 物流名称 |
| | | null, // 物流单号 |
| | | null, // 订单状态 |
| | | 1, // 状态 |
| | | userId, // 添加人员 |
| | | now, // 添加时间 |
| | | userId, // 修改人员 |
| | | now, // 修改时间 |
| | | null // 备注 |
| | | ); |
| | | if (!orderService.insert(order)) { |
| | | throw new CoolException("保存订单表头失败!"); |
| | | } |
| | | // 遍历商品数量并保存 |
| | | for (MatnrDto dto : param.getList()){ |
| | | Mat mat = matService.selectByMatnr(dto.getMatnr()); |
| | | if (mat == null) { |
| | | log.error("{}商品不存在。", dto.getMatnr()); |
| | | continue; |
| | | } |
| | | CustOrder custOrder = new CustOrder( |
| | | param.getNumber(), // 销售单号 |
| | | DateUtils.convert(now), // 单据日期[非空] |
| | | param.getCustomerTypeId(), // 客户编号 |
| | | null, // 经手人编号[空] |
| | | null, |
| | | dto.getMatnr(), // 商品编号 |
| | | dto.getCount(), // 商品数量 |
| | | dto.getCount(), // 总数量 |
| | | Cools.isEmpty(mat.getName())?0.0D:Double.parseDouble(mat.getName()), // 商品单价 |
| | | null, // 商品明细行号 |
| | | null, // 商品备注[空] |
| | | 1, // 状态 |
| | | now, // 添加时间 |
| | | now, // 修改时间 |
| | | null // 备注 |
| | | ); |
| | | if (!custOrderService.insert(custOrder)) { |
| | | throw new CoolException("保存销售订单失败"); |
| | | OrderDetl orderDetl = new OrderDetl(); |
| | | orderDetl.setOrderId(order.getId()); // 订单内码 |
| | | orderDetl.setAnfme(dto.getCount()); // 数量 |
| | | orderDetl.setCreateBy(userId); |
| | | orderDetl.setCreateTime(now); |
| | | orderDetl.setUpdateBy(userId); |
| | | orderDetl.setUpdateTime(now); |
| | | orderDetl.setStatus(1); |
| | | VersionUtils.setOrderDetl(orderDetl, mat); |
| | | if (!orderDetlService.insert(orderDetl)) { |
| | | throw new CoolException("保存订单明细失败"); |
| | | } |
| | | } |
| | | return R.ok("生成销售订单" + param.getNumber() + "成功"); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public R stockTransfer(String number, Long userId) { |
| | | List<CustOrder> custOrders = custOrderService.selectList(new EntityWrapper<CustOrder>().eq("number", number).eq("status", 1)); |
| | | boolean asrs = false; |
| | | List<StockTransferParam> params = new ArrayList<>(); |
| | | for (CustOrder custOrder : custOrders) { |
| | | Double count = locDetlService.selectCountByMatnr(custOrder.getUserCode()); |
| | | if (count == null) { |
| | | count = 0.0D; |
| | | } |
| | | if (count < custOrder.getQty()) { |
| | | if (!asrs) { asrs = true; } |
| | | StockTransferParam param = new StockTransferParam(); |
| | | param.setMatnr(custOrder.getUserCode()); |
| | | param.setAnfme(custOrder.getQty() - count); |
| | | params.add(param); |
| | | } |
| | | } |
| | | if (asrs) { |
| | | // if (asrsService.stockTransfer(params)) { |
| | | // for (StockTransferParam param : params) { |
| | | // // 修改销售订单待出数量 |
| | | // if (!custOrderService.updateQty(number, param.getMatnr(), param.getAnfme())) { |
| | | // throw new CoolException("修改销售订单待出数量失败"); |
| | | // } |
| | | // } |
| | | // return R.ok("库存调拨成功"); |
| | | // } else { |
| | | // return R.error("立库调拨失败,请联系管理员"); |
| | | // } |
| | | } |
| | | return R.error("暂不缺货,不需要立库调拨"); |
| | | } |
| | | |
| | | @Override |
| | | public R asrsStockTransfer(AsrsTransferParam param, Long userId) { |
| | | if (Cools.isEmpty(param.getNode_id(), param.getMatnr(), param.getSafe_qua(), param.getAmount())) { |
| | | return R.error("数量错误"); |
| | | } |
| | | List<StockTransferParam> params = new ArrayList<>(); |
| | | StockTransferParam transferParam = new StockTransferParam(); |
| | | transferParam.setMatnr(param.getMatnr()); |
| | | transferParam.setAnfme(Arith.subtract(2, param.getSafe_qua(), param.getAmount())); |
| | | transferParam.setAllotNo(param.getNode_id()+ "_" +param.getMatnr()); |
| | | params.add(transferParam); |
| | | Result1 result = asrsService.stockTransfer(params); |
| | | if (result.getCode() == 500) { |
| | | if (Cools.isEmpty(result.getData())) { |
| | | throw new CoolException(result.getMsg()); |
| | | } else { |
| | | throw new CodeCoolException("20001-" + result.getData()); |
| | | } |
| | | } |
| | | return R.ok("补仓成功,等待立库调拨"); |
| | | return R.ok("创建订单成功"); |
| | | } |
| | | |
| | | @Override |