diff --git a/pom.xml b/pom.xml index 4f4c084..5ab03f3 100644 --- a/pom.xml +++ b/pom.xml @@ -133,6 +133,11 @@ spring-boot-starter-tomcat provided + + + + + com.fasterxml.jackson.core jackson-databind @@ -291,7 +296,6 @@ easyexcel 3.1.1 - diff --git a/src/main/java/com/glxp/udi/ApiAdminApplication.java b/src/main/java/com/glxp/udi/ApiAdminApplication.java index 0d312c2..404203a 100644 --- a/src/main/java/com/glxp/udi/ApiAdminApplication.java +++ b/src/main/java/com/glxp/udi/ApiAdminApplication.java @@ -2,22 +2,17 @@ package com.glxp.udi; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import org.springframework.context.annotation.ComponentScan; import org.springframework.transaction.annotation.EnableTransactionManagement; @EnableTransactionManagement @SpringBootApplication -public class ApiAdminApplication extends SpringBootServletInitializer { +@ComponentScan +public class ApiAdminApplication { public static void main(String[] args) { SpringApplication.run(ApiAdminApplication.class, args); } - @Override - protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { - return builder.sources(ApiAdminApplication.class); - } - } diff --git a/src/main/java/com/glxp/udi/admin/common/enums/ResultEnum.java b/src/main/java/com/glxp/udi/admin/common/enums/ResultEnum.java index ce1f8d7..0d03c00 100644 --- a/src/main/java/com/glxp/udi/admin/common/enums/ResultEnum.java +++ b/src/main/java/com/glxp/udi/admin/common/enums/ResultEnum.java @@ -8,7 +8,7 @@ import lombok.Getter; @Getter public enum ResultEnum { - SUCCESS(0, "success"), + SUCCESS(20000, "success"), NOT_NETWORK(1, "系统繁忙,请稍后再试。"), LOGIN_VERIFY_FALL(2, "登录失效"), PARAM_VERIFY_FALL(3, "参数验证错误"), diff --git a/src/main/java/com/glxp/udi/admin/common/res/BaseResponse.java b/src/main/java/com/glxp/udi/admin/common/res/BaseResponse.java index 10b5857..8af7bcb 100644 --- a/src/main/java/com/glxp/udi/admin/common/res/BaseResponse.java +++ b/src/main/java/com/glxp/udi/admin/common/res/BaseResponse.java @@ -1,5 +1,6 @@ package com.glxp.udi.admin.common.res; +import com.glxp.udi.admin.common.enums.ResultEnum; import lombok.Data; /** @@ -11,7 +12,7 @@ import lombok.Data; public class BaseResponse { public boolean success() { - return this.code.equals(20000); + return this.code.equals(ResultEnum.SUCCESS.getCode()); } private Integer code; diff --git a/src/main/java/com/glxp/udi/admin/common/util/ResultVOUtils.java b/src/main/java/com/glxp/udi/admin/common/util/ResultVOUtils.java index bf7173e..3863388 100644 --- a/src/main/java/com/glxp/udi/admin/common/util/ResultVOUtils.java +++ b/src/main/java/com/glxp/udi/admin/common/util/ResultVOUtils.java @@ -19,7 +19,7 @@ public class ResultVOUtils { */ public static BaseResponse success(Object data) { BaseResponse baseResponse = new BaseResponse<>(); - baseResponse.setCode(20000); + baseResponse.setCode(ResultEnum.SUCCESS.getCode()); baseResponse.setMessage("success"); baseResponse.setData(data); return baseResponse; diff --git a/src/main/java/com/glxp/udi/admin/config/MybatisPlusConfig.java b/src/main/java/com/glxp/udi/admin/config/MybatisPlusConfig.java index 37e3661..b306dc5 100644 --- a/src/main/java/com/glxp/udi/admin/config/MybatisPlusConfig.java +++ b/src/main/java/com/glxp/udi/admin/config/MybatisPlusConfig.java @@ -1,6 +1,7 @@ package com.glxp.udi.admin.config; import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; import org.mybatis.spring.annotation.MapperScan; import org.springframework.context.annotation.Bean; @@ -19,6 +20,7 @@ public class MybatisPlusConfig { MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); // 分页插件 interceptor.addInnerInterceptor(paginationInnerInterceptor()); + interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor()); return interceptor; } diff --git a/src/main/java/com/glxp/udi/admin/config/SwaggerConfig.java b/src/main/java/com/glxp/udi/admin/config/SwaggerConfig.java index 5617619..04e5d25 100644 --- a/src/main/java/com/glxp/udi/admin/config/SwaggerConfig.java +++ b/src/main/java/com/glxp/udi/admin/config/SwaggerConfig.java @@ -1,33 +1,33 @@ -package com.glxp.udi.admin.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import springfox.documentation.builders.ApiInfoBuilder; -import springfox.documentation.builders.PathSelectors; -import springfox.documentation.builders.RequestHandlerSelectors; -import springfox.documentation.spi.DocumentationType; -import springfox.documentation.spring.web.plugins.Docket; -import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc; - -@Profile({"test", "dev"}) -@Configuration -@EnableSwagger2WebMvc -public class SwaggerConfig { - - @Bean(value = "defaultApi2") - public Docket defaultApi2() { - return new Docket(DocumentationType.SWAGGER_2) - .apiInfo(new ApiInfoBuilder() - .title("UDIMS") - .description("接口文档") - .version("1.0") - .build()) - .select() - //这里指定Controller扫描包路径 - .apis(RequestHandlerSelectors.basePackage("com.glxp.udi.admin.controller")) - .paths(PathSelectors.any()) - .build(); - } - -} +//package com.glxp.udi.admin.config; +// +//import org.springframework.context.annotation.Bean; +//import org.springframework.context.annotation.Configuration; +//import org.springframework.context.annotation.Profile; +//import springfox.documentation.builders.ApiInfoBuilder; +//import springfox.documentation.builders.PathSelectors; +//import springfox.documentation.builders.RequestHandlerSelectors; +//import springfox.documentation.spi.DocumentationType; +//import springfox.documentation.spring.web.plugins.Docket; +//import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc; +// +//@Profile({"test", "dev"}) +//@Configuration +//@EnableSwagger2WebMvc +//public class SwaggerConfig { +// +// @Bean(value = "defaultApi2") +// public Docket defaultApi2() { +// return new Docket(DocumentationType.SWAGGER_2) +// .apiInfo(new ApiInfoBuilder() +// .title("UDIMS") +// .description("接口文档") +// .version("1.0") +// .build()) +// .select() +// //这里指定Controller扫描包路径 +// .apis(RequestHandlerSelectors.basePackage("com.glxp.udi.admin.controller")) +// .paths(PathSelectors.any()) +// .build(); +// } +// +//} diff --git a/src/main/java/com/glxp/udi/admin/controller/basic/BussinessTypeController.java b/src/main/java/com/glxp/udi/admin/controller/basic/BussinessTypeController.java index a84b685..23a44a4 100644 --- a/src/main/java/com/glxp/udi/admin/controller/basic/BussinessTypeController.java +++ b/src/main/java/com/glxp/udi/admin/controller/basic/BussinessTypeController.java @@ -135,7 +135,7 @@ public class BussinessTypeController { //校验单据是否重名 BaseResponse verifyResult = bussinessTypeService.verify(bussinessTypeEntity); - if (!verifyResult.getCode().equals(20000)) { + if (!verifyResult.getCode().equals(ResultEnum.SUCCESS.getCode())) { return verifyResult; } diff --git a/src/main/java/com/glxp/udi/admin/controller/info/PlatformController.java b/src/main/java/com/glxp/udi/admin/controller/info/PlatformController.java index e87b604..98aec8d 100644 --- a/src/main/java/com/glxp/udi/admin/controller/info/PlatformController.java +++ b/src/main/java/com/glxp/udi/admin/controller/info/PlatformController.java @@ -99,7 +99,7 @@ public class PlatformController { String result = restTemplate.postForObject(url, request, String.class, map); log.error(result); Map object = JSON.parseObject(result, Map.class); - if (!String.valueOf(object.get("code")).equals("20000")) { + if (!String.valueOf(object.get("code")).equals(ResultEnum.SUCCESS.getCode().toString())) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, String.valueOf(object.get("message"))); } return ResultVOUtils.success(); diff --git a/src/main/java/com/glxp/udi/admin/controller/inout/OrderController.java b/src/main/java/com/glxp/udi/admin/controller/inout/OrderController.java index 56ad96f..6e8f94e 100644 --- a/src/main/java/com/glxp/udi/admin/controller/inout/OrderController.java +++ b/src/main/java/com/glxp/udi/admin/controller/inout/OrderController.java @@ -375,7 +375,7 @@ public class OrderController { BaseResponse baseResponse = JSONObject.parseObject(response, new TypeReference() { }); - if (baseResponse.getCode() == 20000) { + if (baseResponse.getCode() == ResultEnum.SUCCESS.getCode()) { orderEntity.setUploadStatus("1"); orderService.updateOrder(orderEntity); return baseResponse; diff --git a/src/main/java/com/glxp/udi/admin/handler/GlobalExceptionHandler.java b/src/main/java/com/glxp/udi/admin/handler/GlobalExceptionHandler.java index ad83b1b..0abb541 100644 --- a/src/main/java/com/glxp/udi/admin/handler/GlobalExceptionHandler.java +++ b/src/main/java/com/glxp/udi/admin/handler/GlobalExceptionHandler.java @@ -1,5 +1,6 @@ package com.glxp.udi.admin.handler; +import cn.hutool.core.util.StrUtil; import com.glxp.udi.admin.common.enums.ResultEnum; import com.glxp.udi.admin.common.util.ResultVOUtils; import com.glxp.udi.admin.exception.JsonException; @@ -25,8 +26,9 @@ public class GlobalExceptionHandler { @ExceptionHandler(value = RuntimeException.class) public com.glxp.udi.admin.common.res.BaseResponse handlerRuntimeException(RuntimeException e) { log.error(e.getMessage(), e); + String errorMsg = StrUtil.isBlank(e.getMessage()) ? ResultEnum.NOT_NETWORK.getMessage() : e.getMessage(); // 返回对应的错误信息 - return ResultVOUtils.error(ResultEnum.NOT_NETWORK); + return ResultVOUtils.error(ResultEnum.NOT_NETWORK, errorMsg); } } diff --git a/src/main/java/com/glxp/udi/admin/service/info/PlatformService.java b/src/main/java/com/glxp/udi/admin/service/info/PlatformService.java index ab0c95a..84e3a00 100644 --- a/src/main/java/com/glxp/udi/admin/service/info/PlatformService.java +++ b/src/main/java/com/glxp/udi/admin/service/info/PlatformService.java @@ -138,7 +138,7 @@ public class PlatformService { Map paramMap = new HashMap<>(); paramMap.put("invSubCode", invSubCode); String resp = HttpClient.mipsGet(host + "/udiwms/bussinessType/udimsFilter", paramMap); - if (StrUtil.isNotBlank(resp) && resp.contains("20000")) { + if (StrUtil.isNotBlank(resp) && resp.contains(ResultEnum.SUCCESS.getCode().toString())) { return JSON.parseObject(resp, BaseResponse.class); } else { log.error("获取自助平台单据类型异常"); @@ -158,7 +158,7 @@ public class PlatformService { log.info("拉取自助平台仓库数据:" + url); String resp = HttpUtil.get(url); log.info("拉取结果:" + resp); - if (StrUtil.isNotBlank(resp) && resp.contains("20000")) { + if (StrUtil.isNotBlank(resp) && resp.contains(ResultEnum.SUCCESS.getCode().toString())) { try { return JSON.parseObject(resp, BaseResponse.class); } catch (Exception e) { @@ -182,7 +182,7 @@ public class PlatformService { Map paramMap = new HashMap<>(); paramMap.put("invCode", invCode); String resp = HttpClient.mipsGet(host + "/spms/sub/inv/warehouse/getSubInvForUdims", paramMap); - if (StrUtil.isNotBlank(resp) && resp.contains("20000")) { + if (StrUtil.isNotBlank(resp) && resp.contains(ResultEnum.SUCCESS.getCode().toString())) { return JSON.parseObject(resp, BaseResponse.class); } else { log.error("获取自助平台分库失败"); @@ -202,7 +202,7 @@ public class PlatformService { if (StrUtil.isNotBlank(response)) { try { BaseResponse result = JSONUtil.toBean(response, BaseResponse.class); - if (result.getCode() == 20000) { + if (result.getCode() == ResultEnum.SUCCESS.getCode()) { return ResultVOUtils.success(); } return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL); diff --git a/src/main/java/com/glxp/udi/admin/thread/JaspaperService.java b/src/main/java/com/glxp/udi/admin/thread/JaspaperService.java index ef7ad87..115223f 100644 --- a/src/main/java/com/glxp/udi/admin/thread/JaspaperService.java +++ b/src/main/java/com/glxp/udi/admin/thread/JaspaperService.java @@ -33,10 +33,7 @@ public class JaspaperService { try { JasperUtils.jasperReportToFile(stockPrintTempEntity.getFilePath(), data, resource); stockPrintTempEntity.setStatus(1); - } catch (IOException e) { - stockPrintTempEntity.setStatus(2); - log.error(e.getMessage(), e); - } catch (JRException e) { + } catch (IOException | JRException e) { stockPrintTempEntity.setStatus(2); log.error(e.getMessage(), e); } diff --git a/src/main/java/com/glxp/udi/admin/thread/SubmitOrderToSpmsTask.java b/src/main/java/com/glxp/udi/admin/thread/SubmitOrderToSpmsTask.java index cf7c791..828de44 100644 --- a/src/main/java/com/glxp/udi/admin/thread/SubmitOrderToSpmsTask.java +++ b/src/main/java/com/glxp/udi/admin/thread/SubmitOrderToSpmsTask.java @@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.json.JSONUtil; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; +import com.glxp.udi.admin.common.enums.ResultEnum; import com.glxp.udi.admin.common.res.BaseResponse; import com.glxp.udi.admin.constant.SystemParamConstant; import com.glxp.udi.admin.dao.info.ScheduledDao; @@ -143,7 +144,7 @@ public class SubmitOrderToSpmsTask implements SchedulingConfigurer { BaseResponse baseResponse = JSONObject.parseObject(response, new TypeReference() { }); - if (baseResponse.getCode() == 20000) { + if (baseResponse.getCode() == ResultEnum.SUCCESS.getCode()) { log.info("自动上传单据成功," + unitMaintainEntity.getName() + "上传单据数量为 " + orderEntities.size()); for (OrderEntity orderEntity : orderEntities) { log.info("修改单号为:{} 的上传状态", orderEntity.getOrderId()); diff --git a/src/main/java/com/glxp/udi/admin/thread/SupplementOrderTask.java b/src/main/java/com/glxp/udi/admin/thread/SupplementOrderTask.java index 5c47924..a1249f3 100644 --- a/src/main/java/com/glxp/udi/admin/thread/SupplementOrderTask.java +++ b/src/main/java/com/glxp/udi/admin/thread/SupplementOrderTask.java @@ -1,6 +1,7 @@ package com.glxp.udi.admin.thread; import cn.hutool.core.collection.CollUtil; +import com.glxp.udi.admin.common.enums.ResultEnum; import com.glxp.udi.admin.common.res.BaseResponse; import com.glxp.udi.admin.constant.SystemParamConstant; import com.glxp.udi.admin.dao.info.ScheduledDao; @@ -58,7 +59,7 @@ public class SupplementOrderTask implements SchedulingConfigurer { if (CollUtil.isNotEmpty(orderEntities)) { orderEntities.forEach(orderEntity -> { BaseResponse baseResponse = orderService.supplementOrder(orderEntity); - if (baseResponse.getCode() == 20000) { + if (baseResponse.getCode() == ResultEnum.SUCCESS.getCode()) { counter.addAndGet(1); } }); diff --git a/src/main/java/com/glxp/udi/admin/util/RedisUtil.java b/src/main/java/com/glxp/udi/admin/util/RedisUtil.java index cf0a448..d1b967e 100644 --- a/src/main/java/com/glxp/udi/admin/util/RedisUtil.java +++ b/src/main/java/com/glxp/udi/admin/util/RedisUtil.java @@ -2,6 +2,7 @@ package com.glxp.udi.admin.util; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; @@ -574,4 +575,19 @@ public class RedisUtil { } } + /** + * 不存在key则缓存放入并设置时间 + * + * @param key 键 + * @param value 值 + * @param time 过期时间 (秒) + * @return boolean true为set成功,false为key已存在set失败 + */ + public boolean setIfAbsent(String key, Object value, long time) { + if (StrUtil.isEmpty(key)) { + return false; + } + return Boolean.TRUE.equals(redisTemplate.opsForValue().setIfAbsent(key, value, time, TimeUnit.SECONDS)); + } + } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index f8b0de8..a195c69 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -3,18 +3,14 @@ spring: pathmatch: matching-strategy: ant_path_matcher datasource: - url: jdbc:mysql://127.0.0.1:3306/udims_cg?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true + url: jdbc:mysql://127.0.0.1:3333/udims_cg?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true username: root password: 123456 - data: - mongodb: - uri: mongodb://root:123456@127.0.0.1:27017/udims - redis: database: 11 host: 127.0.0.1 - port: 6379 - password: + port: 6377 + password: 123456 jedis: pool: max-active: 8 @@ -23,17 +19,8 @@ spring: min-idle: 0 logging: level: - org: - springframework: - data: - mongodb: - core: - MongoTemplate: debug - com: - glxp: - udi: - admin: - dao: debug + org.springframework.data.mongodb.core.MongoTemplate: debug + com.glxp.udi.admin.dao: debug #mips服务地址 UDIC_MIPSDOWNLOAD_URL: http://127.0.0.1:8080/UDIC_MIPSDL_Server @@ -41,7 +28,7 @@ UCLOD_SERVER_URL: http://127.0.0.1:9997 UDI_SERVER_URL: https://www.udims.com/UDI_DL_Server_test COOR_UPLOAD_ORDER: http://127.0.0.1:9987/udi/upload -#同步库接口调用地址相关信息 https://www.udims.com/UDI_DL_Server_test +#同步库接口调用地址相关信息 https://www.udims.com/UDI_DL_Server_test UDI_SERVER: url: https://www.udims.com/UDI_DL_Server_test connectTimeout: 2000 diff --git a/src/main/resources/application-pro.yml b/src/main/resources/application-pro.yml index c0d2fb3..a92a039 100644 --- a/src/main/resources/application-pro.yml +++ b/src/main/resources/application-pro.yml @@ -17,19 +17,11 @@ spring: max-idle: 8 min-idle: 0 + logging: level: - org: - springframework: - data: - mongodb: - core: - MongoTemplate: debug - com: - glxp: - udi: - admin: - dao: debug + org.springframework.data.mongodb.core.MongoTemplate: debug + com.glxp.udi.admin.dao: debug #mips服务地址 UDIC_MIPSDOWNLOAD_URL: http://127.0.0.1:8080/UDIC_MIPSDL_Server diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index f0d00c9..5259977 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -21,17 +21,8 @@ spring: min-idle: 0 logging: level: - org: - springframework: - data: - mongodb: - core: - MongoTemplate: debug - com: - glxp: - udi: - admin: - dao: debug + org.springframework.data.mongodb.core.MongoTemplate: debug + com.glxp.udi.admin.dao: debug #mips服务地址 UDIC_MIPSDOWNLOAD_URL: http://127.0.0.1:8080/UDIC_MIPSDL_Server diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 09f529f..56c202a 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -8,7 +8,8 @@ spring: multipart: max-file-size: 100MB max-request-size: 100MB - + main: + allow-bean-definition-overriding: true mybatis-plus: mapperPackage: com.glxp.udi.admin.dao.* @@ -16,10 +17,12 @@ mybatis-plus: type-aliases-package: com.glxp.udi.admin.entity check-config-location: false configuration: - map-underscore-to-camel-case: false #不使用驼峰命名 + #不使用驼峰命名 + map-underscore-to-camel-case: false auto-mapping-unknown-column-behavior: none auto-mapping-behavior: partial log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl - use-column-label: true # 是否可以使用列别名 + #是否可以使用列别名 + use-column-label: true global-config: banner: true diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml index 0596f06..770b296 100644 --- a/src/main/resources/logback-spring.xml +++ b/src/main/resources/logback-spring.xml @@ -1,7 +1,7 @@ logback - +