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

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.api.general.domain.ContainerTypeDomain;
import com.huaheng.api.general.domain.InventoryQueryDomain;
import com.huaheng.api.general.domain.JindieUser;
import com.huaheng.api.general.service.BasicDataApiService;
import com.huaheng.common.utils.StringUtils;
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.framework.web.domain.RetCode;
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.supplier.domain.Supplier;
import com.huaheng.pc.config.warehouse.domain.Warehouse;
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 lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

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

    @Autowired
    private BasicDataApiService basicDataApiService;
    @Autowired
    MaterialService materialService;

    /**
     * 同步物料
     */
    @Log(title = "物料添加", action = BusinessType.INSERT)
    @PostMapping("/addMaterial")
    @ApiOperation("物料添加公共接口")
    @ResponseBody
    @ApiLogger(apiName = "添加物料", from="ERP")
    @Transactional
    public AjaxResult AddMaterialApi(@RequestBody List<Material> materials)
    {
//        materials.forEach((material -> {
//            AjaxResult ajaxResult = basicDataApiService.material(material);
//            if(ajaxResult.getCode()==RetCode.FAIL.getValue()){
//                throw new RuntimeException(ajaxResult.getMsg());
//            }
//        }));
        materials.forEach(material -> {
            Material material1 = materialService.getOne(new LambdaQueryWrapper<Material>().eq(Material::getCode, material.getCode()));
            if(StringUtils.isNotNull(material1)){
                material1.setName(material.getName());
                material1.setSpec(material.getSpec());
                material1.setType(material.getType());
                material1.setUnit(material.getUnit());
                materialService.updateById(material1);
            }else {
                materialService.save(material);
            }
        });
        return AjaxResult.success("物料同步成功");
    }


    @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("/customer")
    @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("/dept")
    @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("/user")
    @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("/supplier")
    @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("/jindieUserAdd")
    @ApiOperation("金蝶用户添加")
    @ResponseBody
    @ApiLogger(apiName = "金蝶用户添加", from="ERP")
    public AjaxResult jindieUserAdd(@RequestBody JindieUser jindieUser)
    {
        AjaxResult ajaxResult = basicDataApiService.jindieUserAdd(jindieUser);
        if (ajaxResult.getCode()==RetCode.FAIL.getValue()) {
            throw new RuntimeException(ajaxResult.getMsg());
        }
        return AjaxResult.success("人员同步成功");
    }

}