接入ai,识别

This commit is contained in:
lcj
2025-10-24 09:23:40 +08:00
parent 9e366554b7
commit 025c3115b7
18 changed files with 279 additions and 245 deletions

View File

@ -36,6 +36,12 @@ snail-job:
--- # 数据源配置
spring:
ai:
dashscope:
api-key: sk-8d8df92fcbac4bd2922edba30b0bb8fa
chat:
options:
model: qwen-plus
datasource:
type: com.zaxxer.hikari.HikariDataSource
# 动态数据源文档 https://www.kancloud.cn/tracy5546/dynamic-datasource/content

View File

@ -39,6 +39,12 @@ snail-job:
--- # 数据源配置
spring:
ai:
dashscope:
api-key: xxx
chat:
options:
model: qwen-plus
datasource:
type: com.zaxxer.hikari.HikariDataSource
# 动态数据源文档 https://www.kancloud.cn/tracy5546/dynamic-datasource/content

View File

@ -39,6 +39,12 @@ snail-job:
--- # 数据源配置
spring:
ai:
dashscope:
api-key: xxx
chat:
options:
model: qwen-plus
datasource:
type: com.zaxxer.hikari.HikariDataSource
# 动态数据源文档 https://www.kancloud.cn/tracy5546/dynamic-datasource/content

View File

@ -29,6 +29,8 @@ import org.dromara.manager.ys7manager.Ys7Constant;
import org.dromara.manager.ys7manager.Ys7Manager;
import org.dromara.manager.ys7manager.vo.Ys7ResponseVo;
import org.dromara.other.domain.OthYs7Device;
import org.dromara.other.domain.dto.ys7deviceimg.OthYs7DeviceImgCreateByCapture;
import org.dromara.other.service.IOthYs7DeviceImgService;
import org.dromara.other.service.IOthYs7DeviceService;
import org.dromara.out.domain.OutConstructionValue;
import org.dromara.out.domain.OutConstructionValueRange;
@ -55,6 +57,8 @@ import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
@ -112,6 +116,9 @@ public class DemoTest {
@Resource
private IOthYs7DeviceService ys7DeviceService;
@Resource
private IOthYs7DeviceImgService ys7DeviceImgService;
@Resource
private Ys7Manager ys7Manager;
@ -547,4 +554,38 @@ public class DemoTest {
}
}
@Test
void capturePic() {
List<String> urlList = List.of(
"http://xny.yj-3d.com:9000/xinnengyuan-dev/2025/10/23/db8a379b456142459852b654f20d5f97.png",
"http://xny.yj-3d.com:9000/xinnengyuan-dev/2025/10/23/913dbcf0f7244c8b878e84b5525bec4b.png",
"http://xny.yj-3d.com:9000/xinnengyuan-dev/2025/10/23/2b904765f03f40b2ad0ddbf6ddeadb45.png"
);
for (String url : urlList) {
Pattern pattern = Pattern.compile(".*/device/img/([^/]+)/.*");
Matcher matcher = pattern.matcher(url);
OthYs7Device ys7Device = ys7DeviceService.lambdaQuery()
.eq(OthYs7Device::getDeviceSerial, "GA1730672")
.last("limit 1")
.one();
if (ys7Device == null) {
throw new ServiceException("设备不存在", HttpStatus.ERROR);
}
String deviceSerial = ys7Device.getDeviceSerial();
// 如果没有预置位,则直接对默认通道抓图
OthYs7DeviceImgCreateByCapture img = new OthYs7DeviceImgCreateByCapture();
img.setProjectId(ys7Device.getProjectId());
img.setDeviceSerial(deviceSerial);
img.setDeviceName(ys7Device.getDeviceName());
// String url = "http://xny.yj-3d.com:9000/xinnengyuan/ys7/device/img/GA1044315/2025-10-13_859fdfb7dde540608356f29cb9e3d63e.jpg";
// String url = "http://xny.yj-3d.com:9000/xinnengyuan/ys7/device/img/GA1044315/2025-10-12_2801707255b84004acb5fee2a75299b2.jpg";
img.setCreateTime(new Date());
img.setUrl(url);
log.info("图片:{},识别中", url);
ys7DeviceImgService.saveCapturePic(List.of(img));
}
}
}

View File

