From d3ca6336b3cee0896f1e6f98d39238f3f08e3714 Mon Sep 17 00:00:00 2001 From: Searises Hao Wang Date: Mon, 4 Aug 2025 13:57:08 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=8D=87=E7=BA=A7=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 24 +- .../com/example/webapi/WebApiApplication.java | 16 +- .../webapi/config/DataSourceConfig.java | 149 ++++++++ .../webapi/config/SimpleJpaConfig.java | 15 + .../example/webapi/config/SwaggerConfig.java | 56 +-- .../webapi/config/SwaggerTestConfig.java | 20 + .../controller/SupplyVarietyController.java | 48 +-- .../controller/TransferRecordController.java | 46 +-- .../TransportCompanyController.java | 46 +-- .../controller/TwiceWeighingController.java | 82 ++++ .../controller/VehicleInfoController.java | 46 +-- .../controller/WeighingRecordController.java | 46 +-- .../webapi/dto/TwiceWeighingQueryDTO.java | 248 ++++++++++++ .../example/webapi/entity/MaterialInfo.java | 3 +- .../com/example/webapi/entity/Supplier.java | 1 + .../example/webapi/entity/SupplyVariety.java | 3 +- .../example/webapi/entity/TransferRecord.java | 1 + .../webapi/entity/TransportCompany.java | 3 +- .../example/webapi/entity/TwiceWeighing.java | 144 +++++++ .../example/webapi/entity/VehicleInfo.java | 3 +- .../example/webapi/entity/WeighingRecord.java | 3 +- .../postgresql/TwiceWeighingPostgreSQL.java | 141 +++++++ .../repository/TwiceWeighingRepository.java | 73 ++++ .../pg/TwiceWeighingPostgreSQLRepository.java | 38 ++ .../webapi/service/DataSyncService.java | 352 ++++++++++++++++++ .../webapi/service/ScheduledSyncService.java | 60 +++ .../webapi/service/TwiceWeighingService.java | 259 +++++++++++++ .../com/example/webapi/util/DataSyncTest.java | 163 ++++++++ .../webapi/util/DatabaseConnectionTest.java | 52 +++ .../webapi/util/SQLServerVersionTest.java | 150 ++++++++ .../java/com/example/webapi/util/SSLTest.java | 86 +++++ src/main/resources/application.yml | 44 ++- 32 files changed, 2228 insertions(+), 193 deletions(-) create mode 100644 src/main/java/com/example/webapi/config/DataSourceConfig.java create mode 100644 src/main/java/com/example/webapi/config/SimpleJpaConfig.java create mode 100644 src/main/java/com/example/webapi/config/SwaggerTestConfig.java create mode 100644 src/main/java/com/example/webapi/controller/TwiceWeighingController.java create mode 100644 src/main/java/com/example/webapi/dto/TwiceWeighingQueryDTO.java create mode 100644 src/main/java/com/example/webapi/entity/TwiceWeighing.java create mode 100644 src/main/java/com/example/webapi/entity/postgresql/TwiceWeighingPostgreSQL.java create mode 100644 src/main/java/com/example/webapi/repository/TwiceWeighingRepository.java create mode 100644 src/main/java/com/example/webapi/repository/pg/TwiceWeighingPostgreSQLRepository.java create mode 100644 src/main/java/com/example/webapi/service/DataSyncService.java create mode 100644 src/main/java/com/example/webapi/service/ScheduledSyncService.java create mode 100644 src/main/java/com/example/webapi/service/TwiceWeighingService.java create mode 100644 src/main/java/com/example/webapi/util/DataSyncTest.java create mode 100644 src/main/java/com/example/webapi/util/DatabaseConnectionTest.java create mode 100644 src/main/java/com/example/webapi/util/SQLServerVersionTest.java create mode 100644 src/main/java/com/example/webapi/util/SSLTest.java diff --git a/pom.xml b/pom.xml index 055c1c2..00cde58 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,7 @@ 4.0.0 @@ -43,6 +43,15 @@ com.microsoft.sqlserver mssql-jdbc + 9.2.1.jre8 + runtime + + + + + org.postgresql + postgresql + 42.2.27 runtime @@ -65,11 +74,16 @@ spring-boot-starter-test test - + + + io.springfox + springfox-swagger2 + 2.9.2 + io.springfox - springfox-boot-starter - 3.0.0 + springfox-swagger-ui + 2.9.2 @@ -89,4 +103,4 @@ - \ No newline at end of file + diff --git a/src/main/java/com/example/webapi/WebApiApplication.java b/src/main/java/com/example/webapi/WebApiApplication.java index e9ba4b9..1147a9a 100644 --- a/src/main/java/com/example/webapi/WebApiApplication.java +++ b/src/main/java/com/example/webapi/WebApiApplication.java @@ -2,6 +2,11 @@ package com.example.webapi; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.scheduling.annotation.EnableScheduling; +import springfox.documentation.swagger2.annotations.EnableSwagger2; /** * SpringBoot WebAPI 应用程序主类 @@ -9,14 +14,21 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; * @author Your Name * @version 1.0.0 */ -@SpringBootApplication +@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class}) +@EnableScheduling +@EnableSwagger2 +@EnableJpaRepositories( + basePackages = {"com.example.webapi.repository.pg"}, + entityManagerFactoryRef = "postgresqlEntityManagerFactory", + transactionManagerRef = "postgresqlTransactionManager" +) public class WebApiApplication { public static void main(String[] args) { SpringApplication.run(WebApiApplication.class, args); System.out.println("================================="); System.out.println("WebAPI 应用程序启动成功!"); - System.out.println("访问地址: http://localhost:8080/api"); + System.out.println("访问地址: http://localhost:8806/fuquanapi"); System.out.println("================================="); } } \ No newline at end of file diff --git a/src/main/java/com/example/webapi/config/DataSourceConfig.java b/src/main/java/com/example/webapi/config/DataSourceConfig.java new file mode 100644 index 0000000..1c933f5 --- /dev/null +++ b/src/main/java/com/example/webapi/config/DataSourceConfig.java @@ -0,0 +1,149 @@ +package com.example.webapi.config; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.jdbc.DataSourceBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; +import org.springframework.transaction.PlatformTransactionManager; + +import javax.sql.DataSource; +import java.util.HashMap; +import java.util.Map; + +@Configuration +public class DataSourceConfig { + + @Value("${spring.datasource.sqlserver.url}") + private String sqlServerUrl; + + @Value("${spring.datasource.sqlserver.username}") + private String sqlServerUsername; + + @Value("${spring.datasource.sqlserver.password}") + private String sqlServerPassword; + + @Value("${spring.datasource.sqlserver.driver-class-name}") + private String sqlServerDriverClassName; + + @Value("${spring.datasource.postgresql.url}") + private String postgresqlUrl; + + @Value("${spring.datasource.postgresql.username}") + private String postgresqlUsername; + + @Value("${spring.datasource.postgresql.password}") + private String postgresqlPassword; + + @Value("${spring.datasource.postgresql.driver-class-name}") + private String postgresqlDriverClassName; + + @Primary + @Bean(name = "sqlServerDataSource") + public DataSource sqlServerDataSource() { + System.out.println("配置SQL Server数据源:"); + System.out.println("URL: " + sqlServerUrl); + System.out.println("Username: " + sqlServerUsername); + System.out.println("Driver: " + sqlServerDriverClassName); + + return DataSourceBuilder.create() + .url(sqlServerUrl) + .username(sqlServerUsername) + .password(sqlServerPassword) + .driverClassName(sqlServerDriverClassName) + .type(com.zaxxer.hikari.HikariDataSource.class) + .build(); + } + + @Bean(name = "postgresqlDataSource") + public DataSource postgresqlDataSource() { + System.out.println("配置PostgreSQL数据源:"); + System.out.println("URL: " + postgresqlUrl); + System.out.println("Username: " + postgresqlUsername); + System.out.println("Driver: " + postgresqlDriverClassName); + + return DataSourceBuilder.create() + .url(postgresqlUrl) + .username(postgresqlUsername) + .password(postgresqlPassword) + .driverClassName(postgresqlDriverClassName) + .type(com.zaxxer.hikari.HikariDataSource.class) + .build(); + } + + @Primary + @Bean(name = "sqlServerEntityManagerFactory") + public LocalContainerEntityManagerFactoryBean sqlServerEntityManagerFactory() { + System.out.println("创建SQL Server EntityManagerFactory..."); + + LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); + em.setDataSource(sqlServerDataSource()); + em.setPackagesToScan("com.example.webapi.entity"); + em.setPersistenceUnitName("sqlServerPersistenceUnit"); + + HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); + vendorAdapter.setDatabasePlatform("org.hibernate.dialect.SQLServer2008Dialect"); + vendorAdapter.setShowSql(true); + em.setJpaVendorAdapter(vendorAdapter); + + Map properties = new HashMap<>(); + properties.put("hibernate.hbm2ddl.auto", "none"); + properties.put("hibernate.show_sql", "true"); + properties.put("hibernate.format_sql", "true"); + properties.put("hibernate.physical_naming_strategy", "org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl"); + em.setJpaPropertyMap(properties); + + System.out.println("SQL Server EntityManagerFactory创建完成"); + return em; + } + + @Bean(name = "postgresqlEntityManagerFactory") + public LocalContainerEntityManagerFactoryBean postgresqlEntityManagerFactory() { + System.out.println("创建PostgreSQL EntityManagerFactory..."); + + LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); + em.setDataSource(postgresqlDataSource()); + em.setPackagesToScan("com.example.webapi.entity.postgresql"); + em.setPersistenceUnitName("postgresqlPersistenceUnit"); + + HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); + vendorAdapter.setDatabasePlatform("org.hibernate.dialect.PostgreSQLDialect"); + vendorAdapter.setShowSql(true); + em.setJpaVendorAdapter(vendorAdapter); + + Map properties = new HashMap<>(); + properties.put("hibernate.hbm2ddl.auto", "none"); + properties.put("hibernate.show_sql", "true"); + properties.put("hibernate.format_sql", "true"); + properties.put("hibernate.physical_naming_strategy", "org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl"); + em.setJpaPropertyMap(properties); + +// System.out.println("PostgreSQL EntityManagerFactory创建完成"); +// System.out.println("PostgreSQL EntityManagerFactory数据源: " + em.getDataSource()); +// System.out.println("PostgreSQL EntityManagerFactory包扫描: " + em.getPackagesToScan()[0]); +// System.out.println("PostgreSQL EntityManagerFactory方言: " + vendorAdapter.getDatabasePlatform()); + return em; + } + + @Primary + @Bean(name = "sqlServerTransactionManager") + public PlatformTransactionManager sqlServerTransactionManager() { + System.out.println("创建SQL Server TransactionManager..."); + JpaTransactionManager transactionManager = new JpaTransactionManager(); + transactionManager.setEntityManagerFactory(sqlServerEntityManagerFactory().getObject()); + System.out.println("SQL Server TransactionManager创建完成"); + return transactionManager; + } + + @Bean(name = "postgresqlTransactionManager") + public PlatformTransactionManager postgresqlTransactionManager() { + System.out.println("创建PostgreSQL TransactionManager..."); + JpaTransactionManager transactionManager = new JpaTransactionManager(); + transactionManager.setEntityManagerFactory(postgresqlEntityManagerFactory().getObject()); + System.out.println("PostgreSQL TransactionManager创建完成"); + return transactionManager; + } +} diff --git a/src/main/java/com/example/webapi/config/SimpleJpaConfig.java b/src/main/java/com/example/webapi/config/SimpleJpaConfig.java new file mode 100644 index 0000000..785e054 --- /dev/null +++ b/src/main/java/com/example/webapi/config/SimpleJpaConfig.java @@ -0,0 +1,15 @@ +package com.example.webapi.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +@Configuration +@EnableJpaRepositories( + basePackages = {"com.example.webapi.repository"}, + entityManagerFactoryRef = "sqlServerEntityManagerFactory", + transactionManagerRef = "sqlServerTransactionManager" +) +@EnableTransactionManagement +public class SimpleJpaConfig { +} \ No newline at end of file diff --git a/src/main/java/com/example/webapi/config/SwaggerConfig.java b/src/main/java/com/example/webapi/config/SwaggerConfig.java index 56fdd62..1dca415 100644 --- a/src/main/java/com/example/webapi/config/SwaggerConfig.java +++ b/src/main/java/com/example/webapi/config/SwaggerConfig.java @@ -3,20 +3,22 @@ package com.example.webapi.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.ParameterBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; -import springfox.documentation.builders.RequestParameterBuilder; -import springfox.documentation.schema.ScalarType; import springfox.documentation.service.ApiInfo; import springfox.documentation.service.Contact; -import springfox.documentation.service.ParameterType; -import springfox.documentation.service.RequestParameter; +import springfox.documentation.service.Parameter; +import springfox.documentation.service.ResponseMessage; +import springfox.documentation.schema.ModelRef; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import java.util.ArrayList; import java.util.List; +import static com.google.common.collect.Lists.newArrayList; + /** * Swagger配置类 * 配置Swagger3文档,支持详细的请求参数和响应参数说明 @@ -25,19 +27,23 @@ import java.util.List; public class SwaggerConfig { @Bean public Docket api() { - return new Docket(DocumentationType.OAS_30) + return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("com.example.webapi.controller")) .paths(PathSelectors.any()) .build() - .globalRequestParameters(getGlobalRequestParameters()) + .globalOperationParameters(getGlobalParameters()) // 以下设置对展示参数说明和返回值说明很重要 .useDefaultResponseMessages(false) // 不使用默认的响应消息 .forCodeGeneration(true) // 为代码生成优化 - .pathMapping("/"); // 设置路径映射 + .pathMapping("/") // 设置路径映射 + .tags(new springfox.documentation.service.Tag("数据同步接口", "数据同步相关接口")) + .tags(new springfox.documentation.service.Tag("供应商管理", "供应商相关接口")) + .tags(new springfox.documentation.service.Tag("车辆管理", "车辆信息相关接口")) + .tags(new springfox.documentation.service.Tag("称重记录", "称重记录相关接口")); } - + /** * API信息配置 */ @@ -49,45 +55,45 @@ public class SwaggerConfig { .contact(new Contact("开发团队", "http://www.example.com", "dev@example.com")) .build(); } - + /** * 获取全局请求参数 * 注意:在Swagger UI中这些参数设置为非必需,以便能够正常访问Swagger界面 * 实际API调用时,这些参数仍然需要通过拦截器进行验证 */ - private List getGlobalRequestParameters() { - List parameters = new ArrayList<>(); - + private List getGlobalParameters() { + List parameters = new ArrayList<>(); + // AK (Access Key) - 在Swagger中设为非必需,便于测试 - RequestParameter akParam = new RequestParameterBuilder() + Parameter akParam = new ParameterBuilder() .name("ak") .description("访问密钥 (Access Key) - 必填") - .in(ParameterType.HEADER.toString()) + .modelRef(new ModelRef("string")) + .parameterType("header") .required(false) // 改为false,让Swagger UI可以正常访问 - .query(param -> param.model(model -> model.scalarModel(ScalarType.STRING))) .build(); parameters.add(akParam); - + // Timestamp - 在Swagger中设为非必需,便于测试 - RequestParameter timestampParam = new RequestParameterBuilder() + Parameter timestampParam = new ParameterBuilder() .name("timestamp") .description("时间戳 (毫秒) - 必填") - .in(ParameterType.HEADER.toString()) + .modelRef(new ModelRef("string")) + .parameterType("header") .required(false) // 改为false,让Swagger UI可以正常访问 - .query(param -> param.model(model -> model.scalarModel(ScalarType.STRING))) .build(); parameters.add(timestampParam); - + // Signature - 在Swagger中设为非必需,便于测试 - RequestParameter signatureParam = new RequestParameterBuilder() + Parameter signatureParam = new ParameterBuilder() .name("signature") .description("签名 (MD5(ak + sk + timestamp)) - 必填") - .in(ParameterType.HEADER.toString()) + .modelRef(new ModelRef("string")) + .parameterType("header") .required(false) // 改为false,让Swagger UI可以正常访问 - .query(param -> param.model(model -> model.scalarModel(ScalarType.STRING))) .build(); parameters.add(signatureParam); - + return parameters; } -} \ No newline at end of file +} diff --git a/src/main/java/com/example/webapi/config/SwaggerTestConfig.java b/src/main/java/com/example/webapi/config/SwaggerTestConfig.java new file mode 100644 index 0000000..df4ab20 --- /dev/null +++ b/src/main/java/com/example/webapi/config/SwaggerTestConfig.java @@ -0,0 +1,20 @@ +package com.example.webapi.config; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; + +@Component +public class SwaggerTestConfig implements CommandLineRunner { + + private static final Logger logger = LoggerFactory.getLogger(SwaggerTestConfig.class); + + @Override + public void run(String... args) throws Exception { + logger.info("=== Swagger配置测试 ==="); + logger.info("Swagger UI地址: http://localhost:8806/fuquanapi/swagger-ui.html"); + logger.info("API文档地址: http://localhost:8806/fuquanapi/v2/api-docs"); + logger.info("Swagger配置测试完成"); + } +} \ No newline at end of file diff --git a/src/main/java/com/example/webapi/controller/SupplyVarietyController.java b/src/main/java/com/example/webapi/controller/SupplyVarietyController.java index 12286a0..d2dac36 100644 --- a/src/main/java/com/example/webapi/controller/SupplyVarietyController.java +++ b/src/main/java/com/example/webapi/controller/SupplyVarietyController.java @@ -7,10 +7,7 @@ import com.example.webapi.dto.ApiResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponses; -import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.annotations.ApiResponses; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.web.bind.annotation.*; @@ -18,7 +15,6 @@ import org.springframework.web.bind.annotation.*; import java.util.Optional; @Api(tags = "供应标识品种信息管理") -@Tag(name = "供应标识品种信息管理", description = "提供供应标识品种信息的增删改查接口") @RestController @RequestMapping("/supply-variety") public class SupplyVarietyController { @@ -28,10 +24,8 @@ public class SupplyVarietyController { @ApiOperation(value = "条件查询供应标识品种信息(分页)", notes = "根据提供的查询条件分页查询供应标识品种信息") @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "查询成功", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = com.example.webapi.dto.ApiResponse.class))), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "服务器内部错误") + @io.swagger.annotations.ApiResponse(code = 200, message = "查询成功"), + @io.swagger.annotations.ApiResponse(code = 500, message = "服务器内部错误") }) @PostMapping("/page/conditions") public ApiResponse> pageByConditions( @@ -42,11 +36,9 @@ public class SupplyVarietyController { @ApiOperation(value = "根据ID查询供应标识品种信息", notes = "根据ID获取单条供应标识品种信息详情") @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "查询成功", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = com.example.webapi.dto.ApiResponse.class))), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "404", description = "记录不存在"), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "服务器内部错误") + @io.swagger.annotations.ApiResponse(code = 200, message = "查询成功"), + @io.swagger.annotations.ApiResponse(code = 404, message = "记录不存在"), + @io.swagger.annotations.ApiResponse(code = 500, message = "服务器内部错误") }) @GetMapping("/{id}") public ApiResponse getById( @@ -58,11 +50,9 @@ public class SupplyVarietyController { @ApiOperation(value = "新增供应标识品种信息", notes = "创建新的供应标识品种信息") @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "创建成功", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = com.example.webapi.dto.ApiResponse.class))), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "请求参数错误"), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "服务器内部错误") + @io.swagger.annotations.ApiResponse(code = 200, message = "创建成功"), + @io.swagger.annotations.ApiResponse(code = 400, message = "请求参数错误"), + @io.swagger.annotations.ApiResponse(code = 500, message = "服务器内部错误") }) @PostMapping public ApiResponse create( @@ -73,17 +63,15 @@ public class SupplyVarietyController { @ApiOperation(value = "更新供应标识品种信息", notes = "根据ID更新供应标识品种信息") @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "更新成功", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = com.example.webapi.dto.ApiResponse.class))), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "请求参数错误"), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "404", description = "记录不存在"), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "服务器内部错误") + @io.swagger.annotations.ApiResponse(code = 200, message = "更新成功"), + @io.swagger.annotations.ApiResponse(code = 400, message = "请求参数错误"), + @io.swagger.annotations.ApiResponse(code = 404, message = "记录不存在"), + @io.swagger.annotations.ApiResponse(code = 500, message = "服务器内部错误") }) @PutMapping("/{id}") public ApiResponse update( @ApiParam(value = "供应标识品种ID", required = true, example = "1") - @PathVariable Integer id, + @PathVariable Integer id, @ApiParam(value = "更新后的供应标识品种实体", required = true) @RequestBody SupplyVariety entity) { entity.setId(id); @@ -92,11 +80,9 @@ public class SupplyVarietyController { @ApiOperation(value = "删除供应标识品种信息", notes = "根据ID删除供应标识品种信息") @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "删除成功", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = com.example.webapi.dto.ApiResponse.class))), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "404", description = "记录不存在"), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "服务器内部错误") + @io.swagger.annotations.ApiResponse(code = 200, message = "删除成功"), + @io.swagger.annotations.ApiResponse(code = 404, message = "记录不存在"), + @io.swagger.annotations.ApiResponse(code = 500, message = "服务器内部错误") }) @DeleteMapping("/{id}") public ApiResponse delete( diff --git a/src/main/java/com/example/webapi/controller/TransferRecordController.java b/src/main/java/com/example/webapi/controller/TransferRecordController.java index 2f99206..43dd9dd 100644 --- a/src/main/java/com/example/webapi/controller/TransferRecordController.java +++ b/src/main/java/com/example/webapi/controller/TransferRecordController.java @@ -7,10 +7,7 @@ import com.example.webapi.dto.ApiResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponses; -import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.annotations.ApiResponses; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.web.bind.annotation.*; @@ -18,7 +15,6 @@ import org.springframework.web.bind.annotation.*; import java.util.Optional; @Api(tags = "转运记录管理") -@Tag(name = "转运记录管理", description = "提供转运记录的增删改查接口") @RestController @RequestMapping("/transfer-record") public class TransferRecordController { @@ -28,10 +24,8 @@ public class TransferRecordController { @ApiOperation(value = "条件查询转运记录(分页)", notes = "根据提供的查询条件分页查询转运记录") @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "查询成功", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = com.example.webapi.dto.ApiResponse.class))), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "服务器内部错误") + @io.swagger.annotations.ApiResponse(code = 200, message = "查询成功"), + @io.swagger.annotations.ApiResponse(code = 500, message = "服务器内部错误") }) @PostMapping("/page/conditions") public ApiResponse> pageByConditions( @@ -43,11 +37,9 @@ public class TransferRecordController { @ApiOperation(value = "根据ID查询转运记录", notes = "根据ID获取单条转运记录详情") @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "查询成功", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = com.example.webapi.dto.ApiResponse.class))), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "404", description = "记录不存在"), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "服务器内部错误") + @io.swagger.annotations.ApiResponse(code = 200, message = "查询成功"), + @io.swagger.annotations.ApiResponse(code = 404, message = "记录不存在"), + @io.swagger.annotations.ApiResponse(code = 500, message = "服务器内部错误") }) @GetMapping("/{id}") public ApiResponse getById( @@ -59,11 +51,9 @@ public class TransferRecordController { @ApiOperation(value = "新增转运记录", notes = "创建新的转运记录") @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "创建成功", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = com.example.webapi.dto.ApiResponse.class))), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "请求参数错误"), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "服务器内部错误") + @io.swagger.annotations.ApiResponse(code = 200, message = "创建成功"), + @io.swagger.annotations.ApiResponse(code = 400, message = "请求参数错误"), + @io.swagger.annotations.ApiResponse(code = 500, message = "服务器内部错误") }) @PostMapping public ApiResponse create( @@ -74,12 +64,10 @@ public class TransferRecordController { @ApiOperation(value = "更新转运记录", notes = "根据ID更新转运记录信息") @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "更新成功", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = com.example.webapi.dto.ApiResponse.class))), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "请求参数错误"), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "404", description = "记录不存在"), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "服务器内部错误") + @io.swagger.annotations.ApiResponse(code = 200, message = "更新成功"), + @io.swagger.annotations.ApiResponse(code = 400, message = "请求参数错误"), + @io.swagger.annotations.ApiResponse(code = 404, message = "记录不存在"), + @io.swagger.annotations.ApiResponse(code = 500, message = "服务器内部错误") }) @PutMapping("/{id}") public ApiResponse update( @@ -93,11 +81,9 @@ public class TransferRecordController { @ApiOperation(value = "删除转运记录", notes = "根据ID删除转运记录") @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "删除成功", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = com.example.webapi.dto.ApiResponse.class))), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "404", description = "记录不存在"), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "服务器内部错误") + @io.swagger.annotations.ApiResponse(code = 200, message = "删除成功"), + @io.swagger.annotations.ApiResponse(code = 404, message = "记录不存在"), + @io.swagger.annotations.ApiResponse(code = 500, message = "服务器内部错误") }) @DeleteMapping("/{id}") public ApiResponse delete( diff --git a/src/main/java/com/example/webapi/controller/TransportCompanyController.java b/src/main/java/com/example/webapi/controller/TransportCompanyController.java index 0f676cb..5554f56 100644 --- a/src/main/java/com/example/webapi/controller/TransportCompanyController.java +++ b/src/main/java/com/example/webapi/controller/TransportCompanyController.java @@ -7,10 +7,7 @@ import com.example.webapi.dto.ApiResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponses; -import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.annotations.ApiResponses; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.web.bind.annotation.*; @@ -18,7 +15,6 @@ import org.springframework.web.bind.annotation.*; import java.util.Optional; @Api(tags = "运输公司管理") -@Tag(name = "运输公司管理", description = "提供运输公司的增删改查接口") @RestController @RequestMapping("/transport-company") public class TransportCompanyController { @@ -28,10 +24,8 @@ public class TransportCompanyController { @ApiOperation(value = "条件查询运输公司(分页)", notes = "根据提供的查询条件分页查询运输公司") @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "查询成功", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = com.example.webapi.dto.ApiResponse.class))), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "服务器内部错误") + @io.swagger.annotations.ApiResponse(code = 200, message = "查询成功"), + @io.swagger.annotations.ApiResponse(code = 500, message = "服务器内部错误") }) @PostMapping("/page/conditions") public ApiResponse> pageByConditions( @@ -42,11 +36,9 @@ public class TransportCompanyController { @ApiOperation(value = "根据ID查询运输公司", notes = "根据ID获取单条运输公司详情") @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "查询成功", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = com.example.webapi.dto.ApiResponse.class))), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "404", description = "记录不存在"), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "服务器内部错误") + @io.swagger.annotations.ApiResponse(code = 200, message = "查询成功"), + @io.swagger.annotations.ApiResponse(code = 404, message = "记录不存在"), + @io.swagger.annotations.ApiResponse(code = 500, message = "服务器内部错误") }) @GetMapping("/{id}") public ApiResponse getById( @@ -58,11 +50,9 @@ public class TransportCompanyController { @ApiOperation(value = "新增运输公司", notes = "创建新的运输公司") @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "创建成功", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = com.example.webapi.dto.ApiResponse.class))), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "请求参数错误"), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "服务器内部错误") + @io.swagger.annotations.ApiResponse(code = 200, message = "创建成功"), + @io.swagger.annotations.ApiResponse(code = 400, message = "请求参数错误"), + @io.swagger.annotations.ApiResponse(code = 500, message = "服务器内部错误") }) @PostMapping public ApiResponse create( @@ -73,12 +63,10 @@ public class TransportCompanyController { @ApiOperation(value = "更新运输公司", notes = "根据ID更新运输公司信息") @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "更新成功", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = com.example.webapi.dto.ApiResponse.class))), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "请求参数错误"), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "404", description = "记录不存在"), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "服务器内部错误") + @io.swagger.annotations.ApiResponse(code = 200, message = "更新成功"), + @io.swagger.annotations.ApiResponse(code = 400, message = "请求参数错误"), + @io.swagger.annotations.ApiResponse(code = 404, message = "记录不存在"), + @io.swagger.annotations.ApiResponse(code = 500, message = "服务器内部错误") }) @PutMapping("/{id}") public ApiResponse update( @@ -92,11 +80,9 @@ public class TransportCompanyController { @ApiOperation(value = "删除运输公司", notes = "根据ID删除运输公司") @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "删除成功", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = com.example.webapi.dto.ApiResponse.class))), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "404", description = "记录不存在"), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "服务器内部错误") + @io.swagger.annotations.ApiResponse(code = 200, message = "删除成功"), + @io.swagger.annotations.ApiResponse(code = 404, message = "记录不存在"), + @io.swagger.annotations.ApiResponse(code = 500, message = "服务器内部错误") }) @DeleteMapping("/{id}") public ApiResponse delete( diff --git a/src/main/java/com/example/webapi/controller/TwiceWeighingController.java b/src/main/java/com/example/webapi/controller/TwiceWeighingController.java new file mode 100644 index 0000000..f1aceb2 --- /dev/null +++ b/src/main/java/com/example/webapi/controller/TwiceWeighingController.java @@ -0,0 +1,82 @@ +package com.example.webapi.controller; + +import com.example.webapi.dto.TwiceWeighingQueryDTO; +import com.example.webapi.entity.TwiceWeighing; +import com.example.webapi.service.TwiceWeighingService; +import com.example.webapi.dto.ApiResponse; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.web.bind.annotation.*; + +import java.util.Optional; + +@Api(tags = "二次称重记录管理") +@RestController +@RequestMapping("/twice-weighing") +public class TwiceWeighingController { + + @Autowired + private TwiceWeighingService service; + + @ApiOperation(value = "条件查询二次称重记录(分页)", notes = "根据提供的查询条件分页查询二次称重记录") + @PostMapping("/page/conditions") + public ApiResponse> pageByConditions(@RequestBody TwiceWeighingQueryDTO queryDTO) { + return ApiResponse.success(service.findByConditions(queryDTO)); + } + + @ApiOperation(value = "根据ID查询二次称重记录", notes = "根据ID获取单条二次称重记录详情") + @GetMapping("/{id}") + public ApiResponse getById(@PathVariable String id) { + Optional result = service.findById(id); + return result.map(ApiResponse::success).orElseGet(() -> ApiResponse.error("未找到该二次称重记录")); + } + + @ApiOperation(value = "新增二次称重记录", notes = "创建新的二次称重记录") + @PostMapping + public ApiResponse create(@RequestBody TwiceWeighing entity) { + return ApiResponse.success(service.save(entity)); + } + + @ApiOperation(value = "更新二次称重记录", notes = "根据ID更新二次称重记录信息") + @PutMapping("/{id}") + public ApiResponse update(@PathVariable String id, @RequestBody TwiceWeighing entity) { + entity.setId(id); + return ApiResponse.success(service.save(entity)); + } + + @ApiOperation(value = "删除二次称重记录", notes = "根据ID删除二次称重记录") + @DeleteMapping("/{id}") + public ApiResponse delete(@PathVariable String id) { + service.deleteById(id); + return ApiResponse.success(); + } + + @ApiOperation(value = "根据车号查询二次称重记录", notes = "根据车号获取二次称重记录") + @GetMapping("/vehicle/{vehicleId}") + public ApiResponse getByVehicleId(@PathVariable String vehicleId) { + TwiceWeighing result = service.findByVehicleId(vehicleId); + return result != null ? ApiResponse.success(result) : ApiResponse.error("未找到该车号的记录"); + } + + @ApiOperation(value = "根据打印编号查询二次称重记录", notes = "根据打印编号获取二次称重记录") + @GetMapping("/print/{printId}") + public ApiResponse getByPrintId(@PathVariable String printId) { + TwiceWeighing result = service.findByPrintId(printId); + return result != null ? ApiResponse.success(result) : ApiResponse.error("未找到该打印编号的记录"); + } + + @ApiOperation(value = "获取上传记录数量", notes = "根据上传标识获取记录数量") + @GetMapping("/count/upload/{uploadFlag}") + public ApiResponse countByUploadFlag(@PathVariable Boolean uploadFlag) { + return ApiResponse.success(service.countByUploadFlag(uploadFlag)); + } + + @ApiOperation(value = "获取作废记录数量", notes = "根据作废标识获取记录数量") + @GetMapping("/count/useless/{uselessFlag}") + public ApiResponse countByUselessFlag(@PathVariable Boolean uselessFlag) { + return ApiResponse.success(service.countByUselessFlag(uselessFlag)); + } +} \ No newline at end of file diff --git a/src/main/java/com/example/webapi/controller/VehicleInfoController.java b/src/main/java/com/example/webapi/controller/VehicleInfoController.java index 9c40e80..b776f81 100644 --- a/src/main/java/com/example/webapi/controller/VehicleInfoController.java +++ b/src/main/java/com/example/webapi/controller/VehicleInfoController.java @@ -7,10 +7,7 @@ import com.example.webapi.dto.ApiResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponses; -import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.annotations.ApiResponses; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.web.bind.annotation.*; @@ -18,7 +15,6 @@ import org.springframework.web.bind.annotation.*; import java.util.Optional; @Api(tags = "车辆信息管理") -@Tag(name = "车辆信息管理", description = "提供车辆信息的增删改查接口") @RestController @RequestMapping("/vehicle-info") public class VehicleInfoController { @@ -28,10 +24,8 @@ public class VehicleInfoController { @ApiOperation(value = "条件查询车辆信息(分页)", notes = "根据提供的查询条件分页查询车辆信息") @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "查询成功", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = com.example.webapi.dto.ApiResponse.class))), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "服务器内部错误") + @io.swagger.annotations.ApiResponse(code = 200, message = "查询成功"), + @io.swagger.annotations.ApiResponse(code = 500, message = "服务器内部错误") }) @PostMapping("/page/conditions") public ApiResponse> pageByConditions( @@ -42,11 +36,9 @@ public class VehicleInfoController { @ApiOperation(value = "根据ID查询车辆信息", notes = "根据ID获取单条车辆信息详情") @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "查询成功", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = com.example.webapi.dto.ApiResponse.class))), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "404", description = "记录不存在"), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "服务器内部错误") + @io.swagger.annotations.ApiResponse(code = 200, message = "查询成功"), + @io.swagger.annotations.ApiResponse(code = 404, message = "记录不存在"), + @io.swagger.annotations.ApiResponse(code = 500, message = "服务器内部错误") }) @GetMapping("/{id}") public ApiResponse getById( @@ -58,11 +50,9 @@ public class VehicleInfoController { @ApiOperation(value = "新增车辆信息", notes = "创建新的车辆信息") @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "创建成功", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = com.example.webapi.dto.ApiResponse.class))), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "请求参数错误"), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "服务器内部错误") + @io.swagger.annotations.ApiResponse(code = 200, message = "创建成功"), + @io.swagger.annotations.ApiResponse(code = 400, message = "请求参数错误"), + @io.swagger.annotations.ApiResponse(code = 500, message = "服务器内部错误") }) @PostMapping public ApiResponse create( @@ -73,12 +63,10 @@ public class VehicleInfoController { @ApiOperation(value = "更新车辆信息", notes = "根据ID更新车辆信息") @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "更新成功", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = com.example.webapi.dto.ApiResponse.class))), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "请求参数错误"), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "404", description = "记录不存在"), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "服务器内部错误") + @io.swagger.annotations.ApiResponse(code = 200, message = "更新成功"), + @io.swagger.annotations.ApiResponse(code = 400, message = "请求参数错误"), + @io.swagger.annotations.ApiResponse(code = 404, message = "记录不存在"), + @io.swagger.annotations.ApiResponse(code = 500, message = "服务器内部错误") }) @PutMapping("/{id}") public ApiResponse update( @@ -92,11 +80,9 @@ public class VehicleInfoController { @ApiOperation(value = "删除车辆信息", notes = "根据ID删除车辆信息") @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "删除成功", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = com.example.webapi.dto.ApiResponse.class))), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "404", description = "记录不存在"), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "服务器内部错误") + @io.swagger.annotations.ApiResponse(code = 200, message = "删除成功"), + @io.swagger.annotations.ApiResponse(code = 404, message = "记录不存在"), + @io.swagger.annotations.ApiResponse(code = 500, message = "服务器内部错误") }) @DeleteMapping("/{id}") public ApiResponse delete( diff --git a/src/main/java/com/example/webapi/controller/WeighingRecordController.java b/src/main/java/com/example/webapi/controller/WeighingRecordController.java index d525195..8256dee 100644 --- a/src/main/java/com/example/webapi/controller/WeighingRecordController.java +++ b/src/main/java/com/example/webapi/controller/WeighingRecordController.java @@ -9,10 +9,7 @@ import com.example.webapi.dto.ApiResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponses; -import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.annotations.ApiResponses; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.web.bind.annotation.*; @@ -20,7 +17,6 @@ import org.springframework.web.bind.annotation.*; import java.util.Optional; @Api(tags = "称重记录管理") -@Tag(name = "称重记录管理", description = "提供称重记录的增删改查接口") @RestController @RequestMapping("/weighing-record") public class WeighingRecordController { @@ -33,10 +29,8 @@ public class WeighingRecordController { @ApiOperation(value = "条件查询称重记录(分页)", notes = "根据提供的查询条件分页查询称重记录") @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "查询成功", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = com.example.webapi.dto.ApiResponse.class))), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "服务器内部错误") + @io.swagger.annotations.ApiResponse(code = 200, message = "查询成功"), + @io.swagger.annotations.ApiResponse(code = 500, message = "服务器内部错误") }) @PostMapping("/page/conditions") public ApiResponse> pageByConditions( @@ -47,11 +41,9 @@ public class WeighingRecordController { @ApiOperation(value = "根据ID查询称重记录", notes = "根据ID获取单条称重记录详情") @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "查询成功", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = com.example.webapi.dto.ApiResponse.class))), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "404", description = "记录不存在"), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "服务器内部错误") + @io.swagger.annotations.ApiResponse(code = 200, message = "查询成功"), + @io.swagger.annotations.ApiResponse(code = 404, message = "记录不存在"), + @io.swagger.annotations.ApiResponse(code = 500, message = "服务器内部错误") }) @GetMapping("/{id}") public ApiResponse getById( @@ -64,11 +56,9 @@ public class WeighingRecordController { @ApiOperation(value = "新增称重记录", notes = "创建新的称重记录") @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "创建成功", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = com.example.webapi.dto.ApiResponse.class))), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "请求参数错误"), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "服务器内部错误") + @io.swagger.annotations.ApiResponse(code = 200, message = "创建成功"), + @io.swagger.annotations.ApiResponse(code = 400, message = "请求参数错误"), + @io.swagger.annotations.ApiResponse(code = 500, message = "服务器内部错误") }) @PostMapping public ApiResponse create( @@ -90,12 +80,10 @@ public class WeighingRecordController { @ApiOperation(value = "更新称重记录", notes = "根据ID更新称重记录信息") @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "更新成功", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = com.example.webapi.dto.ApiResponse.class))), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "请求参数错误"), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "404", description = "记录不存在"), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "服务器内部错误") + @io.swagger.annotations.ApiResponse(code = 200, message = "更新成功"), + @io.swagger.annotations.ApiResponse(code = 400, message = "请求参数错误"), + @io.swagger.annotations.ApiResponse(code = 404, message = "记录不存在"), + @io.swagger.annotations.ApiResponse(code = 500, message = "服务器内部错误") }) @PutMapping("/{id}") public ApiResponse update( @@ -109,11 +97,9 @@ public class WeighingRecordController { @ApiOperation(value = "删除称重记录", notes = "根据ID删除称重记录") @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "删除成功", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = com.example.webapi.dto.ApiResponse.class))), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "404", description = "记录不存在"), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "服务器内部错误") + @io.swagger.annotations.ApiResponse(code = 200, message = "删除成功"), + @io.swagger.annotations.ApiResponse(code = 404, message = "记录不存在"), + @io.swagger.annotations.ApiResponse(code = 500, message = "服务器内部错误") }) @DeleteMapping("/{id}") public ApiResponse delete( diff --git a/src/main/java/com/example/webapi/dto/TwiceWeighingQueryDTO.java b/src/main/java/com/example/webapi/dto/TwiceWeighingQueryDTO.java new file mode 100644 index 0000000..ec1110e --- /dev/null +++ b/src/main/java/com/example/webapi/dto/TwiceWeighingQueryDTO.java @@ -0,0 +1,248 @@ +package com.example.webapi.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +/** + * 二次称重记录查询条件DTO + * + * @author Your Name + * @version 1.0.0 + */ +@ApiModel(description = "二次称重记录查询条件数据传输对象") +public class TwiceWeighingQueryDTO extends BasePageDTO { + + // 基础查询条件(支持模糊查询) + @ApiModelProperty(value = "车号", example = "京A12345") + private String vehicleId; + + @ApiModelProperty(value = "车型", example = "货车") + private String vehicleType; + + @ApiModelProperty(value = "货物", example = "煤炭") + private String goods; + + @ApiModelProperty(value = "收货单位", example = "福泉电厂") + private String receiveUnit; + + @ApiModelProperty(value = "发货单位", example = "福泉煤矿") + private String sendUnit; + + @ApiModelProperty(value = "发货站", example = "福泉站") + private String sendStation; + + @ApiModelProperty(value = "到站", example = "电厂站") + private String theStation; + + @ApiModelProperty(value = "炉号", example = "F001") + private String furnaceNumber; + + @ApiModelProperty(value = "铁号", example = "I001") + private String ironNumber; + + @ApiModelProperty(value = "方向", example = "进厂") + private String direction; + + @ApiModelProperty(value = "毛重操作员ID", example = "OP001") + private String grossOpId; + + @ApiModelProperty(value = "皮重操作员ID", example = "OP002") + private String tareOpId; + + @ApiModelProperty(value = "打印编号", example = "PRINT001") + private String printId; + + @ApiModelProperty(value = "备注", example = "正常称重") + private String demo; + + // 精确匹配查询 + @ApiModelProperty(value = "物资ID", example = "1") + private Integer materialsId; + + @ApiModelProperty(value = "供应商ID", example = "1") + private Integer supplierId; + + @ApiModelProperty(value = "上传标志", example = "false") + private Boolean uploadFlag; + + @ApiModelProperty(value = "作废标志", example = "false") + private Boolean uselessFlag; + + @ApiModelProperty(value = "皮重模式", example = "手动") + private String tareModel; + + @ApiModelProperty(value = "毛重衡器ID", example = "GS001") + private String grossScaleId; + + @ApiModelProperty(value = "皮重衡器ID", example = "TS001") + private String tareScaleId; + + // Getter and Setter methods + public String getVehicleId() { + return vehicleId; + } + + public void setVehicleId(String vehicleId) { + this.vehicleId = vehicleId; + } + + public String getVehicleType() { + return vehicleType; + } + + public void setVehicleType(String vehicleType) { + this.vehicleType = vehicleType; + } + + public String getGoods() { + return goods; + } + + public void setGoods(String goods) { + this.goods = goods; + } + + public String getReceiveUnit() { + return receiveUnit; + } + + public void setReceiveUnit(String receiveUnit) { + this.receiveUnit = receiveUnit; + } + + public String getSendUnit() { + return sendUnit; + } + + public void setSendUnit(String sendUnit) { + this.sendUnit = sendUnit; + } + + public String getSendStation() { + return sendStation; + } + + public void setSendStation(String sendStation) { + this.sendStation = sendStation; + } + + public String getTheStation() { + return theStation; + } + + public void setTheStation(String theStation) { + this.theStation = theStation; + } + + public String getFurnaceNumber() { + return furnaceNumber; + } + + public void setFurnaceNumber(String furnaceNumber) { + this.furnaceNumber = furnaceNumber; + } + + public String getIronNumber() { + return ironNumber; + } + + public void setIronNumber(String ironNumber) { + this.ironNumber = ironNumber; + } + + public String getDirection() { + return direction; + } + + public void setDirection(String direction) { + this.direction = direction; + } + + public String getGrossOpId() { + return grossOpId; + } + + public void setGrossOpId(String grossOpId) { + this.grossOpId = grossOpId; + } + + public String getTareOpId() { + return tareOpId; + } + + public void setTareOpId(String tareOpId) { + this.tareOpId = tareOpId; + } + + public String getPrintId() { + return printId; + } + + public void setPrintId(String printId) { + this.printId = printId; + } + + public String getDemo() { + return demo; + } + + public void setDemo(String demo) { + this.demo = demo; + } + + public Integer getMaterialsId() { + return materialsId; + } + + public void setMaterialsId(Integer materialsId) { + this.materialsId = materialsId; + } + + public Integer getSupplierId() { + return supplierId; + } + + public void setSupplierId(Integer supplierId) { + this.supplierId = supplierId; + } + + public Boolean getUploadFlag() { + return uploadFlag; + } + + public void setUploadFlag(Boolean uploadFlag) { + this.uploadFlag = uploadFlag; + } + + public Boolean getUselessFlag() { + return uselessFlag; + } + + public void setUselessFlag(Boolean uselessFlag) { + this.uselessFlag = uselessFlag; + } + + public String getTareModel() { + return tareModel; + } + + public void setTareModel(String tareModel) { + this.tareModel = tareModel; + } + + public String getGrossScaleId() { + return grossScaleId; + } + + public void setGrossScaleId(String grossScaleId) { + this.grossScaleId = grossScaleId; + } + + public String getTareScaleId() { + return tareScaleId; + } + + public void setTareScaleId(String tareScaleId) { + this.tareScaleId = tareScaleId; + } +} \ No newline at end of file diff --git a/src/main/java/com/example/webapi/entity/MaterialInfo.java b/src/main/java/com/example/webapi/entity/MaterialInfo.java index cd3b3b3..925d5dd 100644 --- a/src/main/java/com/example/webapi/entity/MaterialInfo.java +++ b/src/main/java/com/example/webapi/entity/MaterialInfo.java @@ -11,6 +11,7 @@ import javax.persistence.*; @ApiModel(description = "品种信息实体") public class MaterialInfo { @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "ID") @ApiModelProperty(value = "品种ID", example = "1", notes = "主键,自动生成") private Integer id; @@ -26,4 +27,4 @@ public class MaterialInfo { @Column(name = "Activate", nullable = false) @ApiModelProperty(value = "激活状态", example = "true", notes = "true=激活,false=未激活") private Boolean activate; -} \ No newline at end of file +} diff --git a/src/main/java/com/example/webapi/entity/Supplier.java b/src/main/java/com/example/webapi/entity/Supplier.java index 29b8b35..426b3d1 100644 --- a/src/main/java/com/example/webapi/entity/Supplier.java +++ b/src/main/java/com/example/webapi/entity/Supplier.java @@ -11,6 +11,7 @@ import javax.persistence.*; @ApiModel(description = "供应商信息实体") public class Supplier { @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "ID") @ApiModelProperty(value = "供应商ID", example = "1", notes = "主键,自动生成") private Integer id; diff --git a/src/main/java/com/example/webapi/entity/SupplyVariety.java b/src/main/java/com/example/webapi/entity/SupplyVariety.java index f2ea143..3ab3784 100644 --- a/src/main/java/com/example/webapi/entity/SupplyVariety.java +++ b/src/main/java/com/example/webapi/entity/SupplyVariety.java @@ -11,6 +11,7 @@ import javax.persistence.*; @ApiModel(description = "供应标识品种信息实体") public class SupplyVariety { @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "ID") @ApiModelProperty(value = "记录ID", example = "1", notes = "主键,自动生成") private Integer id; @@ -26,4 +27,4 @@ public class SupplyVariety { @Column(name = "Active") @ApiModelProperty(value = "激活状态", example = "true", notes = "true=激活,false=未激活") private Boolean active; -} \ No newline at end of file +} diff --git a/src/main/java/com/example/webapi/entity/TransferRecord.java b/src/main/java/com/example/webapi/entity/TransferRecord.java index 8ac2c07..7a1bc3a 100644 --- a/src/main/java/com/example/webapi/entity/TransferRecord.java +++ b/src/main/java/com/example/webapi/entity/TransferRecord.java @@ -13,6 +13,7 @@ import java.util.Date; @ApiModel(description = "转运记录实体") public class TransferRecord { @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "ID") @ApiModelProperty(value = "记录ID", example = "1", notes = "主键,自动生成") private Integer id; diff --git a/src/main/java/com/example/webapi/entity/TransportCompany.java b/src/main/java/com/example/webapi/entity/TransportCompany.java index 7f377fd..b92b4a0 100644 --- a/src/main/java/com/example/webapi/entity/TransportCompany.java +++ b/src/main/java/com/example/webapi/entity/TransportCompany.java @@ -11,6 +11,7 @@ import javax.persistence.*; @ApiModel(description = "运输公司实体") public class TransportCompany { @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "编号") @ApiModelProperty(value = "公司ID", example = "1", notes = "主键,自动生成") private Integer id; @@ -22,4 +23,4 @@ public class TransportCompany { @Column(name = "备注", length = 300) @ApiModelProperty(value = "备注", example = "长期合作伙伴") private String remark; -} \ No newline at end of file +} diff --git a/src/main/java/com/example/webapi/entity/TwiceWeighing.java b/src/main/java/com/example/webapi/entity/TwiceWeighing.java new file mode 100644 index 0000000..be77b30 --- /dev/null +++ b/src/main/java/com/example/webapi/entity/TwiceWeighing.java @@ -0,0 +1,144 @@ +package com.example.webapi.entity; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import javax.persistence.*; +import java.math.BigDecimal; +import java.util.Date; +@Data +@Entity +@Table(name = "TB_TWICEWEIGHING") +public class TwiceWeighing { + @Id + @Column(name = "ID", length = 22, nullable = false) + private String id; + + @Column(name = "VEHICLETYPE", length = 10) + private String vehicleType; + + @Column(name = "VEHICLEID", length = 10) + private String vehicleId; + + @Column(name = "GROSS", precision = 18, scale = 3) + private BigDecimal gross; + + @Column(name = "TARE", precision = 18, scale = 3) + private BigDecimal tare; + + @Column(name = "NET", precision = 18, scale = 3) + private BigDecimal net; + + @Column(name = "STANDARD", precision = 18, scale = 3) + private BigDecimal standard; + + @Column(name = "MAXWEIGHT", precision = 18, scale = 3) + private BigDecimal maxWeight; + + @Column(name = "OTHERNET", precision = 18, scale = 3) + private BigDecimal otherNet; + + @Column(name = "GROSSTIME") + private Date grossTime; + + @Column(name = "TARETIME") + private Date tareTime; + + @Column(name = "NETTIME") + private Date netTime; + + @Column(name = "WINTERVAL") + private Integer winterval; + + @Column(name = "GROSSNODEID", length = 22) + private String grossNodeId; + + @Column(name = "TARENODEID", length = 22) + private String tareNodeId; + + @Column(name = "GROSSSCALEID", length = 10) + private String grossScaleId; + + @Column(name = "TARESCALEID", length = 10) + private String tareScaleId; + + @Column(name = "GROSSOPID", length = 10) + private String grossOpId; + + @Column(name = "TAREOPID", length = 10) + private String tareOpId; + + @Column(name = "TAREMODEL", length = 10) + private String tareModel; + + @Column(name = "UPLOADFLAG") + private Boolean uploadFlag; + + @Column(name = "USELESSFLAG") + private Boolean uselessFlag; + + @Column(name = "PRINTCOUNT") + private Integer printCount; + + @Column(name = "PRINTID", length = 30) + private String printId; + + @Column(name = "DEMO", length = 50) + private String demo; + + @Column(name = "MATERIALSID") + private Integer materialsId; + + @Column(name = "SUPPLIERID") + private Integer supplierId; + + @Column(name = "LOSSPATH") + private Float lossPath; + + @Column(name = "WINWEIGHT") + private Float winWeight; + + @Column(name = "LOSSWEIHGT") + private Float lossWeight; + + @Column(name = "GROSSSPEED") + private Float grossSpeed; + + @Column(name = "TARESPEED") + private Float tareSpeed; + + @Column(name = "GROSSLISTID", length = 20) + private String grossListId; + + @Column(name = "TARELISTID", length = 20) + private String tareListId; + + @Column(name = "DELWEIGHT") + private Float delWeight; + + @Column(name = "GOODS", length = 50) + private String goods; + + @Column(name = "RECEIVEUNIT", length = 50) + private String receiveUnit; + + @Column(name = "SENDUNIT", length = 50) + private String sendUnit; + + @Column(name = "SENDSTSTION", length = 50) + private String sendStation; + + @Column(name = "THESTATION", length = 50) + private String theStation; + + @Column(name = "FURNACENUMBER", length = 50) + private String furnaceNumber; + + @Column(name = "IRONNUMBER", length = 50) + private String ironNumber; + + @Column(name = "DIRECTION", length = 50) + private String direction; + + +} diff --git a/src/main/java/com/example/webapi/entity/VehicleInfo.java b/src/main/java/com/example/webapi/entity/VehicleInfo.java index 8877aee..d8e6e50 100644 --- a/src/main/java/com/example/webapi/entity/VehicleInfo.java +++ b/src/main/java/com/example/webapi/entity/VehicleInfo.java @@ -11,6 +11,7 @@ import javax.persistence.*; @ApiModel(description = "车辆信息实体") public class VehicleInfo { @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "ID") @ApiModelProperty(value = "车辆ID", example = "1", notes = "主键,自动生成") private Integer id; @@ -42,4 +43,4 @@ public class VehicleInfo { @Column(name = "Remarks", length = 1000) @ApiModelProperty(value = "备注", example = "新购车辆") private String remarks; -} \ No newline at end of file +} diff --git a/src/main/java/com/example/webapi/entity/WeighingRecord.java b/src/main/java/com/example/webapi/entity/WeighingRecord.java index c21fe28..d4bdabc 100644 --- a/src/main/java/com/example/webapi/entity/WeighingRecord.java +++ b/src/main/java/com/example/webapi/entity/WeighingRecord.java @@ -13,6 +13,7 @@ import java.util.Date; @ApiModel(description = "称重记录实体") public class WeighingRecord { @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "ID") @ApiModelProperty(value = "记录ID", example = "1", notes = "主键,自动生成") private Integer id; @@ -132,4 +133,4 @@ public class WeighingRecord { @Column(name = "WTId") @ApiModelProperty(value = "称重类型ID", example = "1") private Integer wtId; -} \ No newline at end of file +} diff --git a/src/main/java/com/example/webapi/entity/postgresql/TwiceWeighingPostgreSQL.java b/src/main/java/com/example/webapi/entity/postgresql/TwiceWeighingPostgreSQL.java new file mode 100644 index 0000000..91aa603 --- /dev/null +++ b/src/main/java/com/example/webapi/entity/postgresql/TwiceWeighingPostgreSQL.java @@ -0,0 +1,141 @@ +package com.example.webapi.entity.postgresql; + +import lombok.Data; +import javax.persistence.*; +import java.math.BigDecimal; +import java.util.Date; + +@Data +@Entity +@Table(name = "tb_twice_weighing") +public class TwiceWeighingPostgreSQL { + @Id + @Column(name = "id", length = 22, nullable = false) + private String id; + + @Column(name = "vehicle_type", length = 10) + private String vehicleType; + + @Column(name = "vehicle_id", length = 10) + private String vehicleId; + + @Column(name = "gross", precision = 18, scale = 3) + private BigDecimal gross; + + @Column(name = "tare", precision = 18, scale = 3) + private BigDecimal tare; + + @Column(name = "net", precision = 18, scale = 3) + private BigDecimal net; + + @Column(name = "standard", precision = 18, scale = 3) + private BigDecimal standard; + + @Column(name = "max_weight", precision = 18, scale = 3) + private BigDecimal maxWeight; + + @Column(name = "other_net", precision = 18, scale = 3) + private BigDecimal otherNet; + + @Column(name = "gross_time") + private Date grossTime; + + @Column(name = "tare_time") + private Date tareTime; + + @Column(name = "net_time") + private Date netTime; + + @Column(name = "winterval") + private Integer winterval; + + @Column(name = "gross_node_id", length = 22) + private String grossNodeId; + + @Column(name = "tare_node_id", length = 22) + private String tareNodeId; + + @Column(name = "gross_scale_id", length = 10) + private String grossScaleId; + + @Column(name = "tare_scale_id", length = 10) + private String tareScaleId; + + @Column(name = "gross_op_id", length = 10) + private String grossOpId; + + @Column(name = "tare_op_id", length = 10) + private String tareOpId; + + @Column(name = "tare_model", length = 10) + private String tareModel; + + @Column(name = "upload_flag") + private Boolean uploadFlag; + + @Column(name = "useless_flag") + private Boolean uselessFlag; + + @Column(name = "print_count") + private Integer printCount; + + @Column(name = "print_id", length = 30) + private String printId; + + @Column(name = "demo", length = 50) + private String demo; + + @Column(name = "materials_id") + private Integer materialsId; + + @Column(name = "supplier_id") + private Integer supplierId; + + @Column(name = "loss_path") + private Float lossPath; + + @Column(name = "win_weight") + private Float winWeight; + + @Column(name = "loss_weight") + private Float lossWeight; + + @Column(name = "gross_speed") + private Float grossSpeed; + + @Column(name = "tare_speed") + private Float tareSpeed; + + @Column(name = "gross_list_id", length = 20) + private String grossListId; + + @Column(name = "tare_list_id", length = 20) + private String tareListId; + + @Column(name = "del_weight") + private Float delWeight; + + @Column(name = "goods", length = 50) + private String goods; + + @Column(name = "receive_unit", length = 50) + private String receiveUnit; + + @Column(name = "send_unit", length = 50) + private String sendUnit; + + @Column(name = "send_station", length = 50) + private String sendStation; + + @Column(name = "the_station", length = 50) + private String theStation; + + @Column(name = "furnace_number", length = 50) + private String furnaceNumber; + + @Column(name = "iron_number", length = 50) + private String ironNumber; + + @Column(name = "direction", length = 50) + private String direction; +} \ No newline at end of file diff --git a/src/main/java/com/example/webapi/repository/TwiceWeighingRepository.java b/src/main/java/com/example/webapi/repository/TwiceWeighingRepository.java new file mode 100644 index 0000000..b56d1e8 --- /dev/null +++ b/src/main/java/com/example/webapi/repository/TwiceWeighingRepository.java @@ -0,0 +1,73 @@ +package com.example.webapi.repository; + +import com.example.webapi.entity.TwiceWeighing; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.stereotype.Repository; + +/** + * 二次称重记录数据访问层 + * + * @author Your Name + * @version 1.0.0 + */ +@Repository("twiceWeighingRepository") +public interface TwiceWeighingRepository extends JpaRepository, JpaSpecificationExecutor { + + /** + * 根据车号查询记录 + * + * @param vehicleId 车号 + * @return 二次称重记录 + */ + TwiceWeighing findByVehicleId(String vehicleId); + + /** + * 根据打印编号查询记录 + * + * @param printId 打印编号 + * @return 二次称重记录 + */ + TwiceWeighing findByPrintId(String printId); + + /** + * 根据上传标志查询记录数量 + * + * @param uploadFlag 上传标志 + * @return 记录数量 + */ + long countByUploadFlag(Boolean uploadFlag); + + /** + * 根据作废标志查询记录数量 + * + * @param uselessFlag 作废标志 + * @return 记录数量 + */ + long countByUselessFlag(Boolean uselessFlag); + + /** + * 根据上传标志查询记录列表 + * + * @param uploadFlag 上传标志 + * @return 二次称重记录列表 + */ + java.util.List findByUploadFlag(Boolean uploadFlag); + + /** + * 根据皮重时间查询大于指定时间的记录 + * + * @param tareTime 皮重时间 + * @return 二次称重记录列表 + */ + java.util.List findByTareTimeAfter(java.util.Date tareTime); + + /** + * 根据皮重时间查询大于指定时间且未上传的记录 + * + * @param tareTime 皮重时间 + * @param uploadFlag 上传标志 + * @return 二次称重记录列表 + */ + java.util.List findByTareTimeAfterAndUploadFlag(java.util.Date tareTime, Boolean uploadFlag); +} \ No newline at end of file diff --git a/src/main/java/com/example/webapi/repository/pg/TwiceWeighingPostgreSQLRepository.java b/src/main/java/com/example/webapi/repository/pg/TwiceWeighingPostgreSQLRepository.java new file mode 100644 index 0000000..8249206 --- /dev/null +++ b/src/main/java/com/example/webapi/repository/pg/TwiceWeighingPostgreSQLRepository.java @@ -0,0 +1,38 @@ +package com.example.webapi.repository.pg; + +import com.example.webapi.entity.postgresql.TwiceWeighingPostgreSQL; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface TwiceWeighingPostgreSQLRepository extends JpaRepository { + + @Query("SELECT t FROM TwiceWeighingPostgreSQL t WHERE t.uploadFlag = :uploadFlag") + List findByUploadFlag(@Param("uploadFlag") Boolean uploadFlag); + + @Query("SELECT t FROM TwiceWeighingPostgreSQL t WHERE t.uselessFlag = :uselessFlag") + List findByUselessFlag(@Param("uselessFlag") Boolean uselessFlag); + + @Query("SELECT t FROM TwiceWeighingPostgreSQL t WHERE t.vehicleId = :vehicleId") + List findByVehicleId(@Param("vehicleId") String vehicleId); + + @Query("SELECT t FROM TwiceWeighingPostgreSQL t WHERE t.grossTime BETWEEN :startTime AND :endTime") + List findByGrossTimeBetween(@Param("startTime") java.util.Date startTime, + @Param("endTime") java.util.Date endTime); + + /** + * 查询最大的皮重时间 + */ + @Query("SELECT MAX(t.tareTime) FROM TwiceWeighingPostgreSQL t WHERE t.tareTime IS NOT NULL") + java.util.Date findMaxTareTime(); + + /** + * 根据皮重时间范围查询记录 + */ + @Query("SELECT t FROM TwiceWeighingPostgreSQL t WHERE t.tareTime > :tareTime") + List findByTareTimeAfter(@Param("tareTime") java.util.Date tareTime); +} \ No newline at end of file diff --git a/src/main/java/com/example/webapi/service/DataSyncService.java b/src/main/java/com/example/webapi/service/DataSyncService.java new file mode 100644 index 0000000..32ac36f --- /dev/null +++ b/src/main/java/com/example/webapi/service/DataSyncService.java @@ -0,0 +1,352 @@ +package com.example.webapi.service; + +import com.example.webapi.entity.TwiceWeighing; +import com.example.webapi.entity.postgresql.TwiceWeighingPostgreSQL; +import com.example.webapi.repository.TwiceWeighingRepository; +import com.example.webapi.repository.pg.TwiceWeighingPostgreSQLRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Optional; + +@Service +public class DataSyncService { + + @Autowired + @Qualifier("twiceWeighingRepository") + private TwiceWeighingRepository twiceWeighingRepository; + + @Autowired + @Qualifier("twiceWeighingPostgreSQLRepository") + private TwiceWeighingPostgreSQLRepository twiceWeighingPostgreSQLRepository; + + /** + * 同步单条数据 + */ + @Transactional(transactionManager = "postgresqlTransactionManager") + public boolean syncSingleRecord(String id) { + try { + Optional sourceRecord = twiceWeighingRepository.findById(id); + if (sourceRecord.isPresent()) { + TwiceWeighing source = sourceRecord.get(); + TwiceWeighingPostgreSQL target = convertToPostgreSQL(source); + + // 直接插入新记录 + twiceWeighingPostgreSQLRepository.save(target); + return true; + } + return false; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 批量同步数据 - 仅插入操作 + */ + @Transactional(transactionManager = "postgresqlTransactionManager") + public int syncBatchRecords(List ids) { + try { + List sourceRecords = new ArrayList<>(); + + // 批量查询源数据 + for (String id : ids) { + Optional sourceRecord = twiceWeighingRepository.findById(id); + if (sourceRecord.isPresent()) { + sourceRecords.add(sourceRecord.get()); + } + } + + // 使用批量处理方法 + return processBatch(sourceRecords); + } catch (Exception e) { + e.printStackTrace(); + return 0; + } + } + + /** + * 同步所有未上传的数据 - 分批处理 + */ + @Transactional(transactionManager = "postgresqlTransactionManager") + public int syncUnuploadedRecords() { + return syncUnuploadedRecords(500); + } + + /** + * 同步所有未上传的数据 - 指定批次大小 + */ + @Transactional(transactionManager = "postgresqlTransactionManager") + public int syncUnuploadedRecords(int batchSize) { + try { + List unuploadedRecords = twiceWeighingRepository.findByUploadFlag(false); + int totalRecords = unuploadedRecords.size(); + + System.out.println("未上传数据同步开始,总记录数: " + totalRecords + ",批次大小: " + batchSize); + + int successCount = 0; + int batchCount = 0; + + // 分批处理 + for (int i = 0; i < totalRecords; i += batchSize) { + int endIndex = Math.min(i + batchSize, totalRecords); + List batchRecords = unuploadedRecords.subList(i, endIndex); + + batchCount++; + System.out.println("处理第 " + batchCount + " 批,记录范围: " + (i + 1) + " - " + endIndex); + + int batchSuccessCount = processBatch(batchRecords); + successCount += batchSuccessCount; + + System.out.println("第 " + batchCount + " 批处理完成,成功: " + batchSuccessCount + " 条"); + } + + System.out.println("未上传数据同步完成,总成功: " + successCount + " 条"); + return successCount; + } catch (Exception e) { + e.printStackTrace(); + return 0; + } + } + + /** + * 增量同步数据(基于皮重时间) + */ + @Transactional(transactionManager = "postgresqlTransactionManager") + public int syncIncrementalData() { + try { + // 获取PostgreSQL中最大的皮重时间 + Date maxTareTime = twiceWeighingPostgreSQLRepository.findMaxTareTime(); + + if (maxTareTime == null) { + // 如果PostgreSQL中没有数据,则同步所有数据 + return syncAllData(); + } + + // 查询SQL Server中大于最大皮重时间的记录 + List incrementalRecords = twiceWeighingRepository.findByTareTimeAfter(maxTareTime); + + int successCount = 0; + for (TwiceWeighing source : incrementalRecords) { + TwiceWeighingPostgreSQL target = convertToPostgreSQL(source); + + // 检查是否已存在 + Optional existingRecord = twiceWeighingPostgreSQLRepository.findById(source.getId()); + if (existingRecord.isPresent()) { + // 更新现有记录 + TwiceWeighingPostgreSQL existing = existingRecord.get(); + updatePostgreSQLRecord(existing, source); + twiceWeighingPostgreSQLRepository.save(existing); + } else { + // 插入新记录 + twiceWeighingPostgreSQLRepository.save(target); + } + successCount++; + } + + return successCount; + } catch (Exception e) { + e.printStackTrace(); + return 0; + } + } + + /** + * 同步所有数据(用于首次同步或重置)- 分批处理 + */ + @Transactional(transactionManager = "postgresqlTransactionManager") + public int syncAllData() { + return syncAllData(500); + } + + /** + * 同步所有数据(用于首次同步或重置)- 指定批次大小 + */ + @Transactional(transactionManager = "postgresqlTransactionManager") + public int syncAllData(int batchSize) { + try { + List allRecords = twiceWeighingRepository.findAll(); + int totalRecords = allRecords.size(); + + System.out.println("全量同步开始,总记录数: " + totalRecords + ",批次大小: " + batchSize); + + int successCount = 0; + int batchCount = 0; + + // 分批处理 + for (int i = 0; i < totalRecords; i += batchSize) { + int endIndex = Math.min(i + batchSize, totalRecords); + List batchRecords = allRecords.subList(i, endIndex); + + batchCount++; + System.out.println("处理第 " + batchCount + " 批,记录范围: " + (i + 1) + " - " + endIndex); + + int batchSuccessCount = processBatch(batchRecords); + successCount += batchSuccessCount; + + System.out.println("第 " + batchCount + " 批处理完成,成功: " + batchSuccessCount + " 条"); + } + + System.out.println("全量同步完成,总成功: " + successCount + " 条"); + return successCount; + } catch (Exception e) { + e.printStackTrace(); + return 0; + } + } + + /** + * 处理一批数据 - 仅插入操作 + */ + private int processBatch(List batchRecords) { + int successCount = 0; + List entitiesToSave = new ArrayList<>(); + for (TwiceWeighing source : batchRecords) { + try { + // 直接转换为PostgreSQL实体 + TwiceWeighingPostgreSQL target = convertToPostgreSQL(source); + entitiesToSave.add(target); + successCount++; + } catch (Exception e) { + System.err.println("处理记录失败,ID: " + source.getId() + ", 错误: " + e.getMessage()); + } + } + + // 批量插入并立即刷新 + if (!entitiesToSave.isEmpty()) { + try { + twiceWeighingPostgreSQLRepository.saveAllAndFlush(entitiesToSave); + System.out.println("批量插入 " + entitiesToSave.size() + " 条记录成功"); + } catch (Exception e) { + System.err.println("批量插入失败: " + e.getMessage()); + // 如果批量插入失败,尝试逐条插入 + for (TwiceWeighingPostgreSQL entity : entitiesToSave) { + try { + twiceWeighingPostgreSQLRepository.save(entity); + successCount++; + } catch (Exception ex) { + System.err.println("单条插入失败,ID: " + entity.getId() + ", 错误: " + ex.getMessage()); + } + } + } + } + + return successCount; + } + + /** + * 将SQL Server实体转换为PostgreSQL实体 + */ + private TwiceWeighingPostgreSQL convertToPostgreSQL(TwiceWeighing source) { + TwiceWeighingPostgreSQL target = new TwiceWeighingPostgreSQL(); + + target.setId(source.getId()); + target.setVehicleType(source.getVehicleType()); + target.setVehicleId(source.getVehicleId()); + target.setGross(source.getGross()); + target.setTare(source.getTare()); + target.setNet(source.getNet()); + target.setStandard(source.getStandard()); + target.setMaxWeight(source.getMaxWeight()); + target.setOtherNet(source.getOtherNet()); + target.setGrossTime(source.getGrossTime()); + target.setTareTime(source.getTareTime()); + target.setNetTime(source.getNetTime()); + target.setWinterval(source.getWinterval()); + target.setGrossNodeId(source.getGrossNodeId()); + target.setTareNodeId(source.getTareNodeId()); + target.setGrossScaleId(source.getGrossScaleId()); + target.setTareScaleId(source.getTareScaleId()); + target.setGrossOpId(source.getGrossOpId()); + target.setTareOpId(source.getTareOpId()); + target.setTareModel(source.getTareModel()); + target.setUploadFlag(source.getUploadFlag()); + target.setUselessFlag(source.getUselessFlag()); + target.setPrintCount(source.getPrintCount()); + target.setPrintId(source.getPrintId()); + target.setDemo(source.getDemo()); + target.setMaterialsId(source.getMaterialsId()); + target.setSupplierId(source.getSupplierId()); + target.setLossPath(source.getLossPath()); + target.setWinWeight(source.getWinWeight()); + target.setLossWeight(source.getLossWeight()); + target.setGrossSpeed(source.getGrossSpeed()); + target.setTareSpeed(source.getTareSpeed()); + target.setGrossListId(source.getGrossListId()); + target.setTareListId(source.getTareListId()); + target.setDelWeight(source.getDelWeight()); + target.setGoods(source.getGoods()); + target.setReceiveUnit(source.getReceiveUnit()); + target.setSendUnit(source.getSendUnit()); + target.setSendStation(source.getSendStation()); + target.setTheStation(source.getTheStation()); + target.setFurnaceNumber(source.getFurnaceNumber()); + target.setIronNumber(source.getIronNumber()); + target.setDirection(source.getDirection()); + + return target; + } + + /** + * 更新PostgreSQL记录 + */ + private void updatePostgreSQLRecord(TwiceWeighingPostgreSQL target, TwiceWeighing source) { + target.setVehicleType(source.getVehicleType()); + target.setVehicleId(source.getVehicleId()); + target.setGross(source.getGross()); + target.setTare(source.getTare()); + target.setNet(source.getNet()); + target.setStandard(source.getStandard()); + target.setMaxWeight(source.getMaxWeight()); + target.setOtherNet(source.getOtherNet()); + target.setGrossTime(source.getGrossTime()); + target.setTareTime(source.getTareTime()); + target.setNetTime(source.getNetTime()); + target.setWinterval(source.getWinterval()); + target.setGrossNodeId(source.getGrossNodeId()); + target.setTareNodeId(source.getTareNodeId()); + target.setGrossScaleId(source.getGrossScaleId()); + target.setTareScaleId(source.getTareScaleId()); + target.setGrossOpId(source.getGrossOpId()); + target.setTareOpId(source.getTareOpId()); + target.setTareModel(source.getTareModel()); + target.setUploadFlag(source.getUploadFlag()); + target.setUselessFlag(source.getUselessFlag()); + target.setPrintCount(source.getPrintCount()); + target.setPrintId(source.getPrintId()); + target.setDemo(source.getDemo()); + target.setMaterialsId(source.getMaterialsId()); + target.setSupplierId(source.getSupplierId()); + target.setLossPath(source.getLossPath()); + target.setWinWeight(source.getWinWeight()); + target.setLossWeight(source.getLossWeight()); + target.setGrossSpeed(source.getGrossSpeed()); + target.setTareSpeed(source.getTareSpeed()); + target.setGrossListId(source.getGrossListId()); + target.setTareListId(source.getTareListId()); + target.setDelWeight(source.getDelWeight()); + target.setGoods(source.getGoods()); + target.setReceiveUnit(source.getReceiveUnit()); + target.setSendUnit(source.getSendUnit()); + target.setSendStation(source.getSendStation()); + target.setTheStation(source.getTheStation()); + target.setFurnaceNumber(source.getFurnaceNumber()); + target.setIronNumber(source.getIronNumber()); + target.setDirection(source.getDirection()); + } +} diff --git a/src/main/java/com/example/webapi/service/ScheduledSyncService.java b/src/main/java/com/example/webapi/service/ScheduledSyncService.java new file mode 100644 index 0000000..8ea0be8 --- /dev/null +++ b/src/main/java/com/example/webapi/service/ScheduledSyncService.java @@ -0,0 +1,60 @@ +package com.example.webapi.service; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; + +@Component +@Slf4j +@RequiredArgsConstructor +public class ScheduledSyncService implements CommandLineRunner { + + private static final Logger logger = LoggerFactory.getLogger(ScheduledSyncService.class); + + @Autowired + private DataSyncService dataSyncService; + + /** + * 每5分钟执行一次增量同步 + */ + @Scheduled(fixedRate = 300000) // 5分钟 = 300000毫秒 + public void syncIncrementalData() { + try { + logger.info("开始定时增量同步数据..."); + int count = dataSyncService.syncIncrementalData(); + logger.info("定时增量同步完成,成功同步 {} 条记录", count); + } catch (Exception e) { + logger.error("定时增量同步过程中发生错误: {}", e.getMessage(), e); + } + } + + /** + * 每天凌晨2点执行全量同步检查 + */ + @Scheduled(cron = "0 0 2 * * ?") + public void dailyFullSync() { + try { + logger.info("开始每日全量同步检查..."); + int count = dataSyncService.syncIncrementalData(); + logger.info("每日全量同步检查完成,成功同步 {} 条记录", count); + } catch (Exception e) { + logger.error("每日全量同步检查过程中发生错误: {}", e.getMessage(), e); + } + } + + @Override + public void run(String... args) throws Exception { + System.out.println("项目启动后执行增量同步------------------"); + try { + syncIncrementalData(); + } catch (Exception e) { + logger.error("启动时增量同步失败: {}", e.getMessage(), e); + } + } +} diff --git a/src/main/java/com/example/webapi/service/TwiceWeighingService.java b/src/main/java/com/example/webapi/service/TwiceWeighingService.java new file mode 100644 index 0000000..cbad393 --- /dev/null +++ b/src/main/java/com/example/webapi/service/TwiceWeighingService.java @@ -0,0 +1,259 @@ +package com.example.webapi.service; + +import com.example.webapi.dto.TwiceWeighingQueryDTO; +import com.example.webapi.entity.TwiceWeighing; +import com.example.webapi.repository.TwiceWeighingRepository; +import com.example.webapi.util.PageUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; + +import javax.persistence.criteria.Predicate; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +/** + * 二次称重记录服务层 + * + * @author Your Name + * @version 1.0.0 + */ +@Service +@Transactional +public class TwiceWeighingService { + + @Autowired + private TwiceWeighingRepository repository; + + /** + * 根据条件分页查询二次称重记录 + * + * @param queryDTO 查询条件 + * @return 分页结果 + */ + public Page findByConditions(TwiceWeighingQueryDTO queryDTO) { + // 构建分页和排序 + Pageable pageable = buildPageable(queryDTO); + + // 构建查询条件 + Specification spec = buildSpecification(queryDTO); + + return repository.findAll(spec, pageable); + } + + /** + * 根据ID查询二次称重记录 + * + * @param id 记录ID + * @return 二次称重记录 + */ + public Optional findById(String id) { + return repository.findById(id); + } + + /** + * 保存二次称重记录 + * + * @param entity 二次称重记录 + * @return 保存后的记录 + */ + public TwiceWeighing save(TwiceWeighing entity) { + return repository.save(entity); + } + + /** + * 根据ID删除二次称重记录 + * + * @param id 记录ID + */ + public void deleteById(String id) { + repository.deleteById(id); + } + + /** + * 根据车号查询记录 + * + * @param vehicleId 车号 + * @return 二次称重记录 + */ + public TwiceWeighing findByVehicleId(String vehicleId) { + return repository.findByVehicleId(vehicleId); + } + + /** + * 根据打印编号查询记录 + * + * @param printId 打印编号 + * @return 二次称重记录 + */ + public TwiceWeighing findByPrintId(String printId) { + return repository.findByPrintId(printId); + } + + /** + * 获取上传记录数量 + * + * @param uploadFlag 上传标志 + * @return 记录数量 + */ + public long countByUploadFlag(Boolean uploadFlag) { + return repository.countByUploadFlag(uploadFlag); + } + + /** + * 获取作废记录数量 + * + * @param uselessFlag 作废标志 + * @return 记录数量 + */ + public long countByUselessFlag(Boolean uselessFlag) { + return repository.countByUselessFlag(uselessFlag); + } + + /** + * 构建分页和排序 + * + * @param queryDTO 查询条件 + * @return 分页对象 + */ + private Pageable buildPageable(TwiceWeighingQueryDTO queryDTO) { + // 分页参数 + int page = queryDTO.getPage() != null ? queryDTO.getPage() : 0; + int size = queryDTO.getSize() != null ? queryDTO.getSize() : 10; + + // 排序 + Sort sort = Sort.unsorted(); + if (StringUtils.hasText(queryDTO.getSortBy())) { + String direction = "desc".equalsIgnoreCase(queryDTO.getSortDirection()) ? "desc" : "asc"; + sort = Sort.by(Sort.Direction.fromString(direction), queryDTO.getSortBy()); + } + + return PageRequest.of(page, size, sort); + } + + /** + * 构建查询条件 + * + * @param queryDTO 查询条件 + * @return 查询规格 + */ + private Specification buildSpecification(TwiceWeighingQueryDTO queryDTO) { + return (root, query, criteriaBuilder) -> { + List predicates = new ArrayList<>(); + + // 车号模糊查询 + if (StringUtils.hasText(queryDTO.getVehicleId())) { + predicates.add(criteriaBuilder.like(root.get("vehicleId"), "%" + queryDTO.getVehicleId() + "%")); + } + + // 车型精确匹配 + if (StringUtils.hasText(queryDTO.getVehicleType())) { + predicates.add(criteriaBuilder.equal(root.get("vehicleType"), queryDTO.getVehicleType())); + } + + // 货物模糊查询 + if (StringUtils.hasText(queryDTO.getGoods())) { + predicates.add(criteriaBuilder.like(root.get("goods"), "%" + queryDTO.getGoods() + "%")); + } + + // 收货单位模糊查询 + if (StringUtils.hasText(queryDTO.getReceiveUnit())) { + predicates.add(criteriaBuilder.like(root.get("receiveUnit"), "%" + queryDTO.getReceiveUnit() + "%")); + } + + // 发货单位模糊查询 + if (StringUtils.hasText(queryDTO.getSendUnit())) { + predicates.add(criteriaBuilder.like(root.get("sendUnit"), "%" + queryDTO.getSendUnit() + "%")); + } + + // 发货站模糊查询 + if (StringUtils.hasText(queryDTO.getSendStation())) { + predicates.add(criteriaBuilder.like(root.get("sendStation"), "%" + queryDTO.getSendStation() + "%")); + } + + // 到站模糊查询 + if (StringUtils.hasText(queryDTO.getTheStation())) { + predicates.add(criteriaBuilder.like(root.get("theStation"), "%" + queryDTO.getTheStation() + "%")); + } + + // 炉号模糊查询 + if (StringUtils.hasText(queryDTO.getFurnaceNumber())) { + predicates.add(criteriaBuilder.like(root.get("furnaceNumber"), "%" + queryDTO.getFurnaceNumber() + "%")); + } + + // 铁号模糊查询 + if (StringUtils.hasText(queryDTO.getIronNumber())) { + predicates.add(criteriaBuilder.like(root.get("ironNumber"), "%" + queryDTO.getIronNumber() + "%")); + } + + // 方向精确匹配 + if (StringUtils.hasText(queryDTO.getDirection())) { + predicates.add(criteriaBuilder.equal(root.get("direction"), queryDTO.getDirection())); + } + + // 毛重操作员ID模糊查询 + if (StringUtils.hasText(queryDTO.getGrossOpId())) { + predicates.add(criteriaBuilder.like(root.get("grossOpId"), "%" + queryDTO.getGrossOpId() + "%")); + } + + // 皮重操作员ID模糊查询 + if (StringUtils.hasText(queryDTO.getTareOpId())) { + predicates.add(criteriaBuilder.like(root.get("tareOpId"), "%" + queryDTO.getTareOpId() + "%")); + } + + // 打印编号模糊查询 + if (StringUtils.hasText(queryDTO.getPrintId())) { + predicates.add(criteriaBuilder.like(root.get("printId"), "%" + queryDTO.getPrintId() + "%")); + } + + // 备注模糊查询 + if (StringUtils.hasText(queryDTO.getDemo())) { + predicates.add(criteriaBuilder.like(root.get("demo"), "%" + queryDTO.getDemo() + "%")); + } + + // 物资ID精确匹配 + if (queryDTO.getMaterialsId() != null) { + predicates.add(criteriaBuilder.equal(root.get("materialsId"), queryDTO.getMaterialsId())); + } + + // 供应商ID精确匹配 + if (queryDTO.getSupplierId() != null) { + predicates.add(criteriaBuilder.equal(root.get("supplierId"), queryDTO.getSupplierId())); + } + + // 上传标志精确匹配 + if (queryDTO.getUploadFlag() != null) { + predicates.add(criteriaBuilder.equal(root.get("uploadFlag"), queryDTO.getUploadFlag())); + } + + // 作废标志精确匹配 + if (queryDTO.getUselessFlag() != null) { + predicates.add(criteriaBuilder.equal(root.get("uselessFlag"), queryDTO.getUselessFlag())); + } + + // 皮重模式精确匹配 + if (StringUtils.hasText(queryDTO.getTareModel())) { + predicates.add(criteriaBuilder.equal(root.get("tareModel"), queryDTO.getTareModel())); + } + + // 毛重衡器ID精确匹配 + if (StringUtils.hasText(queryDTO.getGrossScaleId())) { + predicates.add(criteriaBuilder.equal(root.get("grossScaleId"), queryDTO.getGrossScaleId())); + } + + // 皮重衡器ID精确匹配 + if (StringUtils.hasText(queryDTO.getTareScaleId())) { + predicates.add(criteriaBuilder.equal(root.get("tareScaleId"), queryDTO.getTareScaleId())); + } + + return criteriaBuilder.and(predicates.toArray(new Predicate[0])); + }; + } +} diff --git a/src/main/java/com/example/webapi/util/DataSyncTest.java b/src/main/java/com/example/webapi/util/DataSyncTest.java new file mode 100644 index 0000000..e43430c --- /dev/null +++ b/src/main/java/com/example/webapi/util/DataSyncTest.java @@ -0,0 +1,163 @@ +package com.example.webapi.util; + +import com.example.webapi.entity.TwiceWeighing; +import com.example.webapi.entity.postgresql.TwiceWeighingPostgreSQL; +import com.example.webapi.repository.TwiceWeighingRepository; +import com.example.webapi.repository.pg.TwiceWeighingPostgreSQLRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; + +/** + * 数据同步测试工具类 + */ +@Component +public class DataSyncTest { + + @Autowired + @Qualifier("twiceWeighingRepository") + private TwiceWeighingRepository twiceWeighingRepository; + + @Autowired + @Qualifier("twiceWeighingPostgreSQLRepository") + private TwiceWeighingPostgreSQLRepository twiceWeighingPostgreSQLRepository; + + /** + * 测试数据源连接 + */ + public void testDataSources() { + System.out.println("=== 测试数据源连接 ==="); + + try { + // 测试SQL Server连接 + long sqlServerCount = twiceWeighingRepository.count(); + System.out.println("SQL Server连接正常,记录总数: " + sqlServerCount); + + // 测试PostgreSQL连接 + long postgresqlCount = twiceWeighingPostgreSQLRepository.count(); + System.out.println("PostgreSQL连接正常,记录总数: " + postgresqlCount); + + } catch (Exception e) { + System.err.println("数据源连接测试失败: " + e.getMessage()); + e.printStackTrace(); + } + } + + /** + * 测试数据同步 + */ + public void testDataSync() { + System.out.println("=== 测试数据同步 ==="); + + try { + // 获取SQL Server中的一条记录 + List records = twiceWeighingRepository.findAll(); + if (!records.isEmpty()) { + TwiceWeighing sourceRecord = records.get(0); + System.out.println("源记录ID: " + sourceRecord.getId()); + + // 转换为PostgreSQL实体 + TwiceWeighingPostgreSQL targetRecord = convertToPostgreSQL(sourceRecord); + + // 保存到PostgreSQL + twiceWeighingPostgreSQLRepository.save(targetRecord); + System.out.println("数据同步测试成功"); + + } else { + System.out.println("SQL Server中没有找到记录"); + } + + } catch (Exception e) { + System.err.println("数据同步测试失败: " + e.getMessage()); + e.printStackTrace(); + } + } + + /** + * 测试增量同步 + */ + public void testIncrementalSync() { + System.out.println("=== 测试增量同步 ==="); + + try { + // 获取PostgreSQL中最大的皮重时间 + Date maxTareTime = twiceWeighingPostgreSQLRepository.findMaxTareTime(); + System.out.println("PostgreSQL中最大皮重时间: " + maxTareTime); + + if (maxTareTime == null) { + System.out.println("PostgreSQL中没有数据,将执行全量同步"); + return; + } + + // 查询SQL Server中大于最大皮重时间的记录 + List incrementalRecords = twiceWeighingRepository.findByTareTimeAfter(maxTareTime); + System.out.println("需要增量同步的记录数: " + incrementalRecords.size()); + + if (!incrementalRecords.isEmpty()) { + System.out.println("第一条增量记录ID: " + incrementalRecords.get(0).getId()); + System.out.println("第一条增量记录皮重时间: " + incrementalRecords.get(0).getTareTime()); + } + + } catch (Exception e) { + System.err.println("增量同步测试失败: " + e.getMessage()); + e.printStackTrace(); + } + } + + /** + * 将SQL Server实体转换为PostgreSQL实体 + */ + private TwiceWeighingPostgreSQL convertToPostgreSQL(TwiceWeighing source) { + TwiceWeighingPostgreSQL target = new TwiceWeighingPostgreSQL(); + + target.setId(source.getId()); + target.setVehicleType(source.getVehicleType()); + target.setVehicleId(source.getVehicleId()); + target.setGross(source.getGross()); + target.setTare(source.getTare()); + target.setNet(source.getNet()); + target.setStandard(source.getStandard()); + target.setMaxWeight(source.getMaxWeight()); + target.setOtherNet(source.getOtherNet()); + target.setGrossTime(source.getGrossTime()); + target.setTareTime(source.getTareTime()); + target.setNetTime(source.getNetTime()); + target.setWinterval(source.getWinterval()); + target.setGrossNodeId(source.getGrossNodeId()); + target.setTareNodeId(source.getTareNodeId()); + target.setGrossScaleId(source.getGrossScaleId()); + target.setTareScaleId(source.getTareScaleId()); + target.setGrossOpId(source.getGrossOpId()); + target.setTareOpId(source.getTareOpId()); + target.setTareModel(source.getTareModel()); + target.setUploadFlag(source.getUploadFlag()); + target.setUselessFlag(source.getUselessFlag()); + target.setPrintCount(source.getPrintCount()); + target.setPrintId(source.getPrintId()); + target.setDemo(source.getDemo()); + target.setMaterialsId(source.getMaterialsId()); + target.setSupplierId(source.getSupplierId()); + target.setLossPath(source.getLossPath()); + target.setWinWeight(source.getWinWeight()); + target.setLossWeight(source.getLossWeight()); + target.setGrossSpeed(source.getGrossSpeed()); + target.setTareSpeed(source.getTareSpeed()); + target.setGrossListId(source.getGrossListId()); + target.setTareListId(source.getTareListId()); + target.setDelWeight(source.getDelWeight()); + target.setGoods(source.getGoods()); + target.setReceiveUnit(source.getReceiveUnit()); + target.setSendUnit(source.getSendUnit()); + target.setSendStation(source.getSendStation()); + target.setTheStation(source.getTheStation()); + target.setFurnaceNumber(source.getFurnaceNumber()); + target.setIronNumber(source.getIronNumber()); + target.setDirection(source.getDirection()); + + return target; + } +} \ No newline at end of file diff --git a/src/main/java/com/example/webapi/util/DatabaseConnectionTest.java b/src/main/java/com/example/webapi/util/DatabaseConnectionTest.java new file mode 100644 index 0000000..e9212f7 --- /dev/null +++ b/src/main/java/com/example/webapi/util/DatabaseConnectionTest.java @@ -0,0 +1,52 @@ +package com.example.webapi.util; + +import org.springframework.stereotype.Component; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.Properties; + +@Component +public class DatabaseConnectionTest { + + public void testConnection() { + try { + // 设置连接属性 + Properties props = new Properties(); + props.setProperty("user", "sa"); + props.setProperty("password", "sa"); + props.setProperty("encrypt", "false"); + props.setProperty("trustServerCertificate", "true"); + props.setProperty("hostNameInCertificate", "*"); + props.setProperty("serverNameAsACE", "false"); + props.setProperty("sendStringParametersAsUnicode", "false"); + props.setProperty("loginTimeout", "60"); + props.setProperty("integratedSecurity", "false"); + props.setProperty("rewriteBatchedStatements", "true"); + props.setProperty("SelectMethod", "cursor"); + props.setProperty("validateBulkLoadParameters", "false"); + props.setProperty("sendTemporalDataTypesAsStringForBulkCopy", "true"); + props.setProperty("delayLoadingLobs", "true"); + props.setProperty("useNTLMV2", "true"); + props.setProperty("authenticationScheme", "NativeAuthentication"); + + // 测试连接 + String url = "jdbc:sqlserver://192.168.35.216:1433;DatabaseName=WY_DATAMANAGE20250731"; + Connection conn = DriverManager.getConnection(url, props); + + System.out.println("数据库连接测试成功!"); + System.out.println("数据库产品名称: " + conn.getMetaData().getDatabaseProductName()); + System.out.println("数据库版本: " + conn.getMetaData().getDatabaseProductVersion()); + System.out.println("驱动名称: " + conn.getMetaData().getDriverName()); + System.out.println("驱动版本: " + conn.getMetaData().getDriverVersion()); + + conn.close(); + + } catch (SQLException e) { + System.err.println("数据库连接测试失败!"); + System.err.println("错误信息: " + e.getMessage()); + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/example/webapi/util/SQLServerVersionTest.java b/src/main/java/com/example/webapi/util/SQLServerVersionTest.java new file mode 100644 index 0000000..9ff7404 --- /dev/null +++ b/src/main/java/com/example/webapi/util/SQLServerVersionTest.java @@ -0,0 +1,150 @@ +package com.example.webapi.util; + +import org.springframework.stereotype.Component; + +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.Properties; + +@Component +public class SQLServerVersionTest { + + public void testConnection() { + System.out.println("=== SQL Server 连接测试 ==="); + + // 测试JTDS驱动 + testJTDSConnection(); + + // 测试Microsoft驱动 + testMicrosoftConnection(); + } + + private void testJTDSConnection() { + System.out.println("\n--- 测试JTDS驱动 ---"); + + try { + // JTDS驱动连接 + System.out.println("尝试JTDS驱动连接..."); + String url = "jdbc:jtds:sqlserver://192.168.35.216:1433/WY_DATAMANAGE20250731"; + Properties props = new Properties(); + props.setProperty("user", "sa"); + props.setProperty("password", "sa"); + props.setProperty("ssl", "ignore"); + props.setProperty("sendStringParametersAsUnicode", "false"); + props.setProperty("loginTimeout", "30"); + props.setProperty("useNTLMV2", "true"); + props.setProperty("useLOBs", "false"); + props.setProperty("useCursors", "true"); + props.setProperty("batchSize", "0"); + props.setProperty("tds", "8.0"); + + Connection conn = DriverManager.getConnection(url, props); + printConnectionInfo(conn, "JTDS驱动"); + conn.close(); + + } catch (SQLException e) { + System.err.println("JTDS驱动连接失败: " + e.getMessage()); + e.printStackTrace(); + } + } + + private void testMicrosoftConnection() { + System.out.println("\n--- 测试Microsoft驱动 ---"); + + try { + // 方法1: 最简单的连接方式 + System.out.println("尝试方法1: 简单连接..."); + String url1 = "jdbc:sqlserver://192.168.35.216:1433;DatabaseName=WY_DATAMANAGE20250731"; + Properties props1 = new Properties(); + props1.setProperty("user", "sa"); + props1.setProperty("password", "sa"); + + Connection conn1 = DriverManager.getConnection(url1, props1); + printConnectionInfo(conn1, "方法1"); + conn1.close(); + + } catch (SQLException e1) { + System.err.println("方法1失败: " + e1.getMessage()); + + try { + // 方法2: 明确禁用SSL + System.out.println("尝试方法2: 明确禁用SSL..."); + String url2 = "jdbc:sqlserver://192.168.35.216:1433;DatabaseName=WY_DATAMANAGE20250731;encrypt=false;trustServerCertificate=true"; + Properties props2 = new Properties(); + props2.setProperty("user", "sa"); + props2.setProperty("password", "sa"); + props2.setProperty("encrypt", "false"); + props2.setProperty("trustServerCertificate", "true"); + + Connection conn2 = DriverManager.getConnection(url2, props2); + printConnectionInfo(conn2, "方法2"); + conn2.close(); + + } catch (SQLException e2) { + System.err.println("方法2失败: " + e2.getMessage()); + + try { + // 方法3: 使用老版本的连接方式 + System.out.println("尝试方法3: 老版本连接方式..."); + String url3 = "jdbc:sqlserver://192.168.35.216:1433;DatabaseName=WY_DATAMANAGE20250731;SelectMethod=cursor;sendStringParametersAsUnicode=false"; + Properties props3 = new Properties(); + props3.setProperty("user", "sa"); + props3.setProperty("password", "sa"); + props3.setProperty("SelectMethod", "cursor"); + props3.setProperty("sendStringParametersAsUnicode", "false"); + + Connection conn3 = DriverManager.getConnection(url3, props3); + printConnectionInfo(conn3, "方法3"); + conn3.close(); + + } catch (SQLException e3) { + System.err.println("方法3失败: " + e3.getMessage()); + + try { + // 方法4: 完全禁用所有SSL相关功能 + System.out.println("尝试方法4: 完全禁用SSL..."); + String url4 = "jdbc:sqlserver://192.168.35.216:1433;DatabaseName=WY_DATAMANAGE20250731;encrypt=false;trustServerCertificate=true;hostNameInCertificate=*;serverNameAsACE=false;sendStringParametersAsUnicode=false;loginTimeout=60;integratedSecurity=false;rewriteBatchedStatements=true;SelectMethod=cursor;validateBulkLoadParameters=false;sendTemporalDataTypesAsStringForBulkCopy=true;delayLoadingLobs=true;useNTLMV2=true;authenticationScheme=NativeAuthentication"; + Properties props4 = new Properties(); + props4.setProperty("user", "sa"); + props4.setProperty("password", "sa"); + props4.setProperty("encrypt", "false"); + props4.setProperty("trustServerCertificate", "true"); + props4.setProperty("hostNameInCertificate", "*"); + props4.setProperty("serverNameAsACE", "false"); + props4.setProperty("sendStringParametersAsUnicode", "false"); + props4.setProperty("loginTimeout", "60"); + props4.setProperty("integratedSecurity", "false"); + props4.setProperty("rewriteBatchedStatements", "true"); + props4.setProperty("SelectMethod", "cursor"); + props4.setProperty("validateBulkLoadParameters", "false"); + props4.setProperty("sendTemporalDataTypesAsStringForBulkCopy", "true"); + props4.setProperty("delayLoadingLobs", "true"); + props4.setProperty("useNTLMV2", "true"); + props4.setProperty("authenticationScheme", "NativeAuthentication"); + + Connection conn4 = DriverManager.getConnection(url4, props4); + printConnectionInfo(conn4, "方法4"); + conn4.close(); + + } catch (SQLException e4) { + System.err.println("方法4失败: " + e4.getMessage()); + System.err.println("Microsoft驱动所有连接方法都失败了!"); + } + } + } + } + } + + private void printConnectionInfo(Connection conn, String method) throws SQLException { + DatabaseMetaData metaData = conn.getMetaData(); + System.out.println("✓ " + method + " 连接成功!"); + System.out.println(" 数据库产品名称: " + metaData.getDatabaseProductName()); + System.out.println(" 数据库版本: " + metaData.getDatabaseProductVersion()); + System.out.println(" 驱动名称: " + metaData.getDriverName()); + System.out.println(" 驱动版本: " + metaData.getDriverVersion()); + System.out.println(" URL: " + metaData.getURL()); + System.out.println(" 用户名: " + metaData.getUserName()); + } +} \ No newline at end of file diff --git a/src/main/java/com/example/webapi/util/SSLTest.java b/src/main/java/com/example/webapi/util/SSLTest.java new file mode 100644 index 0000000..424437d --- /dev/null +++ b/src/main/java/com/example/webapi/util/SSLTest.java @@ -0,0 +1,86 @@ +package com.example.webapi.util; + +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSocketFactory; +import java.security.Security; +import java.util.Arrays; + +public class SSLTest { + + public static void main(String[] args) { + if (args.length > 0 && "list-ciphers".equals(args[0])) { + listCipherSuites(); + } else { + testSSLConfiguration(); + } + } + + public static void testSSLConfiguration() { + System.out.println("=== SSL配置测试 ==="); + + try { + // 获取默认的SSL上下文 + SSLContext sslContext = SSLContext.getInstance("TLS"); + sslContext.init(null, null, null); + + // 获取SSLSocketFactory + SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); + + System.out.println("✓ SSL上下文创建成功"); + System.out.println("✓ SSLSocketFactory创建成功"); + + // 检查系统属性 + System.out.println("\n系统属性检查:"); + System.out.println("jdk.tls.client.cipherSuites: " + System.getProperty("jdk.tls.client.cipherSuites")); + System.out.println("jdk.tls.client.protocols: " + System.getProperty("jdk.tls.client.protocols")); + System.out.println("https.protocols: " + System.getProperty("https.protocols")); + System.out.println("jdk.tls.disabledAlgorithms: " + System.getProperty("jdk.tls.disabledAlgorithms")); + + // 检查SQL Server连接属性 + System.out.println("\nSQL Server连接属性:"); + System.out.println("encrypt: " + System.getProperty("com.microsoft.sqlserver.jdbc.SQLServerConnection.encrypt")); + System.out.println("trustServerCertificate: " + System.getProperty("com.microsoft.sqlserver.jdbc.SQLServerConnection.trustServerCertificate")); + + System.out.println("\n✓ SSL配置测试完成"); + + } catch (Exception e) { + System.err.println("✗ SSL配置测试失败: " + e.getMessage()); + e.printStackTrace(); + } + } + + public static void listCipherSuites() { + System.out.println("=== 支持的密码套件 ==="); + + try { + SSLContext sslContext = SSLContext.getInstance("TLS"); + sslContext.init(null, null, null); + SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); + + String[] defaultCipherSuites = sslSocketFactory.getDefaultCipherSuites(); + String[] supportedCipherSuites = sslSocketFactory.getSupportedCipherSuites(); + + System.out.println("默认密码套件:"); + for (String cipher : defaultCipherSuites) { + if (!cipher.startsWith("TLS_DHE_")) { + System.out.println(" ✓ " + cipher); + } else { + System.out.println(" ✗ " + cipher + " (已禁用)"); + } + } + + System.out.println("\n支持的密码套件:"); + for (String cipher : supportedCipherSuites) { + if (!cipher.startsWith("TLS_DHE_")) { + System.out.println(" ✓ " + cipher); + } else { + System.out.println(" ✗ " + cipher + " (已禁用)"); + } + } + + } catch (Exception e) { + System.err.println("获取密码套件失败: " + e.getMessage()); + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 87656f1..ff5b76f 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -6,21 +6,53 @@ server: spring: application: name: fuquanapi + main: + allow-bean-definition-overriding: true datasource: - url: jdbc:sqlserver://112.33.47.173:6789;SelectMethod=cursor;rewriteBatchedStatements=true;DatabaseName=ERPPlatForm2025_FQ_JK;encrypt=false;trustServerCertificate=true - username: PlatForm_FuQ - password: p|Rc9fZza[@XR-4 - driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver + # SQL Server数据源配置 + sqlserver: + # 西宁火车煤 - 备用配置 +# url: jdbc:sqlserver://192.168.35.216:1433;SelectMethod=cursor;rewriteBatchedStatements=true;DatabaseName=WY_DATAMANAGE;encrypt=false;trustServerCertificate=true +# username: sa +# password: sa +# driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver + url: jdbc:sqlserver://112.33.47.173:6789;SelectMethod=cursor;rewriteBatchedStatements=true;DatabaseName=WY_DATAMANAGE20250731;encrypt=false;trustServerCertificate=true + username: admin + password: admin@Erp2021 + driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver + # 连接池配置 + hikari: + maximum-pool-size: 10 + minimum-idle: 5 + connection-timeout: 30000 + idle-timeout: 600000 + max-lifetime: 1800000 + + # PostgreSQL数据源配置 + postgresql: + url: jdbc:postgresql://112.33.111.160:5432/auseft_web_stage + username: postgres + password: Auseft@2025qwer + driver-class-name: org.postgresql.Driver + # 连接池配置 + hikari: + maximum-pool-size: 10 + minimum-idle: 5 + connection-timeout: 30000 + idle-timeout: 600000 + max-lifetime: 1800000 jpa: hibernate: ddl-auto: none show-sql: true properties: hibernate: - dialect: org.hibernate.dialect.SQLServer2012Dialect + dialect: org.hibernate.dialect.SQLServer2008Dialect format_sql: true physical_naming_strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl use_sql_comments: true + # 禁用默认数据源自动配置 + open-in-view: false jackson: date-format: yyyy-MM-dd HH:mm:ss time-zone: GMT+8 @@ -40,3 +72,5 @@ logging: com.example.webapi: DEBUG pattern: console: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n" + +# Swagger配置 - Swagger2不需要额外配置