From 5c38593cad55879a188dd88824a2cde415b68c7a Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Thu, 22 Aug 2024 10:51:02 +0800 Subject: [PATCH 01/19] =?UTF-8?q?fix:=20=E5=90=91=E9=87=8F=E5=BA=93?= =?UTF-8?q?=E7=BB=B4=E6=8A=A4=E4=B8=B4=E6=97=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bigmodel/api/wrapper/BaseSyncWrapper.java | 21 ++++++ .../bigmodel/maintenance/entity/ControlEntity.java | 2 +- hzims-service/hzims-big-model/pom.xml | 5 ++ .../control/DataSourceExecuteController.java | 33 ---------- .../business/control/RemoteController.java | 34 ---------- .../controller/DataSourceExecuteController.java | 33 ++++++++++ .../business/controller/RemoteController.java | 34 ++++++++++ .../business/wrapper/CanvasSyncWrapper.java | 21 ++++++ .../bigmodel/configuration/WeaviateConfig.java | 20 ++++++ .../maintenance/entity/SyncPropertyEntity.java | 40 ++++++++++++ .../maintenance/service/TableColumnService.java | 6 +- .../bigmodel/zhipuai/config/ZhipuAiConfig.java | 35 ++++++++++ .../operational/station/aspect/AddVideoAspect.java | 76 ---------------------- .../station/aspect/VideoSyncAspect.java | 58 +++++++++++++++++ .../station/wrapper/VideoSyncWrapper.java | 38 +++++++++++ 15 files changed, 309 insertions(+), 147 deletions(-) create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/wrapper/BaseSyncWrapper.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/control/DataSourceExecuteController.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/control/RemoteController.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/controller/DataSourceExecuteController.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/controller/RemoteController.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/wrapper/CanvasSyncWrapper.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/WeaviateConfig.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/SyncPropertyEntity.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/aspect/AddVideoAspect.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/aspect/VideoSyncAspect.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/wrapper/VideoSyncWrapper.java diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/wrapper/BaseSyncWrapper.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/wrapper/BaseSyncWrapper.java new file mode 100644 index 0000000..4cef0d1 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/wrapper/BaseSyncWrapper.java @@ -0,0 +1,21 @@ +package com.hnac.hzims.bigmodel.api.wrapper; + +import com.hnac.hzims.bigmodel.api.dto.SyncDTO; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * @Author: huangxing + * @Date: 2024/08/20 09:23 + * @Describe 对象转换为同步对象基础类 + */ +public abstract class BaseSyncWrapper { + + public abstract S convert(O obj); + + public List listVO(List list) { + return list.stream().map(this::convert).collect(Collectors.toList()); + } + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/ControlEntity.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/ControlEntity.java index 889b04a..d2176e8 100644 --- a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/ControlEntity.java +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/ControlEntity.java @@ -26,7 +26,7 @@ public class ControlEntity extends TenantEntity implements Serializable { @ApiModelProperty(value = "itemId",required = true) private String itemId; - @ApiModelProperty(value = "站点名称",required = true) + @ApiModelProperty(value = "站点名称") @QueryField(condition = SqlCondition.LIKE) private String stationName; diff --git a/hzims-service/hzims-big-model/pom.xml b/hzims-service/hzims-big-model/pom.xml index d3624b5..61973c4 100644 --- a/hzims-service/hzims-big-model/pom.xml +++ b/hzims-service/hzims-big-model/pom.xml @@ -83,6 +83,11 @@ oapi-java-sdk release-V4-2.0.2 + + io.weaviate + client + 4.7.0 + diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/control/DataSourceExecuteController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/control/DataSourceExecuteController.java deleted file mode 100644 index 4efcf3b..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/control/DataSourceExecuteController.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.hnac.hzims.bigmodel.business.control; - -import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; -import com.hnac.hzims.bigmodel.business.service.DataSourceService; -import com.hnac.hzims.bigmodel.business.vo.SqlVO; -import io.swagger.annotations.ApiOperation; -import lombok.AllArgsConstructor; -import org.springblade.core.tool.api.R; -import org.springframework.web.bind.annotation.*; - -import javax.validation.Valid; -import java.util.List; -import java.util.Map; - -/** - * @Author: huangxing - * @Date: 2024/06/28 14:07 - */ -@RestController -@RequestMapping("/dataSource/execute") -@AllArgsConstructor -public class DataSourceExecuteController { - - private final DataSourceService dataSourceService; - - @PostMapping("/executeQuery") - @ApiOperation("执行大模型sql") - @ApiOperationSupport(order = 1) - public R>> executeQuery(@RequestBody @Valid SqlVO sqlVO) { - return R.data(dataSourceService.queryListOnSpecificDataSource(sqlVO)); - } - -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/control/RemoteController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/control/RemoteController.java deleted file mode 100644 index 3b4422c..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/control/RemoteController.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.hnac.hzims.bigmodel.business.control; - -import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; -import com.hnac.hzims.bigmodel.BigModelConstants; -import com.hnac.hzims.bigmodel.business.service.RemoteService; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.AllArgsConstructor; -import org.springblade.core.tool.api.R; -import org.springblade.system.dto.ControlDTO; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -/** - * @Author: huangxing - * @Date: 2024/06/24 14:42 - */ -@AllArgsConstructor -@RequestMapping("/remote") -@RestController -@Api(value = "数据平台遥控指令管理",tags = "数据平台遥控指令管理") -public class RemoteController { - - private final RemoteService remoteService; - - @ApiOperation("下发遥控指令") - @ApiOperationSupport(order = 1) - @PostMapping("/sendRemoteControl") - public R sendRemoteControl(ControlDTO controlDTO) { - return remoteService.sendRemoteControl(controlDTO); - } - -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/controller/DataSourceExecuteController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/controller/DataSourceExecuteController.java new file mode 100644 index 0000000..47e7cc5 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/controller/DataSourceExecuteController.java @@ -0,0 +1,33 @@ +package com.hnac.hzims.bigmodel.business.controller; + +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.hzims.bigmodel.business.service.DataSourceService; +import com.hnac.hzims.bigmodel.business.vo.SqlVO; +import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.util.List; +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/06/28 14:07 + */ +@RestController +@RequestMapping("/dataSource/execute") +@AllArgsConstructor +public class DataSourceExecuteController { + + private final DataSourceService dataSourceService; + + @PostMapping("/executeQuery") + @ApiOperation("执行大模型sql") + @ApiOperationSupport(order = 1) + public R>> executeQuery(@RequestBody @Valid SqlVO sqlVO) { + return R.data(dataSourceService.queryListOnSpecificDataSource(sqlVO)); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/controller/RemoteController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/controller/RemoteController.java new file mode 100644 index 0000000..ac0c0b3 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/controller/RemoteController.java @@ -0,0 +1,34 @@ +package com.hnac.hzims.bigmodel.business.controller; + +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.hzims.bigmodel.business.service.RemoteService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; +import org.springblade.core.tool.api.R; +import org.springblade.system.dto.ControlDTO; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Author: huangxing + * @Date: 2024/06/24 14:42 + */ +@AllArgsConstructor +@RequestMapping("/remote") +@RestController +@Api(value = "数据平台遥控指令管理",tags = "数据平台遥控指令管理") +public class RemoteController { + + private final RemoteService remoteService; + + @ApiOperation("下发遥控指令") + @ApiOperationSupport(order = 1) + @PostMapping("/sendRemoteControl") + public R sendRemoteControl(@RequestBody ControlDTO controlDTO) { + return remoteService.sendRemoteControl(controlDTO); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/wrapper/CanvasSyncWrapper.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/wrapper/CanvasSyncWrapper.java new file mode 100644 index 0000000..306e13d --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/wrapper/CanvasSyncWrapper.java @@ -0,0 +1,21 @@ +package com.hnac.hzims.bigmodel.business.wrapper; + +import com.hnac.hzims.bigmodel.api.dto.CanvasSyncDTO; +import com.hnac.hzims.bigmodel.api.wrapper.BaseSyncWrapper; +import com.hnac.hzinfo.sdk.v5.scada.vo.CanvasVO; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Component; + +/** + * @Author: huangxing + * @Date: 2024/08/20 16:49 + */ +@Component +@AllArgsConstructor +public class CanvasSyncWrapper extends BaseSyncWrapper { + + @Override + public CanvasSyncDTO convert(CanvasVO obj) { + return null; + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/WeaviateConfig.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/WeaviateConfig.java new file mode 100644 index 0000000..022663a --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/WeaviateConfig.java @@ -0,0 +1,20 @@ +package com.hnac.hzims.bigmodel.configuration; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +/** + * @Author: huangxing + * @Date: 2024/08/21 15:22 + */ +@Configuration +public class WeaviateConfig { + + @Bean + public WebClient weaviateClient() { + return WebClient.create("http://192.168.60.16:9992"); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/SyncPropertyEntity.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/SyncPropertyEntity.java new file mode 100644 index 0000000..c800041 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/SyncPropertyEntity.java @@ -0,0 +1,40 @@ +package com.hnac.hzims.bigmodel.maintenance.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.core.tenant.mp.TenantEntity; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/08/21 08:33 + */ +@Data +@EqualsAndHashCode +@ApiModel(value = "同步向量库基础配置",description = "同步向量库基础配置") +@TableName("") +public class SyncPropertyEntity extends TenantEntity implements Serializable { + + @ApiModelProperty("配置编号") + private String code; + + @ApiModelProperty("数据源") + private String datasource; + + @ApiModelProperty("数据源名称") + private String datasourceName; + + @ApiModelProperty("数据库表名") + private String tableName; + + @ApiModelProperty("向量数据库表名,由小写字母以及_组成") + private String vectorTableName; + + @ApiModelProperty("表描述") + private String tableDesc; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/TableColumnService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/TableColumnService.java index 91f04fb..b8d4fc3 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/TableColumnService.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/TableColumnService.java @@ -20,17 +20,17 @@ public class TableColumnService { private final DataSourceService dataSourceService; public List> getDatabase(String datasource) { - String sql = "select distinct `table_schema` as tableName from `information_schema`.`tables` where `table_schema` <> 'information_schema';"; + String sql = "select distinct UPPER(`table_schema`) as tableName from `information_schema`.`tables` where `table_schema` <> 'information_schema';"; return dataSourceService.queryListOnSpecificDataSource(sql,datasource); } public List> getTables(String datasource,String database) { - String sql = "select distinct `table_name` as tableName from `information_schema`.`tables` where `table_schema` = '" + database + "';"; + String sql = "select distinct UPPER(`table_name`) as tableName from `information_schema`.`tables` where `table_schema` = '" + database + "';"; return dataSourceService.queryListOnSpecificDataSource(sql,datasource); } public List> getColumns(String datasource,String database,String tableName) { - String sql = "select distinct `column_name` as columnName,`column_comment` as columnComment from `information_schema`.`COLUMNS` where `TABLE_SCHEMA` = '" + database + "' and `TABLE_NAME` = '" + tableName + "';"; + String sql = "select distinct UPPER(`column_name`) as columnName,UPPER(`column_comment`) as columnComment from `information_schema`.`COLUMNS` where `TABLE_SCHEMA` = '" + database + "' and `TABLE_NAME` = '" + tableName + "';"; return dataSourceService.queryListOnSpecificDataSource(sql,datasource); } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/config/ZhipuAiConfig.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/config/ZhipuAiConfig.java index 1c5a8b2..b28a3a5 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/config/ZhipuAiConfig.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/config/ZhipuAiConfig.java @@ -1,11 +1,22 @@ package com.hnac.hzims.bigmodel.zhipuai.config; +import com.alibaba.fastjson.JSON; import com.zhipu.oapi.ClientV4; +import io.weaviate.client.Config; +import io.weaviate.client.WeaviateAuthClient; +import io.weaviate.client.WeaviateClient; +import io.weaviate.client.base.Result; +import io.weaviate.client.v1.auth.exception.AuthException; +import io.weaviate.client.v1.data.model.WeaviateObject; +import io.weaviate.client.v1.misc.model.Meta; import lombok.AllArgsConstructor; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import java.util.HashMap; +import java.util.List; + /** * @Author: ypj * @Date: 2024/8/9 17:01 @@ -21,4 +32,28 @@ public class ZhipuAiConfig { public ClientV4 clientV4() { return new ClientV4.Builder(properties.getApiSecret()).build(); } + +// public static void main(String[] args) throws AuthException { +// Config config = new Config("http", "192.168.60.16:9992"); +// WeaviateClient client = WeaviateAuthClient.apiKey(config,"123"); +// // 新增 HZIMS_TEST +//// Result craeteTableTest = client.data().creator().withClassName("HZIMS_TEST").run(); +//// System.out.println(JSON.toJSONString(craeteTableTest)); +//// Result> searchResult = client.data().objectsGetter().withClassName("HZIMS_TEST").run(); +//// System.out.println(JSON.toJSONString(searchResult)); +// // 新增数据 +//// HashMap hashMap = new HashMap() {{ +//// put("id_", "13412423423412"); +//// put("name", "test"); +//// }}; +//// Result hzimsTest = client.data().creator().withClassName("HZIMS_TEST").withProperties(hashMap).withVector(new Float[]{}).run(); +//// System.out.println(JSON.toJSONString(hzimsTest)); +//// Result> searchResult = client.data().objectsGetter().withClassName("HZIMS_TEST").run(); +//// System.out.println(JSON.toJSONString(searchResult)); +// // 删除数据 +// Result hzimsTest = client.data().deleter().withClassName("HZIMS_TEST").withID("14c6847d-b758-475f-968d-64b0e193e43e").run(); +// System.out.println(JSON.toJSONString(hzimsTest)); +// Result> searchResult = client.data().objectsGetter().withClassName("HZIMS_TEST").run(); +// System.out.println(JSON.toJSONString(searchResult)); +// } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/aspect/AddVideoAspect.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/aspect/AddVideoAspect.java deleted file mode 100644 index 272eda4..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/aspect/AddVideoAspect.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.hnac.hzims.operational.station.aspect; - -import com.alibaba.fastjson.JSON; -import com.google.common.collect.Lists; -import com.hnac.hzims.bigmodel.api.constants.MqttTopicConstants; -import com.hnac.hzims.bigmodel.api.dto.VideoSyncDTO; -import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity; -import com.hnac.hzims.operational.station.feign.IStationClient; -import com.hnac.hzims.operational.station.service.IStationService; -import com.hnac.hzims.operational.station.vo.StationVO; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.aspectj.lang.JoinPoint; -import org.aspectj.lang.annotation.After; -import org.aspectj.lang.annotation.Aspect; -import org.aspectj.lang.annotation.Pointcut; -import org.springblade.core.tool.utils.BeanUtil; -import org.springblade.core.tool.utils.Func; -import org.springblade.mqtt.producer.IMqttSender; -import org.springframework.stereotype.Component; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - -/** - * @Author: huangxing - * @Date: 2024/08/09 14:02 - */ -@Aspect -@Component -@AllArgsConstructor -@Slf4j -public class AddVideoAspect { - - private final IStationService stationService; - private final IMqttSender mqttSender; - - @Pointcut("execution(* com.hnac.hzims.operational.station.service.IStationVideoTypeService.saveBatch(..)) " + - "|| execution(* com.hnac.hzims.operational.station.service.IStationVideoTypeService.save(..)) " + - "|| execution(* com.hnac.hzims.operational.station.service.IStationVideoTypeService.updateById(..)) " + - "|| execution(* com.hnac.hzims.operational.station.service.IStationVideoTypeService.updateBatchById(..))") - private void pointCut() { - - } - - @After("pointCut()") - public void after(JoinPoint point) { - Object[] args = point.getArgs(); - if(args.length == 1) { - Object arg = args[0]; - if(arg instanceof StationVideoTypeEntity) { - List videoSyncDTOS = Lists.newArrayList(this.convert((StationVideoTypeEntity) arg)); - mqttSender.sendToMqtt(MqttTopicConstants.TOPIC_VIDEO_INSERT, JSON.toJSONString(videoSyncDTOS)); - } - else if(arg instanceof List) { - List videoList = (List) args[0]; - List videoSyncDTOS = videoList.stream().map(this::convert).collect(Collectors.toList()); - mqttSender.sendToMqtt(MqttTopicConstants.TOPIC_VIDEO_INSERT, JSON.toJSONString(videoSyncDTOS)); - } - } - } - - private VideoSyncDTO convert(StationVideoTypeEntity entity) { - VideoSyncDTO videoSyncDTO = BeanUtil.copy(entity,VideoSyncDTO.class); - StationVO station = stationService.getStationByCode(entity.getStationId()); - String stationName = Optional.ofNullable(station).map(StationVO::getName).orElse(""); - videoSyncDTO.setId(String.valueOf(entity.getId())); - videoSyncDTO.setItemId(String.valueOf(entity.getId())); - videoSyncDTO.setStationName(stationName); - videoSyncDTO.setItemName(stationName + " " + videoSyncDTO.getName()); - return videoSyncDTO; - } - -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/aspect/VideoSyncAspect.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/aspect/VideoSyncAspect.java new file mode 100644 index 0000000..b5b2e7b --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/aspect/VideoSyncAspect.java @@ -0,0 +1,58 @@ +package com.hnac.hzims.operational.station.aspect; + +import com.alibaba.fastjson.JSON; +import com.google.common.collect.Lists; +import com.hnac.hzims.bigmodel.api.constants.MqttTopicConstants; +import com.hnac.hzims.bigmodel.api.dto.VideoSyncDTO; +import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity; +import com.hnac.hzims.operational.station.wrapper.VideoSyncWrapper; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.After; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; +import org.springblade.mqtt.producer.IMqttSender; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * @Author: huangxing + * @Date: 2024/08/09 14:02 + */ +@Aspect +@Component +@AllArgsConstructor +@Slf4j +public class VideoSyncAspect { + + private final VideoSyncWrapper wrapper; + private final IMqttSender mqttSender; + + @Pointcut("execution(* com.hnac.hzims.operational.station.service.IStationVideoTypeService.saveBatch(..)) " + + "|| execution(* com.hnac.hzims.operational.station.service.IStationVideoTypeService.save(..)) " + + "|| execution(* com.hnac.hzims.operational.station.service.IStationVideoTypeService.updateById(..)) " + + "|| execution(* com.hnac.hzims.operational.station.service.IStationVideoTypeService.updateBatchById(..))") + private void pointCut() { + + } + + @After("pointCut()") + public void after(JoinPoint point) { + Object[] args = point.getArgs(); + if(args.length == 1) { + Object arg = args[0]; + if(arg instanceof StationVideoTypeEntity) { + List videoSyncDTOS = Lists.newArrayList(wrapper.convert((StationVideoTypeEntity) arg)); + mqttSender.sendToMqtt(MqttTopicConstants.TOPIC_VIDEO_INSERT, JSON.toJSONString(videoSyncDTOS)); + } + else if(arg instanceof List) { + List videoList = (List) args[0]; + List videoSyncDTOS = wrapper.listVO(videoList); + mqttSender.sendToMqtt(MqttTopicConstants.TOPIC_VIDEO_INSERT, JSON.toJSONString(videoSyncDTOS)); + } + } + } + +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/wrapper/VideoSyncWrapper.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/wrapper/VideoSyncWrapper.java new file mode 100644 index 0000000..72ce88c --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/wrapper/VideoSyncWrapper.java @@ -0,0 +1,38 @@ +package com.hnac.hzims.operational.station.wrapper; + +import com.hnac.hzims.bigmodel.api.dto.VideoSyncDTO; +import com.hnac.hzims.bigmodel.api.wrapper.BaseSyncWrapper; +import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity; +import com.hnac.hzims.operational.station.service.IStationService; +import com.hnac.hzims.operational.station.vo.StationVO; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import org.springblade.core.tool.utils.BeanUtil; +import org.springblade.core.tool.utils.SpringUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Optional; + +/** + * @Author: huangxing + * @Date: 2024/08/20 11:21 + */ +@Component +@AllArgsConstructor +public class VideoSyncWrapper extends BaseSyncWrapper { + + private final IStationService stationService; + + @Override + public VideoSyncDTO convert(StationVideoTypeEntity entity) { + VideoSyncDTO videoSyncDTO = BeanUtil.copy(entity,VideoSyncDTO.class); + StationVO station = stationService.getStationByCode(entity.getStationId()); + String stationName = Optional.ofNullable(station).map(StationVO::getName).orElse(""); + videoSyncDTO.setId(String.valueOf(entity.getId())); + videoSyncDTO.setItemId(String.valueOf(entity.getId())); + videoSyncDTO.setStationName(stationName); + videoSyncDTO.setItemName(stationName + " " + videoSyncDTO.getName()); + return videoSyncDTO; + } +} From 986536d417052adb51d1c1a111c5cf03766ec878 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Thu, 22 Aug 2024 16:44:58 +0800 Subject: [PATCH 02/19] =?UTF-8?q?fix:=20sql=E6=89=A7=E8=A1=8C=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E8=AF=AD=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/hnac/hzims/common/service/UserAuthDataService.java | 5 +++++ .../com/hnac/hzims/bigmodel/business/service/DataSourceService.java | 1 + 2 files changed, 6 insertions(+) diff --git a/hzims-biz-common/src/main/java/com/hnac/hzims/common/service/UserAuthDataService.java b/hzims-biz-common/src/main/java/com/hnac/hzims/common/service/UserAuthDataService.java index 7d7de77..d793fd8 100644 --- a/hzims-biz-common/src/main/java/com/hnac/hzims/common/service/UserAuthDataService.java +++ b/hzims-biz-common/src/main/java/com/hnac/hzims/common/service/UserAuthDataService.java @@ -1,9 +1,11 @@ package com.hnac.hzims.common.service; +import com.hnac.hzims.common.constant.CommonConstant; import com.hnac.hzims.common.logs.utils.StringUtils; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.Func; import org.springblade.system.user.entity.User; import org.springblade.system.user.feign.IUserClient; import org.springframework.http.HttpStatus; @@ -22,6 +24,9 @@ public class UserAuthDataService { * @return */ public String getUserAuthDataSQL(Long userId) { + if(CommonConstant.SYSTEM_USER.equals(userId)) { + return ""; + } R r = userClient.userInfoById(userId); String sqlScript = null; if(r.getCode() != HttpStatus.OK.value() || r.getData() == null) { diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/DataSourceService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/DataSourceService.java index 23613a2..c616d0a 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/DataSourceService.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/DataSourceService.java @@ -63,6 +63,7 @@ public class DataSourceService { } } } + sql = sql.replaceAll(">", ">").replaceAll("<", "<"); log.info("执行sql:{}",sql); return this.queryListOnSpecificDataSource(sql, sqlVO.getTableAuthVOList().get(0).getDatasourceName()); } From ea653a473f54926ef16c03affef632add024e59a Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Mon, 26 Aug 2024 14:58:49 +0800 Subject: [PATCH 03/19] =?UTF-8?q?fix:=20=E4=B8=B4=E6=97=B6=E6=8F=90?= =?UTF-8?q?=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bigmodel/database/entity/WeaviateEntity.java | 23 +++ .../hzinfo/inspect/obj/entity/ObjectEntity.java | 2 +- .../bigmodel/configuration/BigModelInvokeApi.java | 5 + .../bigmodel/configuration/WeaviateConfig.java | 20 --- .../bigmodel/configuration/WeaviateConfigure.java | 56 +++++++ .../bigmodel/configuration/WeaviateProperties.java | 32 ++++ .../bigmodel/database/service/WeaviateService.java | 183 +++++++++++++++++++++ .../hzims/bigmodel/database/util/WeaviateUtil.java | 11 ++ .../bigmodel/zhipuai/config/ZhipuAiConfig.java | 35 ---- .../src/main/resources/template/template.yml | 2 + 10 files changed, 313 insertions(+), 56 deletions(-) create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/database/entity/WeaviateEntity.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/WeaviateConfig.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/WeaviateConfigure.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/WeaviateProperties.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/database/service/WeaviateService.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/database/util/WeaviateUtil.java diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/database/entity/WeaviateEntity.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/database/entity/WeaviateEntity.java new file mode 100644 index 0000000..6c2b3ba --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/database/entity/WeaviateEntity.java @@ -0,0 +1,23 @@ +package com.hnac.hzims.bigmodel.database.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/08/22 19:35 + */ +@Data +@EqualsAndHashCode +public class WeaviateEntity implements Serializable { + + @JSONField(name = "item_id") + private String itemId; + + @JSONField(name = "item_name") + private String itemName; + +} diff --git a/hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/obj/entity/ObjectEntity.java b/hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/obj/entity/ObjectEntity.java index 4a7efdb..7ef2305 100644 --- a/hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/obj/entity/ObjectEntity.java +++ b/hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/obj/entity/ObjectEntity.java @@ -49,7 +49,7 @@ public class ObjectEntity extends TenantEntity { * 地理位置 */ @ApiModelProperty(value = "地理位置,长度必须为1到128") - @Size(min=1,max = 128,message ="地理位置长度必须为1到128") + // @Size(min=1,max = 128,message ="地理位置长度必须为1到128") private String address; /** * 经度(东经) diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeApi.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeApi.java index c11b4b6..b6b842a 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeApi.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeApi.java @@ -62,4 +62,9 @@ public class BigModelInvokeApi { */ private String updateKnowledge; + /** + * 计算向量 + */ + private String compute; + } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/WeaviateConfig.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/WeaviateConfig.java deleted file mode 100644 index 022663a..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/WeaviateConfig.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.hnac.hzims.bigmodel.configuration; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.reactive.function.client.WebClient; -import reactor.core.publisher.Mono; - -/** - * @Author: huangxing - * @Date: 2024/08/21 15:22 - */ -@Configuration -public class WeaviateConfig { - - @Bean - public WebClient weaviateClient() { - return WebClient.create("http://192.168.60.16:9992"); - } - -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/WeaviateConfigure.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/WeaviateConfigure.java new file mode 100644 index 0000000..6bd2f14 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/WeaviateConfigure.java @@ -0,0 +1,56 @@ +package com.hnac.hzims.bigmodel.configuration; + +import io.weaviate.client.Config; +import io.weaviate.client.WeaviateAuthClient; +import io.weaviate.client.WeaviateClient; +import io.weaviate.client.v1.auth.exception.AuthException; +import io.weaviate.client.v1.data.api.ObjectCreator; +import io.weaviate.client.v1.data.api.ObjectDeleter; +import io.weaviate.client.v1.data.api.ObjectUpdater; +import io.weaviate.client.v1.data.api.ObjectsGetter; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @Author: huangxing + * @Date: 2024/08/22 18:38 + */ +@Configuration +public class WeaviateConfigure { + + private final WeaviateProperties weaviateProperties; + + public WeaviateConfigure(WeaviateProperties weaviateProperties) { + this.weaviateProperties = weaviateProperties; + } + + @Bean + public WeaviateClient weaviateClient() throws AuthException { + Config config = new Config(this.weaviateProperties.getSchema(), this.weaviateProperties.getHost() + ":" + this.weaviateProperties.getPort()); + return WeaviateAuthClient.apiKey(config,this.weaviateProperties.getApiKey()); + } + + @Bean + public ObjectsGetter objectsGetter() throws AuthException { + WeaviateClient weaviateClient = weaviateClient(); + return weaviateClient.data().objectsGetter(); + } + + @Bean + public ObjectCreator objectCreator() throws AuthException { + WeaviateClient weaviateClient = weaviateClient(); + return weaviateClient.data().creator(); + } + + @Bean + public ObjectDeleter deleter() throws AuthException { + WeaviateClient weaviateClient = weaviateClient(); + return weaviateClient.data().deleter(); + } + + @Bean + public ObjectUpdater updater() throws AuthException { + WeaviateClient weaviateClient = weaviateClient(); + return weaviateClient.data().updater(); + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/WeaviateProperties.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/WeaviateProperties.java new file mode 100644 index 0000000..468bae9 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/WeaviateProperties.java @@ -0,0 +1,32 @@ +package com.hnac.hzims.bigmodel.configuration; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +/** + * @Author: huangxing + * @Date: 2024/08/21 15:22 + */ +@Data +@Component +@ConfigurationProperties(prefix = "weaviate.datasource") +public class WeaviateProperties { + + private String schema; + + private String host; + + private String port; + + /** + * 登录认证KEY + */ + private String apiKey; + + /** + * 数据库表名前缀 + */ + private String classNamePrefix; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/database/service/WeaviateService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/database/service/WeaviateService.java new file mode 100644 index 0000000..931a6a8 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/database/service/WeaviateService.java @@ -0,0 +1,183 @@ +package com.hnac.hzims.bigmodel.database.service; + +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import cn.hutool.json.JSONUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.google.common.collect.Lists; +import com.google.protobuf.ServiceException; +import com.hnac.hzims.bigmodel.configuration.BigModelInvokeApi; +import com.hnac.hzinfo.exception.HzServiceException; +import io.weaviate.client.base.Result; +import io.weaviate.client.v1.data.api.ObjectCreator; +import io.weaviate.client.v1.data.api.ObjectDeleter; +import io.weaviate.client.v1.data.api.ObjectUpdater; +import io.weaviate.client.v1.data.model.WeaviateObject; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.tool.utils.BeanUtil; +import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.StringUtil; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +import java.lang.reflect.Field; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.*; +import java.util.stream.Collector; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +/** + * @Author: huangxing + * @Date: 2024/08/22 19:17 + */ +@RequiredArgsConstructor +@Service +@Slf4j +public class WeaviateService { + + private final ObjectCreator objectCreator; + private final ObjectUpdater objectUpdater; + private final ObjectDeleter objectDeleter; + private final BigModelInvokeApi invokeApi; + @Value("${gglm.vectorUrl}") + private final String vectorUrl; + + /** + * 对象保存向量数据库 + * @param entity 保存对象 + * @param className 保存表名 + * @param attrs 待计算的列信息 + * @return 保存操作结果 + */ + public Boolean save(Object entity, String className, List attrs) { + ObjectCreator creator = objectCreator.withClassName(className); + if(Func.isNotEmpty(attrs)) { + JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(entity)); + List vectors = attrs.stream().map(attr -> jsonObject.getString(attr)).collect(Collectors.toList()); + Float[] compute = this.compute(vectors); + creator.withVector(compute); + } + Result result = creator.withProperties(BeanUtil.toMap(entity)).run(); + return !result.hasErrors(); + } + + /** + * 对象批量保存向量数据库 + * @param entities 保存对象列表 + * @param className 保存表名 + * @param attrsMap 待计算的列信息 key-向量名 value-实体类对象属性,多个按逗号分隔 + * @return 保存操作结果 + */ + public Boolean saveBatch(List entities,String className, Map attrsMap) { + ObjectCreator creator = objectCreator.withClassName(className); + List vectorStrs = Lists.newArrayList(); + List attrs = Lists.newArrayList(); + if(Func.isNotEmpty(attrsMap)) { + // 格式化数据 + attrsMap.forEach((k,v) -> attrs.add(v)); + // 解析待计算的向量字段 + entities.forEach(entity -> { + List vectorStr = attrs.stream().map(fields -> this.getFieldValue(fields, entity)).filter(Func::isNotEmpty).collect(Collectors.toList()); + vectorStrs.addAll(vectorStr); + }); + } + if(Func.isNotEmpty(vectorStrs)) { + // 若解析出来的向量存在值 + Float[] vectors = this.compute(vectorStrs); + + } else { + entities.forEach(entity -> creator.withProperties(BeanUtil.toMap(entity)).run()); + return true; + } + return false; + } + + /** + * 拆解计算出来的向量Float[] + * @param entitySize 对象列表size + * @param attrsMap 待计算的列信息 key-向量名 value-实体类对象属性,多个按逗号分隔 + * @param vectorTotal 计算出的向量总量 + * @return 拆解结果 + */ + private List> splitVector(Integer entitySize,Map attrsMap,Float[] vectorTotal) { + List> result = Lists.newArrayList(); + + // 获取待切割的下标 + List indexes = this.getSplitIndex(vectorTotal.length, entitySize); + indexes.forEach(index -> { + + }); + return null; + } + + /** + * 获取将list等量分隔成若干份的列表下标 + * @param size 总数 + * @param splitNum 分隔数量 + * @return 下标集合 + */ + private List getSplitIndex(int size,int splitNum) { + if(size % splitNum != 0) { + throw new HzServiceException("向量计算失败,无法根据同步对象进行等量分隔!"); + } + return IntStream.iterate(0, index -> index + 1) + .limit(splitNum) + .mapToObj(index -> index * (size / splitNum)) + .collect(Collectors.toList()); + } + + + private String getFieldValue(String fields,Object object) { + Class clazz = object.getClass(); + return Func.toStrList(",", fields).stream().map(field -> { + try { + Field declaredField = clazz.getDeclaredField(field); + declaredField.setAccessible(true); + return declaredField.get(object).toString(); + } catch (NoSuchFieldException | IllegalAccessException e) { + return null; + } + }).collect(Collectors.joining(" ")); + } + + /** + * 计算向量值 + * @param vectors 待计算的向量 + * @return 向量值Float[] + */ + private Float[] compute(List vectors) { + // 向量计算 + String url = vectorUrl + invokeApi.getCompute(); + String jsonData = JSONUtil.toJsonStr(vectors); + HttpResponse response = HttpRequest.post(url) + .header("Content-Type", "application/json; charset=utf-8") + .body(jsonData) + .execute(); + byte[] bytes = response.bodyBytes(); + if (bytes.length % 4 != 0) { + throw new HzServiceException("向量计算失败!响应数据长度不是4的倍数"); + } + List chunks = new ArrayList<>(); + int range = bytes.length / 4; + IntStream.range(0, range) + .forEach(index -> { + byte[] chunk = new byte[4]; + int page = index * 4; + chunk[0] = bytes[page]; + chunk[1] = bytes[page + 1]; + chunk[2] = bytes[page + 2]; + chunk[3] = bytes[page + 3]; + chunks.add(chunk); + }); + List floats = chunks.stream().map(b -> { + ByteBuffer buffer = ByteBuffer.wrap(b).order(ByteOrder.LITTLE_ENDIAN); + return buffer.getFloat(); + }).collect(Collectors.toList()); + return floats.toArray(new Float[floats.size()]); + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/database/util/WeaviateUtil.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/database/util/WeaviateUtil.java new file mode 100644 index 0000000..1c056ce --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/database/util/WeaviateUtil.java @@ -0,0 +1,11 @@ +package com.hnac.hzims.bigmodel.database.util; + +/** + * @Author: huangxing + * @Date: 2024/08/23 10:09 + */ +public class WeaviateUtil { + + + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/config/ZhipuAiConfig.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/config/ZhipuAiConfig.java index b28a3a5..1c5a8b2 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/config/ZhipuAiConfig.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/config/ZhipuAiConfig.java @@ -1,22 +1,11 @@ package com.hnac.hzims.bigmodel.zhipuai.config; -import com.alibaba.fastjson.JSON; import com.zhipu.oapi.ClientV4; -import io.weaviate.client.Config; -import io.weaviate.client.WeaviateAuthClient; -import io.weaviate.client.WeaviateClient; -import io.weaviate.client.base.Result; -import io.weaviate.client.v1.auth.exception.AuthException; -import io.weaviate.client.v1.data.model.WeaviateObject; -import io.weaviate.client.v1.misc.model.Meta; import lombok.AllArgsConstructor; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import java.util.HashMap; -import java.util.List; - /** * @Author: ypj * @Date: 2024/8/9 17:01 @@ -32,28 +21,4 @@ public class ZhipuAiConfig { public ClientV4 clientV4() { return new ClientV4.Builder(properties.getApiSecret()).build(); } - -// public static void main(String[] args) throws AuthException { -// Config config = new Config("http", "192.168.60.16:9992"); -// WeaviateClient client = WeaviateAuthClient.apiKey(config,"123"); -// // 新增 HZIMS_TEST -//// Result craeteTableTest = client.data().creator().withClassName("HZIMS_TEST").run(); -//// System.out.println(JSON.toJSONString(craeteTableTest)); -//// Result> searchResult = client.data().objectsGetter().withClassName("HZIMS_TEST").run(); -//// System.out.println(JSON.toJSONString(searchResult)); -// // 新增数据 -//// HashMap hashMap = new HashMap() {{ -//// put("id_", "13412423423412"); -//// put("name", "test"); -//// }}; -//// Result hzimsTest = client.data().creator().withClassName("HZIMS_TEST").withProperties(hashMap).withVector(new Float[]{}).run(); -//// System.out.println(JSON.toJSONString(hzimsTest)); -//// Result> searchResult = client.data().objectsGetter().withClassName("HZIMS_TEST").run(); -//// System.out.println(JSON.toJSONString(searchResult)); -// // 删除数据 -// Result hzimsTest = client.data().deleter().withClassName("HZIMS_TEST").withID("14c6847d-b758-475f-968d-64b0e193e43e").run(); -// System.out.println(JSON.toJSONString(hzimsTest)); -// Result> searchResult = client.data().objectsGetter().withClassName("HZIMS_TEST").run(); -// System.out.println(JSON.toJSONString(searchResult)); -// } } diff --git a/hzims-service/hzims-big-model/src/main/resources/template/template.yml b/hzims-service/hzims-big-model/src/main/resources/template/template.yml index 77287f6..ab25e27 100644 --- a/hzims-service/hzims-big-model/src/main/resources/template/template.yml +++ b/hzims-service/hzims-big-model/src/main/resources/template/template.yml @@ -49,6 +49,7 @@ spring: gglm: url: "http://${gglm.host}:${gglm.port}" + vectorUrl: "http://${vector.host}:${vector.port}" api: assistantAsk: "/qa/assistant_ask" assistantStatus: "/qa/assistant_status" @@ -62,6 +63,7 @@ gglm: smartReportGeneratePower: "/custom/smart_report_generate_power" assistantAnalyseAsk: "/qa/assistant_analyse_ask" updateKnowledge: "/kn/update_knowledge" + compute: "compute" swagger: base-packages: com.hnac.hzims.bigmodel From 2bf6cd4002738f0090fbfd1ad12db61e60d8d56f Mon Sep 17 00:00:00 2001 From: ty <1577900710@qq.com> Date: Tue, 13 Aug 2024 15:14:32 +0800 Subject: [PATCH 04/19] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=EF=BC=9A=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=E6=B5=81=E8=A1=A5=E5=81=BF=E6=9C=BA=E5=88=B6=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E5=8F=91=E9=80=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../consumer/StandardWorkTicketConsumer.java | 4 +- .../strategy/abstracts/ProcessAbstractService.java | 43 ++++++++++++++-------- .../strategy/service/ProcessService.java | 2 +- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/processflow/consumer/StandardWorkTicketConsumer.java b/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/processflow/consumer/StandardWorkTicketConsumer.java index ef665b1..ee66e01 100644 --- a/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/processflow/consumer/StandardWorkTicketConsumer.java +++ b/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/processflow/consumer/StandardWorkTicketConsumer.java @@ -49,8 +49,8 @@ public class StandardWorkTicketConsumer implements IQueueConsume { throw new ServiceException("消息转换失败,消息内容为:" + message); }); if (ObjectUtils.isNotEmpty(response.getCode())&&700==response.getCode()){ - ticketServiceList.get(0).pushFailMessage(Long.valueOf(response.getTaskId()),response.getBusinessKey(), - response.getUserId(), response.getTaskName(),response.getResult(),response.getDeptId()); + ticketServiceList.get(0).pushFailMessage(response.getTaskId(),response.getProcessDefinitionKey(), + response.getTaskName(),response.getResult(),response.getDeptId()); } // 保存日志 WorkflowOperationLog log = BeanUtil.copy(response, WorkflowOperationLog.class); diff --git a/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/processflow/strategy/abstracts/ProcessAbstractService.java b/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/processflow/strategy/abstracts/ProcessAbstractService.java index 9952839..5628704 100644 --- a/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/processflow/strategy/abstracts/ProcessAbstractService.java +++ b/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/processflow/strategy/abstracts/ProcessAbstractService.java @@ -4,13 +4,14 @@ import com.hnac.hzims.middle.processflow.entity.ProcessDict; import com.hnac.hzims.middle.processflow.service.ProcessDictService; import com.hnac.hzims.middle.processflow.strategy.service.ProcessService; import lombok.extern.slf4j.Slf4j; -import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.core.tool.utils.StringUtil; import org.springblade.flow.core.entity.BladeFlow; import org.springblade.flow.core.feign.IFlowClient; import org.springblade.message.MessageConstants; -import org.springblade.message.dto.BusinessMessageDTO; +import org.springblade.message.dto.BusinessMessageFlowDTO; import org.springblade.message.fegin.IMessageClient; import org.springblade.system.feign.ISysClient; import org.springblade.system.user.entity.User; @@ -60,7 +61,7 @@ public abstract class ProcessAbstractService implements ProcessService { log.error("开启流程失败:{}",result); log.error("流程信息为{}",variables); r.setData(variables); - pushStartFailMessage(dictValue,Long.valueOf(taskId),userId,processName,result.getMsg()); + pushStartFailMessage(dictValue,taskId,userId,processName,result.getMsg()); } return r; }catch (Exception e){ @@ -85,9 +86,9 @@ public abstract class ProcessAbstractService implements ProcessService { // return r; // } - public void pushStartFailMessage(String dictValue,Long taskId, String userId, String content,String reason) { + public void pushStartFailMessage(String dictValue,String taskId, String userId, String content,String reason) { ProcessDict processDict = processDictService.selectDictLabelByKey(dictValue); - BusinessMessageDTO message = new BusinessMessageDTO(); + BusinessMessageFlowDTO message = new BusinessMessageFlowDTO(); // 计划Id message.setTaskId(taskId); message.setBusinessClassify(MessageConstants.BusinessClassifyEnum.BUSINESS.getKey()); @@ -108,13 +109,14 @@ public abstract class ProcessAbstractService implements ProcessService { } message.setCreateUser(admin.getId()); message.setUserIds(userId); - messageClient.sendAppAndWsMsgByUsers(message); + messageClient.sendAppAndWsMsgByUsersFlow(message); } @Override - public void pushFailMessage(Long taskId, String proessKey, String userId, String content,String reason,String deptId) { + public void pushFailMessage(String taskId, String proessKey, String content,String reason,String deptId) { ProcessDict processDict = processDictService.selectDictLabelByKey(proessKey); - BusinessMessageDTO message = new BusinessMessageDTO(); + BusinessMessageFlowDTO message = new BusinessMessageFlowDTO(); +// BusinessMessageDTO message = new BusinessMessageDTO(); // 计划Id message.setTaskId(taskId); message.setBusinessClassify(MessageConstants.BusinessClassifyEnum.BUSINESS.getKey()); @@ -126,18 +128,27 @@ public abstract class ProcessAbstractService implements ProcessService { processDict.getDictLabel(), reason); message.setContent(res); message.setTenantId("200000"); - R> userListR = userClient.relationUserListByRoleAlias(AuthUtil.getTenantId(), Long.valueOf(deptId), PROJECT_MANAGER); + R> userListR = userClient.queryUserByRoleAlias("200000", Long.valueOf(deptId), PROJECT_MANAGER); User admin = userClient.userByAccount("200000", "admin").getData(); - User createUser = userClient.userInfoById(Long.valueOf(userId)).getData(); - message.setDeptId(createUser.getCreateDept()); - R result = sysClient.getDeptName(createUser.getCreateDept()); + message.setDeptId(Long.valueOf(deptId)); + R result = sysClient.getDeptName(Long.valueOf(deptId)); if (result.isSuccess()) { message.setDeptName(result.getData()); } - List data = userListR.getData(); - String userIds = data.stream().map(user -> user.getId().toString()).collect(Collectors.joining(",")); + if (CollectionUtil.isNotEmpty(userListR.getData())){ + List data = userListR.getData(); + String userIds = data.stream().map(user -> user.getId().toString()).collect(Collectors.joining(",")); + message.setUserIds(userIds); + }else { + R> listR = userClient.queryUserByRoleAlias("200000", Long.valueOf(20000001), PROJECT_MANAGER); + if (ObjectUtil.isEmpty(listR)||CollectionUtil.isEmpty(listR.getData())){ + return; + } + List data =listR.getData(); + String userIds = data.stream().map(user -> user.getId().toString()).collect(Collectors.joining(",")); + message.setUserIds(userIds); + } message.setCreateUser(admin.getId()); - message.setUserIds(userIds); - messageClient.sendAppAndWsMsgByUsers(message); + messageClient.sendAppAndWsMsgByUsersFlow(message); } } diff --git a/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/processflow/strategy/service/ProcessService.java b/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/processflow/strategy/service/ProcessService.java index 7869a16..6475e19 100644 --- a/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/processflow/strategy/service/ProcessService.java +++ b/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/processflow/strategy/service/ProcessService.java @@ -16,7 +16,7 @@ public interface ProcessService { R startFlow(String userId, String dictValue, String taskId, String processName, Map variables) ; - void pushFailMessage(Long taskId, String proessKey, String userId, String content,String reason,String deptId); + void pushFailMessage(String taskId, String proessKey, String content,String reason,String deptId); /** * 设置执行那种实现类 * @param flowQueue From 256d8d6aafa74085e0e3be4489345740d96e1c2d Mon Sep 17 00:00:00 2001 From: ty <1577900710@qq.com> Date: Wed, 14 Aug 2024 18:20:49 +0800 Subject: [PATCH 05/19] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=EF=BC=9A=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=E6=B5=81=E8=A1=A5=E5=81=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/DefectCheckServiceImpl.java | 40 +++++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/impl/DefectCheckServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/impl/DefectCheckServiceImpl.java index f0355a4..51f02c6 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/impl/DefectCheckServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/impl/DefectCheckServiceImpl.java @@ -4,6 +4,8 @@ import cn.hutool.core.collection.CollectionUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; @@ -335,6 +337,10 @@ public class DefectCheckServiceImpl extends ServiceImpl variables = (Map) processWorkFlowResponse.getVariables(); //现象缺陷全表更新 @@ -368,7 +374,6 @@ public class DefectCheckServiceImpl extends ServiceImpl() {{ + eq(OperPhenomenonEntity::getCheckProcessInstanceId, split[1]); + }}); + operPhenomenonEntity.setIsNormal(false); + operPhenomenonEntity.setRemark(JSONObject.toJSONString(processWorkFlowResponse.getVariables())); + operPhenomenonEntity.setCurrentOperator("流程异常"); + operPhenomenonEntity.setCurrentLinkHandler(""); + this.baseMapper.update(operPhenomenonEntity, new LambdaUpdateWrapper() {{ + eq(OperPhenomenonEntity::getDefectCode, operPhenomenonEntity.getDefectCode()); + }}); + log.info("消缺消息转换结束"+ processWorkFlowResponse); return R.success("消息保存成功"); } From 6ccdd59d762953ab77f6917ce4873588764c6cbe Mon Sep 17 00:00:00 2001 From: ty <1577900710@qq.com> Date: Mon, 19 Aug 2024 16:07:03 +0800 Subject: [PATCH 06/19] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E8=A1=A5?= =?UTF-8?q?=E5=81=BF=E6=B5=81=E7=A8=8B=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/AlarmHandleFlowServiceImpl.java | 29 +++++++++++-- .../show/service/impl/AlarmHandleServiceImpl.java | 4 +- .../consumer/StandardWorkTicketConsumer.java | 2 +- .../processflow/feign/CompensateProcessClient.java | 4 +- .../strategy/abstracts/ProcessAbstractService.java | 16 +++---- .../strategy/service/ProcessService.java | 2 +- .../service/impl/AccessPlanV4ServiceImpl.java | 27 ++++++++++-- .../service/impl/AccessTaskV4ServiceImpl.java | 31 +++++++++++--- .../service/impl/DefectCheckServiceImpl.java | 9 ++-- .../operational/duty/feign/DutyRecClient.java | 14 +------ .../duty/service/IImsDutyRecService.java | 3 +- .../duty/service/impl/ImsDutyRecServiceImpl.java | 49 +++++++++++++++++++--- .../operational/src/main/resources/db/3.0.1.sql | 2 + .../risk/service/impl/HazardTaskServiceImpl.java | 34 +++++++++++---- 14 files changed, 167 insertions(+), 59 deletions(-) diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleFlowServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleFlowServiceImpl.java index 700ca5f..2d3090e 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleFlowServiceImpl.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleFlowServiceImpl.java @@ -2,6 +2,8 @@ package com.hnac.hzims.alarm.show.service.impl; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.hnac.hzims.alarm.config.constants.AlarmHandleConstant; @@ -13,6 +15,7 @@ import com.hnac.hzims.alarm.show.service.AlarmHandleFlowService; import com.hnac.hzims.common.logs.utils.StringUtils; import com.hnac.hzims.fdp.feign.IFdpDiagnoseClient; import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse; +import com.hnac.hzims.operational.defect.entity.OperPhenomenonEntity; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.log.exception.ServiceException; @@ -63,6 +66,9 @@ public class AlarmHandleFlowServiceImpl extends ServiceImpl() {{ + eq(AlarmHandleFlowEntity::getId, split[1]); + }}); + alarmHandleFlowEntity.setIsNormal(false); + alarmHandleFlowEntity.setProcessInstanceId(processWorkFlowResponse.getTaskId()); + alarmHandleFlowEntity.setRemark(JSONObject.toJSONString(processWorkFlowResponse.getVariables())); + alarmHandleFlowEntity.setCurrentOperator(processWorkFlowResponse.getTaskName()); + alarmHandleFlowEntity.setCurrentLinkHandler(""); + this.baseMapper.updateById(alarmHandleFlowEntity); + log.info("补偿流程消息转换结束"+ processWorkFlowResponse); + return R.success("补偿流程消息保存成功"); + } private void sendMessage(ProcessWorkFlowResponse processWorkFlowResponse, AlarmHandleFlowEntity alarmHandleFlowEntity, Long taskId) { //推送消息 if (processWorkFlowResponse.getTaskId() != null) { diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleServiceImpl.java index 14f7b9f..769e53e 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleServiceImpl.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleServiceImpl.java @@ -159,9 +159,9 @@ public class AlarmHandleServiceImpl extends ServiceImpl variables) { - return processService.startFlow(userId,dictValue,taskId,processName,variables); + return processService.startFlow(userId,dictValue,businessKey,processName,variables); } } \ No newline at end of file diff --git a/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/processflow/strategy/abstracts/ProcessAbstractService.java b/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/processflow/strategy/abstracts/ProcessAbstractService.java index 5628704..b7014fb 100644 --- a/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/processflow/strategy/abstracts/ProcessAbstractService.java +++ b/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/processflow/strategy/abstracts/ProcessAbstractService.java @@ -44,11 +44,11 @@ public abstract class ProcessAbstractService implements ProcessService { private ProcessDictService processDictService; @Override - public R startFlow(String userId, String dictValue, String taskId, String processName, Map variables) { + public R startFlow(String userId, String dictValue, String businessKey, String processName, Map variables) { log.info("开启流程....."); R r = new R(); try { - R result = flowClient.startProcessInstanceContainNameByKey(dictValue, taskId, processName, variables); + R result = flowClient.startProcessInstanceContainNameByKey(dictValue, businessKey, processName, variables); r.setSuccess(result.isSuccess()); r.setCode(result.getCode()); r.setMsg(result.getMsg()); @@ -61,7 +61,7 @@ public abstract class ProcessAbstractService implements ProcessService { log.error("开启流程失败:{}",result); log.error("流程信息为{}",variables); r.setData(variables); - pushStartFailMessage(dictValue,taskId,userId,processName,result.getMsg()); + pushStartFailMessage(dictValue,businessKey,userId,processName,result.getMsg()); } return r; }catch (Exception e){ @@ -86,11 +86,11 @@ public abstract class ProcessAbstractService implements ProcessService { // return r; // } - public void pushStartFailMessage(String dictValue,String taskId, String userId, String content,String reason) { + public void pushStartFailMessage(String dictValue,String businessKey, String userId, String content,String reason) { ProcessDict processDict = processDictService.selectDictLabelByKey(dictValue); BusinessMessageFlowDTO message = new BusinessMessageFlowDTO(); // 计划Id - message.setTaskId(taskId); + message.setTaskId(businessKey); message.setBusinessClassify(MessageConstants.BusinessClassifyEnum.BUSINESS.getKey()); message.setBusinessKey(MessageConstants.BusinessClassifyEnum.BUSINESS.getKey()); // 主题 @@ -113,18 +113,18 @@ public abstract class ProcessAbstractService implements ProcessService { } @Override - public void pushFailMessage(String taskId, String proessKey, String content,String reason,String deptId) { + public void pushFailMessage(String businessKey, String proessKey, String content,String reason,String deptId) { ProcessDict processDict = processDictService.selectDictLabelByKey(proessKey); BusinessMessageFlowDTO message = new BusinessMessageFlowDTO(); // BusinessMessageDTO message = new BusinessMessageDTO(); // 计划Id - message.setTaskId(taskId); + message.setTaskId(businessKey); message.setBusinessClassify(MessageConstants.BusinessClassifyEnum.BUSINESS.getKey()); message.setBusinessKey(MessageConstants.BusinessClassifyEnum.BUSINESS.getKey()); // 主题 message.setSubject(MessageConstants.BusinessClassifyEnum.BUSINESS.getDescription()); // 内容 - String res= StringUtil.format("你有一个{}的{}流程流转失败,失败原因为:{}",content, + String res= StringUtil.format("你有一个流程环节为{}的{}流转失败,失败原因为:{}",content, processDict.getDictLabel(), reason); message.setContent(res); message.setTenantId("200000"); diff --git a/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/processflow/strategy/service/ProcessService.java b/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/processflow/strategy/service/ProcessService.java index 6475e19..68ab7f0 100644 --- a/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/processflow/strategy/service/ProcessService.java +++ b/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/processflow/strategy/service/ProcessService.java @@ -14,7 +14,7 @@ import java.util.Map; */ public interface ProcessService { - R startFlow(String userId, String dictValue, String taskId, String processName, Map variables) ; + R startFlow(String userId, String dictValue, String businessKey, String processName, Map variables) ; void pushFailMessage(String taskId, String proessKey, String content,String reason,String deptId); /** diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/impl/AccessPlanV4ServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/impl/AccessPlanV4ServiceImpl.java index cc715ff..e2cc2da 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/impl/AccessPlanV4ServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/impl/AccessPlanV4ServiceImpl.java @@ -121,7 +121,6 @@ public class AccessPlanV4ServiceImpl implements AccessPlanV4Service, StartProces private final TransactionTemplate transactionTemplate; @Override public String saveEntity(String entity) { - transactionTemplate.setTransactionManager(transactionManager); String res = transactionTemplate.execute(status -> { AccessPlanV4DTO accessPlanV4DTO = JSONObject.parseObject(entity, AccessPlanV4DTO.class); @@ -289,8 +288,8 @@ public class AccessPlanV4ServiceImpl implements AccessPlanV4Service, StartProces entity.setNextStepOperator(processWorkFlowResponse.getNextStepOperator()); entity.setIsNormal(true); if(ObjectUtils.isNotEmpty(processWorkFlowResponse.getCode())&&700==processWorkFlowResponse.getCode()){ - entity.setIsNormal(false); - entity.setRemark(JSONObject.toJSONString(processWorkFlowResponse.getVariables())); + handException(processWorkFlowResponse); + return false; } if(ObjectUtil.isNotEmpty(variables.get("examine")) && (Boolean) variables.get("examine")){ entity.setTaskName("流程结束"); @@ -322,7 +321,27 @@ public class AccessPlanV4ServiceImpl implements AccessPlanV4Service, StartProces } return true; } - + private R handException(ProcessWorkFlowResponse processWorkFlowResponse) { + String[] split = processWorkFlowResponse.getBusinessKey().split(":"); + if (StringUtils.isBlank(split[1])){ + log.error("异常消息转换失败,未找到BusinessKey:"+ processWorkFlowResponse); + return R.fail("异常消息处理失败"); + } + OperAccessPlanEntity operAccessPlanEntity = planService.getOne(new LambdaQueryWrapper() {{ + eq(OperAccessPlanEntity::getId, split[1]); + }}); + operAccessPlanEntity.setIsNormal(false); + operAccessPlanEntity.setRemark(JSONObject.toJSONString(processWorkFlowResponse.getVariables())); + operAccessPlanEntity.setTaskName(processWorkFlowResponse.getTaskName()); + operAccessPlanEntity.setProcessInstanceId(processWorkFlowResponse.getTaskId()); + operAccessPlanEntity.setNextStepOperator(""); + boolean flag = planService.updateById(operAccessPlanEntity); + if (!flag){ + log.info("异常状态消息保存失败"+ processWorkFlowResponse); + return R.success("消息保存失败"); + } + return R.fail("消息保存成功"); + } /** * 开启检修任务 diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/impl/AccessTaskV4ServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/impl/AccessTaskV4ServiceImpl.java index 675064c..90ba737 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/impl/AccessTaskV4ServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/impl/AccessTaskV4ServiceImpl.java @@ -131,7 +131,7 @@ public class AccessTaskV4ServiceImpl implements AccessTaskV4Service, StartProces String.valueOf(accessTaskV4DTO.getId())), accessTaskV4DTO.getName(),variables); log.error("开启检修任务流程失败{}" + result); // 更新任务流程Id - if (200==result.getCode()) { + if (200==result.getCode()&&ObjectUtil.isNotEmpty(result.getData())) { accessTaskV4DTO.setProcessInstanceId(result.getData().toString()); accessTaskV4DTO.setIsNormal(true); taskService.updateById(accessTaskV4DTO); @@ -237,8 +237,8 @@ public class AccessTaskV4ServiceImpl implements AccessTaskV4Service, StartProces AccessTaskV4DTO entity = JSONObject.parseObject(JSONObject.toJSONString(variables), new TypeReference(){}); entity.setIsNormal(true); if(ObjectUtils.isNotEmpty(processWorkFlowResponse.getCode())&&700==processWorkFlowResponse.getCode()){ - entity.setIsNormal(false); - entity.setRemark(JSONObject.toJSONString(processWorkFlowResponse.getVariables())); + handException(processWorkFlowResponse); + return false; } // 当前流程名称 entity.setTaskName(processWorkFlowResponse.getTaskName()); @@ -266,12 +266,31 @@ public class AccessTaskV4ServiceImpl implements AccessTaskV4Service, StartProces String content = "您有一条检修任务待处理/审核,检修任务名称:".concat(entity.getName()) .concat(",当前环节:") .concat(processWorkFlowResponse.getTaskName()); - if(ObjectUtils.isEmpty(processWorkFlowResponse.getCode())||700!=processWorkFlowResponse.getCode()){ - this.sendMessage(entity,processWorkFlowResponse.getUserId(),content); - } + this.sendMessage(entity,processWorkFlowResponse.getUserId(),content); return true; } + private R handException(ProcessWorkFlowResponse processWorkFlowResponse) { + String[] split = processWorkFlowResponse.getBusinessKey().split(":"); + if (StringUtils.isBlank(split[1])){ + log.error("异常消息转换失败,未找到BusinessKey:"+ processWorkFlowResponse); + return R.fail("异常消息处理失败"); + } + OperAccessTaskEntity operAccessTaskEntity = taskService.getOne(new LambdaQueryWrapper() {{ + eq(OperAccessTaskEntity::getId, split[1]); + }}); + operAccessTaskEntity.setIsNormal(false); + operAccessTaskEntity.setRemark(JSONObject.toJSONString(processWorkFlowResponse.getVariables())); + operAccessTaskEntity.setTaskName(processWorkFlowResponse.getTaskName()); + operAccessTaskEntity.setProcessInstanceId(processWorkFlowResponse.getTaskId()); + operAccessTaskEntity.setNextStepOperator(""); + boolean flag = taskService.updateById(operAccessTaskEntity); + if (!flag){ + log.info("异常状态消息保存失败"+ processWorkFlowResponse); + return R.success("消息保存失败"); + } + return R.fail("消息保存成功"); + } /** * 推送业务流程消息 diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/impl/DefectCheckServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/impl/DefectCheckServiceImpl.java index 51f02c6..1247345 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/impl/DefectCheckServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/impl/DefectCheckServiceImpl.java @@ -411,17 +411,18 @@ public class DefectCheckServiceImpl extends ServiceImpl() {{ - eq(OperPhenomenonEntity::getCheckProcessInstanceId, split[1]); + eq(OperPhenomenonEntity::getId, split[1]); }}); operPhenomenonEntity.setIsNormal(false); + operPhenomenonEntity.setCheckProcessInstanceId(processWorkFlowResponse.getTaskId()); operPhenomenonEntity.setRemark(JSONObject.toJSONString(processWorkFlowResponse.getVariables())); - operPhenomenonEntity.setCurrentOperator("流程异常"); + operPhenomenonEntity.setCurrentOperator(processWorkFlowResponse.getTaskName()); operPhenomenonEntity.setCurrentLinkHandler(""); this.baseMapper.update(operPhenomenonEntity, new LambdaUpdateWrapper() {{ eq(OperPhenomenonEntity::getDefectCode, operPhenomenonEntity.getDefectCode()); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/feign/DutyRecClient.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/feign/DutyRecClient.java index eab7449..7df8870 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/feign/DutyRecClient.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/feign/DutyRecClient.java @@ -32,18 +32,6 @@ public class DutyRecClient implements IDutyRecClient { @Override public R dealDutyRecFlow(ProcessWorkFlowResponse processWorkFlowResponse) { - log.info("operational:duty:rec:dealDutyRecFlow","接受到消息:消息内容为:"+ JSON.toJSONString(processWorkFlowResponse)); - //ImsDutyRecDTO recDTO = BeanUtil.copy(processWorkFlowResponse.getVariables(),ImsDutyRecDTO.class); - ImsDutyRecDTO recDTO = JSONObject.parseObject(JSON.toJSONString(processWorkFlowResponse.getVariables()),ImsDutyRecDTO.class); - Assert.isTrue(ObjectUtil.isNotEmpty(recDTO),() -> { - throw new RuntimeException("未接收到交接班信息!"); - }); - recDTO.setDealChain(processWorkFlowResponse.getTaskName()); - recDTO.setIsNormal(true); - if(ObjectUtils.isNotEmpty(processWorkFlowResponse.getCode())&&700==processWorkFlowResponse.getCode()){ - recDTO.setIsNormal(false); - recDTO.setRemark(JSONObject.toJSONString(processWorkFlowResponse.getVariables())); - } - return R.status(service.dealDutyRecFlow(recDTO)); + return service.dealDutyRecFlow(processWorkFlowResponse); } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/IImsDutyRecService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/IImsDutyRecService.java index a217f4c..1d0461f 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/IImsDutyRecService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/IImsDutyRecService.java @@ -2,6 +2,7 @@ package com.hnac.hzims.operational.duty.service; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; +import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse; import com.hnac.hzims.operational.duty.dto.ChangeShiftsReqDTO; import com.hnac.hzims.operational.duty.dto.ChangeShiftsRspDTO; import com.hnac.hzims.operational.duty.dto.ImsDutyRecDTO; @@ -130,7 +131,7 @@ public interface IImsDutyRecService extends IService { * @param recDTO 交接班信息 * @return */ - Boolean dealDutyRecFlow(ImsDutyRecDTO recDTO); + R dealDutyRecFlow(ProcessWorkFlowResponse processWorkFlowResponse); R getDutyLog(ImsDutyLogEntity imsDutyLogEntity); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyRecServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyRecServiceImpl.java index c88e34e..89284c7 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyRecServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyRecServiceImpl.java @@ -10,10 +10,13 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.google.common.collect.Lists; import com.hnac.hzims.common.flow.StartProcessService; +import com.hnac.hzims.common.logs.utils.StringUtils; import com.hnac.hzims.middle.process.feign.ICompensateProcessClient; +import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse; import com.hnac.hzims.monitor.utils.DateUtils; import com.hnac.hzims.operational.OperationalConstants; import com.hnac.hzims.operational.access.dto.AccessTaskV4DTO; +import com.hnac.hzims.operational.access.entity.OperAccessTaskEntity; import com.hnac.hzims.operational.defect.constants.TreatMethodConstant; import com.hnac.hzims.operational.defect.entity.OperAppearanceEntity; import com.hnac.hzims.operational.defect.entity.OperDefectStatisticsEntity; @@ -1321,8 +1324,19 @@ public class ImsDutyRecServiceImpl extends ServiceImpl { + throw new RuntimeException("未接收到交接班信息!"); + }); + recDTO.setDealChain(processWorkFlowResponse.getTaskName()); + recDTO.setIsNormal(true); + if(ObjectUtil.isNotEmpty(processWorkFlowResponse.getCode())&&700==processWorkFlowResponse.getCode()){ + handException(processWorkFlowResponse); + + } ImsDutyMainEntity headDutyMain = BeanUtil.copy(recDTO.getHeadDutyMainVo(), ImsDutyMainEntity.class); ImsDutyMainEntity carryDutyMain = BeanUtil.copy(recDTO.getCarryDutyMainVo(), ImsDutyMainEntity.class); if(StringUtil.isBlank(recDTO.getDealChain())) { @@ -1366,13 +1380,36 @@ public class ImsDutyRecServiceImpl extends ServiceImpl() {{ + eq(ImsDutyRecEntity::getId, split[1]); + }}); + imsDutyRecEntity.setIsNormal(false); + imsDutyRecEntity.setRemark(JSONObject.toJSONString(processWorkFlowResponse.getVariables())); + imsDutyRecEntity.setDealChain(processWorkFlowResponse.getTaskName()); + imsDutyRecEntity.setProcessInstanceId(processWorkFlowResponse.getTaskId()); + boolean flag = this.updateById(imsDutyRecEntity); + if (!flag){ + log.info("异常状态消息保存失败"+ processWorkFlowResponse); + return R.success("消息保存失败"); + } + return R.fail("消息保存成功"); + } /** * 计算交接班状态 * @param duty 值班信息 diff --git a/hzims-service/operational/src/main/resources/db/3.0.1.sql b/hzims-service/operational/src/main/resources/db/3.0.1.sql index 0dc314e..9ec9561 100644 --- a/hzims-service/operational/src/main/resources/db/3.0.1.sql +++ b/hzims-service/operational/src/main/resources/db/3.0.1.sql @@ -1,5 +1,7 @@ ALTER TABLE `hzims_oper_phenomenon` MODIFY COLUMN `REMARK` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '冗余字段' ; +ALTER TABLE `hzims_oper_phenomenon` + ADD COLUMN `is_normal` tinyint(2) NULL DEFAULT 1 ; ALTER TABLE `hz_ims_duty_rec` ADD COLUMN `is_normal` tinyint(2) NULL DEFAULT 1 ; ALTER TABLE `hzims_oper_access_task` diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/risk/service/impl/HazardTaskServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/risk/service/impl/HazardTaskServiceImpl.java index 7d05dfa..952f6cc 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/risk/service/impl/HazardTaskServiceImpl.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/risk/service/impl/HazardTaskServiceImpl.java @@ -3,6 +3,7 @@ package com.hnac.hzims.safeproduct.risk.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; @@ -159,7 +160,7 @@ public class HazardTaskServiceImpl extends ServiceImpl variables = (Map) processWorkFlowResponse.getVariables(); + //流程找不到下一个审批人处理 + if(ObjectUtils.isNotEmpty(processWorkFlowResponse.getCode())&&700==processWorkFlowResponse.getCode()){ + handException(processWorkFlowResponse); + log.info("风险排查流程补偿流程处理完毕"); + return false; + } // 对象转换 HazardRiskProcessDTO entity = JSONObject.parseObject(JSONObject.toJSONString(variables), new TypeReference(){}); try{ @@ -238,11 +245,7 @@ public class HazardTaskServiceImpl extends ServiceImpl() {{ + eq(HazardTask::getId, split[1]); + }}); + hazardTask.setIsNormal(false); + hazardTask.setProcessInstanceId(processWorkFlowResponse.getTaskId()); + hazardTask.setRemark(JSONObject.toJSONString(processWorkFlowResponse.getVariables())); + hazardTask.setProcessSteps(processWorkFlowResponse.getTaskName()); + hazardTask.setNextStepOperator(""); + this.baseMapper.updateById(hazardTask); + log.info("补偿流程消息转换结束"+ processWorkFlowResponse); + return R.success("补偿流程消息保存成功"); + } /** * 风险评估变量值流程穿插 * @param processWorkFlowResponse From c30bc7dd23c2402859f998a80594d5d926571589 Mon Sep 17 00:00:00 2001 From: ty <1577900710@qq.com> Date: Thu, 22 Aug 2024 15:16:31 +0800 Subject: [PATCH 07/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9A=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=E6=B5=81=E8=A1=A5=E5=81=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scheduled/MaintenanceTaskSchedule.java | 32 +++++++-- .../service/impl/MaintenanceServiceImpl.java | 30 +++++++- .../service/impl/InnerDangerFlowServiceImpl.java | 61 ++++++++++++----- .../repair/service/impl/WorkTaskServiceImpl.java | 56 ++++++++++++--- .../service/impl/OperationTicketServiceImpl.java | 71 +++++++++++++++---- .../service/impl/TicketProcessServiceImpl.java | 79 ++++++++++++++++++---- .../ticket/src/main/resources/db/3.0.0.sql | 4 ++ 7 files changed, 275 insertions(+), 58 deletions(-) diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskSchedule.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskSchedule.java index c40702b..5228a86 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskSchedule.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskSchedule.java @@ -1,12 +1,17 @@ package com.hnac.hzims.operational.maintenance.scheduled; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.hnac.hzims.alarm.config.constants.AlarmHandleConstant; +import com.hnac.hzims.alarm.config.entity.AlarmHandleFlowEntity; import com.hnac.hzims.common.flow.StartProcessService; import com.hnac.hzims.common.logs.utils.StringUtils; import com.hnac.hzims.equipment.entity.EmInfoEntity; import com.hnac.hzims.equipment.feign.IEmInfoClient; +import com.hnac.hzims.middle.process.feign.ICompensateProcessClient; import com.hnac.hzims.operational.constants.FlowKeyConstants; import com.hnac.hzims.operational.constants.RedisKeyConstants; import com.hnac.hzims.operational.duty.entity.ImsDutyMainEntity; @@ -28,6 +33,7 @@ import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.*; import org.springblade.flow.core.entity.BladeFlow; import org.springblade.flow.core.feign.IFlowClient; +import org.springblade.flow.core.utils.FlowUtil; import org.springblade.system.user.cache.UserCache; import org.springblade.system.user.entity.User; import org.springframework.data.redis.core.RedisTemplate; @@ -41,6 +47,7 @@ import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; +import static com.hnac.hzims.operational.constants.FlowKeyConstants.MAINTENANCE_TASK_FLOW_KEY; import static com.hnac.hzims.operational.maintenance.constants.ScheduledConstant.GENERATE_MAINTENANCE_TASK_SCHEDULE; /** @@ -57,6 +64,7 @@ public class MaintenanceTaskSchedule implements StartProcessService { private final IImsDutyMainService dutyMainService; private final RedisTemplate redisTemplate; private final IEmInfoClient emInfoClient; + private final ICompensateProcessClient compensateProcessClient; @XxlJob(GENERATE_MAINTENANCE_TASK_SCHEDULE) public ReturnT execute(String param) throws Exception { @@ -173,10 +181,11 @@ public class MaintenanceTaskSchedule implements StartProcessService { */ private void startProcessInstance(OperMaintenanceTaskEntity task) { String s = saveEntity(JSONObject.toJSONString(task)); - startProcess(s,FlowKeyConstants.MAINTENANCE_TASK_FLOW_KEY,null); + startProcess(s, MAINTENANCE_TASK_FLOW_KEY,null); } @Override + //没有保存多张表,不单独开启事务 public String saveEntity(String entity) { return entity; } @@ -202,8 +211,13 @@ public class MaintenanceTaskSchedule implements StartProcessService { }); put("operMaintenanceTaskEntityVo",vo); }}; - R flowResult = flowClient.startProcessInstanceContainNameByKey(dictValue, String.valueOf(task.getId()), task.getTitle(), params); - if (!flowResult.isSuccess()){ + if (StringUtils.isNotBlank(param)){ + params=JSONObject.parseObject(JSONObject.toJSONStringWithDateFormat(param,DateUtil.PATTERN_DATETIME), Map.class); + } + String businessKey = FlowUtil.getBusinessKey("hzims_oper_maintenance_task", "" +task.getId()); + R flowResult = compensateProcessClient.startFlow(AuthUtil.getUserId().toString(), dictValue, businessKey, task.getTitle(), params); +// R flowResult = flowClient.startProcessInstanceContainNameByKey(dictValue, String.valueOf(task.getId()), task.getTitle(), params); + if (200!=flowResult.getCode()){ task.setIsNormal(false); task.setRemark(JSONObject.toJSONString(params)); taskService.updateById(task); @@ -213,14 +227,22 @@ public class MaintenanceTaskSchedule implements StartProcessService { r.setData(params); log.error(task.getId()+"日常维护任务启动流程失败{}", task); return r; + }else { + task.setIsNormal(true); + task.setProcessInstanceId(flowResult.getData().toString()); + taskService.updateById(task); } - String s = Optional.ofNullable(flowResult).filter(r -> r.isSuccess()).map(R::getData).map(BladeFlow::getProcessInstanceId).orElse(null); + String s = flowResult.getData().toString(); log.info(task.getId()+"日常维护任务启动成功{}", s); return R.success("启动流程成功"); } @Override public R compensationProcess(String id) { - return null; + OperMaintenanceTaskEntity operMaintenanceTaskEntity = taskService.getById(id); + if (ObjectUtils.isNotEmpty(operMaintenanceTaskEntity)){ + return this.startProcess(JSON.toJSONString(operMaintenanceTaskEntity), MAINTENANCE_TASK_FLOW_KEY,operMaintenanceTaskEntity.getRemark()); + } + return R.fail("找不到对应流程数据,请稍后重试!"); } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceServiceImpl.java index 5c0b65e..a786d50 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceServiceImpl.java @@ -10,6 +10,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.hnac.hzims.common.logs.utils.StringUtils; import com.hnac.hzims.common.utils.DateUtil; import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse; +import com.hnac.hzims.operational.access.entity.OperAccessPlanEntity; import com.hnac.hzims.operational.duty.entity.ImsDutyMainEntity; import com.hnac.hzims.operational.duty.service.IImsDutyMainService; import com.hnac.hzims.operational.maintenance.entity.OperMaintenancePlanEntity; @@ -125,12 +126,17 @@ public class MaintenanceServiceImpl implements MaintenanceService { log.error("获取表单出现异常了~~~~"+response); throw new IllegalArgumentException(e.getMessage()); } + if(ObjectUtils.isNotEmpty(response.getCode())&&700==response.getCode()){ + handException(response); + return; + } OperMaintenanceTaskEntity entity = new OperMaintenanceTaskEntity(); BeanUtils.copyProperties(standardTicketInfoVo, entity); //1.查询日常维护信息 //有Id才进行生成操作 if (StringUtils.isNotBlank(response.getBusinessKey())) { - Long id = NumberUtils.toLong(response.getBusinessKey()); + String str = response.getBusinessKey().split(":")[1]; + Long id = NumberUtils.toLong(str); OperMaintenanceTaskEntity dbOperMaintenanceTaskEntity = taskService.getById(id); if (ObjectUtils.isEmpty(dbOperMaintenanceTaskEntity)) { log.error("获取日常维护数据不存在" + response); @@ -178,6 +184,28 @@ public class MaintenanceServiceImpl implements MaintenanceService { } } + private R handException(ProcessWorkFlowResponse response) { + String[] split = response.getBusinessKey().split(":"); + if (StringUtils.isBlank(split[1])){ + log.error("异常消息转换失败,未找到BusinessKey:"+ response); + return R.fail("异常消息处理失败"); + } + OperMaintenanceTaskEntity entity = taskService.getOne(new LambdaQueryWrapper() {{ + eq(OperMaintenanceTaskEntity::getId, split[1]); + }}); + entity.setIsNormal(false); + entity.setRemark(JSONObject.toJSONString(response.getVariables())); + entity.setFlowTaskName(response.getTaskName()); + entity.setProcessInstanceId(response.getTaskId()); + entity.setNextStepOperator(""); + boolean flag = taskService.updateById(entity); + if (!flag){ + log.info("异常状态消息保存失败"+ response); + return R.success("消息保存失败"); + } + return R.fail("消息保存成功"); + } + /** * 填充日常维护信息 diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/flow/service/impl/InnerDangerFlowServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/flow/service/impl/InnerDangerFlowServiceImpl.java index 513b05c..d9110cf 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/flow/service/impl/InnerDangerFlowServiceImpl.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/flow/service/impl/InnerDangerFlowServiceImpl.java @@ -13,7 +13,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.hnac.hzims.common.flow.StartProcessService; import com.hnac.hzims.common.logs.utils.StringUtils; +import com.hnac.hzims.middle.process.feign.ICompensateProcessClient; import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse; +import com.hnac.hzims.operational.access.entity.OperAccessPlanEntity; import com.hnac.hzims.safeproduct.dto.InnerDangerDTO; import com.hnac.hzims.safeproduct.entity.InnerDangerEntity; import com.hnac.hzims.safeproduct.flow.mapper.InnerDangerMapper; @@ -31,6 +33,7 @@ import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.Func; import org.springblade.flow.core.entity.BladeFlow; import org.springblade.flow.core.feign.IFlowClient; +import org.springblade.flow.core.utils.FlowUtil; import org.springblade.message.dto.BusinessMessageDTO; import org.springblade.message.fegin.IMessageClient; import org.springblade.system.feign.ISysClient; @@ -61,6 +64,8 @@ public class InnerDangerFlowServiceImpl extends ServiceImpl" + innerDangerEntity.getHiddenDangerName(); // 开启新的隐患处理流程 Map variable = JSONObject.parseObject(JSONObject.toJSONStringWithDateFormat(innerDangerVo, DateUtil.PATTERN_DATETIME), Map.class); - R result = processClient.startProcessInstanceContainNameByKey(dictValue, innerDangerVo.getId().toString(), processName, variable); + R result = compensateProcessClient.startFlow(AuthUtil.getUserId().toString(), + dictValue, FlowUtil.getBusinessKey("hzims_inner_danger_info", String.valueOf(innerDangerVo.getId())), + processName, variable); // 流程开启失败 - if (!result.isSuccess()) { + if (200!=result.getCode()) { innerDangerEntity.setIsNormal(false); innerDangerEntity.setRemark(JSONObject.toJSONString(variable)); - this.baseMapper.updateById(innerDangerVo); + this.baseMapper.updateById(innerDangerEntity); log.error("隐患处理流程开启失败,错误描述 : {}", result); R r=new R(); r.setCode(result.getCode()); @@ -146,19 +145,28 @@ public class InnerDangerFlowServiceImpl extends ServiceImpl() {{ eq(InnerDangerEntity::getCode, hiddenDangerVo.getCode()); last("limit 1"); @@ -193,6 +204,21 @@ public class InnerDangerFlowServiceImpl extends ServiceImpl getHiddenDangerBase(HiddenDangerBaseVo hiddenDangerBaseVo, Query query) { InnerDangerEntity innerDangerEntity = new InnerDangerEntity(); @@ -292,6 +318,7 @@ public class InnerDangerFlowServiceImpl extends ServiceImpl()); } + return iPage; } diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/repair/service/impl/WorkTaskServiceImpl.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/repair/service/impl/WorkTaskServiceImpl.java index 6302741..d3cfa36 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/repair/service/impl/WorkTaskServiceImpl.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/repair/service/impl/WorkTaskServiceImpl.java @@ -2,13 +2,18 @@ package com.hnac.hzims.ticket.repair.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.hnac.hzims.common.constant.CommonConstant; import com.hnac.hzims.common.flow.StartProcessService; +import com.hnac.hzims.common.logs.utils.StringUtils; +import com.hnac.hzims.middle.process.feign.ICompensateProcessClient; import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse; +import com.hnac.hzims.operational.access.entity.OperAccessPlanEntity; import com.hnac.hzims.ticket.repair.constants.WorkTaskConstants; import com.hnac.hzims.ticket.repair.entity.WorkTaskEntity; import com.hnac.hzims.ticket.repair.mapper.WorkTaskMapper; @@ -42,6 +47,8 @@ import org.springblade.system.user.entity.User; import org.springblade.system.user.feign.IUserClient; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.support.TransactionTemplate; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; @@ -58,6 +65,8 @@ public class WorkTaskServiceImpl extends ServiceImpl variables = JSONObject.parseObject(JSONObject.toJSONStringWithDateFormat(workTask, DateUtil.PATTERN_DATETIME), Map.class); + Map variables; + if (StringUtil.isNotBlank(param)) { + variables = JSONObject.parseObject(JSONObject.toJSONStringWithDateFormat(param, DateUtil.PATTERN_DATETIME), Map.class); + }else { + variables = JSONObject.parseObject(JSONObject.toJSONStringWithDateFormat(workTask, DateUtil.PATTERN_DATETIME), Map.class); + } variables.put("head", TaskUtil.getTaskUser(String.valueOf(workTask.getHead()))); // 班组成员 String[] member = workTask.getMember().split(","); @@ -139,13 +157,16 @@ public class WorkTaskServiceImpl extends ServiceImpl result = flowClient.startProcessInstanceContainNameByKey(dictValue, FlowUtil.getBusinessKey("work_task_v4",String.valueOf(workTask.getId())), workTask.getCode(), variables); + R result = compensateProcessClient.startFlow(AuthUtil.getUserId().toString(), + dictValue,FlowUtil.getBusinessKey("work_task_v4",String.valueOf(workTask.getId())) + , workTask.getCode(), variables); log.error("work_task_start_process_result :{}",result); // 更新任务流程Id - if (result.isSuccess()) { - BladeFlow flow = result.getData(); - workTask.setProcessInstanceId(flow.getProcessInstanceId()); + if (200==result.getCode()) { + workTask.setIsNormal(true); + workTask.setProcessInstanceId(result.getData().toString()); this.updateById(workTask); + return R.success("启动流程成功"); } else { workTask.setIsNormal(false); workTask.setRemark(JSONObject.toJSONString(variables)); @@ -156,7 +177,6 @@ public class WorkTaskServiceImpl extends ServiceImpl variables = (Map) processWorkFlowResponse.getVariables(); + if(ObjectUtils.isNotEmpty(processWorkFlowResponse.getCode())&&700==processWorkFlowResponse.getCode()){ + handException(processWorkFlowResponse); + return false; + } log.error("work_task_listener_variables : {}",variables); Object head = variables.get("head"); if(ObjectUtil.isNotEmpty(head)){ @@ -176,6 +200,7 @@ public class WorkTaskServiceImpl extends ServiceImpl(){}); // 当前流程名称 entity.setTaskName(processWorkFlowResponse.getTaskName()); + entity.setIsNormal(true); // 流程阶段执行人员名称 entity.setNextStepOperator(processWorkFlowResponse.getNextStepOperator()); entity.setHeadHandleTime(new Date()); @@ -198,6 +223,21 @@ public class WorkTaskServiceImpl extends ServiceImpl { //3. 保存操作对象 StandardTicketInfoEntity standardTicketInfo = getStandardTicketInfoEntity(standardTicketInfoVo); standardTicketInfo.setStatus(1); @@ -167,6 +179,8 @@ public class OperationTicketServiceImpl implements OperationTicketService , Star standardTicketInfoVo.setStandardTicketMeasureVos(standardTicketInfoVos); log.info("保存操作对象 :{}", standardTicketInfoVo); return JSON.toJSONString(standardTicketInfoVo); + }); + return res; } @@ -175,20 +189,23 @@ public class OperationTicketServiceImpl implements OperationTicketService , Star public R startProcess(String entity, String dictValue,String param) { StandardTicketInfoVo standardTicketInfoVo= JSONObject.parseObject(entity, StandardTicketInfoVo.class); StandardTicketInfoEntity standardTicketInfoEntity = getStandardTicketInfoEntity(standardTicketInfoVo); - Instant start = Instant.now(); Map params = new HashMap<>(4); params.put("standardTicketInfoVo", standardTicketInfoVo); params.put("taskId", standardTicketInfoVo.getId()); if (ObjectUtils.isNotEmpty(standardTicketInfoVo.getGuardian())) { params.put("guardianUserIds", "taskUser_".concat(standardTicketInfoVo.getGuardian().toString())); } + if (StringUtils.isNotBlank(param)){ + params=JSONObject.parseObject(JSONObject.toJSONStringWithDateFormat(param, DateUtil.PATTERN_DATETIME), Map.class); + } //已开启流程 - R processInstanceContainNameByKey = flowClient.startProcessInstanceContainNameByKey(dictValue, String.valueOf(standardTicketInfoVo.getId()), - standardTicketInfoVo.getTitle(), params); - if (!processInstanceContainNameByKey.isSuccess()) { + R processInstanceContainNameByKey = compensateProcessClient.startFlow(AuthUtil.getUserId().toString(), + dictValue, FlowUtil.getBusinessKey("hzims_standard_ticket_info", + String.valueOf(standardTicketInfoVo.getId())),standardTicketInfoVo.getTitle(), params); + if (200!=processInstanceContainNameByKey.getCode()) { standardTicketInfoEntity.setIsNormal(false); standardTicketInfoEntity.setRemarkFlow(JSONObject.toJSONString(params)); - standardTicketInfoService.save(standardTicketInfoEntity); + standardTicketInfoService.updateById(standardTicketInfoEntity); R r=new R(); r.setCode(processInstanceContainNameByKey.getCode()); r.setMsg(processInstanceContainNameByKey.getMsg()); @@ -196,17 +213,21 @@ public class OperationTicketServiceImpl implements OperationTicketService , Star log.error("开启流程失败 {}", processInstanceContainNameByKey.getMsg()); return r; } - Duration between = Duration.between(start, Instant.now()); - log.info("================================================================"); - log.info("耗时: " + (between.getSeconds()) + "秒"); - log.info("耗时: " + (between.toMillis()) + "毫秒"); - log.info("================================================================"); + standardTicketInfoEntity.setProcessInstanceId(processInstanceContainNameByKey.getData().toString()); + standardTicketInfoEntity.setIsNormal(true); + standardTicketInfoService.updateById(standardTicketInfoEntity); return R.success("启动流程成功"); } @Override public R compensationProcess(String id) { - return null; + //查询流程对应value + String dictValue = processDictFeignService.selectDictValueByKey(OPERATION_TICKET_KEY); + StandardTicketInfoEntity entity = standardTicketInfoService.getById(id); + if (ObjectUtils.isNotEmpty(entity)){ + return this.startProcess(JSON.toJSONString(entity), dictValue,entity.getRemark()); + } + return R.fail("找不到对应流程数据,请稍后重试!"); } /** @@ -227,6 +248,10 @@ public class OperationTicketServiceImpl implements OperationTicketService , Star String formData = JSON.toJSONString(response.getVariables()); log.info("获取表单的数据:{}", formData); StandardTicketInfoVo standardTicketInfoVo = null; + if(ObjectUtils.isNotEmpty(response.getCode())&&700==response.getCode()){ + handException(response); + return ; + } try { JSONObject jsonObject = JSONObject.parseObject(formData); // standardTicketInfoVo = JSONObject.toJavaObject(jsonObject, StandardTicketInfoVo.class); @@ -238,6 +263,7 @@ public class OperationTicketServiceImpl implements OperationTicketService , Star e.printStackTrace(); throw new IllegalArgumentException(e.getMessage()); } + //1.查询操作票信息 Long id = NumberUtils.toLong(response.getBusinessKey()); StandardTicketInfoEntity standardTicketInfoEntity = standardTicketInfoService.getById(id); @@ -310,6 +336,27 @@ public class OperationTicketServiceImpl implements OperationTicketService , Star } } + private R handException(ProcessWorkFlowResponse processWorkFlowResponse) { + String[] split = processWorkFlowResponse.getBusinessKey().split(":"); + if (StringUtils.isBlank(split[1])){ + log.error("异常消息转换失败,未找到BusinessKey:"+ processWorkFlowResponse); + return R.fail("异常消息处理失败"); + } + StandardTicketInfoEntity entity = standardTicketInfoService.getOne(new LambdaQueryWrapper() {{ + eq(StandardTicketInfoEntity::getId, split[1]); + }}); + entity.setIsNormal(false); + entity.setRemark(JSONObject.toJSONString(processWorkFlowResponse.getVariables())); + entity.setTaskName(processWorkFlowResponse.getTaskName()); + entity.setProcessInstanceId(processWorkFlowResponse.getTaskId()); + entity.setNextStepOperator(""); + boolean flag = standardTicketInfoService.updateById(entity); + if (!flag){ + log.info("异常状态消息保存失败"+ processWorkFlowResponse); + return R.success("消息保存失败"); + } + return R.fail("消息保存成功"); + } /** * 填充数据 diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketProcessServiceImpl.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketProcessServiceImpl.java index 994bd28..c875b77 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketProcessServiceImpl.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketProcessServiceImpl.java @@ -3,13 +3,16 @@ package com.hnac.hzims.ticket.twoTicket.service.impl; import cn.afterturn.easypoi.word.WordExportUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.hnac.hzims.common.flow.StartProcessService; import com.hnac.hzims.common.logs.utils.StringUtils; +import com.hnac.hzims.middle.process.feign.ICompensateProcessClient; import com.hnac.hzims.middle.process.feign.ProcessDictFeignService; import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse; +import com.hnac.hzims.operational.access.entity.OperAccessPlanEntity; import com.hnac.hzims.operational.access.entity.OperAccessTaskEntity; import com.hnac.hzims.operational.access.feign.IOperAccessTaskClient; import com.hnac.hzims.operational.feign.IAccessTaskClient; @@ -51,6 +54,7 @@ import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.core.tool.utils.StringUtil; import org.springblade.flow.core.entity.BladeFlow; import org.springblade.flow.core.feign.IFlowClient; +import org.springblade.flow.core.utils.FlowUtil; import org.springblade.message.MessageConstants; import org.springblade.message.dto.BusinessMessageDTO; import org.springblade.message.fegin.IMessageClient; @@ -60,7 +64,9 @@ import org.springblade.system.user.entity.User; import org.springblade.system.user.feign.IUserClient; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.support.TransactionTemplate; import org.springframework.util.Assert; import javax.servlet.ServletOutputStream; @@ -140,6 +146,7 @@ public class TicketProcessServiceImpl implements TicketProcessService, StartProc @Value("${hzims.ticket.path.word.templatePath}") private String templatePath; + private final ICompensateProcessClient compensateProcessClient; private final TicketInfoDangerService ticketInfoDangerService; @@ -162,7 +169,7 @@ public class TicketProcessServiceImpl implements TicketProcessService, StartProc */ // @SneakyThrows @Override - @Transactional +// @Transactional public R startUp(WorkTicketVo workTicketVo) { log.info("ticket:start:request",JSON.toJSONString(workTicketVo)); log.info("执行 com.hnac.hzims.ticket.twoTicket.service.impl【startUp】 。。。方法"); @@ -179,7 +186,8 @@ public class TicketProcessServiceImpl implements TicketProcessService, StartProc R r = this.startProcess(saveEntity, dictValue,""); return r; } - + private final PlatformTransactionManager transactionManager; + private final TransactionTemplate transactionTemplate; @Override public String saveEntity(String entity) { WorkTicketVo workTicketVo= JSONObject.parseObject(entity, WorkTicketVo.class); @@ -208,7 +216,6 @@ public class TicketProcessServiceImpl implements TicketProcessService, StartProc throw new ServiceException("票据抬头未配置,请您到站点管理配置"); } //signage = signage.length() == 2 ? station.getSignage() : station.getSignage().substring(0, 2); - workTicketVo.getWorkTicket().setSignage(station.getSignage()); workTicketVo.getWorkTicket().setSignageCode(station.getCode()); //2. 获取编码 @@ -217,6 +224,8 @@ public class TicketProcessServiceImpl implements TicketProcessService, StartProc if (StringUtils.isBlank(code)) { throw new ServiceException("服务器异常,请联系管理员"); } + transactionTemplate.setTransactionManager(transactionManager); + String res = transactionTemplate.execute(status -> { workTicketVo.getWorkTicket().setCode(code); //保存工作对象 log.info("ticket:start:vo",JSON.toJSONString(workTicketVo.getWorkTicket())); @@ -231,6 +240,8 @@ public class TicketProcessServiceImpl implements TicketProcessService, StartProc //保存工作任务 this.saveWorkTicketContentDto(workTicketVo.getWorkTicketContentDtoList(), workTicketVo.getWorkTicket()); return JSONObject.toJSONString(workTicketVo); + }); + return res; } @@ -245,7 +256,7 @@ public class TicketProcessServiceImpl implements TicketProcessService, StartProc if (status.intValue() != workTicketVo.getWorkTicket().getFlowStatus().intValue()) { return R.success("线下流程,开票成功"); } - Map params = new HashMap<>(4); + Map params = new HashMap<>(); params.put("workTicketVo", workTicketVo); //获取当前登录人 Long userId = AuthUtil.getUserId(); @@ -255,7 +266,10 @@ public class TicketProcessServiceImpl implements TicketProcessService, StartProc params.put("principal", "taskUser_" + workTicketVo.getWorkTicket().getPrincipal()); } //已开启流程 - R processInstanceContainNameByKey = flowClient.startProcessInstanceContainNameByKey(dictValue, String.valueOf(workTicketVo.getWorkTicket().getId()), workTicketVo.getWorkTicket().getWorkContent(), params); + R processInstanceContainNameByKey = compensateProcessClient.startFlow( + AuthUtil.getUserId().toString(),dictValue, + FlowUtil.getBusinessKey("hzims_work_ticket_info",String.valueOf(workTicketVo.getWorkTicket().getId())), + workTicketVo.getWorkTicket().getWorkContent(),params); log.info("processInstanceContainNameByKey.isSuccess() : {}", processInstanceContainNameByKey.isSuccess()); if (!processInstanceContainNameByKey.isSuccess()) { //保存流程开始失败情况 @@ -272,20 +286,24 @@ public class TicketProcessServiceImpl implements TicketProcessService, StartProc r.setMsg("流程开启失败,请检查流程和用户权限后重试!"); r.setData(params); return r; + }else { + workTicket.setProcessInstanceId(processInstanceContainNameByKey.getData().toString()); + workTicket.setIsNormal(true); + firstWorkTicketService.updateById(workTicket); + return R.success("启动流程成功"); } - log.info("获取启动流程数据 : {}", processInstanceContainNameByKey); - Duration between = Duration.between(start, Instant.now()); - - log.info("================================================================"); - log.info("耗时: " + (between.getSeconds()) + "秒"); - log.info("耗时: " + (between.toMillis()) + "毫秒"); - log.info("================================================================"); - return R.success("启动流程成功"); } @Override public R compensationProcess(String id) { - return null; + WorkTicketInfoEntity entity = firstWorkTicketService.getById(id); + if (ObjectUtils.isNotEmpty(entity)){ + WorkTicketVo workTicketVo = new WorkTicketVo(); + workTicketVo.setWorkTicket(entity); + String dictValue = getDictValue(workTicketVo); + return this.startProcess(JSON.toJSONString(entity), dictValue,entity.getRemark()); + } + return R.fail("找不到对应流程数据,请稍后重试!"); } /** @@ -321,7 +339,6 @@ public class TicketProcessServiceImpl implements TicketProcessService, StartProc @Override @Transactional(rollbackFor = Exception.class) public void findPending(ProcessWorkFlowResponse response) { - try { log.info("获取待处理的数据 {}", response); log.info("获取businessKey: {}", response.getBusinessKey()); @@ -332,6 +349,10 @@ public class TicketProcessServiceImpl implements TicketProcessService, StartProc log.info("获取根据handleType区分是用户还是候选组角色: {}", response.getHandleType()); //json转换表单 String formData = JSON.toJSONString(response.getVariables()); + if(ObjectUtils.isNotEmpty(response.getCode())&&700==response.getCode()){ + handException(response); + return ; + } log.info("获取表单的数据:{}", formData); FristWorkTicketVo fristWorkFlowResponse = null; try { @@ -343,6 +364,7 @@ public class TicketProcessServiceImpl implements TicketProcessService, StartProc //获取表单数据 WorkTicketVo workTicketVo = fristWorkFlowResponse.getWorkTicketVo(); WorkTicketInfoEntity workTicket = workTicketVo.getWorkTicket(); + workTicket.setIsNormal(true); //2.流程处理 String businessKey = response.getBusinessKey(); WorkTicketInfoEntity workTicketInfo = ticketInfoService.getById(businessKey); @@ -503,10 +525,33 @@ public class TicketProcessServiceImpl implements TicketProcessService, StartProc } } catch (Exception e) { e.printStackTrace(); + log.error("工作票流转失败,失败原因:{}",e); } } + private R handException(ProcessWorkFlowResponse processWorkFlowResponse) { + String[] split = processWorkFlowResponse.getBusinessKey().split(":"); + if (StringUtils.isBlank(split[1])){ + log.error("异常消息转换失败,未找到BusinessKey:"+ processWorkFlowResponse); + return R.fail("异常消息处理失败"); + } + WorkTicketInfoEntity workTicketInfoEntity = ticketInfoService.getOne(new LambdaQueryWrapper() {{ + eq(WorkTicketInfoEntity::getId, split[1]); + }}); + workTicketInfoEntity.setIsNormal(false); + workTicketInfoEntity.setRemark(JSONObject.toJSONString(processWorkFlowResponse.getVariables())); + workTicketInfoEntity.setTaskName(processWorkFlowResponse.getTaskName()); + workTicketInfoEntity.setProcessInstanceId(processWorkFlowResponse.getTaskId()); + workTicketInfoEntity.setNextStepOperator(""); + boolean flag = ticketInfoService.updateById(workTicketInfoEntity); + if (!flag){ + log.info("异常状态消息保存失败"+ processWorkFlowResponse); + return R.success("消息保存失败"); + } + return R.fail("消息保存成功"); + } + @Override public Boolean offlineTicketFindPending(ProcessWorkFlowResponse response) { log.info("线下工作票接收到的工作票数据为:{}",JSON.toJSONString(response)); @@ -515,6 +560,10 @@ public class TicketProcessServiceImpl implements TicketProcessService, StartProc log.error("接收到的数据为:{}",JSON.toJSONString(response.getVariables())); throw new ServiceException("线下工作票处理流程环节接收数据失败,请联系管理员"); }); + if(ObjectUtils.isNotEmpty(response.getCode())&&700==response.getCode()){ + handException(response); + return false; + } WorkTicketVo workTicketVo = ticketResponse.getWorkTicketVo(); WorkTicketInfoEntity workTicket = workTicketVo.getWorkTicket(); WorkTicketInfoEntity info = firstWorkTicketService.getById(workTicket.getId()); diff --git a/hzims-service/ticket/src/main/resources/db/3.0.0.sql b/hzims-service/ticket/src/main/resources/db/3.0.0.sql index 983e8e9..f4ac06d 100644 --- a/hzims-service/ticket/src/main/resources/db/3.0.0.sql +++ b/hzims-service/ticket/src/main/resources/db/3.0.0.sql @@ -2,11 +2,15 @@ ALTER TABLE `hzims_standard_ticket_info` ADD COLUMN `remark_flow` text NULL ; ALTER TABLE `hzims_work_ticket_info` ADD COLUMN `remark` text NULL ; +ALTER TABLE `hzims_work_task` + ADD COLUMN `remark` text NULL ; ALTER TABLE `hzims_standard_ticket_info` ADD COLUMN `is_normal` tinyint(2) NULL DEFAULT 1 ; ALTER TABLE `hzims_work_ticket_info` ADD COLUMN `is_normal` tinyint(2) NULL DEFAULT 1 ; +ALTER TABLE `hzims_work_task` + ADD COLUMN `is_normal` tinyint(2) NULL DEFAULT 1 ; ALTER TABLE `hzims_standard_ticket_info` ADD COLUMN `em_code` varchar(255) NULL COMMENT '设备编号' , From 7092f66b538f38b789f74d272ff355527e0153df Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Wed, 28 Aug 2024 08:33:34 +0800 Subject: [PATCH 08/19] =?UTF-8?q?fix:=20=E4=B8=B4=E6=97=B6=E6=8F=90?= =?UTF-8?q?=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/service/DataSourceService.java | 5 +- .../bigmodel/database/service/WeaviateService.java | 87 +++++++++++++++++++--- .../controller/FontEndInteractiveController.java | 2 +- .../interactive/service/IHznlmInvokeService.java | 2 + .../service/impl/HznlmInvokeServiceImpl.java | 28 +++++++ .../inspect/obj/mapper/ObjectTemplateMapper.xml | 2 +- 6 files changed, 114 insertions(+), 12 deletions(-) diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/DataSourceService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/DataSourceService.java index c616d0a..ac1c3c8 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/DataSourceService.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/DataSourceService.java @@ -58,7 +58,10 @@ public class DataSourceService { throw new HzServiceException(ResultCode.FAILURE,"查询语句中存在未进行鉴权的表,查询失败!"); }); if("1".equals(propertise.get(0).getAuthType())) { - String tableSubStr = "(SELECT * FROM " + tableAuthVO.getTableName() + " where" + userAuthDataSQL +") temp"; + String tableSubStr = "(SELECT * FROM " + tableAuthVO.getTableName() + " where is_deleted = 0 and " + userAuthDataSQL +") temp"; + sql = sql.replace(tableAuthVO.getTableName(),tableSubStr); + } else { + String tableSubStr = "(SELECT * FROM " + tableAuthVO.getTableName() + " where is_deleted = 0) temp"; sql = sql.replace(tableAuthVO.getTableName(),tableSubStr); } } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/database/service/WeaviateService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/database/service/WeaviateService.java index 931a6a8..cbc926b 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/database/service/WeaviateService.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/database/service/WeaviateService.java @@ -6,28 +6,26 @@ import cn.hutool.json.JSONUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.google.common.collect.Lists; -import com.google.protobuf.ServiceException; import com.hnac.hzims.bigmodel.configuration.BigModelInvokeApi; import com.hnac.hzinfo.exception.HzServiceException; import io.weaviate.client.base.Result; import io.weaviate.client.v1.data.api.ObjectCreator; import io.weaviate.client.v1.data.api.ObjectDeleter; import io.weaviate.client.v1.data.api.ObjectUpdater; +import io.weaviate.client.v1.data.api.ObjectsGetter; import io.weaviate.client.v1.data.model.WeaviateObject; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.tool.utils.BeanUtil; import org.springblade.core.tool.utils.Func; -import org.springblade.core.tool.utils.StringUtil; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; -import org.springframework.util.Assert; import java.lang.reflect.Field; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.*; -import java.util.stream.Collector; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -43,9 +41,11 @@ public class WeaviateService { private final ObjectCreator objectCreator; private final ObjectUpdater objectUpdater; private final ObjectDeleter objectDeleter; + private final ObjectsGetter objectsGetter; private final BigModelInvokeApi invokeApi; + @Value("${gglm.vectorUrl}") - private final String vectorUrl; + private String vectorUrl; /** * 对象保存向量数据库 @@ -89,7 +89,10 @@ public class WeaviateService { if(Func.isNotEmpty(vectorStrs)) { // 若解析出来的向量存在值 Float[] vectors = this.compute(vectorStrs); - + List> vector = this.splitVector(entities.size(), attrsMap, vectors); + for(int i = 0; i < entities.size(); i++) { + creator.withProperties(BeanUtil.toMap(entities.get(i))).withVectors(vector.get(i)).run(); + } } else { entities.forEach(entity -> creator.withProperties(BeanUtil.toMap(entity)).run()); return true; @@ -98,6 +101,63 @@ public class WeaviateService { } /** + * 删除向量数据库(表名) + * @param className 表名 + * @return 删除结果 + */ + public Boolean deleteByClassName(String className) { + Result result = objectDeleter.withClassName(className).run(); + return !result.hasErrors(); + } + + /** + * 删除向量数据库(ID) + * @param id 向量数据库ID + * @return 删除结果 + */ + public Boolean deleteById(String id) { + Result result = objectDeleter.withID(id).run(); + return !result.hasErrors(); + } + + /** + * 更新数据库(通过ID) + * @param id 向量数据库ID + * @return 更新结果 + */ + public Boolean updateById(String id, Object entity, String className, Map attrMap) { + ObjectUpdater updater = objectUpdater.withClassName(className).withID(id).withProperties(BeanUtil.toMap(entity)); + // 计算向量 + Map vector = new HashMap<>(); + if(Func.isNotEmpty(attrMap)) { + attrMap.forEach((k,v) -> { + String fieldValue = this.getFieldValue(v, entity); + Float[] compute = this.compute(Lists.newArrayList(fieldValue)); + vector.put(k,compute); + }); + } + if(Func.isNotEmpty(vector)) { + updater.withVectors(vector); + } + Result result = updater.run(); + return !result.hasErrors(); + } + + public List list(String id,String className) { + if(Func.isNotEmpty(id)) { + objectsGetter.withID(id); + } + if(Func.isNotEmpty(className)) { + objectsGetter.withClassName(className); + } + Result> result = objectsGetter.run(); + if(result.hasErrors()) { + throw new HzServiceException("查询失败!"); + } + return result.getResult().stream().map(WeaviateObject::getProperties).collect(Collectors.toList()); + } + + /** * 拆解计算出来的向量Float[] * @param entitySize 对象列表size * @param attrsMap 待计算的列信息 key-向量名 value-实体类对象属性,多个按逗号分隔 @@ -106,13 +166,22 @@ public class WeaviateService { */ private List> splitVector(Integer entitySize,Map attrsMap,Float[] vectorTotal) { List> result = Lists.newArrayList(); - + List vectorTotalList = Lists.newArrayList(vectorTotal); // 获取待切割的下标 List indexes = this.getSplitIndex(vectorTotal.length, entitySize); + int step = vectorTotal.length / entitySize; indexes.forEach(index -> { - + List vectors = vectorTotalList.subList(index, index + step); + Map vectorMap = new HashMap<>(); + List splitIndex = this.getSplitIndex(vectors.size(), attrsMap.size()); + AtomicInteger i = new AtomicInteger(); + attrsMap.forEach((k,v) -> { + List vector = vectors.subList(splitIndex.get(i.get()), splitIndex.get(i.get() + (vectors.size() / attrsMap.size()))); + vectorMap.put(k, vector.toArray(new Float[vector.size()])); + i.getAndIncrement(); + }); }); - return null; + return result; } /** diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/FontEndInteractiveController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/FontEndInteractiveController.java index 21b05f4..b7cab25 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/FontEndInteractiveController.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/FontEndInteractiveController.java @@ -64,7 +64,7 @@ public class FontEndInteractiveController { @ApiOperationSupport(order = 5) @GetMapping("/interruptSession") public R interruptSession(@RequestParam(value = "id") String sessionId) { - hznlmInvokeService.askAbort(sessionId); + hznlmInvokeService.interruptSession(sessionId); return R.success("操作成功!"); } } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInvokeService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInvokeService.java index 51ed3f3..2ef2107 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInvokeService.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInvokeService.java @@ -81,6 +81,8 @@ public interface IHznlmInvokeService { */ void askAbort(String sessionId); + void interruptSession(String sessionId); + /** * 发起机组发电量智能报表分析问答 * @param req 待分析的数据 diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java index b8bdb15..48e9881 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java @@ -17,6 +17,7 @@ import com.hnac.hzims.bigmodel.utils.RequestClientUtil; import com.hnac.hzims.bigmodel.websocket.constants.RedisKeyConstants; import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager; import com.hnac.hzims.common.constant.CommonConstant; +import com.hnac.hzinfo.exception.HzServiceException; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.tool.api.R; @@ -126,6 +127,33 @@ public class HznlmInvokeServiceImpl implements IHznlmInvokeService { sessionRedisManager.removeSessionId(sessionId); } + public void interruptSession(String sessionId) { + this.askAbort(sessionId); + // 循环获取该会话ID中断状态,当状态等于-2或重连超6次则中断返回结果 + int status = 999; + int attempts = 0; + while (status > 0) { + // 若重连超过10次 则抛出错误 + if(attempts >= 8) { + throw new HzServiceException("中断失败!长时间未获取到中断状态"); + } + List answers = this.getAnswerBySessionIds(sessionId); + if(Func.isNotEmpty(answers)) { + log.info(answers.get(0).getStatus()+""); + status = answers.get(0).getStatus(); + } + // 若获取到的状态不等于2 则延时0.5秒 + if(status > 0) { + try { + Thread.sleep(500); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + attempts ++; + } + } + @Override public void smartReportGeneratePower(RunReportAnalyseRequest req) { Map params = new HashMap<>(); diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/mapper/ObjectTemplateMapper.xml b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/mapper/ObjectTemplateMapper.xml index 6136502..8220245 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/mapper/ObjectTemplateMapper.xml +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/mapper/ObjectTemplateMapper.xml @@ -3,7 +3,7 @@