CreateShipment.java 4.63 KB
package com.huaheng.api.mts;


import com.huaheng.framework.aspectj.lang.annotation.ApiLogger;
import com.huaheng.framework.aspectj.lang.annotation.Log;
import com.huaheng.framework.aspectj.lang.constant.BusinessType;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.inventory.inventoryHeader.service.InventoryHeaderService;
import com.huaheng.pc.shipment.lockingWorkOrder.domain.LockingWorkOrder;
import com.huaheng.pc.shipment.lockingWorkOrder.service.LockingWorkOrderService;
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
import com.huaheng.pc.shipment.shipmentDetail.service.ShipmentDetailService;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/API/MMS/create_shipment")
@Api(tags = {"mms"}, description = "mms接口")
public class CreateShipment extends BaseController {
    private static final Logger logger = LoggerFactory.getLogger(CreateShipment.class);

    @Resource
    private ShipmentDetailService shipmentDetailService;
    @Resource
    private ShipmentHeaderService shipmentHeaderService;
    @Resource
    private LockingWorkOrderService lockingWorkOrderService;
    @Resource
    private InventoryHeaderService inventoryHeaderService;

    @Log(title = "mms创建备料出库单", action = BusinessType.INSERT)
    @PostMapping("/createPreparationShipment")
    @ApiOperation("mms创建出库单")
    @ResponseBody
    @ApiLogger(apiName = "mms创建手持出库单", from = "mms")
    public AjaxResult createPreparationShipment(@RequestBody List<LockingWorkOrder> list)
    {
        logger.info("MMS发送数据:{}", list);
        if (list.isEmpty()){
            return AjaxResult.error("请勿传送空数据!");
        }
        // 创建出库单头表
        ShipmentHeader header = null;
        List<ShipmentDetail> details = new ArrayList<>();
        for (LockingWorkOrder temp : list){
//            LockingWorkOrder lockingWorkOrder = lockingWorkOrderService.selectEntitysById(temp );
//            if (lockingWorkOrder == null){
//                return AjaxResult.error("该"+temp.getId()+"数据未锁定工作令、请先锁定工作令在创建出库单!");
//            }
//            if (StringUtils.isEmpty(lockingWorkOrder.getWorkOrder()) ||
//                StringUtils.isEmpty(lockingWorkOrder.getBomCode()) ||
//                StringUtils.isEmpty(lockingWorkOrder.getInventoryId())){
//                return AjaxResult.error("物料编码:"+lockingWorkOrder.getBomCode()+"、工作令:"+lockingWorkOrder.getWorkOrder()+"、库存id:"+lockingWorkOrder.getInventoryId()+"不能为空值!");
//            }
//            Inventory inventory = iInventoryService.selectEntityById(Integer.valueOf(lockingWorkOrder.getInventoryId()));
//            if (inventory == null){
//                return AjaxResult.error("查询不到绑定的库存!");
//            }
//            BigDecimal lockingNum = lockingWorkOrder.getLockingNum();
//            BigDecimal qty = inventory.getQty().subtract(inventory.getTaskQty());
//            // 判断库存数量是否大于锁定数量
//            if (qty.compareTo(lockingNum) >= 0){
                // 判断头表是否存在不存在创建
                if (header == null){
                    header = shipmentHeaderService.createShipmentHeader(temp);
                }
                // 创建出库单详情
                try {
                    ShipmentDetail detail = shipmentDetailService.createShipmentDetail(header, temp);
                    if (detail != null){
                        details.add(detail);
                    }
                }catch (Exception e){
                    logger.error(e.getMessage());
                    return AjaxResult.error(e.getMessage());
                }

//           // }else {
//                logger.error("库存数量:"+qty+"小于锁定数量:"+lockingNum+",无法创建出库单!");
//                return AjaxResult.error("库存数量:"+qty+"小于锁定数量:"+lockingNum+",无法创建出库单!");
//            }
        }
        if (details != null){
            details.forEach(item->{
                shipmentDetailService.save(item);
            });
        }
        return AjaxResult.success("创建成功!");
    }


}