yangys
2024-10-30 c27b939fa5fa6ce4d712f7e9ced2ad811d69d5ec
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package com.qianwen.smartman.modules.smis.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import java.lang.invoke.SerializedLambda;
import com.qianwen.smartman.common.constant.CommonConstant;
import com.qianwen.smartman.common.utils.MessageUtils;
import com.qianwen.core.mp.service.impl.BladeServiceImpl;
import com.qianwen.core.mp.support.Condition;
import com.qianwen.core.mp.support.Query;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.modules.smis.convert.StockInTypeConvert;
import com.qianwen.smartman.modules.smis.entity.StockInType;
import com.qianwen.smartman.modules.smis.mapper.StockInTypeMapper;
import com.qianwen.smartman.modules.smis.service.IStockInTypeService;
import com.qianwen.smartman.modules.smis.utils.ThrowFun;
import com.qianwen.smartman.modules.smis.vo.StockInTypeVO;
import org.springframework.stereotype.Service;
 
@Service
public class StockInTypeServiceImpl extends BladeServiceImpl<StockInTypeMapper, StockInType> implements IStockInTypeService {
    
 
    
    public StockInType createStockInType(StockInTypeVO vo) {
        validTheSame(null, vo.getCode(), vo.getName());
        StockInType stockInType = StockInTypeConvert.INSTANCE.convert(vo);
        save(stockInType);
        return stockInType;
    }
 
    private void validTheSame(Long id, String code, String name) {
        long codeCount = count(Wrappers.lambdaQuery(StockInType.class)
                .eq(Func.isNotBlank(code), StockInType::getCode, code)
                .eq(StockInType::getStatus, CommonConstant.ENABLE)
                .ne(Func.isNotEmpty(id), StockInType::getId, id));
        /*
        long codeCount = count(((LambdaQueryWrapper) Wrappers.lambdaQuery(StockInType.class).eq(Func.isNotBlank(code), (v0) -> {
            return v0.getCode();
        }, code).eq((v0) -> {
            return v0.getStatus();
        }, CommonConstant.ENABLE)).ne(Func.isNotEmpty(id), (v0) -> {
            return v0.getId();
        }, id));*/
        ThrowFun.isTrue(codeCount > 0).throwMessage(MessageUtils.message("cps.stock.in.type.code.already.exists", new Object[0]));
        long codeCountDisable = count(Wrappers.lambdaQuery(StockInType.class)
                .eq(Func.isNotBlank(code), StockInType::getCode, code)
                        .eq(StockInType::getStatus, CommonConstant.DEACTIVATE).ne(Func.isNotEmpty(id), StockInType::getId, id));
        ThrowFun.isTrue(codeCountDisable > 0).throwMessage(MessageUtils.message("cps.stock.in.type.code.unable.already.exists", new Object[0]));
        long nameCount = count(Wrappers.lambdaQuery(StockInType.class).eq(Func.isNotBlank(name), (v0) -> {
            return v0.getName();
        }, name).eq((v0) -> {
            return v0.getStatus();
        }, CommonConstant.ENABLE).ne(Func.isNotEmpty(id), (v0) -> {
            return v0.getId();
        }, id));
        ThrowFun.isTrue(nameCount > 0).throwMessage(MessageUtils.message("cps.stock.in.type.name.already.exists", new Object[0]));
        long nameCountDisable = count(Wrappers.lambdaQuery(StockInType.class)
                .eq(Func.isNotBlank(name),StockInType::getName, name)
                .eq(StockInType::getStatus, CommonConstant.DEACTIVATE)
                .ne(Func.isNotEmpty(id), StockInType::getId, id));
        ThrowFun.isTrue(nameCountDisable > 0).throwMessage(MessageUtils.message("cps.stock.in.type.name.unable.already.exists", new Object[0]));
    }
 
    
    public IPage<StockInTypeVO> pageStockInType(Query query, String key, Integer status) {
        IPage<StockInType> page = page(Condition.getPage(query), Wrappers.<StockInType>lambdaQuery().eq(StockInType::getStatus, status)
                .and(Func.isNotBlank(key), c -> {
            c.likeRight(StockInType::getCode, key).or().likeRight(Func.isNotBlank(key), StockInType::getName, key);
        }).orderByDesc(StockInType::getCreateTime));
        return StockInTypeConvert.INSTANCE.convert(page);
    }
 
    
    public StockInTypeVO updateStockIn(StockInTypeVO vo) {
        Long id = vo.getId();
        validTheSame(id, vo.getCode(), vo.getName());
        StockInType stockInType = StockInTypeConvert.INSTANCE.convert(vo);
        updateById(stockInType);
        return StockInTypeConvert.INSTANCE.convert(stockInType);
    }
}