人民企业智能电表水表
This commit is contained in:
parent
7d25e18967
commit
2d0d0b1ac4
|
@ -0,0 +1,41 @@
|
||||||
|
package com.nu.modules.tq.common.controller;
|
||||||
|
|
||||||
|
import com.nu.modules.tq.common.entity.TqDeviceInfo;
|
||||||
|
import com.nu.modules.tq.common.service.ITqDeviceInfoService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.jeecg.common.api.vo.Result;
|
||||||
|
import org.jeecg.common.system.base.controller.JeecgController;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/iot/tq/common/device")
|
||||||
|
public class DeviceInfoController extends JeecgController<TqDeviceInfo, ITqDeviceInfoService> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ITqDeviceInfoService service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取设备信息
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping(value = "/getAllMeter")
|
||||||
|
public Result<String> getAllMeter() {
|
||||||
|
service.getAllMeter();
|
||||||
|
return Result.OK("获取设备信息成功!");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 采集器设备信息
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping(value = "/getAllCollector")
|
||||||
|
public Result<String> getAllCollector() {
|
||||||
|
service.getAllCollector();
|
||||||
|
return Result.OK("获取采集器信息成功!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.nu.modules.tq.common.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 护理单元-物联管理-电水表-接口请求记录表
|
||||||
|
* @Author: caolei
|
||||||
|
* @Date: 2025-06-04
|
||||||
|
* @Version: V1.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName("nu_iot_tq_api_request_log")
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@ApiModel(value="nu_iot_tq_api_request_log", description="护理单元-物联管理-电水表-接口请求记录表")
|
||||||
|
public class TqApiLog implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
/**ID*/
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
@ApiModelProperty(value = "ID")
|
||||||
|
private Integer id;
|
||||||
|
private String oprId; //操作ID
|
||||||
|
private String cid; //采集器号
|
||||||
|
private String address; //表号
|
||||||
|
private Integer type; //类型 0清零 3抄表 10电表拉闸 11电表合闸 43水表开闸 53水表关闸
|
||||||
|
private String requestValue; //请求时的值
|
||||||
|
private String requestTime; //请求时间
|
||||||
|
private String requestStatus; //请求状态
|
||||||
|
private String requestRemark; //请求描述
|
||||||
|
private String resolveValue; //反馈值
|
||||||
|
private String resolveTime; //反馈时间
|
||||||
|
private String resolveStatus; //反馈状态
|
||||||
|
private String resolveRemark; //反馈描述
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.nu.modules.tq.common.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 护理单元-物联管理-电水表-配置信息
|
||||||
|
* @Author: caolei
|
||||||
|
* @Date: 2025-06-04
|
||||||
|
* @Version: V1.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName("nu_iot_tq_config")
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@ApiModel(value="nu_iot_tq_config", description="护理单元-物联管理-电水表-配置信息")
|
||||||
|
public class TqConfig implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
/**ID*/
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
@ApiModelProperty(value = "ID")
|
||||||
|
private Integer id;
|
||||||
|
private String requestUrl; //后台系统地址
|
||||||
|
private String authCode; //授权码
|
||||||
|
private String randomCode; //随机字符串,签名时需要
|
||||||
|
private String notifyUrl; //通知地址
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.nu.modules.tq.common.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 护理单元-物联管理-电水表-设备信息和采集器信息表
|
||||||
|
* @Author: caolei
|
||||||
|
* @Date: 2025-06-04
|
||||||
|
* @Version: V1.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName("nu_iot_tq_collector")
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@ApiModel(value="nu_iot_tq_collector", description="物联采集器")
|
||||||
|
public class TqDeviceInfo implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
/**ID*/
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
@ApiModelProperty(value = "ID")
|
||||||
|
private Integer id;
|
||||||
|
private String cid; //采集器号
|
||||||
|
private String online; //采集器-在线状态 true 在线 false 离线
|
||||||
|
private String csq ; //采集器-信号值 1-31 。 20以上算信号稳定
|
||||||
|
private String disconnectTime; //采集器-上次掉线时间 online = false 时
|
||||||
|
private String connectTime; //采集器-上次上线时间 online = true 时
|
||||||
|
private String remark; //备注
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.nu.modules.tq.common.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.nu.modules.tq.common.entity.TqApiLog;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 护理单元-物联管理-电水表配置信息
|
||||||
|
* @Author: jeecg-boot
|
||||||
|
* @Date: 2025-06-04
|
||||||
|
* @Version: V1.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface TqApiLogMapper extends BaseMapper<TqApiLog> {
|
||||||
|
TqApiLog getApiLog(TqApiLog tqApiLog);
|
||||||
|
int insert(TqApiLog tqApiLog);
|
||||||
|
int update(TqApiLog tqApiLog);
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.nu.modules.tq.common.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.nu.modules.tq.common.entity.TqConfig;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 护理单元-物联管理-电水表配置信息
|
||||||
|
* @Author: jeecg-boot
|
||||||
|
* @Date: 2025-06-04
|
||||||
|
* @Version: V1.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface TqConfigMapper extends BaseMapper<TqConfig> {
|
||||||
|
TqConfig getConfig();
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.nu.modules.tq.common.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.nu.modules.tq.common.entity.TqDeviceInfo;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 护理单元-物联管理-电水表配置信息
|
||||||
|
* @Author: jeecg-boot
|
||||||
|
* @Date: 2025-06-04
|
||||||
|
* @Version: V1.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface TqDeviceInfoMapper extends BaseMapper<TqDeviceInfo> {
|
||||||
|
TqDeviceInfo getDeviceInfo(TqDeviceInfo tqDeviceInfo);
|
||||||
|
int insert(TqDeviceInfo tqDeviceInfo);
|
||||||
|
int update(TqDeviceInfo tqDeviceInfo);
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.nu.modules.tq.common.mapper.TqApiLogMapper">
|
||||||
|
|
||||||
|
<select id="getApiLog" parameterType="com.nu.modules.tq.common.entity.TqApiLog" resultType="com.nu.modules.tq.common.entity.TqApiLog">
|
||||||
|
select
|
||||||
|
id,
|
||||||
|
opr_id as oprId,
|
||||||
|
cid as cid,
|
||||||
|
address,
|
||||||
|
type,
|
||||||
|
request_value as requestValue,
|
||||||
|
request_time as requestTime,
|
||||||
|
request_status as requestStatus,
|
||||||
|
request_remark as requestRemark,
|
||||||
|
resolve_value as resolveValue,
|
||||||
|
resolve_time as resolveTime,
|
||||||
|
resolve_status as resolveStatus,
|
||||||
|
resolve_remark as resolveRemark
|
||||||
|
from nu_iot_tq_api_request_log
|
||||||
|
where opr_id = #{oprId}
|
||||||
|
<if test="cid!=null and cid !=''">
|
||||||
|
and cid = #{cid}
|
||||||
|
</if>
|
||||||
|
<if test="address!=null and address !=''">
|
||||||
|
and address = #{address}
|
||||||
|
</if>
|
||||||
|
<if test="type!=null and type !=''">
|
||||||
|
and type = #{type}
|
||||||
|
</if>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<insert id="insert" parameterType="com.nu.modules.tq.common.entity.TqApiLog">
|
||||||
|
insert into nu_iot_tq_api_request_log(
|
||||||
|
opr_id,
|
||||||
|
cid,
|
||||||
|
address,
|
||||||
|
type,
|
||||||
|
request_value,
|
||||||
|
request_time,
|
||||||
|
request_status,
|
||||||
|
request_remark,
|
||||||
|
create_time
|
||||||
|
)
|
||||||
|
values(
|
||||||
|
#{oprId},
|
||||||
|
#{cid},
|
||||||
|
#{address},
|
||||||
|
#{type},
|
||||||
|
#{requestValue},
|
||||||
|
#{requestTime},
|
||||||
|
#{requestStatus},
|
||||||
|
#{requestRemark},
|
||||||
|
now()
|
||||||
|
)
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<update id="update" parameterType="com.nu.modules.tq.common.entity.TqApiLog">
|
||||||
|
update nu_iot_tq_api_request_log
|
||||||
|
set
|
||||||
|
resolve_value = #{resolveValue},
|
||||||
|
resolve_time = #{resolveTime},
|
||||||
|
resolve_status = #{resolveStatus},
|
||||||
|
resolve_remark = #{resolveRemark},
|
||||||
|
update_time = now()
|
||||||
|
where id = #{id}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
</mapper>
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.nu.modules.tq.common.mapper.TqConfigMapper">
|
||||||
|
|
||||||
|
<select id="getConfig" parameterType="String" resultType="com.nu.modules.tq.common.entity.TqConfig">
|
||||||
|
select
|
||||||
|
id,
|
||||||
|
request_url as requestUrl,
|
||||||
|
auth_code as authCode,
|
||||||
|
random_code as randomCode,
|
||||||
|
notify_url as notifyUrl
|
||||||
|
from nu_iot_tq_config
|
||||||
|
order by id desc
|
||||||
|
limit 1
|
||||||
|
</select>
|
||||||
|
|
||||||
|
</mapper>
|
|
@ -0,0 +1,60 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.nu.modules.tq.common.mapper.TqDeviceInfoMapper">
|
||||||
|
|
||||||
|
<select id="getDeviceInfo" parameterType="com.nu.modules.tq.common.entity.TqDeviceInfo" resultType="com.nu.modules.tq.common.entity.TqDeviceInfo">
|
||||||
|
select
|
||||||
|
id,
|
||||||
|
cid as cid,
|
||||||
|
online,
|
||||||
|
csq,
|
||||||
|
disconnect_time as disconnectTime,
|
||||||
|
connect_time as connectTime,
|
||||||
|
remark
|
||||||
|
from nu_iot_tq_collector
|
||||||
|
where cid = #{cid}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<insert id="insert" parameterType="com.nu.modules.tq.common.entity.TqDeviceInfo">
|
||||||
|
insert into nu_iot_tq_collector(
|
||||||
|
cid,
|
||||||
|
online,
|
||||||
|
csq,
|
||||||
|
<if test="online!=null and online !='' and online =='false' ">
|
||||||
|
disconnect_time,
|
||||||
|
</if>
|
||||||
|
<if test="online!=null and online !='' and online =='true' ">
|
||||||
|
connect_time,
|
||||||
|
</if>
|
||||||
|
create_time
|
||||||
|
)
|
||||||
|
values(
|
||||||
|
#{cid},
|
||||||
|
#{online},
|
||||||
|
#{csq},
|
||||||
|
<if test="online!=null and online !='' and online =='false' ">
|
||||||
|
#{disconnectTime},
|
||||||
|
</if>
|
||||||
|
<if test="online!=null and online !='' and online =='true' ">
|
||||||
|
#{connectTime},
|
||||||
|
</if>
|
||||||
|
now()
|
||||||
|
)
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<update id="update" parameterType="com.nu.modules.tq.common.entity.TqDeviceInfo">
|
||||||
|
update nu_iot_tq_collector
|
||||||
|
set
|
||||||
|
online = #{online},
|
||||||
|
csq = #{csq},
|
||||||
|
<if test="online!=null and online !='' and online =='false' ">
|
||||||
|
disconnect_time = #{disconnectTime},
|
||||||
|
</if>
|
||||||
|
<if test="online!=null and online !='' and online =='true' ">
|
||||||
|
connect_time = #{connectTime},
|
||||||
|
</if>
|
||||||
|
update_time = now()
|
||||||
|
where cid = #{cid}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
</mapper>
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.nu.modules.tq.common.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.nu.modules.tq.common.entity.TqApiLog;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 护理单元-物联管理-电水表-接口请求记录表
|
||||||
|
* @Author: jeecg-boot
|
||||||
|
* @Date: caolei
|
||||||
|
* @Version: V1.0
|
||||||
|
*/
|
||||||
|
public interface ITqApiLogService extends IService<TqApiLog> {
|
||||||
|
TqApiLog getApiLog(TqApiLog tqApiLog);
|
||||||
|
int insert(TqApiLog tqApiLog);
|
||||||
|
int update(TqApiLog tqApiLog);
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.nu.modules.tq.common.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.nu.modules.tq.common.entity.TqConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 护理单元-物联管理-电水表-配置信息
|
||||||
|
* @Author: jeecg-boot
|
||||||
|
* @Date: caolei
|
||||||
|
* @Version: V1.0
|
||||||
|
*/
|
||||||
|
public interface ITqConfigService extends IService<TqConfig> {
|
||||||
|
TqConfig getConfig();
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.nu.modules.tq.common.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.nu.modules.tq.common.entity.TqDeviceInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 护理单元-物联管理-电水表-设备信息和采集器信息表
|
||||||
|
* @Author: jeecg-boot
|
||||||
|
* @Date: caolei
|
||||||
|
* @Version: V1.0
|
||||||
|
*/
|
||||||
|
public interface ITqDeviceInfoService extends IService<TqDeviceInfo> {
|
||||||
|
void getAllMeter();
|
||||||
|
void getAllCollector();
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.nu.modules.tq.common.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.nu.modules.tq.common.entity.TqApiLog;
|
||||||
|
import com.nu.modules.tq.common.entity.TqConfig;
|
||||||
|
import com.nu.modules.tq.common.mapper.TqApiLogMapper;
|
||||||
|
import com.nu.modules.tq.common.service.ITqApiLogService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 护理单元-物联管理-电水表配置信息
|
||||||
|
* @Author: caolei
|
||||||
|
* @Date: 2025-06-04
|
||||||
|
* @Version: V1.0
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class TqApiLogServiceImpl extends ServiceImpl<TqApiLogMapper, TqApiLog> implements ITqApiLogService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TqApiLog getApiLog(TqApiLog tqApiLog){
|
||||||
|
return baseMapper.getApiLog(tqApiLog);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int insert(TqApiLog tqApiLog){
|
||||||
|
return baseMapper.insert(tqApiLog);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int update(TqApiLog tqApiLog){
|
||||||
|
return baseMapper.update(tqApiLog);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.nu.modules.tq.common.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.nu.modules.tq.common.entity.TqConfig;
|
||||||
|
import com.nu.modules.tq.common.mapper.TqConfigMapper;
|
||||||
|
import com.nu.modules.tq.common.service.ITqConfigService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 护理单元-物联管理-电水表配置信息
|
||||||
|
* @Author: caolei
|
||||||
|
* @Date: 2025-06-04
|
||||||
|
* @Version: V1.0
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class TqConfigServiceImpl extends ServiceImpl<TqConfigMapper, TqConfig> implements ITqConfigService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TqConfig getConfig(){
|
||||||
|
return baseMapper.getConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,130 @@
|
||||||
|
package com.nu.modules.tq.common.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.json.JSONArray;
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.nu.modules.tq.common.entity.TqDeviceInfo;
|
||||||
|
import com.nu.modules.tq.common.mapper.TqDeviceInfoMapper;
|
||||||
|
import com.nu.modules.tq.common.service.ITqDeviceInfoService;
|
||||||
|
import com.nu.modules.tq.electricity.entity.ElectricityMeter;
|
||||||
|
import com.nu.modules.tq.electricity.mapper.ElectricityMeterMapper;
|
||||||
|
import com.nu.modules.tq.utils.TqApi;
|
||||||
|
import com.nu.modules.tq.water.entity.WaterMeter;
|
||||||
|
import com.nu.modules.tq.water.mapper.WaterMeterMapper;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 护理单元-物联管理-电水表-设备信息和采集器信息表
|
||||||
|
* @Author: caolei
|
||||||
|
* @Date: 2025-06-04
|
||||||
|
* @Version: V1.0
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class TqDeviceInfoServiceImpl extends ServiceImpl<TqDeviceInfoMapper, TqDeviceInfo> implements ITqDeviceInfoService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
TqApi tqApi;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ElectricityMeterMapper electricityMeterMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
WaterMeterMapper waterMeterMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取设备信息
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void getAllMeter(){
|
||||||
|
String responseStr = tqApi.getMeters();
|
||||||
|
JSONObject jsonObject = new JSONObject(responseStr);
|
||||||
|
String status = jsonObject.getStr("status");
|
||||||
|
if(status.equals("1")){
|
||||||
|
// Integer total = jsonObject.getInt("total");
|
||||||
|
String data = jsonObject.getStr("data");
|
||||||
|
JSONArray jsonArray = new JSONArray(data);
|
||||||
|
for(int i=0;i<jsonArray.size();i++){
|
||||||
|
JSONObject json = (JSONObject)jsonArray.get(i);
|
||||||
|
String cid = json.getStr("collectorid");
|
||||||
|
String address = json.getStr("address");
|
||||||
|
String deviceType = json.getStr("device_type");
|
||||||
|
String relayState = json.getStr("relay_state");
|
||||||
|
String remark = json.getStr("description");
|
||||||
|
if(deviceType.equals("1")){
|
||||||
|
String batteryState = json.getStr("battery_state");
|
||||||
|
WaterMeter waterMeter = new WaterMeter();
|
||||||
|
waterMeter.setCid(cid);
|
||||||
|
waterMeter.setAddress(address);
|
||||||
|
waterMeter.setRelayState(relayState);
|
||||||
|
waterMeter.setBatteryState(batteryState);
|
||||||
|
waterMeter.setRemark(remark);
|
||||||
|
WaterMeter entity = waterMeterMapper.getWaterMeter(waterMeter);
|
||||||
|
if(entity == null){
|
||||||
|
waterMeterMapper.insert(waterMeter);
|
||||||
|
}else{
|
||||||
|
waterMeterMapper.update(waterMeter);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
ElectricityMeter electricityMeter = new ElectricityMeter();
|
||||||
|
electricityMeter.setCid(cid);
|
||||||
|
electricityMeter.setAddress(address);
|
||||||
|
electricityMeter.setRelayState(relayState);
|
||||||
|
electricityMeter.setRemark(remark);
|
||||||
|
ElectricityMeter entity = electricityMeterMapper.getElectricityMeter(electricityMeter);
|
||||||
|
if(entity == null){
|
||||||
|
electricityMeterMapper.insert(electricityMeter);
|
||||||
|
}else{
|
||||||
|
electricityMeterMapper.update(electricityMeter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 采集器设备信息
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void getAllCollector(){
|
||||||
|
String responseStr = tqApi.getCollectors();
|
||||||
|
JSONObject jsonObject = new JSONObject(responseStr);
|
||||||
|
String status = jsonObject.getStr("status");
|
||||||
|
if(status.equals("1")){
|
||||||
|
// Integer total = jsonObject.getInt("total");
|
||||||
|
String data = jsonObject.getStr("data");
|
||||||
|
JSONArray jsonArray = new JSONArray(data);
|
||||||
|
for(int i=0;i<jsonArray.size();i++){
|
||||||
|
JSONObject json = (JSONObject)jsonArray.get(i);
|
||||||
|
TqDeviceInfo tdi = new TqDeviceInfo();
|
||||||
|
String cid = json.getStr("collectorid");
|
||||||
|
String csq = json.getStr("csq");
|
||||||
|
String online = json.getStr("online");
|
||||||
|
if(online.equals("true")){
|
||||||
|
String connectTime = json.getStr("connect_time");
|
||||||
|
tdi.setConnectTime(connectTime);
|
||||||
|
}else{
|
||||||
|
String disconnectTime = json.getStr("disconnect_time");
|
||||||
|
tdi.setDisconnectTime(disconnectTime);
|
||||||
|
}
|
||||||
|
String remark = json.getStr("description");
|
||||||
|
tdi.setCid(cid);
|
||||||
|
tdi.setCsq(csq);
|
||||||
|
tdi.setOnline(online);
|
||||||
|
tdi.setRemark(remark);
|
||||||
|
TqDeviceInfo entity = baseMapper.getDeviceInfo(tdi);
|
||||||
|
if(entity == null){
|
||||||
|
baseMapper.insert(tdi);
|
||||||
|
}else{
|
||||||
|
baseMapper.update(tdi);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,87 @@
|
||||||
|
package com.nu.modules.tq.electricity.api;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.nu.modules.tq.electricity.entity.ElectricityMeter;
|
||||||
|
import com.nu.modules.tq.utils.SignTool;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.jeecg.common.system.base.controller.JeecgController;
|
||||||
|
import com.nu.modules.tq.electricity.service.IElectricityMeterService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/iot/tq/api/electricityMeter")
|
||||||
|
public class ElectricityMeterApiController extends JeecgController<ElectricityMeter, IElectricityMeterService> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IElectricityMeterService service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 电表清零回调
|
||||||
|
* @param response_content
|
||||||
|
* @param timestamp
|
||||||
|
* @param sign
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/eleResetNotify")
|
||||||
|
@ApiOperation("电表清零回调")
|
||||||
|
public String eleResetNotify(String response_content, String timestamp, String sign) {
|
||||||
|
log.info("eleResetNotify:response_content:{}",response_content);
|
||||||
|
log.info("eleResetNotify:timestamp:{}",timestamp);
|
||||||
|
log.info("eleResetNotify:sign:{}",sign);
|
||||||
|
//-----------加入业务逻辑-----------
|
||||||
|
String result = service.eleResetNotify(response_content, timestamp, sign);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 电表开关闸回调
|
||||||
|
* @param response_content
|
||||||
|
* @param timestamp
|
||||||
|
* @param sign
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/eleControlNotify")
|
||||||
|
@ApiOperation("电表开关闸回调")
|
||||||
|
public String eleControlNotify(String response_content, String timestamp, String sign) {
|
||||||
|
log.info("eleControlNotify:response_content:{}",response_content);
|
||||||
|
log.info("eleControlNotify:timestamp:{}",timestamp);
|
||||||
|
log.info("eleControlNotify:sign:{}",sign);
|
||||||
|
//-----------加入业务逻辑-----------
|
||||||
|
String result = service.eleControlNotify(response_content, timestamp, sign);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 电表抄表回调
|
||||||
|
* @param response_content
|
||||||
|
* @param timestamp
|
||||||
|
* @param sign
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/eleReadNotify")
|
||||||
|
@ApiOperation("电表抄表回调")
|
||||||
|
public String eleReadNotify(String response_content, String timestamp, String sign) {
|
||||||
|
log.info("eleReadNotify:response_content:{}",response_content);
|
||||||
|
log.info("eleReadNotify:timestamp:{}",timestamp);
|
||||||
|
log.info("eleReadNotify:sign:{}",sign);
|
||||||
|
//-----------加入业务逻辑-----------
|
||||||
|
String result = service.eleReadNotify(response_content, timestamp, sign);
|
||||||
|
//--------------------------------
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
package com.nu.modules.tq.electricity.controller;
|
||||||
|
|
||||||
|
import com.nu.modules.tq.electricity.entity.ElectricityMeter;
|
||||||
|
import com.nu.modules.tq.electricity.service.IElectricityMeterService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.jeecg.common.api.vo.Result;
|
||||||
|
import org.jeecg.common.system.base.controller.JeecgController;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/iot/tq/electricityMeter")
|
||||||
|
public class ElectricityMeterController extends JeecgController<ElectricityMeter, IElectricityMeterService> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IElectricityMeterService service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取设备信息
|
||||||
|
* @param electricityMeter
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping(value = "/eleReset")
|
||||||
|
public Result<String> eleReset(ElectricityMeter electricityMeter) {
|
||||||
|
return service.eleReset(electricityMeter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 拉闸、合闸
|
||||||
|
* @param electricityMeter
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping(value = "/eleControl")
|
||||||
|
public Result<String> eleControl(ElectricityMeter electricityMeter) {
|
||||||
|
return service.eleControl(electricityMeter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抄表
|
||||||
|
* @param electricityMeter
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping(value = "/eleRead")
|
||||||
|
public Result<String> eleRead(ElectricityMeter electricityMeter) {
|
||||||
|
return service.eleRead(electricityMeter);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
package com.nu.modules.tq.electricity.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Class :物联电表管理Entity
|
||||||
|
* <p>功能描述:功能描述
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName("nu_iot_tq_electricity_meter")
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@ApiModel(value="nu_iot_tq_electricity_meter对象", description="物联电表")
|
||||||
|
public class ElectricityMeter implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
@ApiModelProperty(value = "主键")
|
||||||
|
private Integer id;
|
||||||
|
@Excel(name = "采集器号", width = 15)
|
||||||
|
@ApiModelProperty(value = "采集器号,4G、NB设备采集器号与表号一致")
|
||||||
|
private String cid;
|
||||||
|
@Excel(name = "表号", width = 15)
|
||||||
|
@ApiModelProperty(value = "表号(表地址)")
|
||||||
|
private String address;
|
||||||
|
@Excel(name = "操作类型", width = 15)
|
||||||
|
@ApiModelProperty(value = "操作类型")
|
||||||
|
@TableField(exist = false)
|
||||||
|
private Integer type;//9清零 3抄表 10电表拉闸 11电表合闸 43水表开闸 53水表关闸
|
||||||
|
@Excel(name = "电表值", width = 15)
|
||||||
|
@ApiModelProperty(value = "电表值")
|
||||||
|
private String eleValue; //电表-电量值
|
||||||
|
@Excel(name = "阀门状态", width = 15)
|
||||||
|
@ApiModelProperty(value = "阀门状态")
|
||||||
|
private String relayState; //电表-阀门状态 1 表示合闸/开阀, 0 表示拉闸/关阀,其他,表示未知状态或异常
|
||||||
|
@Excel(name = "在线状态", width = 15)
|
||||||
|
@ApiModelProperty(value = "在线状态")
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String online; //采集器-在线状态 true 在线 false 离线
|
||||||
|
@Excel(name = "信号值", width = 15)
|
||||||
|
@ApiModelProperty(value = "信号值")
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String csq ; //采集器-信号值 1-31 。 20以上算信号稳定
|
||||||
|
@Excel(name = "上次掉线时间", width = 15)
|
||||||
|
@ApiModelProperty(value = "上次掉线时间")
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String disconnectTime; //采集器-上次掉线时间 online = false 时
|
||||||
|
@Excel(name = "上次上线时间", width = 15)
|
||||||
|
@ApiModelProperty(value = "上次上线时间")
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String connectTime; //采集器-上次上线时间 online = true 时
|
||||||
|
@Excel(name = "上次查表时间", width = 15)
|
||||||
|
@ApiModelProperty(value = "上次查表时间")
|
||||||
|
private String readTime; //电表-上次查表时间
|
||||||
|
@Excel(name = "描述", width = 15)
|
||||||
|
@ApiModelProperty(value = "描述")
|
||||||
|
private String remark;
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.nu.modules.tq.electricity.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.nu.modules.tq.electricity.entity.ElectricityMeter;
|
||||||
|
|
||||||
|
public interface ElectricityMeterMapper extends BaseMapper<ElectricityMeter> {
|
||||||
|
ElectricityMeter getElectricityMeter(ElectricityMeter electricityMeter);
|
||||||
|
int insert(ElectricityMeter electricityMeter);
|
||||||
|
int update(ElectricityMeter electricityMeter);
|
||||||
|
int updateValue(ElectricityMeter electricityMeter);
|
||||||
|
int updateRelayState(ElectricityMeter electricityMeter);
|
||||||
|
}
|
|
@ -0,0 +1,66 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.nu.modules.tq.electricity.mapper.ElectricityMeterMapper">
|
||||||
|
|
||||||
|
<select id="getElectricityMeter" parameterType="com.nu.modules.tq.electricity.entity.ElectricityMeter" resultType="com.nu.modules.tq.electricity.entity.ElectricityMeter">
|
||||||
|
select
|
||||||
|
id,
|
||||||
|
cid,
|
||||||
|
address,
|
||||||
|
ele_value as eleValue,
|
||||||
|
relay_state as relayState,
|
||||||
|
read_time as readTime,
|
||||||
|
remark
|
||||||
|
from nu_iot_tq_electricity_meter
|
||||||
|
where cid = #{cid}
|
||||||
|
and address = #{address}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<insert id="insert" parameterType="com.nu.modules.tq.electricity.entity.ElectricityMeter">
|
||||||
|
insert into nu_iot_tq_electricity_meter(
|
||||||
|
cid,
|
||||||
|
address,
|
||||||
|
relay_state,
|
||||||
|
remark,
|
||||||
|
create_time
|
||||||
|
)
|
||||||
|
values(
|
||||||
|
#{cid},
|
||||||
|
#{address},
|
||||||
|
#{relayState},
|
||||||
|
#{remark},
|
||||||
|
now()
|
||||||
|
)
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<update id="update" parameterType="com.nu.modules.tq.electricity.entity.ElectricityMeter">
|
||||||
|
update nu_iot_tq_electricity_meter
|
||||||
|
set
|
||||||
|
relay_state = #{relayState},
|
||||||
|
remark = #{remark},
|
||||||
|
update_time = now()
|
||||||
|
where cid = #{cid}
|
||||||
|
and address = #{address}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<update id="updateValue" parameterType="com.nu.modules.tq.electricity.entity.ElectricityMeter">
|
||||||
|
update nu_iot_tq_electricity_meter
|
||||||
|
set
|
||||||
|
ele_value = #{eleValue},
|
||||||
|
read_time = #{readTime},
|
||||||
|
update_time = now()
|
||||||
|
where cid = #{cid}
|
||||||
|
and address = #{address}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<update id="updateRelayState" parameterType="com.nu.modules.tq.electricity.entity.ElectricityMeter">
|
||||||
|
update nu_iot_tq_electricity_meter
|
||||||
|
set
|
||||||
|
relay_state = #{relayState},
|
||||||
|
update_time = now()
|
||||||
|
where cid = #{cid}
|
||||||
|
and address = #{address}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.nu.modules.tq.electricity.service;
|
||||||
|
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.nu.modules.tq.electricity.entity.ElectricityMeter;
|
||||||
|
import org.jeecg.common.api.vo.Result;
|
||||||
|
|
||||||
|
public interface IElectricityMeterService extends IService<ElectricityMeter> {
|
||||||
|
|
||||||
|
Result<String> eleReset(ElectricityMeter electricityMeter);
|
||||||
|
Result<String> eleControl(ElectricityMeter electricityMeter);
|
||||||
|
Result<String> eleRead(ElectricityMeter electricityMeter);
|
||||||
|
|
||||||
|
String eleResetNotify(String response_content, String timestamp, String sign);
|
||||||
|
String eleControlNotify(String response_content, String timestamp, String sign);
|
||||||
|
String eleReadNotify(String response_content, String timestamp, String sign);
|
||||||
|
}
|
|
@ -0,0 +1,420 @@
|
||||||
|
package com.nu.modules.tq.electricity.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.json.JSONArray;
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.nu.modules.tq.common.entity.TqApiLog;
|
||||||
|
import com.nu.modules.tq.common.service.ITqApiLogService;
|
||||||
|
import com.nu.modules.tq.utils.HttpTool;
|
||||||
|
import com.nu.modules.tq.utils.SignTool;
|
||||||
|
import com.nu.modules.tq.utils.TqApi;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import com.nu.modules.tq.electricity.entity.ElectricityMeter;
|
||||||
|
import com.nu.modules.tq.electricity.mapper.ElectricityMeterMapper;
|
||||||
|
import com.nu.modules.tq.electricity.service.IElectricityMeterService;
|
||||||
|
import org.jeecg.common.api.vo.Result;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class ElectricityMeterServiceImpl extends ServiceImpl<ElectricityMeterMapper, ElectricityMeter> implements IElectricityMeterService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
TqApi tqApi;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ITqApiLogService logService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清零
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Result<String> eleReset(ElectricityMeter electricityMeter){
|
||||||
|
ElectricityMeter entity = baseMapper.getElectricityMeter(electricityMeter);
|
||||||
|
if(entity == null){
|
||||||
|
return Result.error("请先同步电表设备信息后再进行清零");
|
||||||
|
}
|
||||||
|
String readTimeStr = entity.getReadTime();
|
||||||
|
if(readTimeStr == null || readTimeStr.equals("")){
|
||||||
|
return Result.error("请先进行抄表再进行清零");
|
||||||
|
}
|
||||||
|
Date readTime = DateUtil.parse(readTimeStr,"yyyy-MM-dd HH:mm:ss");
|
||||||
|
Calendar c = Calendar.getInstance();
|
||||||
|
c.add(Calendar.HOUR_OF_DAY,-1);
|
||||||
|
int comInt = DateUtil.compare(readTime,c.getTime());
|
||||||
|
if(comInt<0){
|
||||||
|
return Result.error("请先进行抄表再进行清零");
|
||||||
|
}
|
||||||
|
List<Map<String, Object>> req = new ArrayList<>();
|
||||||
|
Map<String, Object> params = new HashMap<>();
|
||||||
|
params.put("paymentmode", "noprepay");
|
||||||
|
Map<String, Object> item = new HashMap<>();
|
||||||
|
item.put("opr_id", HttpTool.generateOperateId());
|
||||||
|
item.put("time_out", 0);
|
||||||
|
item.put("must_online", true);
|
||||||
|
item.put("retry_times", 1);
|
||||||
|
item.put("cid", electricityMeter.getCid());
|
||||||
|
item.put("address", electricityMeter.getAddress());
|
||||||
|
item.put("params", params);
|
||||||
|
req.add(item);
|
||||||
|
String responseStr = tqApi.eleReset(req);
|
||||||
|
JSONObject jsonObject = new JSONObject(responseStr);
|
||||||
|
String httpStatus = jsonObject.getStr("status");
|
||||||
|
if(httpStatus.equals("SUCCESS")){
|
||||||
|
String response_content = jsonObject.getStr("response_content");
|
||||||
|
JSONArray jsonArray = new JSONArray(response_content);
|
||||||
|
for(int i=0;i<jsonArray.size();i++){
|
||||||
|
JSONObject json = (JSONObject)jsonArray.get(i);
|
||||||
|
String status = json.getStr("status");//状态
|
||||||
|
String oprId = json.getStr("opr_id");//操作ID
|
||||||
|
if(status.equals("SUCCESS")){
|
||||||
|
TqApiLog tqApiLog = new TqApiLog();
|
||||||
|
tqApiLog.setOprId(oprId);
|
||||||
|
tqApiLog.setCid(electricityMeter.getCid());
|
||||||
|
tqApiLog.setAddress(electricityMeter.getAddress());
|
||||||
|
tqApiLog.setType(9);
|
||||||
|
tqApiLog.setResolveValue(entity.getEleValue());
|
||||||
|
tqApiLog.setRequestTime(DateUtil.now());
|
||||||
|
tqApiLog.setRequestStatus(status);
|
||||||
|
logService.insert(tqApiLog);
|
||||||
|
}else{
|
||||||
|
String errorMsg = json.getStr("error_msg");
|
||||||
|
TqApiLog tqApiLog = new TqApiLog();
|
||||||
|
tqApiLog.setOprId(oprId);
|
||||||
|
tqApiLog.setCid(electricityMeter.getCid());
|
||||||
|
tqApiLog.setAddress(electricityMeter.getAddress());
|
||||||
|
tqApiLog.setType(9);
|
||||||
|
tqApiLog.setResolveValue(entity.getEleValue());
|
||||||
|
tqApiLog.setRequestTime(DateUtil.now());
|
||||||
|
tqApiLog.setRequestStatus(status);
|
||||||
|
tqApiLog.setRequestRemark(errorMsg);
|
||||||
|
logService.insert(tqApiLog);
|
||||||
|
return Result.error(errorMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
String errorMsg = jsonObject.getStr("error_msg");
|
||||||
|
TqApiLog tqApiLog = new TqApiLog();
|
||||||
|
tqApiLog.setCid(electricityMeter.getCid());
|
||||||
|
tqApiLog.setAddress(electricityMeter.getAddress());
|
||||||
|
tqApiLog.setType(9);
|
||||||
|
tqApiLog.setResolveValue(entity.getEleValue());
|
||||||
|
tqApiLog.setRequestTime(DateUtil.now());
|
||||||
|
tqApiLog.setRequestStatus(httpStatus);
|
||||||
|
tqApiLog.setRequestRemark(errorMsg);
|
||||||
|
logService.insert(tqApiLog);
|
||||||
|
return Result.error(errorMsg);
|
||||||
|
}
|
||||||
|
return Result.OK("清零成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 拉合闸
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Result<String> eleControl(ElectricityMeter electricityMeter){
|
||||||
|
Integer type = electricityMeter.getType();
|
||||||
|
ElectricityMeter entity = baseMapper.getElectricityMeter(electricityMeter);
|
||||||
|
if(entity == null){
|
||||||
|
if(type.equals(10)){
|
||||||
|
return Result.error("请先同步电表设备信息后再进行拉闸");
|
||||||
|
}else{
|
||||||
|
return Result.error("请先同步电表设备信息后再进行合闸");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<Map<String, Object>> req = new ArrayList<>();
|
||||||
|
Map<String, Object> item = new HashMap<>();
|
||||||
|
item.put("opr_id", HttpTool.generateOperateId());
|
||||||
|
item.put("time_out", 0);
|
||||||
|
item.put("must_online", true);
|
||||||
|
item.put("retry_times", 1);
|
||||||
|
item.put("cid", electricityMeter.getCid());
|
||||||
|
item.put("address", electricityMeter.getAddress());
|
||||||
|
item.put("type", type);
|
||||||
|
req.add(item);
|
||||||
|
String responseStr = tqApi.eleControl(req);
|
||||||
|
JSONObject jsonObject = new JSONObject(responseStr);
|
||||||
|
String httpStatus = jsonObject.getStr("status");
|
||||||
|
if(httpStatus.equals("SUCCESS")){
|
||||||
|
String response_content = jsonObject.getStr("response_content");
|
||||||
|
JSONArray jsonArray = new JSONArray(response_content);
|
||||||
|
for(int i=0;i<jsonArray.size();i++){
|
||||||
|
JSONObject json = (JSONObject)jsonArray.get(i);
|
||||||
|
String status = json.getStr("status");//状态
|
||||||
|
String oprId = json.getStr("opr_id");//操作ID
|
||||||
|
if(status.equals("SUCCESS")){
|
||||||
|
TqApiLog tqApiLog = new TqApiLog();
|
||||||
|
tqApiLog.setOprId(oprId);
|
||||||
|
tqApiLog.setCid(electricityMeter.getCid());
|
||||||
|
tqApiLog.setAddress(electricityMeter.getAddress());
|
||||||
|
tqApiLog.setType(electricityMeter.getType());
|
||||||
|
tqApiLog.setRequestTime(DateUtil.now());
|
||||||
|
tqApiLog.setRequestStatus(status);
|
||||||
|
logService.insert(tqApiLog);
|
||||||
|
}else{
|
||||||
|
String errorMsg = json.getStr("error_msg");
|
||||||
|
TqApiLog tqApiLog = new TqApiLog();
|
||||||
|
tqApiLog.setOprId(oprId);
|
||||||
|
tqApiLog.setCid(electricityMeter.getCid());
|
||||||
|
tqApiLog.setAddress(electricityMeter.getAddress());
|
||||||
|
tqApiLog.setType(electricityMeter.getType());
|
||||||
|
tqApiLog.setRequestTime(DateUtil.now());
|
||||||
|
tqApiLog.setRequestStatus(status);
|
||||||
|
tqApiLog.setRequestRemark(errorMsg);
|
||||||
|
logService.insert(tqApiLog);
|
||||||
|
return Result.error(errorMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
String errorMsg = jsonObject.getStr("error_msg");
|
||||||
|
TqApiLog tqApiLog = new TqApiLog();
|
||||||
|
tqApiLog.setCid(electricityMeter.getCid());
|
||||||
|
tqApiLog.setAddress(electricityMeter.getAddress());
|
||||||
|
tqApiLog.setType(electricityMeter.getType());
|
||||||
|
tqApiLog.setRequestTime(DateUtil.now());
|
||||||
|
tqApiLog.setRequestStatus(httpStatus);
|
||||||
|
tqApiLog.setRequestRemark(errorMsg);
|
||||||
|
logService.insert(tqApiLog);
|
||||||
|
return Result.error(errorMsg);
|
||||||
|
}
|
||||||
|
if(type.equals(10)){
|
||||||
|
return Result.OK("拉闸成功");
|
||||||
|
}else{
|
||||||
|
return Result.OK("合闸成功");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抄电表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Result<String> eleRead(ElectricityMeter electricityMeter){
|
||||||
|
ElectricityMeter entity = baseMapper.getElectricityMeter(electricityMeter);
|
||||||
|
if(entity == null){
|
||||||
|
return Result.error("请先同步电表设备信息后再进行抄表");
|
||||||
|
}
|
||||||
|
List<Map<String, Object>> req = new ArrayList<>();
|
||||||
|
Map<String, Object> item = new HashMap<>();
|
||||||
|
item.put("opr_id", HttpTool.generateOperateId());
|
||||||
|
item.put("time_out", 0);
|
||||||
|
item.put("must_online", true);
|
||||||
|
item.put("retry_times", 1);
|
||||||
|
item.put("cid", electricityMeter.getCid());
|
||||||
|
item.put("address", electricityMeter.getAddress());
|
||||||
|
item.put("type", 3);
|
||||||
|
req.add(item);
|
||||||
|
String responseStr = tqApi.eleRead(req);
|
||||||
|
JSONObject jsonObject = new JSONObject(responseStr);
|
||||||
|
String httpStatus = jsonObject.getStr("status");
|
||||||
|
if(httpStatus.equals("SUCCESS")){
|
||||||
|
String response_content = jsonObject.getStr("response_content");
|
||||||
|
JSONArray jsonArray = new JSONArray(response_content);
|
||||||
|
for(int i=0;i<jsonArray.size();i++){
|
||||||
|
JSONObject json = (JSONObject)jsonArray.get(i);
|
||||||
|
String status = json.getStr("status");//状态
|
||||||
|
String oprId = json.getStr("opr_id");//操作ID
|
||||||
|
if(status.equals("SUCCESS")){
|
||||||
|
TqApiLog tqApiLog = new TqApiLog();
|
||||||
|
tqApiLog.setOprId(oprId);
|
||||||
|
tqApiLog.setCid(electricityMeter.getCid());
|
||||||
|
tqApiLog.setAddress(electricityMeter.getAddress());
|
||||||
|
tqApiLog.setType(3);
|
||||||
|
tqApiLog.setResolveValue(entity.getEleValue());
|
||||||
|
tqApiLog.setRequestTime(DateUtil.now());
|
||||||
|
tqApiLog.setRequestStatus(status);
|
||||||
|
logService.insert(tqApiLog);
|
||||||
|
}else{
|
||||||
|
String errorMsg = json.getStr("error_msg");
|
||||||
|
TqApiLog tqApiLog = new TqApiLog();
|
||||||
|
tqApiLog.setOprId(oprId);
|
||||||
|
tqApiLog.setCid(electricityMeter.getCid());
|
||||||
|
tqApiLog.setAddress(electricityMeter.getAddress());
|
||||||
|
tqApiLog.setType(3);
|
||||||
|
tqApiLog.setResolveValue(entity.getEleValue());
|
||||||
|
tqApiLog.setRequestTime(DateUtil.now());
|
||||||
|
tqApiLog.setRequestStatus(status);
|
||||||
|
tqApiLog.setRequestRemark(errorMsg);
|
||||||
|
logService.insert(tqApiLog);
|
||||||
|
return Result.error(errorMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
String errorMsg = jsonObject.getStr("error_msg");
|
||||||
|
TqApiLog tqApiLog = new TqApiLog();
|
||||||
|
tqApiLog.setCid(electricityMeter.getCid());
|
||||||
|
tqApiLog.setAddress(electricityMeter.getAddress());
|
||||||
|
tqApiLog.setType(3);
|
||||||
|
tqApiLog.setResolveValue(entity.getEleValue());
|
||||||
|
tqApiLog.setRequestTime(DateUtil.now());
|
||||||
|
tqApiLog.setRequestStatus(httpStatus);
|
||||||
|
tqApiLog.setRequestRemark(errorMsg);
|
||||||
|
logService.insert(tqApiLog);
|
||||||
|
return Result.error(errorMsg);
|
||||||
|
}
|
||||||
|
return Result.OK("抄表成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清零回调通知
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String eleResetNotify(String response_content, String timestamp, String sign){
|
||||||
|
// 验签
|
||||||
|
if(!SignTool.checkSign(response_content, timestamp, sign, tqApi.getTqConfig().getRandomCode())) {
|
||||||
|
log.info("eleResetNotify:sign check failed");
|
||||||
|
return "sign check failed";
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
JSONArray jsonArray = new JSONArray(response_content);
|
||||||
|
for(int i=0;i<jsonArray.size();i++){
|
||||||
|
JSONObject jsonObject = (JSONObject)jsonArray.get(i);
|
||||||
|
String status = jsonObject.getStr("status");//返回状态
|
||||||
|
String oprId = jsonObject.getStr("opr_id");//操作ID
|
||||||
|
String resolveTime = jsonObject.getStr("resolve_time");//反馈时间
|
||||||
|
String data = jsonObject.getStr("data");//反馈时间
|
||||||
|
TqApiLog tqApiLog = new TqApiLog();
|
||||||
|
tqApiLog.setOprId(oprId);
|
||||||
|
tqApiLog.setResolveValue("0");
|
||||||
|
tqApiLog.setResolveTime(resolveTime);
|
||||||
|
tqApiLog.setResolveStatus(status);
|
||||||
|
tqApiLog.setResolveRemark(data);
|
||||||
|
TqApiLog logEntity = logService.getApiLog(tqApiLog);
|
||||||
|
if(logEntity!=null) {
|
||||||
|
tqApiLog.setId(logEntity.getId());
|
||||||
|
logService.update(tqApiLog);
|
||||||
|
}
|
||||||
|
if(status.equals("SUCCESS")) {
|
||||||
|
if(logEntity!=null){
|
||||||
|
String cid = logEntity.getCid();
|
||||||
|
String address = logEntity.getAddress();
|
||||||
|
ElectricityMeter em = new ElectricityMeter();
|
||||||
|
em.setCid(cid);
|
||||||
|
em.setAddress(address);
|
||||||
|
em.setEleValue("0");
|
||||||
|
baseMapper.updateValue(em);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
return "FAIL";
|
||||||
|
}
|
||||||
|
return "SUCCESS";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开关闸回调通知
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String eleControlNotify(String response_content, String timestamp, String sign){
|
||||||
|
// 验签
|
||||||
|
if(!SignTool.checkSign(response_content, timestamp, sign, tqApi.getTqConfig().getRandomCode())) {
|
||||||
|
log.info("eleResetNotify:sign check failed");
|
||||||
|
return "sign check failed";
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
JSONArray jsonArray = new JSONArray(response_content);
|
||||||
|
for(int i=0;i<jsonArray.size();i++){
|
||||||
|
JSONObject jsonObject = (JSONObject)jsonArray.get(i);
|
||||||
|
String status = jsonObject.getStr("status");//返回状态
|
||||||
|
String oprId = jsonObject.getStr("opr_id");//操作ID
|
||||||
|
String resolveTime = jsonObject.getStr("resolve_time");//反馈时间
|
||||||
|
TqApiLog tqApiLog = new TqApiLog();
|
||||||
|
tqApiLog.setOprId(oprId);
|
||||||
|
tqApiLog.setResolveTime(resolveTime);
|
||||||
|
tqApiLog.setResolveStatus(status);
|
||||||
|
TqApiLog logEntity = logService.getApiLog(tqApiLog);
|
||||||
|
if(logEntity!=null) {
|
||||||
|
tqApiLog.setId(logEntity.getId());
|
||||||
|
logService.update(tqApiLog);
|
||||||
|
}
|
||||||
|
if(status.equals("SUCCESS")) {
|
||||||
|
if(logEntity!=null){
|
||||||
|
String cid = logEntity.getCid();
|
||||||
|
String address = logEntity.getAddress();
|
||||||
|
Integer type = logEntity.getType();
|
||||||
|
ElectricityMeter em = new ElectricityMeter();
|
||||||
|
em.setCid(cid);
|
||||||
|
em.setAddress(address);
|
||||||
|
if(type.equals(10)){
|
||||||
|
em.setRelayState("0");
|
||||||
|
}else{
|
||||||
|
em.setRelayState("1");
|
||||||
|
}
|
||||||
|
baseMapper.updateRelayState(em);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
return "FAIL";
|
||||||
|
}
|
||||||
|
return "SUCCESS";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抄表回调通知
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String eleReadNotify(String response_content, String timestamp, String sign){
|
||||||
|
// 验签
|
||||||
|
if(!SignTool.checkSign(response_content, timestamp, sign, tqApi.getTqConfig().getRandomCode())) {
|
||||||
|
log.info("eleResetNotify:sign check failed");
|
||||||
|
return "sign check failed";
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
JSONArray jsonArray = new JSONArray(response_content);
|
||||||
|
for(int i=0;i<jsonArray.size();i++){
|
||||||
|
JSONObject jsonObject = (JSONObject)jsonArray.get(i);
|
||||||
|
String status = jsonObject.getStr("status");//返回状态
|
||||||
|
String oprId = jsonObject.getStr("opr_id");//操作ID
|
||||||
|
String resolveTime = jsonObject.getStr("resolve_time");//反馈时间
|
||||||
|
if(status.equals("SUCCESS")) {
|
||||||
|
JSONArray datas = jsonObject.getJSONArray("data");//返回数据
|
||||||
|
for(int j=0;j<datas.size();j++){
|
||||||
|
JSONObject data = (JSONObject)datas.get(j);
|
||||||
|
Integer type = data.getInt("type");//类型
|
||||||
|
String resolveValue = data.getJSONArray("value").get(0).toString();//值
|
||||||
|
String dsp = data.getStr("dsp");//描述
|
||||||
|
|
||||||
|
TqApiLog tqApiLog = new TqApiLog();
|
||||||
|
tqApiLog.setOprId(oprId);
|
||||||
|
tqApiLog.setType(type);
|
||||||
|
tqApiLog.setResolveValue(resolveValue);
|
||||||
|
tqApiLog.setResolveTime(resolveTime);
|
||||||
|
tqApiLog.setResolveStatus(status);
|
||||||
|
tqApiLog.setResolveRemark(dsp);
|
||||||
|
TqApiLog logEntity = logService.getApiLog(tqApiLog);
|
||||||
|
if(logEntity!=null){
|
||||||
|
String cid = logEntity.getCid();
|
||||||
|
String address = logEntity.getAddress();
|
||||||
|
ElectricityMeter em = new ElectricityMeter();
|
||||||
|
em.setCid(cid);
|
||||||
|
em.setAddress(address);
|
||||||
|
em.setEleValue(resolveValue);
|
||||||
|
em.setReadTime(resolveTime);
|
||||||
|
baseMapper.updateValue(em);
|
||||||
|
tqApiLog.setId(logEntity.getId());
|
||||||
|
logService.update(tqApiLog);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
TqApiLog tqApiLog = new TqApiLog();
|
||||||
|
tqApiLog.setOprId(oprId);
|
||||||
|
tqApiLog.setResolveTime(resolveTime);
|
||||||
|
tqApiLog.setResolveStatus(status);
|
||||||
|
TqApiLog logEntity = logService.getApiLog(tqApiLog);
|
||||||
|
if(logEntity!=null){
|
||||||
|
tqApiLog.setId(logEntity.getId());
|
||||||
|
logService.update(tqApiLog);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
return "FAIL";
|
||||||
|
}
|
||||||
|
return "SUCCESS";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.nu.modules.tq.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接口枚举类
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public enum TqApiEnum {
|
||||||
|
|
||||||
|
METER_INFO("/Api/Meter","查询设备列表和当前状态"),
|
||||||
|
COLLECTOR_INFO("/Api/Collector","查询采集器列表和当前状态"),
|
||||||
|
ELE_RESET("/Api_v2/ele_security/reset","电表清零"),
|
||||||
|
WATER_RESET("/Api_v2/water_security/reset","水表清零"),
|
||||||
|
ELE_CONTROL("/Api_v2/ele_control","电表开关闸"),
|
||||||
|
WATER_CONTROL("/Api_v2/water_control","水表开关闸"),
|
||||||
|
ELE_READ("/Api_v2/ele_read","电表抄表"),
|
||||||
|
WATER_READ("/Api_v2/water_read","水表抄表");
|
||||||
|
|
||||||
|
private final String value;//自定义属性,枚举值,获取:如ApiEnum.GET_ENCRYPT_KEY_FOR_LOGIN.getValue();
|
||||||
|
private final String remark;//自定义属性,枚举描述,获取:如ApiEnum.GET_ENCRYPT_KEY_FOR_LOGIN.getRemark();
|
||||||
|
}
|
|
@ -0,0 +1,165 @@
|
||||||
|
package com.nu.modules.tq.utils;
|
||||||
|
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import org.apache.http.HttpEntity;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.NameValuePair;
|
||||||
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||||
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
import org.apache.http.client.methods.HttpPost;
|
||||||
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
import org.apache.http.message.BasicNameValuePair;
|
||||||
|
import org.apache.http.util.EntityUtils;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class HttpTool {
|
||||||
|
|
||||||
|
public static String generateOperateId() {
|
||||||
|
return UUID.randomUUID().toString().replaceAll("-", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getUrlParams(Map<String, Object> map) {
|
||||||
|
if (map == null || map.size() == 0) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
List<String> list = new ArrayList<>();
|
||||||
|
map.forEach((key, value)->{
|
||||||
|
try {
|
||||||
|
list.add(key + "=" + URLEncoder.encode(value.toString(), "UTF-8"));
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return String.join("&", list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送http GET请求
|
||||||
|
* @param url
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String httpClientGet(String url) {
|
||||||
|
try {
|
||||||
|
CloseableHttpClient client = HttpClients.createDefault();
|
||||||
|
HttpGet httpGet = new HttpGet(url);
|
||||||
|
CloseableHttpResponse Response = client.execute(httpGet);
|
||||||
|
HttpEntity entity = Response.getEntity();
|
||||||
|
String resp = EntityUtils.toString(entity, "UTF-8");
|
||||||
|
Response.close();
|
||||||
|
return resp;
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送http POST请求
|
||||||
|
* @param url
|
||||||
|
* @param bodyMap
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static String httpClientPost(String url, Map<String, String> bodyMap) throws Exception {
|
||||||
|
System.out.println("请求地址:" + url);
|
||||||
|
System.out.println("发送参数:" + bodyMap.toString());
|
||||||
|
HttpClient client = HttpClientBuilder.create().build();
|
||||||
|
HttpPost postRequest = new HttpPost(url);
|
||||||
|
|
||||||
|
List<NameValuePair> nvps = new ArrayList<>();
|
||||||
|
|
||||||
|
for(String key : bodyMap.keySet()) {
|
||||||
|
nvps.add(new BasicNameValuePair(key,bodyMap.get(key)));
|
||||||
|
}
|
||||||
|
postRequest.setEntity(new UrlEncodedFormEntity(nvps,"utf-8"));
|
||||||
|
|
||||||
|
|
||||||
|
int retry = 3;
|
||||||
|
HttpResponse execute = null;
|
||||||
|
while(retry-- > 0) {
|
||||||
|
try {
|
||||||
|
execute = client.execute(postRequest);
|
||||||
|
break;
|
||||||
|
} catch (Exception e) {
|
||||||
|
Thread.sleep(5000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(execute == null) {
|
||||||
|
throw new Exception("接口请求失败");
|
||||||
|
}
|
||||||
|
String resp = EntityUtils.toString(execute.getEntity(), "UTF-8");
|
||||||
|
System.out.println("接口返回:" + resp);
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// public static String postUrl(String url, Map<String,Object> map){
|
||||||
|
// String errorMsg = "";
|
||||||
|
// Gson gson = new Gson();
|
||||||
|
// String map2 = gson.toJson(map);
|
||||||
|
// System.out.println(map2);
|
||||||
|
// try {
|
||||||
|
// URL obj = new URL(url);
|
||||||
|
// HttpURLConnection con = (HttpURLConnection) obj.openConnection();
|
||||||
|
// // 设置请求方法为 POST
|
||||||
|
// con.setRequestMethod("POST");
|
||||||
|
// // 设置请求头
|
||||||
|
// con.setRequestProperty("Content-Type", "application/json"); // 声明发送 JSON
|
||||||
|
// con.setRequestProperty("Accept", "application/json"); // 声明期望接收 JSON
|
||||||
|
// con.setDoOutput(true); // 允许写入请求体
|
||||||
|
// // 写入 JSON 请求体
|
||||||
|
// try (OutputStream os = con.getOutputStream()) {
|
||||||
|
// byte[] input = map2.getBytes("utf-8");
|
||||||
|
// os.write(input, 0, input.length);
|
||||||
|
// }
|
||||||
|
// // 获取响应码
|
||||||
|
// int responseCode = con.getResponseCode();
|
||||||
|
// System.out.println("Response Code: " + responseCode);
|
||||||
|
// // 读取响应(成功时)
|
||||||
|
// if (responseCode == HttpURLConnection.HTTP_OK) { // 200
|
||||||
|
// try (BufferedReader br = new BufferedReader(
|
||||||
|
// new InputStreamReader(con.getInputStream(), "UTF-8"))) {
|
||||||
|
// StringBuilder response = new StringBuilder();
|
||||||
|
// String responseLine;
|
||||||
|
// while ((responseLine = br.readLine()) != null) {
|
||||||
|
// response.append(responseLine.trim());
|
||||||
|
// }
|
||||||
|
// System.out.println("Response: " + response.toString());
|
||||||
|
// JSONObject result = new JSONObject(response.toString());
|
||||||
|
// String status = result.getStr("status");
|
||||||
|
// if(status.equals("SUCCESS")){
|
||||||
|
// errorMsg = "";
|
||||||
|
// }else{
|
||||||
|
// errorMsg = result.getStr("error_msg");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } else { // 错误时读取错误流
|
||||||
|
// try (BufferedReader br = new BufferedReader(
|
||||||
|
// new InputStreamReader(con.getErrorStream(), "UTF-8"))) {
|
||||||
|
// StringBuilder errorResponse = new StringBuilder();
|
||||||
|
// String errorLine;
|
||||||
|
// while ((errorLine = br.readLine()) != null) {
|
||||||
|
// errorResponse.append(errorLine.trim());
|
||||||
|
// }
|
||||||
|
// errorMsg = errorResponse.toString();
|
||||||
|
// System.out.println("Error Response: " + errorResponse.toString());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } catch (IOException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// return errorMsg;
|
||||||
|
// }
|
||||||
|
}
|
|
@ -0,0 +1,65 @@
|
||||||
|
package com.nu.modules.tq.utils;
|
||||||
|
|
||||||
|
import com.nu.modules.tq.common.entity.TqConfig;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class SignTool {
|
||||||
|
|
||||||
|
// 生成签名字符串
|
||||||
|
public static String getSign(String nonce,Map<String, String> data)
|
||||||
|
{
|
||||||
|
// 获取关键字列表
|
||||||
|
List<String> keys = new ArrayList<>(data.keySet());
|
||||||
|
// 关键字列表排序
|
||||||
|
keys.sort(Comparator.naturalOrder());
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (String key : keys)
|
||||||
|
{
|
||||||
|
// 取各个字段内容拼接字符串
|
||||||
|
sb.append(data.get(key));
|
||||||
|
}
|
||||||
|
// 加上双方约定随机字符串
|
||||||
|
String txt = sb.toString() + nonce;
|
||||||
|
|
||||||
|
// 计算哈希值
|
||||||
|
return getMD5(txt);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean checkSign(String response_content, String timestamp, String sign,String nonce) {
|
||||||
|
String buf = response_content + timestamp + nonce;
|
||||||
|
String encode = getMD5(buf);
|
||||||
|
return encode.equals(sign);
|
||||||
|
}
|
||||||
|
|
||||||
|
// md5加密
|
||||||
|
public static String getMD5(String password) {
|
||||||
|
MessageDigest md5 = null;
|
||||||
|
try {
|
||||||
|
md5 = MessageDigest.getInstance("MD5");
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
byte[] byteArray = password.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
byte[] md5Bytes = md5.digest(byteArray);
|
||||||
|
StringBuilder hexValue = new StringBuilder();
|
||||||
|
for (byte md5Byte : md5Bytes) {
|
||||||
|
int val = ((int) md5Byte) & 0xff;
|
||||||
|
if (val < 16) {
|
||||||
|
hexValue.append("0");
|
||||||
|
}
|
||||||
|
|
||||||
|
hexValue.append(Integer.toHexString(val));
|
||||||
|
}
|
||||||
|
return hexValue.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,170 @@
|
||||||
|
package com.nu.modules.tq.utils;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.nu.modules.tq.enums.TqApiEnum;
|
||||||
|
import com.nu.modules.tq.common.entity.TqConfig;
|
||||||
|
import com.nu.modules.tq.common.mapper.TqConfigMapper;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class TqApi {
|
||||||
|
|
||||||
|
TqConfig tqConfig;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
TqConfigMapper tqConfigMapper;
|
||||||
|
|
||||||
|
private void initTqConfig(){
|
||||||
|
if(tqConfig==null){
|
||||||
|
tqConfig = tqConfigMapper.getConfig();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public TqConfig getTqConfig(){
|
||||||
|
this.initTqConfig();
|
||||||
|
return tqConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询设备列表和当前状态
|
||||||
|
*/
|
||||||
|
public String getMeters(){
|
||||||
|
this.initTqConfig();
|
||||||
|
Map<String, Object> params = new HashMap<>();
|
||||||
|
params.put("auth", tqConfig.getAuthCode());
|
||||||
|
String urlParams = HttpTool.getUrlParams(params);
|
||||||
|
log.info("getMeters:request:{}",urlParams);
|
||||||
|
String url = tqConfig.getRequestUrl()+TqApiEnum.METER_INFO.getValue()+"?"+urlParams;
|
||||||
|
String responseStr = HttpTool.httpClientGet(url);
|
||||||
|
log.info("getMeters:response:{}",responseStr);
|
||||||
|
return responseStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询采集器列表和当前状态
|
||||||
|
*/
|
||||||
|
public String getCollectors(){
|
||||||
|
this.initTqConfig();
|
||||||
|
Map<String, Object> params = new HashMap<>();
|
||||||
|
params.put("auth", tqConfig.getAuthCode());
|
||||||
|
String urlParams = HttpTool.getUrlParams(params);
|
||||||
|
log.info("getCollectors:request:{}",urlParams);
|
||||||
|
String url = tqConfig.getRequestUrl()+TqApiEnum.COLLECTOR_INFO.getValue()+"?"+urlParams;
|
||||||
|
String responseStr = HttpTool.httpClientGet(url);
|
||||||
|
log.info("getCollectors:response:{}",responseStr);
|
||||||
|
return responseStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 电表清零
|
||||||
|
*/
|
||||||
|
public String eleReset(List<Map<String, Object>> req){
|
||||||
|
this.initTqConfig();
|
||||||
|
String request_content = JSON.toJSONString(req);
|
||||||
|
log.info("eleReset:request:{}",request_content);
|
||||||
|
String url = tqConfig.getRequestUrl()+TqApiEnum.ELE_RESET.getValue();
|
||||||
|
String notifyUrl = tqConfig.getNotifyUrl()+"/electricityMeter/eleResetNotify";
|
||||||
|
String responseStr = requestAsync(url,request_content,notifyUrl);
|
||||||
|
log.info("eleReset:response:{}",responseStr);
|
||||||
|
return responseStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 电表开关闸
|
||||||
|
*/
|
||||||
|
public String eleControl(List<Map<String, Object>> req){
|
||||||
|
this.initTqConfig();
|
||||||
|
String request_content = JSON.toJSONString(req);
|
||||||
|
log.info("eleControl:request:{}",request_content);
|
||||||
|
String url = tqConfig.getRequestUrl()+TqApiEnum.ELE_CONTROL.getValue();
|
||||||
|
String notifyUrl = tqConfig.getNotifyUrl()+"/electricityMeter/eleControlNotify";
|
||||||
|
String responseStr = requestAsync(url,request_content,notifyUrl);
|
||||||
|
log.info("eleControl:response:{}",responseStr);
|
||||||
|
return responseStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 电表抄表
|
||||||
|
*/
|
||||||
|
public String eleRead(List<Map<String, Object>> req){
|
||||||
|
this.initTqConfig();
|
||||||
|
String request_content = JSON.toJSONString(req);
|
||||||
|
log.info("eleRead:request:{}",request_content);
|
||||||
|
String url = tqConfig.getRequestUrl()+TqApiEnum.ELE_READ.getValue();
|
||||||
|
String notifyUrl = tqConfig.getNotifyUrl()+"/electricityMeter/eleReadNotify";
|
||||||
|
String responseStr = requestAsync(url,request_content,notifyUrl);
|
||||||
|
log.info("eleRead:response:{}",responseStr);
|
||||||
|
return responseStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 水表清零
|
||||||
|
*/
|
||||||
|
public String waterReset(List<Map<String, Object>> req){
|
||||||
|
this.initTqConfig();
|
||||||
|
String request_content = JSON.toJSONString(req);
|
||||||
|
log.info("eleReset:request:{}",request_content);
|
||||||
|
String url = tqConfig.getRequestUrl()+TqApiEnum.WATER_RESET.getValue();
|
||||||
|
String notifyUrl = tqConfig.getNotifyUrl()+"/waterMeter/waterResetNotify";
|
||||||
|
String responseStr = requestAsync(url,request_content,notifyUrl);
|
||||||
|
log.info("eleReset:response:{}",responseStr);
|
||||||
|
return responseStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 水表开关闸
|
||||||
|
*/
|
||||||
|
public String waterControl(List<Map<String, Object>> req){
|
||||||
|
this.initTqConfig();
|
||||||
|
String request_content = JSON.toJSONString(req);
|
||||||
|
log.info("waterControl:request:{}",request_content);
|
||||||
|
String url = tqConfig.getRequestUrl()+TqApiEnum.WATER_CONTROL.getValue();
|
||||||
|
String notifyUrl = tqConfig.getNotifyUrl()+"/waterMeter/waterControlNotify";
|
||||||
|
String responseStr = requestAsync(url,request_content,notifyUrl);
|
||||||
|
log.info("waterControl:response:{}",responseStr);
|
||||||
|
return responseStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 水表抄表
|
||||||
|
*/
|
||||||
|
public String waterRead(List<Map<String, Object>> req){
|
||||||
|
this.initTqConfig();
|
||||||
|
String request_content = JSON.toJSONString(req);
|
||||||
|
log.info("waterRead:request:{}",request_content);
|
||||||
|
String url = tqConfig.getRequestUrl()+TqApiEnum.WATER_READ.getValue();
|
||||||
|
String notifyUrl = tqConfig.getNotifyUrl()+"/waterMeter/waterReadNotify";
|
||||||
|
String responseStr = requestAsync(url,request_content,notifyUrl);
|
||||||
|
log.info("waterRead:response:{}",responseStr);
|
||||||
|
return responseStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String requestAsync(String url, String request_content,String notifyUrl){
|
||||||
|
// 时间戳
|
||||||
|
String timestamp = String.valueOf(new Date().getTime()/1000);
|
||||||
|
// 用于签名的内容
|
||||||
|
Map<String, String> data = new HashMap<>();
|
||||||
|
data.put("timestamp", timestamp);
|
||||||
|
data.put("auth_code", tqConfig.getAuthCode());
|
||||||
|
data.put("request_content", request_content);
|
||||||
|
data.put("notify_url", notifyUrl);
|
||||||
|
// 获取签名
|
||||||
|
String sign = SignTool.getSign(tqConfig.getRandomCode(),data);
|
||||||
|
data.put("sign", sign);
|
||||||
|
try {
|
||||||
|
return HttpTool.httpClientPost(url, data);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,76 @@
|
||||||
|
package com.nu.modules.tq.water.api;
|
||||||
|
|
||||||
|
import com.nu.modules.tq.water.entity.WaterMeter;
|
||||||
|
import com.nu.modules.tq.water.service.IWaterMeterService;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.jeecg.common.system.base.controller.JeecgController;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/iot/tq/api/waterMeter")
|
||||||
|
public class WaterMeterApiController extends JeecgController<WaterMeter, IWaterMeterService> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IWaterMeterService service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 水表清零回调
|
||||||
|
* @param response_content
|
||||||
|
* @param timestamp
|
||||||
|
* @param sign
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/waterResetNotify")
|
||||||
|
@ApiOperation("水表清零回调")
|
||||||
|
public String waterResetNotify(String response_content, String timestamp, String sign) {
|
||||||
|
log.info("waterResetNotify:response_content:{}",response_content);
|
||||||
|
log.info("waterResetNotify:timestamp:{}",timestamp);
|
||||||
|
log.info("waterResetNotify:sign:{}",sign);
|
||||||
|
//-----------加入业务逻辑-----------
|
||||||
|
String result = service.waterResetNotify(response_content, timestamp, sign);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 水表开关闸回调
|
||||||
|
* @param response_content
|
||||||
|
* @param timestamp
|
||||||
|
* @param sign
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/waterControlNotify")
|
||||||
|
@ApiOperation("水表开关闸回调")
|
||||||
|
public String waterControlNotify(String response_content, String timestamp, String sign) {
|
||||||
|
log.info("waterControlNotify:response_content:{}",response_content);
|
||||||
|
log.info("waterControlNotify:timestamp:{}",timestamp);
|
||||||
|
log.info("waterControlNotify:sign:{}",sign);
|
||||||
|
//-----------加入业务逻辑-----------
|
||||||
|
String result = service.waterControlNotify(response_content, timestamp, sign);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 水表抄表回调
|
||||||
|
* @param response_content
|
||||||
|
* @param timestamp
|
||||||
|
* @param sign
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/waterReadNotify")
|
||||||
|
@ApiOperation("水表抄表回调")
|
||||||
|
public String waterReadNotify(String response_content, String timestamp, String sign) {
|
||||||
|
log.info("waterReadNotify:response_content:{}",response_content);
|
||||||
|
log.info("waterReadNotify:timestamp:{}",timestamp);
|
||||||
|
log.info("waterReadNotify:sign:{}",sign);
|
||||||
|
//-----------加入业务逻辑-----------
|
||||||
|
String result = service.waterReadNotify(response_content, timestamp, sign);
|
||||||
|
//--------------------------------
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
package com.nu.modules.tq.water.controller;
|
||||||
|
|
||||||
|
import com.nu.modules.tq.water.entity.WaterMeter;
|
||||||
|
import com.nu.modules.tq.water.service.IWaterMeterService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.jeecg.common.api.vo.Result;
|
||||||
|
import org.jeecg.common.system.base.controller.JeecgController;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/iot/tq/waterMeter")
|
||||||
|
public class WaterMeterController extends JeecgController<WaterMeter, IWaterMeterService> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IWaterMeterService service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清零
|
||||||
|
* @param waterMeter
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping(value = "/waterReset")
|
||||||
|
public Result<String> waterReset(WaterMeter waterMeter) {
|
||||||
|
return service.waterReset(waterMeter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开闸、关闸
|
||||||
|
* @param waterMeter
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping(value = "/waterControl")
|
||||||
|
public Result<String> waterControl(WaterMeter waterMeter) {
|
||||||
|
return service.waterControl(waterMeter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抄表
|
||||||
|
* @param waterMeter
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping(value = "/waterRead")
|
||||||
|
public Result<String> waterRead(WaterMeter waterMeter) {
|
||||||
|
return service.waterRead(waterMeter);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,72 @@
|
||||||
|
package com.nu.modules.tq.water.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Class :物联电表管理Entity
|
||||||
|
* <p>功能描述:功能描述
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName("nu_iot_tq_electricity_meter")
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@ApiModel(value="nu_iot_tq_electricity_meter对象", description="物联电表")
|
||||||
|
public class WaterMeter implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
@ApiModelProperty(value = "主键")
|
||||||
|
private Integer id;
|
||||||
|
@Excel(name = "采集器号", width = 15)
|
||||||
|
@ApiModelProperty(value = "采集器号,4G、NB设备采集器号与表号一致")
|
||||||
|
private String cid;
|
||||||
|
@Excel(name = "表号", width = 15)
|
||||||
|
@ApiModelProperty(value = "表号(表地址)")
|
||||||
|
private String address;
|
||||||
|
@Excel(name = "操作类型", width = 15)
|
||||||
|
@ApiModelProperty(value = "操作类型")
|
||||||
|
@TableField(exist = false)
|
||||||
|
private Integer type;//49清零 42抄表 10电表拉闸 11电表合闸 43水表开闸 53水表关闸
|
||||||
|
@Excel(name = "水表值", width = 15)
|
||||||
|
@ApiModelProperty(value = "水表值")
|
||||||
|
private String waterValue; //电表-电量值
|
||||||
|
@Excel(name = "阀门状态", width = 15)
|
||||||
|
@ApiModelProperty(value = "阀门状态")
|
||||||
|
private String relayState; //电表-阀门状态 1 表示合闸/开阀, 0 表示拉闸/关阀,其他,表示未知状态或异常
|
||||||
|
@Excel(name = "水表电池状态", width = 15)
|
||||||
|
@ApiModelProperty(value = "水表电池状态")
|
||||||
|
private String batteryState; //水表电池状态 0 正常 , 1 电池低电压,其他 电池低电压
|
||||||
|
@Excel(name = "在线状态", width = 15)
|
||||||
|
@ApiModelProperty(value = "在线状态")
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String online; //采集器-在线状态 true 在线 false 离线
|
||||||
|
@Excel(name = "信号值", width = 15)
|
||||||
|
@ApiModelProperty(value = "信号值")
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String csq ; //采集器-信号值 1-31 。 20以上算信号稳定
|
||||||
|
@Excel(name = "上次掉线时间", width = 15)
|
||||||
|
@ApiModelProperty(value = "上次掉线时间")
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String disconnectTime; //采集器-上次掉线时间 online = false 时
|
||||||
|
@Excel(name = "上次上线时间", width = 15)
|
||||||
|
@ApiModelProperty(value = "上次上线时间")
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String connectTime; //采集器-上次上线时间 online = true 时
|
||||||
|
@Excel(name = "上次查表时间", width = 15)
|
||||||
|
@ApiModelProperty(value = "上次查表时间")
|
||||||
|
private String readTime; //电表-上次查表时间
|
||||||
|
@Excel(name = "描述", width = 15)
|
||||||
|
@ApiModelProperty(value = "描述")
|
||||||
|
private String remark;
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.nu.modules.tq.water.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.nu.modules.tq.water.entity.WaterMeter;
|
||||||
|
|
||||||
|
public interface WaterMeterMapper extends BaseMapper<WaterMeter> {
|
||||||
|
WaterMeter getWaterMeter(WaterMeter waterMeter);
|
||||||
|
int insert(WaterMeter waterMeter);
|
||||||
|
int update(WaterMeter waterMeter);
|
||||||
|
int updateValue(WaterMeter waterMeter);
|
||||||
|
int updateRelayState(WaterMeter waterMeter);
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.nu.modules.tq.water.mapper.WaterMeterMapper">
|
||||||
|
|
||||||
|
<select id="getWaterMeter" parameterType="com.nu.modules.tq.water.entity.WaterMeter" resultType="com.nu.modules.tq.water.entity.WaterMeter">
|
||||||
|
select
|
||||||
|
id,
|
||||||
|
cid,
|
||||||
|
address,
|
||||||
|
water_value as waterValue,
|
||||||
|
relay_state as relayState,
|
||||||
|
battery_state as batteryState,
|
||||||
|
remark
|
||||||
|
from nu_iot_tq_water_meter
|
||||||
|
where cid = #{cid}
|
||||||
|
and address = #{address}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<insert id="insert" parameterType="com.nu.modules.tq.water.entity.WaterMeter">
|
||||||
|
insert into nu_iot_tq_water_meter(
|
||||||
|
cid,
|
||||||
|
address,
|
||||||
|
relay_state,
|
||||||
|
battery_state,
|
||||||
|
remark,
|
||||||
|
create_time
|
||||||
|
)
|
||||||
|
values(
|
||||||
|
#{cid},
|
||||||
|
#{address},
|
||||||
|
#{relayState},
|
||||||
|
#{batteryState},
|
||||||
|
#{remark},
|
||||||
|
now()
|
||||||
|
)
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<update id="update" parameterType="com.nu.modules.tq.water.entity.WaterMeter">
|
||||||
|
update nu_iot_tq_water_meter
|
||||||
|
set
|
||||||
|
relay_state = #{relayState},
|
||||||
|
battery_state = #{batteryState},
|
||||||
|
remark = #{remark},
|
||||||
|
update_time = now()
|
||||||
|
where cid = #{cid}
|
||||||
|
and address = #{address}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<update id="updateValue" parameterType="com.nu.modules.tq.water.entity.WaterMeter">
|
||||||
|
update nu_iot_tq_water_meter
|
||||||
|
set
|
||||||
|
water_value = #{waterValue},
|
||||||
|
read_time = #{readTime},
|
||||||
|
update_time = now()
|
||||||
|
where cid = #{cid}
|
||||||
|
and address = #{address}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<update id="updateRelayState" parameterType="com.nu.modules.tq.water.entity.WaterMeter">
|
||||||
|
update nu_iot_tq_water_meter
|
||||||
|
set
|
||||||
|
relay_state = #{relayState},
|
||||||
|
update_time = now()
|
||||||
|
where cid = #{cid}
|
||||||
|
and address = #{address}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.nu.modules.tq.water.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.nu.modules.tq.water.entity.WaterMeter;
|
||||||
|
import org.jeecg.common.api.vo.Result;
|
||||||
|
|
||||||
|
public interface IWaterMeterService extends IService<WaterMeter> {
|
||||||
|
|
||||||
|
Result<String> waterReset(WaterMeter waterMeter);
|
||||||
|
Result<String> waterControl(WaterMeter waterMeter);
|
||||||
|
Result<String> waterRead(WaterMeter waterMeter);
|
||||||
|
|
||||||
|
String waterResetNotify(String response_content, String timestamp, String sign);
|
||||||
|
String waterControlNotify(String response_content, String timestamp, String sign);
|
||||||
|
String waterReadNotify(String response_content, String timestamp, String sign);
|
||||||
|
}
|
|
@ -0,0 +1,421 @@
|
||||||
|
package com.nu.modules.tq.water.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.json.JSONArray;
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.nu.modules.tq.common.entity.TqApiLog;
|
||||||
|
import com.nu.modules.tq.common.service.ITqApiLogService;
|
||||||
|
import com.nu.modules.tq.electricity.entity.ElectricityMeter;
|
||||||
|
import com.nu.modules.tq.electricity.mapper.ElectricityMeterMapper;
|
||||||
|
import com.nu.modules.tq.electricity.service.IElectricityMeterService;
|
||||||
|
import com.nu.modules.tq.utils.HttpTool;
|
||||||
|
import com.nu.modules.tq.utils.SignTool;
|
||||||
|
import com.nu.modules.tq.utils.TqApi;
|
||||||
|
import com.nu.modules.tq.water.entity.WaterMeter;
|
||||||
|
import com.nu.modules.tq.water.mapper.WaterMeterMapper;
|
||||||
|
import com.nu.modules.tq.water.service.IWaterMeterService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.jeecg.common.api.vo.Result;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class WaterMeterServiceImpl extends ServiceImpl<WaterMeterMapper, WaterMeter> implements IWaterMeterService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
TqApi tqApi;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ITqApiLogService logService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清零
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Result<String> waterReset(WaterMeter waterMeter){
|
||||||
|
WaterMeter entity = baseMapper.getWaterMeter(waterMeter);
|
||||||
|
if(entity == null){
|
||||||
|
return Result.error("请先同步水表设备信息后再进行清零");
|
||||||
|
}
|
||||||
|
String readTimeStr = entity.getReadTime();
|
||||||
|
if(readTimeStr == null || readTimeStr.equals("")){
|
||||||
|
return Result.error("请先进行抄表再进行清零");
|
||||||
|
}
|
||||||
|
Date readTime = DateUtil.parse(readTimeStr,"yyyy-MM-dd HH:mm:ss");
|
||||||
|
Calendar c = Calendar.getInstance();
|
||||||
|
c.add(Calendar.HOUR_OF_DAY,-1);
|
||||||
|
int comInt = DateUtil.compare(readTime,c.getTime());
|
||||||
|
if(comInt<0){
|
||||||
|
return Result.error("请先进行抄表再进行清零");
|
||||||
|
}
|
||||||
|
List<Map<String, Object>> req = new ArrayList<>();
|
||||||
|
Map<String, Object> params = new HashMap<>();
|
||||||
|
params.put("paymentmode", "noprepay");
|
||||||
|
Map<String, Object> item = new HashMap<>();
|
||||||
|
item.put("opr_id", HttpTool.generateOperateId());
|
||||||
|
item.put("time_out", 0);
|
||||||
|
item.put("must_online", true);
|
||||||
|
item.put("retry_times", 1);
|
||||||
|
item.put("cid", waterMeter.getCid());
|
||||||
|
item.put("address", waterMeter.getAddress());
|
||||||
|
item.put("params", params);
|
||||||
|
req.add(item);
|
||||||
|
String responseStr = tqApi.waterReset(req);
|
||||||
|
JSONObject jsonObject = new JSONObject(responseStr);
|
||||||
|
String httpStatus = jsonObject.getStr("status");
|
||||||
|
if(httpStatus.equals("SUCCESS")){
|
||||||
|
String response_content = jsonObject.getStr("response_content");
|
||||||
|
JSONArray jsonArray = new JSONArray(response_content);
|
||||||
|
for(int i=0;i<jsonArray.size();i++){
|
||||||
|
JSONObject json = (JSONObject)jsonArray.get(i);
|
||||||
|
String status = json.getStr("status");//状态
|
||||||
|
String oprId = json.getStr("opr_id");//操作ID
|
||||||
|
if(status.equals("SUCCESS")){
|
||||||
|
TqApiLog tqApiLog = new TqApiLog();
|
||||||
|
tqApiLog.setOprId(oprId);
|
||||||
|
tqApiLog.setCid(waterMeter.getCid());
|
||||||
|
tqApiLog.setAddress(waterMeter.getAddress());
|
||||||
|
tqApiLog.setType(49);
|
||||||
|
tqApiLog.setResolveValue(entity.getWaterValue());
|
||||||
|
tqApiLog.setRequestTime(DateUtil.now());
|
||||||
|
tqApiLog.setRequestStatus(status);
|
||||||
|
logService.insert(tqApiLog);
|
||||||
|
}else{
|
||||||
|
String errorMsg = json.getStr("error_msg");
|
||||||
|
TqApiLog tqApiLog = new TqApiLog();
|
||||||
|
tqApiLog.setOprId(oprId);
|
||||||
|
tqApiLog.setCid(waterMeter.getCid());
|
||||||
|
tqApiLog.setAddress(waterMeter.getAddress());
|
||||||
|
tqApiLog.setType(49);
|
||||||
|
tqApiLog.setResolveValue(entity.getWaterValue());
|
||||||
|
tqApiLog.setRequestTime(DateUtil.now());
|
||||||
|
tqApiLog.setRequestStatus(status);
|
||||||
|
tqApiLog.setRequestRemark(errorMsg);
|
||||||
|
logService.insert(tqApiLog);
|
||||||
|
return Result.error(errorMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
String errorMsg = jsonObject.getStr("error_msg");
|
||||||
|
TqApiLog tqApiLog = new TqApiLog();
|
||||||
|
tqApiLog.setCid(waterMeter.getCid());
|
||||||
|
tqApiLog.setAddress(waterMeter.getAddress());
|
||||||
|
tqApiLog.setType(49);
|
||||||
|
tqApiLog.setResolveValue(entity.getWaterValue());
|
||||||
|
tqApiLog.setRequestTime(DateUtil.now());
|
||||||
|
tqApiLog.setRequestStatus(httpStatus);
|
||||||
|
tqApiLog.setRequestRemark(errorMsg);
|
||||||
|
logService.insert(tqApiLog);
|
||||||
|
return Result.error(errorMsg);
|
||||||
|
}
|
||||||
|
return Result.OK("清零成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开关闸
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Result<String> waterControl(WaterMeter waterMeter){
|
||||||
|
Integer type = waterMeter.getType();
|
||||||
|
WaterMeter entity = baseMapper.getWaterMeter(waterMeter);
|
||||||
|
if(entity == null){
|
||||||
|
if(type.equals("43")){
|
||||||
|
return Result.error("请先同步水表设备信息后再进行开闸");
|
||||||
|
}else{
|
||||||
|
return Result.error("请先同步水表设备信息后再进行关闸");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<Map<String, Object>> req = new ArrayList<>();
|
||||||
|
Map<String, Object> item = new HashMap<>();
|
||||||
|
item.put("opr_id", HttpTool.generateOperateId());
|
||||||
|
item.put("time_out", 0);
|
||||||
|
item.put("must_online", true);
|
||||||
|
item.put("retry_times", 1);
|
||||||
|
item.put("cid", waterMeter.getCid());
|
||||||
|
item.put("address", waterMeter.getAddress());
|
||||||
|
item.put("type", type);
|
||||||
|
req.add(item);
|
||||||
|
String responseStr = tqApi.waterReset(req);
|
||||||
|
JSONObject jsonObject = new JSONObject(responseStr);
|
||||||
|
String httpStatus = jsonObject.getStr("status");
|
||||||
|
if(httpStatus.equals("SUCCESS")){
|
||||||
|
String response_content = jsonObject.getStr("response_content");
|
||||||
|
JSONArray jsonArray = new JSONArray(response_content);
|
||||||
|
for(int i=0;i<jsonArray.size();i++){
|
||||||
|
JSONObject json = (JSONObject)jsonArray.get(i);
|
||||||
|
String status = json.getStr("status");//状态
|
||||||
|
String oprId = json.getStr("opr_id");//操作ID
|
||||||
|
if(status.equals("SUCCESS")){
|
||||||
|
TqApiLog tqApiLog = new TqApiLog();
|
||||||
|
tqApiLog.setOprId(oprId);
|
||||||
|
tqApiLog.setCid(waterMeter.getCid());
|
||||||
|
tqApiLog.setAddress(waterMeter.getAddress());
|
||||||
|
tqApiLog.setType(waterMeter.getType());
|
||||||
|
tqApiLog.setRequestTime(DateUtil.now());
|
||||||
|
tqApiLog.setRequestStatus(status);
|
||||||
|
logService.insert(tqApiLog);
|
||||||
|
}else{
|
||||||
|
String errorMsg = json.getStr("error_msg");
|
||||||
|
TqApiLog tqApiLog = new TqApiLog();
|
||||||
|
tqApiLog.setOprId(oprId);
|
||||||
|
tqApiLog.setCid(waterMeter.getCid());
|
||||||
|
tqApiLog.setAddress(waterMeter.getAddress());
|
||||||
|
tqApiLog.setType(waterMeter.getType());
|
||||||
|
tqApiLog.setRequestTime(DateUtil.now());
|
||||||
|
tqApiLog.setRequestStatus(status);
|
||||||
|
tqApiLog.setRequestRemark(errorMsg);
|
||||||
|
logService.insert(tqApiLog);
|
||||||
|
return Result.error(errorMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
String errorMsg = jsonObject.getStr("error_msg");
|
||||||
|
TqApiLog tqApiLog = new TqApiLog();
|
||||||
|
tqApiLog.setCid(waterMeter.getCid());
|
||||||
|
tqApiLog.setAddress(waterMeter.getAddress());
|
||||||
|
tqApiLog.setType(waterMeter.getType());
|
||||||
|
tqApiLog.setRequestTime(DateUtil.now());
|
||||||
|
tqApiLog.setRequestStatus(httpStatus);
|
||||||
|
tqApiLog.setRequestRemark(errorMsg);
|
||||||
|
logService.insert(tqApiLog);
|
||||||
|
return Result.error(errorMsg);
|
||||||
|
}
|
||||||
|
if(type.equals(43)){
|
||||||
|
return Result.OK("开闸成功");
|
||||||
|
}else{
|
||||||
|
return Result.OK("关闸成功");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抄水表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Result<String> waterRead(WaterMeter waterMeter){
|
||||||
|
WaterMeter entity = baseMapper.getWaterMeter(waterMeter);
|
||||||
|
if(entity == null){
|
||||||
|
return Result.error("请先同步水表设备信息后再进行抄表");
|
||||||
|
}
|
||||||
|
List<Map<String, Object>> req = new ArrayList<>();
|
||||||
|
Map<String, Object> item = new HashMap<>();
|
||||||
|
item.put("opr_id", HttpTool.generateOperateId());
|
||||||
|
item.put("time_out", 0);
|
||||||
|
item.put("must_online", true);
|
||||||
|
item.put("retry_times", 1);
|
||||||
|
item.put("cid", waterMeter.getCid());
|
||||||
|
item.put("address", waterMeter.getAddress());
|
||||||
|
item.put("type", 42);
|
||||||
|
req.add(item);
|
||||||
|
String responseStr = tqApi.waterRead(req);
|
||||||
|
JSONObject jsonObject = new JSONObject(responseStr);
|
||||||
|
String httpStatus = jsonObject.getStr("status");
|
||||||
|
if(httpStatus.equals("SUCCESS")){
|
||||||
|
String response_content = jsonObject.getStr("response_content");
|
||||||
|
JSONArray jsonArray = new JSONArray(response_content);
|
||||||
|
for(int i=0;i<jsonArray.size();i++){
|
||||||
|
JSONObject json = (JSONObject)jsonArray.get(i);
|
||||||
|
String status = json.getStr("status");//状态
|
||||||
|
String oprId = json.getStr("opr_id");//操作ID
|
||||||
|
if(status.equals("SUCCESS")){
|
||||||
|
TqApiLog tqApiLog = new TqApiLog();
|
||||||
|
tqApiLog.setOprId(oprId);
|
||||||
|
tqApiLog.setCid(waterMeter.getCid());
|
||||||
|
tqApiLog.setAddress(waterMeter.getAddress());
|
||||||
|
tqApiLog.setType(42);
|
||||||
|
tqApiLog.setResolveValue(entity.getWaterValue());
|
||||||
|
tqApiLog.setRequestTime(DateUtil.now());
|
||||||
|
tqApiLog.setRequestStatus(status);
|
||||||
|
logService.insert(tqApiLog);
|
||||||
|
}else{
|
||||||
|
String errorMsg = json.getStr("error_msg");
|
||||||
|
TqApiLog tqApiLog = new TqApiLog();
|
||||||
|
tqApiLog.setOprId(oprId);
|
||||||
|
tqApiLog.setCid(waterMeter.getCid());
|
||||||
|
tqApiLog.setAddress(waterMeter.getAddress());
|
||||||
|
tqApiLog.setType(42);
|
||||||
|
tqApiLog.setResolveValue(entity.getWaterValue());
|
||||||
|
tqApiLog.setRequestTime(DateUtil.now());
|
||||||
|
tqApiLog.setRequestStatus(status);
|
||||||
|
tqApiLog.setRequestRemark(errorMsg);
|
||||||
|
logService.insert(tqApiLog);
|
||||||
|
return Result.error(errorMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
String errorMsg = jsonObject.getStr("error_msg");
|
||||||
|
TqApiLog tqApiLog = new TqApiLog();
|
||||||
|
tqApiLog.setCid(waterMeter.getCid());
|
||||||
|
tqApiLog.setAddress(waterMeter.getAddress());
|
||||||
|
tqApiLog.setType(42);
|
||||||
|
tqApiLog.setResolveValue(entity.getWaterValue());
|
||||||
|
tqApiLog.setRequestTime(DateUtil.now());
|
||||||
|
tqApiLog.setRequestStatus(httpStatus);
|
||||||
|
tqApiLog.setRequestRemark(errorMsg);
|
||||||
|
logService.insert(tqApiLog);
|
||||||
|
return Result.error(errorMsg);
|
||||||
|
}
|
||||||
|
return Result.OK("抄表成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清零回调通知
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String waterResetNotify(String response_content, String timestamp, String sign){
|
||||||
|
// 验签
|
||||||
|
if(!SignTool.checkSign(response_content, timestamp, sign, tqApi.getTqConfig().getRandomCode())) {
|
||||||
|
log.info("eleResetNotify:sign check failed");
|
||||||
|
return "sign check failed";
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
JSONArray jsonArray = new JSONArray(response_content);
|
||||||
|
for(int i=0;i<jsonArray.size();i++){
|
||||||
|
JSONObject jsonObject = (JSONObject)jsonArray.get(i);
|
||||||
|
String status = jsonObject.getStr("status");//返回状态
|
||||||
|
String oprId = jsonObject.getStr("opr_id");//操作ID
|
||||||
|
String resolveTime = jsonObject.getStr("resolve_time");//反馈时间
|
||||||
|
TqApiLog tqApiLog = new TqApiLog();
|
||||||
|
tqApiLog.setOprId(oprId);
|
||||||
|
tqApiLog.setResolveValue("0");
|
||||||
|
tqApiLog.setResolveTime(resolveTime);
|
||||||
|
tqApiLog.setResolveStatus(status);
|
||||||
|
TqApiLog logEntity = logService.getApiLog(tqApiLog);
|
||||||
|
if(logEntity!=null) {
|
||||||
|
tqApiLog.setId(logEntity.getId());
|
||||||
|
logService.update(tqApiLog);
|
||||||
|
}
|
||||||
|
if(status.equals("SUCCESS")) {
|
||||||
|
if(logEntity!=null){
|
||||||
|
String cid = logEntity.getCid();
|
||||||
|
String address = logEntity.getAddress();
|
||||||
|
WaterMeter wm = new WaterMeter();
|
||||||
|
wm.setCid(cid);
|
||||||
|
wm.setAddress(address);
|
||||||
|
wm.setWaterValue("0");
|
||||||
|
baseMapper.updateValue(wm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
return "FAIL";
|
||||||
|
}
|
||||||
|
return "SUCCESS";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开关闸回调通知
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String waterControlNotify(String response_content, String timestamp, String sign){
|
||||||
|
// 验签
|
||||||
|
if(!SignTool.checkSign(response_content, timestamp, sign, tqApi.getTqConfig().getRandomCode())) {
|
||||||
|
log.info("eleResetNotify:sign check failed");
|
||||||
|
return "sign check failed";
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
JSONArray jsonArray = new JSONArray(response_content);
|
||||||
|
for(int i=0;i<jsonArray.size();i++){
|
||||||
|
JSONObject jsonObject = (JSONObject)jsonArray.get(i);
|
||||||
|
String status = jsonObject.getStr("status");//返回状态
|
||||||
|
String oprId = jsonObject.getStr("opr_id");//操作ID
|
||||||
|
String resolveTime = jsonObject.getStr("resolve_time");//反馈时间
|
||||||
|
TqApiLog tqApiLog = new TqApiLog();
|
||||||
|
tqApiLog.setOprId(oprId);
|
||||||
|
tqApiLog.setResolveTime(resolveTime);
|
||||||
|
tqApiLog.setResolveStatus(status);
|
||||||
|
TqApiLog logEntity = logService.getApiLog(tqApiLog);
|
||||||
|
if(logEntity!=null) {
|
||||||
|
tqApiLog.setId(logEntity.getId());
|
||||||
|
logService.update(tqApiLog);
|
||||||
|
}
|
||||||
|
if(status.equals("SUCCESS")) {
|
||||||
|
if(logEntity!=null){
|
||||||
|
String cid = logEntity.getCid();
|
||||||
|
String address = logEntity.getAddress();
|
||||||
|
Integer type = logEntity.getType();
|
||||||
|
WaterMeter wm = new WaterMeter();
|
||||||
|
wm.setCid(cid);
|
||||||
|
wm.setAddress(address);
|
||||||
|
if(type.equals(43)){
|
||||||
|
wm.setRelayState("1");
|
||||||
|
}else{
|
||||||
|
wm.setRelayState("0");
|
||||||
|
}
|
||||||
|
baseMapper.updateRelayState(wm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
return "FAIL";
|
||||||
|
}
|
||||||
|
return "SUCCESS";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抄表回调通知
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String waterReadNotify(String response_content, String timestamp, String sign){
|
||||||
|
// 验签
|
||||||
|
if(!SignTool.checkSign(response_content, timestamp, sign, tqApi.getTqConfig().getRandomCode())) {
|
||||||
|
log.info("eleResetNotify:sign check failed");
|
||||||
|
return "sign check failed";
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
JSONArray jsonArray = new JSONArray(response_content);
|
||||||
|
for(int i=0;i<jsonArray.size();i++){
|
||||||
|
JSONObject jsonObject = (JSONObject)jsonArray.get(i);
|
||||||
|
String status = jsonObject.getStr("status");//返回状态
|
||||||
|
String oprId = jsonObject.getStr("opr_id");//操作ID
|
||||||
|
String resolveTime = jsonObject.getStr("resolve_time");//反馈时间
|
||||||
|
if(status.equals("SUCCESS")) {
|
||||||
|
JSONArray datas = jsonObject.getJSONArray("data");//返回数据
|
||||||
|
for(int j=0;j<datas.size();j++){
|
||||||
|
JSONObject data = (JSONObject)datas.get(j);
|
||||||
|
Integer type = data.getInt("type");//类型
|
||||||
|
String resolveValue = data.getJSONArray("value").get(0).toString();//值
|
||||||
|
String dsp = data.getStr("dsp");//描述
|
||||||
|
|
||||||
|
TqApiLog tqApiLog = new TqApiLog();
|
||||||
|
tqApiLog.setOprId(oprId);
|
||||||
|
tqApiLog.setType(type);
|
||||||
|
tqApiLog.setResolveValue(resolveValue);
|
||||||
|
tqApiLog.setResolveTime(resolveTime);
|
||||||
|
tqApiLog.setResolveStatus(status);
|
||||||
|
tqApiLog.setResolveRemark(dsp);
|
||||||
|
TqApiLog logEntity = logService.getApiLog(tqApiLog);
|
||||||
|
if(logEntity!=null){
|
||||||
|
String cid = logEntity.getCid();
|
||||||
|
String address = logEntity.getAddress();
|
||||||
|
WaterMeter wm = new WaterMeter();
|
||||||
|
wm.setCid(cid);
|
||||||
|
wm.setAddress(address);
|
||||||
|
wm.setWaterValue(resolveValue);
|
||||||
|
wm.setReadTime(resolveTime);
|
||||||
|
baseMapper.updateValue(wm);
|
||||||
|
tqApiLog.setId(logEntity.getId());
|
||||||
|
logService.update(tqApiLog);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
TqApiLog tqApiLog = new TqApiLog();
|
||||||
|
tqApiLog.setOprId(oprId);
|
||||||
|
tqApiLog.setResolveTime(resolveTime);
|
||||||
|
tqApiLog.setResolveStatus(status);
|
||||||
|
TqApiLog logEntity = logService.getApiLog(tqApiLog);
|
||||||
|
if(logEntity!=null){
|
||||||
|
tqApiLog.setId(logEntity.getId());
|
||||||
|
logService.update(tqApiLog);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
return "FAIL";
|
||||||
|
}
|
||||||
|
return "SUCCESS";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue