|
|
|
|
@ -4,9 +4,13 @@ import com.alibaba.excel.util.StringUtils; |
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import jakarta.annotation.Resource; |
|
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
|
import org.springblade.desk.common.feign.IMesNotifyMessageClient; |
|
|
|
|
import org.springblade.desk.common.pojo.entity.MesNotifyMessageEntity; |
|
|
|
|
import org.springblade.desk.device.pojo.entity.EquipmentEntity; |
|
|
|
|
import org.springblade.desk.device.service.IEquipmentService; |
|
|
|
|
import org.springblade.desk.energy.mapper.BsEnergyCoreUseMapper; |
|
|
|
|
@ -18,6 +22,8 @@ import org.springblade.desk.energy.pojo.vo.BsEnergyHistoryRecVO; |
|
|
|
|
import org.springblade.desk.energy.service.IBsEnergyCoreUseService; |
|
|
|
|
import org.springblade.desk.energy.service.IBsEnergyHistoryRecService; |
|
|
|
|
import org.springblade.desk.energy.service.IBsEnergyQuotaService; |
|
|
|
|
import org.springblade.system.feign.ISysClient; |
|
|
|
|
import org.springblade.system.pojo.entity.User; |
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
|
import org.springframework.http.HttpEntity; |
|
|
|
|
import org.springframework.http.HttpHeaders; |
|
|
|
|
@ -34,9 +40,10 @@ import java.time.LocalDateTime; |
|
|
|
|
import java.time.LocalTime; |
|
|
|
|
import java.time.ZoneId; |
|
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
|
import java.util.Arrays; |
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
import static org.springblade.desk.oem.service.impl.OemStatementServiceImpl.SDF; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -56,6 +63,10 @@ public class BsEnergyCoreUseServiceImpl extends BaseServiceImpl<BsEnergyCoreUseM |
|
|
|
|
private IEquipmentService equipmentService; |
|
|
|
|
@Resource |
|
|
|
|
private RestTemplate httpClientTemplate; |
|
|
|
|
@Resource |
|
|
|
|
private ISysClient sysClient; |
|
|
|
|
@Resource |
|
|
|
|
private IMesNotifyMessageClient mesNotifyMessageClient; |
|
|
|
|
|
|
|
|
|
private String timestamp = "timestamp", waterOne = "Water1", waterTwo = "Water2", waterThree = "Water3", waterFour = "Water4", readElectric = "ElectricPower", readElectric2 = "TotalElectricEnergyOfBX2", readElectric3 = "TotalElectricEnergyOfBX3"; |
|
|
|
|
|
|
|
|
|
@ -182,6 +193,76 @@ public class BsEnergyCoreUseServiceImpl extends BaseServiceImpl<BsEnergyCoreUseM |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void warning() { |
|
|
|
|
QueryWrapper<BsEnergyCoreUseEntity> wrapper = new QueryWrapper<>(); |
|
|
|
|
LocalDate today = LocalDate.now(); |
|
|
|
|
LocalDate yesterday = today.minusDays(1); |
|
|
|
|
LocalDate day1 = yesterday.minusDays(1); |
|
|
|
|
LocalDate day2 = yesterday.minusDays(2); |
|
|
|
|
LocalDate day3 = yesterday.minusDays(3); |
|
|
|
|
wrapper.ne("QUO_ELECTRIC_NUM", 0); |
|
|
|
|
wrapper.eq("TYPE", "2"); |
|
|
|
|
wrapper.apply("TRUNC(START_TIME) >= TRUNC({0}) AND TRUNC(START_TIME) < TRUNC({1}) AND (REAL_ELECTRIC_NUM < QUO_ELECTRIC_NUM OR REAL_ELECTRIC_NUM > QUO_ELECTRIC_NUM * 1.3)", day3, today); |
|
|
|
|
List<BsEnergyCoreUseEntity> list = this.list(wrapper); |
|
|
|
|
if (CollectionUtils.isEmpty(list)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
R<List<User>> userResult = sysClient.listAllByRoleAlias("environmentalTechnician"); |
|
|
|
|
if (userResult == null || !userResult.isSuccess()) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
List<User> users = userResult.getData(); |
|
|
|
|
Map<String, Set<String>> workDayMap = list.stream() |
|
|
|
|
.collect(Collectors.groupingBy( |
|
|
|
|
BsEnergyCoreUseEntity::getWorkCenterId, |
|
|
|
|
Collectors.mapping( |
|
|
|
|
entity -> SDF.format(entity.getStartTime()), |
|
|
|
|
Collectors.toSet() |
|
|
|
|
) |
|
|
|
|
)); |
|
|
|
|
Map<String, String> workCenterMap = list.stream() |
|
|
|
|
.collect(Collectors.toMap( |
|
|
|
|
BsEnergyCoreUseEntity::getWorkCenterId, |
|
|
|
|
BsEnergyCoreUseEntity::getWorkCenterName, |
|
|
|
|
(oldVal, newVal) -> oldVal |
|
|
|
|
)); |
|
|
|
|
String date0 = SDF.format(localDateToDate(yesterday)); |
|
|
|
|
String date1 = SDF.format(localDateToDate(day1)); |
|
|
|
|
String date2 = SDF.format(localDateToDate(day2)); |
|
|
|
|
String date3 = SDF.format(localDateToDate(day3)); |
|
|
|
|
for (Map.Entry<String, Set<String>> entry : workDayMap.entrySet()) { |
|
|
|
|
String workCenterId = entry.getKey(); |
|
|
|
|
String workCenterName = workCenterMap.get(workCenterId); |
|
|
|
|
Set<String> dateSet = entry.getValue(); |
|
|
|
|
|
|
|
|
|
// 判断每一天是否异常
|
|
|
|
|
boolean b0 = dateSet.contains(date0); |
|
|
|
|
boolean b1 = dateSet.contains(date1); |
|
|
|
|
boolean b2 = dateSet.contains(date2); |
|
|
|
|
boolean b3 = dateSet.contains(date3); |
|
|
|
|
|
|
|
|
|
// 触发条件:仅最近三天异常
|
|
|
|
|
if (b0 && b1 && b2 && !b3) { |
|
|
|
|
// 发送提醒
|
|
|
|
|
String title = String.format("%s - 用电异常提醒", workCenterName); |
|
|
|
|
String content = String.format("%s - 已连续3天用电异常,请关注", workCenterName); |
|
|
|
|
for (User user : users) { |
|
|
|
|
MesNotifyMessageEntity notifyMessage = MesNotifyMessageEntity.builder() |
|
|
|
|
.title(title) |
|
|
|
|
.content(content) |
|
|
|
|
.receiveUserId(user.getId()) |
|
|
|
|
.build(); |
|
|
|
|
mesNotifyMessageClient.save(notifyMessage); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Date localDateToDate(LocalDate localDate) { |
|
|
|
|
return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 创建作业中心用水用电记录 |
|
|
|
|
* |
|
|
|
|
|