houzhongjian
2024-07-23 a6de490948278991e47952e90671ddba4555e9a2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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);
    }
}