Browse Source

1、大屏接口管理

dev
mh 2 months ago
parent
commit
81a8678db6
  1. 6
      2024新增脚本.sql
  2. 2
      user-service/src/main/java/com/mh/user/controller/DevicesManageController.java
  3. 10
      user-service/src/main/java/com/mh/user/controller/DevicesParamsController.java
  4. 70
      user-service/src/main/java/com/mh/user/controller/ScreenController.java
  5. 64
      user-service/src/main/java/com/mh/user/dto/ScreenRequestParamDTO.java
  6. 2
      user-service/src/main/java/com/mh/user/entity/DataResultEntity.java
  7. 8
      user-service/src/main/java/com/mh/user/entity/DevicesManageEntity.java
  8. 2
      user-service/src/main/java/com/mh/user/job/DealDataJob.java
  9. 4
      user-service/src/main/java/com/mh/user/mapper/DataResultMapper.java
  10. 11
      user-service/src/main/java/com/mh/user/mapper/MeterManageMapper.java
  11. 238
      user-service/src/main/java/com/mh/user/mapper/ScreenMapper.java
  12. 48
      user-service/src/main/java/com/mh/user/service/ScreenService.java
  13. 95
      user-service/src/main/java/com/mh/user/service/impl/DataResultServiceImpl.java
  14. 12
      user-service/src/main/java/com/mh/user/service/impl/GatewayManageServiceImpl.java
  15. 2
      user-service/src/main/java/com/mh/user/service/impl/MeterManageServiceImpl.java
  16. 210
      user-service/src/main/java/com/mh/user/service/impl/ScreenServiceImpl.java
  17. 58
      user-service/src/main/java/com/mh/user/strategy/EleProtocolStrategy.java
  18. 9
      user-service/src/main/java/com/mh/user/strategy/ModbusProtocolStrategy.java
  19. 16
      user-service/src/main/java/com/mh/user/utils/DateUtil.java

6
2024新增脚本.sql

@ -241,3 +241,9 @@ ALTER TABLE mh_jnd.dbo.device_code_param ADD data_type int NULL;
EXEC mh_jnd.sys.sp_addextendedproperty 'MS_Description', N'数据类型', 'schema', N'dbo', 'table', N'device_code_param', 'column', N'data_type'; EXEC mh_jnd.sys.sp_addextendedproperty 'MS_Description', N'数据类型', 'schema', N'dbo', 'table', N'device_code_param', 'column', N'data_type';
ALTER TABLE mh_jnd.dbo.device_code_param ADD protocol_type int NULL; ALTER TABLE mh_jnd.dbo.device_code_param ADD protocol_type int NULL;
EXEC mh_jnd.sys.sp_addextendedproperty 'MS_Description', N'协议类型(数据字典表)', 'schema', N'dbo', 'table', N'device_code_param', 'column', N'protocol_type'; EXEC mh_jnd.sys.sp_addextendedproperty 'MS_Description', N'协议类型(数据字典表)', 'schema', N'dbo', 'table', N'device_code_param', 'column', N'protocol_type';
-- 2024-09-24 data_result表添加字段
ALTER TABLE data_result ADD register_addr varchar(50) NULL;
EXEC sys.sp_addextendedproperty 'MS_Description', N'寄存器地址', 'schema', N'dbo', 'table', N'data_result', 'column', N'register_addr';
ALTER TABLE data_result ADD register_name varchar(50) NULL;
EXEC sys.sp_addextendedproperty 'MS_Description', N'寄存器名称', 'schema', N'dbo', 'table', N'data_result', 'column', N'register_name';

2
user-service/src/main/java/com/mh/user/controller/DevicesManageController.java

