吴健
2024-11-27 fb3b3e41804abeeb4a54d9df3030bc3cdb75c245
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package com.billion.main.bs.service.impl;
 
import java.util.Date;
import java.util.List;
 
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.billion.common.core.domain.entity.SysUser;
import com.billion.common.core.domain.model.LoginUser;
import com.billion.common.exception.ServiceException;
import com.billion.common.utils.DateUtils;
import com.billion.common.utils.SecurityUtils;
import com.billion.main.bs.domain.BsFormulaInfo;
import com.billion.main.bs.mapper.BsFormulaInfoMapper;
import com.billion.main.bs.service.IBsFormulaInfoService;
import com.billion.main.common.BaseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
/**
 * 配方配置Service业务层处理
 * 
 * @author Billion
 * @date 2024-11-26
 */
@Service
public class BsFormulaInfoServiceImpl extends ServiceImpl<BsFormulaInfoMapper, BsFormulaInfo> implements IBsFormulaInfoService
{
    @Autowired
    private BsFormulaInfoMapper bsFormulaInfoMapper;
 
    /**
     * 查询配方配置
     * 
     * @param id 配方配置主键
     * @return 配方配置
     */
    @Override
    public BsFormulaInfo selectBsFormulaInfoById(Long id)
    {
        return bsFormulaInfoMapper.selectBsFormulaInfoById(id);
    }
 
    /**
     * 查询配方配置列表
     * 
     * @param bsFormulaInfo 配方配置
     * @return 配方配置
     */
    @Override
    public List<BsFormulaInfo> selectBsFormulaInfoList(BsFormulaInfo bsFormulaInfo)
    {
        return bsFormulaInfoMapper.selectBsFormulaInfoList(bsFormulaInfo);
    }
 
    /**
     * 新增配方配置
     * 
     * @param bsFormulaInfo 配方配置
     * @return 结果
     */
    @Override
    public int insertBsFormulaInfo(BsFormulaInfo bsFormulaInfo)
    {
        List<BsFormulaInfo> check = this.list(new LambdaQueryWrapper<BsFormulaInfo>().eq(BsFormulaInfo::getFormulaCode, bsFormulaInfo.getFormulaCode()));
        if (CollUtil.isNotEmpty(check)){
            throw new ServiceException("已存在此配方编码");
        }
        List<BsFormulaInfo> check1 = this.list(new LambdaQueryWrapper<BsFormulaInfo>().eq(BsFormulaInfo::getProductCode, bsFormulaInfo.getProductCode()));
        if (CollUtil.isNotEmpty(check1)){
            throw new ServiceException("已存在此产品编码");
        }
        bsFormulaInfo.setCreateTime(DateUtils.getNowDate());
        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysUser user = loginUser.getUser();
        bsFormulaInfo.setCreateTime(new Date());
        bsFormulaInfo.setUpdateTime(new Date());
        bsFormulaInfo.setCreateBy(user.getUserName());
        bsFormulaInfo.setUpdateBy(user.getUserName());
        return bsFormulaInfoMapper.insertBsFormulaInfo(bsFormulaInfo);
    }
 
    /**
     * 修改配方配置
     * 
     * @param bsFormulaInfo 配方配置
     * @return 结果
     */
    @Override
    public int updateBsFormulaInfo(BsFormulaInfo bsFormulaInfo)
    {
        List<BsFormulaInfo> check = this.list(new LambdaQueryWrapper<BsFormulaInfo>().eq(BsFormulaInfo::getFormulaCode, bsFormulaInfo.getFormulaCode())
                .notIn(BaseEntity::getId,bsFormulaInfo.getId()));
        if (CollUtil.isNotEmpty(check)){
            throw new ServiceException("已存在此配方编码");
        }
        List<BsFormulaInfo> check1 = this.list(new LambdaQueryWrapper<BsFormulaInfo>().eq(BsFormulaInfo::getProductCode, bsFormulaInfo.getProductCode())
                .notIn(BaseEntity::getId,bsFormulaInfo.getId()));
        if (CollUtil.isNotEmpty(check1)){
            throw new ServiceException("已存在此产品编码");
        }
        bsFormulaInfo.setUpdateTime(DateUtils.getNowDate());
        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysUser user = loginUser.getUser();
        bsFormulaInfo.setUpdateBy(user.getUserName());
        return bsFormulaInfoMapper.updateBsFormulaInfo(bsFormulaInfo);
    }
 
    /**
     * 批量删除配方配置
     * 
     * @param ids 需要删除的配方配置主键
     * @return 结果
     */
    @Override
    public int deleteBsFormulaInfoByIds(Long[] ids)
    {
        return bsFormulaInfoMapper.deleteBsFormulaInfoByIds(ids);
    }
 
    /**
     * 删除配方配置信息
     * 
     * @param id 配方配置主键
     * @return 结果
     */
    @Override
    public int deleteBsFormulaInfoById(Long id)
    {
        return bsFormulaInfoMapper.deleteBsFormulaInfoById(id);
    }
}