Browse Source

新增:

1、新增航信调用相关文件。
tags/B.2.5.4_20231228_base
10710 2 years ago
parent
commit
d2ee23d052
7 changed files with 249 additions and 3 deletions
  1. +16
    -0
      xueyi-api/xueyi-api-system/src/main/java/com/xueyi/system/api/interfaces/airport/domain/vo/PlaneMessageVo.java
  2. +18
    -0
      xueyi-api/xueyi-api-system/src/main/java/com/xueyi/system/api/interfaces/airport/feign/RemotePlaneController.java
  3. +24
    -0
      xueyi-api/xueyi-api-system/src/main/java/com/xueyi/system/api/interfaces/airport/feign/factory/RemotePlaneFallbackFactory.java
  4. +1
    -0
      xueyi-api/xueyi-api-system/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
  5. +2
    -1
      xueyi-common/xueyi-common-core/src/main/java/com/xueyi/common/core/constant/digitalman/SkillConstants.java
  6. +24
    -2
      xueyi-modules/xueyi-nlt/src/main/java/com/xueyi/nlt/nlt/controller/DmIntentController.java
  7. +164
    -0
      xueyi-modules/xueyi-nlt/src/main/java/com/xueyi/nlt/nlt/template/FlightMessageTemplate.java

+ 16
- 0
xueyi-api/xueyi-api-system/src/main/java/com/xueyi/system/api/interfaces/airport/domain/vo/PlaneMessageVo.java View File

@@ -0,0 +1,16 @@
package com.xueyi.system.api.interfaces.airport.domain.vo;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;

@Data
@NoArgsConstructor
public class PlaneMessageVo {
@Serial
private static final long serialVersionUID = 1L;

private String fNum;
private String date;
}

+ 18
- 0
xueyi-api/xueyi-api-system/src/main/java/com/xueyi/system/api/interfaces/airport/feign/RemotePlaneController.java View File

@@ -0,0 +1,18 @@
package com.xueyi.system.api.interfaces.airport.feign;

import com.alibaba.fastjson2.JSONObject;
import com.xueyi.common.core.constant.basic.ServiceConstants;
import com.xueyi.system.api.interfaces.airport.domain.vo.PlaneMessageVo;
import com.xueyi.system.api.interfaces.airport.feign.factory.RemotePlaneFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;

@FeignClient(contextId = "remotePlaneController", value = ServiceConstants.SYSTEM_SERVICE, fallbackFactory = RemotePlaneFallbackFactory.class)
public interface RemotePlaneController {

@PostMapping("/plane/api/query-flight")
public JSONObject queryFlight(@RequestBody(required = true)PlaneMessageVo planeMessageVo,
@RequestHeader("ts") String timestamp, @RequestHeader("sign") String sign);
}

+ 24
- 0
xueyi-api/xueyi-api-system/src/main/java/com/xueyi/system/api/interfaces/airport/feign/factory/RemotePlaneFallbackFactory.java View File

@@ -0,0 +1,24 @@
package com.xueyi.system.api.interfaces.airport.feign.factory;

import com.alibaba.fastjson2.JSONObject;
import com.xueyi.common.core.web.result.R;
import com.xueyi.system.api.interfaces.airport.domain.vo.PlaneMessageVo;
import com.xueyi.system.api.interfaces.airport.feign.RemotePlaneController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class RemotePlaneFallbackFactory implements FallbackFactory<RemotePlaneController> {
@Override
public RemotePlaneController create(Throwable throwable) {
log.error("航信服务调用失败:{}", throwable.getMessage());
return new RemotePlaneController() {
@Override
public JSONObject queryFlight(PlaneMessageVo planeMessageVo,String timeStamp, String sign){
return R.fail("航班信息服务调用失败:" + throwable.getMessage()).toJson();
}
};
}
}

+ 1
- 0
xueyi-api/xueyi-api-system/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports View File

@@ -9,3 +9,4 @@ com.xueyi.system.api.dict.feign.factory.RemoteConfigFallbackFactory
com.xueyi.system.api.log.feign.factory.RemoteLogFallbackFactory
com.xueyi.system.api.meeting.feign.factory.RemoteMeetingFallbackFactory
com.xueyi.system.api.resource.feign.factory.RemoteH5ConfigFallbackFactory
com.xueyi.system.api.interfaces.airport.feign.factory.RemotePlaneFallbackFactory

+ 2
- 1
xueyi-common/xueyi-common-core/src/main/java/com/xueyi/common/core/constant/digitalman/SkillConstants.java View File

