BasicDataApiController.java 13.6 KB
package com.huaheng.api.general.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.huaheng.common.utils.Wrappers;
import com.huaheng.api.general.domain.BarCodeDomain;
import com.huaheng.api.general.domain.ContainerTypeDomain;
import com.huaheng.api.general.domain.InventoryQueryDomain;
import com.huaheng.api.general.service.BarCodeApiService;
import com.huaheng.api.general.service.BasicDataApiService;
import com.huaheng.common.utils.security.ShiroUtils;
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.barcode.barcodeDetail.domain.BarCodeDetail;
import com.huaheng.pc.barcode.barcodeHeader.domain.BarCodeHeader;
import com.huaheng.pc.config.containerCapacity.domain.ContainerCapacity;
import com.huaheng.pc.config.containerType.domain.ContainerType;
import com.huaheng.pc.config.customer.domain.Customer;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import com.huaheng.pc.config.materialMultiple.domain.MaterialMultiple;
import com.huaheng.pc.config.materialMultiple.service.MaterialMultipleServiceImpl;
import com.huaheng.pc.config.materialUnit.domain.MaterialUnit;
import com.huaheng.pc.config.materialUnit.service.MaterialUnitService;
import com.huaheng.pc.config.supplier.domain.Supplier;
import com.huaheng.pc.config.warehouse.domain.Warehouse;
import com.huaheng.pc.config.zone.domain.Zone;
import com.huaheng.pc.inventory.InventoryMaterialSummary.domain.InventoryMaterialSummary;
import com.huaheng.pc.inventory.InventoryMaterialSummary.service.InventoryMaterialSummaryService;
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryHeader.domain.InventoryHeader;
import com.huaheng.pc.system.dept.domain.Dept;
import com.huaheng.pc.system.dict.domain.DictData;
import com.huaheng.pc.system.user.domain.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

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

@RestController
@RequestMapping("/api/basicData")
@Api(tags = {"基础数据接口"}, value = "基础数据接口basicData")
public class BasicDataApiController extends BaseController {

    @Autowired
    private BasicDataApiService basicDataApiService;
    @Resource
    private MaterialMultipleServiceImpl materialMultipleService;
    @Resource
    private MaterialService materialService;
    @Resource
    private InventoryMaterialSummaryService inventoryMaterialSummaryService;
    @Resource
    private BarCodeApiService barCodeApiService;

    /**
     * 同步物料
     */
    @Log(title = "物料添加", action = BusinessType.INSERT)
    @PostMapping("/addMaterial")
    @ApiOperation("物料添加公共接口")
    @ResponseBody
    @ApiLogger(apiName = "添加物料", from="ERP")
    public AjaxResult AddMaterialApi(@RequestBody Material material)
    {
        AjaxResult ajaxResult = basicDataApiService.material(material);
        return ajaxResult;
    }


    @Log(title = "物料查询", action = BusinessType.INSERT)
    @PostMapping("/queryMaterial")
    @ApiOperation("物料查询公共接口")
    @ResponseBody
    @ApiLogger(apiName = "查询物料", from="ERP")
    public AjaxResult QueryMaterialApi(@RequestBody Material material)
    {
        AjaxResult ajaxResult = basicDataApiService.queryMaterial(material);
        return ajaxResult;
    }

    @Log(title = "库存查询", action = BusinessType.INSERT)
    @PostMapping("/queryInventory")
    @ApiOperation("库存查询公共接口")
    @ResponseBody
    @ApiLogger(apiName = "查询物料", from="ERP")
    public AjaxResult QueryInventoryApi(@RequestBody InventoryQueryDomain inventoryQueryDomain)
    {
//        AjaxResult ajaxResult = basicDataApiService.queryMaterial(material);
        return null;
    }

    /**
     * 同步字典
     */
    @Log(title = "字典添加", action = BusinessType.INSERT)
    @PostMapping("/dictData")
    @ApiOperation("字典添加公共接口")
    @ResponseBody
    @ApiLogger(apiName = "添加字典", from="ERP")
    public AjaxResult UnitlApi(@RequestBody DictData dictData)
    {
        AjaxResult ajaxResult = basicDataApiService.dict(dictData);
        return ajaxResult;
    }


    /**
     * 同步仓库和货主
     */
    @Log(title = "仓库添加", action = BusinessType.INSERT)
    @PostMapping("/addWarehouse")
    @ApiOperation("仓库添加公共接口")
    @ResponseBody
    @ApiLogger(apiName = "添加仓库", from="ERP")
    public AjaxResult WarehouseApi(@RequestBody Warehouse warehouse)
    {
        AjaxResult ajaxResult = basicDataApiService.warehouse(warehouse);
        return ajaxResult;
    }