@ -23,7 +23,7 @@ public class RecognizerTest {
@Test
void test() {
RecognizeVo recognize = recognizerManager.recognize("http://xny.yj-3d.com:7363/file/tif/20250625160218orthophoto.png", List.of(RecognizerTypeEnum.SOLAR));
RecognizeVo recognize = recognizerManager.recognize("http://xny.yj-3d.com:7363/file/tif/20250625160218orthophoto.png", List.of(RecognizerTypeEnum.PANEL));
log.info("recognize: {}", recognize);
}
}

View File

@ -15,9 +15,24 @@
system系统模块
</description>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba.cloud.ai</groupId>
<artifactId>spring-ai-alibaba-bom</artifactId>
<version>1.0.0.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba.cloud.ai</groupId>
<artifactId>spring-ai-alibaba-starter-dashscope</artifactId>
</dependency>
<!-- Java WebSocket 标准API -->
<!-- <dependency>-->
<!-- <groupId>javax.websocket</groupId>-->
@ -119,7 +134,6 @@
</dependency>
<!-- 支持中文字体 -->
<!-- <dependency>-->
<!-- <groupId>com.itextpdf</groupId>-->

View File

@ -0,0 +1,51 @@
package org.dromara.ai.controller;
import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatOptions;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
/**
* @author lilemy
* @date 2025-10-23 11:32
*/
@Validated
@RestController
@RequestMapping("/ai")
public class AIController {
private static final String DEFAULT_PROMPT = "你是一个博学的智能聊天助手,请根据用户提问回答!";
private final ChatClient dashScopeChatClient;
public AIController(ChatClient.Builder chatClientBuilder) {
this.dashScopeChatClient = chatClientBuilder
.defaultSystem(DEFAULT_PROMPT)
// 实现 Logger 的 Advisor
.defaultAdvisors(
new SimpleLoggerAdvisor()
)
// 设置 ChatClient 中 ChatModel 的 Options 参数
.defaultOptions(
DashScopeChatOptions.builder()
.withTopP(0.7)
.build()
)
.build();
}
/**
* ChatClient 流式调用
*/
@GetMapping("/stream/chat")
public Flux<String> streamChat(@RequestParam(value = "query", defaultValue = "你好,很高兴认识你,能简单介绍一下自己吗?") String query, HttpServletResponse response) {
response.setCharacterEncoding("UTF-8");
return dashScopeChatClient.prompt(query).stream().content();
}
}

View File

@ -1,39 +0,0 @@
package org.dromara.facility.domain.vo.matrix;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.dromara.progress.domain.vo.progresscategory.PgsProgressCategoryStructureVo;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
/**
* @author lilemy
* @date 2025-08-23 01:17
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class FacMatrixStructureVo implements Serializable {
@Serial
private static final long serialVersionUID = 7526403047030009646L;
/**
* 主键
*/
private Long id;
/**
* 方阵名称
*/
private String name;
/**
* 分项工程
*/
private List<PgsProgressCategoryStructureVo> children;
}

View File

