123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- package com.huaxu.service;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.huaxu.dao.DayReportMapper;
- import com.huaxu.dao.MonthReportMapper;
- import com.huaxu.dto.DeviceDto;
- import com.huaxu.dto.ReportAttributeDto;
- import com.huaxu.dto.ReportDto;
- import com.huaxu.entity.DayReportEntity;
- import com.huaxu.entity.MonthReportEntity;
- import com.huaxu.model.LoginUser;
- import com.huaxu.util.UserUtil;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import javax.annotation.Resource;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- /**
- * 日报Service接口
- *
- * @author: WYY
- * @date 2020-12-03 16:20
- */
- @Service
- public class MonthReportService extends ServiceImpl<MonthReportMapper, MonthReportEntity> {
- @Resource
- private MonthReportMapper monthReportMapper;
- @Autowired
- private SceneService sceneService;
- @Autowired
- private DeviceService deviceService;
- /**
- * 查列表
- */
- public List<MonthReportEntity> findList(MonthReportEntity monthReportEntity) {
- return monthReportMapper.findList(monthReportEntity);
- }
- /**
- * 保存
- */
- public boolean addMonthReport(MonthReportEntity monthReport) {
- if (this.save(monthReport)) {
- return true;
- }
- return false;
- }
- /**
- * 根居ID获取对象
- */
- public MonthReportEntity findMonthReportById(Long id) {
- return monthReportMapper.findMonthReportById(id);
- }
- public Page<ReportDto> findPage(IPage<ReportDto> page, Long[] ids, Integer year, Integer month, Integer day) {
- LoginUser currentUser = UserUtil.getCurrentUser();
- Page<ReportDto> reportPage = new Page<>();
- //查询场景下的所有设备信息
- List<DeviceDto> devices = new ArrayList<>();
- DeviceDto deviceDto = new DeviceDto();
- for (Long id : ids) {
- deviceDto.setSceneIds(sceneService.findByParentIdsLike(id));
- devices.addAll(deviceService.selectList(deviceDto));
- }
- MonthReportEntity monthReportEntity = new MonthReportEntity();
- monthReportEntity.setYear(year);
- monthReportEntity.setMonth(month);
- monthReportEntity.setTenantId(currentUser.getTenantId());
- monthReportEntity.setParentSceneIds(ids);
- monthReportEntity.setDeviceIds(devices);
- reportPage = monthReportMapper.findPage(page, monthReportEntity);
- //单个属性值
- for (ReportDto item : reportPage.getRecords()) {
- item.setCollectDate(item.getYear() + "-" + String.format("%02d", item.getMonth()) + "-" + String.format("%02d", item.getDay()));
- item.setDeviceIds(devices);
- //固定参数项
- List<ReportDto> reportDtos = monthReportMapper.findReport(item);
- if (reportDtos.size() > 0) {
- item.setYieldWaterUsage(reportDtos.get(0).getYieldWaterUsage());
- item.setIntakeWaterUsage(reportDtos.get(0).getIntakeWaterUsage());
- item.setPowerUsage(reportDtos.get(0).getPowerUsage());
- item.setDrugUsage(reportDtos.get(0).getDrugUsage());
- }
- //动态参数项
- List<ReportAttributeDto> reportAttributeDtos = monthReportMapper.findAttributeList(item);
- item.setDataValues(reportAttributeDtos);
- }
- return reportPage;
- }
- }
|