package com.iailab.module.device.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.iailab.framework.common.service.impl.CrudServiceImpl;
|
import com.iailab.framework.common.util.object.ConvertUtils;
|
import com.iailab.module.device.commons.HealthLevelEnum;
|
import com.iailab.module.device.dao.DeviceStatCountDao;
|
import com.iailab.module.device.dto.DeviceStatCountDTO;
|
import com.iailab.module.device.entity.DeviceStatCountEntity;
|
import com.iailab.module.device.service.DeviceStatCountService;
|
import com.iailab.module.device.service.DeviceHealthEvaluateService;
|
import org.apache.commons.lang3.StringUtils;
|
import javax.annotation.Resource;
|
import org.springframework.stereotype.Service;
|
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 设备健康状态表
|
*
|
* @author lirm ${email}
|
* @since 1.0.0 2024-05-22
|
*/
|
@Service
|
public class DeviceStatCountServiceImpl extends CrudServiceImpl<DeviceStatCountDao, DeviceStatCountEntity, DeviceStatCountDTO> implements DeviceStatCountService {
|
|
@Resource
|
DeviceHealthEvaluateService deviceHealthEvaluateService;
|
|
public QueryWrapper<DeviceStatCountEntity> getWrapper(Map<String, Object> params){
|
String startTime = (String)params.get("startTime");
|
String endTime = (String)params.get("endTime");
|
|
QueryWrapper<DeviceStatCountEntity> wrapper = new QueryWrapper<>();
|
wrapper.ge(StringUtils.isNotBlank(startTime), "date", startTime);
|
wrapper.le(StringUtils.isNotBlank(endTime), "date", endTime);
|
wrapper.orderByDesc("create_date");
|
|
return wrapper;
|
}
|
|
@Override
|
public DeviceStatCountDTO getDeviceStatCount() {
|
DeviceStatCountDTO result = new DeviceStatCountDTO();
|
//健康设备数量
|
Long healthyNum = deviceHealthEvaluateService.selectHealthLevalCount(HealthLevelEnum.Level1.getCode());
|
result.setHealthCount(healthyNum);
|
//良好设备数量
|
Long goodNum = deviceHealthEvaluateService.selectHealthLevalCount(HealthLevelEnum.Level2.getCode());
|
result.setGoodCount(goodNum);
|
//故障设备数量
|
Long accidentNum = deviceHealthEvaluateService.selectHealthLevalCount(HealthLevelEnum.Level3.getCode());
|
result.setAccidentCount(accidentNum);
|
//总设备数量
|
Long totalNum = deviceHealthEvaluateService.selectHealthLevalCount(null);
|
result.setTotalCount(totalNum);
|
return result;
|
}
|
|
@Override
|
public List<DeviceStatCountDTO> getHistory(Map<String, Object> params) {
|
List<DeviceStatCountEntity> list = baseDao.selectList(getWrapper(params));
|
return ConvertUtils.sourceToTarget(list,DeviceStatCountDTO.class);
|
}
|
}
|