@ -847,7 +847,7 @@ public class FacPhotovoltaicPanelPartsServiceImpl implements IFacPhotovoltaicPan
// 根据类型,更新对应数据
if (type.equals(RecognizerTypeEnum.HOLE.getValue())) {
photovoltaicPanelPointService.updateFinishNumberByCoordinate(projectIds, matchPoints);
} else if (type.equals(RecognizerTypeEnum.PILE.getValue())) {
} else if (type.equals(RecognizerTypeEnum.COLUMN.getValue())) {
photovoltaicPanelColumnService.updateFinishNumberByCoordinate(projectIds, matchPoints);
} else if (type.equals(RecognizerTypeEnum.BRACKET.getValue())) {
photovoltaicPanelSupportService.updateFinishNumberByCoordinate(projectIds, matchPoints);
@ -871,7 +871,7 @@ public class FacPhotovoltaicPanelPartsServiceImpl implements IFacPhotovoltaicPan
return list.stream().map(point ->
new IdCoordinatePoint(point.getId(), point.getPositions())).toList();
}
} else if (type.equals(RecognizerTypeEnum.PILE.getValue())) {
} else if (type.equals(RecognizerTypeEnum.COLUMN.getValue())) {
List<FacPhotovoltaicPanelColumn> list = photovoltaicPanelColumnService.lambdaQuery()
.in(FacPhotovoltaicPanelColumn::getProjectId, projectIds)
.ne(FacPhotovoltaicPanelColumn::getStatus, FacFinishStatusEnum.FINISH.getValue())

View File

@ -21,6 +21,7 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLConnection;
import java.util.List;
import java.util.Objects;
/**
* @author lilemy
@ -82,7 +83,9 @@ public class RecognizerManager {
// 画矩形框
g.drawRect(x, y, w, h);
// 写文字(类型 + 置信度)
String label = target.getType() + " (" + String.format("%.2f", target.getScore()) + ")";
RecognizerTypeEnum recognizerTypeEnum = RecognizerTypeEnum.fromValue(target.getType());
String label = recognizerTypeEnum != null ? Objects.requireNonNull(recognizerTypeEnum).getText() : target.getType()
+ " (" + String.format("%.2f", target.getScore()) + ")";
g.drawString(label, x, y - 5);
}
g.dispose();

View File

@ -12,15 +12,17 @@ import java.util.stream.Collectors;
@Getter
public enum RecognizerTypeEnum {
HARDHAT("安全帽识别", "nohelmet", "1"),
VEST("反光背心识别", "novest", ""),
SMOKING("吸烟识别", "smoking", "3"),
FIRE("火焰识别", "fire", "16"),
SMOKE("雾识别","smoke",""),
SOLAR("光伏板识别", "solar", ""),
BRACKET("光伏板支架识别", "bracket", ""),
PILE("光伏板立柱识别", "pile", ""),
HOLE("", "hole", "");
WEARING_ALL("穿戴安全帽反光衣", "wearingall", ""),
NO_EQUIPMENT("没穿安全帽反光衣", "noequipment", "1"),
NO_HELMET("有反光衣没安全帽", "nohelmet", ""),
NO_VEST("有安全帽没反光衣", "novest", ""),
SMOKE("", "smoke", "3"),
FIRE("火焰", "fire", "16"),
SMOGGY("烟雾", "smoggy", ""),
PANEL("光伏板", "solar", ""),
BRACKET("光伏板支架", "bracket", ""),
COLUMN("光伏板桩", "column", ""),
HOLE("光伏板孔", "hole", "");
private final String text;

View File

@ -6,7 +6,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
@Configuration
//@Configuration
public class WebSocketConfig {
@Bean
public ServerEndpointExporter serverEndpointExporter() {

View File

@ -220,7 +220,17 @@ public class OthYs7DeviceImgServiceImpl extends ServiceImpl<OthYs7DeviceImgMappe
othYs7DeviceImg.setDeviceName(img.getDeviceName());
othYs7DeviceImg.setUrl(ossUrl);
// 将抓取的图片进行识别
List<RecognizerTypeEnum> recTypes = List.of(RecognizerTypeEnum.HARDHAT, RecognizerTypeEnum.SMOKING, RecognizerTypeEnum.FIRE);
// List<RecognizerTypeEnum> recTypes = List.of(RecognizerTypeEnum.NO_EQUIPMENT,
// RecognizerTypeEnum.NO_HELMET,
// RecognizerTypeEnum.NO_EQUIPMENT,
// RecognizerTypeEnum.NO_VEST,
// RecognizerTypeEnum.SMOKE,
// RecognizerTypeEnum.FIRE);
List<RecognizerTypeEnum> recTypes = List.of(
RecognizerTypeEnum.COLUMN,
RecognizerTypeEnum.PANEL,
RecognizerTypeEnum.BRACKET,
RecognizerTypeEnum.HOLE);
RecognizeVo recognizeVo = null;
try {
recognizeVo = recognizerManager.recognize(ossUrl, recTypes);

View File

@ -1,37 +0,0 @@
package org.dromara.progress.domain.vo.progresscategory;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
/**
* @author lilemy
* @date 2025-08-23 01:19
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PgsProgressCategoryStructureVo implements Serializable {
@Serial
private static final long serialVersionUID = -8392912623299656962L;
/**
* 主键id
*/
private Long id;
/**
* 类别名称
*/
private String name;
/**
* 子类别
*/
private List<PgsProgressCategoryStructureVo> children;
}

View File

