|
@@ -1,97 +1,34 @@
|
|
|
package com.platform.service.big.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
-import cn.hutool.core.date.DateUtil;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.github.pagehelper.PageHelper;
|
|
|
-import com.platform.activiti.bean.ActObj;
|
|
|
-import com.platform.activiti.enums.ActApplyEnum;
|
|
|
-import com.platform.common.cache.ConfigCache;
|
|
|
-import com.platform.common.constant.CommonConstants;
|
|
|
-import com.platform.common.enums.DataFilterTypeEnum;
|
|
|
import com.platform.common.enums.DictTypeEnum;
|
|
|
-import com.platform.common.enums.ResultCode;
|
|
|
import com.platform.common.exception.BusinessException;
|
|
|
-import com.platform.common.model.UserInfo;
|
|
|
-import com.platform.common.util.*;
|
|
|
-import com.platform.dao.bean.MyVOPage;
|
|
|
-import com.platform.dao.dto.check.CheckStandardDTO;
|
|
|
-import com.platform.dao.dto.part.PartInfoDTO;
|
|
|
+import com.platform.common.util.BeanConverterUtil;
|
|
|
+import com.platform.common.util.DateUtils;
|
|
|
import com.platform.dao.dto.remote.RemoteDegreeLogDTO;
|
|
|
import com.platform.dao.dto.sb.SbInfoDTO;
|
|
|
-import com.platform.dao.dto.sb.SbModelSpareBomDTO;
|
|
|
-import com.platform.dao.dto.upms.SysDeptDTO;
|
|
|
-import com.platform.dao.dto.upms.SysUserDeptDTO;
|
|
|
-import com.platform.dao.dto.workplace.WorkplaceBacklogDTO;
|
|
|
-import com.platform.dao.dto.workplace.WorkplaceBacklogUserDTO;
|
|
|
-import com.platform.dao.entity.check.CheckStandard;
|
|
|
-import com.platform.dao.entity.firm.FirmProducer;
|
|
|
-import com.platform.dao.entity.part.PartInfo;
|
|
|
-import com.platform.dao.entity.part.PartType;
|
|
|
import com.platform.dao.entity.remote.RemoteMeasure;
|
|
|
-import com.platform.dao.entity.repair.RepairApplicationForm;
|
|
|
-import com.platform.dao.entity.sb.*;
|
|
|
-import com.platform.dao.entity.upms.*;
|
|
|
-import com.platform.dao.enums.*;
|
|
|
-import com.platform.dao.mapper.check.CheckStandardMapper;
|
|
|
-import com.platform.dao.mapper.firm.FirmProducerMapper;
|
|
|
-import com.platform.dao.mapper.part.PartInfoMapper;
|
|
|
-import com.platform.dao.mapper.part.PartTypeMapper;
|
|
|
+import com.platform.dao.entity.sb.SbInfo;
|
|
|
+import com.platform.dao.entity.upms.SysDict;
|
|
|
import com.platform.dao.mapper.remote.RemoteDegreeLogMapper;
|
|
|
-import com.platform.dao.mapper.remote.RemoteDegreeMapper;
|
|
|
-import com.platform.dao.mapper.remote.RemoteMeasureLogMapper;
|
|
|
import com.platform.dao.mapper.remote.RemoteMeasureMapper;
|
|
|
-import com.platform.dao.mapper.repair.RepairApplicationFormMapper;
|
|
|
-import com.platform.dao.mapper.sb.*;
|
|
|
-import com.platform.dao.mapper.upms.SysDeptMapper;
|
|
|
+import com.platform.dao.mapper.sb.SbInfoMapper;
|
|
|
import com.platform.dao.mapper.upms.SysDictMapper;
|
|
|
-import com.platform.dao.mapper.upms.SysUserMapper;
|
|
|
-import com.platform.dao.mapper.workplace.WorkplaceBacklogUserMapper;
|
|
|
-import com.platform.dao.util.CustomExcelImportUtil;
|
|
|
-import com.platform.dao.util.ExcelUtil;
|
|
|
-import com.platform.dao.util.MessageTemplateUtil;
|
|
|
-import com.platform.dao.util.UserUtil;
|
|
|
-import com.platform.dao.util.compare.FieldComparedUtils;
|
|
|
-import com.platform.dao.vo.SysUserDeptVO;
|
|
|
-import com.platform.dao.vo.SysUserVO;
|
|
|
-import com.platform.dao.vo.export.sb.ExportSbInfoVO;
|
|
|
import com.platform.dao.vo.query.remote.RemoteDegreeLogVO;
|
|
|
-import com.platform.dao.vo.query.upms.SysDeptVO;
|
|
|
-import com.platform.dao.vo.report.SbInfoTypeReportVO;
|
|
|
-import com.platform.dao.vo.sb.*;
|
|
|
import com.platform.service.base.impl.BaseServiceImpl;
|
|
|
import com.platform.service.big.BigScreenSbInfoService;
|
|
|
-import com.platform.service.business.ActivitiBusinessService;
|
|
|
-import com.platform.service.check.CheckStandardService;
|
|
|
-import com.platform.service.event.WorkplaceBacklogEvent;
|
|
|
-import com.platform.service.part.PartInfoService;
|
|
|
-import com.platform.service.remote.RemoteDegreeLogService;
|
|
|
-import com.platform.service.sb.SbInfoService;
|
|
|
-import com.platform.service.sb.SbModelSpareBomService;
|
|
|
-import com.platform.service.upms.SysDeptRelationService;
|
|
|
-import com.platform.service.upms.SysDeptService;
|
|
|
-import com.platform.service.upms.SysFileService;
|
|
|
-import com.platform.service.upms.SysUserDeptService;
|
|
|
-import com.platform.service.util.CodeFileUtils;
|
|
|
-import com.platform.service.util.ExecuteSql;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.ibatis.exceptions.TooManyResultsException;
|
|
|
-import org.apache.poi.ss.formula.functions.CalendarFieldFunction;
|
|
|
-import org.springframework.core.env.Environment;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Isolation;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
import tk.mybatis.mapper.weekend.Weekend;
|
|
|
import tk.mybatis.mapper.weekend.WeekendCriteria;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.time.LocalDate;
|
|
|
-import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -202,9 +139,6 @@ public class BigScreenSbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, Sb
|
|
|
*/
|
|
|
@Override
|
|
|
public JSONArray getMonthOrDayReport(RemoteDegreeLogDTO record, Boolean isDay) {
|
|
|
-
|
|
|
- // 缩小倍数,哈光宇传过来的10倍的
|
|
|
- BigDecimal d = new BigDecimal(10);
|
|
|
if (record.getYear() == null) {
|
|
|
throw new BusinessException("请选择年份");
|
|
|
}
|
|
@@ -221,17 +155,12 @@ public class BigScreenSbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, Sb
|
|
|
sysDictList.sort(Comparator.comparing(SysDict::getSort));
|
|
|
record.setSbName("G01");
|
|
|
// 如果是月的,只查0点的数据
|
|
|
- if(!isDay){
|
|
|
+ if (!isDay) {
|
|
|
record.setHour(0);
|
|
|
}
|
|
|
List<RemoteDegreeLogVO> list = remoteDegreeLogMapper.selectList(record);
|
|
|
-
|
|
|
- // 全部取绝对值,有负数的去掉
|
|
|
- for (RemoteDegreeLogVO degreeLog : list) {
|
|
|
- degreeLog.setResult(degreeLog.getResult().replace("-", ""));
|
|
|
- }
|
|
|
-
|
|
|
JSONArray jSONArray = new JSONArray();
|
|
|
+ BigDecimal totalDay = new BigDecimal("0");
|
|
|
if (isDay) {// 日报,需要减去上个小时的
|
|
|
// 找到前天晚上23点的
|
|
|
RemoteDegreeLogDTO lastDay = BeanConverterUtil.copyObjectProperties(record, RemoteDegreeLogDTO.class);
|
|
@@ -259,35 +188,36 @@ public class BigScreenSbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, Sb
|
|
|
if (degreeLog.getType().equals(1)) {
|
|
|
positiveTotal = positiveTotal.add(new BigDecimal(degreeLog.getResult()));
|
|
|
// 找到上个时间
|
|
|
- if(i == 0){// 从昨天找
|
|
|
+ if (i == 0) {// 从昨天找
|
|
|
Optional<RemoteDegreeLogVO> lastR = lastList.stream().filter(item -> item.getPositionNum().equals(degreeLog.getPositionNum())).findFirst();
|
|
|
- if(lastR.isPresent()){
|
|
|
+ if (lastR.isPresent()) {
|
|
|
log.info(JSONObject.toJSONString(lastR.get()));
|
|
|
- positiveTotal = positiveTotal.subtract(new BigDecimal(lastR.get().getResult()).abs());
|
|
|
+ positiveTotal = positiveTotal.subtract(new BigDecimal(lastR.get().getResult()));
|
|
|
}
|
|
|
- }else{// 从今天上个时间找,减去上个小时的数据
|
|
|
- Optional<RemoteDegreeLogVO> lastR = list.stream().filter(item -> item.getPositionNum().equals(degreeLog.getPositionNum()) && item.getHour().equals(degreeLog.getHour()-1)).findFirst();
|
|
|
- if(lastR.isPresent()){
|
|
|
- positiveTotal = positiveTotal.subtract(new BigDecimal(lastR.get().getResult()).abs());
|
|
|
+ } else {// 从今天上个时间找,减去上个小时的数据
|
|
|
+ Optional<RemoteDegreeLogVO> lastR = list.stream().filter(item -> item.getPositionNum().equals(degreeLog.getPositionNum()) && item.getHour().equals(degreeLog.getHour() - 1)).findFirst();
|
|
|
+ if (lastR.isPresent()) {
|
|
|
+ positiveTotal = positiveTotal.subtract(new BigDecimal(lastR.get().getResult()));
|
|
|
}
|
|
|
}
|
|
|
- dictJsonObject.put("positive", positiveTotal.divide(d, 2, RoundingMode.HALF_UP).doubleValue());
|
|
|
+ totalDay = totalDay.add(positiveTotal.divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP));
|
|
|
+ dictJsonObject.put("positive", positiveTotal.divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP).doubleValue());
|
|
|
} else {
|
|
|
negativeTotal = negativeTotal.add(new BigDecimal(degreeLog.getResult()));
|
|
|
// 找到上个时间
|
|
|
- if(i == 0){// 从昨天找
|
|
|
+ if (i == 0) {// 从昨天找
|
|
|
Optional<RemoteDegreeLogVO> lastR = lastList.stream().filter(item -> item.getPositionNum().equals(degreeLog.getPositionNum())).findFirst();
|
|
|
- if(lastR.isPresent()){
|
|
|
+ if (lastR.isPresent()) {
|
|
|
log.info(JSONObject.toJSONString(lastR.get()));
|
|
|
- negativeTotal = negativeTotal.subtract(new BigDecimal(lastR.get().getResult()).abs());
|
|
|
+ negativeTotal = negativeTotal.subtract(new BigDecimal(lastR.get().getResult()));
|
|
|
}
|
|
|
- }else{// 从今天上个时间找,减去上个小时的数据
|
|
|
- Optional<RemoteDegreeLogVO> lastR = list.stream().filter(item -> item.getPositionNum().equals(degreeLog.getPositionNum()) && item.getHour().equals(degreeLog.getHour()-1)).findFirst();
|
|
|
- if(lastR.isPresent()){
|
|
|
- negativeTotal = negativeTotal.subtract(new BigDecimal(lastR.get().getResult()).abs());
|
|
|
+ } else {// 从今天上个时间找,减去上个小时的数据
|
|
|
+ Optional<RemoteDegreeLogVO> lastR = list.stream().filter(item -> item.getPositionNum().equals(degreeLog.getPositionNum()) && item.getHour().equals(degreeLog.getHour() - 1)).findFirst();
|
|
|
+ if (lastR.isPresent()) {
|
|
|
+ negativeTotal = negativeTotal.subtract(new BigDecimal(lastR.get().getResult()));
|
|
|
}
|
|
|
}
|
|
|
- dictJsonObject.put("negative", negativeTotal.divide(d, 2, RoundingMode.HALF_UP).doubleValue());
|
|
|
+ dictJsonObject.put("negative", negativeTotal.divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP).doubleValue());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -311,11 +241,6 @@ public class BigScreenSbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, Sb
|
|
|
lastDay.setDay(calendar.getActualMaximum(Calendar.DATE));
|
|
|
List<RemoteDegreeLogVO> lastList = remoteDegreeLogMapper.selectList(lastDay);
|
|
|
|
|
|
- // 全部取绝对值,有负数的去掉
|
|
|
- for (RemoteDegreeLogVO degreeLog : lastList) {
|
|
|
- degreeLog.setResult(degreeLog.getResult().replace("-", ""));
|
|
|
- }
|
|
|
-
|
|
|
for (int i = 1; i <= days; i++) {
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.put("time", i);
|
|
@@ -329,7 +254,7 @@ public class BigScreenSbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, Sb
|
|
|
if (degreeLog.getLine() == null) {
|
|
|
throw new BusinessException("设备未设置电力线路, 设备名称:" + degreeLog.getSbName() + ", 设备编号:" + degreeLog.getSbNo());
|
|
|
}
|
|
|
- if(degreeLog.getDay().equals(nowDay)){// 当天时间不计算。因为当天还没过完,没有全部数据
|
|
|
+ if (degreeLog.getDay().equals(nowDay)) {// 当天时间不计算。因为当天还没过完,没有全部数据
|
|
|
continue;
|
|
|
}
|
|
|
if (degreeLog.getLine().toString().equals(dict.getValue())) {
|
|
@@ -337,17 +262,17 @@ public class BigScreenSbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, Sb
|
|
|
if (degreeLog.getType().equals(1)) {
|
|
|
positiveTotal = positiveTotal.add(new BigDecimal(degreeLog.getResult()));
|
|
|
// 找到下个月时间
|
|
|
- if(i == days){// 从下个月第一天找
|
|
|
+ if (i == days) {// 从下个月第一天找
|
|
|
Optional<RemoteDegreeLogVO> lastR = lastList.stream().filter(item -> item.getPositionNum().equals(degreeLog.getPositionNum())).findFirst();
|
|
|
- if(lastR.isPresent()){
|
|
|
+ if (lastR.isPresent()) {
|
|
|
//log.info("1: " + degreeLog.getDay() + "," + degreeLog.getDay() + ","+ degreeLog.getDay() + ","+ lastR.get().getDay());
|
|
|
- positiveTotal = positiveTotal.subtract(new BigDecimal(lastR.get().getResult()).abs());
|
|
|
+ positiveTotal = positiveTotal.subtract(new BigDecimal(lastR.get().getResult()));
|
|
|
}
|
|
|
- }else{// 从后天时间找,减去昨天的数据
|
|
|
- Optional<RemoteDegreeLogVO> lastR = list.stream().filter(item -> item.getPositionNum().equals(degreeLog.getPositionNum()) && item.getDay().equals(degreeLog.getDay()+1)).findFirst();
|
|
|
- if(lastR.isPresent()){
|
|
|
+ } else {// 从后天时间找,减去昨天的数据
|
|
|
+ Optional<RemoteDegreeLogVO> lastR = list.stream().filter(item -> item.getPositionNum().equals(degreeLog.getPositionNum()) && item.getDay().equals(degreeLog.getDay() + 1)).findFirst();
|
|
|
+ if (lastR.isPresent()) {
|
|
|
//log.info("2: " + degreeLog.getDay() + "," + lastR.get().getDay());
|
|
|
- positiveTotal = new BigDecimal(lastR.get().getResult()).abs().subtract(positiveTotal);
|
|
|
+ positiveTotal = new BigDecimal(lastR.get().getResult()).subtract(positiveTotal);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -371,8 +296,8 @@ public class BigScreenSbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, Sb
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- dictJsonObject.put("positive", positiveTotal.divide(d, 2, RoundingMode.HALF_UP).doubleValue());
|
|
|
- dictJsonObject.put("negative", negativeTotal.divide(d, 2, RoundingMode.HALF_UP).doubleValue());
|
|
|
+ dictJsonObject.put("positive", positiveTotal.divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP).doubleValue());
|
|
|
+ dictJsonObject.put("negative", negativeTotal.divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP).doubleValue());
|
|
|
lineArray.add(dictJsonObject);
|
|
|
}
|
|
|
jsonObject.put("lines", lineArray);
|
|
@@ -382,6 +307,76 @@ public class BigScreenSbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, Sb
|
|
|
return jSONArray;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成生产报表:每日耗电数据
|
|
|
+ *
|
|
|
+ * @param record
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public BigDecimal getScReport(RemoteDegreeLogDTO record) {
|
|
|
+ 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));
|
|
|
+ record.setSbName("G01");
|
|
|
+ List<RemoteDegreeLogVO> list = remoteDegreeLogMapper.selectList(record);
|
|
|
+ BigDecimal totalDay = new BigDecimal("0");
|
|
|
+
|
|
|
+ // 找到前天晚上23点的
|
|
|
+ RemoteDegreeLogDTO lastDay = BeanConverterUtil.copyObjectProperties(record, RemoteDegreeLogDTO.class);
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.set(lastDay.getYear(), lastDay.getMonth() - 1, lastDay.getDay());
|
|
|
+ DateUtils.getLastDay(calendar);
|
|
|
+ lastDay.setYear(calendar.get(Calendar.YEAR));
|
|
|
+ lastDay.setMonth(calendar.get(Calendar.MONTH) + 1);
|
|
|
+ lastDay.setDay(calendar.get(Calendar.DAY_OF_MONTH));
|
|
|
+ lastDay.setHour(23);
|
|
|
+ List<RemoteDegreeLogVO> lastList = remoteDegreeLogMapper.selectList(lastDay);
|
|
|
+
|
|
|
+ for (int i = 0; i < 24; i++) {
|
|
|
+ for (SysDict dict : sysDictList) {
|
|
|
+ BigDecimal positiveTotal = new BigDecimal(0.00);// 正向有功
|
|
|
+ BigDecimal negativeTotal = new BigDecimal(0.00);// 正向无功
|
|
|
+ for (RemoteDegreeLogVO degreeLog : list) {
|
|
|
+ if (degreeLog.getLine().toString().equals(dict.getValue())) {
|
|
|
+ if (degreeLog.getHour().equals(i)) {
|
|
|
+ if (degreeLog.getType().equals(1)) {
|
|
|
+ positiveTotal = positiveTotal.add(new BigDecimal(degreeLog.getResult()));
|
|
|
+ // 找到上个时间
|
|
|
+ if (i == 0) {// 从昨天找
|
|
|
+ Optional<RemoteDegreeLogVO> lastR = lastList.stream().filter(item -> item.getPositionNum().equals(degreeLog.getPositionNum())).findFirst();
|
|
|
+ if (lastR.isPresent()) {
|
|
|
+ log.info(JSONObject.toJSONString(lastR.get()));
|
|
|
+ positiveTotal = positiveTotal.subtract(new BigDecimal(lastR.get().getResult()));
|
|
|
+ }
|
|
|
+ } else {// 从今天上个时间找,减去上个小时的数据
|
|
|
+ Optional<RemoteDegreeLogVO> lastR = list.stream().filter(item -> item.getPositionNum().equals(degreeLog.getPositionNum()) && item.getHour().equals(degreeLog.getHour() - 1)).findFirst();
|
|
|
+ if (lastR.isPresent()) {
|
|
|
+ positiveTotal = positiveTotal.subtract(new BigDecimal(lastR.get().getResult()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ totalDay = totalDay.add(positiveTotal.divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return totalDay;
|
|
|
+ }
|
|
|
+
|
|
|
public static void main(String[] args) {
|
|
|
Map<String, List<RemoteMeasure>> map = new HashMap<>();
|
|
|
map.put("sbName", new ArrayList<>());
|