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
package com.iailab.module.device.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.iailab.framework.common.service.impl.BaseServiceImpl;
import com.iailab.framework.common.util.object.ConvertUtils;
import com.iailab.common.utils.DateUtils;
import com.iailab.module.device.dao.DeviceHealthReportDataDao;
import com.iailab.module.device.dto.DeviceHealthReportDataDTO;
import com.iailab.module.device.entity.DeviceHealthReportDataEntity;
import com.iailab.module.device.service.DeviceHealthReportDataService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;
 
/**
 * @author PanZhibao
 * @Description
 * @createTime 2024年06月28日
 */
@Slf4j
@Service
public class DeviceHealthReportDataServiceImpl extends BaseServiceImpl<DeviceHealthReportDataDao, DeviceHealthReportDataEntity>
        implements DeviceHealthReportDataService {
 
 
    @Override
    public List<DeviceHealthReportDataDTO> listByReportId(String reportId) {
        QueryWrapper<DeviceHealthReportDataEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("report_id", reportId)
                .orderByAsc("sort");
        List<DeviceHealthReportDataEntity> list = baseDao.selectList(wrapper);
        return ConvertUtils.sourceToTarget(list, DeviceHealthReportDataDTO.class);
    }
 
    @Override
    public void save(DeviceHealthReportDataDTO dto) {
        DeviceHealthReportDataEntity entity = ConvertUtils.sourceToTarget(dto, DeviceHealthReportDataEntity.class);
        entity.setId(UUID.randomUUID().toString());
        entity.setCreateDate(new Date());
        insert(entity);
    }
 
    @Override
    public void migrationDeviceHealthReportData(Map<String, Date> tMap) {
        List<DeviceHealthReportDataEntity> list = baseDao.selectList(getDateWrapper(tMap));
        if (CollectionUtils.isEmpty(list)){
            return;
        }
        baseDao.migration(list);
        baseDao.delete(getDateWrapper(tMap));
    }
 
    public QueryWrapper<DeviceHealthReportDataEntity> getDateWrapper(Map<String, Date> params) {
        String startDate = DateUtils.format(params.get("startdate"),DateUtils.DATE_TIME_PATTERN);
        String endDate = DateUtils.format(params.get("enddate"),DateUtils.DATE_TIME_PATTERN);
 
        QueryWrapper<DeviceHealthReportDataEntity> wrapper = new QueryWrapper<>();
        wrapper.ge(StringUtils.isNotBlank(startDate), "create_date", startDate);
        wrapper.le(StringUtils.isNotBlank(endDate), "create_date", endDate);
        return wrapper;
    }
}