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 implements DeviceHealthReportDataService { @Override public List listByReportId(String reportId) { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("report_id", reportId) .orderByAsc("sort"); List 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 tMap) { List list = baseDao.selectList(getDateWrapper(tMap)); if (CollectionUtils.isEmpty(list)){ return; } baseDao.migration(list); baseDao.delete(getDateWrapper(tMap)); } public QueryWrapper getDateWrapper(Map params) { String startDate = DateUtils.format(params.get("startdate"),DateUtils.DATE_TIME_PATTERN); String endDate = DateUtils.format(params.get("enddate"),DateUtils.DATE_TIME_PATTERN); QueryWrapper wrapper = new QueryWrapper<>(); wrapper.ge(StringUtils.isNotBlank(startDate), "create_date", startDate); wrapper.le(StringUtils.isNotBlank(endDate), "create_date", endDate); return wrapper; } }