package com.supervision.police.service.impl; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.supervision.police.domain.ModelIndex; import com.supervision.police.domain.ModelIndexAtomicRelation; import com.supervision.police.dto.ModelIndexAtomicRelationDTO; import com.supervision.police.service.ModelIndexAtomicRelationService; import com.supervision.police.mapper.ModelIndexAtomicRelationMapper; import com.supervision.utils.JudgeLogicUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.Objects; /** * @author Administrator * @description 针对表【model_index_atomic_relation(指标与原子指标的关联关系)】的数据库操作Service实现 * @createDate 2024-08-07 10:52:56 */ @Slf4j @Service public class ModelIndexAtomicRelationServiceImpl extends ServiceImpl implements ModelIndexAtomicRelationService{ @Override public List listByAtomicIndexName(String atomicIndexName) { return super.baseMapper.listByAtomicIndexName(atomicIndexName); } @Override @Transactional(transactionManager = "dataSourceTransactionManager", rollbackFor = Exception.class) public void saveByModelIndex(ModelIndex modelIndex) { if (Objects.isNull(modelIndex.getId())){ log.warn("saveByModelIndex: modelIndexId 为空,不保存关联关系...."); return; } if (StrUtil.isEmpty(modelIndex.getId())){ log.warn("saveByModelIndex: modelIndexId 为空,不保存关联关系....modelIndex:{}", JSONUtil.toJsonStr(modelIndex)); return; } String judgeLogic = modelIndex.getJudgeLogic(); if (StrUtil.isEmpty(judgeLogic)){ log.info("saveByModelIndex: modelIndex judgeLogic 为空,不保存关联关系....modelIndex:{}", JSONUtil.toJsonStr(modelIndex)); return; } List atomicIndexIds = JudgeLogicUtil.pickAtomicIndexIds(judgeLogic); atomicIndexIds.forEach(atomicIndexId -> { ModelIndexAtomicRelation modelIndexAtomicRelation = new ModelIndexAtomicRelation(); modelIndexAtomicRelation.setModelIndexId(modelIndex.getId()); modelIndexAtomicRelation.setAtomicIndexId(atomicIndexId); super.save(modelIndexAtomicRelation); }); } @Override @Transactional(transactionManager = "dataSourceTransactionManager", rollbackFor = Exception.class) public void updateByModelIndex(ModelIndex modelIndex) { if (Objects.isNull(modelIndex.getId())){ log.warn("updateByModelIndex: modelIndexId 为空,不保存关联关系...."); return; } if (StrUtil.isEmpty(modelIndex.getId())){ log.warn("updateByModelIndex: modelIndexId 为空,不保存关联关系....modelIndex:{}", JSONUtil.toJsonStr(modelIndex)); return; } deleteByModelIndex(modelIndex.getId()); saveByModelIndex(modelIndex); } @Override public void deleteByModelIndex(String modelIndexId) { if (StrUtil.isEmpty(modelIndexId)){ log.warn("deleteModelIndex: modelIndexId 为空,不删除关联关系....modelIndexId:{}", modelIndexId); return; } super.remove(new LambdaQueryWrapper().eq(ModelIndexAtomicRelation::getModelIndexId, modelIndexId)); } }