WarehouseApiService.java 4.31 KB
package com.huaheng.pc.u8.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.api.general.service.BasicDataApiService;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.Wrappers;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.company.domain.Company;
import com.huaheng.pc.config.company.domain.CompanyU8;
import com.huaheng.pc.config.company.service.CompanyU8Service;
import com.huaheng.pc.config.warehouse.domain.Warehouse;
import com.huaheng.pc.config.warehouse.domain.WarehouseU8;
import com.huaheng.pc.config.warehouse.service.WarehouseService;
import com.huaheng.pc.config.warehouse.service.WarehouseU8Service;
import com.huaheng.pc.u8.domain.ICSWarehouseModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class WarehouseApiService {

    @Autowired
    WarehouseU8Service warehouseU8Service;

    @Autowired
    BasicDataApiService basicDataApiService;

    @Resource
    private CompanyU8Service companyU8Service;
    @Resource
    private WarehouseService warehouseService;


    @Transactional
    public AjaxResult ICSWarehouse(ICSWarehouseModel icsWarehouse) {
        String warehouseCode = icsWarehouse.getWarehouseCode();
        if(StringUtils.isEmpty(warehouseCode)){
            return AjaxResult.error("warehouseCode不能为空");
        }
        Warehouse warehouse = warehouseService.getOne(new LambdaQueryWrapper<Warehouse>()
                .eq(Warehouse::getCode, warehouseCode));
        if(warehouse==null){
            return AjaxResult.error("warehouseCode:"+warehouseCode+" 仓库编码错误。");
        }
        // 查询货主
        CompanyU8 companyU8 = companyU8Service.getOne(new LambdaQueryWrapper<CompanyU8>()
                .eq(CompanyU8::getWarehouseCode, icsWarehouse.getWarehouseCode())
                .eq(CompanyU8::getUCompanyCode, icsWarehouse.getCompanyCode()));
        if(companyU8==null || StringUtils.isEmpty(icsWarehouse.getCompanyCode())){
            return AjaxResult.error("没有该货主");
        }
        WarehouseU8 warehouseU8 = new WarehouseU8();
        warehouseU8.setUCompanyCode(companyU8.getUCompanyCode());
        warehouseU8.setWarehouseCode(companyU8.getWarehouseCode());
        warehouseU8.setCompanyCode(companyU8.getCompanyCode());
        warehouseU8.setUWarehouseCode(icsWarehouse.getCWhCode());
        warehouseU8.setUWarehouseName(icsWarehouse.getCWhName());
        boolean save = warehouseU8Service.save(warehouseU8);
        return AjaxResult.toAjax(save);
    }
//        Warehouse warehouse = new Warehouse();
//        //查询货主有几个仓库,就新增几次
//        for (WarehouseCompany item : list) {
//            int result = 0;
//            //判断系统中是否有该仓库,若有则更新,若无则新增
//            if (iWarehouseService.selectFirstEntity(warehouse) == null) {
//                warehouse.setCode(icsWarehouse.getcWhCode());
//                warehouse.setName(icsWarehouse.getcWhName());
//                warehouse.setCompanyId(item.getCompanyId());
//                warehouse.setUserDef1(icsWarehouse.getFlag());
//                result = iWarehouseService.insert(warehouse);
//                if (result < 1) {
//                    return AjaxResult.success("新增仓库档案失败!");
//                } else {
//                    return AjaxResult.success("新增仓库档案成功!");
//                }
//            } else {
//                warehouse.setCode(icsWarehouse.getcWhCode());
//                warehouse.setName(icsWarehouse.getcWhName());
//                warehouse.setUserDef1(icsWarehouse.getFlag());
//                warehouse.setCompanyId(item.getCompanyId());
//                warehouse.setLastUpdated(new Date());
//                result = iWarehouseService.updateByModel(warehouse);
//                if (result < 1) {
//                    return AjaxResult.success("更新仓库档案失败!");
//                } else {
//                    return AjaxResult.success("更新仓库档案成功!");
//                }
//            }
//        }

}