WarehouseAPIService.java 3.7 KB
package com.huaheng.api.U8.Service;

import com.huaheng.api.U8.domain.ICSWarehouseModel;
import com.huaheng.api.general.Controller.BasicDataApi;
import com.huaheng.api.general.service.BasicDataApiService;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.general.company.domain.Company;
import com.huaheng.pc.general.company.domain.WarehouseCompany;
import com.huaheng.pc.general.company.mapper.CompanyMapperAuto;
import com.huaheng.pc.general.company.mapper.WarehouseCompanyMapperAuto;
import com.huaheng.pc.general.company.service.ICompanyService;
import com.huaheng.pc.general.warehouse.domain.Warehouse;
import com.huaheng.pc.general.warehouse.service.IWarehouseService;
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;
import java.util.List;

@Service
public class WarehouseAPIService {

    @Autowired
    IWarehouseService iWarehouseService;

    @Autowired
    BasicDataApiService basicDataApiService;

    @Resource
    private ICompanyService companyService;

    @Transactional
    public AjaxResult ICSWarehouse(ICSWarehouseModel icsWarehouse) {
        Company company=new Company();
        company.setCode(icsWarehouse.getCompanyCode());
        company=companyService.selectFirstEntity(company);
        if(company==null || StringUtils.isEmpty(icsWarehouse.getCompanyCode())){
            return AjaxResult.error("没有该货主");
        }
        Warehouse warehouse = new Warehouse();
        warehouse.setCode(icsWarehouse.getcWhCode());
        warehouse.setName(icsWarehouse.getcWhName());
        warehouse.setCompanyId(company.getId());
        warehouse.setUserDef1(icsWarehouse.getFlag());
        warehouse.setCreatedBy(ShiroUtils.getLoginName());
        warehouse.setCreated(new Date());
        warehouse.setLastUpdatedBy(ShiroUtils.getLoginName());
        warehouse.setLastUpdated(new Date());
        return basicDataApiService.warehouse(warehouse);
    }
//        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("更新仓库档案成功!");
//                }
//            }
//        }
}