yangys
2025-11-21 e8ed1a91c77ab62a924f12acd55777f227bacd7e
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 org.springframework.stereotype.Service;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
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.common.constant.CommonConstant;
import com.qianwen.smartman.common.utils.Lambda;
import com.qianwen.smartman.common.utils.MessageUtils;
import com.qianwen.smartman.modules.smis.convert.StockOutTypeConvert;
import com.qianwen.smartman.modules.smis.entity.StockOutType;
import com.qianwen.smartman.modules.smis.mapper.StockOutTypeMapper;
import com.qianwen.smartman.modules.smis.service.IStockOutTypeService;
import com.qianwen.smartman.modules.smis.utils.ThrowFun;
import com.qianwen.smartman.modules.smis.vo.StockOutTypeVO;
 
@Service
public class StockOutTypeServiceImpl extends BladeServiceImpl<StockOutTypeMapper, StockOutType> implements IStockOutTypeService {
    
 
    
    public StockOutType createStockOutType(StockOutTypeVO vo) {
        validTheSame(null, vo.getCode(), vo.getName());
        StockOutType stockOutType = StockOutTypeConvert.INSTANCE.convert(vo);
        save(stockOutType);
        return stockOutType;
    }
 
    
    public IPage<StockOutTypeVO> pageStockOutType(Query query, String key, Integer status) {
        IPage<StockOutType> page = page(Condition.getPage(query), Wrappers.<StockOutType>lambdaQuery()
                .eq(StockOutType::getStatus, status)
                .and(Func.isNotBlank(key), c -> c.likeRight(StockOutType::getCode, key).or().likeRight(Func.isNotBlank(key), StockOutType::getName, key))
                
                .orderByDesc(StockOutType::getCreateTime));
        /*
        IPage<StockOutType> page = page(Condition.getPage(query), (Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getStatus();
        }, status)).and(Func.isNotBlank(key), c -> {
            ((LambdaQueryWrapper) ((LambdaQueryWrapper) c.likeRight((v0) -> {
                return v0.getCode();
            }, key)).or()).likeRight(Func.isNotBlank(key), (v0) -> {
                return v0.getName();
            }, key);
        }).orderByDesc((v0) -> {
            return v0.getCreateTime();
        }));*/
        return StockOutTypeConvert.INSTANCE.convert(page);
    }
 
    private void validTheSame(Long id, String code, String name) {
        long codeCount = count(Lambda.eq(StockOutType::getCode, code)
                .eq(StockOutType::getStatus, CommonConstant.ENABLE)
                .ne(Func.isNotEmpty(id), StockOutType::getId, id));
        
        ThrowFun.isTrue(codeCount > 0).throwMessage(MessageUtils.message("cps.stock.out.type.code.already.exists", new Object[0]));
        //FIXME 这里不应该是enable吧
        long codeCountDisable = count(Lambda.eq(StockOutType::getCode, code)
                .eq(StockOutType::getStatus, CommonConstant.ENABLE)
                .ne(Func.isNotEmpty(id), StockOutType::getId, id));
        
        ThrowFun.isTrue(codeCountDisable > 0).throwMessage(MessageUtils.message("cps.stock.out.type.code.unable.already.exists", new Object[0]));
        long nameCount = count(Lambda.eq(StockOutType::getName, name)
                .ne(Func.isNotEmpty(id), StockOutType::getId, id));
       
        ThrowFun.isTrue(nameCount > 0).throwMessage(MessageUtils.message("cps.stock.out.type.name.already.exists", new Object[0]));
        long nameCountDisable = count(Lambda.eq(StockOutType::getName, name)
                .ne(Func.isNotEmpty(id), StockOutType::getId, id));
        
        ThrowFun.isTrue(nameCountDisable > 0).throwMessage(MessageUtils.message("cps.stock.out.type.name.unable.already.exists", new Object[0]));
    }
 
    
    public StockOutTypeVO updateStockOut(StockOutTypeVO vo) {
        validTheSame(vo.getId(), vo.getCode(), vo.getName());
        StockOutType stockOutType = StockOutTypeConvert.INSTANCE.convert(vo);
        updateById(stockOutType);
        return StockOutTypeConvert.INSTANCE.convert(stockOutType);
    }
}