yang_shj
4 months ago
26 changed files with 222 additions and 925 deletions
@ -1,37 +0,0 @@
|
||||
package com.hnac.hzims.bigmodel.data.controller; |
||||
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
||||
import com.hnac.hzims.bigmodel.BigModelConstants; |
||||
import com.hnac.hzims.bigmodel.data.service.RemoteService; |
||||
import com.hnac.hzinfo.log.annotation.Business; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
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 = "数据平台遥控指令管理") |
||||
@Business(module = BigModelConstants.APP_NAME,value = "数据平台遥控指令管理") |
||||
public class RemoteController { |
||||
|
||||
private final RemoteService remoteService; |
||||
|
||||
@ApiOperation("下发遥控指令") |
||||
@ApiOperationSupport(order = 1) |
||||
@PostMapping("/sendRemoteControl") |
||||
public R<Object> sendRemoteControl(ControlDTO controlDTO) { |
||||
return remoteService.sendRemoteControl(controlDTO); |
||||
} |
||||
|
||||
} |
@ -1,97 +0,0 @@
|
||||
package com.hnac.hzims.bigmodel.data.service; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import com.google.common.collect.Lists; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.DataMethodEnum; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.DateEnum; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.HistoryDataSearchVO; |
||||
import com.hnac.hzinfo.sdk.core.response.Result; |
||||
import com.hnac.hzinfo.sdk.v5.device.DeviceDataClient; |
||||
import com.hnac.hzinfo.sdk.v5.device.dto.ReductionAttrDataDTO; |
||||
import com.hnac.hzinfo.sdk.v5.device.dto.ReductionDataDTO; |
||||
import com.hnac.hzinfo.sdk.v5.device.vo.ReductionDataVO; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springblade.core.log.exception.ServiceException; |
||||
import org.springblade.core.log.logger.BladeLogger; |
||||
import org.springblade.core.tool.utils.DateUtil; |
||||
import org.springblade.core.tool.utils.Func; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.util.Assert; |
||||
|
||||
import java.time.Duration; |
||||
import java.time.LocalDateTime; |
||||
import java.time.temporal.ChronoUnit; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/24 14:57 |
||||
*/ |
||||
@Service |
||||
@Slf4j |
||||
@AllArgsConstructor |
||||
public class HistoryDataService { |
||||
|
||||
private final DeviceDataClient deviceDataClient; |
||||
private final BladeLogger logger; |
||||
public static final int DATA_COUNT_MAX = 1000; |
||||
|
||||
public Result<ReductionDataVO> getPolymerizationData(HistoryDataSearchVO searchVO) { |
||||
DataMethodEnum enumByMethod = DataMethodEnum.getEnumByMethod(searchVO.getMethod()); |
||||
Assert.isTrue(Func.isNotEmpty(enumByMethod),() -> { |
||||
throw new ServiceException("数据查询聚合方式传参有误,查询失败!"); |
||||
}); |
||||
// 聚合数据方式处理
|
||||
DateEnum dateEnum = DateEnum.getDateEnumByType(searchVO.getDataType()); |
||||
ReductionDataDTO dataDTO = new ReductionDataDTO(); |
||||
ReductionAttrDataDTO reductionAttrData = new ReductionAttrDataDTO(); |
||||
reductionAttrData.setSignage(searchVO.getSignage()); |
||||
reductionAttrData.setAccessRules(enumByMethod.getAccessRule()); |
||||
reductionAttrData.setKeepFigures(2); |
||||
dataDTO.setBeginTime(LocalDateTime.parse(searchVO.getStartTime(), DateUtil.DATETIME_FORMATTER)); |
||||
dataDTO.setEndTime(LocalDateTime.parse(searchVO.getEndTime(),DateUtil.DATETIME_FORMATTER)); |
||||
dataDTO.setDeviceCode(searchVO.getDeviceCode()); |
||||
dataDTO.setNeedPage(false); |
||||
dataDTO.setSaveTimeType(dateEnum.getSaveTimeType()); |
||||
dataDTO.setTimeInterval(1); |
||||
dataDTO.setDtos(Lists.newArrayList(reductionAttrData)); |
||||
logger.info("interactive:getPolymerizationData","config传参为:" + JSON.toJSONString(dataDTO)); |
||||
return deviceDataClient.pageDeviceCodeAndSignages(dataDTO); |
||||
} |
||||
|
||||
public DateEnum getDateEnumByDuration(String startTime,String endTime,DateEnum dateEnum) { |
||||
LocalDateTime start = LocalDateTime.parse(startTime, DateUtil.DATETIME_FORMATTER); |
||||
LocalDateTime end = LocalDateTime.parse(endTime, DateUtil.DATETIME_FORMATTER); |
||||
Duration duration = Duration.between(start, end); |
||||
int count; |
||||
switch(dateEnum) { |
||||
case YEAR: |
||||
count = Long.valueOf(ChronoUnit.YEARS.between(start.toLocalDate(), end.toLocalDate())).intValue(); |
||||
break; |
||||
case MONTH: |
||||
count = Long.valueOf(ChronoUnit.MONTHS.between(start.toLocalDate(), end.toLocalDate())).intValue(); |
||||
break; |
||||
case DAY: |
||||
count = Long.valueOf(ChronoUnit.DAYS.between(start.toLocalDate(), end.toLocalDate())).intValue(); |
||||
break; |
||||
case HOUR: |
||||
count = Long.valueOf(duration.toHours()).intValue(); |
||||
break; |
||||
case MINUTE: |
||||
count = Long.valueOf(duration.toMinutes()).intValue(); |
||||
break; |
||||
case SECOND: |
||||
count = Long.valueOf(duration.getSeconds()).intValue(); |
||||
break; |
||||
default: |
||||
throw new ServiceException("未找到相关时间类型,查询失败!"); |
||||
} |
||||
if(count <= DATA_COUNT_MAX) { |
||||
return dateEnum; |
||||
} |
||||
else { |
||||
return getDateEnumByDuration(startTime, endTime, DateEnum.getDateEnumByOrder(dateEnum.getOrder() + 1)); |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,31 +0,0 @@
|
||||
package com.hnac.hzims.bigmodel.data.service; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springblade.system.dto.ControlDTO; |
||||
import org.springblade.system.feign.IRemoteClient; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/24 14:36 |
||||
* @Descirbe: 数据平台 - 遥控服务类 |
||||
*/ |
||||
@Service |
||||
@Slf4j |
||||
@AllArgsConstructor |
||||
public class RemoteService { |
||||
|
||||
private final IRemoteClient remoteClient; |
||||
|
||||
/** |
||||
* 发送遥控指令 |
||||
* @param controlDTO 遥控指令 |
||||
* @return 结果 |
||||
*/ |
||||
public R<Object> sendRemoteControl(ControlDTO controlDTO) { |
||||
return remoteClient.sendCtrl(controlDTO); |
||||
} |
||||
|
||||
} |
@ -1,26 +0,0 @@
|
||||
package com.hnac.hzims.bigmodel.datasource.controller; |
||||
|
||||
import com.hnac.hzims.bigmodel.datasource.service.DataSourceService; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/28 14:07 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/dataSource/execute") |
||||
@AllArgsConstructor |
||||
public class DataSourceExecuteController { |
||||
|
||||
private final DataSourceService dataSourceService; |
||||
|
||||
@GetMapping("/executeQuery") |
||||
public R executeQuery(String sql,String dataSourceName) { |
||||
return R.data(dataSourceService.queryListOnSpecificDataSource(sql,dataSourceName)); |
||||
} |
||||
|
||||
} |
@ -1,62 +0,0 @@
|
||||
package com.hnac.hzims.bigmodel.datasource.service; |
||||
|
||||
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.jdbc.core.JdbcTemplate; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.regex.Pattern; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/28 15:24 |
||||
*/ |
||||
@Service |
||||
@AllArgsConstructor |
||||
@Slf4j |
||||
public class DataSourceService { |
||||
|
||||
private final JdbcTemplate jdbcTemplate; |
||||
|
||||
private static final Pattern UPDATE_PATTERN = Pattern.compile("^UPDATE\\s", Pattern.CASE_INSENSITIVE); |
||||
private static final Pattern DELETE_PATTERN = Pattern.compile("^DELETE\\s", Pattern.CASE_INSENSITIVE); |
||||
|
||||
/** |
||||
* 指定 |
||||
* @param sql |
||||
* @param dataSourceName |
||||
* @return |
||||
*/ |
||||
public List<Map<String, Object>> queryListOnSpecificDataSource(String sql,String dataSourceName) { |
||||
// 切换到指定的数据源
|
||||
DynamicDataSourceContextHolder.push(dataSourceName); |
||||
try { |
||||
return jdbcTemplate.queryForList(sql); |
||||
} finally { |
||||
// 清除,恢复默认数据源
|
||||
DynamicDataSourceContextHolder.clear(); |
||||
} |
||||
} |
||||
|
||||
public Integer updateOnSpecificDataSource(String sql,String dataSourceName) { |
||||
// 切换到指定的数据源
|
||||
DynamicDataSourceContextHolder.push(dataSourceName); |
||||
try { |
||||
return jdbcTemplate.update(sql); |
||||
} finally { |
||||
// 清除,恢复默认数据源
|
||||
DynamicDataSourceContextHolder.clear(); |
||||
} |
||||
} |
||||
|
||||
public static boolean isUpdateOrDelete(String sql) { |
||||
if (sql == null) { |
||||
return false; |
||||
} |
||||
return UPDATE_PATTERN.matcher(sql).find() || DELETE_PATTERN.matcher(sql).find(); |
||||
} |
||||
|
||||
} |
@ -1,14 +0,0 @@
|
||||
package com.hnac.hzims.bigmodel.datasource.service; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/28 14:22 |
||||
*/ |
||||
public interface IDataSourceService { |
||||
|
||||
List<Map<String,Object>> queryList(String sql); |
||||
|
||||
} |
@ -1,34 +0,0 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.controller; |
||||
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
||||
import com.hnac.hzims.bigmodel.interactive.service.IAnalyseDataService; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.HistoryDataSearchVO; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springframework.validation.annotation.Validated; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/29 09:22 |
||||
*/ |
||||
@RequestMapping("/analyse/data") |
||||
@AllArgsConstructor |
||||
@Api(value = "数据查询管理",tags = "数据查询管理") |
||||
@RestController |
||||
@Deprecated |
||||
public class AnalyseDataController { |
||||
|
||||
private final IAnalyseDataService analyseDataService; |
||||
|
||||
@GetMapping("/getHistoryData") |
||||
@ApiOperation("获取历史数据") |
||||
@ApiOperationSupport(order = 1) |
||||
public R getHistoryData(@Validated HistoryDataSearchVO searchVO) { |
||||
return R.data(analyseDataService.getHistoryData(searchVO)); |
||||
} |
||||
} |
@ -1,15 +0,0 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.service; |
||||
|
||||
import com.hnac.hzims.bigmodel.entity.FunctionEntity; |
||||
|
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/09 08:50 |
||||
*/ |
||||
@Deprecated |
||||
public interface IParamsService { |
||||
String dealJumpTypeFunction(FunctionEntity function, Map<String,String> args); |
||||
|
||||
} |
@ -1,128 +0,0 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.service.impl; |
||||
|
||||
import com.google.common.collect.Lists; |
||||
import com.hnac.hzims.bigmodel.entity.FunctionEntity; |
||||
import com.hnac.hzims.bigmodel.function.service.IFunctionService; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.ProjectRemoteTypeEnum; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.SessionContentVO; |
||||
import com.hnac.hzims.bigmodel.websocket.constants.RedisKeyConstants; |
||||
import com.hnac.hzinfo.sdk.core.response.Result; |
||||
import com.hnac.hzinfo.sdk.v5.project.ProjectClient; |
||||
import com.hnac.hzinfo.sdk.v5.project.vo.ProjectVO; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springblade.core.log.exception.ServiceException; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springblade.core.tool.utils.CollectionUtil; |
||||
import org.springblade.core.tool.utils.Func; |
||||
import org.springblade.core.tool.utils.StringUtil; |
||||
import org.springblade.system.dto.DeptStationDTO; |
||||
import org.springblade.system.entity.CtrlAuth; |
||||
import org.springblade.system.feign.IDeptClient; |
||||
import org.springblade.system.feign.IRemoteClient; |
||||
import org.springblade.system.user.feign.IUserClient; |
||||
import org.springframework.data.redis.core.RedisTemplate; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.util.Assert; |
||||
|
||||
import java.util.List; |
||||
import java.util.Optional; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/21 16:10 |
||||
*/ |
||||
@Service |
||||
@AllArgsConstructor |
||||
public class AuthenticationService { |
||||
|
||||
private final IDeptClient deptClient; |
||||
private final IFunctionService functionService; |
||||
private final IUserClient userClient; |
||||
private final ProjectClient projectClient; |
||||
private final IRemoteClient remoteClient; |
||||
private final RedisTemplate redisTemplate; |
||||
|
||||
/** |
||||
* 站点鉴权 |
||||
* @param stationId 站点ID |
||||
* @param userId 用户ID |
||||
*/ |
||||
public void stationAuthentication(String stationId, String userId) { |
||||
List<String> stations = this.getStationPermissionsById(userId).stream().map(DeptStationDTO::getStationId) |
||||
.filter(StringUtil::isNotBlank).filter(Func::isNotEmpty).collect(Collectors.toList()); |
||||
Assert.isTrue(stations.contains(stationId),() -> { |
||||
throw new ServiceException("人员站点鉴权失败!"); |
||||
}); |
||||
} |
||||
|
||||
/** |
||||
* 菜单鉴权 |
||||
* @param userId 用户ID |
||||
* @param func 函数编号 |
||||
*/ |
||||
public void menuAuthentication(String userId, String func) { |
||||
FunctionEntity function = functionService.getFunctionByCode(func); |
||||
if(Func.isNotEmpty(function) && Func.isNotEmpty(function.getRoute()) && StringUtil.isNotBlank(function.getRoute())) { |
||||
R<Boolean> authenticationR = userClient.permissionMenuById(Long.valueOf(userId), function.getRoute()); |
||||
Assert.isTrue(authenticationR.isSuccess() && authenticationR.getData(), () -> { |
||||
throw new ServiceException("人员菜单鉴权失败!"); |
||||
}); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 遥控鉴权 |
||||
* @param stationId 站点ID |
||||
* @param userId 用户ID |
||||
*/ |
||||
public void remoteAuthentication(String stationId, String userId,String sessionId) { |
||||
// 查询数据平台站点是否可被遥控
|
||||
Result<List<ProjectVO>> projectR = projectClient.getProjectIds(Lists.newArrayList(stationId)); |
||||
Assert.isTrue(projectR.isSuccess() && CollectionUtil.isNotEmpty(projectR.getData()) && projectR.getData().size() == 1,() -> { |
||||
throw new ServiceException("未查询到站点,鉴权失败!"); |
||||
}); |
||||
ProjectVO project = projectR.getData().get(0); |
||||
if(ProjectRemoteTypeEnum.NOT_ALLOW.getCtrlType().equals(project.getCtrlType())) { |
||||
// 不允许发送遥控
|
||||
throw new ServiceException("该站点不允许发送遥控指令,校验失败!"); |
||||
} |
||||
else if(ProjectRemoteTypeEnum.VALID.getCtrlType().equals(project.getCtrlType())) { |
||||
// 运行发送遥控并且需要校验权限
|
||||
R<List<CtrlAuth>> ctrlAuthR = remoteClient.getCtrlAuth(Optional.ofNullable(userId).filter(StringUtil::isNotBlank).map(Long::parseLong).orElse(null)); |
||||
Assert.isTrue(ctrlAuthR.isSuccess(),() -> { |
||||
throw new ServiceException("该站点未设置鉴权用户,校验失败!"); |
||||
}); |
||||
List<CtrlAuth> ctrlAuthList = ctrlAuthR.getData(); |
||||
Optional<CtrlAuth> authOptional = ctrlAuthList.stream().filter(c -> c.getProjectId().equals(stationId)).findFirst(); |
||||
Assert.isTrue(authOptional.isPresent() && Func.isNotEmpty(authOptional.get().getIsLimitMachine()), () -> { |
||||
throw new ServiceException("该用户不存在相应站点权限,校验不通过!"); |
||||
}); |
||||
CtrlAuth ctrlAuth = authOptional.get(); |
||||
// 如限制机器发送遥控指令
|
||||
if(ctrlAuth.getIsLimitMachine().intValue() == 1) { |
||||
SessionContentVO sessionContent = (SessionContentVO) redisTemplate.opsForHash().get(RedisKeyConstants.SESSION_CONTENT_KEY, sessionId); |
||||
Assert.isTrue(Func.isNotEmpty(sessionContent),() -> { |
||||
throw new ServiceException("获取问题机器码失败,校验不通过!"); |
||||
}); |
||||
String machineCode = sessionContent.getMachineCode(); |
||||
Assert.isTrue(StringUtil.isNotBlank(machineCode) && Func.isNotEmpty(machineCode) ,() -> { |
||||
throw new ServiceException("获取问题机器码失败,校验不通过!"); |
||||
}); |
||||
Assert.isTrue(machineCode.equals(ctrlAuth.getMachineCode()),() -> { |
||||
throw new ServiceException("站点校验码校验失败,校验不通过!"); |
||||
}); |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
public List<DeptStationDTO> getStationPermissionsById(String userId) { |
||||
R<List<DeptStationDTO>> deptSattionR = deptClient.getStationPermissionsById(Long.valueOf(userId)); |
||||
Assert.isTrue(deptSattionR.isSuccess() && CollectionUtil.isNotEmpty(deptSattionR.getData()),() -> { |
||||
throw new ServiceException("获取人员站点权限失败!"); |
||||
}); |
||||
return deptSattionR.getData(); |
||||
} |
||||
|
||||
} |
@ -1,259 +0,0 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.service.impl; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import com.alibaba.fastjson.JSONArray; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.SearchTypeEnum; |
||||
import com.hnac.hzims.bigmodel.interactive.service.IAnalyseDataService; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.*; |
||||
import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity; |
||||
import com.hnac.hzims.operational.station.feign.IStationClient; |
||||
import com.hnac.hzims.operational.station.feign.IStationVideoTypeClient; |
||||
import com.hnac.hzinfo.sdk.v5.device.client.DeviceClient; |
||||
import com.hnac.hzinfo.sdk.v5.device.vo.DeviceInstanceFuncVO; |
||||
import com.xxl.job.core.log.XxlJobLogger; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springblade.core.tool.utils.*; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.time.format.DateTimeFormatter; |
||||
import java.util.*; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/08 16:19 |
||||
*/ |
||||
@Service |
||||
@AllArgsConstructor |
||||
@Deprecated |
||||
public class ExtraResolveStrategyService { |
||||
|
||||
public static final String PATTERN_DATETIME = "yyyy-MM-dd HH:mm:ss.SSS"; |
||||
|
||||
public static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(PATTERN_DATETIME); |
||||
|
||||
private final IStationClient stationClient; |
||||
private final IStationVideoTypeClient videoTypeClient; |
||||
private final JumpRouteJoinStrategy jumpRouteJoinStrategy; |
||||
private final DeviceClient deviceClient; |
||||
private final IAnalyseDataService analyseDataService; |
||||
|
||||
/** |
||||
* 解析DFP返回extra |
||||
* @param extraStr DFP返回extra |
||||
* @return 与前端交互extra |
||||
*/ |
||||
public ExtraVO resolve(String extraStr) { |
||||
JSONObject extra = JSONObject.parseObject(extraStr); |
||||
String functionCode = Optional.ofNullable(extra.get("func")).map(String::valueOf).orElse(""); |
||||
if(StringUtil.isNotBlank(functionCode)) { |
||||
XxlJobLogger.log("函数编号为:" + functionCode); |
||||
FuncRouteEnum funcRouteEnum = FuncRouteEnum.getEnumByFuncCode(functionCode); |
||||
if(Func.isNotEmpty(funcRouteEnum)) { |
||||
switch (funcRouteEnum) { |
||||
case DIAGNOSE: |
||||
return this.resolveDiagnose(extra); |
||||
case CHOOSE_VIDEO: |
||||
case CHOOSE_CANVAS: |
||||
case CHOOSE_STATION: |
||||
case CHOOSE_FAULT: |
||||
case CHOOSE_YC: |
||||
case CHOOSE_YK: |
||||
return this.resolveChooseSelection(extra,funcRouteEnum); |
||||
case CONFIRM_YK: |
||||
return this.resolveConfirmRemote(extra); |
||||
case SHOW_PARAM: |
||||
return this.resolveShowParam(extra); |
||||
default: |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
else if(extra.containsKey("extra")){ |
||||
return extra.getObject("extra",ExtraVO.class); |
||||
} |
||||
return JSONObject.parseObject(JSON.toJSONString(extra),ExtraVO.class); |
||||
} |
||||
|
||||
private ExtraVO resolveChooseSelection(JSONObject extra,FuncRouteEnum funcRouteEnum) { |
||||
ExtraVO result = new ExtraVO(); |
||||
JSONArray selections = JSONArray.parseArray(JSON.toJSONString(extra.get("data"))); |
||||
result.setFunc(funcRouteEnum.getFuncCode()); |
||||
result.setSpecial(true); |
||||
result.setSelection(selections); |
||||
result.setType(funcRouteEnum.getType().getType()); |
||||
return result; |
||||
} |
||||
|
||||
// private ExtraVO resolveChooseYc(JSONObject extra) {
|
||||
// ExtraVO result = new ExtraVO();
|
||||
// JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data")));
|
||||
// if(data.containsKey("yks")) {
|
||||
//
|
||||
//
|
||||
// List<AttrSelectionVO> attrs = JSONArray.parseArray(JSON.toJSONString(data.get("yks")), AttrSelectionVO.class);
|
||||
// result.setSelection(attrs);
|
||||
// }
|
||||
// result.setFuncCode(FuncRouteEnum.CHOOSE_YC.getFuncCode());
|
||||
// result.setSpecial(true);
|
||||
// result.setType(FuncRouteEnum.CHOOSE_YC.getType().getType());
|
||||
// return result;
|
||||
// }
|
||||
|
||||
private ExtraVO resolveShowParam(Map<String,Object> extra) { |
||||
DataVO data = JSONObject.parseObject(JSON.toJSONString(extra.get("data")),DataVO.class); |
||||
if(Func.isNotEmpty(data)) { |
||||
if(Func.isNotEmpty(data.getReal())) { |
||||
if(Func.isNotEmpty(data.getReal().getTime()) && StringUtil.isNotBlank(data.getReal().getTime())) { |
||||
RealDataVO real = data.getReal(); |
||||
Date date = DateUtil.parse(real.getTime(), PATTERN_DATETIME); |
||||
real.setTime(DateUtil.format(date,DateUtil.PATTERN_DATETIME)); |
||||
} |
||||
} |
||||
if(Func.isNotEmpty(data.getItem()) && StringUtil.isNotBlank(data.getMethod())) { |
||||
if(SearchTypeEnum.HISTORY.getSearchType().equals(data.getType()) && Func.isNotEmpty(data.getItem())) { |
||||
DataItemVO item = data.getItem(); |
||||
HistoryDataSearchVO searchVO = new HistoryDataSearchVO(); |
||||
searchVO.setDataType(data.getDataType()); |
||||
searchVO.setAttrName(item.getAttrName()); |
||||
searchVO.setDeviceCode(item.getDeviceId()); |
||||
searchVO.setDeviceName(item.getDeviceName()); |
||||
searchVO.setStationName(item.getProjectName()); |
||||
searchVO.setMethod(data.getMethod()); |
||||
searchVO.setSignage(item.getSignage()); |
||||
searchVO.setStartTime(data.getStartTime()); |
||||
searchVO.setEndTime(data.getEndTime()); |
||||
return analyseDataService.getHistoryData(searchVO); |
||||
} |
||||
} |
||||
} |
||||
ExtraVO result = new ExtraVO(); |
||||
result.setFunc(FuncRouteEnum.SHOW_PARAM.getFuncCode()); |
||||
result.setType(FuncRouteEnum.SHOW_PARAM.getType().getType()); |
||||
Map<String,Object> param = new HashMap(1); |
||||
param.put("data", data); |
||||
result.setParams(param); |
||||
return result; |
||||
} |
||||
|
||||
@Deprecated |
||||
private ExtraVO resolveConfirmRemote(Map<String,Object> extra) { |
||||
ExtraVO result = new ExtraVO(); |
||||
RemoteParamVO remoteParam = JSONObject.parseObject(JSON.toJSONString(extra.get("data")), RemoteParamVO.class); |
||||
result.setFunc(FuncRouteEnum.CONFIRM_YK.getFuncCode()); |
||||
result.setType(FuncRouteEnum.CONFIRM_YK.getType().getType()); |
||||
R<DeviceInstanceFuncVO> funcVOR = deviceClient.getFuncById(remoteParam.getFuncId()); |
||||
if(funcVOR.isSuccess()) { |
||||
Map<String,Object> param = new HashMap(); |
||||
param.put("control",funcVOR.getData()); |
||||
param.put("deviceName",remoteParam.getDeviceName()); |
||||
param.put("projectName",remoteParam.getProjectName()); |
||||
param.put("deviceCode",remoteParam.getDeviceId()); |
||||
param.put("value",remoteParam.getValue()); |
||||
result.setParams(param); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
// private ExtraVO resolveChooseFault(Map<String,Object> extra) {
|
||||
// ExtraVO result = new ExtraVO();
|
||||
// JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data")));
|
||||
// if(data.containsKey("faults")) {
|
||||
// List<FaultSelectionVO> faults = JSONArray.parseArray(JSON.toJSONString(data.get("faults")), FaultSelectionVO.class);
|
||||
// result.setSelection(faults);
|
||||
// }
|
||||
// result.setFuncCode(FuncRouteEnum.CHOOSE_FAULT.getFuncCode());
|
||||
// result.setSpecial(true);
|
||||
// result.setType(FunctionConstants.TypeEnum.CHOOSE.getType());
|
||||
// return result;
|
||||
// }
|
||||
|
||||
private ExtraVO resolveDiagnose(Map<String,Object> extra) { |
||||
ExtraVO result = new ExtraVO(); |
||||
JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data"))); |
||||
Map<String,Object> params = new HashMap<>(5); |
||||
params.put("faultId",data.getString("fault_id")); |
||||
params.put("name",data.getString("fault_name")); |
||||
params.put("station",data.getString("station_id")); |
||||
params.put("fdpDeviceName",data.getString("device_name")); |
||||
params.put("fdpOrd",data.getString("ord")); |
||||
result.setParams(params); |
||||
result.setFunc(FuncRouteEnum.DIAGNOSE.getFuncCode()); |
||||
result.setType(FunctionConstants.TypeEnum.PARAMS.getType()); |
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param extra |
||||
* @return |
||||
*/ |
||||
// private ExtraVO resolveChooseStation(Map<String,Object> extra) {
|
||||
// ExtraVO result = new ExtraVO();
|
||||
// JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data")));
|
||||
// if(data.containsKey("stations")) {
|
||||
// List<String> stations = JSONArray.parseArray(JSON.toJSONString(data.get("stations")), String.class);
|
||||
// List<StationSelectionVO> selectionList = stations.stream().map(stationId -> {
|
||||
// StationSelectionVO selectionVO = new StationSelectionVO();
|
||||
// R<StationEntity> stationR = stationClient.getStationByCode(stationId);
|
||||
// if (stationR.isSuccess() && Func.isNotEmpty(stationR.getData())) {
|
||||
// selectionVO.setId(stationId);
|
||||
// selectionVO.setName(stationR.getData().getName());
|
||||
// }
|
||||
// return selectionVO;
|
||||
// }).collect(Collectors.toList());
|
||||
// result.setSelection(selectionList);
|
||||
// result.setFuncCode(FuncRouteEnum.CHOOSE_STATION.getFuncCode());
|
||||
// result.setSpecial(true);
|
||||
// result.setType(FunctionConstants.TypeEnum.CHOOSE.getType());
|
||||
// }
|
||||
// result.setType(FunctionConstants.TypeEnum.CHOOSE.getType());
|
||||
// return result;
|
||||
// }
|
||||
|
||||
private ExtraVO resolveChooseVideo(Map<String,Object> extra) { |
||||
ExtraVO result = new ExtraVO(); |
||||
JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data"))); |
||||
if(data.containsKey("videos")) { |
||||
List<JSONObject> videoIds = JSONArray.parseArray(JSON.toJSONString(data.get("videos")), JSONObject.class); |
||||
List<VideoSelectionVO> selections = videoIds.stream().map(video -> { |
||||
R<StationVideoTypeEntity> videoR = videoTypeClient.getById(Long.valueOf(video.getString("id"))); |
||||
VideoSelectionVO selectionVO = new VideoSelectionVO(); |
||||
if (videoR.isSuccess() && Func.isNotEmpty(videoR.getData())) { |
||||
selectionVO.setId(video.getString("id")); |
||||
selectionVO.setName(videoR.getData().getName()); |
||||
} |
||||
return selectionVO; |
||||
}).collect(Collectors.toList()); |
||||
result.setFunc(FuncRouteEnum.CHOOSE_VIDEO.getFuncCode()); |
||||
result.setSpecial(true); |
||||
result.setSelection(selections); |
||||
} |
||||
result.setType(FunctionConstants.TypeEnum.CHOOSE.getType()); |
||||
return result; |
||||
} |
||||
|
||||
private ExtraVO resolveChooseScada(Map<String,Object> extra) { |
||||
ExtraVO result = new ExtraVO(); |
||||
JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data"))); |
||||
if(data.containsKey("canvases")) { |
||||
List<JSONObject> canvases = JSONArray.parseArray(JSON.toJSONString(data.get("canvases")), JSONObject.class); |
||||
List<ScadaSelectionVO> selections = canvases.stream().map(canvas -> { |
||||
ScadaSelectionVO selectionVO = new ScadaSelectionVO(); |
||||
Map<String, String> resolve = jumpRouteJoinStrategy.resolve(canvas.getString("id"), JumpRouteJoinStrategy.SCADA_PARAMS_SOLVE); |
||||
selectionVO.setId(canvas.getString("id")); |
||||
selectionVO.setName(resolve.get("name")); |
||||
return selectionVO; |
||||
}).collect(Collectors.toList()); |
||||
result.setFunc(FuncRouteEnum.CHOOSE_CANVAS.getFuncCode()); |
||||
result.setSpecial(true); |
||||
result.setSelection(selections); |
||||
} |
||||
result.setType(FunctionConstants.TypeEnum.CHOOSE.getType()); |
||||
return result; |
||||
} |
||||
} |
@ -1,73 +0,0 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.service.impl; |
||||
|
||||
import com.hnac.hzims.bigmodel.entity.FunctionEntity; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; |
||||
import com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; |
||||
import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity; |
||||
import com.hnac.hzims.operational.station.feign.IStationVideoTypeClient; |
||||
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.core.tool.utils.StringUtil; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/09 08:56 |
||||
*/ |
||||
@Component |
||||
@Slf4j |
||||
@AllArgsConstructor |
||||
@Deprecated |
||||
public class ParamStrategy { |
||||
|
||||
private final IStationVideoTypeClient videoClient; |
||||
|
||||
/** |
||||
* 解析发送参数方式函数 |
||||
* @param function 函数 |
||||
* @param args 大模型识别参数 |
||||
* @return 前端传参EXTRA |
||||
*/ |
||||
public ExtraVO resolve(FunctionEntity function, Map<String,String> args) { |
||||
FuncRouteEnum routeEnum = FuncRouteEnum.getEnumByFuncCode(function.getCode()); |
||||
if(Func.isNotEmpty(routeEnum)) { |
||||
switch(routeEnum) { |
||||
case OPEN_VIDEO: |
||||
return this.getVideoExtra(args); |
||||
default: |
||||
break; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public ExtraVO getVideoExtra(Map<String,String> args) { |
||||
// 跳转页面逻辑
|
||||
ExtraVO extraVO = new ExtraVO(); |
||||
String id = args.get("canvas_id"); |
||||
if(StringUtil.isNotBlank(id) && Func.isNotEmpty(id)) { |
||||
R<StationVideoTypeEntity> videoR = videoClient.getById(Long.valueOf(id)); |
||||
if(videoR.isSuccess()) { |
||||
StationVideoTypeEntity video = videoR.getData(); |
||||
extraVO.setType(FunctionConstants.TypeEnum.PARAMS.getType()); |
||||
extraVO.setImmediatelyJump(true); |
||||
extraVO.setFunc(FuncRouteEnum.OPEN_VIDEO.getFuncCode()); |
||||
Map<String,Object> params = new HashMap<>(); |
||||
params.put("name", video.getName()); |
||||
params.put("videoHost", video.getVideoHost()); |
||||
params.put("pointCode", video.getPointCode()); |
||||
params.put("appKey", video.getAppKey()); |
||||
params.put("appSecret", video.getAppSecret()); |
||||
params.put("liveSourceAddress",video.getLiveSourceAddress()); |
||||
extraVO.setParams(params); |
||||
} |
||||
} |
||||
return extraVO; |
||||
} |
||||
} |
@ -1,36 +0,0 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.service.impl; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import com.hnac.hzims.bigmodel.entity.FuncParamEntity; |
||||
import com.hnac.hzims.bigmodel.entity.FunctionEntity; |
||||
import com.hnac.hzims.bigmodel.interactive.service.IParamsService; |
||||
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springblade.core.log.exception.ServiceException; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.util.Assert; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.Optional; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/05/09 08:51 |
||||
*/ |
||||
@Service |
||||
@Slf4j |
||||
@AllArgsConstructor |
||||
@Deprecated |
||||
public class ParamsServiceImpl implements IParamsService { |
||||
|
||||
private final ParamStrategy strategy; |
||||
|
||||
@Override |
||||
public String dealJumpTypeFunction(FunctionEntity function, Map<String, String> args) { |
||||
// 跳转页面逻辑
|
||||
ExtraVO extraVO = strategy.resolve(function,args); |
||||
return JSON.toJSONString(extraVO); |
||||
} |
||||
} |
Loading…
Reference in new issue