dev
parent
eb4bb59f93
commit
4a38278c92
15
pom.xml
15
pom.xml
|
@ -72,6 +72,21 @@
|
|||
<version>2.0.39</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
package com.bwie;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* @Author: wangxinyuan
|
||||
* @Date: 2024/4/11 下午9:08
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package com.bwie;
|
||||
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author: wangxinyuan
|
||||
* @Date: 2024/4/14 上午9:38
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableScheduling
|
||||
public class ScheduledTaskApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ScheduledTaskApplication.class, args);
|
||||
}
|
||||
|
||||
@Component
|
||||
public class DataGenerator {
|
||||
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
@Scheduled(fixedRate = 5000) // 每5秒发送一次模拟数据
|
||||
public void generateData() {
|
||||
// 生成模拟数据
|
||||
Map<String, Object> data1 = generateData1();
|
||||
Map<String, Object> data2 = generateData2();
|
||||
Map<String, Object> data3 = generateData3();
|
||||
|
||||
// 发送模拟数据到对应的消息队列
|
||||
rabbitTemplate.convertAndSend("dandong", "data1", data1);
|
||||
rabbitTemplate.convertAndSend("dandong", "data2", data2);
|
||||
rabbitTemplate.convertAndSend("dandong", "data3", data3);
|
||||
|
||||
System.out.println("Simulated data sent to message queues.");
|
||||
}
|
||||
|
||||
private Map<String, Object> generateData1() {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("id", "403320120240308110035393");
|
||||
data.put("XM", "dongyc");
|
||||
data.put("Card", "320000");
|
||||
data.put("Age", 18);
|
||||
data.put("Time", LocalDateTime.now().toString());
|
||||
return data;
|
||||
}
|
||||
|
||||
private Map<String, Object> generateData2() {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("id", "403320120240308110035393");
|
||||
data.put("XM", "dongyc");
|
||||
data.put("Card", "320000198020236547");
|
||||
// Assuming base64 encoded photos
|
||||
data.put("Photo1", Base64.getEncoder().encodeToString("photo1".getBytes()));
|
||||
data.put("Photo2", Base64.getEncoder().encodeToString("photo2".getBytes()));
|
||||
return data;
|
||||
}
|
||||
|
||||
private Map<String, Object> generateData3() {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("id", "403320120240308110035393");
|
||||
data.put("plate", "苏D12345");
|
||||
data.put("Time", LocalDateTime.now().toString());
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.bwie.Service;
|
||||
|
||||
|
||||
import com.bwie.admin.Data;
|
||||
import com.bwie.mapper.MessageMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class DataService {
|
||||
|
||||
@Autowired
|
||||
private MessageMapper messageMapper;
|
||||
|
||||
public void saveOrUpdateMessage(Data message) {
|
||||
// 根据消息的ID查询数据库中是否存在该消息
|
||||
Data existingMessage = (Data) messageMapper.findById(message.getId()).orElse(null);
|
||||
|
||||
if (existingMessage != null) {
|
||||
// 如果数据库中已存在该消息,则更新
|
||||
existingMessage.setXM(message.getXM());
|
||||
existingMessage.setAge(message.getAge());
|
||||
existingMessage.setTime(message.getTime());
|
||||
existingMessage.setPlate(message.getPlate());
|
||||
existingMessage.setCard(message.getCard());
|
||||
existingMessage.setPhoto1(message.getPhoto1());
|
||||
existingMessage.setPhoto2(message.getPhoto2());
|
||||
messageMapper.save(existingMessage);
|
||||
} else {
|
||||
// 如果数据库中不存在该消息,则插入
|
||||
messageMapper.save(message);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.bwie.admin;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author: wangxinyuan
|
||||
* @Date: 2024/4/11 下午7:33
|
||||
*/
|
||||
|
||||
@lombok.Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Data {
|
||||
|
||||
|
||||
private String id;
|
||||
private String XM;
|
||||
private String Age;
|
||||
private String Time;
|
||||
private String plate;
|
||||
private String Card;
|
||||
private String Photo1;
|
||||
private String Photo2;
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.bwie.admin;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author: wangxinyuan
|
||||
* @Date: 2024/4/14 上午11:13
|
||||
*/
|
||||
@lombok.Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Data2 {
|
||||
|
||||
private String id;
|
||||
private String XM;
|
||||
private String Age;
|
||||
private String Time;
|
||||
private String plate;
|
||||
private String Card;
|
||||
private String Photo1;
|
||||
private String Photo2;
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.bwie.admin;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author: wangxinyuan
|
||||
* @Date: 2024/4/14 上午11:13
|
||||
*/
|
||||
@lombok.Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Data3 {
|
||||
|
||||
private String id;
|
||||
private String XM;
|
||||
private String Age;
|
||||
private String Time;
|
||||
private String plate;
|
||||
private String Card;
|
||||
private String Photo1;
|
||||
private String Photo2;
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package com.bwie.admin;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.deser.std.DateDeserializers;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author: wangxinyuan
|
||||
* @Date: 2024/4/11 下午7:33
|
||||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Pur {
|
||||
|
||||
|
||||
private String id;
|
||||
|
||||
private String xm;
|
||||
|
||||
private String age;
|
||||
|
||||
private String time;
|
||||
|
||||
private String card;
|
||||
|
||||
private String photo1;
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package com.bwie.admin;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author: wangxinyuan
|
||||
* @Date: 2024/4/12 下午3:10
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Pur2 {
|
||||
|
||||
private String id;
|
||||
|
||||
private String xm;
|
||||
|
||||
|
||||
|
||||
private String card;
|
||||
|
||||
private String photo1;
|
||||
|
||||
private String photo2;
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package com.bwie.admin;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author: wangxinyuan
|
||||
* @Date: 2024/4/12 下午3:12
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Pur3 {
|
||||
|
||||
private String id;
|
||||
|
||||
|
||||
private String time;
|
||||
|
||||
private String plate;
|
||||
|
||||
|
||||
}
|
|
@ -4,6 +4,9 @@ import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
|||
import org.springframework.amqp.support.converter.MessageConverter;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class RabbitmqConfig {
|
||||
|
@ -12,4 +15,22 @@ public class RabbitmqConfig {
|
|||
public MessageConverter jsonMessageConverter() {
|
||||
return new Jackson2JsonMessageConverter();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Queue data1Queue() {
|
||||
return new Queue("data1_queue", true);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Queue data2Queue() {
|
||||
return new Queue("data2_queue", true);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Queue data3Queue() {
|
||||
return new Queue("data3_queue", true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
//package com.bwie.consumer;
|
||||
//
|
||||
//import lombok.extern.log4j.Log4j2;
|
||||
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.jdbc.core.JdbcTemplate;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import java.sql.Timestamp;
|
||||
//
|
||||
///**
|
||||
// * @Author: wangxinyuan
|
||||
// * @Date: 2024/4/11 下午7:40
|
||||
// */
|
||||
////@Component
|
||||
//@Log4j2
|
||||
//public class ConsumeData2 {
|
||||
//
|
||||
// //@Autowired
|
||||
// private JdbcTemplate jdbcTemplate;
|
||||
//
|
||||
// //@RabbitListener(queues = "data2")
|
||||
// public void consumeData2(String message) {
|
||||
// log.info("Received data2: " + message);
|
||||
// saveDataToDatabase(message);
|
||||
// }
|
||||
//
|
||||
// private void saveDataToDatabase(String message) {
|
||||
// try {
|
||||
// String[] parts = message.split(",");
|
||||
// if (parts.length >= 9) {
|
||||
// String id = parts[0];
|
||||
// String XM = parts[1];
|
||||
// String Age = parts[2];
|
||||
// String timeStr = parts[3];
|
||||
// Timestamp Time = Timestamp.valueOf(timeStr);
|
||||
// String plate = parts[4];
|
||||
// String Card = parts[5];
|
||||
// String Photo1 = parts[7];
|
||||
// String Photo2 = parts[8];
|
||||
//
|
||||
//
|
||||
// String querySql = "SELECT * FROM pur WHERE id = ?";
|
||||
// Integer count = jdbcTemplate.queryForObject(querySql, new Object[]{id}, Integer.class);
|
||||
//
|
||||
// if (count == null || count == 0) {
|
||||
// String insertSql = "INSERT INTO pur (id, XM, Age, Time, plate, Card, Photo1, Photo2) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
// jdbcTemplate.update(insertSql, id, XM, Age, Time, plate, Card, Photo1, Photo2);
|
||||
// log.info("Data saved to database successfully.");
|
||||
// } else {
|
||||
// String updateSql = "UPDATE pur SET XM = ?, Age = ?, Time = ?, plate = ?, Card = ?, Photo1 = ?, Photo2 = ? WHERE id = ?";
|
||||
// jdbcTemplate.update(updateSql, XM, Age, Time, plate, Card, Photo1, Photo2, id);
|
||||
// log.info("Data updated in database successfully.");
|
||||
// }
|
||||
// } else {
|
||||
// log.info("Data saved to database failed.");
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// log.error("Error while saving data to database: " + e.getMessage());
|
||||
// }
|
||||
// }
|
||||
//}
|
|
@ -1,64 +0,0 @@
|
|||
//package com.bwie.consumer;
|
||||
//
|
||||
//import lombok.extern.log4j.Log4j2;
|
||||
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.jdbc.core.JdbcTemplate;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import java.sql.Timestamp;
|
||||
//
|
||||
///**
|
||||
// * @Author: wangxinyuan
|
||||
// * @Date: 2024/4/11 下午7:40
|
||||
// */
|
||||
////@Component
|
||||
//@Log4j2
|
||||
//public class ConsumeData3 {
|
||||
//
|
||||
//
|
||||
// //@Autowired
|
||||
// private JdbcTemplate jdbcTemplate;
|
||||
//
|
||||
// //@RabbitListener(queues = "data3")
|
||||
// public void consumeData3(String message) {
|
||||
// log.info("Received data3: " + message);
|
||||
// saveDataToDatabase(message);
|
||||
// }
|
||||
//
|
||||
// private void saveDataToDatabase(String message) {
|
||||
// try {
|
||||
// String[] parts = message.split(",");
|
||||
// if (parts.length >= 9) {
|
||||
// String id = parts[0];
|
||||
// String XM = parts[1];
|
||||
// String Age = parts[2];
|
||||
// String timeStr = parts[3];
|
||||
// Timestamp Time = Timestamp.valueOf(timeStr);
|
||||
// String plate = parts[4];
|
||||
// String Card = parts[5];/**/
|
||||
// String Photo1 = parts[7];
|
||||
// String Photo2 = parts[8];
|
||||
//
|
||||
//
|
||||
// String querySql = "SELECT * FROM pur WHERE id = ?";
|
||||
// Integer count = jdbcTemplate.queryForObject(querySql, new Object[]{id}, Integer.class);
|
||||
//
|
||||
//
|
||||
// if (count == null || count == 0) {
|
||||
// String insertSql = "INSERT INTO pur (id, XM, Age, Time, plate, Card, Photo1, Photo2) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
// jdbcTemplate.update(insertSql, id, XM, Age, Time, plate, Card, Photo1, Photo2);
|
||||
// log.info("Data saved to database successfully.");
|
||||
// } else {
|
||||
// String updateSql = "UPDATE pur SET XM = ?, Age = ?, Time = ?, plate = ?, Card = ?, Photo1 = ?, Photo2 = ? WHERE id = ?";
|
||||
// jdbcTemplate.update(updateSql, XM, Age, Time, plate, Card, Photo1, Photo2, id);
|
||||
// log.info("Data updated in database successfully.");
|
||||
// }
|
||||
// } else {
|
||||
// log.info("Data saved to database failed.");
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// log.error("Error while saving data to database: " + e.getMessage());
|
||||
// }
|
||||
// }
|
||||
//}
|
|
@ -1,70 +0,0 @@
|
|||
//package com.bwie.consumer;
|
||||
//
|
||||
//import com.bwie.admin.Pur;
|
||||
//import lombok.extern.log4j.Log4j2;
|
||||
//import org.junit.jupiter.api.Test;
|
||||
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.jdbc.core.JdbcTemplate;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import java.sql.Timestamp;
|
||||
//import java.util.Date;
|
||||
//
|
||||
///**
|
||||
// * @Author: wangxinyuan
|
||||
// * @Date: 2024/4/11 下午7:40
|
||||
// */
|
||||
////@Component
|
||||
//@Log4j2
|
||||
//public class ConsumerDate1 {
|
||||
//
|
||||
//
|
||||
// //@Autowired
|
||||
// private JdbcTemplate jdbcTemplate;
|
||||
//
|
||||
// //@RabbitListener(queues = "data1")
|
||||
// public void consumeData1(String message) {
|
||||
// log.info("Received data1: " + message);
|
||||
// saveDataToDatabase(message);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private void saveDataToDatabase(String message) {
|
||||
// try {
|
||||
// String[] parts = message.split(",");
|
||||
// if (parts.length >= 9) {
|
||||
// String id = parts[0];
|
||||
// String XM = parts[1];
|
||||
// String Age = parts[2];
|
||||
// String timeStr = parts[3];
|
||||
// Timestamp Time = Timestamp.valueOf(timeStr);
|
||||
// String plate = parts[4];
|
||||
// String Card = parts[5];
|
||||
// String Photo1 = parts[7];
|
||||
// String Photo2 = parts[8];
|
||||
//
|
||||
// String querySql = "SELECT * FROM pur WHERE id = ?";
|
||||
// Integer count = jdbcTemplate.queryForObject(querySql, new Object[]{id}, Integer.class);
|
||||
//
|
||||
//
|
||||
// if (count == null || count == 0) {
|
||||
// String insertSql = "INSERT INTO pur (id, XM, Age, Time, plate, Card, Photo1, Photo2) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
// jdbcTemplate.update(insertSql, id, XM, Age, Time, plate, Card, Photo1, Photo2);
|
||||
// log.info("Data saved to database successfully.");
|
||||
// } else {
|
||||
// String updateSql = "UPDATE pur SET XM = ?, Age = ?, Time = ?, plate = ?, Card = ?, Photo1 = ?, Photo2 = ? WHERE id = ?";
|
||||
// jdbcTemplate.update(updateSql, XM, Age, Time, plate, Card, Photo1, Photo2, id);
|
||||
// log.info("Data updated in database successfully.");
|
||||
// }
|
||||
// } else {
|
||||
// log.info("Data saved to database failed.");
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// log.error("Error while saving data to database: " + e.getMessage());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//}
|
|
@ -0,0 +1,21 @@
|
|||
package com.bwie.consumer;
|
||||
|
||||
import com.bwie.Service.DataService;
|
||||
import com.bwie.admin.Data;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class Data1Consumer {
|
||||
|
||||
@Autowired
|
||||
private DataService messageService;
|
||||
|
||||
@RabbitListener(queues = "data1_queue")
|
||||
public void consumeData1(Data message) {
|
||||
System.out.println("Received data1 message: " + message);
|
||||
// 保存或更新消息到数据库
|
||||
messageService.saveOrUpdateMessage(message);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.bwie.consumer;
|
||||
|
||||
import com.bwie.Service.DataService;
|
||||
import com.bwie.admin.Data;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Author: wangxinyuan
|
||||
* @Date: 2024/4/14 上午10:07
|
||||
*/
|
||||
@Component
|
||||
public class Data2Consumer {
|
||||
|
||||
@Autowired
|
||||
private DataService messageService;
|
||||
|
||||
@RabbitListener(queues = "data2_queue")
|
||||
public void consumeData1(Data message) {
|
||||
System.out.println("Received data2 message: " + message);
|
||||
// 保存或更新消息到数据库
|
||||
messageService.saveOrUpdateMessage(message);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.bwie.consumer;
|
||||
|
||||
import com.bwie.Service.DataService;
|
||||
import com.bwie.admin.Data;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Author: wangxinyuan
|
||||
* @Date: 2024/4/14 上午10:07
|
||||
*/
|
||||
@Component
|
||||
public class Data3Consumer {
|
||||
|
||||
@Autowired
|
||||
private DataService messageService;
|
||||
|
||||
@RabbitListener(queues = "data3_queue")
|
||||
public void consumeData1(Data message) {
|
||||
System.out.println("Received data3 message: " + message);
|
||||
// 保存或更新消息到数据库
|
||||
messageService.saveOrUpdateMessage(message);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,116 +0,0 @@
|
|||
package com.bwie.consumer;
|
||||
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.bwie.admin.Pur;
|
||||
import com.bwie.admin.Pur2;
|
||||
import com.bwie.admin.Pur3;
|
||||
import com.bwie.controller.PurController;
|
||||
import com.bwie.mapper.PurMapper;
|
||||
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import com.rabbitmq.client.Channel;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @Author: wangxinyuan
|
||||
* @Date: 2024/4/11 下午9:24
|
||||
*/
|
||||
@Component
|
||||
@Log4j2
|
||||
public class DataConsumer {
|
||||
|
||||
|
||||
@Autowired
|
||||
private PurController purController;
|
||||
|
||||
|
||||
@Autowired
|
||||
private PurMapper purMapper;
|
||||
|
||||
|
||||
@RabbitListener(queuesToDeclare = {@Queue(name = "data1")})
|
||||
public void consumeData1(Object data, Channel channel, Message message) throws IOException {
|
||||
Pur pur = new Pur();
|
||||
if (pur != null) {
|
||||
pur = (Pur) data;
|
||||
}
|
||||
log.info("消费的数据为:{}", JSONObject.toJSONString(pur));
|
||||
List<String> list = purMapper.list();
|
||||
int count = 0;
|
||||
if (pur.getId() != null && !"".equals(pur.getId())) {
|
||||
for (String s : list) {
|
||||
if (pur.getId().equals(s)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (count > 0) {
|
||||
purMapper.updateData1(pur);
|
||||
} else {
|
||||
purMapper.insertData1(pur);
|
||||
}
|
||||
}
|
||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
||||
}
|
||||
|
||||
@RabbitListener(queuesToDeclare = {@Queue(name = "data2")})
|
||||
public void consumeData2(Object data, Channel channel, Message message) throws IOException {
|
||||
Pur2 pur2 = new Pur2();
|
||||
if (pur2 != null) {
|
||||
pur2 = (Pur2) data;
|
||||
}
|
||||
log.info("消费的数据为:{}", JSONObject.toJSONString(pur2));
|
||||
List<String> list = purMapper.Purlist2();
|
||||
int count = 0;
|
||||
if (pur2.getId() != null && !"".equals(pur2.getId())) {
|
||||
for (String s : list) {
|
||||
if (pur2.getId().equals(s)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (count > 0) {
|
||||
purMapper.updateData2(pur2);
|
||||
} else {
|
||||
purMapper.insertData2(pur2);
|
||||
}
|
||||
}
|
||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
||||
}
|
||||
|
||||
@RabbitListener(queuesToDeclare = {@Queue(name = "data3")})
|
||||
public void consumeData3(Object data, Channel channel, Message message) throws IOException {
|
||||
Pur3 pur3 = new Pur3();
|
||||
if (pur3 != null) {
|
||||
pur3 = (Pur3) data;
|
||||
}
|
||||
log.info("消费的数据为:{}", JSONObject.toJSONString(pur3));
|
||||
List<String> list = purMapper.Purlist3();
|
||||
int count = 0;
|
||||
if (pur3.getId() != null && !"".equals(pur3.getId())) {
|
||||
for (String s : list) {
|
||||
if (pur3.getId().equals(s)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (count > 0) {
|
||||
purMapper.updateData3(pur3);
|
||||
} else {
|
||||
purMapper.insertData3(pur3);
|
||||
}
|
||||
}
|
||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package com.bwie.consumer;
|
||||
|
||||
import com.bwie.admin.Data;
|
||||
import com.bwie.util.RandomUtil;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Base64;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @Author: wangxinyuan
|
||||
* @Date: 2024/4/14 下午2:16
|
||||
*/
|
||||
@Component
|
||||
public class DataGeneratorTask {
|
||||
@Autowired
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
|
||||
@Scheduled(cron = "0/10 * * * * ?") // 每10秒执行一次
|
||||
public void generateData() {
|
||||
// 生成随机数据
|
||||
String id = UUID.randomUUID().toString();
|
||||
String XM = RandomUtil.generateRandomAlphabetic(8);
|
||||
String Age = RandomUtil.generateRandomAlphabetic(2);
|
||||
String Time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
String plate = RandomUtil.generateRandomAlphabetic(7);
|
||||
String Card = RandomUtil.generateRandomAlphabetic(18);
|
||||
|
||||
// 创建实体类对象
|
||||
Data data1 = new Data(id, XM, Age, Time, plate, Card,"","");
|
||||
Data data2 = new Data(id, XM, Age, Time, plate, Card,"","");
|
||||
Data data3 = new Data(id, XM, Age, Time, plate, Card,"","");
|
||||
|
||||
// 发送消息到对应的消息队列
|
||||
rabbitTemplate.convertAndSend("data1Queue", data1);
|
||||
rabbitTemplate.convertAndSend("data2Queue", data2);
|
||||
rabbitTemplate.convertAndSend("data3Queue", data3);
|
||||
}
|
||||
}
|
|
@ -1,48 +1,42 @@
|
|||
package com.bwie.controller;
|
||||
|
||||
|
||||
import com.bwie.admin.Pur;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.amqp.AmqpException;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: wangxinyuan
|
||||
* @Date: 2024/4/11 下午10:37
|
||||
*/
|
||||
@RestController
|
||||
public class PurController {
|
||||
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
|
||||
|
||||
@GetMapping("/data1")
|
||||
@Transactional
|
||||
public void sendData1() throws JsonProcessingException {
|
||||
Pur pur = new Pur();
|
||||
pur.setId("593720128240812819055333");
|
||||
pur.setXm("dsc");
|
||||
pur.setCard("128963");
|
||||
pur.setAge("56");
|
||||
pur.setTime("2022-10-10 10:10:11");
|
||||
String message = objectMapper.writeValueAsString(pur);
|
||||
rabbitTemplate.convertAndSend("data1", "id", message);
|
||||
}
|
||||
|
||||
}
|
||||
//package com.bwie.controller;
|
||||
//
|
||||
//
|
||||
//import com.bwie.admin.Message;
|
||||
//
|
||||
//import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
//import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
//import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.transaction.annotation.Transactional;
|
||||
//import org.springframework.web.bind.annotation.GetMapping;
|
||||
//import org.springframework.web.bind.annotation.RestController;
|
||||
//
|
||||
///**
|
||||
// * @Author: wangxinyuan
|
||||
// * @Date: 2024/4/11 下午10:37
|
||||
// */
|
||||
//@RestController
|
||||
//public class PurController {
|
||||
//
|
||||
// @Autowired
|
||||
// private RabbitTemplate rabbitTemplate;
|
||||
//
|
||||
// @Autowired
|
||||
// private ObjectMapper objectMapper;
|
||||
//
|
||||
//
|
||||
//
|
||||
// @GetMapping("/data1")
|
||||
//// @Transactional
|
||||
// public void sendData1() throws JsonProcessingException {
|
||||
// Message pur = new Message();
|
||||
// pur.setId("593720128240812819055333");
|
||||
// pur.setXm("dsc");
|
||||
// pur.setCard("128963");
|
||||
// pur.setAge("56");
|
||||
// pur.setTime("2022-10-10 10:10:11");
|
||||
// String message = objectMapper.writeValueAsString(pur);
|
||||
// rabbitTemplate.convertAndSend("data1", "id", message);
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package com.bwie.mapper;
|
||||
|
||||
import com.bwie.admin.Data;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: wangxinyuan
|
||||
* @Date: 2024/4/14 上午11:17
|
||||
*/
|
||||
@Mapper
|
||||
public interface Data1Mapper {
|
||||
|
||||
List<Data> selectAll();
|
||||
|
||||
|
||||
List<Data> selectByTime(String lastTime);
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.bwie.mapper;
|
||||
|
||||
import com.bwie.admin.Data2;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @Author: wangxinyuan
|
||||
* @Date: 2024/4/14 上午11:33
|
||||
*/
|
||||
@Mapper
|
||||
public interface Data2Mapper {
|
||||
Data2 selectByData1Id(String id);
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.bwie.mapper;
|
||||
|
||||
import com.bwie.admin.Data3;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @Author: wangxinyuan
|
||||
* @Date: 2024/4/14 上午11:33
|
||||
*/
|
||||
@Mapper
|
||||
public interface Data3Mapper {
|
||||
|
||||
|
||||
Data3 selectByData1Id(String id);
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.bwie.mapper;
|
||||
|
||||
import com.bwie.admin.Data;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @Author: wangxinyuan
|
||||
* @Date: 2024/4/14 上午10:33
|
||||
*/
|
||||
@Mapper
|
||||
public interface MessageMapper {
|
||||
Optional<Object> findById(String id);
|
||||
|
||||
void save(Data existingMessage);
|
||||
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package com.bwie.mapper;
|
||||
|
||||
import com.bwie.admin.Pur;
|
||||
import com.bwie.admin.Pur2;
|
||||
import com.bwie.admin.Pur3;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: wangxinyuan
|
||||
* @Date: 2024/4/11 下午11:34
|
||||
*/
|
||||
@Mapper
|
||||
public interface PurMapper {
|
||||
List<String> list();
|
||||
|
||||
void updateData1(Pur pur);
|
||||
|
||||
void insertData1(Pur pur);
|
||||
|
||||
|
||||
List<String> Purlist2();
|
||||
|
||||
void updateData2(Pur2 pur2);
|
||||
|
||||
void insertData2(Pur2 pur2);
|
||||
|
||||
List<String> Purlist3();
|
||||
|
||||
void updateData3(Pur3 pur3);
|
||||
|
||||
void insertData3(Pur3 pur3);
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
package com.bwie.task;
|
||||
import com.bwie.admin.Data;
|
||||
import com.bwie.admin.Data2;
|
||||
import com.bwie.admin.Data3;
|
||||
import com.bwie.mapper.Data1Mapper;
|
||||
import com.bwie.mapper.Data2Mapper;
|
||||
import com.bwie.mapper.Data3Mapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.bwie.util.PhotoUtils.savePhoto;
|
||||
|
||||
|
||||
/**
|
||||
* @Author: wangxinyuan
|
||||
* @Date: 2024/4/14 上午11:06
|
||||
*/
|
||||
@Component
|
||||
public class SpringTask {
|
||||
|
||||
@Autowired
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
@Autowired
|
||||
private Data1Mapper data1Mapper;
|
||||
|
||||
@Autowired
|
||||
private Data2Mapper data2Mapper;
|
||||
|
||||
@Autowired
|
||||
private Data3Mapper data3Mapper;
|
||||
|
||||
|
||||
@Async
|
||||
public void execute() throws IOException {
|
||||
|
||||
// 1. 从Redis中获取最新的数据时间
|
||||
String lastTime = stringRedisTemplate.opsForValue().get("dataLastTime");
|
||||
|
||||
// 根据时间查询data1的数据
|
||||
List<Data> data1s = new ArrayList<>();
|
||||
if (lastTime == null) {
|
||||
data1s = data1Mapper.selectAll();
|
||||
} else {
|
||||
data1s = data1Mapper.selectByTime(lastTime);
|
||||
}
|
||||
|
||||
// 遍历data1s 根据id查询去data2和data3查询
|
||||
for (Data data1 : data1s) {
|
||||
// 根据data1的ID查询data2和data3
|
||||
Data2 data2 = data2Mapper.selectByData1Id(data1.getId());
|
||||
Data3 data3 = data3Mapper.selectByData1Id(data1.getId());
|
||||
|
||||
// 如果查询到的data2和data3有一个为空,则跳过当前数据
|
||||
if (data2 == null || data3 == null) {
|
||||
continue;
|
||||
}
|
||||
// 5. 编写图片保存方法,将图片存储到本地路径 ,并返回图片名称
|
||||
String photoName1 = savePhoto(data1.getPhoto1());
|
||||
String photoName2 = savePhoto(data1.getPhoto2());
|
||||
|
||||
// 6. 根据data1、2、3及返回的图片名称,拼接字符串写入到bcp文件中,并返回文件名称
|
||||
String fileName = writeToBcpFile(data1, data2, data3, photoName1, photoName2);
|
||||
|
||||
|
||||
}
|
||||
// 处理完数据后,更新Redis中存储的最新数据时间
|
||||
if (!data1s.isEmpty()) {
|
||||
String newestTime = data1s.get(data1s.size() - 1).getTime();
|
||||
stringRedisTemplate.opsForValue().set("dataLastTime", newestTime);
|
||||
}
|
||||
}
|
||||
|
||||
private String writeToBcpFile(Data data1, Data2 data2, Data3 data3, String photoName1, String photoName2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,109 +0,0 @@
|
|||
package com.bwie.task;
|
||||
|
||||
import com.bwie.admin.Pur;
|
||||
import com.bwie.admin.Pur2;
|
||||
import com.bwie.admin.Pur3;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: wangxinyuan
|
||||
* @Date: 2024/4/12 下午3:35
|
||||
*/
|
||||
@Component
|
||||
public class Task {
|
||||
|
||||
@Scheduled(cron = "0 0/1 * * * ?") // 每分钟执行一次
|
||||
public void doTask() {
|
||||
// 查询data1的全部数据,得到data1s
|
||||
List<Pur> data1s = queryPur1();
|
||||
|
||||
for (Pur data1 : data1s) {
|
||||
// 根据id去data2和data3进行查询
|
||||
Pur2 data2 = queryPur2(data1.getId());
|
||||
Pur3 data3 = queryPur3(data1.getId());
|
||||
|
||||
// 如果查询到的data2和data3有一个为空,则跳过,等待下次定时调度
|
||||
if (data2 == null || data3 == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 编写图片保存方法,将图片存储到本地路径 ,并返回图片名称
|
||||
String imageName = saveImage(data1.getPhoto1());
|
||||
|
||||
// 根据data1、2、3及返回的图片名称,拼接字符串写入到bcp文件中,并返回文件名称
|
||||
String bcpFileName = writeBcpFile(data1, data2, data3, imageName);
|
||||
|
||||
// 写入规则为字段+"\t"
|
||||
// 读取索引的模板文件(xml),并替换掉文件名称,并将新的xml内容写到文件中
|
||||
String xmlFileName = replaceXmlContent(bcpFileName);
|
||||
|
||||
// 压缩生产的三个文件为zip,压缩到其他目录
|
||||
String zipFileName = compressFiles(bcpFileName, xmlFileName, imageName);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private String compressFiles(String bcpFileName, String xmlFileName, String imageName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private String replaceXmlContent(String bcpFileName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private String writeBcpFile(Pur data1, Pur2 data2, Pur3 data3, String imageName) {
|
||||
// 实现根据data1、2、3及返回的图片名称,拼接字符串写入到bcp文件中,并返回文件名称的逻辑
|
||||
try {
|
||||
String fileName = "D:/save/files/" + data1.getId() + ".bcp";
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
|
||||
writer.write(data1.toString() + "\t");
|
||||
writer.write(data2.toString() + "\t");
|
||||
writer.write(data3.toString() + "\t");
|
||||
writer.write(imageName);
|
||||
writer.close();
|
||||
return fileName;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private String saveImage(String photo1) {
|
||||
try {
|
||||
URL url = new URL(photo1);
|
||||
String fileName = photo1.substring(photo1.lastIndexOf("/") + 1);
|
||||
InputStream inputStream = url.openStream();
|
||||
FileOutputStream outputStream = new FileOutputStream("D:/to/image/" + fileName);
|
||||
byte[] buffer = new byte[4096];
|
||||
int bytesRead;
|
||||
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
||||
outputStream.write(buffer, 0, bytesRead);
|
||||
}
|
||||
inputStream.close();
|
||||
outputStream.close();
|
||||
return fileName;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Pur3 queryPur3(String id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private Pur2 queryPur2(String id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<Pur> queryPur1() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.bwie.util;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Base64;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @Author: wangxinyuan
|
||||
* @Date: 2024/4/14 上午11:58
|
||||
*/
|
||||
public class PhotoUtils {
|
||||
|
||||
public static String savePhoto(String base64EncodedPhoto) throws IOException {
|
||||
// 解码base64字符串为字节数组
|
||||
byte[] photoBytes = Base64.getDecoder().decode(base64EncodedPhoto);
|
||||
|
||||
// 生成随机的文件名
|
||||
String photoName = UUID.randomUUID().toString() + ".jpg";
|
||||
|
||||
// 设置保存图片的路径
|
||||
String filePath = "D:/path/ppp/save/photo/" + photoName;
|
||||
|
||||
// 将字节数组写入文件
|
||||
try (FileOutputStream fos = new FileOutputStream(filePath)) {
|
||||
fos.write(photoBytes);
|
||||
}
|
||||
|
||||
// 返回图片名称
|
||||
return photoName;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.bwie.util;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @Author: wangxinyuan
|
||||
* @Date: 2024/4/14 下午2:27
|
||||
*/
|
||||
public class RandomUtil {
|
||||
|
||||
private static final Random RANDOM = new Random();
|
||||
|
||||
// 生成一个指定范围内的随机整数
|
||||
public static int generateRandomInt(int min, int max) {
|
||||
return RANDOM.nextInt(max - min + 1) + min;
|
||||
}
|
||||
|
||||
// 生成一个随机长整数
|
||||
public static long generateRandomLong() {
|
||||
return RANDOM.nextLong();
|
||||
}
|
||||
|
||||
// 生成一个随机浮点数
|
||||
public static double generateRandomDouble() {
|
||||
return RANDOM.nextDouble();
|
||||
}
|
||||
|
||||
// 生成一个随机布尔值
|
||||
public static boolean generateRandomBoolean() {
|
||||
return RANDOM.nextBoolean();
|
||||
}
|
||||
|
||||
// 生成一个指定长度的随机字母字符串
|
||||
public static String generateRandomAlphabetic(int length) {
|
||||
String alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < length; i++) {
|
||||
builder.append(alphabet.charAt(RANDOM.nextInt(alphabet.length())));
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
// 生成一个指定长度的随机数字字符串
|
||||
public static String generateRandomNumeric(int length) {
|
||||
String digits = "0123456789";
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < length; i++) {
|
||||
builder.append(digits.charAt(RANDOM.nextInt(digits.length())));
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
|
||||
# Tomcat
|
||||
server:
|
||||
port: 9000
|
||||
port: 9899
|
||||
redis:
|
||||
host: 111.231.174.71
|
||||
port: 6379
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
|
@ -9,7 +11,7 @@ spring:
|
|||
# 应用名称
|
||||
name: boot-4.11z
|
||||
rabbitmq:
|
||||
host: 111.231.174.71
|
||||
host: 43.142.117.78
|
||||
port: 5672
|
||||
username: guest
|
||||
password: guest
|
||||
|
@ -51,6 +53,7 @@ spring:
|
|||
use-global-data-source-stat: true
|
||||
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
|
||||
connect-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
|
||||
|
||||
# mybatis
|
||||
mybatis:
|
||||
configuration:
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.bwie.mapper.Data1Mapper">
|
||||
|
||||
|
||||
<select id="selectAll" resultType="com.bwie.admin.Data">
|
||||
select id , XM , Card , Age , now() from pur
|
||||
</select>
|
||||
|
||||
<select id="selectByTime" resultType="com.bwie.admin.Data">
|
||||
SELECT * FROM pur WHERE Time > #{Time}
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.bwie.mapper.Data2Mapper">
|
||||
|
||||
|
||||
<select id="selectByData1Id" resultType="com.bwie.admin.Data2">
|
||||
select id , XM , Card , Age , now() from pur where id = #{id}
|
||||
</select>
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.bwie.mapper.Data3Mapper">
|
||||
|
||||
|
||||
<select id="selectByData1Id" resultType="com.bwie.admin.Data3">
|
||||
select id , XM , Card , Age , now() from pur where id = #{id}
|
||||
</select>
|
||||
</mapper>
|
|
@ -1,54 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.bwie.mapper.PurMapper">
|
||||
<mapper namespace="com.bwie.mapper.MessageMapper">
|
||||
|
||||
<insert id="insertData1">
|
||||
INSERT INTO pur (id, xm, age, time, plate, card, photo1, photo2)
|
||||
VALUES (#{id}, #{xm}, #{age}, #{time}, #{plate}, #{card}, #{photo1}, #{photo2});
|
||||
</insert>
|
||||
|
||||
<select id="list" resultType="java.lang.String">
|
||||
-- 查询所有数据
|
||||
SELECT id , xm , age , time , plate , card , photo1 , photo2 FROM pur;
|
||||
</select>
|
||||
<update id="save">
|
||||
|
||||
<insert id="insertData2">
|
||||
INSERT INTO pur (id, xm, age, time, plate, card, photo1, photo2)
|
||||
VALUES (#{id}, #{xm}, #{age}, #{time}, #{plate}, #{card}, #{photo1}, #{photo2});
|
||||
</insert>
|
||||
|
||||
<insert id="insertData3">
|
||||
INSERT INTO pur (id, xm, age, time, plate, card, photo1, photo2)
|
||||
VALUES (#{id}, #{xm}, #{age}, #{time}, #{plate}, #{card}, #{photo1}, #{photo2});
|
||||
</insert>
|
||||
|
||||
<update id="updateData1">
|
||||
-- 更新数据
|
||||
UPDATE pur
|
||||
SET xm = #{xm}, age = #{age}, time = #{time}, plate = #{plate}, card = #{card}, photo1 = #{photo1}, photo2 = #{photo2}
|
||||
WHERE id = #{id};
|
||||
</update>
|
||||
|
||||
|
||||
<update id="updateData2">
|
||||
UPDATE pur
|
||||
SET xm = #{xm}, age = #{age}, time = #{time}, plate = #{plate}, card = #{card}, photo1 = #{photo1}, photo2 = #{photo2}
|
||||
WHERE id = #{id};
|
||||
</update>
|
||||
|
||||
|
||||
<update id="updateData3">
|
||||
UPDATE pur
|
||||
SET xm = #{xm}, age = #{age}, time = #{time}, plate = #{plate}, card = #{card}, photo1 = #{photo1}, photo2 = #{photo2}
|
||||
WHERE id = #{id};
|
||||
</update>
|
||||
|
||||
<select id="Purlist3" resultType="java.lang.String">
|
||||
SELECT id , xm , age , time , plate , card , photo1 , photo2 FROM pur;
|
||||
<select id="findById" resultType="java.lang.Object">
|
||||
select * from pur
|
||||
</select>
|
||||
|
||||
<select id="Purlist2" resultType="java.lang.String">
|
||||
SELECT id , xm , age , time , plate , card , photo1 , photo2 FROM pur;
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue