完成天气部分继承
This commit is contained in:
parent
b691b889e8
commit
8004a63b80
@ -0,0 +1,47 @@
|
||||
package com.qiuguo.iot.base.enums;
|
||||
|
||||
/*
|
||||
* 动作类型
|
||||
* 作者:吴林
|
||||
* */
|
||||
// 动作类型:0:文本播放 1音频播放 2 U3D动作 3物联网设备动作
|
||||
public enum TimeKeyEnum {
|
||||
TODAY(0, "今天"),
|
||||
YESTERDAY(1, "昨天"),
|
||||
TOMORROW(2, "明天"),
|
||||
ACQUIRED(3, "后天"),
|
||||
;
|
||||
TimeKeyEnum(Integer c, String n){
|
||||
code = c;
|
||||
name = n;
|
||||
}
|
||||
private Integer code;
|
||||
private String name;
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public static TimeKeyEnum getEnumWithCode(Integer c){
|
||||
for (TimeKeyEnum e:values()
|
||||
) {
|
||||
if(e.getCode().compareTo(c) == 0){
|
||||
return e;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static TimeKeyEnum getEnumWithName(String name){
|
||||
for (TimeKeyEnum e:values()
|
||||
) {
|
||||
if(e.getName().equals(name)){
|
||||
return e;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
package com.qiuguo.iot.base.enums;
|
||||
|
||||
/*
|
||||
* 动作类型
|
||||
* 作者:吴林
|
||||
* */
|
||||
// 动作类型:0:文本播放 1音频播放 2 U3D动作 3物联网设备动作
|
||||
public enum WebSocketReqTypeEnum {
|
||||
TTS(0, "文本播放"),
|
||||
IOT(1, "IOT控制"),
|
||||
ALARM_CLOCK(3, "闹钟"),
|
||||
WEATHER(2, "天气"),
|
||||
|
||||
U3D(4, "U3D动作"),
|
||||
|
||||
UPDATE(100, "固件升级"),
|
||||
;
|
||||
WebSocketReqTypeEnum(Integer c, String n){
|
||||
code = c;
|
||||
name = n;
|
||||
}
|
||||
private Integer code;
|
||||
private String name;
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public static WebSocketReqTypeEnum getEnumWithCode(Integer c){
|
||||
for (WebSocketReqTypeEnum e:values()
|
||||
) {
|
||||
if(e.getCode().compareTo(c) == 0){
|
||||
return e;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static WebSocketReqTypeEnum getEnumWithName(String name){
|
||||
for (WebSocketReqTypeEnum e:values()
|
||||
) {
|
||||
if(e.getName().equals(name)){
|
||||
return e;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,92 @@
|
||||
package com.qiuguo.iot.data.entity.system;
|
||||
import org.hswebframework.ezorm.rdb.mapping.annotation.Comment;
|
||||
import org.hswebframework.web.crud.annotation.EnableEntityEvent;
|
||||
import org.hswebframework.web.api.crud.entity.GenericEntity;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Table;import lombok.Data;
|
||||
import java.util.Date;
|
||||
/**
|
||||
* <p>
|
||||
* </p>*数据-区域
|
||||
* @author wulin
|
||||
* @since 2023-09-26
|
||||
*/
|
||||
|
||||
@Data
|
||||
@Comment("数据-区域")
|
||||
@Table(name = "system_address")
|
||||
@EnableEntityEvent
|
||||
public class SystemAddressEntity extends GenericEntity<Long> {
|
||||
@Comment("ID")
|
||||
@Column(name = "id", length = 11, nullable = false, unique = true)
|
||||
private Long id;
|
||||
|
||||
@Comment("is_delete")
|
||||
@Column(name = "is_delete")
|
||||
private Integer isDelete;
|
||||
|
||||
@Comment("create_time")
|
||||
@Column(name = "create_time")
|
||||
private Date createTime;
|
||||
|
||||
@Comment("modify_time")
|
||||
@Column(name = "modify_time")
|
||||
private Date modifyTime;
|
||||
|
||||
@Comment("上级ID")
|
||||
@Column(name = "parent_id", nullable = false)
|
||||
private Long parentId;
|
||||
|
||||
@Comment("adcode")
|
||||
@Column(name = "adcode")
|
||||
private Integer adcode;
|
||||
|
||||
@Comment("上级 adcode")
|
||||
@Column(name = "padcode", nullable = false)
|
||||
private Integer padcode;
|
||||
|
||||
@Comment("首字母")
|
||||
@Column(name = "first", length = 50)
|
||||
private String first;
|
||||
|
||||
@Comment("区域简称")
|
||||
@Column(name = "short_name", length = 100)
|
||||
private String shortName;
|
||||
|
||||
@Comment("区域名称")
|
||||
@Column(name = "name", length = 100)
|
||||
private String name;
|
||||
|
||||
@Comment("adcode_link")
|
||||
@Column(name = "adcode_link", length = 56)
|
||||
private String adcodeLink;
|
||||
|
||||
@Comment("name_link")
|
||||
@Column(name = "name_link", length = 255)
|
||||
private String nameLink;
|
||||
|
||||
@Comment("区域层级")
|
||||
@Column(name = "level")
|
||||
private Integer level;
|
||||
|
||||
@Comment("区域拼音")
|
||||
@Column(name = "pinyin", length = 100)
|
||||
private String pinyin;
|
||||
|
||||
@Comment("区域邮编")
|
||||
@Column(name = "postcode", length = 100)
|
||||
private String postcode;
|
||||
|
||||
@Comment("使用状态")
|
||||
@Column(name = "status", length = 1)
|
||||
private Integer status;
|
||||
|
||||
@Comment("所在经度")
|
||||
@Column(name = "lng", length = 100)
|
||||
private String lng;
|
||||
|
||||
@Comment("所在纬度")
|
||||
@Column(name = "lat", length = 100)
|
||||
private String lat;
|
||||
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
package com.qiuguo.iot.data.request.system;
|
||||
import lombok.Data;
|
||||
import java.util.Date;
|
||||
/**
|
||||
* <p>
|
||||
*数据-区域请求类
|
||||
* @author wulin
|
||||
* @since 2023-09-26
|
||||
*/
|
||||
|
||||
|
||||
@Data
|
||||
public class SystemAddressRequest implements java.io.Serializable {
|
||||
|
||||
private int currPage = 1;
|
||||
private int pageSize = 10;
|
||||
private String sort;
|
||||
private String order;
|
||||
//ID
|
||||
private Long id;
|
||||
//
|
||||
private Integer isDelete;
|
||||
//
|
||||
private Date createTime;
|
||||
//搜索开始
|
||||
|
||||
private Date createTimeStart;
|
||||
|
||||
//搜索结束
|
||||
private Date createTimeEnd;
|
||||
//
|
||||
private Date modifyTime;
|
||||
//搜索开始
|
||||
|
||||
private Date modifyTimeStart;
|
||||
|
||||
//搜索结束
|
||||
private Date modifyTimeEnd;
|
||||
//上级ID
|
||||
private Long parentId;
|
||||
//adcode
|
||||
private Integer adcode;
|
||||
//上级 adcode
|
||||
private Integer padcode;
|
||||
//首字母
|
||||
private String first;
|
||||
//区域简称
|
||||
private String shortName;
|
||||
//区域名称
|
||||
private String name;
|
||||
//
|
||||
private String adcodeLink;
|
||||
//
|
||||
private String nameLink;
|
||||
//区域层级
|
||||
private Integer level;
|
||||
//区域拼音
|
||||
private String pinyin;
|
||||
//区域邮编
|
||||
private String postcode;
|
||||
//使用状态
|
||||
private Integer status;
|
||||
//所在经度
|
||||
private String lng;
|
||||
//所在纬度
|
||||
private String lat;
|
||||
}
|
||||
@ -41,4 +41,7 @@ public class ThirdWeatherInfoRequest {
|
||||
* 经度
|
||||
*/
|
||||
private String lng;
|
||||
|
||||
//城市
|
||||
private String city;
|
||||
}
|
||||
|
||||
@ -0,0 +1,70 @@
|
||||
package com.qiuguo.iot.data.resp.system;
|
||||
import com.qiuguo.iot.data.entity.system.SystemAddressEntity;
|
||||
import lombok.Data;
|
||||
import java.util.Date;
|
||||
/**
|
||||
* <p>
|
||||
* </p>*数据-区域返回类
|
||||
* @author wulin
|
||||
* @since 2023-09-26
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class SystemAddressResp {
|
||||
public SystemAddressResp(){
|
||||
}
|
||||
public SystemAddressResp(SystemAddressEntity entity){
|
||||
id = entity.getId();
|
||||
createTime = entity.getCreateTime();
|
||||
modifyTime = entity.getModifyTime();
|
||||
parentId = entity.getParentId();
|
||||
adcode = entity.getAdcode();
|
||||
padcode = entity.getPadcode();
|
||||
first = entity.getFirst();
|
||||
shortName = entity.getShortName();
|
||||
name = entity.getName();
|
||||
adcodeLink = entity.getAdcodeLink();
|
||||
nameLink = entity.getNameLink();
|
||||
level = entity.getLevel();
|
||||
pinyin = entity.getPinyin();
|
||||
postcode = entity.getPostcode();
|
||||
status = entity.getStatus();
|
||||
lng = entity.getLng();
|
||||
lat = entity.getLat();
|
||||
}
|
||||
|
||||
//ID
|
||||
private Long id;
|
||||
//
|
||||
private Date createTime;
|
||||
//
|
||||
private Date modifyTime;
|
||||
//上级ID
|
||||
private Long parentId;
|
||||
//adcode
|
||||
private Integer adcode;
|
||||
//上级 adcode
|
||||
private Integer padcode;
|
||||
//首字母
|
||||
private String first;
|
||||
//区域简称
|
||||
private String shortName;
|
||||
//区域名称
|
||||
private String name;
|
||||
//
|
||||
private String adcodeLink;
|
||||
//
|
||||
private String nameLink;
|
||||
//区域层级
|
||||
private Integer level;
|
||||
//区域拼音
|
||||
private String pinyin;
|
||||
//区域邮编
|
||||
private String postcode;
|
||||
//使用状态
|
||||
private Integer status;
|
||||
//所在经度
|
||||
private String lng;
|
||||
//所在纬度
|
||||
private String lat;
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package com.qiuguo.iot.data.resp.third.weather;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* https://tianqiapi.com/index/doc?version=v91
|
||||
*/
|
||||
@Data
|
||||
public class TianqiapiItemResp {
|
||||
private String date;//日期
|
||||
private String wea;//天气
|
||||
private String tem2;//最低气温
|
||||
private String tem1;//最高气温
|
||||
private String visibility;//可见度
|
||||
private String humidity;//湿度
|
||||
private String win_speed;//风速
|
||||
private String air_level;//空气质量
|
||||
private String narrative;//自然语言描述
|
||||
private List<TianqiapiLifeItemResp> index;
|
||||
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package com.qiuguo.iot.data.resp.third.weather;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 生活指数
|
||||
* https://tianqiapi.com/index/doc?version=v91
|
||||
*/
|
||||
@Data
|
||||
public class TianqiapiLifeItemResp {
|
||||
private String title;//指数名词
|
||||
private String level;//指数级别
|
||||
/***
|
||||
* 指数建议
|
||||
*
|
||||
*/
|
||||
private String desc;
|
||||
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package com.qiuguo.iot.data.resp.third.weather;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* https://tianqiapi.com/index/doc?version=v91
|
||||
*/
|
||||
@Data
|
||||
public class TianqiapiResp {
|
||||
|
||||
/***
|
||||
* 城市
|
||||
*/
|
||||
private String city;
|
||||
private List<TianqiapiItemResp> data;
|
||||
|
||||
}
|
||||
@ -0,0 +1,290 @@
|
||||
package com.qiuguo.iot.data.service.system;
|
||||
|
||||
|
||||
|
||||
import com.qiuguo.iot.base.utils.StringUtils;
|
||||
import com.qiuguo.iot.data.entity.system.SystemAddressEntity;
|
||||
import com.qiuguo.iot.data.request.system.SystemAddressRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.hswebframework.ezorm.rdb.mapping.ReactiveQuery;
|
||||
import org.hswebframework.ezorm.rdb.mapping.ReactiveUpdate;
|
||||
import org.hswebframework.ezorm.rdb.operator.dml.query.SortOrder;
|
||||
import org.hswebframework.web.api.crud.entity.PagerResult;
|
||||
import org.hswebframework.web.api.crud.entity.QueryParamEntity;
|
||||
import org.hswebframework.web.crud.service.GenericReactiveCrudService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.Date;
|
||||
/**
|
||||
* <p>
|
||||
* 数据-区域服务类
|
||||
* </p>
|
||||
*
|
||||
* @author wulin
|
||||
* @since 2023-09-26
|
||||
*/
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SystemAddressService extends GenericReactiveCrudService<SystemAddressEntity, Long> {
|
||||
|
||||
|
||||
public Mono<SystemAddressEntity> selectSystemAddressByRequest(SystemAddressRequest request){
|
||||
ReactiveQuery<SystemAddressEntity> reactiveQuery = createQuery();
|
||||
reactiveQuery = reactiveQuery.and("is_delete", 0);
|
||||
if(request.getId() != null){
|
||||
reactiveQuery = reactiveQuery.and(SystemAddressRequest::getId, request.getId());
|
||||
}
|
||||
if(request.getIsDelete() != null){
|
||||
reactiveQuery = reactiveQuery.and(SystemAddressRequest::getIsDelete, request.getIsDelete());
|
||||
}
|
||||
if(request.getCreateTime() != null){
|
||||
reactiveQuery = reactiveQuery.and(SystemAddressRequest::getCreateTime, request.getCreateTime());
|
||||
}
|
||||
if(request.getModifyTime() != null){
|
||||
reactiveQuery = reactiveQuery.and(SystemAddressRequest::getModifyTime, request.getModifyTime());
|
||||
}
|
||||
if(request.getParentId() != null){
|
||||
reactiveQuery = reactiveQuery.and(SystemAddressRequest::getParentId, request.getParentId());
|
||||
}
|
||||
if(request.getAdcode() != null){
|
||||
reactiveQuery = reactiveQuery.and(SystemAddressRequest::getAdcode, request.getAdcode());
|
||||
}
|
||||
if(request.getPadcode() != null){
|
||||
reactiveQuery = reactiveQuery.and(SystemAddressRequest::getPadcode, request.getPadcode());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(request.getFirst())){
|
||||
reactiveQuery = reactiveQuery.and(SystemAddressRequest::getFirst, request.getFirst());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(request.getShortName())){
|
||||
reactiveQuery = reactiveQuery.and(SystemAddressRequest::getShortName, request.getShortName());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(request.getName())){
|
||||
reactiveQuery = reactiveQuery.and(SystemAddressRequest::getName, request.getName());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(request.getAdcodeLink())){
|
||||
reactiveQuery = reactiveQuery.and(SystemAddressRequest::getAdcodeLink, request.getAdcodeLink());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(request.getNameLink())){
|
||||
reactiveQuery = reactiveQuery.and(SystemAddressRequest::getNameLink, request.getNameLink());
|
||||
}
|
||||
if(request.getLevel() != null){
|
||||
reactiveQuery = reactiveQuery.and(SystemAddressRequest::getLevel, request.getLevel());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(request.getPinyin())){
|
||||
reactiveQuery = reactiveQuery.and(SystemAddressRequest::getPinyin, request.getPinyin());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(request.getPostcode())){
|
||||
reactiveQuery = reactiveQuery.and(SystemAddressRequest::getPostcode, request.getPostcode());
|
||||
}
|
||||
if(request.getStatus() != null){
|
||||
reactiveQuery = reactiveQuery.and(SystemAddressRequest::getStatus, request.getStatus());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(request.getLng())){
|
||||
reactiveQuery = reactiveQuery.and(SystemAddressRequest::getLng, request.getLng());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(request.getLat())){
|
||||
reactiveQuery = reactiveQuery.and(SystemAddressRequest::getLat, request.getLat());
|
||||
}
|
||||
SortOrder sortOrder = null;
|
||||
if(StringUtils.isNotEmpty(request.getOrder())){
|
||||
if(StringUtils.isNotEmpty(request.getSort()) && request.getSort().compareTo("0") == 0){
|
||||
sortOrder = SortOrder.desc(request.getOrder());
|
||||
}else{
|
||||
sortOrder = SortOrder.asc(request.getOrder());
|
||||
}
|
||||
reactiveQuery = reactiveQuery.orderBy(sortOrder);
|
||||
}
|
||||
return reactiveQuery.fetchOne();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Mono<PagerResult<SystemAddressEntity>> selectSystemAddresssByRequest(SystemAddressRequest request){
|
||||
ReactiveQuery<SystemAddressEntity> reactiveQuery = createQuery();
|
||||
reactiveQuery = reactiveQuery.and("is_delete", 0);
|
||||
if(request.getId() != null){
|
||||
reactiveQuery = reactiveQuery.and(SystemAddressRequest::getId, request.getId());
|
||||
}
|
||||
if(request.getIsDelete() != null){
|
||||
reactiveQuery = reactiveQuery.and(SystemAddressRequest::getIsDelete, request.getIsDelete());
|
||||
}
|
||||
if(request.getCreateTimeStart() != null){
|
||||
reactiveQuery = reactiveQuery.gte(SystemAddressRequest::getCreateTime, request.getCreateTimeStart());
|
||||
}
|
||||
if(request.getCreateTimeEnd() != null){
|
||||
reactiveQuery = reactiveQuery.lte(SystemAddressRequest::getCreateTime, request.getCreateTimeEnd());
|
||||
}
|
||||
if(request.getModifyTimeStart() != null){
|
||||
reactiveQuery = reactiveQuery.gte(SystemAddressRequest::getModifyTime, request.getModifyTimeStart());
|
||||
}
|
||||
if(request.getModifyTimeEnd() != null){
|
||||
reactiveQuery = reactiveQuery.lte(SystemAddressRequest::getModifyTime, request.getModifyTimeEnd());
|
||||
}
|
||||
if(request.getParentId() != null){
|
||||
reactiveQuery = reactiveQuery.and(SystemAddressRequest::getParentId, request.getParentId());
|
||||
}
|
||||
if(request.getAdcode() != null){
|
||||
reactiveQuery = reactiveQuery.and(SystemAddressRequest::getAdcode, request.getAdcode());
|
||||
}
|
||||
if(request.getPadcode() != null){
|
||||
reactiveQuery = reactiveQuery.and(SystemAddressRequest::getPadcode, request.getPadcode());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(request.getFirst())){
|
||||
reactiveQuery = reactiveQuery.$like$(SystemAddressRequest::getFirst, request.getFirst());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(request.getShortName())){
|
||||
reactiveQuery = reactiveQuery.$like$(SystemAddressRequest::getShortName, request.getShortName());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(request.getName())){
|
||||
reactiveQuery = reactiveQuery.$like$(SystemAddressRequest::getName, request.getName());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(request.getAdcodeLink())){
|
||||
reactiveQuery = reactiveQuery.$like$(SystemAddressRequest::getAdcodeLink, request.getAdcodeLink());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(request.getNameLink())){
|
||||
reactiveQuery = reactiveQuery.$like$(SystemAddressRequest::getNameLink, request.getNameLink());
|
||||
}
|
||||
if(request.getLevel() != null){
|
||||
reactiveQuery = reactiveQuery.and(SystemAddressRequest::getLevel, request.getLevel());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(request.getPinyin())){
|
||||
reactiveQuery = reactiveQuery.$like$(SystemAddressRequest::getPinyin, request.getPinyin());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(request.getPostcode())){
|
||||
reactiveQuery = reactiveQuery.$like$(SystemAddressRequest::getPostcode, request.getPostcode());
|
||||
}
|
||||
if(request.getStatus() != null){
|
||||
reactiveQuery = reactiveQuery.and(SystemAddressRequest::getStatus, request.getStatus());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(request.getLng())){
|
||||
reactiveQuery = reactiveQuery.$like$(SystemAddressRequest::getLng, request.getLng());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(request.getLat())){
|
||||
reactiveQuery = reactiveQuery.$like$(SystemAddressRequest::getLat, request.getLat());
|
||||
}
|
||||
SortOrder sortOrder = null;
|
||||
if(StringUtils.isNotEmpty(request.getOrder())){
|
||||
if(StringUtils.isNotEmpty(request.getSort()) && request.getSort().compareTo("0") == 0){
|
||||
sortOrder = SortOrder.desc(request.getOrder());
|
||||
}else{
|
||||
sortOrder = SortOrder.asc(request.getOrder());
|
||||
}
|
||||
reactiveQuery = reactiveQuery.orderBy(sortOrder);
|
||||
}
|
||||
QueryParamEntity param = QueryParamEntity.of(reactiveQuery.getParam());
|
||||
param.setPageIndex(request.getCurrPage());
|
||||
param.setPageSize(request.getPageSize());
|
||||
param.setPaging(true);
|
||||
param.setFirstPageIndex(1);
|
||||
return queryPager(param);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Mono<SystemAddressEntity> selectSystemAddressById(Long id){
|
||||
return createQuery()
|
||||
.and("is_delete", 0)
|
||||
.and("id", id)
|
||||
.fetchOne();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Mono<Integer> insertSystemAddress(SystemAddressEntity entity){
|
||||
entity.setId(null);
|
||||
entity.setCreateTime(null);
|
||||
entity.setModifyTime(null);
|
||||
return insert(entity);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Mono<Integer> updateSystemAddressById(SystemAddressEntity entity){
|
||||
ReactiveUpdate<SystemAddressEntity> update = createUpdate()
|
||||
.set(SystemAddressEntity::getModifyTime, new Date());
|
||||
if(entity.getIsDelete() != null){
|
||||
update = update.set(SystemAddressEntity::getIsDelete, entity.getIsDelete());
|
||||
}
|
||||
if(entity.getParentId() != null){
|
||||
update = update.set(SystemAddressEntity::getParentId, entity.getParentId());
|
||||
}
|
||||
if(entity.getAdcode() != null){
|
||||
update = update.set(SystemAddressEntity::getAdcode, entity.getAdcode());
|
||||
}
|
||||
if(entity.getPadcode() != null){
|
||||
update = update.set(SystemAddressEntity::getPadcode, entity.getPadcode());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(entity.getFirst())){
|
||||
update = update.set(SystemAddressEntity::getFirst, entity.getFirst());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(entity.getShortName())){
|
||||
update = update.set(SystemAddressEntity::getShortName, entity.getShortName());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(entity.getName())){
|
||||
update = update.set(SystemAddressEntity::getName, entity.getName());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(entity.getAdcodeLink())){
|
||||
update = update.set(SystemAddressEntity::getAdcodeLink, entity.getAdcodeLink());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(entity.getNameLink())){
|
||||
update = update.set(SystemAddressEntity::getNameLink, entity.getNameLink());
|
||||
}
|
||||
if(entity.getLevel() != null){
|
||||
update = update.set(SystemAddressEntity::getLevel, entity.getLevel());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(entity.getPinyin())){
|
||||
update = update.set(SystemAddressEntity::getPinyin, entity.getPinyin());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(entity.getPostcode())){
|
||||
update = update.set(SystemAddressEntity::getPostcode, entity.getPostcode());
|
||||
}
|
||||
if(entity.getStatus() != null){
|
||||
update = update.set(SystemAddressEntity::getStatus, entity.getStatus());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(entity.getLng())){
|
||||
update = update.set(SystemAddressEntity::getLng, entity.getLng());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(entity.getLat())){
|
||||
update = update.set(SystemAddressEntity::getLat, entity.getLat());
|
||||
}
|
||||
return update.where(SystemAddressEntity::getId, entity.getId()).and("is_delete", 0).execute();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Mono<Integer> updateCoverSystemAddressById(SystemAddressEntity entity){
|
||||
ReactiveUpdate<SystemAddressEntity> update = createUpdate()
|
||||
.set(SystemAddressEntity::getModifyTime, new Date());
|
||||
update = update.set(SystemAddressEntity::getIsDelete, entity.getIsDelete());
|
||||
update = update.set(SystemAddressEntity::getParentId, entity.getParentId());
|
||||
update = update.set(SystemAddressEntity::getAdcode, entity.getAdcode());
|
||||
update = update.set(SystemAddressEntity::getPadcode, entity.getPadcode());
|
||||
update = update.set(SystemAddressEntity::getFirst, entity.getFirst());
|
||||
update = update.set(SystemAddressEntity::getShortName, entity.getShortName());
|
||||
update = update.set(SystemAddressEntity::getName, entity.getName());
|
||||
update = update.set(SystemAddressEntity::getAdcodeLink, entity.getAdcodeLink());
|
||||
update = update.set(SystemAddressEntity::getNameLink, entity.getNameLink());
|
||||
update = update.set(SystemAddressEntity::getLevel, entity.getLevel());
|
||||
update = update.set(SystemAddressEntity::getPinyin, entity.getPinyin());
|
||||
update = update.set(SystemAddressEntity::getPostcode, entity.getPostcode());
|
||||
update = update.set(SystemAddressEntity::getStatus, entity.getStatus());
|
||||
update = update.set(SystemAddressEntity::getLng, entity.getLng());
|
||||
update = update.set(SystemAddressEntity::getLat, entity.getLat());
|
||||
return update.where(SystemAddressEntity::getId, entity.getId()).and("is_delete", 0).execute();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Mono<Integer> deleteSystemAddressById(Long id){
|
||||
return createUpdate()
|
||||
.set("is_delete", 1)
|
||||
.set("modify_time", new Date())
|
||||
.where("id", id)
|
||||
.execute();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -42,6 +42,7 @@ public class SystemTalkAnswerConfigService extends GenericReactiveCrudService<Sy
|
||||
@PostConstruct
|
||||
public void initGroup() {
|
||||
log.info("初始化自定义回答缓存数据");
|
||||
group.clear();
|
||||
ReactiveQuery<SystemTalkAnswerConfigEntity> reactiveQuery = createQuery();
|
||||
reactiveQuery = reactiveQuery.and("is_delete", 0);
|
||||
|
||||
|
||||
@ -11,4 +11,7 @@ public class Action {
|
||||
private String action;//动作(动词)
|
||||
private List<String> name;//动作对象(名词)。可能存在多个,如果有关系词连接
|
||||
private String status;//动作程度结果(名词,量词)
|
||||
|
||||
private String time;//具体时间
|
||||
private List<String> lbs;//一些城市地狱名词
|
||||
}
|
||||
|
||||
@ -23,6 +23,7 @@ public class Actions {
|
||||
Action action = new Action();
|
||||
String name = "";
|
||||
action.setName(new ArrayList<>());
|
||||
action.setLbs(new ArrayList<>());
|
||||
for (NlpKey key : nlp.getKeys()
|
||||
) {
|
||||
|
||||
@ -31,11 +32,21 @@ public class Actions {
|
||||
}else if(key.getType().equals(ChinesePartSpeechEnum.n.getCode())){
|
||||
name += key.getKey();
|
||||
//action.getName().add(key.getKey());
|
||||
}else if(key.getType().equals(ChinesePartSpeechEnum.m.getCode())){
|
||||
action.setStatus(key.getKey());
|
||||
//action.getName().add(key.getKey());
|
||||
}else if(key.getType().equals(ChinesePartSpeechEnum.c.getCode())){
|
||||
//action.setStatus(key.getKey());
|
||||
if(StringUtils.isNotEmpty(name)){
|
||||
action.getName().add(name);
|
||||
}
|
||||
name = "";
|
||||
}else if(key.getType().equals(ChinesePartSpeechEnum.nt.getCode())){
|
||||
//action.setStatus(key.getKey());
|
||||
action.getLbs().add(key.getKey());
|
||||
}else if(key.getType().equals(ChinesePartSpeechEnum.t.getCode())){
|
||||
//解析时间关键字
|
||||
//action.setTime(key.getKey());
|
||||
}
|
||||
}
|
||||
if(StringUtils.isNotEmpty(name)){
|
||||
|
||||
@ -71,7 +71,7 @@ public class TuyaDeviceService {
|
||||
if (type.equalsIgnoreCase("boolean")) {
|
||||
jsonObject.put("value", Boolean.parseBoolean(data.getValue()));
|
||||
} else if (type.equalsIgnoreCase("Integer")) {
|
||||
jsonObject.put("value", Integer.parseInt(data.getValue()));
|
||||
jsonObject.put("value", Integer.parseInt(query.getValue()));
|
||||
} else if (type.equalsIgnoreCase("Enum")) {
|
||||
jsonObject.put("value", data.getValue());
|
||||
} else {
|
||||
|
||||
@ -1,13 +1,17 @@
|
||||
package com.qiuguo.iot.third.service;
|
||||
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.qiuguo.iot.base.utils.StringUtils;
|
||||
import com.qiuguo.iot.data.request.third.ThirdWeatherInfoRequest;
|
||||
import com.qiuguo.iot.data.resp.third.ThirdIpInfoResp;
|
||||
import com.qiuguo.iot.data.resp.third.ThirdRpcResp;
|
||||
import com.qiuguo.iot.data.resp.third.weather.TianqiapiResp;
|
||||
import com.qiuguo.iot.data.resp.third.weather.WeatherResp;
|
||||
import com.qiuguo.iot.third.enums.WeatherEnum;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
@ -19,8 +23,11 @@ import reactor.core.publisher.Mono;
|
||||
import reactor.util.annotation.Nullable;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
||||
|
||||
/**
|
||||
* @author simon
|
||||
* @date 2023/9/21
|
||||
@ -36,6 +43,9 @@ public class WeatherService {
|
||||
@Value("https://api.caiyunapp.com/v2.6/ilUeAnf1vNkphxYS/")
|
||||
private String queryWeatherUrl;
|
||||
|
||||
private static WebClient webClient = WebClient.builder()
|
||||
.defaultHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON_VALUE).build();
|
||||
|
||||
@Resource
|
||||
private IpService ipService;
|
||||
|
||||
@ -92,7 +102,7 @@ public class WeatherService {
|
||||
}
|
||||
|
||||
public Mono<WeatherResp> thirdQueryWeather(Mono<ThirdWeatherInfoRequest> lngLatMono, Integer queryType, Integer querySize) {
|
||||
WebClient webClient = WebClient.builder().build();
|
||||
//WebClient webClient = WebClient.builder().build();
|
||||
|
||||
return lngLatMono.flatMap(r -> {
|
||||
if (queryType.equals(WeatherEnum.QUERY_TYPE_1.getCode())) {
|
||||
@ -105,4 +115,16 @@ public class WeatherService {
|
||||
return webClient.get().uri(queryWeatherUrl).retrieve().bodyToMono(WeatherResp.class);
|
||||
});
|
||||
}
|
||||
|
||||
public Mono<TianqiapiResp> tianqiApi(ThirdWeatherInfoRequest req){
|
||||
//WebClient webClient = WebClient.builder().build();
|
||||
String url = SpringUtil.getProperty("tianqiapi.url");
|
||||
if(StringUtils.isNotEmpty(req.getIp())){
|
||||
url += "&ip=" + req.getIp();
|
||||
}else{
|
||||
url += "&city=" + req.getCity();
|
||||
}
|
||||
return webClient.get().uri(url).retrieve()
|
||||
.bodyToMono(TianqiapiResp.class);
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,21 +20,12 @@
|
||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.protobuf</groupId>
|
||||
<artifactId>protobuf-java</artifactId>
|
||||
<version>3.11.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.projectreactor</groupId>
|
||||
<artifactId>reactor-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-util</artifactId>
|
||||
<version>9.4.9.v20180320</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hswebframework.web</groupId>
|
||||
<artifactId>hsweb-commons-crud</artifactId>
|
||||
@ -43,6 +34,26 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- 基礎通用功能 -->
|
||||
<dependency>
|
||||
<groupId>org.hswebframework.web</groupId>
|
||||
<artifactId>hsweb-commons-crud</artifactId>
|
||||
<version>${hswebframework.version}</version>
|
||||
</dependency>
|
||||
<!-- 權限控制 -->
|
||||
<dependency>
|
||||
<groupId>org.hswebframework.web</groupId>
|
||||
<artifactId>hsweb-system-authorization-default</artifactId>
|
||||
<version>${hswebframework.version}</version>
|
||||
|
||||
</dependency>
|
||||
<!-- 模塊啓動器 -->
|
||||
<dependency>
|
||||
<groupId>org.hswebframework.web</groupId>
|
||||
<artifactId>hsweb-starter</artifactId>
|
||||
<version>${hswebframework.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/cn.hutool/hutool-all -->
|
||||
|
||||
@ -6,6 +6,11 @@ import com.qiuguo.iot.box.websocket.api.domain.box.resp.BoxMessageResp;
|
||||
import com.qiuguo.iot.box.websocket.api.domain.user.UserSession;
|
||||
import com.qiuguo.iot.box.websocket.api.handler.BoxWebSocketHandler;
|
||||
import com.qiuguo.iot.box.websocket.api.handler.CustomerWebSocketHandler;
|
||||
import com.qiuguo.iot.data.service.system.SystemTalkAnswerConfigService;
|
||||
import com.qiuguo.iot.data.service.system.SystemTalkBindDeviceService;
|
||||
import com.qiuguo.iot.third.nlp.Nlp;
|
||||
import com.qiuguo.iot.third.service.LacNlpService;
|
||||
import com.qiuguo.iot.third.service.NlpService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@ -22,6 +27,12 @@ public class WebsocketController {
|
||||
BoxWebSocketHandler boxWebSocketHandler;
|
||||
@Autowired
|
||||
CustomerWebSocketHandler customerWebSocketHandler;
|
||||
|
||||
@Autowired
|
||||
LacNlpService lacNlpService;
|
||||
|
||||
@Autowired
|
||||
SystemTalkAnswerConfigService systemTalkAnswerConfigService;
|
||||
@GetMapping("/push/message")
|
||||
public Mono<String> pushMessage(@RequestParam String message, @RequestParam String id, @RequestParam Integer type) {
|
||||
|
||||
@ -50,4 +61,17 @@ public class WebsocketController {
|
||||
return Mono.just("用户未上线");
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/init/sysTalkAnswer")
|
||||
public Mono<String> sysTalkAnswer() {
|
||||
|
||||
systemTalkAnswerConfigService.initGroup();
|
||||
return Mono.just("重新读取指令完成");
|
||||
}
|
||||
|
||||
@GetMapping("/test/nlp")
|
||||
public Mono<Nlp> nlp(@RequestParam String value) {
|
||||
|
||||
return lacNlpService.geSingletNlp(value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,5 +10,7 @@ public class BaseSession {
|
||||
protected WebSocketSession session;
|
||||
protected FluxSink<WebSocketMessage> sink;
|
||||
|
||||
protected String logId;
|
||||
protected String logId;//当前请求日志ID
|
||||
|
||||
protected String customerIP;//客户端IP
|
||||
}
|
||||
|
||||
@ -9,11 +9,13 @@ import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.io.buffer.DataBufferFactory;
|
||||
import org.springframework.core.io.buffer.DataBufferUtils;
|
||||
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequestDecorator;
|
||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||
import org.springframework.http.server.reactive.ServerHttpResponseDecorator;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.WebFilter;
|
||||
import org.springframework.web.server.WebFilterChain;
|
||||
@ -22,6 +24,8 @@ import reactor.core.publisher.Mono;
|
||||
import reactor.util.context.Context;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -32,6 +36,8 @@ import java.nio.charset.StandardCharsets;
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class LogWebFilter implements WebFilter {
|
||||
String customerIp = "";
|
||||
public static String HEAD_IP = "customerIP";
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
@ -39,12 +45,12 @@ public class LogWebFilter implements WebFilter {
|
||||
String requestId = request.getId();
|
||||
MDC.put(LogMdcConfiguration.PRINT_LOG_ID, requestId);
|
||||
|
||||
String ip = request.getRemoteAddress().getAddress().getHostAddress();//.getHostName();
|
||||
customerIp = request.getRemoteAddress().getAddress().getHostAddress();//.getHostName();
|
||||
String m = request.getMethod().toString();
|
||||
|
||||
log.info("api start time:{} ip:{} method:{} url:{} param:{} headers:{}",
|
||||
startTime,
|
||||
ip,
|
||||
customerIp,
|
||||
m,
|
||||
request.getPath(),
|
||||
request.getQueryParams(),
|
||||
@ -54,9 +60,9 @@ public class LogWebFilter implements WebFilter {
|
||||
|
||||
ex.response(getResponse(exchange, requestId));
|
||||
|
||||
if(!request.getMethod().equals(HttpMethod.GET) && !request.getMethod().equals(HttpMethod.DELETE)){
|
||||
ex.request(getRequest(exchange));
|
||||
}
|
||||
// if(!request.getMethod().equals(HttpMethod.GET) && !request.getMethod().equals(HttpMethod.DELETE)){
|
||||
ex.request(getRequest(exchange));
|
||||
|
||||
return chain.filter(ex.build())
|
||||
.contextWrite(context -> {
|
||||
Context contextTmp = context.put(LogMdcConfiguration.PRINT_LOG_ID, requestId);
|
||||
@ -73,7 +79,7 @@ public class LogWebFilter implements WebFilter {
|
||||
|
||||
private ServerHttpRequest getRequest(ServerWebExchange exchange){
|
||||
ServerHttpRequest request = exchange.getRequest();
|
||||
return new ServerHttpRequestDecorator(request){
|
||||
ServerHttpRequest newRequest = new ServerHttpRequestDecorator(request){
|
||||
@Override
|
||||
public Flux<DataBuffer> getBody() {
|
||||
Flux<DataBuffer> body = this.getDelegate().getBody();
|
||||
@ -82,7 +88,15 @@ public class LogWebFilter implements WebFilter {
|
||||
return dataBuffer;
|
||||
});
|
||||
}
|
||||
@Override
|
||||
public HttpHeaders getHeaders(){
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
httpHeaders.putAll(super.getHeaders());
|
||||
httpHeaders.set(HEAD_IP, customerIp);
|
||||
return httpHeaders;
|
||||
}
|
||||
};
|
||||
return newRequest;
|
||||
}
|
||||
|
||||
private ServerHttpResponse getResponse(ServerWebExchange exchange, String requestId){
|
||||
|
||||
@ -0,0 +1,164 @@
|
||||
package com.qiuguo.iot.box.websocket.api.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.qiuguo.iot.base.enums.WebSocketReqTypeEnum;
|
||||
import com.qiuguo.iot.base.utils.StringUtils;
|
||||
import com.qiuguo.iot.box.websocket.api.domain.BaseSession;
|
||||
import com.qiuguo.iot.box.websocket.api.domain.box.BoxSession;
|
||||
import com.qiuguo.iot.box.websocket.api.domain.box.resp.BoxMessageResp;
|
||||
import com.qiuguo.iot.data.entity.device.DeviceUserBindEntity;
|
||||
import com.qiuguo.iot.data.entity.system.SystemTalkAnswerConfigEntity;
|
||||
import com.qiuguo.iot.data.entity.system.SystemTalkBindDeviceEntity;
|
||||
import com.qiuguo.iot.data.request.device.DeviceUserBindRequest;
|
||||
import com.qiuguo.iot.data.request.system.SystemTalkBindDeviceRequest;
|
||||
import com.qiuguo.iot.data.request.third.ThirdWeatherInfoRequest;
|
||||
import com.qiuguo.iot.data.resp.third.weather.TianqiapiItemResp;
|
||||
import com.qiuguo.iot.data.resp.third.weather.WeatherResp;
|
||||
import com.qiuguo.iot.data.service.device.DeviceUserBindService;
|
||||
import com.qiuguo.iot.data.service.system.SystemAddressService;
|
||||
import com.qiuguo.iot.data.service.system.SystemTalkAnswerConfigService;
|
||||
import com.qiuguo.iot.data.service.system.SystemTalkBindDeviceService;
|
||||
import com.qiuguo.iot.third.enums.WeatherEnum;
|
||||
import com.qiuguo.iot.third.nlp.action.Action;
|
||||
import com.qiuguo.iot.third.nlp.action.Actions;
|
||||
import com.qiuguo.iot.third.query.TuyaQuery;
|
||||
import com.qiuguo.iot.third.service.NlpService;
|
||||
import com.qiuguo.iot.third.service.TuyaDeviceService;
|
||||
import com.qiuguo.iot.third.service.WeatherService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.hswebframework.web.api.crud.entity.PagerResult;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Slf4j
|
||||
public class BaseWebSocketProcess {
|
||||
|
||||
@Resource
|
||||
protected SystemTalkAnswerConfigService systemTalkAnswerConfigService;
|
||||
|
||||
@Resource
|
||||
protected DeviceUserBindService deviceUserBindService;
|
||||
|
||||
|
||||
@Autowired
|
||||
protected TuyaDeviceService tuyaDeviceService;
|
||||
|
||||
@Resource
|
||||
protected SystemTalkBindDeviceService systemTalkBindDeviceService;
|
||||
|
||||
@Autowired
|
||||
protected WeatherService weatherService;
|
||||
|
||||
@Autowired
|
||||
protected SystemAddressService systemAddressService;
|
||||
protected void processAction(Actions actions, Long userId, BaseSession baseSession) {
|
||||
//目前只处理第一条动作
|
||||
Action action = actions.getActions().get(0);
|
||||
|
||||
SystemTalkAnswerConfigEntity talkAnswerConfigEntity =
|
||||
systemTalkAnswerConfigService.getSystemTalkWithKey(action.getAction());
|
||||
log.info("匹配到自定义指令{}", talkAnswerConfigEntity);
|
||||
BoxMessageResp resp = new BoxMessageResp();
|
||||
resp.setType(talkAnswerConfigEntity.getAnswerType());
|
||||
if(talkAnswerConfigEntity.getAnswerType().equals(WebSocketReqTypeEnum.IOT.getCode())){
|
||||
String deviceName = action.getName().get(0);
|
||||
DeviceUserBindRequest deviceUserBindRequest = new DeviceUserBindRequest();
|
||||
deviceUserBindRequest.setUserId(userId);
|
||||
deviceUserBindRequest.setPageSize(2);
|
||||
deviceUserBindRequest.setBindName(deviceName);
|
||||
|
||||
//查询是否有相关设备
|
||||
deviceUserBindService.selectDeviceUserBindsByRequest(deviceUserBindRequest)
|
||||
.defaultIfEmpty(new PagerResult<>(0, null))
|
||||
.map(binds ->{
|
||||
if(binds.getTotal() == 0){
|
||||
//返回告诉没有备
|
||||
|
||||
resp.setText("未找到相关设备,无法操做!");
|
||||
baseSession.getSink().next(baseSession.getSession().textMessage(JSONObject.toJSONString(resp)));
|
||||
}else if(binds.getTotal() > 1){
|
||||
//返回告诉有多个设备,请详细说明具体说明设备
|
||||
resp.setText("您有多个相同设备,请明确说明");
|
||||
baseSession.getSink().next(baseSession.getSession().textMessage(JSONObject.toJSONString(resp)));
|
||||
}else{
|
||||
//查询是否有相关指令绑定
|
||||
DeviceUserBindEntity deviceUserBindEntity = binds.getData().get(0);
|
||||
SystemTalkBindDeviceRequest systemTalkBindDeviceRequest = new SystemTalkBindDeviceRequest();
|
||||
systemTalkBindDeviceRequest.setCategoryCode(deviceUserBindEntity.getCategoryCode());
|
||||
systemTalkBindDeviceRequest.setSystemTalkId(talkAnswerConfigEntity.getId());
|
||||
systemTalkBindDeviceService.selectSystemTalkBindDeviceByRequest(systemTalkBindDeviceRequest)
|
||||
.defaultIfEmpty(new SystemTalkBindDeviceEntity())
|
||||
.map(systemTalkBindDeviceEntity -> {
|
||||
if(systemTalkBindDeviceEntity.getId() == null){
|
||||
//通知不支持的指令
|
||||
resp.setText(deviceName + "不支持" + action.getAction() + "指令!");
|
||||
baseSession.getSink().next(baseSession.getSession().textMessage(JSONObject.toJSONString(resp)));
|
||||
}else{
|
||||
//调用涂鸦
|
||||
TuyaQuery query = new TuyaQuery();
|
||||
query.setDeviceId(deviceUserBindEntity.getOtherDeviceId());
|
||||
query.setValue(action.getStatus());
|
||||
query.setUserHandlingDeviceId(systemTalkBindDeviceEntity.getUserHandlingId());
|
||||
tuyaDeviceService.controlDevice(query).map(isOk ->{
|
||||
if(isOk){
|
||||
//通知打开灯成功
|
||||
String msg = talkAnswerConfigEntity.getAnswerValue().replaceAll("#name#", deviceName);
|
||||
if(StringUtils.isNotEmpty(action.getStatus())){
|
||||
msg.replace("#value#", action.getStatus());
|
||||
}
|
||||
resp.setText(msg);
|
||||
|
||||
log.info("执行指令");
|
||||
}else{
|
||||
//通知开灯失败;
|
||||
resp.setText(talkAnswerConfigEntity.getAnswerValueFaild().replaceAll("#name#", deviceName));
|
||||
log.info("执行指令失败");
|
||||
}
|
||||
baseSession.getSink().next(baseSession.getSession().textMessage(JSONObject.toJSONString(resp)));
|
||||
return isOk;
|
||||
}).subscribe();
|
||||
}
|
||||
return systemTalkBindDeviceEntity;
|
||||
}).subscribe();
|
||||
|
||||
}
|
||||
return Mono.empty();
|
||||
}).subscribe();
|
||||
|
||||
|
||||
}else if(talkAnswerConfigEntity.getAnswerType().equals(WebSocketReqTypeEnum.WEATHER.getCode())){
|
||||
ThirdWeatherInfoRequest req = new ThirdWeatherInfoRequest();
|
||||
//String city = "";
|
||||
if(action.getLbs() != null && action.getLbs().size() > 0){
|
||||
//根据地址查询天气
|
||||
// city = ;
|
||||
req.setCity(action.getLbs().get(action.getLbs().size() - 1));
|
||||
}else{
|
||||
//使用IP查询天气
|
||||
req.setIp("115.205.2.137");
|
||||
}
|
||||
weatherService.tianqiApi(req).map(t ->{
|
||||
log.info("查询的天气{}", JSONObject.toJSONString(t));
|
||||
TianqiapiItemResp item = null;
|
||||
if(StringUtils.isNotEmpty(action.getTime())){
|
||||
//匹配对应的日期
|
||||
}else{
|
||||
item = t.getData().get(0);
|
||||
}
|
||||
if(item != null){
|
||||
//返回给客户端播报内容
|
||||
resp.setText(t.getCity() + "天气" + item.getNarrative() + ",空气质量" + item.getAir_level()
|
||||
+ ",湿度" + item.getHumidity() + ",最高气温" + item.getTem1() + ",最低气温" + item.getTem2());
|
||||
}else{
|
||||
resp.setText(talkAnswerConfigEntity.getAnswerValueFaild());
|
||||
log.info("执行指令失败");
|
||||
}
|
||||
baseSession.getSink().next(baseSession.getSession().textMessage(JSONObject.toJSONString(resp)));
|
||||
return t;
|
||||
}).subscribe();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -4,10 +4,13 @@ import cn.hutool.crypto.digest.MD5;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.qiuguo.iot.base.annotation.WebSocketMapping;
|
||||
import com.qiuguo.iot.base.constans.RedisConstans;
|
||||
import com.qiuguo.iot.base.enums.WebSocketReqTypeEnum;
|
||||
import com.qiuguo.iot.base.utils.StringUtils;
|
||||
import com.qiuguo.iot.box.websocket.api.domain.box.BoxSession;
|
||||
import com.qiuguo.iot.box.websocket.api.domain.box.BoxTalkMessage;
|
||||
import com.qiuguo.iot.box.websocket.api.domain.box.resp.BoxMessageResp;
|
||||
import com.qiuguo.iot.box.websocket.api.filter.LogMdcConfiguration;
|
||||
import com.qiuguo.iot.box.websocket.api.filter.LogWebFilter;
|
||||
import com.qiuguo.iot.data.entity.device.DeviceInfoEntity;
|
||||
import com.qiuguo.iot.data.entity.device.DeviceUserBindEntity;
|
||||
import com.qiuguo.iot.data.entity.system.SystemTalkAnswerConfigEntity;
|
||||
@ -25,10 +28,12 @@ import com.qiuguo.iot.third.nlp.action.Action;
|
||||
import com.qiuguo.iot.third.nlp.action.Actions;
|
||||
import com.qiuguo.iot.third.query.TuyaQuery;
|
||||
import com.qiuguo.iot.third.service.NlpService;
|
||||
import com.qiuguo.iot.third.service.TuyaDeviceConnector;
|
||||
import com.qiuguo.iot.third.service.TuyaDeviceService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.hswebframework.web.api.crud.entity.PagerResult;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
|
||||
import org.springframework.data.redis.core.ReactiveValueOperations;
|
||||
@ -44,7 +49,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
@Component
|
||||
@WebSocketMapping("/websocket/box")
|
||||
@Slf4j
|
||||
public class BoxWebSocketHandler implements WebSocketHandler {
|
||||
public class BoxWebSocketHandler extends BaseWebSocketProcess implements WebSocketHandler {
|
||||
@Value("${device.checkTimeout}")
|
||||
private Boolean checkTimeout;
|
||||
@Value("${device.timeout}")
|
||||
@ -56,23 +61,11 @@ public class BoxWebSocketHandler implements WebSocketHandler {
|
||||
@Resource
|
||||
private DeviceInfoService deviceInfoService;
|
||||
|
||||
@Resource
|
||||
private SystemTalkAnswerConfigService systemTalkAnswerConfigService;
|
||||
|
||||
@Resource
|
||||
private NlpService nlpService;
|
||||
|
||||
@Resource
|
||||
private DeviceUserBindService deviceUserBindService;
|
||||
|
||||
@Resource
|
||||
private UserHandlingDeviceService userHandlingDeviceService;
|
||||
|
||||
@Resource
|
||||
private TuyaDeviceService tuyaDeviceService;
|
||||
|
||||
@Resource
|
||||
private SystemTalkBindDeviceService systemTalkBindDeviceService;
|
||||
|
||||
public static ConcurrentHashMap<String, BoxSession> group = new ConcurrentHashMap<>();
|
||||
|
||||
@ -88,6 +81,7 @@ public class BoxWebSocketHandler implements WebSocketHandler {
|
||||
log.info("设备{},请求数据已超时", sn);
|
||||
return session.close();
|
||||
}
|
||||
String ip = headers.get(LogWebFilter.HEAD_IP).get(0);
|
||||
String signature = headers.get("signature").get(0);
|
||||
Long userId = Long.parseLong(headers.get("userId").get(0));
|
||||
|
||||
@ -103,23 +97,25 @@ public class BoxWebSocketHandler implements WebSocketHandler {
|
||||
log.info("设备端收到消息:{}", text);
|
||||
BoxTalkMessage boxTalkMessage = JSONObject.parseObject(text, BoxTalkMessage.class);
|
||||
nlpService.getActionWithLacSingle(boxTalkMessage.getMessage()).defaultIfEmpty(new Actions()).map(actions -> {
|
||||
BoxSession boxSession = getBoxSessionWithSn(boxTalkMessage.getSn());
|
||||
//处理
|
||||
if(actions.getActions() == null || actions.getActions().size() == 0){
|
||||
//调用千问回答
|
||||
log.info("未匹配到自定义命令,调用千问");
|
||||
}else{
|
||||
processAction(actions, userId);
|
||||
processAction(actions, userId, boxSession);
|
||||
}
|
||||
|
||||
return Mono.empty();
|
||||
}).subscribe();
|
||||
|
||||
log.info("收到SN:{},消息{}", boxTalkMessage.getSn(), boxTalkMessage.getMessage());
|
||||
log.info("收到SN:{},消息:{}", boxTalkMessage.getSn(), boxTalkMessage.getMessage());
|
||||
//MDC.remove(LogMdcConfiguration.PRINT_LOG_ID);
|
||||
return Mono.empty();
|
||||
}).then();
|
||||
BoxSession boxSession = new BoxSession();
|
||||
boxSession.setSn(sn);
|
||||
boxSession.setCustomerIP(ip);
|
||||
boxSession.setSession(session);
|
||||
boxSession.setLogId(MDC.get(LogMdcConfiguration.PRINT_LOG_ID));
|
||||
group.put(sn, boxSession);
|
||||
@ -136,59 +132,7 @@ public class BoxWebSocketHandler implements WebSocketHandler {
|
||||
}).then();
|
||||
}
|
||||
|
||||
private void processAction(Actions actions, Long userId) {
|
||||
//目前只处理第一条动作
|
||||
Action action = actions.getActions().get(0);
|
||||
SystemTalkAnswerConfigEntity talkAnswerConfigEntity =
|
||||
systemTalkAnswerConfigService.getSystemTalkWithKey(action.getAction());
|
||||
DeviceUserBindRequest deviceUserBindRequest = new DeviceUserBindRequest();
|
||||
deviceUserBindRequest.setUserId(userId);
|
||||
deviceUserBindRequest.setPageSize(2);
|
||||
deviceUserBindRequest.setBindName(action.getName().get(0));
|
||||
//查询是否有相关设备
|
||||
deviceUserBindService.selectDeviceUserBindsByRequest(deviceUserBindRequest)
|
||||
.defaultIfEmpty(new PagerResult<>(0, null))
|
||||
.map(binds ->{
|
||||
if(binds.getTotal() == 0){
|
||||
//返回告诉没有备
|
||||
}else if(binds.getTotal() > 1){
|
||||
//返回告诉有多个设备,请详细说明具体说明设备
|
||||
}else{
|
||||
//查询是否有相关指令绑定
|
||||
DeviceUserBindEntity deviceUserBindEntity = binds.getData().get(0);
|
||||
SystemTalkBindDeviceRequest systemTalkBindDeviceRequest = new SystemTalkBindDeviceRequest();
|
||||
systemTalkBindDeviceRequest.setCategoryCode(deviceUserBindEntity.getCategoryCode());
|
||||
systemTalkBindDeviceRequest.setSystemTalkId(talkAnswerConfigEntity.getId());
|
||||
systemTalkBindDeviceService.selectSystemTalkBindDeviceByRequest(systemTalkBindDeviceRequest)
|
||||
.defaultIfEmpty(new SystemTalkBindDeviceEntity())
|
||||
.map(systemTalkBindDeviceEntity -> {
|
||||
if(systemTalkBindDeviceEntity.getId() == null){
|
||||
//通知不支持的指令
|
||||
}else{
|
||||
//调用涂鸦
|
||||
TuyaQuery query = new TuyaQuery();
|
||||
query.setDeviceId(deviceUserBindEntity.getOtherDeviceId());
|
||||
query.setUserHandlingDeviceId(systemTalkBindDeviceEntity.getUserHandlingId());
|
||||
tuyaDeviceService.controlDevice(query).map(isOk ->{
|
||||
if(isOk){
|
||||
//通知打开灯成功
|
||||
log.info("执行指令");
|
||||
}else{
|
||||
//通知开灯失败
|
||||
log.info("执行指令失败");
|
||||
}
|
||||
return isOk;
|
||||
}).subscribe();
|
||||
}
|
||||
return systemTalkBindDeviceEntity;
|
||||
}).subscribe();
|
||||
|
||||
}
|
||||
return Mono.empty();
|
||||
}).subscribe();
|
||||
|
||||
log.info("匹配到自定义指令{}", talkAnswerConfigEntity);
|
||||
}
|
||||
|
||||
private void checkToken(String sn, Long linkTime, String signature, Long userId){
|
||||
ReactiveValueOperations<String, String> operations = reactiveStringRedisTemplate.opsForValue();
|
||||
|
||||
@ -3,10 +3,14 @@ package com.qiuguo.iot.box.websocket.api.handler;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.qiuguo.iot.base.annotation.WebSocketMapping;
|
||||
import com.qiuguo.iot.base.constans.RedisConstans;
|
||||
import com.qiuguo.iot.box.websocket.api.domain.box.BoxSession;
|
||||
import com.qiuguo.iot.box.websocket.api.domain.box.BoxTalkMessage;
|
||||
import com.qiuguo.iot.box.websocket.api.domain.user.UserSession;
|
||||
import com.qiuguo.iot.box.websocket.api.domain.user.UserTalkMessage;
|
||||
import com.qiuguo.iot.box.websocket.api.filter.LogMdcConfiguration;
|
||||
import com.qiuguo.iot.box.websocket.api.filter.LogWebFilter;
|
||||
import com.qiuguo.iot.third.nlp.action.Actions;
|
||||
import com.qiuguo.iot.third.service.NlpService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@ -27,7 +31,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
@Component
|
||||
@WebSocketMapping("/websocket/customer")
|
||||
@Slf4j
|
||||
public class CustomerWebSocketHandler implements WebSocketHandler {
|
||||
public class CustomerWebSocketHandler extends BaseWebSocketProcess implements WebSocketHandler {
|
||||
@Value("${device.checkTimeout}")
|
||||
private Boolean checkTimeout;
|
||||
@Value("${device.timeout}")
|
||||
@ -37,6 +41,9 @@ public class CustomerWebSocketHandler implements WebSocketHandler {
|
||||
|
||||
@Resource
|
||||
private ReactiveStringRedisTemplate reactiveStringRedisTemplate;
|
||||
|
||||
@Resource
|
||||
private NlpService nlpService;
|
||||
@Override
|
||||
public Mono<Void> handle(WebSocketSession session) {
|
||||
HandshakeInfo handshakeInfo = session.getHandshakeInfo();
|
||||
@ -50,7 +57,7 @@ public class CustomerWebSocketHandler implements WebSocketHandler {
|
||||
log.info("用户{},请求数据已超时", userId);
|
||||
return session.close();
|
||||
}
|
||||
|
||||
String ip = headers.get(LogWebFilter.HEAD_IP).get(0);
|
||||
ReactiveValueOperations<String, String> operations = reactiveStringRedisTemplate.opsForValue();
|
||||
operations.get(RedisConstans.DEVICE_INFO + userId).defaultIfEmpty("ba2ef9fd8a70a6ac72c38aa6a46be4f6").flatMap(s -> {
|
||||
if(com.qiuguo.iot.base.utils.StringUtils.isNotBlank(s)){
|
||||
@ -72,13 +79,26 @@ public class CustomerWebSocketHandler implements WebSocketHandler {
|
||||
String text = webSocketMessage.getPayloadAsText();
|
||||
log.info("收到用户消息:{}", text);
|
||||
UserTalkMessage userTalkMessage = JSONObject.parseObject(text, UserTalkMessage.class);
|
||||
log.info("收到用户userId:{},消息{}", userTalkMessage.getUserId(), userTalkMessage.getMessage());
|
||||
nlpService.getActionWithLacSingle(userTalkMessage.getMessage()).defaultIfEmpty(new Actions()).map(actions -> {
|
||||
UserSession userSession = getUserSessionWithUserId(userTalkMessage.getUserId());
|
||||
//处理
|
||||
if(actions.getActions() == null || actions.getActions().size() == 0){
|
||||
//调用千问回答
|
||||
log.info("未匹配到自定义命令,调用千问");
|
||||
}else{
|
||||
processAction(actions, userId, userSession);
|
||||
}
|
||||
|
||||
return Mono.empty();
|
||||
}).subscribe();
|
||||
log.info("收到用户userId:{},消息:{}", userTalkMessage.getUserId(), userTalkMessage.getMessage());
|
||||
//MDC.remove(LogMdcConfiguration.PRINT_LOG_ID);
|
||||
return Mono.empty();
|
||||
}).then();
|
||||
UserSession userSession = new UserSession();
|
||||
userSession.setUserId(userId);
|
||||
userSession.setSession(session);
|
||||
userSession.setCustomerIP(ip);
|
||||
userSession.setLogId(MDC.get(LogMdcConfiguration.PRINT_LOG_ID));
|
||||
group.put(userId, userSession);
|
||||
Mono<Void> output = session.send(Flux.create(sink -> userSession.setSink(sink))).then();
|
||||
|
||||
@ -34,4 +34,6 @@ spring:
|
||||
host: 192.168.8.146
|
||||
port: 32030
|
||||
password: 123456
|
||||
timeout: 5000
|
||||
timeout: 5000
|
||||
tianqiapi:
|
||||
url: https://v0.yiketianqi.com/api?unescape=1&version=v91&appid=23293151&appsecret=Lj6ZMcqn&ext=life
|
||||
@ -82,7 +82,7 @@ public class MysqlMain {
|
||||
}
|
||||
List<TablesBean> list = new ArrayList<>();
|
||||
|
||||
list.add(new TablesBean("system_talk_bind_device"));
|
||||
list.add(new TablesBean("system_address"));
|
||||
//list.add(new TablesBean("user_room"));
|
||||
|
||||
List<TablesBean> list2 = new ArrayList<TablesBean>();
|
||||
|
||||
@ -1,88 +0,0 @@
|
||||
package com.admin.service.impl;
|
||||
|
||||
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import java.util.Date;
|
||||
/**
|
||||
* <p>
|
||||
* 自定义命令和设备动作绑定Controller类
|
||||
* </p>
|
||||
*
|
||||
* @author wulin
|
||||
* @since 2023-09-25
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequestMapping("/SystemTalkBindDevice")
|
||||
public class SystemTalkBindDeviceController{
|
||||
|
||||
|
||||
@Autowired
|
||||
private SystemTalkBindDeviceService systemTalkBindDeviceService;
|
||||
@PostMapping("/info")
|
||||
public Mono<SystemTalkBindDeviceResp> selectSystemTalkBindDeviceByRequest(@RequestBody SystemTalkBindDeviceRequest request){
|
||||
return systemTalkBindDeviceService.selectSystemTalkBindDeviceByRequest(request).map(d -> {return new SystemTalkBindDeviceResp(d);});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/list")
|
||||
public Mono<PagerResult<SystemTalkBindDeviceResp>> selectSystemTalkBindDevicesByRequest(@RequestBody SystemTalkBindDeviceRequest request){
|
||||
return systemTalkBindDeviceService.selectDeviceInfosByRequest(request).map(d -> {
|
||||
PagerResult<SystemTalkBindDeviceResp> result = new PagerResult<>();
|
||||
result.setPageIndex(d.getPageIndex());
|
||||
result.setPageSize(d.getPageSize());
|
||||
result.setTotal(d.getTotal());
|
||||
List<SystemTalkBindDeviceResp> ds = d.getData().stream().map(new Function<SystemTalkBindDeviceEntity, SystemTalkBindDeviceResp>() {
|
||||
@Override
|
||||
public DeviceInfoResp apply(SystemTalkBindDeviceEntity entity) {
|
||||
return new SystemTalkBindDeviceResp(entity);
|
||||
}
|
||||
}
|
||||
|
||||
).collect(Collectors.toList());
|
||||
result.setData(ds);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GetMapping("/id")
|
||||
public Mono<SystemTalkBindDeviceResp> selectSystemTalkBindDeviceById(@RequestParam Long id){
|
||||
return systemTalkBindDeviceService.selectSystemTalkBindDeviceById(id).map(d -> {return new SystemTalkBindDeviceResp(d);});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/save")
|
||||
public Mono<Integer> insertSystemTalkBindDevice(@RequestBody SystemTalkBindDeviceEntity entity){
|
||||
return systemTalkBindDeviceService.insertSystemTalkBindDevice(entity);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/update")
|
||||
public Mono<Integer> updateSystemTalkBindDeviceById(@RequestBody SystemTalkBindDeviceEntity entity){
|
||||
return systemTalkBindDeviceService.updateSystemTalkBindDeviceById(entity);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/updateCover")
|
||||
public Mono<Integer> updateCoverSystemTalkBindDeviceById(@RequestBody SystemTalkBindDeviceEntity entity){
|
||||
return systemTalkBindDeviceService.updateCoverSystemTalkBindDeviceById(entity);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Mono<Integer> deleteSystemTalkBindDeviceById(@RequestParam Long id){
|
||||
return systemTalkBindDeviceService.deleteSystemTalkBindDeviceById(id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user