GeneralService.java 5.25 KB
package com.huaheng.api.U8.service;

import com.huaheng.api.U8.domain.ICSInventoryModel;
import com.huaheng.api.U8.domain.ICSWarehouseModel;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.general.company.domain.WarehouseCompany;
import com.huaheng.pc.general.company.mapper.WarehouseCompanyMapperAuto;
import com.huaheng.pc.general.material.domain.Material;
import com.huaheng.pc.general.material.service.IMaterialService;
import com.huaheng.pc.system.dict.domain.DictData;
import com.huaheng.pc.system.dict.domain.DictType;
import com.huaheng.pc.system.dict.service.IDictDataService;
import com.huaheng.pc.system.dict.service.IDictTypeService;
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 GeneralService {

    @Autowired
    IDictTypeService dictTypeService;
    @Autowired
    IDictDataService dictDataService;
    @Autowired
    IMaterialService materialService;
    @Resource
    private WarehouseCompanyMapperAuto warehouseCompanyMapperAuto;

    @Transactional
    public AjaxResult ICSInventory(ICSInventoryModel iCSInventory)    {
        //先查询货主对应的仓库,有几个仓库,就循环几次来添加。
        WarehouseCompany warehouseCompany = new WarehouseCompany();
        warehouseCompany.setCompanyCode(iCSInventory.getCompanyCode());
        List<WarehouseCompany> list = warehouseCompanyMapperAuto.selectListEntityByEqual(warehouseCompany);
        for (WarehouseCompany item :list ) {
            int result = 0;
            //检查字典表是否存在物料类型编码,如果没有就添加
            DictData dictData = new DictData();
            dictData.setDictType("materialType");
            dictData.setWarehouseCode(item.getWarehouseCode());
            dictData.setDictValue(iCSInventory.getcInvStd());
            List<DictData> dictDatas = dictDataService.selectDictDataList(dictData);
            if (dictDatas.size() < 1)   {
                //找出字典头表的id
                DictType dictType = new DictType();
                dictType.setWarehouseCode(item.getWarehouseCode());
                dictType.setDictType("materialType");
                List<DictType> dictList = dictTypeService.selectDictTypeList(dictType);
                if (dictList.size() < 1)    {
                        throw   new ServiceException("字典表头没有  物料类型!");
                }
                //增新一条字典明细表的记录
                dictData.setHeaderId(dictList.get(0).getId());
                dictData.setWarehouseId(item.getWarehouseId());
                dictData.setDictLabel(iCSInventory.getcInvCName());
                dictData.setEnable(true);
                result = dictDataService.insertDictData(dictData);
                if (result < 1) {
                    throw   new ServiceException("新增物料类型失败!");
                }
            }
            // 检查是否存在物料,如果存在就修改,不存在就新增
            Material material = new Material();
            material.setCode(iCSInventory.getcInvCode());
            material.setWarehouseCode(item.getWarehouseCode());
            material = materialService.selectFirstEntity(material);
            if (material == null)   {
                material = new Material();
            }
            material.setCode(iCSInventory.getcInvCode());
            material.setBarcode(iCSInventory.getcInvCode());
            material.setName(iCSInventory.getcInvName());
            material.setUserDef1(iCSInventory.getcInvAddCode());
            material.setSpecification(iCSInventory.getcInvStd());
            material.setMasterUnit(iCSInventory.getcComUnitName());
            material.setAssistUnit(iCSInventory.getcAssComUnitCode());
            material.setConvertRate(iCSInventory.getfConvertRate());
            material.setType(iCSInventory.getcInvCCode());
            material.setCompanyId(item.getCompanyId());
            material.setCompanyCode(item.getCompanyCode());
            material.setWarehouseId(item.getWarehouseId());
            material.setWarehouseCode(item.getWarehouseCode());
            material.setLastUpdatedBy(ShiroUtils.getLoginName());
            material.setLastUpdated(new Date());

            if (material.getId() == null)       {
                material.setCreatedBy(ShiroUtils.getLoginName());
                material.setCreated(new Date());
                result = materialService.insert(material);
                if (result < 1) {
                    throw   new ServiceException("新增物料类型失败!");
                }
            }
            else      {
                result = materialService.updateByModel(material);
                if (result < 1) {
                    throw   new ServiceException("编辑物料类型失败!");
                }
            }
        }
        return AjaxResult.success("成功!");
    }

    public AjaxResult ICSWarehouse(ICSWarehouseModel iCSWarehouse)      {
        return AjaxResult.success("成功!");
    }

}