| | |
| | | package com.zy.asrs.wms.asrs.service.impl;
|
| | |
|
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
| | | import com.zy.asrs.framework.common.Cools;
|
| | | import com.zy.asrs.framework.exception.CoolException;
|
| | | import com.zy.asrs.wms.asrs.entity.*;
|
| | | import com.zy.asrs.wms.asrs.entity.dto.OrderInfoDto;
|
| | | import com.zy.asrs.wms.asrs.entity.enums.OrderSettleType;
|
| | | import com.zy.asrs.wms.asrs.entity.enums.OrderType;
|
| | | import com.zy.asrs.wms.asrs.entity.param.CreateOrderParam;
|
| | | import com.zy.asrs.wms.asrs.entity.param.UpdateOrderParam;
|
| | | import com.zy.asrs.wms.asrs.mapper.OrderMapper;
|
| | |
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.Collections;
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.*;
|
| | |
|
| | | @Service("orderService")
|
| | | public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
|
| | |
| | | private OrderNoRuleService orderNoRuleService;
|
| | | @Autowired
|
| | | private OrderUtils orderUtils;
|
| | | @Autowired
|
| | | private WaitPakinService waitPakinService;
|
| | | @Autowired
|
| | | private LocDetlService locDetlService;
|
| | |
|
| | | @Override
|
| | | @Transactional
|
| | | public boolean createOrder(List<CreateOrderParam> list) {
|
| | | public boolean createOrder(List<CreateOrderParam> list, Long userId) {
|
| | | for (CreateOrderParam orderParam : list) {
|
| | | createOrder(orderParam);
|
| | | createOrder(orderParam, userId);
|
| | | }
|
| | | return true;
|
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional
|
| | | public boolean createOrder(CreateOrderParam param) {
|
| | | public boolean createOrder(CreateOrderParam param, Long userId) {
|
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
| | |
|
| | | List<Order> orderList = this.list(new LambdaQueryWrapper<Order>().eq(Order::getOrderNo, param.getOrderNo()));
|
| | |
| | | Order order = new Order();
|
| | | order.setOrderNo(orderNo);
|
| | | order.setOrderType(param.getOrderType());
|
| | | order.setCustomer(param.getCustomer());
|
| | | order.setPhone(param.getPhone());
|
| | | order.setAddress(param.getAddress());
|
| | | order.setOrderSettle(OrderSettleType.INIT.val());
|
| | | order.setIoPri(orderUtils.getIoPri());
|
| | | order.setOrderTime(format.format(new Date()));
|
| | | order.setCreateTime(new Date());
|
| | | order.setCreateBy(9527L);
|
| | | order.setCreateBy(userId);
|
| | | order.setUpdateBy(userId);
|
| | | boolean result = this.save(order);
|
| | | if (!result) {
|
| | | throw new CoolException("生成订单失败");
|
| | | }
|
| | |
|
| | | for (HashMap<String, Object> map : param.getList()) {
|
| | | double anfme = Double.parseDouble(map.get("anfme").toString());
|
| | | Double anfme = Double.parseDouble(map.get("anfme").toString());
|
| | | String batch = map.get("batch").toString();
|
| | | String matnr = map.get("matnr").toString();
|
| | | Double qty = 0D;
|
| | |
| | | if (map.containsKey("workQty")) {
|
| | | workQty = Double.parseDouble(map.get("workQty").toString());
|
| | | }
|
| | |
|
| | | if (param.getOrderType() == 2) {
|
| | | List<LocDetl> detls = locDetlService.list(new LambdaQueryWrapper<LocDetl>()
|
| | | .eq(StringUtils.isNotBlank(batch), LocDetl::getBatch, batch)
|
| | | .eq(StringUtils.isNotBlank(matnr), LocDetl::getMatnr, matnr));
|
| | | if (detls.isEmpty()) {
|
| | | throw new CoolException("物料:" + matnr + "剩余库存余下:0" + ",无法生成出库单!!");
|
| | | }
|
| | | Double sum = detls.stream().mapToDouble(LocDetl::getAnfme).sum();
|
| | | if (anfme.compareTo(sum) > 0) {
|
| | | throw new CoolException("物料:" + matnr + "剩余库存余下:" + sum + ",无法生成出库单!!");
|
| | | }
|
| | | }
|
| | |
|
| | | String memo = map.getOrDefault("memo", "").toString();
|
| | | Mat mat = matService.getOne(new LambdaQueryWrapper<Mat>().eq(Mat::getMatnr, matnr));
|
| | | if (mat == null) {
|
| | |
| | | orderDetl.setMatId(mat.getId());
|
| | | orderDetl.setMemo(memo);
|
| | | orderDetl.setCreateTime(new Date());
|
| | | orderDetl.setCreateBy(9527L);
|
| | | orderDetl.setCreateBy(userId);
|
| | | orderDetl.setUpdateBy(userId);
|
| | | boolean save = orderDetlService.save(orderDetl);
|
| | | if (!save) {
|
| | | throw new CoolException("订单明细创建失败");
|
| | |
| | | throw new CoolException("更新明细索引失败");
|
| | | }
|
| | |
|
| | | mat.setUtiliz(Objects.isNull(mat.getUtiliz()) ? 0 : mat.getUtiliz() + 1);
|
| | |
|
| | | if (!matService.updateById(mat)) {
|
| | | throw new CoolException("物料使用率修改失败!!");
|
| | | }
|
| | | }
|
| | |
|
| | | return true;
|
| | |
| | | throw new CoolException("订单已经生成波次,删除失败");
|
| | | }
|
| | |
|
| | | List<WaitPakin> waitPakins = waitPakinService.list(new LambdaQueryWrapper<WaitPakin>().eq(WaitPakin::getOrderId, orderId));
|
| | | if (!waitPakins.isEmpty()) {
|
| | | throw new CoolException("单据已生成组托,不可执行删除操作!!");
|
| | | }
|
| | | //删除订单
|
| | | this.removeById(orderId);
|
| | | //删除明细
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | public List<OrderInfoDto> getDetlForOrderId(Long id) {
|
| | | return this.baseMapper.getDetlForOrderId(id);
|
| | | public List<OrderInfoDto> getDetlForOrderId(Long id, String matnr) {
|
| | | if (!Objects.isNull(matnr)) {
|
| | | if (Objects.isNull(matnr)) {
|
| | | return this.baseMapper.getDetlForOrderId(id, null);
|
| | | } else {
|
| | | return this.baseMapper.getDetlForOrderId(id, matnr);
|
| | | }
|
| | | } else {
|
| | | return this.baseMapper.getDetlForOrderId(id, null);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 提交完结订单
|
| | | * @param id
|
| | | * @return
|
| | | */
|
| | | @Override
|
| | | public Order doneOrder(Long id) {
|
| | | return null;
|
| | | }
|
| | | }
|