    /**
     * 同步客户档案
     */
    @Log(title = "客户档案添加", action = BusinessType.INSERT)
    @PostMapping("/addCustomer")
    @ApiOperation("客户档案添加公共接口")
    @ResponseBody
    @ApiLogger(apiName = "添加客户", from="ERP")
    public AjaxResult CustomerApi(@RequestBody Customer customer)
    {
        AjaxResult ajaxResult = basicDataApiService.customer(customer);
        return ajaxResult;
    }

    /**
     * 同步部门档案
     */
    @Log(title = "部门档案添加", action = BusinessType.INSERT)
    @PostMapping("/addDepart")
    @ApiOperation("部门档案添加公共接口")
    @ResponseBody
    @ApiLogger(apiName = "添加部门", from="ERP")
    public AjaxResult DeptApi(@RequestBody Dept dept)
    {
        AjaxResult ajaxResult = basicDataApiService.dept(dept);
        return ajaxResult;
    }

    /**
     * 同步人员档案
     */
    @Log(title = "人员档案添加", action = BusinessType.INSERT)
    @PostMapping("/addUser")
    @ApiOperation("人员档案添加公共接口")
    @ResponseBody
    @ApiLogger(apiName = "添加人员", from="ERP")
    public AjaxResult UserApi(@RequestBody User user)
    {
        AjaxResult ajaxResult = basicDataApiService.user(user);
        return ajaxResult;
    }


    @Log(title = "用户同步", action = BusinessType.INSERT)
    @PostMapping("/queryUserApi")
    @ApiOperation("用户查询公共接口")
    @ResponseBody
    @ApiLogger(apiName = "查询用户", from="ERP")
    public AjaxResult queryUserApi(@RequestBody User user)
    {
        AjaxResult ajaxResult = basicDataApiService.queryUser(user);
        return ajaxResult;
    }

    /**
     * 同步容器容量
     */
    @Log(title = "容器容量添加", action = BusinessType.INSERT)
    @PostMapping("/containerCapacity")
    @ApiOperation("容器容量添加公共接口")
    @ResponseBody
    @ApiLogger(apiName = "添加容器容量", from="ERP")
    public AjaxResult containerCapacityApi(@RequestBody ContainerCapacity containerCapacity){
        AjaxResult ajaxResult = basicDataApiService.containerCapacity(containerCapacity);
        return ajaxResult;
    }

    /**
     * 同步容器类型
     */
    @Log(title = "同步容器类型", action = BusinessType.INSERT)
    @PostMapping("/containerType")
    @ApiOperation("同步容器类型")
    @ResponseBody
    @ApiLogger(apiName = "同步容器类型", from="ERP")
    public AjaxResult containerTypeApi(@RequestBody ContainerTypeDomain containerTypeDomain){
        AjaxResult ajaxResult = basicDataApiService.containerType(containerTypeDomain);
        return ajaxResult;
    }

    /**
     * 同步供应商档案
     */
    @Log(title = "供应商档案添加", action = BusinessType.INSERT)
    @PostMapping("/addSupplier")
    @ApiOperation("供应商档案添加公共接口")
    @ResponseBody
    @ApiLogger(apiName = "添加供应商", from="ERP")
    public AjaxResult SupplierApi(@RequestBody Supplier supplier){
        AjaxResult ajaxResult = basicDataApiService.supplier(supplier);
        return ajaxResult;
    }



    @Log(title = "库存同步", action = BusinessType.INSERT)
    @PostMapping("/queryInventoryApi")
    @ApiOperation("库存查询公共接口")
    @ResponseBody
    @ApiLogger(apiName = "查询库存", from="ERP")
    public AjaxResult queryInventoryApi(@RequestBody InventoryDetail inventoryDetail)
    {
        AjaxResult ajaxResult = basicDataApiService.queryInventoryApi(inventoryDetail);
        return ajaxResult;
    }


