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 implements IEamBaseHFCodeService { @Override public boolean checkDuplicate(String category, String id) { LambdaQueryWrapper 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 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 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); } }