BomHeaderServiceImpl.java 2.24 KB
package com.huaheng.pc.config.bom.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.pc.config.bom.domain.BomHeader;
import com.huaheng.pc.config.bom.mapper.BomHeaderMapper;

import javax.annotation.Resource;

import static com.huaheng.framework.web.domain.AjaxResult.toAjax;

@Service
public class BomHeaderServiceImpl extends ServiceImpl<BomHeaderMapper, BomHeader> implements BomHeaderService{

    @Resource
    private MaterialService materialService;

    @Override
    public AjaxResult dataValidation(BomHeader bomHeader) {
        LambdaQueryWrapper<Material> lamdba = Wrappers.lambdaQuery();
        lamdba.eq(Material::getCode, bomHeader.getMaterialCode());
        Material material = materialService.getOne(lamdba);
        if ( material == null){
            return AjaxResult.error("不存在物料编码"+bomHeader.getMaterialCode());
        } else {
            bomHeader.setCompanyCode(material.getCompanyCode());
            bomHeader.setWarehouseCode(material.getWarehouseCode());
            bomHeader.setMaterialCode(material.getCode());
            bomHeader.setMaterialName(material.getName());
            bomHeader.setMaterialSpec(material.getSpec());
            bomHeader.setMaterialUnit(material.getUnit());
            bomHeader.setCreatedBy(ShiroUtils.getLoginName());
            bomHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
        }
        LambdaQueryWrapper<BomHeader> query = Wrappers.lambdaQuery();
        query.eq(BomHeader::getMaterialCode, bomHeader.getMaterialCode()).
                eq(BomHeader::getCompanyCode, bomHeader.getCompanyCode()).
                eq(BomHeader::getWarehouseCode, bomHeader.getWarehouseCode());
        if (this.getOne(query) != null){
            return AjaxResult.error("数据已存在请勿重复添加!");
        }
        return toAjax(this.save(bomHeader));
    }
}