package com.iailab.module.device.service.impl;
|
|
import com.alibaba.nacos.client.naming.utils.CollectionUtils;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.iailab.framework.common.constant.Constant;
|
import com.iailab.common.enums.IsEnableEnum;
|
import com.iailab.framework.common.page.PageData;
|
import com.iailab.framework.common.service.impl.BaseServiceImpl;
|
import com.iailab.framework.common.util.object.ConvertUtils;
|
import com.iailab.module.device.dao.DeviceHealthEvaluateDao;
|
import com.iailab.module.device.dto.DeviceHealthEvaluateDTO;
|
import com.iailab.module.device.entity.DeviceHealthEvaluateEntity;
|
import com.iailab.module.device.service.DeviceEvaluateIndexService;
|
import com.iailab.module.device.service.DeviceHealthEvaluateService;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import javax.annotation.Resource;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.*;
|
|
/**
|
* @author PanZhibao
|
* @Description
|
* @createTime 2024年06月29日
|
*/
|
@Slf4j
|
@Service
|
public class DeviceHealthEvaluateServiceImpl extends BaseServiceImpl<DeviceHealthEvaluateDao, DeviceHealthEvaluateEntity>
|
implements DeviceHealthEvaluateService {
|
|
@Resource
|
private DeviceEvaluateIndexService deviceEvaluateIndexService;
|
|
@Override
|
public PageData<DeviceHealthEvaluateDTO> page(Map<String, Object> params) {
|
IPage<DeviceHealthEvaluateEntity> page = baseDao.selectPage(
|
getPage(params, Constant.CREATE_DATE, false),
|
getWrapper(params).orderByAsc("dev_name")
|
);
|
return getPageData(page, DeviceHealthEvaluateDTO.class);
|
}
|
|
@Override
|
public List<DeviceHealthEvaluateDTO> list(Map<String, Object> params) {
|
List<DeviceHealthEvaluateEntity> list = baseDao.selectList(getWrapper(params));
|
|
return ConvertUtils.sourceToTarget(list, DeviceHealthEvaluateDTO.class);
|
}
|
|
private QueryWrapper<DeviceHealthEvaluateEntity> getWrapper(Map<String, Object> params) {
|
String devId = (String) params.get("devId");
|
String devName = (String) params.get("devName");
|
String healthLevel = (String) params.get("healthLevel");
|
Integer isEnable = params.get("isEnable") == null ? null : Integer.parseInt(params.get("isEnable").toString());
|
QueryWrapper<DeviceHealthEvaluateEntity> wrapper = new QueryWrapper<>();
|
wrapper.eq(StringUtils.isNotBlank(devId), "dev_id", devId)
|
.eq(isEnable != null, "is_enable", isEnable)
|
.like(StringUtils.isNotBlank(devName), "dev_name", devName)
|
.eq(StringUtils.isNotBlank(healthLevel), "health_level", healthLevel);
|
return wrapper;
|
}
|
|
@Override
|
public DeviceHealthEvaluateDTO get(String id) {
|
DeviceHealthEvaluateEntity entity = baseDao.selectById(id);
|
DeviceHealthEvaluateDTO result = ConvertUtils.sourceToTarget(entity, DeviceHealthEvaluateDTO.class);
|
result.setIndexList(deviceEvaluateIndexService.listByEvaluateId(id));
|
return result;
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void save(DeviceHealthEvaluateDTO dto) {
|
DeviceHealthEvaluateEntity entity = ConvertUtils.sourceToTarget(dto, DeviceHealthEvaluateEntity.class);
|
entity.setId(UUID.randomUUID().toString());
|
entity.setCreateDate(new Date());
|
insert(entity);
|
deviceEvaluateIndexService.updateList(entity.getId(), dto.getIndexList());
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void update(DeviceHealthEvaluateDTO dto) {
|
DeviceHealthEvaluateEntity entity = ConvertUtils.sourceToTarget(dto, DeviceHealthEvaluateEntity.class);
|
entity.setUpdateDate(new Date());
|
updateById(entity);
|
deviceEvaluateIndexService.updateList(entity.getId(), dto.getIndexList());
|
}
|
|
@Override
|
public void updateReport(DeviceHealthEvaluateDTO dto) {
|
DeviceHealthEvaluateEntity entity = ConvertUtils.sourceToTarget(dto, DeviceHealthEvaluateEntity.class);
|
entity.setUpdateDate(new Date());
|
updateById(entity);
|
}
|
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void delete(String[] ids) {
|
baseDao.deleteBatchIds(Arrays.asList(ids));
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void enableByIds(String[] ids) {
|
if (CollectionUtils.isEmpty(Arrays.asList(ids))) {
|
return;
|
}
|
Arrays.asList(ids).forEach(item -> {
|
DeviceHealthEvaluateEntity entity = new DeviceHealthEvaluateEntity();
|
entity.setId(item);
|
entity.setIsEnable(IsEnableEnum.ENABLE.value());
|
baseDao.updateById(entity);
|
});
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void disableByIds(String[] ids) {
|
if (CollectionUtils.isEmpty(Arrays.asList(ids))) {
|
return;
|
}
|
Arrays.asList(ids).forEach(item -> {
|
DeviceHealthEvaluateEntity entity = new DeviceHealthEvaluateEntity();
|
entity.setId(item);
|
entity.setIsEnable(IsEnableEnum.DISABLE.value());
|
baseDao.updateById(entity);
|
});
|
}
|
|
@Override
|
public Long selectHealthLevalCount(String healthLeval) {
|
QueryWrapper<DeviceHealthEvaluateEntity> wrapper = new QueryWrapper<>();
|
wrapper.eq(StringUtils.isNotBlank(healthLeval),"health_level",healthLeval);
|
wrapper.eq("is_enable",1);
|
return baseDao.selectCount(wrapper);
|
}
|
}
|