|
@@ -0,0 +1,242 @@
|
|
|
+package com.bizmatics.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.bizmatics.common.core.exception.BusinessException;
|
|
|
+import com.bizmatics.common.mvc.base.AbstractCrudService;
|
|
|
+import com.bizmatics.model.BulletinCruxConfig;
|
|
|
+import com.bizmatics.model.Device;
|
|
|
+import com.bizmatics.model.DeviceAnalogVariableList;
|
|
|
+import com.bizmatics.model.DeviceStatus;
|
|
|
+import com.bizmatics.model.system.SysUser;
|
|
|
+import com.bizmatics.model.vo.BulletinCruxConfigVo;
|
|
|
+import com.bizmatics.model.vo.RtData;
|
|
|
+import com.bizmatics.model.vo.SiteData;
|
|
|
+import com.bizmatics.persistence.mapper.BulletinCruxConfigMapper;
|
|
|
+import com.bizmatics.service.BulletinCruxConfigService;
|
|
|
+import com.bizmatics.service.DeviceAnalogVariableListService;
|
|
|
+import com.bizmatics.service.DeviceService;
|
|
|
+import com.bizmatics.service.DeviceStatusService;
|
|
|
+import com.bizmatics.service.util.SecurityUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 数据看板
|
|
|
+ *
|
|
|
+ * @author ya
|
|
|
+ * @since 2022-06-01
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class BulletinCruxConfigServiceImpl extends AbstractCrudService<BulletinCruxConfigMapper, BulletinCruxConfig> implements BulletinCruxConfigService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DeviceAnalogVariableListService deviceAnalogVariableListService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DeviceService deviceService;
|
|
|
+ @Autowired
|
|
|
+ private DeviceStatusService deviceStatusService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据看板-数据配置查询1
|
|
|
+ *
|
|
|
+ * @param siteId 站点ID
|
|
|
+ * @param id 配置ID
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<Object> getBulletinCruxConfigList(Integer siteId, Integer id) {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ SimpleDateFormat sdfa = new SimpleDateFormat("yyyy");
|
|
|
+ //配置数据查询1
|
|
|
+ LambdaQueryWrapper<BulletinCruxConfig> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(BulletinCruxConfig::getSiteId, siteId);
|
|
|
+ if (id != 0) {
|
|
|
+ queryWrapper.eq(BulletinCruxConfig::getId, id);
|
|
|
+ }
|
|
|
+ List<BulletinCruxConfig> list = this.list(queryWrapper);
|
|
|
+// List<BulletinCruxConfigVo> list1 = new ArrayList<>();
|
|
|
+ List<Object> list2 = new ArrayList<>();
|
|
|
+ if (list.size() > 0) {
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ BulletinCruxConfigVo bulletinCruxConfigVo = new BulletinCruxConfigVo();
|
|
|
+ bulletinCruxConfigVo.setId(list.get(i).getId());
|
|
|
+ bulletinCruxConfigVo.setDataName(list.get(i).getDataName());
|
|
|
+ bulletinCruxConfigVo.setDataType(list.get(i).getDataType());
|
|
|
+ bulletinCruxConfigVo.setDataValue(list.get(i).getDataValue());
|
|
|
+ bulletinCruxConfigVo.setBackgroundColor(list.get(i).getBackgroundColor());
|
|
|
+ bulletinCruxConfigVo.setDataNameColor(list.get(i).getDataNameColor());
|
|
|
+ bulletinCruxConfigVo.setDataValueColor(list.get(i).getDataValueColor());
|
|
|
+ bulletinCruxConfigVo.setDataNameFont(list.get(i).getDataNameFont());
|
|
|
+ bulletinCruxConfigVo.setDataValueFont(list.get(i).getDataValueFont());
|
|
|
+ bulletinCruxConfigVo.setIconPath(list.get(i).getIconPath());
|
|
|
+ bulletinCruxConfigVo.setCreateBy(list.get(i).getCreateBy());
|
|
|
+ bulletinCruxConfigVo.setCreateTime(list.get(i).getCreateTime());
|
|
|
+ bulletinCruxConfigVo.setSiteId(list.get(i).getSiteId());
|
|
|
+ bulletinCruxConfigVo.setIdx(""+(list2.size()+1));
|
|
|
+ if (list.get(i).getDataType() == 1) {//普通文本
|
|
|
+
|
|
|
+ } else if (list.get(i).getDataType() == 2) {//站点管理信息
|
|
|
+ List<SiteData> site = baseMapper.getSiteData(list.get(i).getSiteId());
|
|
|
+ //1名称 2地址 3联系电话 4额定容量 5供电类型 6电压等级 7投运时间 8运行天数
|
|
|
+ if (list.get(i).getDataValue() == 1) {
|
|
|
+ bulletinCruxConfigVo.setTextValue(site.get(0).getSiteName());
|
|
|
+ } else if (list.get(i).getDataValue() == 2) {
|
|
|
+ bulletinCruxConfigVo.setTextValue(site.get(0).getSiteAddress());
|
|
|
+ } else if (list.get(i).getDataValue() == 3) {
|
|
|
+ bulletinCruxConfigVo.setTextValue(site.get(0).getPhone());
|
|
|
+ } else if (list.get(i).getDataValue() == 4) {
|
|
|
+ bulletinCruxConfigVo.setTextValue(site.get(0).getInstalledCapacity());
|
|
|
+ } else if (list.get(i).getDataValue() == 5) {
|
|
|
+ if (site.get(0).getPowerSupplyType() == 1) {
|
|
|
+ bulletinCruxConfigVo.setTextValue("单路");
|
|
|
+ } else if (site.get(0).getPowerSupplyType() == 2) {
|
|
|
+ bulletinCruxConfigVo.setTextValue("双路");
|
|
|
+ }
|
|
|
+ } else if (list.get(i).getDataValue() == 6) {
|
|
|
+ bulletinCruxConfigVo.setTextValue(site.get(0).getVoltageLevel());
|
|
|
+ } else if (list.get(i).getDataValue() == 7) {
|
|
|
+ bulletinCruxConfigVo.setTextValue("" + site.get(0).getOperationTime());
|
|
|
+ } else if (list.get(i).getDataValue() == 8) {
|
|
|
+ int time = daysBetween(site.get(0).getCreateTime(), new Date());
|
|
|
+ bulletinCruxConfigVo.setTextValue("" + time);
|
|
|
+ }
|
|
|
+ } else if (list.get(i).getDataType() == 3) {//智能设备数据
|
|
|
+ LambdaQueryWrapper<DeviceAnalogVariableList> queryWrapper1 = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper1.eq(DeviceAnalogVariableList::getId, list.get(i).getVariableId());
|
|
|
+ List<DeviceAnalogVariableList> deviceAttributelist = deviceAnalogVariableListService.list(queryWrapper1);
|
|
|
+ String[] deviceAttribute = deviceAttributelist.get(0).getVariableCoding().split("_");
|
|
|
+ String deviceCode = deviceAttribute[0];
|
|
|
+ String field = deviceAttribute[1];
|
|
|
+ String fieldData = null;
|
|
|
+ if (list.get(i).getMethod() == 1) {//平均
|
|
|
+ fieldData = " avg(" + field + ") as textValue ";
|
|
|
+ } else if (list.get(i).getMethod() == 2) {//最大
|
|
|
+ fieldData = " max(" + field + ") as textValue ";
|
|
|
+ } else if (list.get(i).getMethod() == 3) {//最小
|
|
|
+ fieldData = " min(" + field + ") as textValue ";
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<Device> queryWrapper2 = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper2.eq(Device::getDeviceCode, deviceCode);
|
|
|
+ List<Device> Devicelist = deviceService.list(queryWrapper2);
|
|
|
+ String table = "ht_analog_data";
|
|
|
+ String table1 = "rt_analog_data";
|
|
|
+ if (Devicelist.get(0).getDeviceType().equals("1")) {
|
|
|
+ table = "ht_analog_data";
|
|
|
+ table1 = "rt_analog_data";
|
|
|
+ } else if (Devicelist.get(0).getDeviceType().equals("3")) {
|
|
|
+ table = "ht_analog_171_data";
|
|
|
+ table1 = "rt_analog_171_data";
|
|
|
+ } else if (Devicelist.get(0).getDeviceType().equals("4")) {
|
|
|
+ table = "ht_analog_173_data";
|
|
|
+ table1 = "rt_analog_173_data";
|
|
|
+ }
|
|
|
+ String startHms = "00:00:00";
|
|
|
+ String endHms = "23:59:59";
|
|
|
+ if (list.get(i).getCycle() == 1) {//本日
|
|
|
+ String time = sdf.format(new Date());
|
|
|
+ String startTime = time + " " + startHms;
|
|
|
+ String endTime = time + " " + endHms;
|
|
|
+ List<RtData> rtData = baseMapper.getTextData(table, fieldData, deviceCode, startTime, endTime);
|
|
|
+ bulletinCruxConfigVo.setTextValue(rtData.get(0).getTextValue());
|
|
|
+ } else if (list.get(i).getCycle() == 2) {//本月
|
|
|
+ Calendar calendar = new GregorianCalendar();
|
|
|
+ calendar.setTime(new Date());
|
|
|
+ //获得本月第一天
|
|
|
+ calendar.add(Calendar.MONTH, 0);
|
|
|
+ calendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
+ String startTime = sdf.format(calendar.getTime()) + " " + startHms;
|
|
|
+ //获得本月最后一天
|
|
|
+ calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
|
|
|
+ String endTime = sdf.format(calendar.getTime()) + " " + endHms;
|
|
|
+ List<RtData> rtData = baseMapper.getTextData(table, fieldData, deviceCode, startTime, endTime);
|
|
|
+ bulletinCruxConfigVo.setTextValue(rtData.get(0).getTextValue());
|
|
|
+ } else if (list.get(i).getCycle() == 3) {//本年
|
|
|
+ String time = sdfa.format(new Date());
|
|
|
+ String startTime = time + "-01-01 00:00:00";
|
|
|
+ String endTime = time + "-12-31 23:59:59";
|
|
|
+ List<RtData> rtData = baseMapper.getTextData(table, fieldData, deviceCode, startTime, endTime);
|
|
|
+ bulletinCruxConfigVo.setTextValue(rtData.get(0).getTextValue());
|
|
|
+ } else if (list.get(i).getCycle() == 3) {//实时值
|
|
|
+ List<RtData> rtData = baseMapper.getTextData(table1, field + " as textValue ", deviceCode, null, null);
|
|
|
+ bulletinCruxConfigVo.setTextValue(rtData.get(0).getTextValue());
|
|
|
+ }
|
|
|
+ } else if (list.get(i).getDataType() == 4) {//站点告警状态
|
|
|
+ Integer alarCount = baseMapper.getAlarmCount(siteId);
|
|
|
+ bulletinCruxConfigVo.setTextValue("无告警");
|
|
|
+ if (alarCount>0){
|
|
|
+ bulletinCruxConfigVo.setTextValue("告警");
|
|
|
+ }
|
|
|
+ } else if (list.get(i).getDataType() == 5) {//站点通信状态
|
|
|
+ LambdaQueryWrapper<DeviceStatus> queryWrapper1 = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper1.eq(DeviceStatus::getSiteId, siteId);
|
|
|
+ List<DeviceStatus> deviceStatusList = deviceStatusService.list(queryWrapper1);
|
|
|
+ if (deviceStatusList.size()>0){
|
|
|
+ for (int j = 0; j < deviceStatusList.size(); j++) {
|
|
|
+ bulletinCruxConfigVo.setTextValue("在线");
|
|
|
+ if (deviceStatusList.get(j).getDeviceStatus()==1){
|
|
|
+ bulletinCruxConfigVo.setTextValue("离线");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ bulletinCruxConfigVo.setTextValue("离线");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ list2.add(bulletinCruxConfigVo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //配置数据查询1
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return list2;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public int daysBetween(Date smdate, Date bdate) {
|
|
|
+ try {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ smdate = sdf.parse(sdf.format(smdate));
|
|
|
+ bdate = sdf.parse(sdf.format(bdate));
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ cal.setTime(smdate);
|
|
|
+ long time1 = cal.getTimeInMillis();
|
|
|
+ cal.setTime(bdate);
|
|
|
+ long time2 = cal.getTimeInMillis();
|
|
|
+ long between_days = (time2 - time1) / (1000 * 3600 * 24);
|
|
|
+ return Integer.parseInt(String.valueOf(between_days));
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BusinessException("时间计算错误");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据看板-数据配置1编辑
|
|
|
+ *
|
|
|
+ * @param bulletinCruxConfig
|
|
|
+ */
|
|
|
+ public void editBulletinCruxConfig(BulletinCruxConfig bulletinCruxConfig) {
|
|
|
+ if (bulletinCruxConfig.getId() == 0) {
|
|
|
+ this.updateById(bulletinCruxConfig);
|
|
|
+ } else {
|
|
|
+ SysUser user = SecurityUtils.getLoginUser().getUser();
|
|
|
+ bulletinCruxConfig.setCreateTime(LocalDateTime.now());
|
|
|
+ bulletinCruxConfig.setCreateBy(user.getUserName());
|
|
|
+ this.save(bulletinCruxConfig);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据看板-数据配置1删除
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ */
|
|
|
+ public void delBulletinCruxConfig(Integer id) {
|
|
|
+ baseMapper.delBulletinCruxConfig(id);
|
|
|
+ }
|
|
|
+}
|