MaterialMultipleServiceImpl.java 2.1 KB
package com.huaheng.pc.config.materialMultiple.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.pc.config.materialMultiple.domain.MaterialMultiple;
import com.huaheng.pc.config.materialMultiple.mapper.MaterialMultipleMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
public class MaterialMultipleServiceImpl extends ServiceImpl<MaterialMultipleMapper, MaterialMultiple> implements IService<MaterialMultiple> {

    private static final Logger log = LoggerFactory.getLogger(MaterialMultipleServiceImpl.class);

    /**
     * 单位转换
     * @param materialCode 物料编码
     * @param unit1 单位1
     * @param unit2 单位2
     * @param value 转换值
     * @return 转换后的值,异常返回""
     */
    public String multiple(String materialCode, String unit1, String unit2, BigDecimal value){
        LambdaQueryWrapper<MaterialMultiple> lambda = Wrappers.lambdaQuery();
        lambda.select(MaterialMultiple::getMultiple)
                .eq(MaterialMultiple::getMaterialCode, materialCode)
                .eq(MaterialMultiple::getUnitId1, unit1)
                .eq(MaterialMultiple::getUnitId2, unit2)
                .eq(MaterialMultiple::getEnable, 1)
                .eq(MaterialMultiple::getWarehouseCode, ShiroUtils.getWarehouseCode());
        try {
            BigDecimal multiple = this.getOne(lambda).getMultiple();
            return String.valueOf(value.subtract(multiple));
        } catch (NullPointerException e){
           log.info("查询不到物料编码:"+materialCode+",单位:"+unit1+", "+unit2+"的转换系数");
        } catch (Exception e){
            log.info("查询不到物料编码:"+materialCode+",单位:"+unit1+", "+unit2+"的转换系数出错");
        }

        return "";
    }
}