|
@@ -0,0 +1,205 @@
|
|
|
+package com.platform.service.remote.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.platform.common.bean.AbstractPageResultBean;
|
|
|
+import com.platform.common.enums.DictTypeEnum;
|
|
|
+import com.platform.common.exception.BusinessException;
|
|
|
+import com.platform.common.util.IdGeneratorUtils;
|
|
|
+import com.platform.dao.bean.MyPage;
|
|
|
+import com.platform.dao.dto.remote.RemoteMeasureLogDTO;
|
|
|
+import com.platform.dao.entity.remote.RemoteMeasureLog;
|
|
|
+import com.platform.dao.entity.upms.SysDict;
|
|
|
+import com.platform.dao.mapper.remote.RemoteMeasureLogMapper;
|
|
|
+import com.platform.dao.mapper.upms.SysDictMapper;
|
|
|
+import com.platform.dao.vo.query.remote.RemoteMeasureLogVO;
|
|
|
+import com.platform.service.base.impl.BaseServiceImpl;
|
|
|
+import com.platform.service.remote.RemoteMeasureLogService;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import tk.mybatis.mapper.weekend.Weekend;
|
|
|
+import tk.mybatis.mapper.weekend.WeekendCriteria;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.Comparator;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description 设备电度记录表 service 实现类
|
|
|
+ * @Author xc
|
|
|
+ * @Date 2022-09-13 14:14:35
|
|
|
+ * @Version Copyright (c) 2020,北京乾元坤和科技有限公司 All rights reserved.
|
|
|
+ */
|
|
|
+@AllArgsConstructor
|
|
|
+@Service("remoteMeasureLogService")
|
|
|
+public class RemoteMeasureLogServiceImpl extends BaseServiceImpl<RemoteMeasureLogMapper, RemoteMeasureLog, RemoteMeasureLogDTO> implements RemoteMeasureLogService {
|
|
|
+
|
|
|
+ private final SysDictMapper sysDictMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int batchDelete(List<String> ids) {
|
|
|
+ Weekend<RemoteMeasureLog> weekend = new Weekend<>(RemoteMeasureLog.class);
|
|
|
+ WeekendCriteria<RemoteMeasureLog, Object> weekendCriteria = weekend.weekendCriteria();
|
|
|
+ weekendCriteria.andIn(RemoteMeasureLog::getId, ids);
|
|
|
+ mapper.deleteByExample(weekend);
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AbstractPageResultBean<RemoteMeasureLogVO> selectPageList(RemoteMeasureLogDTO record, int pageNum, int pageSize) {
|
|
|
+ PageHelper.startPage(pageNum, pageSize);
|
|
|
+ return new MyPage(mapper.selectList(record));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void addByPositionNum(Integer positionNum, String result) {
|
|
|
+ RemoteMeasureLog remoteDegreeLog = new RemoteMeasureLog();
|
|
|
+ remoteDegreeLog.setPositionNum(positionNum);
|
|
|
+ remoteDegreeLog.setId(IdGeneratorUtils.getObjectId());
|
|
|
+ remoteDegreeLog.setResult(result);
|
|
|
+ remoteDegreeLog.setCreatedTime(LocalDateTime.now());
|
|
|
+ mapper.insert(remoteDegreeLog);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 参数:
|
|
|
+ * 查询月报表、日报表
|
|
|
+ * 1:根据线路分组,线路1,线路2
|
|
|
+ * 2:日报表
|
|
|
+ * 根据年、月,日,查询出来
|
|
|
+ * 根据小时分组,循环24小时分组
|
|
|
+ * 根据线路分组:累加
|
|
|
+ * <p>
|
|
|
+ * 3:月报表
|
|
|
+ * 根据年、月,查询出来
|
|
|
+ * 根据天分组,循环到当前月有多少天,
|
|
|
+ * 根据月分组:累加
|
|
|
+ * <p>
|
|
|
+ * 日报格式, 月报没有negative数据
|
|
|
+ * [{
|
|
|
+ * time: “00:00”,
|
|
|
+ * lines: [
|
|
|
+ * {name:"line1", "positive ": “00:00”, "negative": “00:00”},
|
|
|
+ * {name:"line2", "positive": “00:00”, "negative": “00:00”},
|
|
|
+ * {name:"line3", "positive": “00:00”, "negative": “00:00”},
|
|
|
+ * {name:"line4", "positive": “00:00”, "negative": “00:00”},
|
|
|
+ * {name:"line5", "positive": “00:00”, "negative": “00:00”},
|
|
|
+ * {name:"line6", "positive": “00:00”, "negative": “00:00”},
|
|
|
+ * ]
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * time: “01:00”,
|
|
|
+ * lines: [
|
|
|
+ * {name:"line1", "positive ": “00:00”, "negative": “00:00”},
|
|
|
+ * {name:"line2", "positive": “00:00”, "negative": “00:00”},
|
|
|
+ * {name:"line3", "positive": “00:00”, "negative": “00:00”},
|
|
|
+ * {name:"line4", "positive": “00:00”, "negative": “00:00”},
|
|
|
+ * {name:"line5", "positive": “00:00”, "negative": “00:00”},
|
|
|
+ * {name:"line6", "positive": “00:00”, "negative": “00:00”},
|
|
|
+ * ]
|
|
|
+ * }
|
|
|
+ * ]
|
|
|
+ *
|
|
|
+ * @param record
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Object getMonthOrDayReport(RemoteMeasureLogDTO record, Boolean isDay) {
|
|
|
+ if (record.getYear() == null) {
|
|
|
+ throw new BusinessException("请选择年份");
|
|
|
+ }
|
|
|
+ if (record.getMonth() == null) {
|
|
|
+ throw new BusinessException("请选择月份");
|
|
|
+ }
|
|
|
+ Weekend<SysDict> weekend = new Weekend<>(SysDict.class);
|
|
|
+ WeekendCriteria<SysDict, Object> weekendCriteria = weekend.weekendCriteria();
|
|
|
+ weekendCriteria.andEqualTo(SysDict::getType, DictTypeEnum.REMOTE_LINE);
|
|
|
+ List<SysDict> sysDictList = sysDictMapper.selectByExample(weekend);
|
|
|
+ if (CollectionUtils.isEmpty(sysDictList)) {
|
|
|
+ throw new BusinessException("请在数据字典配置设备电力线路");
|
|
|
+ }
|
|
|
+ sysDictList.sort(Comparator.comparing(SysDict::getSort));
|
|
|
+ List<RemoteMeasureLogVO> list = mapper.selectList(record);
|
|
|
+ JSONArray jSONArray = new JSONArray();
|
|
|
+ if (isDay) {//
|
|
|
+ for (int i = 0; i < 24; i++) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("time", i + ":00");
|
|
|
+ JSONArray lineArray = new JSONArray();
|
|
|
+ for (SysDict dict : sysDictList) {
|
|
|
+ JSONObject dictJsonObject = new JSONObject();
|
|
|
+ dictJsonObject.put("name", dict.getLabel());
|
|
|
+ BigDecimal positiveTotal = new BigDecimal(0.00);// 正向有功
|
|
|
+ BigDecimal negativeTotal = new BigDecimal(0.00);// 正向无功
|
|
|
+ for (RemoteMeasureLogVO log : list) {
|
|
|
+ if (log.getBaoyangTimes().toString().equals(dict.getValue())) {
|
|
|
+ if (log.getHour().equals(i)) {
|
|
|
+ if (log.getType().equals(1)) {
|
|
|
+ positiveTotal = positiveTotal.add(new BigDecimal(log.getResult()));
|
|
|
+ } else {
|
|
|
+ negativeTotal = negativeTotal.add(new BigDecimal(log.getResult()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dictJsonObject.put("positive", positiveTotal);
|
|
|
+ dictJsonObject.put("negative", negativeTotal);
|
|
|
+ lineArray.add(dictJsonObject);
|
|
|
+ }
|
|
|
+ jsonObject.put("lines", lineArray);
|
|
|
+ jSONArray.add(jsonObject);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ LocalDate localDate = LocalDate.of(record.getYear(), record.getMonth(), 1);
|
|
|
+ int days = localDate.lengthOfMonth();
|
|
|
+ for (int i = 1; i <= days; i++) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("time", i);
|
|
|
+ JSONArray lineArray = new JSONArray();
|
|
|
+ for (SysDict dict : sysDictList) {
|
|
|
+ JSONObject dictJsonObject = new JSONObject();
|
|
|
+ dictJsonObject.put("name", dict.getLabel());
|
|
|
+ BigDecimal positiveTotal = new BigDecimal(0.00);// 正向有功
|
|
|
+ BigDecimal negativeTotal = new BigDecimal(0.00);// 正向无功,不需要吗,后面可以删除,先保存
|
|
|
+ for (RemoteMeasureLogVO log : list) {
|
|
|
+ if(log.getBaoyangTimes() == null){
|
|
|
+ throw new BusinessException("设备未设置电力线路, 设备名称:" + log.getSbName() + ", 设备编号:" + log.getSbNo());
|
|
|
+ }
|
|
|
+ if (log.getBaoyangTimes().toString().equals(dict.getValue())) {
|
|
|
+ if (log.getDay().equals(i)) {
|
|
|
+ if (log.getType().equals(1)) {
|
|
|
+ positiveTotal = positiveTotal.add(new BigDecimal(log.getResult()));
|
|
|
+ } else {
|
|
|
+ negativeTotal = negativeTotal.add(new BigDecimal(log.getResult()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dictJsonObject.put("positive", positiveTotal);
|
|
|
+ dictJsonObject.put("negative", negativeTotal);
|
|
|
+ lineArray.add(dictJsonObject);
|
|
|
+ }
|
|
|
+ jsonObject.put("lines", lineArray);
|
|
|
+ jSONArray.add(jsonObject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return jSONArray;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ LocalDate localDate = LocalDate.of(2022, 10, 1);
|
|
|
+ int days = localDate.lengthOfMonth();
|
|
|
+ System.out.println(days);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AbstractPageResultBean<RemoteMeasureLog> selectPageInfo(RemoteMeasureLogDTO record, int pageNum, int pageSize) {
|
|
|
+ PageHelper.startPage(pageNum, pageSize);
|
|
|
+ return new MyPage(mapper.selectList(record));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|