@ -45,7 +45,7 @@ public class DevicesManageController {
@SysLogger(value="资产管理信息",optDesc = "添加资产管理信息") @SysLogger(value="资产管理信息",optDesc = "添加资产管理信息")
@PostMapping("/save") @PostMapping("/save")
public HttpResult saveGw(DevicesManageEntity entity) { public HttpResult saveDevice(DevicesManageEntity entity) {
devicesManageService.save(entity); devicesManageService.save(entity);
return HttpResult.ok(); return HttpResult.ok();
} }

10
user-service/src/main/java/com/mh/user/controller/DevicesParamsController.java

@ -23,34 +23,34 @@ public class DevicesParamsController {
@Autowired @Autowired
private DeviceParamsService deviceParamsService; private DeviceParamsService deviceParamsService;
@SysLogger(value="资产管理信息",optDesc = "查询资产管理信息") @SysLogger(value="设备参数管理",optDesc = "查询设备参数管理")
@PostMapping("/findByPage") @PostMapping("/findByPage")
public PageResult queryGatewayManage(@RequestBody PageRequest pageRequest) { public PageResult queryGatewayManage(@RequestBody PageRequest pageRequest) {
return deviceParamsService.queryByPage(pageRequest); return deviceParamsService.queryByPage(pageRequest);
} }
@SysLogger(value="资产管理信息",optDesc = "编辑资产管理信息") @SysLogger(value="设备参数管理",optDesc = "编辑设备参数管理")
@PostMapping("/update") @PostMapping("/update")
public HttpResult updateProInfo(DeviceParamsEntity entity) { public HttpResult updateProInfo(DeviceParamsEntity entity) {
deviceParamsService.update(entity); deviceParamsService.update(entity);
return HttpResult.ok(); return HttpResult.ok();
} }
@SysLogger(value="资产管理信息",optDesc = "根据项目id查询对应信息") @SysLogger(value="设备参数管理",optDesc = "根据项目id查询对应信息")
@GetMapping("/findById") @GetMapping("/findById")
public HttpResult findById(@RequestParam("id") Long id) { public HttpResult findById(@RequestParam("id") Long id) {
DeviceParamsEntity entity = deviceParamsService.findById(id); DeviceParamsEntity entity = deviceParamsService.findById(id);
return HttpResult.ok(entity); return HttpResult.ok(entity);
} }
@SysLogger(value="资产管理信息",optDesc = "添加资产管理信息") @SysLogger(value="设备参数管理",optDesc = "添加设备参数管理")
@PostMapping("/save") @PostMapping("/save")
public HttpResult saveGw(DeviceParamsEntity entity) { public HttpResult saveGw(DeviceParamsEntity entity) {
deviceParamsService.save(entity); deviceParamsService.save(entity);
return HttpResult.ok(); return HttpResult.ok();
} }
@SysLogger(value="资产管理信息",optDesc = "删除资产管理信息") @SysLogger(value="设备参数管理",optDesc = "删除设备参数管理")
@GetMapping("/deleteById") @GetMapping("/deleteById")
public HttpResult deleteProInfo(@RequestParam String id) { public HttpResult deleteProInfo(@RequestParam String id) {
deviceParamsService.delete(id); deviceParamsService.delete(id);

70
user-service/src/main/java/com/mh/user/controller/ScreenController.java

@ -0,0 +1,70 @@
package com.mh.user.controller;
import com.alibaba.fastjson2.JSONObject;
import com.mh.common.http.HttpResult;
import com.mh.user.dto.ScreenRequestParamDTO;
import com.mh.user.service.ScreenService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
/**
* @author LJF
* @version 1.0
* @project mh_esi
* @description 大屏接口类
* @date 2024-09-24 11:40:15
*/
@RestController
@RequestMapping("/screen")
public class ScreenController {
@Resource
private ScreenService screenService;
/**
* 能耗数据
* @return
*/
@PostMapping("/energyData")
public HttpResult energyData(@RequestBody ScreenRequestParamDTO screenRequestParamDTO) {
return HttpResult.ok(screenService.energyData(screenRequestParamDTO));
}
/**
* 节能量概况
* @return
*/
@PostMapping("/savingEnergyData")
public HttpResult savingEnergy(@RequestBody ScreenRequestParamDTO screenRequestParamDTO) {
return HttpResult.ok(screenService.savingEnergy(screenRequestParamDTO));
}
/**
* 节能量同比
* @return
*/
@PostMapping("/savingYoyEnergyData")
public HttpResult savingYoyEnergyData(@RequestBody ScreenRequestParamDTO screenRequestParamDTO) {
return HttpResult.ok(screenService.savingYoyEnergyData(screenRequestParamDTO));
}
/**
* 故障详情
* @return
*/
@PostMapping("/faultList")
public HttpResult faultList() {
return HttpResult.ok(screenService.faultList());
}
/**
* 项目坐标数据
* @return
*/
@PostMapping("/projectData")
public HttpResult projectData() {
return HttpResult.ok(screenService.projectData());
}
}

64
user-service/src/main/java/com/mh/user/dto/ScreenRequestParamDTO.java

@ -0,0 +1,64 @@
package com.mh.user.dto;
/**
* @author LJF
* @version 1.0
* @project mh_esi
* @description 大屏请求参数
* @date 2024-09-24 14:12:01
*/
public class ScreenRequestParamDTO {
/**
* 查询类型now:当前数据, day:日数据, week:周数据, month:月数据, year:年数据
*/
private String timeType;
private String startTime;
private String endTime;
private String projectId;
public String getProjectId() {
return projectId;
}
public void setProjectId(String projectId) {
this.projectId = projectId;
}
public String getTimeType() {
return timeType;
}
public void setTimeType(String timeType) {
this.timeType = timeType;
}
public String getStartTime() {
return startTime;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public String getEndTime() {
return endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
@Override
public String toString() {
return "ScreenRequestParamDTO{" +
"timeType='" + timeType + '\'' +
", startTime='" + startTime + '\'' +
", endTime='" + endTime + '\'' +
", projectId='" + projectId + '\'' +
'}';
}
}

2
user-service/src/main/java/com/mh/user/entity/DataResultEntity.java

@ -29,4 +29,6 @@ public class DataResultEntity {
private String havedUpdate; private String havedUpdate;
private String projectName; private String projectName;
private String projectId; private String projectId;
private String registerName;
private String registerAddr;
} }

8
user-service/src/main/java/com/mh/user/entity/DevicesManageEntity.java

@ -116,6 +116,10 @@ public class DevicesManageEntity implements Serializable {
*/ */
private Long projectId; private Long projectId;
private String factoryBarcode;
private String imuCode;
@Override @Override
public String toString() { public String toString() {
return "DevicesManageEntity{" + return "DevicesManageEntity{" +
@ -127,7 +131,7 @@ public class DevicesManageEntity implements Serializable {
", ratedRefrigerationCapacity=" + ratedRefrigerationCapacity + ", ratedRefrigerationCapacity=" + ratedRefrigerationCapacity +
", ratedCop=" + ratedCop + ", ratedCop=" + ratedCop +
", ratedFlow=" + ratedFlow + ", ratedFlow=" + ratedFlow +
", productionTime=" + productionTime + ", productionTime='" + productionTime + '\'' +
", createTime=" + createTime + ", createTime=" + createTime +
", updateTime=" + updateTime + ", updateTime=" + updateTime +
", createBy='" + createBy + '\'' + ", createBy='" + createBy + '\'' +
@ -137,6 +141,8 @@ public class DevicesManageEntity implements Serializable {
", grade=" + grade + ", grade=" + grade +
", systemId=" + systemId + ", systemId=" + systemId +
", projectId=" + projectId + ", projectId=" + projectId +
", factoryBarcode='" + factoryBarcode + '\'' +
", imuCode='" + imuCode + '\'' +
'}'; '}';
} }
} }

2
user-service/src/main/java/com/mh/user/job/DealDataJob.java

@ -83,7 +83,7 @@ public class DealDataJob {
dealDataService.proDataResult(curDate,projectId); //1珠江酒店,2广合,3广大 dealDataService.proDataResult(curDate,projectId); //1珠江酒店,2广合,3广大
} }
} }
log.info("---------能效监测定时汇总,每一分钟!"+curDate); log.info("---------能效监测定时汇总,每一分钟!{}", curDate);
} catch (Exception e) { } catch (Exception e) {
log.error("能效监测定时汇总异常", e); log.error("能效监测定时汇总异常", e);
} }

4
user-service/src/main/java/com/mh/user/mapper/DataResultMapper.java

@ -14,8 +14,8 @@ import java.util.List;
public interface DataResultMapper extends BaseMapper<DataResultEntity> { public interface DataResultMapper extends BaseMapper<DataResultEntity> {
//保存水电表等数据 //保存水电表等数据
@Insert("insert into data_result(device_addr,device_type,project_id,last_value,last_date,cur_value,cur_date,ratio,calc_value,grade) values (" + @Insert("insert into data_result(device_addr,device_type,project_id,last_value,last_date,cur_value,cur_date,ratio,calc_value,grade,register_addr, register_name) values (" +
" #{deviceAddr},#{deviceType},#{projectId},#{lastValue},#{lastDate},#{curValue},#{curDate},#{ratio},#{calcValue},#{grade})") " #{deviceAddr},#{deviceType},#{projectId},#{lastValue},#{lastDate},#{curValue},#{curDate},#{ratio},#{calcValue},#{grade}, #{registerAddr}, #{registerName})")
void saveDataResult(DataResultEntity dataResultEntity); void saveDataResult(DataResultEntity dataResultEntity);
@Update("<script>" + @Update("<script>" +

11
user-service/src/main/java/com/mh/user/mapper/MeterManageMapper.java

@ -3,6 +3,8 @@ package com.mh.user.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mh.user.entity.MeterManageEntity; import com.mh.user.entity.MeterManageEntity;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
/** /**
* @author LJF * @author LJF
@ -13,4 +15,13 @@ import org.apache.ibatis.annotations.Mapper;
*/ */
@Mapper @Mapper
public interface MeterManageMapper extends BaseMapper<MeterManageEntity> { public interface MeterManageMapper extends BaseMapper<MeterManageEntity> {
@Select("select * from meter_manage where mt_code=#{deviceAddr} " +
" and mt_type=#{deviceType} " +
" and project_id=#{projectId} " +
" and register_addr = #{registerAddr} ")
MeterManageEntity selectDevice(@Param("deviceAddr") String deviceAddr,
@Param("deviceType") String deviceType,
@Param("projectId") String projectId,
@Param("registerAddr") String registerAddr);
} }

238
user-service/src/main/java/com/mh/user/mapper/ScreenMapper.java

@ -0,0 +1,238 @@
package com.mh.user.mapper;
import com.mh.user.dto.ScreenRequestParamDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import java.util.Map;
/**
* @author LJF
* @version 1.0
* @project mh_esi
* @description 大屏服务mapper
* @date 2024-09-24 14:54:06
*/
public interface ScreenMapper {
@Select("with projectmttypes as ( " +
" select " +
" project_id, " +
" count(distinct mt_type) as distinct_mt_types " +
" from " +
" meter_manage mm " +
" where " +
" mm.mt_type in (1, 2) " +
" and mt_is_sum = 1 " +
" and mm.grade between 40 and 49 " +
" and mm.system_id = 1 " +
" group by " +
" project_id " +
" having " +
" count(distinct mt_type) = 2 " +
") " +
"select " +
" pi2.id, " +
" pi2.project_name, " +
" t.mt_type, " +
" t.cur_value, " +
" t.cur_time " +
"from " +
" project_info pi2 " +
"left join projectmttypes pmt on pi2.id = pmt.project_id " +
"left join ( " +
" select " +
" project_id, " +
" mt_type, " +
" sum(isnull(cur_value, 0)) as cur_value, " +
" cur_time " +
" from " +
" meter_manage mm " +
" where " +
" mm.mt_type in (1, 2) " +
" and mt_is_sum = 1 " +
" and mm.grade between 140 and 149 " +
" and mm.system_id = 1 " +
" and datepart(hour, mm.cur_time) = datepart(hour, getdate()) " +
" group by " +
" project_id, " +
" mt_type, " +
" cur_time " +
") t on pi2.id = t.project_id " +
"where " +
" pmt.project_id is not null; ")
List<Map<String, Object>> queryNowData();
@Select("select " +
" pi2.project_name, " +
" pi2.longitude, " +
" pi2.latitude, " +
" isnull(t.fault, 0) as fault " +
"from " +
" project_info pi2 " +
"left join ( " +
"select " +
" project_id, " +
" system_id, " +
" case " +
" when sum(cur_value) > 0 then 1 " +
" else 0 " +
" end as fault " +
"from " +
" meter_manage mm " +
"where " +
" mm.system_id = 1 " +
" and mm.grade between 50 and 59 " +
" and system_id = 1 " +
"group by " +
" project_id, " +
" system_id " +
") t on pi2.id = t.project_id and pi2.system_id = t.system_id ")
List<Map<String, Object>> queryProjectData();
@Select("select " +
" cur_date as curDate, " +
" elect, " +
" cl, " +
" cop " +
"from " +
" energy_data_day edm " +
"where " +
" cur_date between #{startTime} and #{endTime} " +
" and project_id = #{projectId} " +
"order by " +
" cur_date")
List<Map<String, Object>> queryMonthData(ScreenRequestParamDTO screenRequestParamDTO);
/**
*
* @param screenRequestParamDTO
* @return
*/
@Select("<script>" +
"WITH ProjectMTType1 AS ( " +
"SELECT " +
" project_id " +
"FROM " +
" meter_manage mm " +
"WHERE " +
" mm.mt_type = 1 " +
" AND mt_is_sum = 1 " +
" AND mm.grade BETWEEN 40 AND 49 " +
" AND mm.system_id = 1 " +
"GROUP BY " +
" project_id " +
"HAVING " +
" COUNT(DISTINCT mt_type) = 1 " +
"), " +
"ProjectMTType2 AS ( " +
"SELECT " +
" project_id " +
"FROM " +
" meter_manage mm " +
"WHERE " +
" mm.mt_type = 2 " +
" AND mt_is_sum = 1 " +
" AND mm.grade BETWEEN 40 AND 49 " +
" AND mm.system_id = 1 " +
"GROUP BY " +
" project_id " +
"HAVING " +
" COUNT(DISTINCT mt_type) = 1 " +
") " +
"SELECT " +
" pi2.id, " +
" pi2.project_name as projectName, " +
" isnull(edd.elect, " +
" 0) as elect " +
"FROM " +
" ProjectMTType1 pmt1 " +
"left join project_info pi2 on " +
" pi2.id = pmt1.project_id " +
"left join energy_data_day edd on " +
" edd.project_id = pmt1.project_id " +
" and edd.cur_date between #{startTime} and #{endTime} " +
"WHERE " +
" NOT EXISTS ( " +
" SELECT " +
" 1 " +
" FROM " +
" ProjectMTType2 pmt2 " +
" WHERE " +
" pmt2.project_id = pmt1.project_id " +
" ) " +
"<if test='projectId != null and projectId != \"\"'>" +
" and pi2.id = #{projectId} " +
"</if>" +
"</script>")
List<Map<String, Object>> savingEnergy(ScreenRequestParamDTO screenRequestParamDTO);
@Select("select " +
" t1.cur_date as curDate, " +
" t1.sumValue as curValue, " +
" isnull(t2.sumValue, 0) as lastValue, " +
" case " +
" when t2.sumValue > 0 then concat(convert(decimal(18, 2),(t1.sumValue - t2.sumValue)/ t2.sumValue * 100), '%') " +
" when (t1.sumValue - t2.sumValue) = 0 then '0.00%' " +
" else '同期无数据' " +
" end yoy " +
"from " +
" ( " +
" select " +
" cur_date, " +
" sum(elect) as sumValue " +
" from " +
" energy_data_day edd " +
" where " +
" edd.cur_date between #{startTime} and #{endTime} " +
" and edd.project_id = #{projectId} " +
" group by " +
" cur_date " +
") t1 " +
"left join ( " +
" select " +
" convert(varchar(10), " +
" dateadd(YEAR, 1, cur_date), " +
" 120) as cur_date , " +
" case " +
" when elect is null then '同期无数据' " +
" else sum(elect) " +
" end " +
" sumValue " +
" from " +
" energy_data_day edd " +
" where " +
" edd.cur_date between #{lastStartTime} and #{lastEndTime} " +
" and edd.project_id = #{projectId} " +
" group by " +
" cur_date, elect " +
") t2 on " +
" t1.cur_date = t2.cur_date order by cur_date ")
List<Map<String, Object>> savingYoyEnergyData(@Param("projectId") String projectId,
@Param("startTime") String startTime,
@Param("endTime") String endTime,
@Param("lastStartTime") String lastStartTime,
@Param("lastEndTime") String lastEndTime);
@Select("select " +
" pi2.project_name, " +
" t1.other_name " +
"from " +
" project_info pi2 " +
"join ( " +
" select " +
" project_id, " +
" other_name " +
" from " +
" meter_manage mm " +
" where " +
" grade between 50 and 59 " +
" and cur_value = 1 " +
" and day(cur_time) = day(getdate()) " +
" group by " +
" project_id, " +
" other_name " +
" ) t1 on " +
" pi2.id = t1.project_id ")
List<Map<String, Object>> queryFaultList();
}

48
user-service/src/main/java/com/mh/user/service/ScreenService.java

@ -0,0 +1,48 @@
package com.mh.user.service;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.mh.user.dto.ScreenRequestParamDTO;
/**
* @author LJF
* @version 1.0
* @project mh_esi
* @description 大屏服务类
* @date 2024-09-24 14:02:44
*/
public interface ScreenService {
/**
* 获取项目概况以及当月项目数据
* @param screenRequestParamDTO
* @return
*/
JSONArray energyData(ScreenRequestParamDTO screenRequestParamDTO);
/**
* 项目坐标以及是否有故障
* @return
*/
JSONArray projectData();
/**
* 当日节能量概况
* @param screenRequestParamDTO
* @return
*/
JSONArray savingEnergy(ScreenRequestParamDTO screenRequestParamDTO);
/**
* 获取节能量同比
* @param screenRequestParamDTO
* @return
*/
JSONArray savingYoyEnergyData(ScreenRequestParamDTO screenRequestParamDTO);
/**
* 故障详情
* @return
*/
JSONArray faultList();
}

95
user-service/src/main/java/com/mh/user/service/impl/DataResultServiceImpl.java

@ -1,9 +1,6 @@
package com.mh.user.service.impl; package com.mh.user.service.impl;
import com.mh.user.entity.DataResultClEntity; import com.mh.user.entity.*;
import com.mh.user.entity.DataResultEntity;
import com.mh.user.entity.DataResultChEntity;
import com.mh.user.entity.DeviceInstallEntity;
import com.mh.user.mapper.*; import com.mh.user.mapper.*;
import com.mh.user.service.DataResultService; import com.mh.user.service.DataResultService;
import com.mh.user.service.DeviceInstallService; import com.mh.user.service.DeviceInstallService;
@ -57,6 +54,9 @@ public class DataResultServiceImpl implements DataResultService {
@Resource @Resource
DataResultNowMapper dataResultNowMapper; DataResultNowMapper dataResultNowMapper;
@Resource
MeterManageMapper meterManageMapper;
private final SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private final SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@Override @Override
@ -69,30 +69,26 @@ public class DataResultServiceImpl implements DataResultService {
dataResultEntity.setCurDate(date); dataResultEntity.setCurDate(date);
} }
//从安装表获取设备信息 //从安装表获取设备信息
DeviceInstallEntity deviceInstallEntity = deviceInstallMapper.selectDevice(dataResultEntity.getDeviceAddr(), dataResultEntity.getDeviceType(), dataResultEntity.getProjectId()); MeterManageEntity meterManageEntity = meterManageMapper.selectDevice(dataResultEntity.getDeviceAddr(),
dataResultEntity.getDeviceType(),
dataResultEntity.getProjectId(),
dataResultEntity.getRegisterAddr());
//判断是否有记录 //判断是否有记录
// int r = dataResultMapper.selectDataResultCount(sdf1.format(dataResultEntity.getCurDate()),
// dataResultEntity.getDeviceAddr(),dataResultEntity.getDeviceType());
// if (r==0){//插入记录
DataResultEntity data = new DataResultEntity(); DataResultEntity data = new DataResultEntity();
if (dataResultEntity.getDeviceType().equals("水表") || dataResultEntity.getDeviceType().equals("电表")) { //通讯地址
// String str=dataResultEntity.getDeviceAddr(); data.setDeviceAddr(dataResultEntity.getDeviceAddr()); //通讯地址
// data.setDeviceAddr(str.substring(str.length()-8,str.length())); //通讯地址
data.setDeviceAddr(dataResultEntity.getDeviceAddr()); //通讯地址
} else {
data.setDeviceAddr(dataResultEntity.getDeviceAddr()); //通讯地址
}
data.setDeviceType(dataResultEntity.getDeviceType()); //设备类型 data.setDeviceType(dataResultEntity.getDeviceType()); //设备类型
String curDate = sdf1.format(dataResultEntity.getCurDate()); String curDate = sdf1.format(dataResultEntity.getCurDate());
data.setCurDate(sdf1.parse(curDate));//当前日期 data.setCurDate(sdf1.parse(curDate));//当前日期
data.setCurValue(dataResultEntity.getCurValue()); //当前读数 data.setCurValue(dataResultEntity.getCurValue()); //当前读数
data.setProjectId(deviceInstallEntity.getProjectId()); //楼栋编号 data.setProjectId(String.valueOf(meterManageEntity.getProjectId())); //楼栋编号
data.setRatio(deviceInstallEntity.getRatio()); //倍率 data.setRatio(BigDecimal.valueOf(meterManageEntity.getMtRatio())); //倍率
BigDecimal lastValue = deviceInstallEntity.getLastValue(); //安装基表上次读数 BigDecimal lastValue = meterManageEntity.getCurValue(); //安装基表上次读数
BigDecimal calcValue = dataResultEntity.getCurValue().subtract(lastValue); //计算用量 BigDecimal calcValue = dataResultEntity.getCurValue().subtract(lastValue); //计算用量
data.setCalcValue(calcValue);//用量 data.setCalcValue(calcValue);//用量
if (deviceInstallEntity.getLastDate() != null) {//上次抄表日期 if (meterManageEntity.getCurTime() != null) {//上次抄表日期
String lastDate = sdf1.format(deviceInstallEntity.getLastDate()); String lastDate = sdf1.format(meterManageEntity.getCurTime());
data.setLastDate(sdf1.parse(lastDate)); data.setLastDate(sdf1.parse(lastDate));
} else { } else {
String lastDate = sdf1.format(date); String lastDate = sdf1.format(date);
@ -100,23 +96,11 @@ public class DataResultServiceImpl implements DataResultService {
} }
data.setLastValue(lastValue);//上次读数 data.setLastValue(lastValue);//上次读数
data.setGrade(dataResultEntity.getGrade());//级别 data.setGrade(dataResultEntity.getGrade());//级别
data.setRegisterAddr(dataResultEntity.getRegisterAddr());
data.setRegisterName(dataResultEntity.getRegisterName());
dataResultMapper.saveDataResult(data); //插入新的记录 dataResultMapper.saveDataResult(data); //插入新的记录
// }else {//修改记录的curValue、calcValue
// DataResultEntity data2=dataResultMapper.selectDataResult(sdf1.format(dataResultEntity.getCurDate()),dataResultEntity.getDeviceAddr(),dataResultEntity.getDeviceType());
// double lastValue=data2.getLastValue(); //安装基表上次读数
// double calcValue=dataResultEntity.getCurValue()-lastValue; //计算用量
// String curDate=sdf1.format(dataResultEntity.getCurDate());
// data2.setCurDate(sdf1.parse(curDate));//当前日期
// data2.setCurValue(dataResultEntity.getCurValue());//当前读数
// data2.setCalcValue(calcValue);//用量
//
// dataResultMapper.updateDataResult(data2); //更新记录
// }
//修改安装表中lastValue,lastDate的值
deviceInstallMapper.updateLastValue(deviceInstallEntity.getId(), dataResultEntity.getCurValue(), date);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); log.error("保存数据异常", e);
} }
} }
@ -141,23 +125,34 @@ public class DataResultServiceImpl implements DataResultService {
public void saveDataResultCl(DataResultClEntity dataResultClEntity) throws ParseException { public void saveDataResultCl(DataResultClEntity dataResultClEntity) throws ParseException {
try { try {
//获取系统日期 //获取系统日期
Date date = new Date();
if (dataResultClEntity.getCurDate() == null) {
dataResultClEntity.setCurDate(date);
}
//从安装表获取设备信息 //从安装表获取设备信息
DeviceInstallEntity deviceInstallEntity = deviceInstallMapper.selectDevice(dataResultClEntity.getDeviceAddr(), dataResultClEntity.getDeviceType(), dataResultClEntity.getProjectId()); // DeviceInstallEntity deviceInstallEntity = deviceInstallMapper.selectDevice(dataResultClEntity.getDeviceAddr(), dataResultClEntity.getDeviceType(), dataResultClEntity.getProjectId());
if (null == deviceInstallEntity) { MeterManageEntity meterManageEntity = meterManageMapper.selectDevice(dataResultClEntity.getDeviceAddr(),
dataResultClEntity.getDeviceType(),
dataResultClEntity.getProjectId(),
dataResultClEntity.getRegisterAddr());
if (null == meterManageEntity) {
return; return;
} }
BigDecimal lastValue = deviceInstallEntity.getLastValue();
if (meterManageEntity.getCurTime() == null) {
Date date = new Date();
dataResultClEntity.setLastDate(date);
}
BigDecimal lastValue = meterManageEntity.getCurValue();
BigDecimal curValue = dataResultClEntity.getCurValue(); BigDecimal curValue = dataResultClEntity.getCurValue();
dataResultClEntity.setRatio(deviceInstallEntity.getRatio()); //倍率 dataResultClEntity.setLastValue(lastValue);
dataResultClEntity.setLastDate(meterManageEntity.getCurTime());
dataResultClEntity.setRatio(BigDecimal.valueOf(meterManageEntity.getMtRatio())); //倍率
dataResultClEntity.setCalcValue(curValue.subtract(lastValue).multiply(dataResultClEntity.getRatio()));
// if ((curValue-lastValue)<1000 && (curValue-lastValue)>=0){ // if ((curValue-lastValue)<1000 && (curValue-lastValue)>=0){
if (curValue.compareTo(lastValue) >= 0) { if (curValue.compareTo(lastValue) >= 0) {
dataResultClMapper.saveDataResultCl(dataResultClEntity); //插入新的记录 dataResultClMapper.saveDataResultCl(dataResultClEntity); //插入新的记录
//修改安装表中lastValue,lastDate的值 //修改安装表中lastValue,lastDate的值
deviceInstallMapper.updateLastValue(deviceInstallEntity.getId(), curValue, date); // deviceInstallMapper.updateLastValue(meterManageEntity.getId(), curValue, date);
} }
} catch (Exception e) { } catch (Exception e) {
@ -175,10 +170,14 @@ public class DataResultServiceImpl implements DataResultService {
dataResultClEntity.setCurDate(date); dataResultClEntity.setCurDate(date);
} }
//从安装表获取设备信息 //从安装表获取设备信息
DeviceInstallEntity deviceInstallEntity = deviceInstallMapper.selectDevice(dataResultClEntity.getDeviceAddr(), dataResultClEntity.getDeviceType(), dataResultClEntity.getProjectId()); // DeviceInstallEntity deviceInstallEntity = deviceInstallMapper.selectDevice(dataResultClEntity.getDeviceAddr(), dataResultClEntity.getDeviceType(), dataResultClEntity.getProjectId());
dataResultClEntity.setRatio(deviceInstallEntity.getRatio()); //倍率 MeterManageEntity meterManageEntity = meterManageMapper.selectDevice(dataResultClEntity.getDeviceAddr(),
dataResultClEntity.getDeviceType(),
dataResultClEntity.getProjectId(),
dataResultClEntity.getRegisterAddr());
dataResultClEntity.setRatio(BigDecimal.valueOf(meterManageEntity.getMtRatio())); //倍率
String curDate = DateUtil.dateToString(dataResultClEntity.getCurDate(), "yyyy-MM-dd HH:mm:ss"); String curDate = DateUtil.dateToString(dataResultClEntity.getCurDate(), "yyyy-MM-dd HH:mm:ss");
String deviceAddr = deviceInstallEntity.getDeviceAddr(); String deviceAddr = meterManageEntity.getMtCode();
String registerAddr = dataResultClEntity.getRegisterAddr(); String registerAddr = dataResultClEntity.getRegisterAddr();
String projectId = dataResultClEntity.getProjectId(); String projectId = dataResultClEntity.getProjectId();
int row = dataResultClBakMapper.selectDataResultChBakCount(curDate, deviceAddr, registerAddr, projectId);//无记录 int row = dataResultClBakMapper.selectDataResultChBakCount(curDate, deviceAddr, registerAddr, projectId);//无记录
@ -203,7 +202,7 @@ public class DataResultServiceImpl implements DataResultService {
//从安装表获取设备信息 //从安装表获取设备信息
String deviceAddr = dataResultChEntity.getDeviceAddr(); String deviceAddr = dataResultChEntity.getDeviceAddr();
String registerAddr = dataResultChEntity.getRegisterAddr(); String registerAddr = dataResultChEntity.getRegisterAddr();
String curDate = DateUtil.dateToString(dataResultChEntity.getCurDate(), "yyyy-MM-dd HH:mm:ss"); String curDate = DateUtil.dateToString(dataResultChEntity.getCurDate(), "yyyy-MM-dd HH:mm:00");
String projectId = dataResultChEntity.getProjectId(); String projectId = dataResultChEntity.getProjectId();
int row = dataResultChMapper.selectDataResultChCount(curDate, deviceAddr, registerAddr, projectId, dataResultChEntity.getGrade());//无记录 int row = dataResultChMapper.selectDataResultChCount(curDate, deviceAddr, registerAddr, projectId, dataResultChEntity.getGrade());//无记录
if (row == 0) { if (row == 0) {

12
user-service/src/main/java/com/mh/user/service/impl/GatewayManageServiceImpl.java

@ -39,10 +39,14 @@ public class GatewayManageServiceImpl implements GatewayManageService {
if (pageNum != 0) { if (pageNum != 0) {
PageHelper.startPage(pageNum, pageSize); PageHelper.startPage(pageNum, pageSize);
} }
List<GatewayManageEntity> manageEntities = gatewayManageMapper.selectList( QueryWrapper<GatewayManageEntity> queryWrapper = new QueryWrapper<>();
new QueryWrapper<GatewayManageEntity>() if (!StringUtils.isBlank(systemID)) {
.eq("system_id", systemID) queryWrapper.eq("system_id", systemID);
.eq("project_id", projectId) }
if (!StringUtils.isBlank(projectId)) {
queryWrapper.eq("project_id", projectId);
}
List<GatewayManageEntity> manageEntities = gatewayManageMapper.selectList(queryWrapper
.orderByDesc("create_time")); .orderByDesc("create_time"));
return MybatisPageHelper.getPageResult(pageRequest, new PageInfo<>(manageEntities)); return MybatisPageHelper.getPageResult(pageRequest, new PageInfo<>(manageEntities));
} }

2
user-service/src/main/java/com/mh/user/service/impl/MeterManageServiceImpl.java

@ -43,7 +43,7 @@ public class MeterManageServiceImpl implements MeterManageService {
if (!StringUtils.isBlank(projectId)) { if (!StringUtils.isBlank(projectId)) {
queryWrapper.eq("project_id", projectId); queryWrapper.eq("project_id", projectId);
} }
queryWrapper.eq("is_use", 1); queryWrapper.eq("is_use", 0);
return meterManageMapper.selectList(queryWrapper.orderByDesc("create_time")); return meterManageMapper.selectList(queryWrapper.orderByDesc("create_time"));
} }

210
user-service/src/main/java/com/mh/user/service/impl/ScreenServiceImpl.java

@ -0,0 +1,210 @@
package com.mh.user.service.impl;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.mh.user.dto.ScreenRequestParamDTO;
import com.mh.user.mapper.ScreenMapper;
import com.mh.user.service.ScreenService;
import com.mh.user.utils.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author LJF
* @version 1.0
* @project mh_esi
* @description 大屏服务实现类
* @date 2024-09-24 14:52:28
*/
@Slf4j
@Service
public class ScreenServiceImpl implements ScreenService {
@Resource
private ScreenMapper screenMapper;
@Override
public JSONArray faultList() {
JSONArray resultJson = new JSONArray();
List<Map<String, Object>> faultList = screenMapper.queryFaultList();
if (faultList.isEmpty()) {
return resultJson;
}
// 根据项目名称分组
Map<Object, List<Map<String, Object>>> projectIds = faultList.stream().collect(Collectors.groupingBy(map -> map.get("project_name")));
for (Map.Entry<Object, List<Map<String, Object>>> entry : projectIds.entrySet()) {
String projectName = (String) entry.getKey();
List<Map<String, Object>> projectId = faultList.stream().filter(map -> map.get("project_name").equals(projectName)).collect(Collectors.toList());
JSONObject data = new JSONObject();
data.put("projectName", projectName);
data.put("faultNum", projectId.size());
String[] faultListStr = new String[projectId.size()];
for (int i = 0; i < projectId.size(); i++) {
faultListStr[i] = (String) projectId.get(i).get("other_name");
}
data.put("faultList", faultListStr);
resultJson.add(data);
}
return resultJson;
}
@Override
public JSONArray savingYoyEnergyData(ScreenRequestParamDTO screenRequestParamDTO) {
// 判断类型
JSONArray resultJson = new JSONArray();
switch (screenRequestParamDTO.getTimeType()) {
case "day":
String projectId = screenRequestParamDTO.getProjectId();
String startTime = screenRequestParamDTO.getStartTime();
String endTime = screenRequestParamDTO.getEndTime();
String lastStartTime = DateUtil.yoyDate(startTime + " 00:00:00").substring(0, 10);
String lastEndTime = DateUtil.yoyDate(endTime+ " 23:59:59").substring(0, 10);
List<Map<String, Object>> monthData = screenMapper.savingYoyEnergyData(projectId, startTime, endTime, lastStartTime, lastEndTime);
resultJson.add(monthData);
break;
default:
break;
}
return resultJson;
}
@Override
public JSONArray savingEnergy(ScreenRequestParamDTO screenRequestParamDTO) {
// 判断类型
JSONArray resultJson = new JSONArray();
switch (screenRequestParamDTO.getTimeType()) {
case "day":
screenRequestParamDTO.setStartTime(screenRequestParamDTO.getStartTime());
screenRequestParamDTO.setEndTime(screenRequestParamDTO.getEndTime());
List<Map<String, Object>> monthData = screenMapper.savingEnergy(screenRequestParamDTO);
resultJson.add(monthData);
break;
default:
break;
}
return resultJson;
}
@Override
public JSONArray projectData() {
JSONArray resultJson = new JSONArray();
List<Map<String, Object>> projectData = screenMapper.queryProjectData();
if (projectData.isEmpty()) {
return resultJson;
}
for (Map<String, Object> map : projectData) {
JSONObject data = new JSONObject();
float[] ll = new float[2];
data.put("name", map.get("project_name"));
ll[0] = Float.parseFloat(map.get("longitude").toString());
ll[1] = Float.parseFloat(map.get("latitude").toString());
data.put("value", ll);
data.put("fault", map.get("fault"));
resultJson.add(data);
}
return resultJson;
}
@Override
public JSONArray energyData(ScreenRequestParamDTO screenRequestParamDTO) {
// 判断类型
JSONArray resultJson = new JSONArray();
switch (screenRequestParamDTO.getTimeType()) {
case "now":
getNowData(resultJson);
break;
case "day":
screenRequestParamDTO.setStartTime(screenRequestParamDTO.getStartTime());
screenRequestParamDTO.setEndTime(screenRequestParamDTO.getEndTime());
getMonthData(resultJson, screenRequestParamDTO);
break;
default:
break;
}
return resultJson;
}
private void getMonthData(JSONArray resultJson, ScreenRequestParamDTO screenRequestParamDTO) {
List<Map<String, Object>> monthData = screenMapper.queryMonthData(screenRequestParamDTO);
resultJson.add(monthData);
}
private void getNowData(JSONArray resultJson) {
List<Map<String, Object>> nowData = screenMapper.queryNowData();
if (nowData.isEmpty()) {
return;
}
// 根据项目名进行分组
Map<Object, List<Map<String, Object>>> projectIds = nowData.stream().collect(Collectors.groupingBy(map -> map.get("id")));
// 根据项目名获取对应的冷量计、电表数据,计算EER
for (Map.Entry<Object, List<Map<String, Object>>> entry : projectIds.entrySet()) {
Long proId = (Long) entry.getKey();
List<Map<String, Object>> projectId = nowData.stream().filter(map -> map.get("id").equals(proId)).collect(Collectors.toList());
if (projectId.isEmpty()) {
continue;
}
String projectName = (String) projectId.get(0).get("project_name");
log.info("项目名:{}", projectName);
String cooling = "未采集";
String ele = "未采集";
JSONObject data = new JSONObject();
data.put("projectName", projectName);
for (Map<String, Object> map : projectId) {
// 获取冷量计:2、电表数据:1
Long mtType = (Long) map.get("mt_type");
if (null == mtType) {
continue;
}
if (1 == mtType) {
ele = ((BigDecimal) map.get("cur_value")).setScale(2, RoundingMode.HALF_UP).toString();
}
if (2 == mtType) {
cooling = ((BigDecimal) map.get("cur_value")).setScale(2, RoundingMode.HALF_UP).toString();
}
}
JSONObject dataDetail = new JSONObject();
dataDetail.clear();
HashMap<String, Object> map = new HashMap<>();
map.put("name", projectName);
map.put("value", ele);
dataDetail.put("ele", new HashMap<>(map));
map.clear();
map.put("name", projectName);
map.put("value", cooling);
dataDetail.put("cooling", new HashMap<>(map));
// 计算EER
map.clear();
if ("未采集".equals(cooling) || "未采集".equals(ele)) {
map.put("name", projectName);
map.put("value", "未采集");
dataDetail.put("eer", new HashMap<>(map));
} else {
double coolingValue = Double.parseDouble(cooling);
double eleValue = Double.parseDouble(ele);
double eer = 0;
if (eleValue <= 0 || coolingValue <= 0) {
eer = 0;
} else {
eer = coolingValue / eleValue;
}
map.put("name", projectName);
map.put("value", (new BigDecimal(eer).setScale(2, RoundingMode.HALF_UP)).toString());
dataDetail.put("eer", new HashMap<>(map));
}
data.put("data", dataDetail);
resultJson.add(data);
}
}
}

58
user-service/src/main/java/com/mh/user/strategy/EleProtocolStrategy.java

@ -113,13 +113,7 @@ public class EleProtocolStrategy implements ProtocolStrategy {
String meterId = checkStr.substring(12, 14) + checkStr.substring(10, 12) + checkStr.substring(8, 10) String meterId = checkStr.substring(12, 14) + checkStr.substring(10, 12) + checkStr.substring(8, 10)
+ checkStr.substring(6, 8) + checkStr.substring(4, 6) + checkStr.substring(2, 4); + checkStr.substring(6, 8) + checkStr.substring(4, 6) + checkStr.substring(2, 4);
meterId = String.format("%012d", Long.parseLong(meterId)); meterId = String.format("%012d", Long.parseLong(meterId));
StringBuilder stringBuilder = getStringBuilder(receiveData, checkStr); data = getAnalysisData(receiveData, checkStr, meterId);
data = stringBuilder.toString();
data = ExchangeStringUtil.cutThree(data);
// 0 代表前面补充0,4 代表长度为4,d 代表参数为正数型
data = String.format("%08d", Long.parseLong(data));
data = data.substring(0, 6) + "." + data.substring(6, 8);
log.info("电表表号:{},电表读数:{}", meterId, data);
} else { } else {
log.info("电表报文检验失败: {}", receiveData); log.info("电表报文检验失败: {}", receiveData);
} }
@ -132,20 +126,44 @@ public class EleProtocolStrategy implements ProtocolStrategy {
return data; return data;
} }
private static StringBuilder getStringBuilder(String receiveData, String checkStr) { private static String getAnalysisData(String receiveData, String checkStr, String meterId) {
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
if (receiveData.length() == 36 || receiveData.length() == 34) { // 累计总读数据:FE FE FE FE 68 69 04 00 70 01 08 68 81 06 43 C3 A5 33 33 33 81 16
for (int i = 0; i < 4; i++) { // 瞬时有功功率:FE FE FE FE 68 69 04 00 70 01 08 68 81 05 63 E9 33 33 33 21 16
String data1 = checkStr.substring(32 - 2 * (i + 1), 32 - 2 * i); // 判断属于哪个数据标识
stringBuilder.append(data1); String resultData = Constant.FAIL;
} if (receiveData.length() > 24) {
} else { String identifyCode = ExchangeStringUtil.changePosition(ExchangeStringUtil.cutThree(receiveData.substring(20, 24)));
for (int i = 0; i < 4; i++) { switch (identifyCode) {
String data1 = checkStr.substring(36 - 2 * (i + 1), 36 - 2 * i); case "9010":
stringBuilder.append(data1); // 累计总读数据
for (int i = 0; i < 4; i++) {
String data1 = checkStr.substring(32 - 2 * (i + 1), 32 - 2 * i);
stringBuilder.append(data1);
}
resultData = stringBuilder.toString();
resultData = ExchangeStringUtil.cutThree(resultData);
// 0 代表前面补充0,4 代表长度为4,d 代表参数为正数型
resultData = String.format("%08d", Long.parseLong(resultData));
resultData = resultData.substring(0, 6) + "." + resultData.substring(6, 8);
log.info("电表表号:{},电表累计总量读数:{}", meterId, resultData);
break;
case "B630":
// 瞬时有功功率
for (int i = 0; i < 3; i++) {
String data1 = checkStr.substring(30 - 2 * (i + 1), 30 - 2 * i);
stringBuilder.append(data1);
}
resultData = stringBuilder.toString();
resultData = ExchangeStringUtil.cutThree(resultData);
// 0 代表前面补充0,4 代表长度为4,d 代表参数为正数型
resultData = String.format("%06d", Long.parseLong(resultData));
resultData = resultData.substring(0, 2) + "." + resultData.substring(2, 6);
log.info("电表表号:{},电表瞬时有功功率读数:{}", meterId, resultData);
break;
} }
} }
return stringBuilder; return resultData;
} }
/** /**
@ -160,11 +178,13 @@ public class EleProtocolStrategy implements ProtocolStrategy {
try { try {
DataResultEntity dataResultEntity = new DataResultEntity(); DataResultEntity dataResultEntity = new DataResultEntity();
dataResultEntity.setDeviceAddr(deviceCodeParam.getDeviceAddr()); //通讯编号 dataResultEntity.setDeviceAddr(deviceCodeParam.getDeviceAddr()); //通讯编号
dataResultEntity.setDeviceType("电表"); //类型 dataResultEntity.setDeviceType(deviceCodeParam.getDeviceType()); //类型
dataResultEntity.setProjectId(deviceCodeParam.getProjectId()); //所属项目 dataResultEntity.setProjectId(deviceCodeParam.getProjectId()); //所属项目
dataResultEntity.setCurValue(new BigDecimal(dataStr)); //当前读数 dataResultEntity.setCurValue(new BigDecimal(dataStr)); //当前读数
dataResultEntity.setCurDate(sdf1.parse(dateStr)); //当前日期 dataResultEntity.setCurDate(sdf1.parse(dateStr)); //当前日期
dataResultEntity.setGrade(deviceCodeParam.getGrade()); dataResultEntity.setGrade(deviceCodeParam.getGrade());
dataResultEntity.setRegisterAddr(deviceCodeParam.getRegisterAddr());
dataResultEntity.setRegisterName(deviceCodeParam.getRegisterName());
String projectName = projectInfoService.selectName(deviceCodeParam.getProjectId()); String projectName = projectInfoService.selectName(deviceCodeParam.getProjectId());
log.info("电表==>{},读数==>{},项目名称==>{}", deviceCodeParam.getDeviceAddr(), dataStr, projectName); log.info("电表==>{},读数==>{},项目名称==>{}", deviceCodeParam.getDeviceAddr(), dataStr, projectName);
dataResultService.saveDataResult(dataResultEntity); dataResultService.saveDataResult(dataResultEntity);

9
user-service/src/main/java/com/mh/user/strategy/ModbusProtocolStrategy.java

@ -158,10 +158,10 @@ public void initialDataResultCh(DeviceCodeParamEntity deviceCodeParam, DataResul
dataResultCh.setFunCode(deviceCodeParam.getFunCode()); dataResultCh.setFunCode(deviceCodeParam.getFunCode());
dataResultCh.setProjectId(deviceCodeParam.getProjectId()); dataResultCh.setProjectId(deviceCodeParam.getProjectId());
String projectName = projectInfoService.selectName(deviceCodeParam.getProjectId()); String projectName = projectInfoService.selectName(deviceCodeParam.getProjectId());
log.info("冷水机:" + chillerAddr + ",状态:" + data + ",项目名称:" + projectName); log.info("冷水机:{},状态:{},项目名称:{}", chillerAddr, data, projectName);
dataResultService.saveDataResultChiller(dataResultCh); dataResultService.saveDataResultChiller(dataResultCh);
dataResultService.deleteDataResultNow(deviceCodeParam.getDeviceAddr(), deviceCodeParam.getDeviceType(), deviceCodeParam.getRegisterAddr(), deviceCodeParam.getProjectId()); // dataResultService.deleteDataResultNow(deviceCodeParam.getDeviceAddr(), deviceCodeParam.getDeviceType(), deviceCodeParam.getRegisterAddr(), deviceCodeParam.getProjectId());
log.info("冷水机保存成功!项目名称:" + projectName); log.info("冷水机保存成功!项目名称:{}", projectName);
} }
//解析冷量表 //解析冷量表
@ -185,6 +185,7 @@ public void analysisCloudOrder485(final String data, final DeviceCodeParamEntity
if (registerAddr.equals("0004") || registerAddr.equals("0014")) { if (registerAddr.equals("0004") || registerAddr.equals("0014")) {
dataResultCh.setDeviceAddr(cloudId); dataResultCh.setDeviceAddr(cloudId);
dataResultCh.setDeviceType(deviceCodeParam.getDeviceType()); dataResultCh.setDeviceType(deviceCodeParam.getDeviceType());
dataResultCh.setFunCode(deviceCodeParam.getFunCode());
dataResultCh.setCurDate(sdf1.parse(dateStr)); dataResultCh.setCurDate(sdf1.parse(dateStr));
dataResultCh.setCurValue(data); dataResultCh.setCurValue(data);
@ -200,7 +201,7 @@ public void analysisCloudOrder485(final String data, final DeviceCodeParamEntity
} else if (registerAddr.equals("0050")) { } else if (registerAddr.equals("0050")) {
dataResultCl.setDeviceAddr(cloudId); dataResultCl.setDeviceAddr(cloudId);
dataResultCl.setDeviceType(deviceCodeParam.getDeviceType()); dataResultCl.setDeviceType(deviceCodeParam.getDeviceType());
dataResultCh.setCurDate(sdf1.parse(dateStr)); dataResultCl.setCurDate(sdf1.parse(dateStr));
BigDecimal lData = new BigDecimal(data); BigDecimal lData = new BigDecimal(data);
dataResultCl.setCurValue(lData);//字符串转整型 dataResultCl.setCurValue(lData);//字符串转整型
dataResultCl.setRegisterAddr(deviceCodeParam.getRegisterAddr()); dataResultCl.setRegisterAddr(deviceCodeParam.getRegisterAddr());

16
user-service/src/main/java/com/mh/user/utils/DateUtil.java

@ -3,6 +3,8 @@ package com.mh.user.utils;
import java.text.ParseException; import java.text.ParseException;
import java.text.ParsePosition; import java.text.ParsePosition;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
@ -308,4 +310,18 @@ public class DateUtil {
} }
return null; return null;
} }
/*
* 获取同一个时间的上一个时间
* @param timerStr
* @return
*/
public static String yoyDate(String timerStr) {
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
DateTimeFormatter timeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate localDate = LocalDate.parse(timerStr, timeFormatter);
LocalDate localDate1 = localDate.minusYears(1);
return localDate1.format(timeFormatter1).concat(timerStr.substring(10));
}
} }

Loading…
Cancel
Save