zhangherong
9 天以前 42c6702c415ad4e2d6bbd07545820bf98292111e
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
package org.jeecg.modules.eam.service.impl;
 
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.enums.EnableDisableEnum;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.util.SimpleVersionGenerateUtil;
import org.jeecg.modules.eam.entity.EamBaseHFCode;
import org.jeecg.modules.eam.mapper.EamBaseHFCodeMapper;
import org.jeecg.modules.eam.service.IEamBaseHFCodeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.List;
 
/**
 * @Description: HFCode维护
 * @Author: jeecg-boot
 * @Date:   2025-07-05
 * @Version: V1.0
 */
@Service
public class EamBaseHFCodeServiceImpl extends ServiceImpl<EamBaseHFCodeMapper, EamBaseHFCode> implements IEamBaseHFCodeService {
 
    @Override
    public boolean checkDuplicate(String category, String id) {
        LambdaQueryWrapper<EamBaseHFCode> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EamBaseHFCode::getHfCategory, category);
        queryWrapper.eq(EamBaseHFCode::getDelFlag, CommonConstant.DEL_FLAG_0);
        queryWrapper.eq(EamBaseHFCode::getHfStatus, EnableDisableEnum.ENABLE.name());
        if(StringUtils.isNotBlank(id)) {
            queryWrapper.ne(EamBaseHFCode::getId, id);
        }
        List<EamBaseHFCode> list = super.getBaseMapper().selectList(queryWrapper);
        return CollectionUtil.isEmpty(list);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean addEamBaseHFCode(EamBaseHFCode entity) {
        if(!checkDuplicate(entity.getHfCategory(), null)) {
            throw new JeecgBootException("重复添加!");
        }
        entity.setHfVersion(SimpleVersionGenerateUtil.getInitVersion());
        entity.setDelFlag(CommonConstant.DEL_FLAG_0);
        entity.setHfStatus(EnableDisableEnum.ENABLE.name());
        super.getBaseMapper().insert(entity);
        return true;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean editEamBaseHFCode(EamBaseHFCode entity) {
        EamBaseHFCode eamBaseHFCode = this.getBaseMapper().selectById(entity.getId());
        if(eamBaseHFCode == null) {
            throw new JeecgBootException("要编辑的数据不存在!");
        }
        if(!checkDuplicate(entity.getHfCategory(), entity.getId())) {
            throw new JeecgBootException("重复添加!");
        }
        this.getBaseMapper().updateById(entity);
        return true;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean upgradeEamBaseHFCode(EamBaseHFCode entity) {
        EamBaseHFCode eamBaseHFCode = this.getBaseMapper().selectById(entity.getId());
        if(eamBaseHFCode == null) {
            throw new JeecgBootException("要升版的数据不存在!");
        }
        if(!checkDuplicate(entity.getHfCategory(), entity.getId())) {
            throw new JeecgBootException("重复添加!");
        }
        //禁用原来的HF编码
        eamBaseHFCode.setHfStatus(EnableDisableEnum.DISABLE.name());
        this.getBaseMapper().updateById(eamBaseHFCode);
        //新增一个新的版本
        entity.setId(null);
        entity.setCreateBy(null);
        entity.setCreateTime(null);
        entity.setDelFlag(CommonConstant.DEL_FLAG_0);
        entity.setHfVersion(SimpleVersionGenerateUtil.addVersion(entity.getHfVersion()));
        entity.setHfStatus(EnableDisableEnum.ENABLE.name());
        super.getBaseMapper().insert(entity);
        return true;
    }
 
    @Override
    public EamBaseHFCode selectByCategory(String category) {
        LambdaQueryWrapper<EamBaseHFCode> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EamBaseHFCode::getHfCategory, category);
        queryWrapper.eq(EamBaseHFCode::getDelFlag, CommonConstant.DEL_FLAG_0);
        queryWrapper.eq(EamBaseHFCode::getHfStatus, EnableDisableEnum.ENABLE.name());
        return this.getBaseMapper().selectOne(queryWrapper);
    }
}