package org.dromara.demo.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import lombok.RequiredArgsConstructor;
|
import org.dromara.common.core.utils.MapstructUtils;
|
import org.dromara.common.core.utils.StringUtils;
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
import org.dromara.demo.domain.RsIndicatorInfo;
|
import org.dromara.demo.domain.bo.RsIndicatorInfoBo;
|
import org.dromara.demo.domain.vo.RsIndicatorInfoVo;
|
import org.dromara.demo.mapper.RsIndicatorInfoMapper;
|
import org.dromara.demo.service.IRsIndicatorInfoService;
|
import org.springframework.stereotype.Service;
|
|
import java.util.*;
|
|
/**
|
* 指标取值Service业务层处理
|
*
|
* @author gonghl
|
* @date 2024-03-04
|
*/
|
@RequiredArgsConstructor
|
@Service
|
public class RsIndicatorInfoServiceImpl implements IRsIndicatorInfoService {
|
|
private final RsIndicatorInfoMapper baseMapper;
|
|
/**
|
* 查询指标取值
|
*/
|
@Override
|
public RsIndicatorInfoVo queryById(String id){
|
return baseMapper.selectVoById(id);
|
}
|
|
/**
|
* 查询指标取值列表
|
*/
|
@Override
|
public TableDataInfo<RsIndicatorInfoVo> queryPageList(RsIndicatorInfoBo bo, PageQuery pageQuery) {
|
LambdaQueryWrapper<RsIndicatorInfo> lqw = buildQueryWrapper(bo);
|
Page<RsIndicatorInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
return TableDataInfo.build(result);
|
}
|
|
/**
|
* 查询指标取值列表
|
*/
|
@Override
|
public List<RsIndicatorInfoVo> queryList(RsIndicatorInfoBo bo) {
|
LambdaQueryWrapper<RsIndicatorInfo> lqw = buildQueryWrapper(bo);
|
return baseMapper.selectVoList(lqw);
|
}
|
|
private LambdaQueryWrapper<RsIndicatorInfo> buildQueryWrapper(RsIndicatorInfoBo bo) {
|
Map<String, Object> params = bo.getParams();
|
LambdaQueryWrapper<RsIndicatorInfo> lqw = Wrappers.lambdaQuery();
|
lqw.like(StringUtils.isNotBlank(bo.getIndicatorName()), RsIndicatorInfo::getIndicatorName, bo.getIndicatorName());
|
lqw.eq(bo.getCreateTime() != null, RsIndicatorInfo::getCreateTime, bo.getCreateTime());
|
lqw.eq(bo.getStatus() != null, RsIndicatorInfo::getStatus, bo.getStatus());
|
lqw.orderByDesc(RsIndicatorInfo::getCreateTime);
|
return lqw;
|
}
|
|
/**
|
* 新增指标取值
|
*/
|
@Override
|
public Boolean insertByBo(RsIndicatorInfoBo bo) {
|
RsIndicatorInfo add = MapstructUtils.convert(bo, RsIndicatorInfo.class);
|
validEntityBeforeSave(add);
|
boolean flag = baseMapper.insert(add) > 0;
|
if (flag) {
|
bo.setId(add.getId());
|
}
|
return flag;
|
}
|
|
/**
|
* 修改指标取值
|
*/
|
@Override
|
public Boolean updateByBo(RsIndicatorInfoBo bo) {
|
RsIndicatorInfo update = MapstructUtils.convert(bo, RsIndicatorInfo.class);
|
return baseMapper.updateById(update) > 0;
|
}
|
|
/**
|
* 保存前的数据校验
|
*/
|
private void validEntityBeforeSave(RsIndicatorInfo entity){
|
entity.setCreateTime(new Date());
|
}
|
|
/**
|
* 批量删除指标取值
|
*/
|
@Override
|
public Boolean deleteWithValidByIds(Collection<String> ids, Boolean isValid) {
|
if(isValid){
|
//TODO 做一些业务上的校验,判断是否需要校验
|
}
|
return baseMapper.deleteBatchIds(ids) > 0;
|
}
|
|
@Override
|
public Map<String, Long> status() {
|
List<RsIndicatorInfo> list = baseMapper.selectList(new LambdaQueryWrapper<RsIndicatorInfo>().orderByDesc(RsIndicatorInfo::getCreateTime));
|
Map<String, Long> map = new HashMap<>();
|
for (RsIndicatorInfo info : list) {
|
map.put(info.getIndicatorKey(), info.getStatus());
|
}
|
return map;
|
}
|
}
|