59 changed files with 883 additions and 459 deletions
@ -1,62 +0,0 @@
|
||||
package com.mh.user.config.mqtt; |
||||
|
||||
import com.mh.user.config.MHConfig; |
||||
import com.mh.user.constants.ChannelName; |
||||
import com.mh.user.constants.TopicEnum; |
||||
import com.mh.user.utils.SpringBeanUtil; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.integration.annotation.Router; |
||||
import org.springframework.integration.mqtt.support.MqttHeaders; |
||||
import org.springframework.integration.router.AbstractMessageRouter; |
||||
import org.springframework.messaging.Message; |
||||
import org.springframework.messaging.MessageChannel; |
||||
import org.springframework.messaging.MessageHeaders; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import java.util.Collection; |
||||
import java.util.Collections; |
||||
import java.util.Objects; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project springboot-mqtt-demo |
||||
* @description 入站消息路由分发中心 |
||||
* @date 2024-10-29 17:04:17 |
||||
*/ |
||||
@Slf4j |
||||
@Component |
||||
public class InboundMessageRouter extends AbstractMessageRouter { |
||||
|
||||
/** 系统基础配置 */ |
||||
@Autowired |
||||
private MHConfig mHConfig; |
||||
|
||||
/** |
||||
* 目前只需要这个方式,后期在拓展使用IntegrationFlow方式 |
||||
* @param message |
||||
* @return |
||||
*/ |
||||
@Router(inputChannel = ChannelName.INBOUND) |
||||
@Override |
||||
protected Collection<MessageChannel> determineTargetChannels(Message<?> message) { |
||||
MessageHeaders headers = message.getHeaders(); |
||||
String topic = Objects.requireNonNull(headers.get(MqttHeaders.RECEIVED_TOPIC)).toString(); |
||||
// byte[] payload = (byte[]) message.getPayload();
|
||||
// log.info("从当前主题 topic: {}, 接收到的消息:{}", topic, new String(payload));
|
||||
// 判断当前主题是否是当前项目的,温湿度目前写死的
|
||||
if (!topic.startsWith(mHConfig.getName()) && !topic.contains("/temp")) { |
||||
log.info("当前主题 topic: {} 不是当前项目的,直接丢弃", topic); |
||||
return Collections.singleton((MessageChannel) SpringBeanUtil.getBean(ChannelName.DEFAULT_BOUND)); |
||||
} |
||||
// 找到对应的主题消息通道
|
||||
if (topic.contains("/temp")) { |
||||
return Collections.singleton((MessageChannel) SpringBeanUtil.getBean(ChannelName.EVENTS_UPLOAD_INBOUND)); |
||||
} else { |
||||
TopicEnum topicEnum = TopicEnum.find(mHConfig.getName() + "/", topic); |
||||
MessageChannel bean = (MessageChannel) SpringBeanUtil.getBean(topicEnum.getBeanName()); |
||||
return Collections.singleton(bean); |
||||
} |
||||
} |
||||
} |
||||
@ -1,99 +0,0 @@
|
||||
package com.mh.user.config.mqtt; |
||||
|
||||
import com.mh.user.constants.MqttClientOptions; |
||||
import com.mh.user.constants.MqttProtocolEnum; |
||||
import com.mh.user.constants.MqttUseEnum; |
||||
import lombok.Data; |
||||
import org.eclipse.paho.client.mqttv3.MqttConnectOptions; |
||||
import org.springframework.boot.context.properties.ConfigurationProperties; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.integration.mqtt.core.DefaultMqttPahoClientFactory; |
||||
import org.springframework.integration.mqtt.core.MqttPahoClientFactory; |
||||
import org.springframework.util.StringUtils; |
||||
|
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project springboot-mqtt-demo |
||||
* @description mqtt连接配置 |
||||
* @date 2024-10-29 14:44:51 |
||||
*/ |
||||
@Configuration |
||||
@Data |
||||
@ConfigurationProperties |
||||
public class MqttConfig { |
||||
|
||||
private static Map<MqttUseEnum, MqttClientOptions> mqttSpring; |
||||
|
||||
public void setMqttSpring(Map<MqttUseEnum, MqttClientOptions> mqtt) { |
||||
MqttConfig.mqttSpring = mqtt; |
||||
} |
||||
|
||||
/** |
||||
* 获取mqtt基本配置 |
||||
* @return |
||||
*/ |
||||
static MqttClientOptions getBasicMqttClientOptions() { |
||||
if (!mqttSpring.containsKey(MqttUseEnum.BASIC)) { |
||||
throw new Error("请先配置MQTT的基本连接参数,否则无法启动项目"); |
||||
} |
||||
return mqttSpring.get(MqttUseEnum.BASIC); |
||||
} |
||||
|
||||
/** |
||||
* 拼接获取对应mqtt的连接地址 |
||||
* @param options |
||||
* @return |
||||
*/ |
||||
public static String getMqttAddress(MqttClientOptions options) { |
||||
StringBuilder addr = new StringBuilder(); |
||||
addr.append(options.getProtocol().getProtocolAddr()) |
||||
.append(options.getHost().trim()) |
||||
.append(":") |
||||
.append(options.getPort()); |
||||
if ((options.getProtocol() == MqttProtocolEnum.WS || options.getProtocol() == MqttProtocolEnum.WSS) |
||||
&& StringUtils.hasText(options.getPath())) { |
||||
addr.append(options.getPath()); |
||||
} |
||||
return addr.toString(); |
||||
} |
||||
|
||||
public static String getBasicMqttAddress() { |
||||
return getMqttAddress(getBasicMqttClientOptions()); |
||||
} |
||||
|
||||
/** |
||||
* 获取连接参数,注入到spring中 |
||||
* @return |
||||
*/ |
||||
@Bean |
||||
public MqttConnectOptions mqttConnectionOptions() { |
||||
|
||||
MqttConnectOptions mqttConnectOptions = new MqttConnectOptions(); |
||||
|
||||
MqttClientOptions customizeOptions = getBasicMqttClientOptions(); |
||||
String basicMqttAddress = getBasicMqttAddress(); |
||||
mqttConnectOptions.setServerURIs(new String[]{basicMqttAddress}); |
||||
mqttConnectOptions.setUserName(StringUtils.hasText(customizeOptions.getUsername()) ? |
||||
customizeOptions.getUsername() : ""); |
||||
mqttConnectOptions.setPassword(StringUtils.hasText(customizeOptions.getPassword()) ? |
||||
customizeOptions.getPassword().toCharArray() : new char[0]); |
||||
// 直接进行自动连接
|
||||
mqttConnectOptions.setAutomaticReconnect(true); |
||||
// 时间间隔时间10s
|
||||
mqttConnectOptions.setKeepAliveInterval(10); |
||||
|
||||
return mqttConnectOptions; |
||||
} |
||||
|
||||
@Bean |
||||
public MqttPahoClientFactory mqttClientFactory() { |
||||
DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory(); |
||||
factory.setConnectionOptions(mqttConnectionOptions()); |
||||
return factory; |
||||
} |
||||
|
||||
} |
||||
@ -1,91 +0,0 @@
|
||||
package com.mh.user.config.mqtt; |
||||
|
||||
import com.mh.user.constants.ChannelName; |
||||
import com.mh.user.constants.MqttClientOptions; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.integration.annotation.IntegrationComponentScan; |
||||
import org.springframework.integration.annotation.ServiceActivator; |
||||
import org.springframework.integration.endpoint.MessageProducerSupport; |
||||
import org.springframework.integration.mqtt.core.MqttPahoClientFactory; |
||||
import org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter; |
||||
import org.springframework.integration.mqtt.support.DefaultPahoMessageConverter; |
||||
import org.springframework.integration.mqtt.support.MqttHeaders; |
||||
import org.springframework.messaging.MessageChannel; |
||||
import org.springframework.messaging.MessageHandler; |
||||
|
||||
import javax.annotation.Resource; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project springboot-mqtt-demo |
||||
* @description 入站配置 |
||||
* @date 2024-10-29 16:22:10 |
||||
*/ |
||||
@Slf4j |
||||
@Configuration |
||||
@IntegrationComponentScan |
||||
public class MqttInboundConfig { |
||||
|
||||
@Autowired |
||||
private MqttPahoClientFactory mqttClientFactory; |
||||
|
||||
@Resource(name = ChannelName.INBOUND) |
||||
private MessageChannel inboundChannel; |
||||
|
||||
private String clientId; |
||||
|
||||
/** |
||||
* 入站适配器 |
||||
* @return |
||||
*/ |
||||
@Bean(name = "adapter") |
||||
public MessageProducerSupport mqttInbound() { |
||||
MqttClientOptions options = MqttConfig.getBasicMqttClientOptions(); |
||||
// 此处初始化的时候,默认订阅了配置文件中已经写好的topic
|
||||
// 如果需要订阅多个,可以自己手动订阅,会写一个addTopic()进行添加订阅
|
||||
clientId = options.getClientId() + "_consumer_" + System.currentTimeMillis(); |
||||
MqttPahoMessageDrivenChannelAdapter adapter = new MqttPahoMessageDrivenChannelAdapter( |
||||
clientId, |
||||
mqttClientFactory, |
||||
options.getInboundTopic().split(",")); |
||||
// System.out.println("每一次都会入站适配器吗?"+clientId);
|
||||
DefaultPahoMessageConverter converter = new DefaultPahoMessageConverter(); |
||||
// 统一是字节处理
|
||||
converter.setPayloadAsBytes(true); |
||||
// 设置消息转换器
|
||||
adapter.setConverter(converter); |
||||
// 设置qos(quality of service)
|
||||
// 0:最多一次传输(消息会丢失),
|
||||
// 1:至少一次传输(消息会重复),
|
||||
// 2:只有当消息发送成功时才确认(消息不回丢,但延迟高)。
|
||||
adapter.setQos(0); |
||||
// 设置在接收已经订阅的主题信息后,发送给哪个通道,具体的发送方法需要翻上层的抽象类
|
||||
adapter.setOutputChannel(inboundChannel); |
||||
return adapter; |
||||
} |
||||
|
||||
/** |
||||
* 默认声明一个消息处理器,用于处理无效的消息 |
||||
* @return |
||||
*/ |
||||
@Bean |
||||
@ServiceActivator(inputChannel = ChannelName.DEFAULT_BOUND) |
||||
public MessageHandler handler() { |
||||
return message -> { |
||||
log.info("The default channel does not handle messages." + |
||||
"\nTopic: {}" + |
||||
"\nPayload: {}", |
||||
message.getHeaders().get(MqttHeaders.RECEIVED_TOPIC), |
||||
message.getPayload()); |
||||
}; |
||||
} |
||||
|
||||
public String getClientId() { |
||||
return clientId; |
||||
} |
||||
|
||||
} |
||||
@ -1,55 +0,0 @@
|
||||
package com.mh.user.config.mqtt; |
||||
|
||||
import com.mh.user.constants.ChannelName; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.integration.channel.DirectChannel; |
||||
import org.springframework.messaging.MessageChannel; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project springboot-mqtt-demo |
||||
* @description 声明所有通道的定义类 |
||||
* @date 2024-10-29 16:23:32 |
||||
*/ |
||||
@Slf4j |
||||
@Configuration |
||||
public class MqttMessageChannel { |
||||
|
||||
@Bean(name = ChannelName.OUTBOUND) |
||||
public MessageChannel outboundChannel() { |
||||
return new DirectChannel(); |
||||
} |
||||
|
||||
@Bean(name = ChannelName.INBOUND) |
||||
public MessageChannel inboundChannel() { |
||||
return new DirectChannel(); |
||||
} |
||||
|
||||
/** |
||||
* 事件主动上报通道 |
||||
* @return |
||||
*/ |
||||
@Bean(name = ChannelName.EVENTS_UPLOAD_INBOUND) |
||||
public MessageChannel eventsUploadInbound() { |
||||
return new DirectChannel(); |
||||
} |
||||
|
||||
@Bean(name = ChannelName.EVENTS_COLLECTION_INBOUND) |
||||
public MessageChannel eventsCollectionInbound() { |
||||
return new DirectChannel(); |
||||
} |
||||
|
||||
@Bean(name = ChannelName.EVENTS_CONTROL_INBOUND) |
||||
public MessageChannel eventsControlInbound() { |
||||
return new DirectChannel(); |
||||
} |
||||
|
||||
@Bean(name = ChannelName.EVENTS_SEND_INBOUND) |
||||
public MessageChannel eventsSendInbound() { |
||||
return new DirectChannel(); |
||||
} |
||||
|
||||
} |
||||
@ -1,51 +0,0 @@
|
||||
package com.mh.user.config.mqtt; |
||||
|
||||
import com.mh.user.constants.ChannelName; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.integration.annotation.IntegrationComponentScan; |
||||
import org.springframework.integration.annotation.ServiceActivator; |
||||
import org.springframework.integration.mqtt.core.MqttPahoClientFactory; |
||||
import org.springframework.integration.mqtt.outbound.MqttPahoMessageHandler; |
||||
import org.springframework.integration.mqtt.support.DefaultPahoMessageConverter; |
||||
import org.springframework.messaging.MessageHandler; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project springboot-mqtt-demo |
||||
* @description 入站配置 |
||||
* @date 2024-10-29 16:22:10 |
||||
*/ |
||||
@Slf4j |
||||
@Configuration |
||||
@IntegrationComponentScan |
||||
public class MqttOutboundConfig { |
||||
|
||||
@Autowired |
||||
private MqttPahoClientFactory mqttClientFactory; |
||||
|
||||
/** |
||||
* 默认声明一个出站处理器,用于处理无效的消息 |
||||
* @return |
||||
*/ |
||||
@Bean |
||||
@ServiceActivator(inputChannel = ChannelName.OUTBOUND) |
||||
public MessageHandler mqttOutbound() { |
||||
MqttPahoMessageHandler messageHandler = new MqttPahoMessageHandler( |
||||
MqttConfig.getBasicMqttClientOptions().getClientId() + "_producer_" + System.currentTimeMillis(), |
||||
mqttClientFactory); |
||||
DefaultPahoMessageConverter converter = new DefaultPahoMessageConverter(); |
||||
// use byte types uniformly
|
||||
converter.setPayloadAsBytes(true); |
||||
|
||||
messageHandler.setAsync(true); |
||||
messageHandler.setDefaultQos(0); |
||||
messageHandler.setConverter(converter); |
||||
return messageHandler; |
||||
} |
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,71 @@
|
||||
package com.mh.user.controller; |
||||
|
||||
import com.mh.common.http.HttpResult; |
||||
import com.mh.common.utils.StringUtils; |
||||
import com.mh.user.annotation.SysLogger; |
||||
import com.mh.user.entity.CollectionParamsManageEntity; |
||||
import com.mh.user.entity.DeviceInstallEntity; |
||||
import com.mh.user.model.DeviceModel; |
||||
import com.mh.user.service.*; |
||||
import org.apache.poi.hssf.usermodel.HSSFCell; |
||||
import org.apache.poi.hssf.usermodel.HSSFSheet; |
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
||||
import org.apache.poi.ss.usermodel.CellType; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.web.bind.annotation.*; |
||||
import org.springframework.web.multipart.MultipartFile; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.io.IOException; |
||||
import java.io.InputStream; |
||||
import java.text.SimpleDateFormat; |
||||
import java.util.*; |
||||
|
||||
/** |
||||
* 基表参数信息管理 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("cpm") |
||||
public class CollectionParamsManageController { |
||||
|
||||
@Autowired |
||||
private CollectionParamsManageService collectionParamsManageService; |
||||
|
||||
//保存
|
||||
@SysLogger(title="基表采集信息",optDesc = "保存基表采集参数信息") |
||||
@PostMapping(value="/save") |
||||
public HttpResult saveDevice(@RequestBody CollectionParamsManageEntity collectionParamsManageEntity) { |
||||
return HttpResult.ok(collectionParamsManageService.insertCPM(collectionParamsManageEntity)); |
||||
} |
||||
|
||||
//修改
|
||||
@SysLogger(title="基表采集参数信息",optDesc = "修改基表采集参数信息") |
||||
@PostMapping(value="/update") |
||||
public HttpResult updateDevice(@RequestBody CollectionParamsManageEntity collectionParamsManageEntity) { |
||||
return HttpResult.ok(collectionParamsManageService.updateCPM(collectionParamsManageEntity)); |
||||
} |
||||
|
||||
// 删除多
|
||||
@PostMapping(value="/deletes") |
||||
public HttpResult deleteDevices(@RequestBody String[] ids) { |
||||
return HttpResult.ok(collectionParamsManageService.deleteByIds(ids)); |
||||
} |
||||
|
||||
// 按条件查询
|
||||
@SysLogger(title="基表采集信息",optDesc = "按条件查询基表采集参数信息") |
||||
@PostMapping(value="/query") |
||||
public HttpResult queryDevice( @RequestParam(value = "deviceInstallId", required = false)String deviceInstallId, |
||||
@RequestParam(value = "buildingId", required = false)String buildingId, |
||||
@RequestParam(value = "otherName", required = false)String otherName, |
||||
@RequestParam(value = "page", required=true)Integer page, |
||||
@RequestParam(value = "limit", required=true)Integer limit) { |
||||
try{ |
||||
int count=collectionParamsManageService.selectCPMListCount(buildingId, deviceInstallId,otherName, page, limit); |
||||
List<CollectionParamsManageEntity> records=collectionParamsManageService.selectCPMList(buildingId, deviceInstallId,otherName, page, limit); |
||||
return HttpResult.ok(count,records); |
||||
}catch (Exception e){ |
||||
return HttpResult.error(e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,108 @@
|
||||
package com.mh.user.entity; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
import org.springframework.format.annotation.DateTimeFormat; |
||||
|
||||
import java.io.Serializable; |
||||
import java.math.BigDecimal; |
||||
import java.time.LocalDateTime; |
||||
import java.util.Date; |
||||
import java.util.StringJoiner; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project CHWS |
||||
* @description 采集参数实体类 |
||||
* @date 2025-12-10 10:53:33 |
||||
*/ |
||||
@Getter |
||||
@Setter |
||||
public class CollectionParamsManageEntity implements Serializable { |
||||
|
||||
static final long serialVersionUID = 42L; |
||||
|
||||
private Long id; |
||||
|
||||
/** 当前时间 */ |
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
private Date createTime; |
||||
|
||||
/** 当前时间 */ |
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
private Date updateTime; |
||||
private Long buildingId; |
||||
/** 设备id */ |
||||
private Long deviceInstallId; |
||||
/** 寄存器地址 */ |
||||
private String registerAddr; |
||||
/** 功能码 */ |
||||
private String funcCode; |
||||
/** 倍率 */ |
||||
private Integer mtRatio; |
||||
/** 初始值 */ |
||||
private BigDecimal mtInitValue; |
||||
/** 小数点 */ |
||||
private Integer digits; |
||||
/** 数据类型 */ |
||||
private Integer dataType; |
||||
/** 当前值 */ |
||||
private BigDecimal curValue; |
||||
/** 当前时间 */ |
||||
/** 当前时间 */ |
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
private Date curTime; |
||||
/** 是否是总表 (0: 是, 1: 否) */ |
||||
private Integer mtIsSum; |
||||
/** 单位 */ |
||||
private String unit; |
||||
/** 排序 */ |
||||
private Long orderNum; |
||||
/** 备注 */ |
||||
private String remark; |
||||
/** 读取的寄存器大小 */ |
||||
private Integer registerSize; |
||||
/** 是否使用 */ |
||||
private Integer isUse; |
||||
/** 别名:mqtt上传名,唯一值 */ |
||||
private String otherName; |
||||
/** 40,累计值,140瞬时值 */ |
||||
private Integer grade; |
||||
/** 参数id */ |
||||
private Integer paramTypeId; |
||||
/** 遥测、遥信数据类型 */ |
||||
private Integer collectionType; |
||||
/** 上报质量 */ |
||||
private String quality; |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return new StringJoiner(", ", CollectionParamsManageEntity.class.getSimpleName() + "[", "]") |
||||
.add("deviceInstallId=" + deviceInstallId) |
||||
.add("registerAddr='" + registerAddr + "'") |
||||
.add("funcCode='" + funcCode + "'") |
||||
.add("mtRatio=" + mtRatio) |
||||
.add("mtInitValue=" + mtInitValue) |
||||
.add("digits=" + digits) |
||||
.add("dataType=" + dataType) |
||||
.add("curValue=" + curValue) |
||||
.add("curTime=" + curTime) |
||||
.add("mtIsSum=" + mtIsSum) |
||||
.add("unit='" + unit + "'") |
||||
.add("orderNum=" + orderNum) |
||||
.add("remark='" + remark + "'") |
||||
.add("registerSize=" + registerSize) |
||||
.add("isUse=" + isUse) |
||||
.add("otherName='" + otherName + "'") |
||||
.add("grade=" + grade) |
||||
.add("paramTypeId=" + paramTypeId) |
||||
.add("collectionType=" + collectionType) |
||||
.add("quality='" + quality + "'") |
||||
.toString(); |
||||
} |
||||
} |
||||
@ -0,0 +1,128 @@
|
||||
package com.mh.user.mapper; |
||||
|
||||
import com.mh.user.entity.CollectionParamsManageEntity; |
||||
import com.mh.user.entity.DeviceInstallEntity; |
||||
import org.apache.ibatis.annotations.*; |
||||
import tk.mybatis.mapper.common.BaseMapper; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project CHWS |
||||
* @description 采集参数设备mapper类 |
||||
* @date 2025-12-10 11:31:42 |
||||
*/ |
||||
@Mapper |
||||
public interface CollectionParamsManageMapper extends BaseMapper<CollectionParamsManageEntity> { |
||||
|
||||
@Select("<script>" + |
||||
"SELECT * FROM (" + |
||||
"SELECT cpm.*, ROW_NUMBER() OVER (ORDER BY cpm.device_install_id) AS row_num " + |
||||
"FROM collection_params_manage cpm join device_install di on cpm.device_install_id = di.id where 1=1" + |
||||
"<if test='deviceInstallId != null and deviceInstallId != \"\"'>" + |
||||
"AND cpm.device_install_id = #{deviceInstallId} " + |
||||
"</if>" + |
||||
"<if test='buildingId != null and buildingId != \"\"'>" + |
||||
"AND di.building_id = #{buildingId} " + |
||||
"</if>" + |
||||
"<if test='otherName != null and otherName != \"\"'>" + |
||||
"AND cpm.other_name LIKE CONCAT('%', #{otherName}, '%') " + |
||||
"</if>" + |
||||
") AS t WHERE t.row_num BETWEEN (#{pageNum}-1)*#{pageSize} AND #{pageNum}*#{pageSize}" + |
||||
"</script>") |
||||
@Results({ |
||||
@Result(column = "id", property = "id"), |
||||
@Result(column = "create_time", property = "createTime"), |
||||
@Result(column = "update_time", property = "updateTime"), |
||||
@Result(column = "device_install_id", property = "deviceInstallId"), |
||||
@Result(column = "register_addr", property = "registerAddr"), |
||||
@Result(column = "func_code", property = "funcCode"), |
||||
@Result(column = "mt_ratio", property = "mtRatio"), |
||||
@Result(column = "mt_init_value", property = "mtInitValue"), |
||||
@Result(column = "digits", property = "digits"), |
||||
@Result(column = "data_type", property = "dataType"), |
||||
@Result(column = "cur_value", property = "curValue"), |
||||
@Result(column = "cur_time", property = "curTime"), |
||||
@Result(column = "mt_is_sum", property = "mtIsSum"), |
||||
@Result(column = "unit", property = "unit"), |
||||
@Result(column = "order_num", property = "orderNum"), |
||||
@Result(column = "remark", property = "remark"), |
||||
@Result(column = "register_size", property = "registerSize"), |
||||
@Result(column = "is_use", property = "isUse"), |
||||
@Result(column = "other_name", property = "otherName"), |
||||
@Result(column = "grade", property = "grade"), |
||||
@Result(column = "param_type_id", property = "paramTypeId"), |
||||
@Result(column = "collection_type", property = "collectionType"), |
||||
@Result(column = "quality", property = "quality") |
||||
}) |
||||
List<CollectionParamsManageEntity> selectCPMList(String buildingId,String deviceInstallId, String otherName, Integer pageNum, Integer pageSize); |
||||
|
||||
@Select("<script>" + |
||||
"SELECT count(1) " + |
||||
"FROM collection_params_manage cpm join device_install di on cpm.device_install_id = di.id where 1=1" + |
||||
"<if test='deviceInstallId != null and deviceInstallId != \"\"'>" + |
||||
"AND cpm.device_install_id = #{deviceInstallId} " + |
||||
"</if>" + |
||||
"<if test='buildingId != null and buildingId != \"\"'>" + |
||||
"AND di.building_id = #{buildingId} " + |
||||
"</if>" + |
||||
"<if test='otherName != null and otherName != \"\"'>" + |
||||
"AND cpm.other_name LIKE CONCAT('%', #{otherName}, '%') " + |
||||
"</if>" + |
||||
"</script>") |
||||
int selectCPMListCount(String buildingId, String deviceInstallId, String otherName, Integer pageNum, Integer pageSize); |
||||
|
||||
@Select("select count(1) from collection_params_manage where other_name = #{otherName} ") |
||||
int selectCountByOtherName(String otherName); |
||||
|
||||
@Update("update collection_params_manage set cur_value = #{value}, cur_time = #{time} where other_name = #{name}") |
||||
void updateCPMByOtherName(String name, float value, String time); |
||||
|
||||
@Select("select top 1 * from collection_params_manage where other_name = #{name}") |
||||
CollectionParamsManageEntity selectDeviceInstallByOtherName(String name); |
||||
|
||||
@Insert("insert into collection_params_manage(" + |
||||
"device_install_id, register_addr, func_code, mt_ratio, mt_init_value, digits, data_type, " + |
||||
"mt_is_sum, unit, order_num, remark, register_size, is_use, " + |
||||
"other_name, grade, param_type_id, collection_type, quality, create_time, building_id, cur_value, cur_time) " + |
||||
"values(#{deviceInstallId}, #{registerAddr}, #{funcCode}, #{mtRatio}, #{mtInitValue}, " + |
||||
"#{digits}, #{dataType}, #{mtIsSum}, #{unit}, #{orderNum}, " + |
||||
"#{remark}, #{registerSize}, #{isUse}, #{otherName}, #{grade}, #{paramTypeId}, " + |
||||
"#{collectionType}, #{quality}, getdate(), #{buildingId}, #{curValue}, #{curTime})") |
||||
void insertCPM(CollectionParamsManageEntity cpmEntity); |
||||
|
||||
@Update("<script>" + |
||||
"update collection_params_manage " + |
||||
"<set>" + |
||||
"<if test='deviceInstallId != null'>device_install_id = #{deviceInstallId},</if>" + |
||||
"<if test='registerAddr != null'>register_addr = #{registerAddr},</if>" + |
||||
"<if test='funcCode != null'>func_code = #{funcCode},</if>" + |
||||
"<if test='mtRatio != null'>mt_ratio = #{mtRatio},</if>" + |
||||
"<if test='mtInitValue != null'>mt_init_value = #{mtInitValue},</if>" + |
||||
"<if test='digits != null'>digits = #{digits},</if>" + |
||||
"<if test='dataType != null'>data_type = #{dataType},</if>" + |
||||
"<if test='curValue != null'>cur_value = #{curValue},</if>" + |
||||
"<if test='curTime != null'>cur_time = #{curTime},</if>" + |
||||
"<if test='mtIsSum != null'>mt_is_sum = #{mtIsSum},</if>" + |
||||
"<if test='unit != null'>unit = #{unit},</if>" + |
||||
"<if test='orderNum != null'>order_num = #{orderNum},</if>" + |
||||
"<if test='remark != null'>remark = #{remark},</if>" + |
||||
"<if test='registerSize != null'>register_size = #{registerSize},</if>" + |
||||
"<if test='isUse != null'>is_use = #{isUse},</if>" + |
||||
"<if test='otherName != null'>other_name = #{otherName},</if>" + |
||||
"<if test='grade != null'>grade = #{grade},</if>" + |
||||
"<if test='paramTypeId != null'>param_type_id = #{paramTypeId},</if>" + |
||||
"<if test='collectionType != null'>collection_type = #{collectionType},</if>" + |
||||
"<if test='quality != null'>quality = #{quality},</if>" + |
||||
"<if test='buildingId != null'>building_id = #{buildingId},</if>" + |
||||
" update_time = getdate() " + |
||||
"</set>" + |
||||
"where id = #{id}" + |
||||
"</script>") |
||||
void updateById(CollectionParamsManageEntity cpmEntity); |
||||
|
||||
@Delete("delete from collection_params_manage where id = #{msId}") |
||||
void deleteById(String msId); |
||||
} |
||||
@ -0,0 +1,32 @@
|
||||
package com.mh.user.service; |
||||
|
||||
import com.mh.user.entity.CollectionParamsManageEntity; |
||||
import com.mh.user.entity.DeviceInstallEntity; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description 采集参数管理 |
||||
* @date 2025-02-14 13:58:37 |
||||
*/ |
||||
public interface CollectionParamsManageService { |
||||
|
||||
List<CollectionParamsManageEntity> selectCPMList(String buildingId, String deviceInstallId, String otherName, Integer pageNum, Integer pageSize); |
||||
|
||||
int selectCPMListCount(String buildingId, String deviceInstallId, String otherName, Integer pageNum, Integer pageSize); |
||||
|
||||
CollectionParamsManageEntity selectById(String msId); |
||||
|
||||
String insertCPM(CollectionParamsManageEntity mqttSubscription); |
||||
|
||||
String updateCPM(CollectionParamsManageEntity mqttSubscription); |
||||
|
||||
int deleteByIds(String[] msIds); |
||||
|
||||
void updateCPMByOtherName(String name, float value, String time); |
||||
|
||||
CollectionParamsManageEntity selectDeviceInstallByOtherName(String name); |
||||
} |
||||
@ -0,0 +1,84 @@
|
||||
package com.mh.user.service.impl; |
||||
|
||||
import com.mh.user.constants.Constant; |
||||
import com.mh.user.entity.CollectionParamsManageEntity; |
||||
import com.mh.user.entity.DeviceInstallEntity; |
||||
import com.mh.user.mapper.CollectionParamsManageMapper; |
||||
import com.mh.user.service.CollectionParamsManageService; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project CHWS |
||||
* @description 采集参数设备实现类 |
||||
* @date 2025-12-10 11:30:54 |
||||
*/ |
||||
@Service |
||||
public class CollectionParamsManageServiceImpl implements CollectionParamsManageService { |
||||
|
||||
private final CollectionParamsManageMapper collectionParamsManageMapper; |
||||
|
||||
public CollectionParamsManageServiceImpl(CollectionParamsManageMapper collectionParamsManageMapper) { |
||||
this.collectionParamsManageMapper = collectionParamsManageMapper; |
||||
} |
||||
|
||||
@Override |
||||
public CollectionParamsManageEntity selectDeviceInstallByOtherName(String name) { |
||||
return collectionParamsManageMapper.selectDeviceInstallByOtherName(name); |
||||
} |
||||
|
||||
@Override |
||||
public void updateCPMByOtherName(String name, float value, String time) { |
||||
collectionParamsManageMapper.updateCPMByOtherName(name, value, time); |
||||
} |
||||
|
||||
@Override |
||||
public List<CollectionParamsManageEntity> selectCPMList(String buildingId, String deviceInstallId, String otherName, Integer pageNum, Integer pageSize) { |
||||
return collectionParamsManageMapper.selectCPMList(buildingId, deviceInstallId, otherName, pageNum, pageSize); |
||||
} |
||||
|
||||
@Override |
||||
public int selectCPMListCount(String buildingId, String deviceInstallId, String otherName, Integer pageNum, Integer pageSize) { |
||||
return collectionParamsManageMapper.selectCPMListCount(buildingId, deviceInstallId, otherName, pageNum, pageSize); |
||||
} |
||||
|
||||
@Override |
||||
public CollectionParamsManageEntity selectById(String msId) { |
||||
return collectionParamsManageMapper.selectByPrimaryKey(msId); |
||||
} |
||||
|
||||
@Override |
||||
public String insertCPM(CollectionParamsManageEntity cpmEntity) { |
||||
// 判断是否存在otherName
|
||||
if (collectionParamsManageMapper.selectCountByOtherName(cpmEntity.getOtherName()) > 0) { |
||||
return "存在相同参数名称"; |
||||
} |
||||
collectionParamsManageMapper.insertCPM(cpmEntity); |
||||
return Constant.SUCCESS; |
||||
} |
||||
|
||||
@Override |
||||
public String updateCPM(CollectionParamsManageEntity cpmEntity) { |
||||
// 判断是否存在otherName
|
||||
// if (collectionParamsManageMapper.selectCountByOtherName(cpmEntity.getOtherName()) > 0) {
|
||||
// return "存在相同参数名称";
|
||||
// }
|
||||
collectionParamsManageMapper.updateById(cpmEntity); |
||||
return Constant.SUCCESS; |
||||
} |
||||
|
||||
@Override |
||||
public int deleteByIds(String[] msIds) { |
||||
if (msIds != null && msIds.length > 0) { |
||||
for (String msId : msIds) { |
||||
collectionParamsManageMapper.deleteById(msId); |
||||
} |
||||
return msIds.length; |
||||
} |
||||
return 0; |
||||
} |
||||
} |
||||
@ -1,3 +1,6 @@
|
||||
spring: |
||||
profiles: |
||||
active: dev |
||||
active: prod |
||||
mvc: |
||||
pathmatch: |
||||
matching-strategy: ant_path_matcher |
||||
|
||||
Loading…
Reference in new issue