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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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);
    }
}