QGIS地震专题图修改将图片保存到数据库中
This commit is contained in:
@@ -28,4 +28,4 @@ public class XianApplication {
|
|||||||
XianApplication app = context.getBean(XianApplication.class);
|
XianApplication app = context.getBean(XianApplication.class);
|
||||||
System.out.println("后端服务启动成功!访问地址: http://localhost:" + app.port);
|
System.out.println("后端服务启动成功!访问地址: http://localhost:" + app.port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,9 +12,12 @@ import org.springframework.stereotype.Component;
|
|||||||
@Order(1)
|
@Order(1)
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class DataSourceAspect {
|
public class DataSourceAspect {
|
||||||
|
|
||||||
@Around("@annotation(dataSource) || @within(dataSource)")
|
@Around("@annotation(dataSource) || @within(dataSource)")
|
||||||
public Object around(ProceedingJoinPoint point, DataSource dataSource) throws Throwable {
|
public Object around(ProceedingJoinPoint point, DataSource dataSource) throws Throwable {
|
||||||
|
if (dataSource == null) {
|
||||||
|
return point.proceed();
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
String dsName = dataSource.value();
|
String dsName = dataSource.value();
|
||||||
log.debug("切换数据源: {}", dsName);
|
log.debug("切换数据源: {}", dsName);
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ import com.gis.xian.domain.ApiResponse;
|
|||||||
import com.gis.xian.dto.pub.EqTriggerDTO;
|
import com.gis.xian.dto.pub.EqTriggerDTO;
|
||||||
import com.gis.xian.query.EqQuery;
|
import com.gis.xian.query.EqQuery;
|
||||||
import com.gis.xian.service.pub.IDZEqEventService;
|
import com.gis.xian.service.pub.IDZEqEventService;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.geolatte.geom.V;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@@ -19,25 +21,19 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/open")
|
@RequestMapping("/open")
|
||||||
public class DZEqEventController {
|
public class DZEqEventController {
|
||||||
@Autowired
|
@Resource
|
||||||
private IDZEqEventService idzEqEventService;
|
private IDZEqEventService idzEqEventService;
|
||||||
|
|
||||||
@PostMapping("/eq/trigger")
|
@PostMapping("/eq/trigger")
|
||||||
public ApiResponse trigger(@RequestBody @Validated EqTriggerDTO trigger) {
|
public ApiResponse<EqQuery> trigger(@RequestBody @Validated EqTriggerDTO trigger) {
|
||||||
EqQuery query = idzEqEventService.trigger(trigger);
|
EqQuery query = idzEqEventService.trigger(trigger);
|
||||||
if (query == null) {
|
|
||||||
return ApiResponse.error(BaseConstants.RESULT_ERROR);
|
|
||||||
}
|
|
||||||
return ApiResponse.ok(query);
|
return ApiResponse.ok(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/eq/delete/{Id}")
|
@PostMapping("/eq/delete/{Id}")
|
||||||
public ApiResponse delete(@PathVariable Long Id) {
|
public ApiResponse<Boolean> delete(@PathVariable Long Id) {
|
||||||
Boolean deleted = idzEqEventService.deletedById(Id);
|
Boolean deleted = idzEqEventService.deletedById(Id);
|
||||||
if (!deleted) {
|
return ApiResponse.ok(deleted);
|
||||||
return ApiResponse.error("删除失败!");
|
|
||||||
}
|
|
||||||
return ApiResponse.ok("删除成功!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package com.gis.xian.controller;
|
||||||
|
|
||||||
|
import com.gis.xian.constant.BaseConstants;
|
||||||
|
import com.gis.xian.domain.ApiResponse;
|
||||||
|
import com.gis.xian.dto.pub.EqAssessmentDTO;
|
||||||
|
import com.gis.xian.query.EqQuery;
|
||||||
|
import com.gis.xian.service.dzxx.IDZXXInfluenceService;
|
||||||
|
import com.gis.xian.service.pub.IDZInfluenceService;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
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;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zzw
|
||||||
|
* @description: 影响场控制类
|
||||||
|
* @date 2026/6/4 下午3:09
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/open")
|
||||||
|
public class DZInfluenceController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IDZInfluenceService idzInfluenceService;
|
||||||
|
@Resource
|
||||||
|
private IDZXXInfluenceService idzxxInfluenceService;
|
||||||
|
|
||||||
|
@PostMapping("/influence")
|
||||||
|
public ApiResponse<Map<String, String>> getInfluence(@RequestBody @Validated EqQuery query) {
|
||||||
|
Map<String, String> influence = idzInfluenceService.getInfluence(query);
|
||||||
|
return ApiResponse.ok(influence);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/generate/influence")
|
||||||
|
public ApiResponse<String> generateInfluence(@RequestBody @Validated EqAssessmentDTO assess) {
|
||||||
|
idzxxInfluenceService.handle(assess);
|
||||||
|
return ApiResponse.ok("地震影响场已生成!");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.gis.xian.controller;
|
||||||
|
|
||||||
|
import com.gis.xian.domain.ApiResponse;
|
||||||
|
import com.gis.xian.dto.pub.DZProductDTO;
|
||||||
|
import com.gis.xian.query.ProductQuery;
|
||||||
|
import com.gis.xian.service.pub.IDZProductService;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zzw
|
||||||
|
* @description: 产出结果控制类
|
||||||
|
* @date 2026/6/4 下午3:38
|
||||||
|
*/
|
||||||
|
public class DZProductController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IDZProductService idzProductService;
|
||||||
|
|
||||||
|
@PostMapping("/product")
|
||||||
|
public ApiResponse<List<DZProductDTO>> getProducts(@RequestBody ProductQuery query) {
|
||||||
|
List<DZProductDTO> products = idzProductService.getProducts(query);
|
||||||
|
return ApiResponse.ok(products);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,9 +6,14 @@ import org.springframework.amqp.core.*;
|
|||||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||||
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
|
import org.springframework.amqp.support.converter.AllowedListDeserializingMessageConverter;
|
||||||
|
import org.springframework.amqp.support.converter.MessageConverter;
|
||||||
|
import org.springframework.amqp.support.converter.SimpleMessageConverter;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author zzw
|
* @author zzw
|
||||||
* @description: RabbitMq 配置
|
* @description: RabbitMq 配置
|
||||||
@@ -66,11 +71,22 @@ public class RabbitConfig {
|
|||||||
return BindingBuilder.bind(dlqQueue()).to(exchange()).with(BaseConstants.DLQ_QUEUE);
|
return BindingBuilder.bind(dlqQueue()).to(exchange()).with(BaseConstants.DLQ_QUEUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public MessageConverter messageConverter() {
|
||||||
|
SimpleMessageConverter converter = new SimpleMessageConverter();
|
||||||
|
converter.setAllowedListPatterns(Arrays.asList(
|
||||||
|
"com.gis.xian.params.QgisArgs",
|
||||||
|
"com.gis.xian.domain.DlqMessage"
|
||||||
|
));
|
||||||
|
return converter;
|
||||||
|
}
|
||||||
|
|
||||||
// 设置消息回调函数 自动确认消息 ack
|
// 设置消息回调函数 自动确认消息 ack
|
||||||
@Bean
|
@Bean
|
||||||
public RabbitTemplate createRabbitTemplate(ConnectionFactory connectionFactory) {
|
public RabbitTemplate createRabbitTemplate(ConnectionFactory connectionFactory) {
|
||||||
RabbitTemplate rabbitTemplate = new RabbitTemplate();
|
RabbitTemplate rabbitTemplate = new RabbitTemplate();
|
||||||
rabbitTemplate.setConnectionFactory(connectionFactory);
|
rabbitTemplate.setConnectionFactory(connectionFactory);
|
||||||
|
rabbitTemplate.setMessageConverter(messageConverter());
|
||||||
// 设置开启Mandatory,才能触发回调函数,无论消息推送结果怎么样都强制调用回调函数
|
// 设置开启Mandatory,才能触发回调函数,无论消息推送结果怎么样都强制调用回调函数
|
||||||
rabbitTemplate.setMandatory(true);
|
rabbitTemplate.setMandatory(true);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,110 @@
|
|||||||
|
package com.gis.xian.listener;
|
||||||
|
|
||||||
|
import com.gis.xian.config.DataSourceContextHolder;
|
||||||
|
import com.gis.xian.constant.BaseConstants;
|
||||||
|
import com.gis.xian.entity.pub.DZProduct;
|
||||||
|
import com.gis.xian.params.QgisArgs;
|
||||||
|
import com.gis.xian.service.ex.ServeException;
|
||||||
|
import com.gis.xian.service.pub.IDZProductService;
|
||||||
|
import com.rabbitmq.client.Channel;
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.amqp.core.Message;
|
||||||
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||||
|
import org.springframework.amqp.support.AmqpHeaders;
|
||||||
|
import org.springframework.messaging.handler.annotation.Header;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zzw
|
||||||
|
* @description: 专题图产出监听器
|
||||||
|
* @date 2026/6/4 下午4:10
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class MapReceiveListener {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IDZProductService idzProductService;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void init() {
|
||||||
|
log.info("========================================");
|
||||||
|
log.info("MapReceiveListener 监听器已初始化");
|
||||||
|
log.info("正在监听队列: maps");
|
||||||
|
log.info("监听方法: receive(QgisArgs args, Channel channel, ...)");
|
||||||
|
log.info("ACK模式: MANUAL (手动确认)");
|
||||||
|
log.info("========================================");
|
||||||
|
}
|
||||||
|
|
||||||
|
// rabbitmq 监听专题图队列
|
||||||
|
@RabbitListener(queues = "maps", ackMode = "MANUAL")
|
||||||
|
public void receive(QgisArgs args, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag, Message message) throws IOException {
|
||||||
|
log.info("接收通知:{} 已生成!", args.getName());
|
||||||
|
try {
|
||||||
|
// 获取路径
|
||||||
|
File originFile = new File(args.getOutFile());
|
||||||
|
if (!originFile.exists()) {
|
||||||
|
throw new ServeException(BaseConstants.FILE_NOT_FOUND_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 直接使用本地文件路径保存到数据库
|
||||||
|
handleData(args, originFile.getAbsolutePath());
|
||||||
|
log.info("{} 本地路径已保存到数据库!", args.getName());
|
||||||
|
|
||||||
|
// 手动确认消息
|
||||||
|
channel.basicAck(deliveryTag, false);
|
||||||
|
log.info("ack:消息确认成功!");
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
log.error("处理消息失败: {}", ex);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数说明:
|
||||||
|
* 1. deliveryTag:消息唯一标识
|
||||||
|
* 2. multiple:是否拒绝多条
|
||||||
|
* 3. requeue:是否重新入队(false=直接丢弃,true=重新入队重试)
|
||||||
|
* 建议:非幂等业务设置为 false,避免死循环;幂等业务可设置为 true
|
||||||
|
*/
|
||||||
|
channel.basicNack(deliveryTag, false, false);
|
||||||
|
|
||||||
|
// 抛出异常
|
||||||
|
throw new ServeException(BaseConstants.THEMATIC_FAILED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleData(QgisArgs args, String filePath) {
|
||||||
|
try {
|
||||||
|
DataSourceContextHolder.setDataSource("slave1");
|
||||||
|
log.debug("切换数据源到: slave1");
|
||||||
|
|
||||||
|
DZProduct product = new DZProduct();
|
||||||
|
product.setEqQueueId(args.getQueueId());
|
||||||
|
product.setProTime(LocalDateTime.now());
|
||||||
|
product.setCode(args.getMapLayout());
|
||||||
|
product.setFileType("图片");
|
||||||
|
product.setFileName(args.getName());
|
||||||
|
product.setFilePath(args.getPath());
|
||||||
|
product.setFileExtension(".jpg");
|
||||||
|
// 地震/暴雨 专题图
|
||||||
|
product.setProType(args.getDisaster());
|
||||||
|
|
||||||
|
// 将本地文件路径设置到源文件字段中
|
||||||
|
product.setSourceFile(filePath);
|
||||||
|
|
||||||
|
// 将图件信息插入到结果表中
|
||||||
|
idzProductService.save(product);
|
||||||
|
log.info("{} 已保存到数据库!", args.getName());
|
||||||
|
} finally {
|
||||||
|
DataSourceContextHolder.clearDataSource();
|
||||||
|
log.debug("清除数据源上下文");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ import com.gis.xian.service.base.IShanXiCountyService;
|
|||||||
import com.gis.xian.service.base.IShanXiTownsService;
|
import com.gis.xian.service.base.IShanXiTownsService;
|
||||||
import com.gis.xian.service.dzxx.IDZXXDistanceService;
|
import com.gis.xian.service.dzxx.IDZXXDistanceService;
|
||||||
import com.gis.xian.service.ex.ParmaException;
|
import com.gis.xian.service.ex.ParmaException;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.locationtech.jts.geom.*;
|
import org.locationtech.jts.geom.*;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
@@ -35,11 +36,11 @@ import java.util.List;
|
|||||||
public class DZXXDistanceServiceImpl extends ServiceImpl<DZXXDistanceMapper, DZXXDistance> implements IDZXXDistanceService {
|
public class DZXXDistanceServiceImpl extends ServiceImpl<DZXXDistanceMapper, DZXXDistance> implements IDZXXDistanceService {
|
||||||
private static final GeometryFactory GEOMETRY_FACTORY = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING), 4326);
|
private static final GeometryFactory GEOMETRY_FACTORY = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING), 4326);
|
||||||
|
|
||||||
@Autowired
|
@Resource
|
||||||
private IShanXiCitiesService iShanXiCitiesService;
|
private IShanXiCitiesService iShanXiCitiesService;
|
||||||
@Autowired
|
@Resource
|
||||||
private IShanXiCountyService iShanXiCountyService;
|
private IShanXiCountyService iShanXiCountyService;
|
||||||
@Autowired
|
@Resource
|
||||||
private IShanXiTownsService iShanXiTownsService;
|
private IShanXiTownsService iShanXiTownsService;
|
||||||
|
|
||||||
// 处理所有乡镇表
|
// 处理所有乡镇表
|
||||||
|
|||||||
@@ -40,11 +40,11 @@ import java.util.List;
|
|||||||
public class DZXXInfluenceServiceImpl extends ServiceImpl<DZXXInfluenceMapper, DZXXInfluence> implements IDZXXInfluenceService {
|
public class DZXXInfluenceServiceImpl extends ServiceImpl<DZXXInfluenceMapper, DZXXInfluence> implements IDZXXInfluenceService {
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Resource
|
||||||
private IActiveFaultService faultService;
|
private IActiveFaultService faultService;
|
||||||
@Autowired
|
@Resource
|
||||||
private EllipseToWktHandler ellipseToWktHandler;
|
private EllipseToWktHandler ellipseToWktHandler;
|
||||||
@Autowired
|
@Resource
|
||||||
private IDZInfluenceService idzInfluenceService;
|
private IDZInfluenceService idzInfluenceService;
|
||||||
@Resource
|
@Resource
|
||||||
private EarthquakeHandler earthquakeHandler;
|
private EarthquakeHandler earthquakeHandler;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import com.gis.xian.service.ex.ServeException;
|
|||||||
import com.gis.xian.service.pub.IDZEqEventService;
|
import com.gis.xian.service.pub.IDZEqEventService;
|
||||||
import com.gis.xian.service.pub.IDZEqQueueService;
|
import com.gis.xian.service.pub.IDZEqQueueService;
|
||||||
import com.gis.xian.utils.BaseUtils;
|
import com.gis.xian.utils.BaseUtils;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -33,9 +34,9 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
@DataSource("slave1")
|
@DataSource("slave1")
|
||||||
public class DZEqEventServiceImpl extends ServiceImpl<DZEqEventMapper, DZEqEvent> implements IDZEqEventService {
|
public class DZEqEventServiceImpl extends ServiceImpl<DZEqEventMapper, DZEqEvent> implements IDZEqEventService {
|
||||||
|
|
||||||
@Autowired
|
@Resource
|
||||||
private IDZXXCenterService idzxxCenterService;
|
private IDZXXCenterService idzxxCenterService;
|
||||||
@Autowired
|
@Resource
|
||||||
private IDZEqQueueService idzEqQueueService;
|
private IDZEqQueueService idzEqQueueService;
|
||||||
|
|
||||||
// 地震业务触发
|
// 地震业务触发
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import com.gis.xian.service.ex.ServeException;
|
|||||||
import com.gis.xian.service.pub.IDZEqQueueService;
|
import com.gis.xian.service.pub.IDZEqQueueService;
|
||||||
import com.gis.xian.service.pub.IDZProductService;
|
import com.gis.xian.service.pub.IDZProductService;
|
||||||
import com.gis.xian.utils.BaseUtils;
|
import com.gis.xian.utils.BaseUtils;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -35,11 +36,11 @@ import java.time.LocalDateTime;
|
|||||||
@DataSource("slave1")
|
@DataSource("slave1")
|
||||||
public class DZEqQueueServiceImpl extends ServiceImpl<DZEqQueueMapper, DZEqQueue> implements IDZEqQueueService {
|
public class DZEqQueueServiceImpl extends ServiceImpl<DZEqQueueMapper, DZEqQueue> implements IDZEqQueueService {
|
||||||
|
|
||||||
@Autowired
|
@Resource
|
||||||
private IDZXXDistanceService idzxxDistanceService;
|
private IDZXXDistanceService idzxxDistanceService;
|
||||||
@Autowired
|
@Resource
|
||||||
private IDZXXInfluenceService idzxxInfluenceService;
|
private IDZXXInfluenceService idzxxInfluenceService;
|
||||||
@Autowired
|
@Resource
|
||||||
private IDZProductService idzProductService;
|
private IDZProductService idzProductService;
|
||||||
|
|
||||||
// 地震评估
|
// 地震评估
|
||||||
|
|||||||
Reference in New Issue
Block a user