From 1c274b93c3573115d9ba794a3b7e630655abf291 Mon Sep 17 00:00:00 2001 From: vastlan Date: Tue, 13 Aug 2024 17:20:04 +0800 Subject: [PATCH 1/2] =?UTF-8?q?chore:=20=E5=8A=A0=E5=85=A5nacos=E9=80=82?= =?UTF-8?q?=E9=85=8D=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 88 +++++++++++++++++-- .../com/binary/weight/WeightApplication.java | 2 +- .../weight/controller/SSEController.java | 3 +- .../weight/controller/WeightController.java | 4 +- .../binary/weight/service/SyncService.java | 2 +- .../binary/weight/service/WeightService.java | 2 +- .../binary/weight/timer/WeightDataTimer.java | 2 +- src/main/resources/application.yml | 22 ++--- src/main/resources/bootstrap.yml | 4 +- 9 files changed, 103 insertions(+), 26 deletions(-) diff --git a/pom.xml b/pom.xml index 1e5a168..56399c3 100644 --- a/pom.xml +++ b/pom.xml @@ -2,21 +2,74 @@ 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 3.2.3 - - + + + + + + com.binary weight 0.0.1-SNAPSHOT weight Weight project for Spring Boot + 17 + 2.7.15 + 2021.0.8 + 17 + 17 + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + 2021.1 + pom + import + + + + + + org.springframework.cloud + spring-cloud-starter-bootstrap + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + org.springframework.cloud + spring-cloud-starter-loadbalancer + + org.apache.commons commons-lang3 @@ -51,10 +104,33 @@ + ${project.name}-server + org.springframework.boot spring-boot-maven-plugin + + + + repackage + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.11.0 + + ${maven.compile.source} + ${maven.compile.target} + UTF-8 + + -parameters + + diff --git a/src/main/java/com/binary/weight/WeightApplication.java b/src/main/java/com/binary/weight/WeightApplication.java index 380d9bb..2b09375 100644 --- a/src/main/java/com/binary/weight/WeightApplication.java +++ b/src/main/java/com/binary/weight/WeightApplication.java @@ -4,7 +4,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.scheduling.annotation.EnableScheduling; -//@EnableScheduling +@EnableScheduling @SpringBootApplication public class WeightApplication { diff --git a/src/main/java/com/binary/weight/controller/SSEController.java b/src/main/java/com/binary/weight/controller/SSEController.java index d3db80d..ce8567a 100644 --- a/src/main/java/com/binary/weight/controller/SSEController.java +++ b/src/main/java/com/binary/weight/controller/SSEController.java @@ -1,13 +1,14 @@ package com.binary.weight.controller; import com.binary.weight.service.SSEService; -import jakarta.annotation.Resource; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; +import javax.annotation.Resource; + @RestController @CrossOrigin public class SSEController { diff --git a/src/main/java/com/binary/weight/controller/WeightController.java b/src/main/java/com/binary/weight/controller/WeightController.java index 03ccddd..a29e3a6 100644 --- a/src/main/java/com/binary/weight/controller/WeightController.java +++ b/src/main/java/com/binary/weight/controller/WeightController.java @@ -1,12 +1,12 @@ package com.binary.weight.controller; import com.binary.weight.service.WeightService; -import jakarta.annotation.Resource; -import jakarta.servlet.http.HttpServletResponse; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; +import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; import java.io.IOException; diff --git a/src/main/java/com/binary/weight/service/SyncService.java b/src/main/java/com/binary/weight/service/SyncService.java index 8e8b80a..0242a6c 100644 --- a/src/main/java/com/binary/weight/service/SyncService.java +++ b/src/main/java/com/binary/weight/service/SyncService.java @@ -1,12 +1,12 @@ package com.binary.weight.service; -import jakarta.annotation.Resource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Service; +import javax.annotation.Resource; import javax.sql.DataSource; import java.util.List; import java.util.Map; diff --git a/src/main/java/com/binary/weight/service/WeightService.java b/src/main/java/com/binary/weight/service/WeightService.java index 8a83275..1385014 100644 --- a/src/main/java/com/binary/weight/service/WeightService.java +++ b/src/main/java/com/binary/weight/service/WeightService.java @@ -1,10 +1,10 @@ package com.binary.weight.service; import com.fasterxml.jackson.databind.ObjectMapper; -import jakarta.annotation.Resource; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Service; +import javax.annotation.Resource; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; diff --git a/src/main/java/com/binary/weight/timer/WeightDataTimer.java b/src/main/java/com/binary/weight/timer/WeightDataTimer.java index 61d9c81..7f6e68c 100644 --- a/src/main/java/com/binary/weight/timer/WeightDataTimer.java +++ b/src/main/java/com/binary/weight/timer/WeightDataTimer.java @@ -1,10 +1,10 @@ package com.binary.weight.timer; import com.binary.weight.service.SyncService; -import jakarta.annotation.Resource; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; +import javax.annotation.Resource; import java.io.IOException; @Component diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index f65b022..8d66c5a 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,15 +1,15 @@ spring: - datasource: - mysql: - jdbc-url: jdbc:mysql://192.168.1.152:3307/eagle-cloud-plus?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8 - username: root - password: Cnqisoft@2020 - driver-class-name: com.mysql.cj.jdbc.Driver - sqlserver: - jdbc-url: jdbc:sqlserver://221.179.56.134:51433;DatabaseName=WEIGHT55;encrypt=false;trustServerCertificate=true; - username: sa - password: ABCabc12345 - driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver +# datasource: +# mysql: +# jdbc-url: jdbc:mysql://192.168.1.152:3307/eagle-cloud-plus?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8 +# username: root +# password: Cnqisoft@2020 +# driver-class-name: com.mysql.cj.jdbc.Driver +# sqlserver: +# jdbc-url: jdbc:sqlserver://221.179.56.134:51433;DatabaseName=WEIGHT55;encrypt=false;trustServerCertificate=true; +# username: sa +# password: ABCabc12345 +# driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver profiles: active: prod diff --git a/src/main/resources/bootstrap.yml b/src/main/resources/bootstrap.yml index da93efb..64ed726 100644 --- a/src/main/resources/bootstrap.yml +++ b/src/main/resources/bootstrap.yml @@ -1,6 +1,6 @@ spring: application: - name: dispatch-server + name: weighbridge-server cloud: nacos: @@ -9,4 +9,4 @@ spring: file-extension: yaml discovery: ip: 192.168.1.152 - port: 8006 + port: 8005 From 9413a78cc1b2692e3369fcffda08c9e2addf6ab2 Mon Sep 17 00:00:00 2001 From: vastlan Date: Thu, 22 Aug 2024 10:50:15 +0800 Subject: [PATCH 2/2] =?UTF-8?q?chore:=20=E5=B0=86=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=99=A8=E6=8E=A5=E5=85=A5=E6=82=9F=E7=A9=BA=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E7=9A=84nacos=E6=9C=8D=E5=8A=A1=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 7 ++++ .../weight/controller/OrderController.java | 28 ++++++++++++++ .../binary/weight/service/OrderService.java | 38 ++++++++++++++++--- 3 files changed, 68 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 56399c3..318b835 100644 --- a/pom.xml +++ b/pom.xml @@ -101,6 +101,13 @@ spring-boot-starter-test test + + + org.antlr + antlr4-runtime + 4.9.2 + + diff --git a/src/main/java/com/binary/weight/controller/OrderController.java b/src/main/java/com/binary/weight/controller/OrderController.java index 01323f9..edd7df4 100644 --- a/src/main/java/com/binary/weight/controller/OrderController.java +++ b/src/main/java/com/binary/weight/controller/OrderController.java @@ -19,6 +19,29 @@ public class OrderController { @PostMapping public Response addOrder(@RequestBody Order order) { int result = orderService.addOrder(order); + + if (result > 0) { + return new Response("ok", true, null); + } else { + return new Response("error", false, null); + } + } + + @PutMapping + public Response updateOrder(@RequestBody Order order) { + int result = orderService.updateOrder(order); + + if (result > 0) { + return new Response("ok", true, null); + } else { + return new Response("error", false, null); + } + } + + @DeleteMapping("/no/{orderNo}") + public Response deleteOrderByNo(@PathVariable String orderNo) { + int result = orderService.deleteByNo(orderNo); + if (result > 0) { return new Response("ok", true, null); } else { @@ -37,7 +60,12 @@ public class OrderController { @GetMapping("/{id}") public Response getOrderById(@PathVariable int id) { Order order = orderService.getOrderById(id); + return Response.success(order); + } + @GetMapping("/no/{orderNo}") + public Response getOrderByNo(@PathVariable String orderNo) { + Order order = orderService.getOrderByNo(orderNo); return Response.success(order); } } diff --git a/src/main/java/com/binary/weight/service/OrderService.java b/src/main/java/com/binary/weight/service/OrderService.java index fef2239..3585ef7 100644 --- a/src/main/java/com/binary/weight/service/OrderService.java +++ b/src/main/java/com/binary/weight/service/OrderService.java @@ -3,6 +3,7 @@ package com.binary.weight.service; import com.binary.weight.entity.Order; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Service; @@ -20,17 +21,44 @@ public class OrderService { } public int addOrder(Order order) { - String sql = "INSERT INTO tbl_order (orderno, receiver, salesty, goods1, tonnage1, goods2, tonnage2, goods3, tonnage3, goods4, tonnage4, shipno, transportinfo, wharf, car_team1, cars1, car_team2, cars2, car_team3, cars3, car_team4, cars4, order_time, remark) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + String sql = "INSERT INTO tbl_order (orderno, receiver, salesty, goods1, tonnage1, goods2, tonnage2, goods3, tonnage3, goods4, tonnage4, shipno, transportinfo, wharf, car_team1, cars1, car_team2, cars2, car_team3, cars3, car_team4, cars4, order_time, remark) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; return jdbcTemplate.update(sql, order.getOrderNo(), order.getReceiver(), order.getSalesTy(), order.getGoods1(), order.getTonnage1(), order.getGoods2(), order.getTonnage2(), order.getGoods3(), order.getTonnage3(), order.getGoods4(), order.getTonnage4(), order.getShipNo(), order.getTransportInfo(), order.getWharf(), order.getCarTeam1(), order.getCars1(), order.getCarTeam2(), order.getCars2(), order.getCarTeam3(), order.getCars3(), order.getCarTeam4(), order.getCars4(), order.getOrderTime(), order.getRemark()); } + public int updateOrder(Order order) { + String sql = "UPDATE tbl_order set orderno = ?, receiver = ?, salesty = ?, goods1 = ?, tonnage1 = ?, goods2 = ?, tonnage2 = ?, goods3 = ?, tonnage3 = ?, goods4 = ?, tonnage4 = ?, shipno = ?, transportinfo = ?, wharf = ?, car_team1 = ?, cars1 = ?, car_team2 = ?, cars2 = ?, car_team3 = ?, cars3 = ?, car_team4 = ?, cars4 = ?, order_time = ?, remark = ? where id = ?"; + return jdbcTemplate.update(sql, order.getOrderNo(), order.getReceiver(), order.getSalesTy(), order.getGoods1(), order.getTonnage1(), order.getGoods2(), order.getTonnage2(), order.getGoods3(), order.getTonnage3(), order.getGoods4(), order.getTonnage4(), order.getShipNo(), order.getTransportInfo(), order.getWharf(), order.getCarTeam1(), order.getCars1(), order.getCarTeam2(), order.getCars2(), order.getCarTeam3(), order.getCars3(), order.getCarTeam4(), order.getCars4(), order.getOrderTime(), order.getRemark(), order.getId()); + } + + public int deleteByNo(String orderNo) { + String sql = "delete from tbl_order where orderno = ?"; + return jdbcTemplate.update(sql, orderNo); + } + public List getOrders() { - String sql = "SELECT * FROM tbl_order"; - return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Order.class)); + try { + String sql = "SELECT * FROM tbl_order"; + return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Order.class)); + } catch (EmptyResultDataAccessException e) { + return null; + } } public Order getOrderById(int id) { - String sql = "SELECT * FROM tbl_order WHERE id = ?"; - return jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(Order.class), id); + try { + String sql = "SELECT * FROM tbl_order WHERE id = ?"; + return jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(Order.class), id); + } catch (EmptyResultDataAccessException e) { + return null; + } + } + + public Order getOrderByNo(String orderNo) { + try { + String sql = "SELECT * FROM tbl_order WHERE orderno = ?"; + return jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(Order.class), orderNo); + } catch (EmptyResultDataAccessException e) { + return null; + } } }