ZoneCapacityServiceImpl.java 2.31 KB
package com.huaheng.pc.config.zoneCapacity.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.common.utils.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.zoneCapacity.domain.ZoneCapacity;
import com.huaheng.pc.config.zoneCapacity.mapper.ZoneCapacityMapper;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ZoneCapacityServiceImpl extends ServiceImpl<ZoneCapacityMapper, ZoneCapacity> implements ZoneCapacityService {
   @Autowired
   private MaterialService materialService;

   //添加库区容量时,查找到该物料的具体信息,一并加入到库区容量中
    @Override
    public AjaxResult insertModel(ZoneCapacity zoneCapacity) {
        zoneCapacity.setWarehouseCode(ShiroUtils.getWarehouseCode());
        zoneCapacity.setCreatedBy(ShiroUtils.getLoginName());
        zoneCapacity.setLastUpdatedBy(ShiroUtils.getLoginName());
        if(StringUtils.isEmpty(zoneCapacity.getMaterialCode())){
            return AjaxResult.error("没有输入物料编码");
        }

        //查找该物料信息
        LambdaQueryWrapper<Material> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(StringUtils.isNotEmpty(zoneCapacity.getMaterialCode()),Material::getCode, zoneCapacity.getMaterialCode())
                .eq(StringUtils.isNotEmpty(zoneCapacity.getWarehouseCode()),Material::getWarehouseCode, zoneCapacity.getWarehouseCode());
        Material material=materialService.getOne(lambdaQueryWrapper);
        if(material==null){
            return AjaxResult.error("系统没有该物料");
        }
        zoneCapacity.setMaterialName(material.getName());
        zoneCapacity.setMaterialSpec(material.getSpec());
        zoneCapacity.setMaterialUnit(material.getUnit());
        if(!this.save(zoneCapacity)){
            return AjaxResult.error("新增库区容量失败");
        }
        return AjaxResult.success("新增库区容量成功");
    }
}