Browse Source

Merge remote-tracking branch 'origin/prod-5.1.3' into prod-5.1.3

zhongwei
yang_shj 2 months ago
parent
commit
d2256bc5e3
  1. 109
      hzims-biz-common/src/main/java/com/hnac/hzims/common/utils/FileUtil.java
  2. 5
      hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/scheduled/DeviceLedgerScheduledTask.java
  3. 2
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/business/service/DataSourceService.java
  4. 16
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/interactive/service/impl/ControlAnswerResolveServiceImpl.java
  5. 2
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/zhipuai/service/impl/ZhipuAnalysisServiceImpl.java
  6. 3
      hzims-service/gglm-big-model/src/main/resources/template/template.yml
  7. 4
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/plan/controller/PlanController.java
  8. 3
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/feign/OperAccessTaskClient.java
  9. 6
      hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/feign/TicketInfoClient.java
  10. 5
      hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/service/impl/WorkTicketInfoServiceImpl.java
  11. 3
      hzims-service/ticket/src/main/resources/template/template.yml
  12. 3
      hzims-service/ticket/src/test/resources/application-test.yml

109
hzims-biz-common/src/main/java/com/hnac/hzims/common/utils/FileUtil.java

@ -11,13 +11,20 @@ import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.util.EntityUtils;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.web.multipart.MultipartFile;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLDecoder;
import java.net.URLConnection;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import java.util.UUID;
/**
* @Author: ypj
@ -43,12 +50,16 @@ public class FileUtil {
return bytes;
}
public static byte[] getUrlByte(URL url) throws IOException {
InputStream inputStream = null;
public static byte[] getUrlByte(URL url) throws IOException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
URLConnection conn = getUrlConnection(url);
conn.connect();
return getUrlByte(conn.getInputStream());
}
public static byte[] getUrlByte(InputStream inputStream) throws IOException {
ByteArrayOutputStream outputStream = null;
byte[] fileBytes = null;
try {
inputStream = url.openStream();
outputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[4096];
int bytesRead;
@ -67,80 +78,46 @@ public class FileUtil {
return fileBytes;
}
public static byte[] getUrlByte(String urlString) throws IOException {
public static byte[] getUrlByte(String urlString) throws IOException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
return getUrlByte(new URL(urlString));
}
public static String getContentTypeFromUrl(String url) {
String result = "";
String fileType = url.toLowerCase();
if (fileType.indexOf(".png") >= 0) {
result = "image/png";
} else if (fileType.indexOf(".gif") >= 0) {
result = "image/gif";
} else if (fileType.indexOf(".jpg") >= 0 || fileType.indexOf(".jpeg") >= 0) {
result = "image/jpeg";
} else if (fileType.indexOf(".svg") >= 0) {
result = "image/svg+xml";
} else if (fileType.indexOf(".doc") >= 0) {
result = "application/msword";
} else if (fileType.indexOf(".xls") >= 0) {
result = "application/x-excel";
} else if (fileType.indexOf(".zip") >= 0) {
result = "application/zip";
} else if (fileType.indexOf(".pdf") >= 0) {
result = "application/pdf";
} else if (fileType.indexOf(".mpeg") >= 0) { //MP3
result = "audio/mpeg";
} else if (fileType.indexOf(".mp4") >= 0) {
result = "video/mp4";
} else if (fileType.indexOf(".plain") >= 0) {
result = "text/plain";
} else if (fileType.indexOf(".html") >= 0) {
result = "text/html";
} else if (fileType.indexOf(".json") >= 0) {
result = "application/json";
} else {
result = "application/octet-stream";
}
return result;
public static String getUrlBase64(String urlString) throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, IOException {
return getBase64(getUrlByte(urlString));
}
public static String getPureUrl(String url) throws UnsupportedEncodingException {
String result = removeUrlParam(url);
result = URLDecoder.decode(result, "utf-8");
int index = result.lastIndexOf("http");
if (index > 0) {
result = result.substring(index);
public static URLConnection getUrlConnection(URL url) throws IOException, KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
URLConnection conn = url.openConnection();
if (url.getProtocol().equalsIgnoreCase("https")) {
SSLContext sslContext = SSLContextBuilder.create().loadTrustMaterial(null, (x509Certificate, s) -> true).build();
((HttpsURLConnection) conn).setSSLSocketFactory(sslContext.getSocketFactory());
((HttpsURLConnection) conn).setHostnameVerifier(NoopHostnameVerifier.INSTANCE);
}
return result;
((HttpURLConnection) conn).setRequestMethod("GET");
conn.setRequestProperty("User-Agent", "Mozilla/5.0");
conn.setRequestProperty("Accept", "*/*");
return conn;
}
public static String getOriginalFilename(String path) {
String result = path;
int index = path.lastIndexOf("/");
if (index > 0) {
result = path.substring(index + 1);
}
return result;
public static URLConnection getUrlConnection(String urlString) throws IOException, KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
URL url = new URL(urlString);
return getUrlConnection(url);
}
public static String removeUrlParam(String url) {
int index = url.indexOf("?");
if (index > 0) {
return url.substring(0, index);
}
return url;
}
public static ByteArrayMultipartFile getMultipartFileFromUrl(String urlStr) throws IOException {
public static ByteArrayMultipartFile getMultipartFileFromUrl(String urlStr, String fileName) {
ByteArrayMultipartFile result = null;
try {
URL url = new URL(urlStr);
byte[] bytes = getUrlByte(url);
URLConnection conn = getUrlConnection(url);
conn.connect();
byte[] bytes = getUrlByte(conn.getInputStream());
String name = url.getPath();
String originalName = getOriginalFilename(name);
String contentType = getContentTypeFromUrl(originalName);
String originalName = StringUtil.isBlank(fileName) ? UUID.randomUUID().toString() : fileName;
String contentType = conn.getContentType();
result = new ByteArrayMultipartFile(name, originalName, contentType, bytes);
} catch (Exception e) {
log.error("获取传输文件失败", e);
}
return result;
}
@ -148,11 +125,11 @@ public class FileUtil {
return Base64.getEncoder().encodeToString(bytes);
}
public static String getBase64(String filePath) throws IOException {
public static String getFileBase64(String filePath) throws IOException {
return getBase64(getFileBytes(filePath));
}
public static String getBase64(URL url) throws IOException {
public static String getUrlBase64(URL url) throws IOException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
return getBase64(getUrlByte(url));
}

5
hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/scheduled/DeviceLedgerScheduledTask.java

@ -60,7 +60,10 @@ public class DeviceLedgerScheduledTask {
// 取出数据ID 删除数据
JSONObject queryJson = JSONObject.parseObject(JSON.toJSONString(searchResult.getData()));
JSONArray data = Optional.ofNullable(queryJson).map(json -> json.getJSONObject("Get"))
.map(json -> json.getJSONArray(ScheduledConstant.DEVICE_LEDGER_CLASS_NAME)).orElse(null);
.map(jsonObject -> {
Optional<String> tableName = jsonObject.keySet().stream().filter(key -> key.contains(ScheduledConstant.DEVICE_LEDGER_CLASS_NAME)).findFirst();
return tableName.isPresent() ? jsonObject.getJSONArray(tableName.get()) : null;
}).orElse(null);
if(Func.isNotEmpty(data)) {
List<String> ids = data.stream().map(item -> {
JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(item));

2
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/business/service/DataSourceService.java

@ -53,7 +53,7 @@ public class DataSourceService {
for (TableAuthVO tableAuthVO : sqlVO.getTableAuthVOList()) {
// 查询改数据源下的表格是否存在鉴权
LambdaQueryWrapper<TablePropertyEntity> wrapper = Wrappers.<TablePropertyEntity>lambdaQuery()
.eq(TablePropertyEntity::getDatasourceId, tableAuthVO.getDatasourceName())
//.eq(TablePropertyEntity::getDatasourceId, tableAuthVO.getDatasourceName())
.eq(TablePropertyEntity::getTableName, tableAuthVO.getTableName());
List<TablePropertyEntity> propertise = tablePropertyService.list(wrapper);
Assert.isTrue(Func.isNotEmpty(propertise), () -> {

16
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/interactive/service/impl/ControlAnswerResolveServiceImpl.java

@ -8,9 +8,11 @@ import com.hnac.gglm.bigmodel.interactive.factory.AnswerResolveFactory;
import com.hnac.gglm.bigmodel.interactive.service.IAnswerResolveService;
import com.hnac.gglm.bigmodel.interactive.vo.AnswerVO;
import com.hnac.gglm.bigmodel.interactive.vo.ExtraVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.utils.Func;
import org.springblade.system.cache.ParamCache;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.hnac.gglm.bigmodel.interactive.constants.ParamKeyConstants;
@ -23,8 +25,14 @@ import java.util.Map;
*/
@Service(AnswerResolveFactory.CONTROL_DEVICE_SERVICE)
@Slf4j
@RequiredArgsConstructor
public class ControlAnswerResolveServiceImpl implements IAnswerResolveService {
@Value("${gglm.remote.initiateRobotPlan}")
private String initiateRobotPlanUrl;
@Value("${gglm.remote.initiateVideoTask}")
private String initiateVideoTaskUrl;
@Override
public AnswerVO resolve(AnswerVO answer) {
Object[] extraArray = this.extraStream(answer).map(this::getExtra).toArray();
@ -38,14 +46,14 @@ public class ControlAnswerResolveServiceImpl implements IAnswerResolveService {
JSONObject params = originExtra.getJSONObject("params");
if(Func.isNotEmpty(params) && Func.isNotEmpty(params.getString("itemId"))) {
String itemId = ParamCache.getValue(ParamKeyConstants.VIDEO_INSPECTION_CODE);
String url = ParamCache.getValue(ParamKeyConstants.VIDEO_INSPECTION_URL);
if(Func.isNotEmpty(itemId) && Func.isNotEmpty(url)
//String url = ParamCache.getValue(ParamKeyConstants.VIDEO_INSPECTION_URL);
if(Func.isNotEmpty(itemId) && Func.isNotEmpty(initiateVideoTaskUrl)
&& itemId.equals(params.getString("itemId")) && Func.isNotEmpty(params.getString("stationId"))) {
log.info("控制指令传参为:{}", JSON.toJSONString(originExtra));
String stationId = params.getString("stationId");
HashMap<String, String> param = new HashMap<>(1);
param.put("stationId",stationId);
String body = HttpRequest.post(url).body(JSON.toJSONString(param)).execute().body();
String body = HttpRequest.post(initiateVideoTaskUrl).body(JSON.toJSONString(param)).execute().body();
params.put("data",body);
log.info("识别结果为:{}", body);
ExtraVO result = originExtra.toJavaObject(ExtraVO.class);
@ -55,7 +63,7 @@ public class ControlAnswerResolveServiceImpl implements IAnswerResolveService {
HashMap<String, String> param = new HashMap<>(1);
param.put("itemName", params.getString("itemName"));
log.info("机器人巡检传参为:{}", JSON.toJSONString(param));
String body = HttpRequest.post("http://192.168.60.29:8080/api/hzinfo-inspect/plan/initiateRobotPlan").body(JSON.toJSONString(param)).execute().body();
String body = HttpRequest.post(initiateRobotPlanUrl).body(JSON.toJSONString(param)).execute().body();
log.info("结果为:{}",body);
ExtraVO result = originExtra.toJavaObject(ExtraVO.class);
result.setType(FunctionConstants.TypeEnum.PARAMS.getType());

2
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/zhipuai/service/impl/ZhipuAnalysisServiceImpl.java

@ -105,7 +105,7 @@ public class ZhipuAnalysisServiceImpl implements ZhipuAnalysisService {
throw ErrorCode.GET_FILE_CONTENT_FAILURE.throwException();
});
try {
return FileUtil.getBase64(request.getFilePath());
return FileUtil.getFileBase64(request.getFilePath());
} catch (IOException e) {
throw ErrorCode.GET_FILE_CONTENT_FAILURE.throwException();
}

3
hzims-service/gglm-big-model/src/main/resources/template/template.yml

@ -68,6 +68,9 @@ gglm:
insertVectors: "/vector/insert_vectors"
createTable: "/vector/create_table"
deleteTable: "/vector/delete_table"
remote:
initiateRobotPlan: "http://${hzims.server.ip}/api/hzinfo-inspect/plan/initiateRobotPlan"
initiateVideoTask: "http://${hzims.server.ip}/api/hzinfo-inspect/feign/ai/analysisByStationId"
swagger:
base-packages: com.hnac.hzims.bigmodel

4
hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/plan/controller/PlanController.java

@ -218,7 +218,9 @@ public class PlanController extends BladeController {
throw new HzServiceException("未获取到机器人配置!");
}
// 获取机器人巡检路线
List<RouteEntity> routeEntityList = routeService.list(Wrappers.<RouteEntity>lambdaQuery().eq(RouteEntity::getCreateDept, UserCache.getUser(robotEntity.getUserId()).getDeptId()));
List<RouteEntity> routeEntityList = routeService.list(Wrappers.<RouteEntity>lambdaQuery()
.eq(RouteEntity::getCreateDept, UserCache.getUser(robotEntity.getUserId()).getDeptId())
.eq(RouteEntity::getSupportAutoVideo, Constants.InspectTypeEnum.ROBOT.getVal()));
if(CollectionUtil.isEmpty(routeEntityList)) {
throw new HzServiceException("获取机器人巡检路线失败!");
}

3
hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/feign/OperAccessTaskClient.java

@ -131,7 +131,8 @@ public class OperAccessTaskClient implements IOperAccessTaskClient, IAccessTaskC
// 确保日期格式一致
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String formattedDate = sdf.format(task.getPlanStartTime());
String overview = String.format(overviewTemplate, task.getCreateUserName(), formattedDate, task.getEmName(), task.getActHours(), details);
Integer actHour = Optional.ofNullable(task.getActHours()).orElse(0);
String overview = String.format(overviewTemplate, task.getCreateUserName(), formattedDate, task.getEmName(), actHour, details);
return overview;
}).filter(Func::isNotEmpty).collect(Collectors.toList());
return R.data(overviewList);

6
hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/feign/TicketInfoClient.java

@ -25,6 +25,8 @@ import org.springblade.core.mp.base.BaseEntity;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.*;
import org.springblade.flow.core.feign.IFlowClient;
import org.springblade.system.user.cache.UserCache;
import org.springblade.system.user.entity.User;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
@ -37,6 +39,7 @@ import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.stream.Collectors;
@ -303,7 +306,8 @@ public class TicketInfoClient implements ITicketInfoClient {
if(Func.isNotEmpty(workTicketList)) {
List<String> overviewList = workTicketList.stream().map(workTicketInfo -> {
String startTime = workTicketInfo.getPlanStartTime().format(DateUtil.DATETIME_FORMATTER);
return String.format(overviewTemplate, workTicketInfo.getCreateUserName(), startTime, workTicketInfo.getEmName(), workTicketInfo.getWorkContent());
String createUserName = Optional.ofNullable(workTicketInfo.getCreateUser()).map(UserCache::getUser).map(User::getName).orElse("");
return String.format(overviewTemplate, createUserName, startTime, workTicketInfo.getEmName(), workTicketInfo.getWorkContent());
}).collect(Collectors.toList());
return R.data(overviewList);
}

5
hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/service/impl/WorkTicketInfoServiceImpl.java

@ -121,6 +121,9 @@ public class WorkTicketInfoServiceImpl extends ServiceImpl<WorkTicketInfoMapper,
private final IEmInfoClient emInfoClient;
private final ISysClient sysClient;
@Value("${gglm.url_summary}")
private String summaryUrl;
/**
* 生成两票编号锁
**/
@ -1353,7 +1356,7 @@ public class WorkTicketInfoServiceImpl extends ServiceImpl<WorkTicketInfoMapper,
params.put("chat_id",chatId);
params.put("q_id",queryId);
params.put("user_id",AuthUtil.getUserId().toString());
HttpRequest.post("http://192.168.60.16:9997/custom/device_ledger_summary").body(JSON.toJSONString(params)).execute();
HttpRequest.post(summaryUrl).body(JSON.toJSONString(params)).execute();
return chatId;
}
}

3
hzims-service/ticket/src/main/resources/template/template.yml

@ -116,4 +116,7 @@ ticket:
- status: 12
flowId: sid-6358A80D-F592-4875-B281-A5B14A0EA39E
segment: 工作票延期
# 大模型获取设备台账总结url
gglm:
url_summary: "http://${gglm.host}:${gglm.port}/custom/device_ledger_summary"

3
hzims-service/ticket/src/test/resources/application-test.yml

@ -75,3 +75,6 @@ hzims:
first-work-flow-key: firstWorkTicket
first-work-flow-key-new: newFirstWorkTicket
app-config-business-key: ticket_invalid
# 大模型获取设备台账总结url
gglm:
url_summary: "http://${gglm.host}:${gglm.port}/custom/device_ledger_summary"

Loading…
Cancel
Save