ShippingCombinationController.java 6.1 KB
package com.huaheng.pc.shipment.shippingCombination.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.page.TableDataInfo;
import com.huaheng.pc.config.material.service.MaterialServiceImpl;
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
import com.huaheng.pc.shipment.shipmentContainerDetail.service.ShipmentContainerDetailService;
import com.huaheng.pc.shipment.shipmentContainerHeader.domain.ShipmentCombinationModel;
import com.huaheng.pc.shipment.shipmentContainerHeader.domain.ShipmentContainerHeader;
import com.huaheng.pc.shipment.shipmentContainerHeader.service.ShipmentContainerHeaderService;
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
import com.huaheng.pc.shipment.shipmentDetail.service.ShipmentDetailServiceImpl;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
import com.huaheng.pc.shipment.shippingCombination.service.ShippingCombinationService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/shipment/shippingCombination")
public class ShippingCombinationController extends BaseController {

    private String prefix = "shipment/shippingCombination";

    @Autowired
    MaterialServiceImpl materialService;
    @Autowired
    ShipmentDetailServiceImpl shipmentDetailService;
    @Autowired
    ShippingCombinationService shippingCombinationService;
    @Autowired
    ShipmentContainerHeaderService shipmentContainerHeaderService;
    @Autowired
    ShipmentContainerDetailService shipmentContainerDetailService;
    @Autowired
    ShipmentHeaderService shipmentHeaderService;
    @Autowired
    InventoryDetailService inventoryDetailService;


    /**
     *  打开出库组盘页面
     * @param shipmentCode
     * @param map
     * @return
     */
    @RequiresPermissions("shipment:shippingCombination:view")
    @GetMapping()
    public String ShippingCombination(String shipmentCode, ModelMap map){
        map.put("code", shipmentCode);
        return prefix+"/shippingCombination";
    }

    /**
     * 获取单据列表
     * @param code
     * @return
     */
    @GetMapping("/listShipmentDetail")
    @ResponseBody
    public AjaxResult listShipmentDetail(String code){
        if(StringUtils.isEmpty(code)){
            return null;
        }
        LambdaQueryWrapper<ShipmentDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(ShipmentDetail::getShipmentCode,code)
                .in(ShipmentDetail::getCompanyCode,ShiroUtils.getCompanyCodeList())
                .eq(ShipmentDetail::getWarehouseCode,ShiroUtils.getWarehouseCode());
        List<ShipmentDetail> shipmentDetails =shipmentDetailService.list(lambdaQueryWrapper) ;
        return AjaxResult.success(shipmentDetails);
    }


    /**
     * 获取能出库的库存列表
     * @param code,id
     * @return
     */
    @PostMapping("/getInventory")
    @ResponseBody
    public TableDataInfo getInventory(String code, Integer id){
        //找到主单的账套和u8仓库
        LambdaQueryWrapper<ShipmentHeader> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(ShipmentHeader::getCode,code)
                .eq(ShipmentHeader::getWarehouseCode,ShiroUtils.getWarehouseCode());
        ShipmentHeader shipmentHeader=shipmentHeaderService.getOne(lambdaQueryWrapper);
        if(shipmentHeader==null){
            throw new ServiceException("找不到主单");
        }
        //找到子单物料
        ShipmentDetail shipmentDetail=new ShipmentDetail();
        shipmentDetail=shipmentDetailService.getById(id);
        if(shipmentDetail==null){
            throw new ServiceException("找不到子单");
        }
        LambdaQueryWrapper<InventoryDetail> lam = Wrappers.lambdaQuery();
        lam.eq(InventoryDetail::getWarehouseCode,shipmentHeader.getWarehouseCode())
                .eq(InventoryDetail::getCompanyCode,shipmentHeader.getCompanyCode())
                .eq(InventoryDetail::getMaterialName,shipmentDetail.getMaterialCode());

        List<InventoryDetail> list= inventoryDetailService.list(lam);
        return getDataTable(list);
    }


    /**
     * 保存组盘
     * @param shipmentCombinationModel
     * @return
     */
    @RequiresPermissions("shipment:shippingCombination:combination")
    @PostMapping("/Addcombination")
    @ResponseBody
    public AjaxResult Addcombination(ShipmentCombinationModel shipmentCombinationModel){
        ShipmentContainerHeader shipmentContainerHeader= shipmentContainerHeaderService.combination(shipmentCombinationModel);
        return  AjaxResult.success(shipmentContainerHeader.getId());
    }

    /**
     * 自动组盘
     * @param shipmentCode
     * @return
     */
    @RequiresPermissions("shipment:shippingCombination:combination")
    @PostMapping("/autoCombination")
    @ResponseBody
    public AjaxResult autoCombination(String shipmentCode){
        AjaxResult ajaxResult = shipmentContainerHeaderService.autoCombination(shipmentCode);
        return ajaxResult;
    }



    /** 取消组盘
     *
     * @param shipmentContainerDetailIds
     * @return
     */
    @RequiresPermissions("shipment:shippingCombination:remove")
    @PostMapping("/cancelCombination")
    @ResponseBody
    public AjaxResult cancelCombination(@RequestBody List<Integer> shipmentContainerDetailIds){
        return shipmentContainerHeaderService.cancelCombinationDetail(shipmentContainerDetailIds);
    }


}