package com.ruoyi.system.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.enums.DataScreenConfigEnum;
import com.ruoyi.common.utils.BeanUtils;
import com.ruoyi.system.domain.TbDataScreenConfig;
import com.ruoyi.system.dto.update.DataIndicatorsUpdDTO;
import com.ruoyi.system.dto.update.FormalIndicatorsUpdDTO;
import com.ruoyi.system.dto.update.RiskLevelUpdDTO;
import com.ruoyi.system.mapper.TbDataScreenConfigMapper;
import com.ruoyi.system.query.DataScreenConfigQuery;
import com.ruoyi.system.service.TbDataScreenConfigService;
import com.ruoyi.system.vo.DataScreenConfigVO;
import java.util.List;
import java.util.Objects;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
*
* 大屏数据配置表 服务实现类
*
*
* @author mitao
* @since 2024-03-13
*/
@Service
public class TbDataScreenConfigServiceImpl extends
ServiceImpl implements
TbDataScreenConfigService {
@Override
public DataScreenConfigVO getRiskLevel() {
TbDataScreenConfig tbDataScreenConfig = this.lambdaQuery()
.eq(TbDataScreenConfig::getType, DataScreenConfigEnum.RISK_LEVEL)
.one();
return Objects.nonNull(tbDataScreenConfig) ? BeanUtils.copyBean(tbDataScreenConfig,
DataScreenConfigVO.class) : new DataScreenConfigVO();
}
@Override
@Transactional(rollbackFor = Exception.class)
public DataScreenConfigVO editRiskLevel(RiskLevelUpdDTO dto) {
//查询是否有该指标配置
TbDataScreenConfig tbDataScreenConfig = this.lambdaQuery()
.eq(TbDataScreenConfig::getType, DataScreenConfigEnum.RISK_LEVEL)
.oneOpt().orElseGet(() -> BeanUtils.copyBean(dto,
TbDataScreenConfig.class));
tbDataScreenConfig.setType(DataScreenConfigEnum.RISK_LEVEL);
this.saveOrUpdate(tbDataScreenConfig);
return BeanUtils.copyBean(tbDataScreenConfig, DataScreenConfigVO.class);
}
@Override
public List getIndicatorsConfig(DataScreenConfigQuery query) {
List list = this.lambdaQuery()
.eq(TbDataScreenConfig::getType, query.getType()).list();
return BeanUtils.copyList(list, DataScreenConfigVO.class);
}
@Override
@Transactional(rollbackFor = Exception.class)
public DataScreenConfigVO editDataIndicatorsConfig(DataIndicatorsUpdDTO dto) {
//查询是否有该指标配置
TbDataScreenConfig tbDataScreenConfig = this.lambdaQuery()
.eq(TbDataScreenConfig::getType, DataScreenConfigEnum.DATA_INDICATORS)
.eq(TbDataScreenConfig::getSubType,
dto.getSubType()).oneOpt().orElseGet(() -> BeanUtils.copyBean(dto,
TbDataScreenConfig.class));
tbDataScreenConfig.setType(DataScreenConfigEnum.DATA_INDICATORS);
this.saveOrUpdate(tbDataScreenConfig);
return BeanUtils.copyBean(tbDataScreenConfig, DataScreenConfigVO.class);
}
@Override
@Transactional(rollbackFor = Exception.class)
public DataScreenConfigVO editFormalIndicatorsConfig(FormalIndicatorsUpdDTO dto) {
//查询是否有该指标配置
TbDataScreenConfig tbDataScreenConfig = this.lambdaQuery()
.eq(TbDataScreenConfig::getType, DataScreenConfigEnum.FORMAL_INDICATORS)
.eq(TbDataScreenConfig::getSubType,
dto.getSubType()).oneOpt().orElseGet(() -> BeanUtils.copyBean(dto,
TbDataScreenConfig.class));
tbDataScreenConfig.setType(DataScreenConfigEnum.FORMAL_INDICATORS);
this.saveOrUpdate(tbDataScreenConfig);
return BeanUtils.copyBean(tbDataScreenConfig, DataScreenConfigVO.class);
}
}