@@ -21,7 +21,8 @@ public class SkillConstants {
INTRODUCE_STRANGER("24", "熟人介绍生人"),
BROADCAST_DISPLAY("25", "播报展示"),
OPEN_DOOR("26", "开门"),
DELIVERY("33", "寄快递");
DELIVERY("33", "寄快递"),
FLIGHT("34", "航班信息");

private final String code;
private final String info;


+ 24
- 2
xueyi-modules/xueyi-nlt/src/main/java/com/xueyi/nlt/nlt/controller/DmIntentController.java View File

@@ -49,6 +49,8 @@ import com.xueyi.system.api.digitalmans.feign.RemoteDigitalmanService;
import com.xueyi.system.api.digitalmans.feign.RemoteManDeviceService;
import com.xueyi.system.api.digitalmans.feign.RemoteQuestionanswersService;
import com.xueyi.system.api.digitalmans.feign.RemoteSkillService;
import com.xueyi.system.api.interfaces.airport.domain.vo.PlaneMessageVo;
import com.xueyi.system.api.interfaces.airport.feign.RemotePlaneController;
import com.xueyi.system.api.model.Source;
import com.xueyi.system.api.organize.domain.dto.SysEnterpriseDto;
import com.xueyi.system.api.organize.feign.RemoteEnterpriseService;
@@ -57,6 +59,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.util.DigestUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
@@ -67,10 +70,11 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
@@ -153,6 +157,9 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt

@Autowired
private DmRegularMapper regularMapper;

@Autowired
private FlightMessageTemplate flightMessageTemplate;
/**
* 意图请求
列表
@@ -224,6 +231,12 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt
response.setSkillCode("33");
response.setH5(deliveryOrderTemplate.handle(intent.getDevId(),intent.getContent(), enterpriseId));
return AjaxResult.success(response);
case "flight":
response.setMsg("");
response.setSkillCode("34");
response.setH5(flightMessageTemplate.handle(intent.getDevId(),intent.getContent(), enterpriseId));
return AjaxResult.success(response);

}
}

@@ -479,6 +492,9 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt
redisTemplate.opsForValue().increment("dashboard:delivery", 1);
pushIntoDashboardRedis(enterpriseName, "寄快递", "skill");
}
}else if (SkillType.FLIGHT.getCode().equals(intent.getSkillCode()) ) {
redisTemplate.opsForValue().increment("dashboard:flight", 1);
pushIntoDashboardRedis(enterpriseName, "查询航班信息", "skill");
}
// 判断是否有权限
R<List<DmSkillDto>> skilllistInner = remoteskillService.skilllistInner(intent.getDevId(),"1",Long.parseLong(enterpriseId), source.getMaster(), SecurityConstants.INNER);
@@ -505,6 +521,9 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt
// 做快递预约处理
response.setH5(deliveryOrderTemplate.handle(intent.getDevId(), intent.getContent(), Long.parseLong(SecurityContextHolder.getLocalMap().get("enterprise_id").toString())));
break;
case "34":
// 做查询航班信息处理
response.setH5(flightMessageTemplate.handle(intent.getDevId(), intent.getContent(), Long.parseLong(SecurityContextHolder.getLocalMap().get("enterprise_id").toString())));
default:
break;
}
@@ -773,18 +792,20 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt
return matcher.find();
}

private DmIntentResponse doMatchRegular(DmIntentVo intent) {
private DmIntentResponse doMatchRegular(DmIntentVo intent){
DmIntentResponse response = new DmIntentResponse();

List <DmRegularPo> regularPos = regularMapper.selectList(null);


boolean flag = false;
for (DmRegularPo regularPo : regularPos) {
if (isMatchRegular(intent.getContent(), regularPo.getExpression())) {
response.setMsg(regularPo.getText());
response.setSkillCode(regularPo.getSkillCode());
response.setAction(regularPo.getAction());
response.setH5(regularPo.getJson());
flag = true;
break;
}
}
@@ -822,6 +843,7 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt
return response;
}


interface Auth {
/** 系统 - 意图管理
管理 - 列表 */


+ 164
- 0
xueyi-modules/xueyi-nlt/src/main/java/com/xueyi/nlt/nlt/template/FlightMessageTemplate.java View File

@@ -0,0 +1,164 @@
package com.xueyi.nlt.nlt.template;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.xueyi.common.core.constant.digitalman.SkillConstants;
import com.xueyi.nlt.api.nlt.domain.vo.CoversationSessionVo;
import com.xueyi.system.api.interfaces.airport.domain.vo.PlaneMessageVo;
import com.xueyi.system.api.interfaces.airport.feign.RemotePlaneController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Service("flight-message")
public class FlightMessageTemplate implements BaseTemplate{

private static final Logger log = LoggerFactory.getLogger(FlightMessageTemplate.class);

@Autowired
private RedisTemplate<Object,Object> objectRedisTemplate;

@Autowired
private RemotePlaneController remotePlaneController;


private void init(){
log.info("航信服务已启动。");
}
@Override
public JSONObject handle(String dev, String content) {
return null;
}

@Override
public JSONObject handle(String devId, String content, Long tenantId) {

CoversationSessionVo session = (CoversationSessionVo) objectRedisTemplate.opsForValue().get("group:device" + ":" + devId + ":" +"session");
boolean flag = true;
if (session == null) {
session = new CoversationSessionVo();
session.setCategory("flight");
JSONObject data = new JSONObject();
session.setFormat(new JSONObject());
session.getFormat().put("skillCode", SkillConstants.SkillType.FLIGHT.getCode());
session.getFormat().put("errorTime", 0);
flag = false;
}
JSONObject result;
content = content.replace("-", "").replace(" ", "").replace("$", "").toUpperCase();
Pattern pattern = Pattern.compile("([A-Z]{2}|\\d[A-Z]|[A-Z]\\d)\\d{4}");
Matcher matcher = pattern.matcher(content);
if(matcher.find()){
String fNum = matcher.group();
result = checkFlight(fNum, 0);
if(result.isEmpty()){
result = checkFlight(fNum, 1);
if(result.isEmpty()){
result = new JSONObject();
result.put("status", -1);
result.put("skillCode", "34");
session.getFormat().put("errorTime", session.getFormat().getInteger("errorTime") + 1);
}else{
session.getFormat().put("errorTime", 0);
}
}
}else{
if(flag){
result = new JSONObject();
result.put("status", -2);
result.put("skillCode", "34");
session.getFormat().put("errorTime", session.getFormat().getInteger("errorTime") + 1);
}else{
result = new JSONObject();
result.put("status", 0);
result.put("skillCode", "34");
}
}

if(session.getFormat().getInteger("errorTime") > 5){
objectRedisTemplate.delete("group:device" + ":" + devId + ":" +"session");
}else{
objectRedisTemplate.opsForValue().set("group:device" + ":" + devId + ":" +"session", session, 1, TimeUnit.MINUTES);
}
return result;
}

private JSONObject checkFlight(String fNum, Integer days) {
Long timestamp = System.currentTimeMillis();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
String date = dateFormat.format(timestamp + days * 1000 * 60 * 60 * 24);
String singStr = date + fNum + timestamp;
String sign = DigestUtils.md5DigestAsHex(singStr.getBytes());
PlaneMessageVo planeMessageVo = new PlaneMessageVo();
planeMessageVo.setFNum(fNum);
planeMessageVo.setDate(date);
JSONObject result = new JSONObject();
JSONObject flightMessage = remotePlaneController.queryFlight(planeMessageVo, String.valueOf(timestamp), sign);
log.info(flightMessage.toString());
if (flightMessage.containsKey("reason") &&
flightMessage.getString("reason").equals("success")) {
JSONObject fullFlight = flightMessage.getJSONArray("result").getJSONObject(0);
SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date dateNow = new Date(System.currentTimeMillis());
try{
if(dateNow.after(formatter.parse(fullFlight.getString("FlightDeptimePlanDate")))){
return new JSONObject();
}
} catch (ParseException e) {
log.error(e.toString());
return new JSONObject();
}

result.put("stopFlag", fullFlight.getInteger("StopFlag"));
result.put("flightNo", fullFlight.getString("FlightNo"));
result.put("flightCompany", fullFlight.getString("FlightCompany"));
JSONArray nowFlights = flightMessage.getJSONArray("result");
JSONArray flights = new JSONArray();
for (int i = 0; i < nowFlights.size(); i++) {
JSONObject nowFlight = nowFlights.getJSONObject(i);
if (nowFlight.getString("StopFlag").equals("0")) {
JSONObject newFlight = new JSONObject();
newFlight.put("Dep", nowFlight.getString("FlightDep"));
newFlight.put("Arr", nowFlight.getString("FlightArr"));
newFlight.put("DepTime", nowFlight.getString("FlightDeptimePlanDate"));
newFlight.put("ArrTime", nowFlight.getString("FlightArrtimePlanDate"));
flights.add(newFlight);
}
}
result.put("flights", flights);
List<String> transit = new ArrayList<>();
for (int i = 1; i < flights.size(); i++) {
SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date begin = simpleDateFormat2.parse(flights.getJSONObject(i - 1).getString("ArrTime"));
Date end = simpleDateFormat2.parse(flights.getJSONObject(i).getString("DepTime"));
long minutes = (end.getTime() - begin.getTime()) / (1000 * 60);
if (minutes < 60) {
transit.add(String.format("%d分钟", (int) minutes));
} else {
transit.add(String.format("%dh%dm", minutes / 60, minutes % 60));
}
} catch (ParseException e) {
log.error(e.toString());
return new JSONObject();
}
}
result.put("transit", transit);
result.put("status", 0);
result.put("skillCode", "34");
}
return result;
}
}

Loading…
Cancel
Save