MonthReportService.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package com.huaxu.service;
  2. import com.baomidou.mybatisplus.core.metadata.IPage;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  5. import com.huaxu.dao.DayReportMapper;
  6. import com.huaxu.dao.MonthReportMapper;
  7. import com.huaxu.dto.DeviceDto;
  8. import com.huaxu.dto.ReportAttributeDto;
  9. import com.huaxu.dto.ReportDto;
  10. import com.huaxu.entity.DayReportEntity;
  11. import com.huaxu.entity.MonthReportEntity;
  12. import com.huaxu.model.LoginUser;
  13. import com.huaxu.util.UserUtil;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.stereotype.Service;
  16. import org.springframework.transaction.annotation.Transactional;
  17. import javax.annotation.Resource;
  18. import java.util.ArrayList;
  19. import java.util.Arrays;
  20. import java.util.List;
  21. /**
  22. * 日报Service接口
  23. *
  24. * @author: WYY
  25. * @date 2020-12-03 16:20
  26. */
  27. @Service
  28. public class MonthReportService extends ServiceImpl<MonthReportMapper, MonthReportEntity> {
  29. @Resource
  30. private MonthReportMapper monthReportMapper;
  31. @Autowired
  32. private SceneService sceneService;
  33. @Autowired
  34. private DeviceService deviceService;
  35. /**
  36. * 查列表
  37. */
  38. public List<MonthReportEntity> findList(MonthReportEntity monthReportEntity) {
  39. return monthReportMapper.findList(monthReportEntity);
  40. }
  41. /**
  42. * 保存
  43. */
  44. public boolean addMonthReport(MonthReportEntity monthReport) {
  45. if (this.save(monthReport)) {
  46. return true;
  47. }
  48. return false;
  49. }
  50. /**
  51. * 根居ID获取对象
  52. */
  53. public MonthReportEntity findMonthReportById(Long id) {
  54. return monthReportMapper.findMonthReportById(id);
  55. }
  56. public Page<ReportDto> findPage(IPage<ReportDto> page, Long[] ids, Integer year, Integer month, Integer day) {
  57. LoginUser currentUser = UserUtil.getCurrentUser();
  58. Page<ReportDto> reportPage = new Page<>();
  59. //查询场景下的所有设备信息
  60. List<DeviceDto> devices = new ArrayList<>();
  61. DeviceDto deviceDto = new DeviceDto();
  62. for (Long id : ids) {
  63. deviceDto.setSceneIds(sceneService.findByParentIdsLike(id));
  64. devices.addAll(deviceService.selectList(deviceDto));
  65. }
  66. MonthReportEntity monthReportEntity = new MonthReportEntity();
  67. monthReportEntity.setYear(year);
  68. monthReportEntity.setMonth(month);
  69. monthReportEntity.setTenantId(currentUser.getTenantId());
  70. monthReportEntity.setParentSceneIds(ids);
  71. monthReportEntity.setDeviceIds(devices);
  72. reportPage = monthReportMapper.findPage(page, monthReportEntity);
  73. //单个属性值
  74. for (ReportDto item : reportPage.getRecords()) {
  75. item.setCollectDate(item.getYear() + "-" + String.format("%02d", item.getMonth()) + "-" + String.format("%02d", item.getDay()));
  76. item.setDeviceIds(devices);
  77. //固定参数项
  78. List<ReportDto> reportDtos = monthReportMapper.findReport(item);
  79. if (reportDtos.size() > 0) {
  80. item.setYieldWaterUsage(reportDtos.get(0).getYieldWaterUsage());
  81. item.setIntakeWaterUsage(reportDtos.get(0).getIntakeWaterUsage());
  82. item.setPowerUsage(reportDtos.get(0).getPowerUsage());
  83. item.setDrugUsage(reportDtos.get(0).getDrugUsage());
  84. }
  85. //动态参数项
  86. List<ReportAttributeDto> reportAttributeDtos = monthReportMapper.findAttributeList(item);
  87. item.setDataValues(reportAttributeDtos);
  88. }
  89. return reportPage;
  90. }
  91. }