mqtt 处理站点运营消息通知
This commit is contained in:
parent
d7c5bae22f
commit
8d45177d10
@ -0,0 +1,25 @@
|
||||
package com.evotech.hd.common.core.Dto.request.template;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 类
|
||||
*
|
||||
* @ClassName:AlarmTemplateDto
|
||||
* @date: 2025年05月05日 16:29
|
||||
* @author: andy.shi
|
||||
* @contact: 17330188597
|
||||
* @remark: 开发人员联系方式 1042025947@qq.com/微信同步
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class AlarmTemplateDto {
|
||||
|
||||
List<String> wuid;
|
||||
|
||||
String stationName;
|
||||
|
||||
String alarmMsg;
|
||||
}
|
||||
@ -4,6 +4,9 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.evotech.hd.common.core.constant.HDConstant;
|
||||
import com.evotech.hd.common.core.entity.resource.auth.AuthUser;
|
||||
import com.evotech.hd.common.core.permission.DataScope;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zrb
|
||||
@ -12,4 +15,6 @@ import com.evotech.hd.common.core.permission.DataScope;
|
||||
@DataScope(permissionObject = HDConstant.OPERATOR_ROLE_CODE, permissionScopeName = "creater", permissionScopeRedisKey = HDConstant.PermissionConstant.PERMISSION_AUTH_USER_UID)
|
||||
public interface AuthUserDao extends BaseMapper<AuthUser> {
|
||||
|
||||
List<String> findWuIdByStationCodeAndProxyCode(@Param("stationCode") String stationCode, @Param("proxyCode") String proxyCode);
|
||||
|
||||
}
|
||||
|
||||
@ -131,4 +131,7 @@ public class BatteryStation extends BaseEntity implements Serializable {
|
||||
|
||||
@Schema(description = "场地Code--DH")
|
||||
private String orgCode;
|
||||
|
||||
@Schema(description = "告警状态", hidden = true)
|
||||
private Boolean alarm;
|
||||
}
|
||||
|
||||
@ -2,6 +2,8 @@ package com.evotech.hd.common.config;
|
||||
|
||||
import com.mongodb.ConnectionString;
|
||||
import lombok.Data;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.mongodb.MongoDatabaseFactory;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory;
|
||||
@ -23,12 +25,25 @@ import java.util.List;
|
||||
* @remark: 开发人员联系方式 1042025947@qq.com/微信同步
|
||||
*/
|
||||
@Data
|
||||
@Configuration
|
||||
public abstract class AbstractMongoDbConfig{
|
||||
|
||||
// MongoDB Properties
|
||||
private String uri, userName, password, host, dataBase, authenticationDataBase;
|
||||
@Value("${yt.base_properties.uri:}")
|
||||
private String uri;
|
||||
@Value("${yt.base_properties.user_name:''}")
|
||||
private String userName;
|
||||
@Value("${yt.base_properties.password:''}")
|
||||
private String password;
|
||||
@Value("${yt.base_properties.host:''}")
|
||||
private String host;
|
||||
@Value("${yt.base_properties.authentication-database:''}")
|
||||
private String authenticationDataBase;
|
||||
private String dataBase;
|
||||
@Value("${yt.base_properties.port:''}")
|
||||
private Integer port;
|
||||
|
||||
|
||||
public MongoDatabaseFactory mongoDbFactory(){
|
||||
//String connectionString = "mongodb://" + userName + ":" + password+ "@"+ host+":"+port+"/" + dataBase+"?authSource="+authenticationDataBase;
|
||||
return new SimpleMongoClientDatabaseFactory(getConnectionString());
|
||||
|
||||
@ -17,7 +17,7 @@ import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
*/
|
||||
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "yt.battery-box", ignoreUnknownFields = true)
|
||||
@ConfigurationProperties(prefix = "yt.battery-box", ignoreInvalidFields = true)
|
||||
public class BatteryBoxProperties extends AbstractMongoDbConfig {
|
||||
|
||||
@Bean("mongoTemplateBatteryBox")
|
||||
|
||||
@ -17,8 +17,9 @@ import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
*/
|
||||
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "yt.battery-info", ignoreUnknownFields = true)
|
||||
@ConfigurationProperties(prefix = "yt.battery-info", ignoreInvalidFields = true)
|
||||
public class BatteryInfoProperties extends AbstractMongoDbConfig {
|
||||
|
||||
@Primary
|
||||
@Bean("mongoTemplateBatteryInfo")
|
||||
@Override
|
||||
|
||||
@ -0,0 +1,27 @@
|
||||
package com.evotech.hd.common.config;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
|
||||
/**
|
||||
* 站相关推送信息记录类
|
||||
*
|
||||
* @ClassName:BatteryInfoProperties
|
||||
* @date: 2025年04月29日 16:32
|
||||
* @author: andy.shi
|
||||
* @contact: 17330188597
|
||||
* @remark: 开发人员联系方式 1042025947@qq.com/微信同步
|
||||
*/
|
||||
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "yt.station-info", ignoreInvalidFields = true)
|
||||
public class StationInfoProperties extends AbstractMongoDbConfig {
|
||||
@Bean("mongoTemplateStationInfo")
|
||||
@Override
|
||||
public MongoTemplate getMongoTemplate() throws Exception {
|
||||
return new MongoTemplate(mongoDbFactory());
|
||||
}
|
||||
|
||||
}
|
||||
@ -14,6 +14,8 @@ public class MongoConstant {
|
||||
public static final String BATTERY_DATA_BASE="battery_info";
|
||||
//电池箱实时信息数据库
|
||||
public static final String BATTERY_BOX_DATA_BASE="battery_box";
|
||||
//电池箱实时信息数据库
|
||||
public static final String STATION_INFO_BASE="station_info";
|
||||
|
||||
public static final String SEPARATION = "_";
|
||||
/***
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
package com.evotech.hd.common.documnet;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
/**
|
||||
* 类
|
||||
*
|
||||
* @ClassName:BaseDocumentEntity
|
||||
* @date: 2025年05月05日 13:38
|
||||
* @author: andy.shi
|
||||
* @contact: 17330188597
|
||||
* @remark: 开发人员联系方式 1042025947@qq.com/微信同步
|
||||
*/
|
||||
@Data
|
||||
@Document
|
||||
public class BaseDocumentEntity {
|
||||
|
||||
/***
|
||||
* 时间戳做id
|
||||
*/
|
||||
@Id
|
||||
String id;
|
||||
|
||||
String stationCode;
|
||||
|
||||
String value;
|
||||
}
|
||||
@ -1,7 +1,6 @@
|
||||
package com.evotech.hd.common.documnet;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
/**
|
||||
@ -14,22 +13,12 @@ import org.springframework.data.mongodb.core.mapping.Document;
|
||||
*/
|
||||
@Data
|
||||
@Document
|
||||
public class BatData {
|
||||
|
||||
/***
|
||||
* 时间戳做id
|
||||
*/
|
||||
@Id
|
||||
String id;
|
||||
|
||||
String stationCode;
|
||||
public class BatData extends BaseDocumentEntity{
|
||||
|
||||
String batCode;
|
||||
|
||||
String cabinetNo;
|
||||
|
||||
String value;
|
||||
|
||||
/***
|
||||
* value 内容参考
|
||||
* 仓位序号 cabinetNo int 仓位序号
|
||||
@ -64,9 +53,7 @@ public class BatData {
|
||||
public BatData() {
|
||||
}
|
||||
|
||||
public BatData(String id, String stationCode, String batCode, String cabinetNo, String value) {
|
||||
this.id = id;
|
||||
this.stationCode = stationCode;
|
||||
public BatData(String batCode, String cabinetNo, String value) {
|
||||
this.batCode = batCode;
|
||||
this.cabinetNo = cabinetNo;
|
||||
this.value = value;
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package com.evotech.hd.common.documnet;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
/**
|
||||
@ -15,21 +14,12 @@ import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Data
|
||||
@Document
|
||||
public class ChargingData {
|
||||
/***
|
||||
* 时间戳做id
|
||||
*/
|
||||
@Id
|
||||
String id;
|
||||
|
||||
String stationCode;
|
||||
public class ChargingData extends BaseDocumentEntity{
|
||||
|
||||
String batCode;
|
||||
|
||||
String chgSn;
|
||||
|
||||
String value;
|
||||
|
||||
/***
|
||||
* value 内容参考
|
||||
* 充电机编号 chgID string 充电机编号,采用 16 位数字编码
|
||||
@ -168,9 +158,7 @@ public class ChargingData {
|
||||
public ChargingData() {
|
||||
}
|
||||
|
||||
public ChargingData(String id,String stationCode, String batCode, String chgSn, String value) {
|
||||
this.id = id;
|
||||
this.stationCode = stationCode;
|
||||
public ChargingData(String batCode, String chgSn, String value) {
|
||||
this.batCode = batCode;
|
||||
this.chgSn = chgSn;
|
||||
this.value = value;
|
||||
|
||||
@ -0,0 +1,36 @@
|
||||
package com.evotech.hd.common.documnet;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
/**
|
||||
* 站级状态信息类
|
||||
*
|
||||
* @ClassName:StationState
|
||||
* @date: 2025年05月05日 13:28
|
||||
* @author: andy.shi
|
||||
* @contact: 17330188597
|
||||
* @remark: 开发人员联系方式 1042025947@qq.com/微信同步
|
||||
*/
|
||||
@Data
|
||||
@Document
|
||||
public class StationState extends BaseDocumentEntity{
|
||||
|
||||
|
||||
/***
|
||||
* value 信息参考
|
||||
* 1 运行状态 state int 1-运营;2-调试;3-检修; 是 是
|
||||
* 2 烟感告警信号 smoke string 0-未知;1-正常;2-告警,多个烟感时, 以逗号分隔,如:2,1,2,0,1,0,1,2,一 般和架载机个数相同 是 是
|
||||
* 3 消防告警信号 fire int 0-未知;1-正常;2-告警 是 是
|
||||
* 4 温度 temp int 换电站室内温度,°C,未接入时传null 是 否
|
||||
* 5 湿度 humid int 换电站室内湿度,%,未接入时传 null 是 否
|
||||
* 6 电表读数 totalElect float 单位:kWh,未接入时传 null 是 否
|
||||
*/
|
||||
|
||||
public StationState() {
|
||||
}
|
||||
|
||||
public StationState(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
@ -39,7 +39,6 @@ public class MongoDBService {
|
||||
private void init(){
|
||||
if(!CollectionUtils.isEmpty(mongoTemplates)){
|
||||
for (MongoTemplate mongoTemplate: mongoTemplates){
|
||||
System.out.println(mongoTemplate.getDb().getName());
|
||||
mongoTemplateMap.put(mongoTemplate.getDb().getName(),mongoTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,7 +14,7 @@ import com.evotech.hd.cloud.device.dh.DHRequestUtil;
|
||||
import com.evotech.hd.cloud.mqtt.message.MessageTopic;
|
||||
import com.evotech.hd.cloud.mqtt.message.MqttMessageHeader;
|
||||
import com.evotech.hd.cloud.mqtt.message.processor.MqttRequestExchangeProcessor;
|
||||
import com.evotech.hd.cloud.mqtt.message.processor.impl.state.MqttStateChargingDataRequestExchangeProcessor;
|
||||
import com.evotech.hd.cloud.mqtt.message.processor.impl.state.MqttStateChargingDataExchangeProcessor;
|
||||
import com.evotech.hd.cloud.utils.components.SwapOrderBasicFeeComponent;
|
||||
import com.evotech.hd.common.core.entity.Result;
|
||||
import com.evotech.hd.common.core.entity.cloud.BatteryStation;
|
||||
@ -50,7 +50,7 @@ public class TestController {
|
||||
@Resource
|
||||
private SwapOrderBasicFeeComponent orderBasicFeeComponent;
|
||||
@Resource
|
||||
MqttStateChargingDataRequestExchangeProcessor mqttStateChargingDataRequestExchangeProcessor;
|
||||
MqttStateChargingDataExchangeProcessor mqttStateChargingDataRequestExchangeProcessor;
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
// @Resource
|
||||
|
||||
@ -12,14 +12,13 @@ import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Component
|
||||
//@Component
|
||||
@Order(value = 20)
|
||||
@Slf4j
|
||||
public class MqttConnectInit implements ApplicationRunner {
|
||||
|
||||
@ -14,6 +14,7 @@ public enum StateFunctionTypesEnum {
|
||||
FUN_TEST("test", "", "没用的占位"),
|
||||
FUN_CHARGING_DATA("chargingData", "", "充电过程实时信息"),
|
||||
FUN_BAT_DATA("batData", "", "电池实时信息"),
|
||||
FUN_STATION_STATE("stationState", "", "站级状态信息"),
|
||||
;
|
||||
|
||||
|
||||
|
||||
@ -11,7 +11,9 @@ import com.evotech.hd.cloud.mqtt.message.MessageTopic;
|
||||
import com.evotech.hd.cloud.mqtt.message.MqttMessageHeader;
|
||||
import com.evotech.hd.cloud.mqtt.message.dto.newer.req.MqttResponse;
|
||||
import com.evotech.hd.cloud.mqtt.message.handle.MessageUtilService;
|
||||
import com.evotech.hd.common.documnet.BaseDocumentEntity;
|
||||
import com.evotech.hd.common.permission.util.SpringUtil;
|
||||
import com.evotech.hd.common.service.MongoDBService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -45,4 +47,18 @@ public interface MqttRequestExchangeProcessor {
|
||||
logger.info("\r\n=====>>>站端取消订单--MQTT发送到消息主题:{},头部信息:{},message:{}", topic,header, JSONUtil.parseObj(response, new JSONConfig().setDateFormat(DatePattern.NORM_DATETIME_PATTERN)));
|
||||
messageUtilService.publishAESMessage(topic, header, JSONUtil.parseObj(response, new JSONConfig().setDateFormat(DatePattern.NORM_DATETIME_PATTERN)));
|
||||
}
|
||||
|
||||
/***
|
||||
* 存储到mongoDB中
|
||||
* @param database
|
||||
* @param collectionName
|
||||
* @param document
|
||||
* @param <T>
|
||||
*/
|
||||
default <T extends BaseDocumentEntity> void saveMongoDB(MessageTopic topic, String database, String collectionName, T document){
|
||||
MongoDBService mongoDBService = SpringUtil.getBean(MongoDBService.class);
|
||||
document.setId(String.valueOf(System.currentTimeMillis()));
|
||||
document.setStationCode(topic.getStationCode());
|
||||
mongoDBService.save(database, collectionName, document);
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ import org.springframework.util.Assert;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class MqttRequestPushCarCreateMakeAppointmentExchangeProcessorImpl implements MqttRequestExchangeProcessor {
|
||||
public class MqttRequestPushCarInfoExchangeProcessorImpl implements MqttRequestExchangeProcessor {
|
||||
|
||||
@Resource
|
||||
VehicleService vehicleService;
|
||||
@ -41,9 +41,9 @@ public class MqttRequestPushCarCreateMakeAppointmentExchangeProcessorImpl implem
|
||||
|
||||
@Override
|
||||
public void exchange(MessageTopic topic, MqttMessageHeader header, JSONObject dataBody) {
|
||||
log.info("MqttRequestPushCarCreateMakeAppointmentExchangeProcessorImpl-->>>>> 请求参数{}", JSONUtil.toJsonStr(dataBody));
|
||||
String plateNum = dataBody.getStr("licensePlateNumber");
|
||||
Assert.hasText(plateNum, "licensePlateNumber is null");
|
||||
log.info("MqttRequestPushCarInfoExchangeProcessorImpl-->>>>> 请求参数{}", JSONUtil.toJsonStr(dataBody));
|
||||
String plateNum = dataBody.getStr("plateNum");
|
||||
Assert.hasText(plateNum, "plateNum is null");
|
||||
MqttResponse response = null;
|
||||
if(StringUtils.isNotEmpty(plateNum)){
|
||||
//如果不存在车辆信息
|
||||
@ -56,7 +56,7 @@ public class MqttRequestPushCarCreateMakeAppointmentExchangeProcessorImpl implem
|
||||
//如果response == null 则证明 车辆创建成功了
|
||||
if(response == null){
|
||||
//创建预约订单
|
||||
if (orderSwapBatteryService.addPreByPlanNum(plateNum, topic.getStationCode())){
|
||||
if (orderSwapBatteryService.addPreByPlateNum(plateNum, topic.getStationCode())){
|
||||
//返回状态信息
|
||||
response = new MqttResponse().success("预约单初始化完成");
|
||||
}else{
|
||||
@ -37,15 +37,15 @@ public class MqttRequestStrategyExchangeProcessorImpl implements MqttRequestExch
|
||||
|
||||
@Override
|
||||
public void exchange(MessageTopic topic, MqttMessageHeader header, JSONObject dataBody) {
|
||||
log.info("StrategyMqttMessageRequestExchangeProcessorImpl-->>>>> 请求参数{}", JSONUtil.toJsonStr(dataBody));
|
||||
log.info("MqttRequestStrategyExchangeProcessorImpl-->>>>> 请求参数{}", JSONUtil.toJsonStr(dataBody));
|
||||
MqttResponse response = null;
|
||||
String stationCode = dataBody.getStr("stationCode");
|
||||
if(StringUtils.isEmpty(stationCode)){
|
||||
log.error("StrategyMqttMessageRequestExchangeProcessorImpl-->>>>> stationCode is null");
|
||||
log.error("MqttRequestStrategyExchangeProcessorImpl-->>>>> stationCode is null");
|
||||
response = new MqttResponse<>().paramsError("stationCode is null");
|
||||
}else{
|
||||
List<BatteryStationCdStrategy> list = batteryStationCdStrategyService.chargeStationFindList(stationCode);
|
||||
log.info("StrategyMqttMessageRequestExchangeProcessorImpl-->>>>> 查询到的策略信息{}", JSONUtil.toJsonStr(list));
|
||||
log.info("MqttRequestStrategyExchangeProcessorImpl-->>>>> 查询到的策略信息{}", JSONUtil.toJsonStr(list));
|
||||
response = new MqttResponse<List<BatteryStationCdStrategy>>().success(list);
|
||||
}
|
||||
sendAESMessage(topic, header, RequestFunctionTypesEnum.FUN_STRATEGY_INFO, response);
|
||||
|
||||
@ -8,14 +8,12 @@ import com.evotech.hd.cloud.mqtt.message.MqttMessageHeader;
|
||||
import com.evotech.hd.cloud.mqtt.message.processor.MqttRequestExchangeProcessor;
|
||||
import com.evotech.hd.common.constant.MongoConstant;
|
||||
import com.evotech.hd.common.documnet.BatData;
|
||||
import com.evotech.hd.common.service.MongoDBService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* 充电过程实时信息类
|
||||
* 电池箱实时信息类
|
||||
*
|
||||
* @ClassName:ChargingDataMqttStateRequestEx
|
||||
* @date: 2025年04月29日 13:26
|
||||
@ -25,9 +23,7 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class MqttStateBatDataDataRequestExchangeProcessor implements MqttRequestExchangeProcessor {
|
||||
@Resource
|
||||
MongoDBService mongoDBService;
|
||||
public class MqttStateBatDataDataExchangeProcessor implements MqttRequestExchangeProcessor {
|
||||
|
||||
@Override
|
||||
public boolean accept(String functionName) {
|
||||
@ -37,17 +33,20 @@ public class MqttStateBatDataDataRequestExchangeProcessor implements MqttRequest
|
||||
@Override
|
||||
public void exchange(MessageTopic topic, MqttMessageHeader header, JSONObject dataBody) {
|
||||
//记录充电过程信息
|
||||
log.info("MqttStateBatDataDataRequestExchangeProcessor-->>>>> 请求参数{}", JSONUtil.toJsonStr(dataBody));
|
||||
log.info("MqttStateBatDataDataExchangeProcessor-->>>>> 请求参数{}", JSONUtil.toJsonStr(dataBody));
|
||||
String batCode = dataBody.getStr("batCode");
|
||||
if (StringUtils.isEmpty(batCode)) {
|
||||
log.error("MqttStateBatDataDataRequestExchangeProcessor-->>>>> batCode is null");
|
||||
log.error("MqttStateBatDataDataExchangeProcessor-->>>>> batCode is null");
|
||||
return;
|
||||
}
|
||||
String cabinetNo = dataBody.getStr("cabinetNo");
|
||||
if (StringUtils.isEmpty(cabinetNo)) {
|
||||
log.error("MqttStateChargingDataRequestExchangeProcessor-->>>>> cabinetNo is null");
|
||||
log.error("MqttStateBatDataDataExchangeProcessor-->>>>> cabinetNo is null");
|
||||
return;
|
||||
}
|
||||
mongoDBService.save(MongoConstant.BATTERY_DATA_BASE, batCode, new BatData(String.valueOf(System.currentTimeMillis()), topic.getStationCode(), batCode,cabinetNo,dataBody.toString()));
|
||||
//String.valueOf(System.currentTimeMillis()), topic.getStationCode(),
|
||||
|
||||
saveMongoDB(topic, MongoConstant.BATTERY_BOX_DATA_BASE, batCode, new BatData(batCode,cabinetNo,dataBody.toString()));
|
||||
// mongoDBService.save(MongoConstant.BATTERY_BOX_DATA_BASE, batCode, new BatData(batCode,cabinetNo,dataBody.toString()));
|
||||
}
|
||||
}
|
||||
@ -8,8 +8,6 @@ import com.evotech.hd.cloud.mqtt.message.MqttMessageHeader;
|
||||
import com.evotech.hd.cloud.mqtt.message.processor.MqttRequestExchangeProcessor;
|
||||
import com.evotech.hd.common.constant.MongoConstant;
|
||||
import com.evotech.hd.common.documnet.ChargingData;
|
||||
import com.evotech.hd.common.service.MongoDBService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
@ -25,9 +23,7 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class MqttStateChargingDataRequestExchangeProcessor implements MqttRequestExchangeProcessor {
|
||||
@Resource
|
||||
MongoDBService mongoDBService;
|
||||
public class MqttStateChargingDataExchangeProcessor implements MqttRequestExchangeProcessor {
|
||||
|
||||
@Override
|
||||
public boolean accept(String functionName) {
|
||||
@ -37,17 +33,17 @@ public class MqttStateChargingDataRequestExchangeProcessor implements MqttReques
|
||||
@Override
|
||||
public void exchange(MessageTopic topic, MqttMessageHeader header, JSONObject dataBody) {
|
||||
//记录充电过程信息
|
||||
log.info("MqttStateChargingDataRequestExchangeProcessor-->>>>> 请求参数{}", JSONUtil.toJsonStr(dataBody));
|
||||
log.info("MqttStateChargingDataExchangeProcessor-->>>>> 请求参数{}", JSONUtil.toJsonStr(dataBody));
|
||||
String batCode = dataBody.getStr("batCode");
|
||||
if (StringUtils.isEmpty(batCode)) {
|
||||
log.error("MqttStateChargingDataRequestExchangeProcessor-->>>>> batCode is null");
|
||||
log.error("MqttStateChargingDataExchangeProcessor-->>>>> batCode is null");
|
||||
return;
|
||||
}
|
||||
String chgSn = dataBody.getStr("chgSn");
|
||||
if (StringUtils.isEmpty(chgSn)) {
|
||||
log.error("MqttStateChargingDataRequestExchangeProcessor-->>>>> chgSn is null");
|
||||
log.error("MqttStateChargingDataExchangeProcessor-->>>>> chgSn is null");
|
||||
return;
|
||||
}
|
||||
mongoDBService.save(MongoConstant.BATTERY_DATA_BASE, batCode, new ChargingData(String.valueOf(System.currentTimeMillis()), topic.getStationCode(), batCode,chgSn,dataBody.toString()));
|
||||
saveMongoDB(topic, MongoConstant.BATTERY_DATA_BASE, batCode, new ChargingData(batCode,chgSn,dataBody.toString()));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
package com.evotech.hd.cloud.mqtt.message.processor.impl.state;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.evotech.hd.cloud.mqtt.enums.StateFunctionTypesEnum;
|
||||
import com.evotech.hd.cloud.mqtt.message.MessageTopic;
|
||||
import com.evotech.hd.cloud.mqtt.message.MqttMessageHeader;
|
||||
import com.evotech.hd.cloud.mqtt.message.processor.MqttRequestExchangeProcessor;
|
||||
import com.evotech.hd.cloud.service.BatteryStationService;
|
||||
import com.evotech.hd.common.constant.MongoConstant;
|
||||
import com.evotech.hd.common.documnet.StationState;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 换电站状态类
|
||||
*
|
||||
* @ClassName:MqttStateStationStateExchangeProcessor
|
||||
* @date: 2025年05月05日 13:23
|
||||
* @author: andy.shi
|
||||
* @contact: 17330188597
|
||||
* @remark: 开发人员联系方式 1042025947@qq.com/微信同步
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class MqttStateStationStateExchangeProcessor implements MqttRequestExchangeProcessor {
|
||||
|
||||
@Resource
|
||||
BatteryStationService batteryStationService;
|
||||
@Override
|
||||
public boolean accept(String functionName) {
|
||||
return StateFunctionTypesEnum.FUN_STATION_STATE.getFunction().equals(functionName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exchange(MessageTopic topic, MqttMessageHeader header, JSONObject dataBody) {
|
||||
//记录站级状态信息
|
||||
log.info("MqttStateStationStateExchangeProcessor-->>>>> 请求参数{}", JSONUtil.toJsonStr(dataBody));
|
||||
/***
|
||||
* state: 获取运行状态 1-运营;2-调试;3-检修;
|
||||
* smoke: 获取烟感告警信号, 多个烟感状态,分割, 每个代表一个烟感的状态 0-未知;1-正常;2-告警
|
||||
* fire: 获取消防告警信号 0-未知;1-正常;2-告警
|
||||
*/
|
||||
//通知云端站做状态调整
|
||||
batteryStationService.updateStatusByAlarm(topic.getStationCode(), dataBody.getInt("state"), dataBody.getStr("smoke"), dataBody.getInt("fire"));
|
||||
saveMongoDB(topic, MongoConstant.STATION_INFO_BASE, header.getFunction(),new StationState(dataBody.toString()));
|
||||
}
|
||||
}
|
||||
@ -35,4 +35,14 @@ public interface BatteryStationService {
|
||||
|
||||
List<BatteryStation> deviceList(String proxyCode);
|
||||
|
||||
/***
|
||||
* 根据站级推送状态, 调整相关信息
|
||||
* @param stationCode 站编码
|
||||
* @param state 运营状态 1-运营;2-调试;3-检修;
|
||||
* @param smoke 烟感告警状态 0-未知;1-正常;2-告警,多个烟感时, 以逗号分隔,如:2,1,2,0,1,0,1,2,一 般和架载机个数相同
|
||||
* @param fire 消防告警状态 0-未知;1-正常;2-告警
|
||||
* @return
|
||||
*/
|
||||
Boolean updateStatusByAlarm(String stationCode, Integer state, String smoke, Integer fire);
|
||||
|
||||
}
|
||||
|
||||
@ -55,5 +55,9 @@ public interface OrderSwapBatteryService {
|
||||
public Result<Integer> checkList(PageListSwapOrderRequest plsor);
|
||||
|
||||
|
||||
public Boolean addPreByPlanNum(String planNum, String stationCode);
|
||||
public Boolean addPreByPlateNum(String plateNum, String stationCode);
|
||||
|
||||
public List<OrderSwapBatteryPre> findOrderSwapBatteryPreList(String stationCode);
|
||||
|
||||
Boolean clearOrderSwapBatteryPre(List<Integer> ids);
|
||||
}
|
||||
|
||||
@ -17,9 +17,15 @@ import com.evotech.hd.cloud.entity.BatteryStationSecretKey;
|
||||
import com.evotech.hd.cloud.entity.request.PageListBatteryStationRequest;
|
||||
import com.evotech.hd.cloud.exception.DHException;
|
||||
import com.evotech.hd.cloud.service.BatteryStationService;
|
||||
import com.evotech.hd.cloud.service.OrderSwapBatteryService;
|
||||
import com.evotech.hd.cloud.service.newthread.GZHTemplateMessageService;
|
||||
import com.evotech.hd.cloud.service.rpc.ResourceService;
|
||||
import com.evotech.hd.cloud.service.rpc.WechatService;
|
||||
import com.evotech.hd.common.core.Dto.Result;
|
||||
import com.evotech.hd.common.core.Dto.ResultUtil;
|
||||
import com.evotech.hd.common.core.Dto.request.template.AlarmTemplateDto;
|
||||
import com.evotech.hd.common.core.entity.cloud.BatteryStation;
|
||||
import com.evotech.hd.common.core.entity.cloud.OrderSwapBatteryPre;
|
||||
import com.evotech.hd.common.core.entity.cloud.VehicleInfo;
|
||||
import com.evotech.hd.common.core.entity.cloud.vo.BatteryStationVO;
|
||||
import com.evotech.hd.common.core.enums.CodeMsg;
|
||||
@ -40,6 +46,7 @@ import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.security.KeyPair;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@ -53,6 +60,12 @@ public class BatteryStationServiceImpl implements BatteryStationService {
|
||||
private VehicleInfoDao vehicleInfoDao;
|
||||
@Resource
|
||||
private WechatService wechatService;
|
||||
@Resource
|
||||
private ResourceService resourceService;
|
||||
@Resource
|
||||
private GZHTemplateMessageService templateMessageService;
|
||||
@Resource
|
||||
OrderSwapBatteryService orderSwapBatteryService;
|
||||
|
||||
@Override
|
||||
public com.evotech.hd.common.core.entity.Result<Integer> add(BatteryStation bs) {
|
||||
@ -319,4 +332,68 @@ public class BatteryStationServiceImpl implements BatteryStationService {
|
||||
return batteryStationDao.selectList(new LambdaQueryWrapper<BatteryStation>().eq(BatteryStation::getProxyId, proxyCode).select(BatteryStation::getPkId, BatteryStation::getName, BatteryStation::getStoreId, BatteryStation::getOrgCode));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean updateStatusByAlarm(String stationCode, Integer state, String smoke, Integer fire) {
|
||||
BatteryStation batteryStation = batteryStationDao.selectOne(new LambdaQueryWrapper<BatteryStation>().eq(BatteryStation::getCode, stationCode), false);
|
||||
if(ObjectUtils.isEmpty(batteryStation)){
|
||||
throw new RuntimeException("未找到站点信息");
|
||||
}
|
||||
//推送状态, 不等于站点状态
|
||||
if(!state.equals(batteryStation.getStatus())){
|
||||
//当前站点推送状态也营运状态不一样
|
||||
batteryStation.setStatus(state);
|
||||
}
|
||||
//默认告警状态为false
|
||||
Boolean isAlarm = false;
|
||||
//报警信息
|
||||
StringBuilder alarmMsg = new StringBuilder("");
|
||||
//0-未知;1-正常;2-告警 沟通 只有2才算告警,未知不算告警
|
||||
isAlarm = Integer.valueOf(2).equals(fire);
|
||||
//如果消防告警存在信息
|
||||
if(isAlarm){
|
||||
alarmMsg.append("消防报警");
|
||||
}
|
||||
//如果消防没有报警, 检查烟感
|
||||
if(!isAlarm){
|
||||
//因为烟感有多个, 所以一个烟感报警,及存在报警信息
|
||||
isAlarm = Collections.asList(smoke.split(",")).contains(Integer.valueOf(2));
|
||||
if(isAlarm){
|
||||
alarmMsg.append("烟感报警");
|
||||
}
|
||||
}
|
||||
|
||||
batteryStation.setAlarm(isAlarm);
|
||||
int n = 0;
|
||||
if((n = batteryStationDao.updateById(batteryStation)) > 0){
|
||||
//更新成功, 如果推送状态是运营状态, 则不需要做任何处理, 如果推送的状态非运营状态, 则需要同步推送预约单用户信息
|
||||
if(!Integer.valueOf(1).equals(batteryStation.getStatus())){
|
||||
//不是营运状态, 推送服务号通知
|
||||
List<OrderSwapBatteryPre> preList = orderSwapBatteryService.findOrderSwapBatteryPreList(batteryStation.getCode());
|
||||
if(Collections.isNotEmpty(preList)){
|
||||
//直接关闭预约单
|
||||
orderSwapBatteryService.clearOrderSwapBatteryPre(preList.stream().map(OrderSwapBatteryPre::getPkId).collect(Collectors.toList()));
|
||||
//查询站点是否存在预约单, 存在的话. 通知客户,
|
||||
templateMessageService.serviceStopMessageSend(preList.stream().map(OrderSwapBatteryPre::getUcode).collect(Collectors.toList()), (Integer.valueOf(2).equals(batteryStation.getStatus()) ? "调试" : "检修"));
|
||||
}
|
||||
}
|
||||
//存在报警信息
|
||||
if(batteryStation.getAlarm()){
|
||||
//同步推送站管理员, 和 运营商
|
||||
//站信息查找站管理员和运营商信息, 根据运营商信息, 查对应的负责人信息
|
||||
List<String> wuidList = ResultUtil.getValue(resourceService.alarmUserList(batteryStation.getCode(), batteryStation.getProxyId()));
|
||||
if(Collections.isEmpty(wuidList)){
|
||||
log.error("当前站端管理员信息没有找到绑定的微信信息");
|
||||
return n>0;
|
||||
}
|
||||
AlarmTemplateDto alarmTemplateDto = new AlarmTemplateDto();
|
||||
alarmTemplateDto.setWuid(wuidList);
|
||||
alarmTemplateDto.setStationName(batteryStation.getName());
|
||||
alarmTemplateDto.setAlarmMsg(alarmMsg.toString());
|
||||
templateMessageService.alarmMessageSend(alarmTemplateDto);
|
||||
}
|
||||
}
|
||||
|
||||
return n > 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.evotech.hd.cloud.dao.*;
|
||||
import com.evotech.hd.cloud.entity.vo.NativePayVO;
|
||||
@ -670,7 +671,7 @@ public class OrderSwapBatteryServiceImpl implements OrderSwapBatteryService {
|
||||
|
||||
|
||||
@Override
|
||||
public Boolean addPreByPlanNum(String planNum, String stationCode) {
|
||||
public Boolean addPreByPlateNum(String PlateNum, String stationCode) {
|
||||
BatteryStation batteryStation = batteryStationDao.selectOne(new LambdaQueryWrapper<BatteryStation>().eq(BatteryStation::getCode, stationCode).select(BatteryStation::getCode, BatteryStation::getName), false);
|
||||
// 3. 添加预约
|
||||
Date day = new Date();
|
||||
@ -680,7 +681,7 @@ public class OrderSwapBatteryServiceImpl implements OrderSwapBatteryService {
|
||||
osbp.setUcode("hp_station_push");
|
||||
osbp.setUname("慧鹏站端推送");
|
||||
osbp.setPhone("12332112345");
|
||||
osbp.setPlateNum(planNum);
|
||||
osbp.setPlateNum(PlateNum);
|
||||
osbp.setStationCode(batteryStation.getCode());
|
||||
osbp.setStationName(batteryStation.getName());
|
||||
osbp.setSwapDay(DateUtil.format(day, DatePattern.PURE_DATE_FORMATTER));
|
||||
@ -708,4 +709,24 @@ public class OrderSwapBatteryServiceImpl implements OrderSwapBatteryService {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OrderSwapBatteryPre> findOrderSwapBatteryPreList(String stationCode) {
|
||||
return orderSwapBatteryPreDao.selectList(new LambdaQueryWrapper<OrderSwapBatteryPre>()
|
||||
.eq(OrderSwapBatteryPre::getStationCode, stationCode)
|
||||
.ne(OrderSwapBatteryPre::getUcode,"hp_station_push")
|
||||
.eq(OrderSwapBatteryPre::getStatus, 1)
|
||||
.select(OrderSwapBatteryPre::getUcode)
|
||||
.select(OrderSwapBatteryPre::getPkId)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean clearOrderSwapBatteryPre(List<Integer> ids) {
|
||||
|
||||
return orderSwapBatteryPreDao.update(new UpdateWrapper<OrderSwapBatteryPre>()
|
||||
.in("pk_id", ids)
|
||||
.set("status", 3) //直接取消
|
||||
) > 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,14 +1,15 @@
|
||||
package com.evotech.hd.cloud.service.newthread;
|
||||
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.evotech.hd.cloud.service.rpc.WechatService;
|
||||
import com.evotech.hd.common.core.Dto.request.template.AlarmTemplateDto;
|
||||
import com.evotech.hd.common.core.entity.cloud.OrderSwapBattery;
|
||||
import com.evotech.hd.common.core.entity.cloud.OrderSwapBatteryPre;
|
||||
import com.evotech.hd.common.core.entity.cloud.TradeDetail;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class GZHTemplateMessageService {
|
||||
@ -42,4 +43,24 @@ public class GZHTemplateMessageService {
|
||||
wechatService.backMessage(trade, money);
|
||||
}
|
||||
|
||||
/***
|
||||
* 告警信息推送
|
||||
* @param trade
|
||||
* @param money
|
||||
*/
|
||||
@Async("taskExecutor")
|
||||
public void alarmMessageSend(AlarmTemplateDto alarmTemplate) {
|
||||
wechatService.alarmMessageSend(alarmTemplate);
|
||||
}
|
||||
|
||||
/***
|
||||
* 站端关闭, 预约单服务停止消息推送
|
||||
* @param trade
|
||||
* @param money
|
||||
*/
|
||||
@Async("taskExecutor")
|
||||
public void serviceStopMessageSend(List<String>wuIds, String reason) {
|
||||
wechatService.serviceStopMessageSend(wuIds, reason);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ import com.evotech.hd.common.core.entity.resource.dict.Dict;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.List;
|
||||
@ -25,4 +26,7 @@ public interface ResourceService {
|
||||
@GetMapping(value = "/proxyoperater/basic/info",
|
||||
consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE})
|
||||
public Result<ProxyOperater> basicInfo(@RequestParam String proxyCode);
|
||||
|
||||
@PostMapping(value = "/user/alarm_user", consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE})
|
||||
public Result<List<String>> alarmUserList(@RequestParam String stationCode, @RequestParam String proxyCode);
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.evotech.hd.cloud.service.rpc;
|
||||
|
||||
import com.evotech.hd.common.core.Dto.request.template.AlarmTemplateDto;
|
||||
import org.springdoc.core.annotations.ParameterObject;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.http.MediaType;
|
||||
@ -14,6 +15,8 @@ import com.evotech.hd.common.core.entity.cloud.OrderSwapBattery;
|
||||
import com.evotech.hd.common.core.entity.cloud.OrderSwapBatteryPre;
|
||||
import com.evotech.hd.common.core.entity.cloud.TradeDetail;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@FeignClient(name = "${WECHAT-SERVER-API-NAME}", path = "${WECHAT-SERVER-API-PATH}")
|
||||
public interface WechatService {
|
||||
|
||||
@ -54,4 +57,10 @@ public interface WechatService {
|
||||
consumes = {MediaType.APPLICATION_JSON_VALUE})
|
||||
public Result<String> backMessage(@RequestBody TradeDetail trade, @RequestParam Integer money);
|
||||
|
||||
@PostMapping(value = "/gzh/msg/send/alarm", consumes = {MediaType.APPLICATION_JSON_VALUE})
|
||||
public com.evotech.hd.common.core.Dto.Result<String> alarmMessageSend(@RequestBody AlarmTemplateDto alarmTemplate);
|
||||
|
||||
@PostMapping(value = "/gzh/msg/send/service", consumes = {MediaType.APPLICATION_JSON_VALUE})
|
||||
public com.evotech.hd.common.core.Dto.Result<String> serviceStopMessageSend(@RequestParam List<String> wuIds, @RequestParam String reason);
|
||||
|
||||
}
|
||||
|
||||
@ -32,6 +32,7 @@
|
||||
<result column="updater" property="updater" />
|
||||
<result column="store_id" property="storeId" />
|
||||
<result column="org_code" property="orgCode" />
|
||||
<result column="alarm" property="alarm"/>
|
||||
<collection property="dcList"
|
||||
select="com.evotech.hd.cloud.dao.BatteryStationDcDao.getDcByStationCode"
|
||||
column="code">
|
||||
|
||||
@ -92,5 +92,11 @@ public class AuthUserController {
|
||||
return authUserService.loadUserStation(uid);
|
||||
}
|
||||
|
||||
@PostMapping("/alarm_user")
|
||||
@ApiOperationSupport(order = 5)
|
||||
public Result<List<String>> alarmUserList(@RequestParam String stationCode, @RequestParam String proxyCode) {
|
||||
return authUserService.alarmUserList(stationCode, proxyCode);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -27,4 +27,6 @@ public interface AuthUserService {
|
||||
public com.evotech.hd.common.core.entity.Result<Integer> addUserStation(String stationIds, String uid);
|
||||
|
||||
public Result<List<AuthUserStation>> loadUserStation(String uid);
|
||||
|
||||
public Result<List<String>> alarmUserList(String stationCode, String proxyCode);
|
||||
}
|
||||
|
||||
@ -232,5 +232,10 @@ public class AuthUserServiceImpl implements AuthUserService {
|
||||
return new Result<List<AuthUserStation>>().success(authUserStationDao.selectList(new LambdaQueryWrapper<AuthUserStation>().eq(AuthUserStation::getUid, uid).select(AuthUserStation::getStationId, AuthUserStation::getStationCode)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<List<String>> alarmUserList(String stationCode, String proxyCode) {
|
||||
return new Result<List<String>>().success(userDao.findWuIdByStationCodeAndProxyCode(stationCode, proxyCode));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -34,4 +34,18 @@
|
||||
pk_id, uid, uname, type, type_relate_code, name, password, email, phone, sex, status, readonly, del_flag, avatar, password_error_last_time, password_error_num, password_expire_time, last_login_time, creater, ctime, updater, uptime
|
||||
</sql>
|
||||
|
||||
<select id="findWuIdByStationCodeAndProxyCode" resultType="java.lang.String">
|
||||
SELECT DISTINCT au.wuid FROM yt_auth_user_station aus LEFT JOIN yt_auth_user au ON aus.uid = au.uid
|
||||
WHERE
|
||||
au.wuid is not null
|
||||
<if test="stationCode != null and proxyCode != null ">
|
||||
and (aus.station_code = #{stationCode} or (au.type=2 and au.business_code=#{proxyCode}))
|
||||
</if>
|
||||
<if test="stationCode != null and proxyCode == null ">
|
||||
and aus.station_code = #{stationCode}
|
||||
</if>
|
||||
<if test="stationCode == null and proxyCode != null">
|
||||
and au.type=2 and au.business_code=#{proxyCode}
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@ -35,4 +35,6 @@ public class GZHProperties {
|
||||
private String orderToPayTemplateId2;
|
||||
|
||||
private String WalletBackTemplateId;
|
||||
|
||||
private String alarmTemplateId;
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.evotech.hd.wechat.controller.gzh;
|
||||
|
||||
import com.evotech.hd.common.core.Dto.request.template.AlarmTemplateDto;
|
||||
import org.springdoc.core.annotations.ParameterObject;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
@ -20,6 +21,8 @@ import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "公众号发送消息")
|
||||
@RestController
|
||||
@RequestMapping("/gzh/msg/send")
|
||||
@ -75,4 +78,18 @@ public class GZHMessageSendController {
|
||||
return gzhMessageTemplateService.sendTemplateMessageBack(trade, money);
|
||||
}
|
||||
|
||||
@Operation(summary = "告警信息推送站端员工和运营商")
|
||||
@PostMapping("/alarm")
|
||||
@ApiOperationSupport(order = 6)
|
||||
public com.evotech.hd.common.core.Dto.Result<String> sendTemplateMessageAlarm(@RequestBody AlarmTemplateDto alarmTemplateDto) {
|
||||
return gzhMessageTemplateService.sendTemplateMessageAlarm(alarmTemplateDto);
|
||||
}
|
||||
|
||||
@Operation(summary = "站端停止服务, 推送客户")
|
||||
@PostMapping("/service")
|
||||
@ApiOperationSupport(order = 6)
|
||||
public com.evotech.hd.common.core.Dto.Result<String> serviceStopMessageSend(@RequestParam List<String> wuIds, @RequestParam String reason) {
|
||||
return gzhMessageTemplateService.sendTemplateServiceStop(wuIds, reason);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,44 @@
|
||||
package com.evotech.hd.wechat.entity.gzh.templatemessage;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
*
|
||||
* 站端报警通知类
|
||||
* @ClassName:AlarmMessageTemplateData
|
||||
* @date: 2025年05月05日 17:24
|
||||
* @author: andy.shi
|
||||
* @contact: 17330188597
|
||||
* @remark: 开发人员联系方式 1042025947@qq.com/微信同步
|
||||
*/
|
||||
|
||||
@Getter
|
||||
public class AlarmMessageTemplateData {
|
||||
/***
|
||||
* 站点名称
|
||||
*/
|
||||
private JSONObject thing6;
|
||||
/***
|
||||
* 报警内容
|
||||
*/
|
||||
private JSONObject const4;
|
||||
/***
|
||||
* 报警时间
|
||||
*/
|
||||
private JSONObject time3;
|
||||
|
||||
|
||||
public void setThing6(JSONObject thing6) {
|
||||
this.thing6 = thing6;
|
||||
}
|
||||
|
||||
public void setConst4(JSONObject const4) {
|
||||
this.const4 = const4;
|
||||
}
|
||||
|
||||
|
||||
public void setTime3(JSONObject time3) {
|
||||
this.time3 = time3;
|
||||
}
|
||||
}
|
||||
@ -4,7 +4,10 @@ import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.evotech.hd.common.core.Dto.ResultUtil;
|
||||
import com.evotech.hd.common.core.Dto.request.template.AlarmTemplateDto;
|
||||
import com.evotech.hd.common.core.dao.cloud.OrderSwapBatteryDao;
|
||||
import com.evotech.hd.common.core.dao.wechat.WechatUserDao;
|
||||
import com.evotech.hd.common.core.entity.Result;
|
||||
@ -13,6 +16,7 @@ import com.evotech.hd.common.core.entity.cloud.OrderSwapBatteryPre;
|
||||
import com.evotech.hd.common.core.entity.cloud.TradeDetail;
|
||||
import com.evotech.hd.common.core.entity.wechat.WechatUser;
|
||||
import com.evotech.hd.common.core.enums.CodeMsg;
|
||||
import com.evotech.hd.common.core.utils.Collections;
|
||||
import com.evotech.hd.wechat.config.GZHProperties;
|
||||
import com.evotech.hd.wechat.config.XcxProperties;
|
||||
import com.evotech.hd.wechat.entity.gzh.templatemessage.*;
|
||||
@ -24,6 +28,9 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@ -271,4 +278,126 @@ public class GZHMessageTemplateService {
|
||||
return new Result<String>().error(CodeMsg.WECHAT_API_ERROR, jo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 告警信息推送公众号消息
|
||||
* @return
|
||||
*/
|
||||
public com.evotech.hd.common.core.Dto.Result<String> sendTemplateMessageAlarm(AlarmTemplateDto alarmTemplateDto) {
|
||||
|
||||
Map<String, String> gzhOpenIdMap = wechatUserDao.selectList(new LambdaQueryWrapper<WechatUser>().in(WechatUser::getWuid, alarmTemplateDto.getWuid()).isNotNull(WechatUser::getGzhOpenid).select(WechatUser::getWuid, WechatUser::getGzhOpenid)).stream().collect(Collectors.toMap(WechatUser::getWuid,WechatUser::getGzhOpenid, (d1,d2) -> d1));
|
||||
if (Collections.isEmpty(gzhOpenIdMap)) {
|
||||
return new com.evotech.hd.common.core.Dto.Result<String>().error(CodeMsg.PARAM_IS_NULL,"当前工作人员没有关注服务号");
|
||||
}
|
||||
StringBuilder error = new StringBuilder("");
|
||||
Iterator<String> iterator = alarmTemplateDto.getWuid().iterator();
|
||||
List<String> existsGzhOpenIdList = gzhOpenIdMap.keySet().stream().collect(Collectors.toList());
|
||||
while (iterator.hasNext()) {
|
||||
String key = iterator.next();
|
||||
if (existsGzhOpenIdList.contains(key)) {
|
||||
iterator.remove(); // 删除当前迭代的元素"b"
|
||||
}
|
||||
}
|
||||
//去掉存在gzhopenid的wuid对象
|
||||
List<String> oldWuIdList = StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false)
|
||||
.collect(Collectors.toList());
|
||||
if(Collections.isNotEmpty(oldWuIdList)){
|
||||
error.append("以下用户ID没有关注公众号").append(String.join(",", oldWuIdList)).append(";");
|
||||
}
|
||||
|
||||
AlarmMessageTemplateData data = new AlarmMessageTemplateData();
|
||||
data.setThing6(JSONUtil.parseObj(Collections.asMap("value", alarmTemplateDto.getStationName())));
|
||||
data.setConst4(JSONUtil.parseObj(Collections.asMap("value", alarmTemplateDto.getAlarmMsg())));
|
||||
data.setTime3(JSONUtil.parseObj(Collections.asMap("value", DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss"))));
|
||||
|
||||
String templateId = gzhProperties.getAlarmTemplateId();
|
||||
List<String> errorGzhOpenIdList = Collections.emptyList();
|
||||
gzhOpenIdMap.values().forEach(gzhOpenId ->{
|
||||
String result = ResultUtil.getValue(sendTemplateMessage(gzhOpenId,templateId, JSONUtil.parseObj(data),true));
|
||||
if(org.apache.commons.lang3.StringUtils.isEmpty(result)){
|
||||
errorGzhOpenIdList.add(gzhOpenId);
|
||||
}
|
||||
});
|
||||
if(Collections.isNotEmpty(errorGzhOpenIdList)){
|
||||
error.append("以下公众号ID推送告警信息失败了").append(String.join(",", errorGzhOpenIdList)).append(";");
|
||||
}
|
||||
|
||||
if(org.apache.commons.lang3.StringUtils.isNotEmpty(error)){
|
||||
return new com.evotech.hd.common.core.Dto.Result<String>().error(CodeMsg.PARAM_IS_NULL,error.toString());
|
||||
}
|
||||
return new com.evotech.hd.common.core.Dto.Result<String>().success("成功");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 告警信息推送公众号消息
|
||||
* @return
|
||||
*/
|
||||
public com.evotech.hd.common.core.Dto.Result<String> sendTemplateServiceStop(List<String> wuIds, String reason) {
|
||||
|
||||
return new com.evotech.hd.common.core.Dto.Result<String>().success("模版审核中, 暂时不做");
|
||||
|
||||
// Map<String, String> gzhOpenIdMap = wechatUserDao.selectList(new LambdaQueryWrapper<WechatUser>().in(WechatUser::getWuid, wuIds).isNotNull(WechatUser::getGzhOpenid).select(WechatUser::getWuid, WechatUser::getGzhOpenid)).stream().collect(Collectors.toMap(WechatUser::getWuid,WechatUser::getGzhOpenid, (d1,d2) -> d1));
|
||||
// if (Collections.isEmpty(gzhOpenIdMap)) {
|
||||
// return new com.evotech.hd.common.core.Dto.Result<String>().error(CodeMsg.PARAM_IS_NULL,"当前预约客户没有关注服务号");
|
||||
// }
|
||||
// StringBuilder error = new StringBuilder("");
|
||||
// Iterator<String> iterator = wuIds.iterator();
|
||||
// List<String> existsGzhOpenIdList = gzhOpenIdMap.keySet().stream().collect(Collectors.toList());
|
||||
// while (iterator.hasNext()) {
|
||||
// String key = iterator.next();
|
||||
// if (existsGzhOpenIdList.contains(key)) {
|
||||
// iterator.remove(); // 删除当前迭代的元素"b"
|
||||
// }
|
||||
// }
|
||||
// //去掉存在gzhopenid的wuid对象
|
||||
// List<String> oldWuIdList = StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false)
|
||||
// .collect(Collectors.toList());
|
||||
// if(Collections.isNotEmpty(oldWuIdList)){
|
||||
// error.append("以下用户ID没有关注公众号").append(String.join(",", oldWuIdList)).append(";");
|
||||
// }
|
||||
//
|
||||
// AlarmMessageTemplateData data = new AlarmMessageTemplateData();
|
||||
// String templateId = gzhProperties.getWalletBackTemplateId();
|
||||
// List<String> errorGzhOpenIdList = Collections.emptyList();
|
||||
// gzhOpenIdMap.values().forEach(gzhOpenId ->{
|
||||
// String result = ResultUtil.getValue(sendTemplateMessage( gzhOpenId,templateId,JSONUtil.parseObj(data),true));
|
||||
// if(org.apache.commons.lang3.StringUtils.isEmpty(result)){
|
||||
// errorGzhOpenIdList.add(gzhOpenId);
|
||||
// }
|
||||
// });
|
||||
// if(Collections.isNotEmpty(errorGzhOpenIdList)){
|
||||
// error.append("以下公众号ID推送站端停止运营消息失败了").append(String.join(",", errorGzhOpenIdList)).append(";");
|
||||
// }
|
||||
//
|
||||
// if(org.apache.commons.lang3.StringUtils.isNotEmpty(error)){
|
||||
// return new com.evotech.hd.common.core.Dto.Result<String>().error(CodeMsg.PARAM_IS_NULL,error.toString());
|
||||
// }
|
||||
// return new com.evotech.hd.common.core.Dto.Result<String>().success("成功");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private com.evotech.hd.common.core.Dto.Result<String> sendTemplateMessage(String gzhOpenId, String templateId, JSONObject templateData, Boolean isJumpApplet){
|
||||
MessageTemplateSendData sendData = new MessageTemplateSendData();
|
||||
sendData.setTouser(gzhOpenId);
|
||||
sendData.setTemplate_id(templateId);
|
||||
sendData.setData(templateData);
|
||||
if(isJumpApplet){
|
||||
Miniprogram miniprogram = new Miniprogram();
|
||||
miniprogram.setAppid(xcxProperties.getAppid());
|
||||
miniprogram.setPath(orderPage);
|
||||
sendData.setMiniprogram(miniprogram);
|
||||
}
|
||||
|
||||
String res = TemplateMessageUtil.templateMessageSend(gzhAccessTokenService.gzhAccessToken(), sendData);
|
||||
JSONObject jo = JSONUtil.parseObj(res);
|
||||
if (jo.getInt("errcode") == 0) {
|
||||
return new com.evotech.hd.common.core.Dto.Result<String>().success(jo.toString());
|
||||
}
|
||||
return new com.evotech.hd.common.core.Dto.Result<String>().error(CodeMsg.WECHAT_API_ERROR, jo.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,4 +125,5 @@ hbyt:
|
||||
order_end_template_id: C5-AGh67aFXChQONqSwxaRrJgFrn_Z25VTlTk0jHSUY
|
||||
wallet_recharge_template_id: 8JXsn_VkI0S0YZSbT2EKmV_zOxyudo4IsBLeU7V-SFk
|
||||
order_to_pay_template_id2: K6cdaBOkxGJpah0vsz5rq5UBID04mk-eEWp2XM0KyA0
|
||||
wallet_back_template_id: aO9GDhgIcYnCDCpsVSMB-CeXG3J4JzHlOUV2bhOAvVI
|
||||
wallet_back_template_id: aO9GDhgIcYnCDCpsVSMB-CeXG3J4JzHlOUV2bhOAvVI
|
||||
alarm_template_id: 8vW_gOzoOMzlJqvtSOF0fLeNm8Z6pttJG63oeFe1gq4
|
||||
Loading…
Reference in New Issue
Block a user