MaterialMultipleServiceImpl.java
2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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;
@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, String 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 {
Double multiple = this.getOne(lambda).getMultiple();
return String.valueOf(Double.parseDouble(value)*multiple);
} catch (NullPointerException e){
log.info("查询不到物料编码:"+materialCode+",单位:"+unit1+", "+unit2+"的转换系数");
} catch (Exception e){
log.info("查询不到物料编码:"+materialCode+",单位:"+unit1+", "+unit2+"的转换系数出错");
}
return "";
}
}