@ -1149,8 +1149,8 @@ public class PgsProgressPlanDetailServiceImpl extends ServiceImpl<PgsProgressPla
}
List<Long> projectIds = projects.stream().map(BusProject::getId).distinct().toList();
// 识别类型:洞、桩、架、架子
List<RecognizerTypeEnum> enumList = List.of(RecognizerTypeEnum.HOLE, RecognizerTypeEnum.SOLAR,
RecognizerTypeEnum.PILE, RecognizerTypeEnum.BRACKET);
List<RecognizerTypeEnum> enumList = List.of(RecognizerTypeEnum.HOLE, RecognizerTypeEnum.PANEL,
RecognizerTypeEnum.COLUMN, RecognizerTypeEnum.BRACKET);
// 调用识别算法
RecognizeVo recognizeVo = null;
try {
@ -1187,10 +1187,10 @@ public class PgsProgressPlanDetailServiceImpl extends ServiceImpl<PgsProgressPla
}
log.info("类型:{},识别到的设施:{},转换坐标:{}", type, value, coordinateList);
// 处理对应设施
if (type.equals(RecognizerTypeEnum.SOLAR.getValue())) {
if (type.equals(RecognizerTypeEnum.PANEL.getValue())) {
photovoltaicPanelService.updateFinishNumberByCoordinate(projectIds, coordinateList);
} else if (type.equals(RecognizerTypeEnum.HOLE.getValue())
|| type.equals(RecognizerTypeEnum.PILE.getValue())
|| type.equals(RecognizerTypeEnum.COLUMN.getValue())
|| type.equals(RecognizerTypeEnum.BRACKET.getValue())) {
photovoltaicPanelPartsService.updateFinishNumberByCoordinate(projectIds, coordinateList, type);
} else {

View File

@ -1,6 +1,8 @@
package org.dromara.project.domain.vo.project;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serial;
import java.io.Serializable;
@ -11,6 +13,8 @@ import java.util.List;
* @date 2025-08-23 01:14
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class BusProjectStructureVo implements Serializable {
@Serial
@ -29,5 +33,5 @@ public class BusProjectStructureVo implements Serializable {
/**
* 子项目列表
*/
private List<BusSubProjectStructureVo> children;
private List<BusProjectStructureVo> children;
}

View File

@ -1,38 +0,0 @@
package org.dromara.project.domain.vo.project;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.dromara.facility.domain.vo.matrix.FacMatrixStructureVo;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
/**
* @author lilemy
* @date 2025-08-23 01:15
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class BusSubProjectStructureVo implements Serializable {
@Serial
private static final long serialVersionUID = 6993209784456857540L;
/**
* 项目主键
*/
private Long id;
/**
* 项目名称
*/
private String name;
/**
* 方阵列表
*/
private List<FacMatrixStructureVo> children;
}

View File

@ -38,14 +38,12 @@ import org.dromara.contractor.service.ISubContractorService;
import org.dromara.design.service.IDesTechnicalStandardService;
import org.dromara.facility.domain.FacMatrix;
import org.dromara.facility.domain.vo.matrix.FacMatrixBySubProjectVo;
import org.dromara.facility.domain.vo.matrix.FacMatrixStructureVo;
import org.dromara.facility.service.IFacMatrixService;
import org.dromara.manager.weathermanager.WeatherConstant;
import org.dromara.manager.weathermanager.WeatherManager;
import org.dromara.manager.weathermanager.vo.WeatherVo;
import org.dromara.progress.domain.PgsProgressCategory;
import org.dromara.progress.domain.enums.PgsRelevancyStructureEnum;
import org.dromara.progress.domain.vo.progresscategory.PgsProgressCategoryStructureVo;
import org.dromara.progress.service.IPgsProgressCategoryService;
import org.dromara.progress.service.IPgsProgressCategoryTemplateService;
import org.dromara.project.constant.BusProjectConstant;
@ -1023,8 +1021,8 @@ public class BusProjectServiceImpl extends ServiceImpl<BusProjectMapper, BusProj
.list();
// 构造子项目结构
List<BusSubProjectStructureVo> subProjectStructures = subProjects.stream().map(subProject -> {
BusSubProjectStructureVo subProjectVo = new BusSubProjectStructureVo();
List<BusProjectStructureVo> subProjectStructures = new ArrayList<>(subProjects.stream().map(subProject -> {
BusProjectStructureVo subProjectVo = new BusProjectStructureVo();
subProjectVo.setId(subProject.getId());
subProjectVo.setName(subProject.getProjectName());
@ -1054,22 +1052,22 @@ public class BusProjectServiceImpl extends ServiceImpl<BusProjectMapper, BusProj
.collect(Collectors.groupingBy(PgsProgressCategory::getParentId));
}
Map<Long, List<PgsProgressCategory>> finalSub3CategoryMap = sub3CategoryMap;
List<FacMatrixStructureVo> structureVoList = sub1Category.stream()
List<BusProjectStructureVo> structureVoList = sub1Category.stream()
.map(category -> {
FacMatrixStructureVo matrixVo = new FacMatrixStructureVo();
BusProjectStructureVo matrixVo = new BusProjectStructureVo();
Long id = category.getId();
matrixVo.setId(id);
matrixVo.setName(category.getName());
if (CollUtil.isNotEmpty(finalSub2CategoryMap) && finalSub2CategoryMap.containsKey(id)) {
matrixVo.setChildren(finalSub2CategoryMap.get(id).stream()
.map(c -> {
PgsProgressCategoryStructureVo subSubCategoryVo = new PgsProgressCategoryStructureVo();
BusProjectStructureVo subSubCategoryVo = new BusProjectStructureVo();
subSubCategoryVo.setId(c.getId());
subSubCategoryVo.setName(c.getName());
if (CollUtil.isNotEmpty(finalSub3CategoryMap) && finalSub3CategoryMap.containsKey(c.getId())) {
subSubCategoryVo.setChildren(finalSub3CategoryMap.get(c.getId()).stream()
.map(c3 -> {
PgsProgressCategoryStructureVo sub3CategoryVo = new PgsProgressCategoryStructureVo();
BusProjectStructureVo sub3CategoryVo = new BusProjectStructureVo();
sub3CategoryVo.setId(c3.getId());
sub3CategoryVo.setName(c3.getName());
return sub3CategoryVo;
@ -1097,8 +1095,8 @@ public class BusProjectServiceImpl extends ServiceImpl<BusProjectMapper, BusProj
.list();
// 找到该子项目下的方阵
List<FacMatrix> matrices = matrixMap.getOrDefault(subProject.getId(), new ArrayList<>());
List<FacMatrixStructureVo> matrixVos = matrices.stream().map(matrix -> {
FacMatrixStructureVo matrixVo = new FacMatrixStructureVo();
List<BusProjectStructureVo> matrixVos = matrices.stream().map(matrix -> {
BusProjectStructureVo matrixVo = new BusProjectStructureVo();
matrixVo.setId(matrix.getId());
matrixVo.setName(matrix.getMatrixName());
@ -1108,19 +1106,26 @@ public class BusProjectServiceImpl extends ServiceImpl<BusProjectMapper, BusProj
.toList();
// 构造分项工程树
List<PgsProgressCategoryStructureVo> categoryTree = buildCategoryTree(categories);
List<BusProjectStructureVo> categoryTree = buildCategoryTree(categories);
matrixVo.setChildren(categoryTree);
return matrixVo;
}).toList();
List<FacMatrixStructureVo> resultList = Stream.concat(
List<BusProjectStructureVo> resultList = Stream.concat(
structureVoList.stream(),
matrixVos.stream()
).toList();
subProjectVo.setChildren(resultList);
}
return subProjectVo;
}).toList();
}).toList());
// 获取分项工程
List<PgsProgressCategory> progressCategoryList = progressCategoryService.lambdaQuery()
.eq(PgsProgressCategory::getRelevancyStructure, PgsRelevancyStructureEnum.PROJECT.getValue())
.in(PgsProgressCategory::getProjectId, projectId)
.list();
List<BusProjectStructureVo> projectStructureVos = this.buildCategoryTree(progressCategoryList);
subProjectStructures.addAll(projectStructureVos);
vo.setChildren(subProjectStructures);
return vo;
}
@ -1486,21 +1491,21 @@ public class BusProjectServiceImpl extends ServiceImpl<BusProjectMapper, BusProj
/**
* 构造分项工程树
*/
private List<PgsProgressCategoryStructureVo> buildCategoryTree(List<PgsProgressCategory> categories) {
Map<Long, PgsProgressCategoryStructureVo> map = new HashMap<>();
List<PgsProgressCategoryStructureVo> roots = new ArrayList<>();
private List<BusProjectStructureVo> buildCategoryTree(List<PgsProgressCategory> categories) {
Map<Long, BusProjectStructureVo> map = new HashMap<>();
List<BusProjectStructureVo> roots = new ArrayList<>();
for (PgsProgressCategory c : categories) {
PgsProgressCategoryStructureVo node = new PgsProgressCategoryStructureVo(c.getId(), c.getName(), new ArrayList<>());
BusProjectStructureVo node = new BusProjectStructureVo(c.getId(), c.getName(), new ArrayList<>());
map.put(c.getId(), node);
}
for (PgsProgressCategory c : categories) {
PgsProgressCategoryStructureVo node = map.get(c.getId());
BusProjectStructureVo node = map.get(c.getId());
if (c.getParentId() == 0) {
roots.add(node);
} else {
PgsProgressCategoryStructureVo parent = map.get(c.getParentId());
BusProjectStructureVo parent = map.get(c.getParentId());
if (parent != null) {
parent.getChildren().add(node);
}