    @Log(title = "计算单位换算", action = BusinessType.INSERT)
    @PostMapping("/addMaterialMultiple")
    @ApiOperation("计算单位换算接口")
    @ResponseBody
    @ApiLogger(apiName = "计算单位换算接口", from="ERP")
    public AjaxResult addMaterialMultiple(@RequestBody MaterialMultiple materialMultiple)
    {
        LambdaQueryWrapper<Material> lam = Wrappers.lambdaQuery();
        lam.eq(Material::getCode,materialMultiple.getMaterialCode())
                .eq(Material::getWarehouseCode,materialMultiple.getWarehouseCode());
        Material material = materialService.getOne(lam);
        if(material ==null){
            return AjaxResult.error("物料编码错误,系统没有此物料");
        }
        //todo:胡海-- 物料单位是否存在需要判断  只有系统有维护的单位才可以进行换算
        LambdaQueryWrapper<MaterialMultiple> lambda = Wrappers.lambdaQuery();
        lambda.eq(MaterialMultiple::getCompanyCode,materialMultiple.getCompanyCode())
                .eq(MaterialMultiple::getMaterialCode, materialMultiple)
                .eq(MaterialMultiple::getWarehouseCode, materialMultiple.getWarehouseCode())
                .eq(MaterialMultiple::getUnitId1, materialMultiple.getUnitId1())
                .eq(MaterialMultiple::getUnitId2, materialMultiple.getUnitId2());
        if (!materialMultipleService.list(lambda).isEmpty()){
            return AjaxResult.error("该信息已存在");
        }
        materialMultiple.setMaterialName(material.getName());
        materialMultiple.setMaterialSpec(material.getSpec());
        materialMultiple.setWarehouseCode(materialMultiple.getWarehouseCode());
        materialMultiple.setCreatedBy("ERP");
        materialMultiple.setLastUpdatedBy("ERP");
        materialMultiple.setCompanyCode(materialMultiple.getCompanyCode());
        materialMultiple.setUnitId1(materialMultiple.getUnitId1());
        materialMultiple.setUnitId2(materialMultiple.getUnitId2());
        materialMultiple.setMaterialSpec(materialMultiple.getMaterialSpec());
        return toAjax(materialMultipleService.save(materialMultiple));
    }


    @Log(title = "包装成品信息入库", action = BusinessType.INSERT)
    @PostMapping("/addBarCode")
    @ApiOperation("MES下发成品入库接口")
    @ResponseBody
    @ApiLogger(apiName = "MES下发成品入库接口", from="MES")
    public AjaxResult addBarCode(@RequestBody BarCodeDomain barCodeDomain)
    {
        BarCodeHeader barCodeHeader = barCodeDomain.getBarCodeHeader();
        List<BarCodeDetail> barCodeDetails = barCodeDomain.getBarCodeDetails();

        if(barCodeHeader == null) {
            return AjaxResult.error("包装信息入库,包装信息头为空");
        }
        if(barCodeDetails == null || barCodeDetails.size() <= 0) {
            return AjaxResult.error("包装信息入库,包装信息明细为空");
        }

        AjaxResult ajaxResult = handleMultiProcess(new MultiProcessListener() {
            @Override
            public AjaxResult doProcess() {
                AjaxResult ajaxResult = barCodeApiService.addBarCodeApi(barCodeDomain);
                return ajaxResult;
            }
        });
        return ajaxResult;
    }


    /**
     * 查询库存
     */
    @PostMapping("/searchInventory")
    @ApiOperation("查询库存")
    @ResponseBody
    @ApiLogger(apiName = "查询库存", from = "MES")
    public AjaxResult searchInventory(@RequestBody InventoryMaterialSummary inventoryMaterialSummary) {
        LambdaQueryWrapper<InventoryMaterialSummary> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper
                .eq(StringUtils.isNotEmpty(inventoryMaterialSummary.getWarehouseCode()),
                        InventoryMaterialSummary::getWarehouseCode, inventoryMaterialSummary.getWarehouseCode())
                //物料编码
                .eq(StringUtils.isNotEmpty(inventoryMaterialSummary.getMaterialCode()),
                        InventoryMaterialSummary::getMaterialCode, inventoryMaterialSummary.getMaterialCode())
                //物料名称
                .eq(StringUtils.isNotEmpty(inventoryMaterialSummary.getMaterialName()),
                        InventoryMaterialSummary::getMaterialName, inventoryMaterialSummary.getMaterialName())
                .eq(StringUtils.isNotEmpty(inventoryMaterialSummary.getZoneCode()),
                        InventoryMaterialSummary::getZoneCode, inventoryMaterialSummary.getZoneCode())
                .eq(InventoryMaterialSummary::getTaskQty, 0)
                //货主
                .eq(!StringUtils.isEmpty(inventoryMaterialSummary.getCompanyCode()),
                        InventoryMaterialSummary::getCompanyCode, inventoryMaterialSummary.getCompanyCode());
        List<InventoryMaterialSummary> list = inventoryMaterialSummaryService.list(lambdaQueryWrapper);
        if (list == null) {
            list = Collections.emptyList();
        }
        //筛选库存汇总数据的专用方法
        List<InventoryMaterialSummary> details = inventoryMaterialSummaryService.duplicateRemoval(list);
        return AjaxResult.success(details);
    }
}