Showing
23 changed files
with
1522 additions
and
8 deletions
assembly.xml
0 → 100644
| 1 | +<assembly | ||
| 2 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 3 | + xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" | ||
| 4 | + xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"> | ||
| 5 | + <id>${project.version}</id> | ||
| 6 | + <formats> | ||
| 7 | + <format>dir</format> | ||
| 8 | + <format>tar.gz</format> | ||
| 9 | + </formats> | ||
| 10 | + <includeBaseDirectory>false</includeBaseDirectory> | ||
| 11 | + <baseDirectory>${build.directory}</baseDirectory> | ||
| 12 | + | ||
| 13 | + <fileSets> | ||
| 14 | +<!-- <fileSet>--> | ||
| 15 | +<!-- <directory>conf/</directory>--> | ||
| 16 | +<!-- <outputDirectory>${project.artifactId}/conf</outputDirectory>--> | ||
| 17 | +<!-- </fileSet>--> | ||
| 18 | + <fileSet> | ||
| 19 | + <directory>db/</directory> | ||
| 20 | + <outputDirectory>${project.artifactId}/db</outputDirectory> | ||
| 21 | + </fileSet> | ||
| 22 | + <fileSet> | ||
| 23 | + <directory>${build.directory}</directory> | ||
| 24 | + <includes> | ||
| 25 | + <include>*.jar</include> | ||
| 26 | + </includes> | ||
| 27 | + <excludes> | ||
| 28 | + <exclude>*sources.jar</exclude> | ||
| 29 | + </excludes> | ||
| 30 | + <outputDirectory>${project.artifactId}/lib</outputDirectory> | ||
| 31 | + </fileSet> | ||
| 32 | + <fileSet> | ||
| 33 | + <directory>bin/</directory> | ||
| 34 | + <outputDirectory>${project.artifactId}/bin</outputDirectory> | ||
| 35 | + <fileMode>754</fileMode> | ||
| 36 | + <lineEnding>unix</lineEnding> | ||
| 37 | + </fileSet> | ||
| 38 | + </fileSets> | ||
| 39 | +</assembly> |
bin/service.sh
0 → 100644
| 1 | +#!/bin/bash | ||
| 2 | +source /etc/profile | ||
| 3 | + | ||
| 4 | +BASE_HOME=/opt | ||
| 5 | +APP_NAME=crp-operation | ||
| 6 | +APP_HOME=${BASE_HOME}/${APP_NAME} | ||
| 7 | +APP_VERSION=1.0.0 | ||
| 8 | +SERVICE_NAME=${APP_NAME} | ||
| 9 | + | ||
| 10 | +LOG_HOME=${APP_HOME}/logs | ||
| 11 | +LOG_PATH=${LOG_HOME}/${APP_NAME} | ||
| 12 | +ENV_LIST=("default" "dev" "test" "prod") | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + | ||
| 16 | +SERVICE_LIB=${APP_HOME}/lib | ||
| 17 | +SERVICE_CONF=${APP_HOME}/conf | ||
| 18 | +SERVICE_RESOURCES=${APP_HOME}/resources | ||
| 19 | + | ||
| 20 | +if [[ -n "$2" ]]; then | ||
| 21 | + PROJECT_ENV=$2 | ||
| 22 | +else | ||
| 23 | + PROJECT_ENV="dev" | ||
| 24 | +fi | ||
| 25 | + | ||
| 26 | +safemkdir(){ | ||
| 27 | + if [[ ! -d $1 ]] ; then | ||
| 28 | + mkdir -p $1 | ||
| 29 | + fi | ||
| 30 | +} | ||
| 31 | + | ||
| 32 | +# Production config | ||
| 33 | +if [[ "$PROJECT_ENV" == "prod" ]]; then | ||
| 34 | + JAVA_OPTIONS="-server -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$LOG_PATH -Xms128M -Xmx256M -Xmn512M -XX:MetaspaceSize=256M -XX:MaxMetaspaceSize=256M -XX:+DisableExplicitGC -XX:SurvivorRatio=8 -XX:LargePageSizeInBytes=128M -XX:SoftRefLRUPolicyMSPerMB=0 " | ||
| 35 | +else | ||
| 36 | + JAVA_OPTIONS="-server -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$LOG_PATH -Xms128M -Xmx256M -Xmn128M -XX:MetaspaceSize=128M -XX:MaxMetaspaceSize=256M -XX:+DisableExplicitGC -XX:SurvivorRatio=8 -XX:LargePageSizeInBytes=128M -XX:SoftRefLRUPolicyMSPerMB=0" | ||
| 37 | +fi | ||
| 38 | + | ||
| 39 | +if [[ "$PROJECT_ENV" == "dev" || "$PROJECT_ENV" == "test" ]]; then | ||
| 40 | + JAVA_OPTIONS="-Xdebug -Xrunjdwp:transport=dt_socket,address=$REMOTE_PORT,server=y,suspend=n $JAVA_OPTIONS" | ||
| 41 | +fi | ||
| 42 | + | ||
| 43 | +JAVA_OPTIONS="-XX:ErrorFile=$LOG_PATH/hs_err_pid%p.log $JAVA_OPTIONS -Dspring.cloud.inetutils.ignored-interfaces=lo.* -Dspring.config.additional-location=$SERVICE_CONF/ -Dspring.profiles.active=$PROJECT_ENV -Dapp.name=$APP_NAME -Dlog.home=$LOG_HOME -Denv=$PROJECT_ENV -Djava.security.egd=file:/dev/./urandom" | ||
| 44 | + | ||
| 45 | +export CLASSPATH=${CLASSPATH}:${SERVICE_CONF}:${SERVICE_RESOURCES} | ||
| 46 | +export JAVA_OPTIONS | ||
| 47 | +export PID_FILE=${APP_HOME}/.pid/${APP_NAME}.pid | ||
| 48 | +dateFormat=$(date '+%Y-%m-%d') | ||
| 49 | + | ||
| 50 | +safemkdir ${APP_HOME}/.pid/ | ||
| 51 | +safemkdir ${LOG_PATH}/ | ||
| 52 | + | ||
| 53 | +ACCESS_LOG=${LOG_PATH}/${dateFormat}.info.log | ||
| 54 | +ERROR_LOG=${LOG_PATH}/${dateFormat}.error.log | ||
| 55 | + | ||
| 56 | +hint="Usage: start " | ||
| 57 | +hasEnv=0 | ||
| 58 | + | ||
| 59 | +checkEnvParam(){ | ||
| 60 | + for env_name in ${ENV_LIST[@]};do | ||
| 61 | + if [[ "${env_name}" == "$1" ]] ; then | ||
| 62 | + hasEnv=1 | ||
| 63 | + fi | ||
| 64 | + done | ||
| 65 | +} | ||
| 66 | + | ||
| 67 | +getUsageHint(){ | ||
| 68 | + for env_name in ${ENV_LIST[@]};do | ||
| 69 | + hint=${hint}${env_name}" or " | ||
| 70 | + done | ||
| 71 | + | ||
| 72 | + hint=${hint}"|stop|log|error" | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +checkEnvParam $2 | ||
| 76 | +getUsageHint | ||
| 77 | + | ||
| 78 | +started="#################################################################################\n | ||
| 79 | + Application [${APP_NAME}] for environment [${PROJECT_ENV}] Started At $(date) \n | ||
| 80 | + ##################################################################################\n" | ||
| 81 | + | ||
| 82 | +stopped="#################################################################################\n | ||
| 83 | + Application [${APP_NAME}] Stopped At $(date) \n | ||
| 84 | + ##################################################################################\n" | ||
| 85 | + | ||
| 86 | +if [[ "$1" == "start" ]]; then | ||
| 87 | + if [[ "${hasEnv}" == 0 ]]; then | ||
| 88 | + echo ${hint} | ||
| 89 | + exit 0 | ||
| 90 | + fi | ||
| 91 | + | ||
| 92 | + if [[ ! -f "$PID_FILE" ]]; then | ||
| 93 | + echo -e ${started} | tee -a ${ACCESS_LOG} | ||
| 94 | + nohup java ${JAVA_OPTIONS} ${SCOUNT_CONFIG} -jar ${APP_HOME}/lib/${APP_NAME}-${APP_VERSION}.jar 1>> ${ACCESS_LOG} 2>> ${ERROR_LOG} 2>&1 &echo $! > ${PID_FILE} | ||
| 95 | + | ||
| 96 | + sleep 10 | ||
| 97 | + tail -n 300 ${ACCESS_LOG} | ||
| 98 | + else | ||
| 99 | + echo "$APP_NAME service already started, please stop first and try again" | ||
| 100 | + fi | ||
| 101 | +elif [[ "$1" == "stop" ]]; then | ||
| 102 | + if [[ -f "$PID_FILE" ]]; then | ||
| 103 | + echo -e ${stopped} | tee -a ${ACCESS_LOG} | ||
| 104 | + cat ${PID_FILE} | xargs kill -9 | ||
| 105 | + rm ${PID_FILE} | ||
| 106 | + echo "$APP_NAME stop : [OK]" | ||
| 107 | + else | ||
| 108 | + echo "$APP_NAME service not started yet, please start first and try again" | ||
| 109 | + fi | ||
| 110 | +elif [[ "$1" == "log" ]] | ||
| 111 | + then if [[ "$2" == "error" ]] | ||
| 112 | + then | ||
| 113 | + tail -f ${ERROR_LOG} | ||
| 114 | + else | ||
| 115 | + tail -f ${ACCESS_LOG} | ||
| 116 | + fi | ||
| 117 | +elif [[ "$1" == "-v" ]]; then | ||
| 118 | + echo ${APP_VERSION} | ||
| 119 | +elif [[ "$1" == "status" ]]; then | ||
| 120 | + pid=`cat ${PID_FILE}` | ||
| 121 | + if [[ $? -eq 0 ]]; then | ||
| 122 | + p_status=`ps -p ${pid}` | ||
| 123 | + if [[ $? -eq 0 ]]; then | ||
| 124 | + echo "Application [${APP_NAME}] is running, pid : ${pid}." | ||
| 125 | + else | ||
| 126 | + echo "Application [${APP_NAME}] is not running." | ||
| 127 | + fi | ||
| 128 | + else | ||
| 129 | + echo "Application [${APP_NAME}] is not running." | ||
| 130 | + fi | ||
| 131 | +else | ||
| 132 | + echo ${hint} | ||
| 133 | +fi | ||
| 134 | + | ||
| 135 | + |
| @@ -6,7 +6,14 @@ | @@ -6,7 +6,14 @@ | ||
| 6 | 6 | ||
| 7 | <groupId>com.wondertek</groupId> | 7 | <groupId>com.wondertek</groupId> |
| 8 | <artifactId>crp-operation</artifactId> | 8 | <artifactId>crp-operation</artifactId> |
| 9 | - <version>1.0-SNAPSHOT</version> | 9 | + <version>1.0.0</version> |
| 10 | + | ||
| 11 | + <parent> | ||
| 12 | + <groupId>org.springframework.boot</groupId> | ||
| 13 | + <artifactId>spring-boot-starter-parent</artifactId> | ||
| 14 | + <version>3.3.3</version> | ||
| 15 | + <relativePath/> <!-- lookup parent from repository --> | ||
| 16 | + </parent> | ||
| 10 | 17 | ||
| 11 | <properties> | 18 | <properties> |
| 12 | <maven.compiler.source>17</maven.compiler.source> | 19 | <maven.compiler.source>17</maven.compiler.source> |
| @@ -14,4 +21,156 @@ | @@ -14,4 +21,156 @@ | ||
| 14 | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | 21 | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
| 15 | </properties> | 22 | </properties> |
| 16 | 23 | ||
| 24 | + | ||
| 25 | + | ||
| 26 | + <dependencies> | ||
| 27 | + | ||
| 28 | + <dependency> | ||
| 29 | + <groupId>org.springframework.boot</groupId> | ||
| 30 | + <artifactId>spring-boot-starter-web</artifactId> | ||
| 31 | + </dependency> | ||
| 32 | + | ||
| 33 | + <dependency> | ||
| 34 | + <groupId>mysql</groupId> | ||
| 35 | + <artifactId>mysql-connector-java</artifactId> | ||
| 36 | + <scope>runtime</scope> | ||
| 37 | + <version>8.0.26</version> | ||
| 38 | + </dependency> | ||
| 39 | + <dependency> | ||
| 40 | + <groupId>org.springframework.boot</groupId> | ||
| 41 | + <artifactId>spring-boot-starter-json</artifactId> | ||
| 42 | + </dependency> | ||
| 43 | + | ||
| 44 | + | ||
| 45 | + <dependency> | ||
| 46 | + <groupId>org.springframework.boot</groupId> | ||
| 47 | + <artifactId>spring-boot-configuration-processor</artifactId> | ||
| 48 | + <optional>true</optional> | ||
| 49 | + </dependency> | ||
| 50 | + | ||
| 51 | + <dependency> | ||
| 52 | + <groupId>org.projectlombok</groupId> | ||
| 53 | + <artifactId>lombok</artifactId> | ||
| 54 | + </dependency> | ||
| 55 | + | ||
| 56 | + | ||
| 57 | + <dependency> | ||
| 58 | + <groupId>com.baomidou</groupId> | ||
| 59 | + <artifactId>mybatis-plus-spring-boot3-starter</artifactId> | ||
| 60 | + <version>3.5.7</version> | ||
| 61 | + | ||
| 62 | + </dependency> | ||
| 63 | + | ||
| 64 | + | ||
| 65 | + | ||
| 66 | + | ||
| 67 | + | ||
| 68 | + | ||
| 69 | + <dependency> | ||
| 70 | + <groupId>com.alibaba</groupId> | ||
| 71 | + <artifactId>fastjson</artifactId> | ||
| 72 | + <version>1.2.47</version> | ||
| 73 | + </dependency> | ||
| 74 | + | ||
| 75 | + | ||
| 76 | + | ||
| 77 | + <dependency> | ||
| 78 | + <groupId>com.alibaba</groupId> | ||
| 79 | + <artifactId>druid</artifactId> | ||
| 80 | + <version>1.1.22</version> | ||
| 81 | + </dependency> | ||
| 82 | + | ||
| 83 | + <dependency> | ||
| 84 | + <groupId>com.alibaba</groupId> | ||
| 85 | + <artifactId>druid-spring-boot-starter</artifactId> | ||
| 86 | + <version>1.1.22</version> | ||
| 87 | + </dependency> | ||
| 88 | + | ||
| 89 | + | ||
| 90 | + | ||
| 91 | + | ||
| 92 | + <!--常用库依赖--> | ||
| 93 | + <dependency> | ||
| 94 | + <groupId>commons-codec</groupId> | ||
| 95 | + <artifactId>commons-codec</artifactId> | ||
| 96 | + </dependency> | ||
| 97 | + <dependency> | ||
| 98 | + <groupId>org.apache.commons</groupId> | ||
| 99 | + <artifactId>commons-lang3</artifactId> | ||
| 100 | + <version>3.6</version> | ||
| 101 | + </dependency> | ||
| 102 | + <dependency> | ||
| 103 | + <groupId>com.google.guava</groupId> | ||
| 104 | + <artifactId>guava</artifactId> | ||
| 105 | + <version>23.0</version> | ||
| 106 | + </dependency> | ||
| 107 | + | ||
| 108 | + | ||
| 109 | + | ||
| 110 | + <dependency> | ||
| 111 | + <groupId>ch.qos.logback</groupId> | ||
| 112 | + <artifactId>logback-classic</artifactId> | ||
| 113 | + <!-- <version>1.2.3</version>--> | ||
| 114 | + </dependency> | ||
| 115 | + | ||
| 116 | + | ||
| 117 | + | ||
| 118 | + <dependency> | ||
| 119 | + <groupId>org.codehaus.janino</groupId> | ||
| 120 | + <artifactId>janino</artifactId> | ||
| 121 | + </dependency> | ||
| 122 | + | ||
| 123 | + </dependencies> | ||
| 124 | + | ||
| 125 | + <build> | ||
| 126 | + <plugins> | ||
| 127 | + <plugin> | ||
| 128 | + <groupId>org.springframework.boot</groupId> | ||
| 129 | + <artifactId>spring-boot-maven-plugin</artifactId> | ||
| 130 | + <configuration> | ||
| 131 | + <excludes> | ||
| 132 | + <exclude> | ||
| 133 | + <groupId>org.projectlombok</groupId> | ||
| 134 | + <artifactId>lombok</artifactId> | ||
| 135 | + </exclude> | ||
| 136 | + </excludes> | ||
| 137 | + </configuration> | ||
| 138 | + </plugin> | ||
| 139 | + | ||
| 140 | + <plugin> | ||
| 141 | + <groupId>org.apache.maven.plugins</groupId> | ||
| 142 | + <artifactId>maven-assembly-plugin</artifactId> | ||
| 143 | + <configuration> | ||
| 144 | + <appendAssemblyId>false</appendAssemblyId> | ||
| 145 | + <descriptors> | ||
| 146 | + <descriptor>assembly.xml</descriptor> | ||
| 147 | + </descriptors> | ||
| 148 | + | ||
| 149 | + </configuration> | ||
| 150 | + <executions> | ||
| 151 | + <execution> | ||
| 152 | + <id>make-assembly</id> | ||
| 153 | + <phase>package</phase> | ||
| 154 | + <goals> | ||
| 155 | + <goal>single</goal> | ||
| 156 | + </goals> | ||
| 157 | + </execution> | ||
| 158 | + </executions> | ||
| 159 | + </plugin> | ||
| 160 | + | ||
| 161 | + <plugin> | ||
| 162 | + <groupId>org.apache.maven.plugins</groupId> | ||
| 163 | + <artifactId>maven-resources-plugin</artifactId> | ||
| 164 | + <version>3.2.0</version> | ||
| 165 | + <configuration> | ||
| 166 | + <nonFilteredFileExtensions> | ||
| 167 | + <nonFilteredFileExtension>db</nonFilteredFileExtension> | ||
| 168 | + </nonFilteredFileExtensions> | ||
| 169 | + </configuration> | ||
| 170 | + </plugin> | ||
| 171 | + | ||
| 172 | + | ||
| 173 | + </plugins> | ||
| 174 | + </build> | ||
| 175 | + | ||
| 17 | </project> | 176 | </project> |
| 1 | +package com.wondertek; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import org.mybatis.spring.annotation.MapperScan; | ||
| 5 | +import org.springframework.boot.SpringApplication; | ||
| 6 | +import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
| 7 | +import org.springframework.boot.web.servlet.ServletComponentScan; | ||
| 8 | + | ||
| 9 | +@ServletComponentScan | ||
| 10 | +@MapperScan({"com.wondertek.mapper"}) | ||
| 11 | +@SpringBootApplication(scanBasePackages = {"com.wondertek"}) | ||
| 12 | +public class CrpOperationApplication { | ||
| 13 | + public static void main(String[] args) { | ||
| 14 | + SpringApplication.run(CrpOperationApplication.class, args); | ||
| 15 | + } | ||
| 16 | +} |
| 1 | + | ||
| 2 | + | ||
| 3 | +package com.wondertek.config; | ||
| 4 | + | ||
| 5 | + | ||
| 6 | + | ||
| 7 | + | ||
| 8 | +import lombok.extern.slf4j.Slf4j; | ||
| 9 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
| 10 | +import org.springframework.context.annotation.Bean; | ||
| 11 | +import org.springframework.context.annotation.Configuration; | ||
| 12 | +import org.springframework.web.cors.CorsConfiguration; | ||
| 13 | +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; | ||
| 14 | +import org.springframework.web.filter.CorsFilter; | ||
| 15 | +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
| 16 | + | ||
| 17 | +/** | ||
| 18 | + * 跨域配置 | ||
| 19 | + */ | ||
| 20 | +@Slf4j | ||
| 21 | +@Configuration | ||
| 22 | +@ConditionalOnProperty(value = {"light-blog.cors.enable"}, matchIfMissing = true) | ||
| 23 | +public class CorsConfig implements WebMvcConfigurer { | ||
| 24 | + | ||
| 25 | + | ||
| 26 | + @Bean | ||
| 27 | + public CorsFilter corsFilter() { | ||
| 28 | + CorsConfiguration config = new CorsConfiguration(); | ||
| 29 | + // 允许所有域名进行跨域调用 | ||
| 30 | + config.addAllowedOriginPattern("*"); | ||
| 31 | + // 允许任何请求头 | ||
| 32 | + config.addAllowedHeader("*"); | ||
| 33 | + // 允许任何方法(POST、GET等) | ||
| 34 | + config.addAllowedMethod("*"); | ||
| 35 | + // 允许携带凭证 | ||
| 36 | + config.setAllowCredentials(true); | ||
| 37 | + | ||
| 38 | + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); | ||
| 39 | + // 对所有接口都有效 | ||
| 40 | + source.registerCorsConfiguration("/**", config); | ||
| 41 | + | ||
| 42 | + return new CorsFilter(source); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + | ||
| 46 | + | ||
| 47 | +} |
| 1 | +/** | ||
| 2 | + * Copyright (c) 2018 人人开源 All rights reserved. | ||
| 3 | + * | ||
| 4 | + * https://www.renren.io | ||
| 5 | + * | ||
| 6 | + * 版权所有,侵权必究! | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +package com.wondertek.config; | ||
| 10 | + | ||
| 11 | +import com.baomidou.mybatisplus.annotation.DbType; | ||
| 12 | +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; | ||
| 13 | +import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor; | ||
| 14 | +import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor; | ||
| 15 | +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; | ||
| 16 | +import org.springframework.context.annotation.Bean; | ||
| 17 | +import org.springframework.context.annotation.Configuration; | ||
| 18 | + | ||
| 19 | +/** | ||
| 20 | + * mybatis-plus配置 | ||
| 21 | + * | ||
| 22 | + * @author Mark sunlightcs@gmail.com | ||
| 23 | + */ | ||
| 24 | +@Configuration | ||
| 25 | +public class MybatisPlusConfig { | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * 配置分页等 | ||
| 29 | + */ | ||
| 30 | + @Bean | ||
| 31 | + public MybatisPlusInterceptor mybatisPlusInterceptor() { | ||
| 32 | + MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor(); | ||
| 33 | + // 分页插件 | ||
| 34 | + mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); | ||
| 35 | + // 乐观锁 | ||
| 36 | + mybatisPlusInterceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor()); | ||
| 37 | + // 防止全表更新与删除 | ||
| 38 | + mybatisPlusInterceptor.addInnerInterceptor(new BlockAttackInnerInterceptor()); | ||
| 39 | + | ||
| 40 | + return mybatisPlusInterceptor; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | +} |
| 1 | +/** | ||
| 2 | + * Copyright (c) 2018 人人开源 All rights reserved. | ||
| 3 | + * <p> | ||
| 4 | + * https://www.renren.io | ||
| 5 | + * <p> | ||
| 6 | + * 版权所有,侵权必究! | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +package com.wondertek.config; | ||
| 10 | + | ||
| 11 | +import com.fasterxml.jackson.annotation.JsonAutoDetect; | ||
| 12 | +import com.fasterxml.jackson.annotation.PropertyAccessor; | ||
| 13 | +import com.fasterxml.jackson.databind.DeserializationFeature; | ||
| 14 | +import com.fasterxml.jackson.databind.ObjectMapper; | ||
| 15 | +import com.fasterxml.jackson.databind.module.SimpleModule; | ||
| 16 | +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; | ||
| 17 | +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
| 18 | +import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer; | ||
| 19 | +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; | ||
| 20 | +import com.wondertek.util.DateUtil; | ||
| 21 | +import org.springframework.context.annotation.Bean; | ||
| 22 | +import org.springframework.context.annotation.Configuration; | ||
| 23 | +import org.springframework.http.converter.ByteArrayHttpMessageConverter; | ||
| 24 | +import org.springframework.http.converter.HttpMessageConverter; | ||
| 25 | +import org.springframework.http.converter.ResourceHttpMessageConverter; | ||
| 26 | +import org.springframework.http.converter.StringHttpMessageConverter; | ||
| 27 | +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; | ||
| 28 | +import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter; | ||
| 29 | +import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; | ||
| 30 | +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
| 31 | + | ||
| 32 | +import java.text.SimpleDateFormat; | ||
| 33 | +import java.time.LocalDateTime; | ||
| 34 | +import java.time.format.DateTimeFormatter; | ||
| 35 | +import java.util.List; | ||
| 36 | +import java.util.TimeZone; | ||
| 37 | + | ||
| 38 | +/** | ||
| 39 | + * MVC配置 | ||
| 40 | + * | ||
| 41 | + * @author Mark sunlightcs@gmail.com | ||
| 42 | + */ | ||
| 43 | +@Configuration | ||
| 44 | +public class WebMvcConfig extends WebMvcConfigurationSupport { | ||
| 45 | + | ||
| 46 | + | ||
| 47 | + @Override | ||
| 48 | + public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { | ||
| 49 | + converters.add(new ByteArrayHttpMessageConverter()); | ||
| 50 | + converters.add(new StringHttpMessageConverter()); | ||
| 51 | + converters.add(new ResourceHttpMessageConverter()); | ||
| 52 | + converters.add(new AllEncompassingFormHttpMessageConverter()); | ||
| 53 | + converters.add(new StringHttpMessageConverter()); | ||
| 54 | + converters.add(jackson2HttpMessageConverter()); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + @Bean | ||
| 58 | + public MappingJackson2HttpMessageConverter jackson2HttpMessageConverter() { | ||
| 59 | + MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); | ||
| 60 | + ObjectMapper mapper = new ObjectMapper(); | ||
| 61 | + | ||
| 62 | + //日期格式转换 | ||
| 63 | + // 解决jackson2无法反序列化LocalDateTime的问题 | ||
| 64 | + JavaTimeModule javaTimeModule = new JavaTimeModule(); | ||
| 65 | + javaTimeModule.addSerializer(LocalDateTime.class, | ||
| 66 | + new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); | ||
| 67 | + javaTimeModule.addDeserializer(LocalDateTime.class, | ||
| 68 | + new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); | ||
| 69 | + mapper.registerModule(javaTimeModule); | ||
| 70 | + | ||
| 71 | + mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); | ||
| 72 | + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | ||
| 73 | + | ||
| 74 | + //Long类型转String类型 | ||
| 75 | +// SimpleModule simpleModule = new SimpleModule(); | ||
| 76 | +// simpleModule.addSerializer(Long.class, ToStringSerializer.instance); | ||
| 77 | +// simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); | ||
| 78 | +// mapper.registerModule(simpleModule); | ||
| 79 | + | ||
| 80 | + converter.setObjectMapper(mapper); | ||
| 81 | + return converter; | ||
| 82 | + } | ||
| 83 | +} |
| 1 | +package com.wondertek.controller; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import com.wondertek.dto.CrpBackupMaterialDto; | ||
| 5 | +import com.wondertek.service.CrpBackupMaterialService; | ||
| 6 | +import com.wondertek.util.PageBean; | ||
| 7 | +import jakarta.annotation.Resource; | ||
| 8 | +import lombok.extern.slf4j.Slf4j; | ||
| 9 | +import org.springframework.web.bind.annotation.GetMapping; | ||
| 10 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 11 | +import org.springframework.web.bind.annotation.RestController; | ||
| 12 | + | ||
| 13 | +@Slf4j | ||
| 14 | +@RestController | ||
| 15 | +@RequestMapping("bkMaterial") | ||
| 16 | +public class CrpBackupMaterialController { | ||
| 17 | + @Resource | ||
| 18 | + private CrpBackupMaterialService crpBackupMaterialService; | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + @GetMapping("queryPage") | ||
| 22 | + PageBean queryPage(CrpBackupMaterialDto crpBackupMaterialDto){ | ||
| 23 | + return crpBackupMaterialService.queryPage(crpBackupMaterialDto); | ||
| 24 | + } | ||
| 25 | +} |
| 1 | +package com.wondertek.entity; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import com.baomidou.mybatisplus.annotation.TableId; | ||
| 5 | +import com.baomidou.mybatisplus.annotation.TableName; | ||
| 6 | +import com.baomidou.mybatisplus.extension.activerecord.Model; | ||
| 7 | +import com.fasterxml.jackson.annotation.JsonFormat; | ||
| 8 | +import lombok.Data; | ||
| 9 | + | ||
| 10 | +import java.io.Serializable; | ||
| 11 | +import java.time.LocalDateTime; | ||
| 12 | +import java.util.Date; | ||
| 13 | + | ||
| 14 | +/** | ||
| 15 | + * 垫片素材表; | ||
| 16 | + * @author : http://www.chiner.pro | ||
| 17 | + * @date : 2025-7-18 | ||
| 18 | + */ | ||
| 19 | +@Data | ||
| 20 | +@TableName("crp_backup_material") | ||
| 21 | +public class CrpBackupMaterial extends Model<CrpBackupMaterial> { | ||
| 22 | + /** id */ | ||
| 23 | + @TableId | ||
| 24 | + private Long id ; | ||
| 25 | + /** 文件类型 */ | ||
| 26 | + private String fileType ; | ||
| 27 | + /** 文件路径 */ | ||
| 28 | + private String filePath ; | ||
| 29 | + /** 垫片名称 */ | ||
| 30 | + private String backupName ; | ||
| 31 | + /** 创建人 */ | ||
| 32 | + private String createdBy ; | ||
| 33 | + /** 创建时间 */ | ||
| 34 | + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | ||
| 35 | + private LocalDateTime createdTime ; | ||
| 36 | + | ||
| 37 | + | ||
| 38 | +} |
| 1 | +package com.wondertek.enums; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * 系统全局编码 | ||
| 5 | + * @Description -1-99, 避开HTTP状态码100-600 | ||
| 6 | + */ | ||
| 7 | +public enum GlobalCodeEnum { | ||
| 8 | + FALLBACK("-2", "JPA服务熔断"), | ||
| 9 | + UNKNOW_ERROR("-1", "未知错误"), | ||
| 10 | + SUCCESS("0", "成功"), | ||
| 11 | + FAILURE("1", "失败"), | ||
| 12 | + INVALID_PARAMS("2", "请求参数无效"), | ||
| 13 | + UNSUPPORTED_URI("3", "未知URI"), | ||
| 14 | + TOUCH_API_LIMIT("4", "接口调用次数已达到设定的上限"), | ||
| 15 | + NO_AUTHORIZATION("6", "无访问权限"), | ||
| 16 | + //持久层错误 | ||
| 17 | + DB_ERROR("20", "数据库异常"), | ||
| 18 | + SOLR_ERROR("21", "搜索引擎异常"), | ||
| 19 | + | ||
| 20 | + //消息中间件错误 | ||
| 21 | + MQ_ERROR("30", "消息中间件异常"); | ||
| 22 | + | ||
| 23 | + private String code; | ||
| 24 | + private String msg; | ||
| 25 | + | ||
| 26 | + private GlobalCodeEnum(String code, String msg) { | ||
| 27 | + this.code = code; | ||
| 28 | + this.msg = msg; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public String getCode() { | ||
| 32 | + return code; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public String getMsg() { | ||
| 36 | + return msg; | ||
| 37 | + } | ||
| 38 | +} |
| 1 | +package com.wondertek.service; | ||
| 2 | + | ||
| 3 | +import com.baomidou.mybatisplus.extension.service.IService; | ||
| 4 | +import com.wondertek.dto.CrpBackupMaterialDto; | ||
| 5 | +import com.wondertek.entity.CrpBackupMaterial; | ||
| 6 | +import com.wondertek.util.PageBean; | ||
| 7 | +import com.wondertek.util.PageResult; | ||
| 8 | + | ||
| 9 | +public interface CrpBackupMaterialService extends IService<CrpBackupMaterial> { | ||
| 10 | + | ||
| 11 | + PageBean queryPage(CrpBackupMaterialDto crpBackupMaterialDto); | ||
| 12 | +} |
| 1 | +package com.wondertek.service.impl; | ||
| 2 | + | ||
| 3 | +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||
| 4 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | ||
| 5 | +import com.baomidou.mybatisplus.core.metadata.IPage; | ||
| 6 | +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | ||
| 7 | +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | ||
| 8 | +import com.wondertek.dto.CrpBackupMaterialDto; | ||
| 9 | +import com.wondertek.entity.CrpBackupMaterial; | ||
| 10 | +import com.wondertek.mapper.CrpBackupMaterialMapper; | ||
| 11 | +import com.wondertek.service.CrpBackupMaterialService; | ||
| 12 | +import com.wondertek.util.PageBean; | ||
| 13 | +import jakarta.annotation.Resource; | ||
| 14 | +import org.apache.commons.lang3.StringUtils; | ||
| 15 | +import org.springframework.stereotype.Service; | ||
| 16 | + | ||
| 17 | +@Service | ||
| 18 | +public class CrpBackupMaterialServiceImpl extends ServiceImpl<CrpBackupMaterialMapper, CrpBackupMaterial> implements CrpBackupMaterialService { | ||
| 19 | + | ||
| 20 | + @Resource | ||
| 21 | + private CrpBackupMaterialMapper crpBackupMaterialMapper; | ||
| 22 | + | ||
| 23 | + @Override | ||
| 24 | + public PageBean queryPage(CrpBackupMaterialDto crpBackupMaterialDto) { | ||
| 25 | + Integer page = crpBackupMaterialDto.getPage(); | ||
| 26 | + Integer size = crpBackupMaterialDto.getSize(); | ||
| 27 | + | ||
| 28 | + | ||
| 29 | + | ||
| 30 | + LambdaQueryWrapper<CrpBackupMaterial> queryWrapper = new LambdaQueryWrapper<>(); | ||
| 31 | + | ||
| 32 | + if(StringUtils.isNotBlank(crpBackupMaterialDto.getBackupName())){ | ||
| 33 | + queryWrapper.like(CrpBackupMaterial::getBackupName,crpBackupMaterialDto.getBackupName()); | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + | ||
| 37 | + Page<CrpBackupMaterial> pageInfo = new Page<>(page, size); | ||
| 38 | + | ||
| 39 | + | ||
| 40 | + IPage<CrpBackupMaterial> resultPage = crpBackupMaterialMapper.selectPage(pageInfo, queryWrapper); | ||
| 41 | + return new PageBean(Integer.parseInt(String.valueOf(resultPage.getPages())),resultPage.getTotal(),resultPage.getRecords()); | ||
| 42 | + } | ||
| 43 | +} |
| 1 | +package com.wondertek.util; | ||
| 2 | + | ||
| 3 | +import lombok.extern.slf4j.Slf4j; | ||
| 4 | +import org.springframework.util.Assert; | ||
| 5 | +import org.springframework.util.StringUtils; | ||
| 6 | + | ||
| 7 | +import java.text.DateFormat; | ||
| 8 | +import java.text.ParseException; | ||
| 9 | +import java.text.SimpleDateFormat; | ||
| 10 | +import java.time.*; | ||
| 11 | +import java.time.format.DateTimeFormatter; | ||
| 12 | +import java.time.temporal.ChronoUnit; | ||
| 13 | +import java.util.*; | ||
| 14 | + | ||
| 15 | +/** | ||
| 16 | + * @author w4178 | ||
| 17 | + */ | ||
| 18 | +@Slf4j | ||
| 19 | +public class DateUtil { | ||
| 20 | + | ||
| 21 | + public static final String regex = "yyyy-MM-dd HH:mm:ss"; | ||
| 22 | + | ||
| 23 | + private static final SimpleDateFormat sdf = new SimpleDateFormat(regex); | ||
| 24 | + | ||
| 25 | + private static final ThreadLocal<Map<String, DateFormat>> dateFormatThreadLocal = new ThreadLocal(); | ||
| 26 | + | ||
| 27 | + public static LocalDateTime toLocalDateTime(Date date) { | ||
| 28 | + if (date != null) { | ||
| 29 | +// return date.toInstant().atOffset(ZoneOffset.of("+8")).toLocalDateTime(); | ||
| 30 | +// return date.toInstant().atOffset(ZoneOffset.of("+0")).toLocalDateTime(); | ||
| 31 | + return Instant.ofEpochMilli(date.getTime()).atZone(ZoneId.systemDefault()).toLocalDateTime(); | ||
| 32 | + } | ||
| 33 | + return null; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + public static Date asDate(LocalDateTime localDateTime){ | ||
| 37 | + return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + public static LocalDateTime asLocalDateTime(Date date){ | ||
| 41 | + return Instant.ofEpochMilli(date.getTime()).atZone(ZoneId.systemDefault()).toLocalDateTime(); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + public static String format(LocalDateTime date) { | ||
| 45 | + try { | ||
| 46 | + if (date != null) { | ||
| 47 | + DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); | ||
| 48 | + return df.format(date); | ||
| 49 | + } | ||
| 50 | + } catch (Exception e) { | ||
| 51 | + log.error("date 日期格式化错误:" + e.getMessage()); | ||
| 52 | + } | ||
| 53 | + return ""; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public static String format(Date date, String patten) { | ||
| 57 | + return getDateFormat(patten).format(date); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + | ||
| 61 | + private static DateFormat getDateFormat(String pattern) { | ||
| 62 | + if (pattern != null && pattern.trim().length() != 0) { | ||
| 63 | + Map<String, DateFormat> dateFormatMap = (Map)dateFormatThreadLocal.get(); | ||
| 64 | + if (dateFormatMap != null && ((Map)dateFormatMap).containsKey(pattern)) { | ||
| 65 | + return (DateFormat)((Map)dateFormatMap).get(pattern); | ||
| 66 | + } else { | ||
| 67 | + synchronized(dateFormatThreadLocal) { | ||
| 68 | + if (dateFormatMap == null) { | ||
| 69 | + dateFormatMap = new HashMap(); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + ((Map)dateFormatMap).put(pattern, new SimpleDateFormat(pattern)); | ||
| 73 | + dateFormatThreadLocal.set(dateFormatMap); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + return (DateFormat)((Map)dateFormatMap).get(pattern); | ||
| 77 | + } | ||
| 78 | + } else { | ||
| 79 | + throw new IllegalArgumentException("pattern cannot be empty."); | ||
| 80 | + } | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + public static String dateToString(Date d,String format) | ||
| 84 | + { | ||
| 85 | + return new SimpleDateFormat(format).format(d); | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + public static String dateToString(Date d) | ||
| 89 | + { | ||
| 90 | + return new SimpleDateFormat(regex).format(d); | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + public static Date stringToDate(String s,String format) throws ParseException | ||
| 94 | + { | ||
| 95 | + return new SimpleDateFormat(format).parse(s); | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + public static Date stringToDate(String s) throws ParseException | ||
| 99 | + { | ||
| 100 | + return new SimpleDateFormat(regex).parse(s); | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + | ||
| 104 | + | ||
| 105 | + public static String resolve(LocalDateTime localDateTime) { | ||
| 106 | + try { | ||
| 107 | + if (localDateTime != null) { | ||
| 108 | + DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); | ||
| 109 | + return df.format(localDateTime); | ||
| 110 | + } | ||
| 111 | + } catch (Exception e) { | ||
| 112 | + log.error("date 日期格式化错误:" + e.getMessage()); | ||
| 113 | + } | ||
| 114 | + return ""; | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + public static Long getTime(LocalDateTime localDateTime) { | ||
| 118 | + if (localDateTime != null) { | ||
| 119 | + Date date = DateUtil.toDate(localDateTime); | ||
| 120 | + return date.getTime(); | ||
| 121 | + } | ||
| 122 | + return null; | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + public static Date toDate(LocalDateTime localDateTime) { | ||
| 126 | + if (localDateTime != null) { | ||
| 127 | + ZoneId zoneId = ZoneId.systemDefault(); | ||
| 128 | + ZonedDateTime zdt = localDateTime.atZone(zoneId); | ||
| 129 | + return Date.from(zdt.toInstant()); | ||
| 130 | + } | ||
| 131 | + return null; | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + public static Date toDate(String content) { | ||
| 135 | + if (!StringUtils.isEmpty(content) && !"null".equals(content)) { | ||
| 136 | + Long time = getTime(content); | ||
| 137 | + if (time != null) { | ||
| 138 | + return new Date(time); | ||
| 139 | + } | ||
| 140 | + } | ||
| 141 | + return null; | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + /** | ||
| 145 | + * <p><b>Title:</b> listBetweenMinutes</p> | ||
| 146 | + * <p><b>Description:</b> 得到时间范围内所有时间(按分钟算),开始时间不算</p> | ||
| 147 | + * | ||
| 148 | + * @param startTime | ||
| 149 | + * @param endTime | ||
| 150 | + * @param s 间隔多少分钟 | ||
| 151 | + * @return | ||
| 152 | + * @author Zewei.Zhou | ||
| 153 | + */ | ||
| 154 | + public static List<LocalDateTime> listBetweenMinutes(LocalDateTime startTime, LocalDateTime endTime, int s) { | ||
| 155 | + long between = ChronoUnit.MINUTES.between(startTime.withSecond(0).withNano(0), | ||
| 156 | + endTime.withSecond(0).withNano(0)); | ||
| 157 | + Assert.state(between >= 0, "开始时间必须小于等于结束时间"); | ||
| 158 | + | ||
| 159 | + List<LocalDateTime> list = new ArrayList<>(Integer.parseInt(between + "")); | ||
| 160 | + | ||
| 161 | + list.add(startTime); | ||
| 162 | + for (int i = s; i < between; i = i + s) { | ||
| 163 | + list.add(startTime.plusMinutes(i)); | ||
| 164 | + | ||
| 165 | + } | ||
| 166 | + | ||
| 167 | + return list; | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + public static boolean checkBetweenDays(String startTime,String endTime,Long days){ | ||
| 171 | + try { | ||
| 172 | + long between = ChronoUnit.DAYS.between(DateUtil.str2date(startTime).withSecond(0).withNano(0), | ||
| 173 | + DateUtil.str2date(endTime).withSecond(0).withNano(0)); | ||
| 174 | + return between > days; | ||
| 175 | + }catch (Exception ex){ | ||
| 176 | + return false; | ||
| 177 | + } | ||
| 178 | + } | ||
| 179 | + | ||
| 180 | + public static Long getTimeMill(String timeStr) { | ||
| 181 | + String defaultDateFormat = "yyyy-MM-dd HH:mm:ss"; | ||
| 182 | + timeStr = timeStr.trim(); | ||
| 183 | + boolean flag = isDate(timeStr, defaultDateFormat); | ||
| 184 | + if (flag) { | ||
| 185 | + LocalDateTime localDateTime = LocalDateTime.parse(timeStr, DateTimeFormatter.ofPattern(defaultDateFormat)); | ||
| 186 | + Date date = DateUtil.toDate(localDateTime); | ||
| 187 | + return date.getTime(); | ||
| 188 | + } | ||
| 189 | + return null; | ||
| 190 | + } | ||
| 191 | + | ||
| 192 | + /** | ||
| 193 | + * 判断是否为合法的日期时间字符串 | ||
| 194 | + * | ||
| 195 | + * @param dateStr 时间字符串 | ||
| 196 | + * @param rDateFormat 时间格式化模板 | ||
| 197 | + * @return boolean;符合为true,不符合为false | ||
| 198 | + */ | ||
| 199 | + public static boolean isDate(String dateStr, String rDateFormat) { | ||
| 200 | + if (!StringUtils.isEmpty(dateStr)) { | ||
| 201 | + SimpleDateFormat formatter = new SimpleDateFormat(rDateFormat); | ||
| 202 | + formatter.setLenient(false); | ||
| 203 | + try { | ||
| 204 | + formatter.format(formatter.parse(dateStr)); | ||
| 205 | + } catch (Exception e) { | ||
| 206 | + return false; | ||
| 207 | + } | ||
| 208 | + return true; | ||
| 209 | + } | ||
| 210 | + return false; | ||
| 211 | + } | ||
| 212 | + | ||
| 213 | + /** | ||
| 214 | + * localDateTime装换为Date | ||
| 215 | + * | ||
| 216 | + * @param localDateTime localDateTime | ||
| 217 | + * @return Date | ||
| 218 | + */ | ||
| 219 | + public static Date localDateTimeToDate(LocalDateTime localDateTime) { | ||
| 220 | + if (localDateTime == null) { | ||
| 221 | + return null; | ||
| 222 | + } | ||
| 223 | + ZoneId zoneId = ZoneId.systemDefault(); | ||
| 224 | + Instant instant = localDateTime.atZone(zoneId).toInstant(); | ||
| 225 | + return Date.from(instant); | ||
| 226 | + } | ||
| 227 | + | ||
| 228 | + // 把时间转为字符串 | ||
| 229 | + public static String date2Str(LocalDateTime time, String format) { | ||
| 230 | + try { | ||
| 231 | + DateTimeFormatter pattern = DateTimeFormatter.ofPattern(format); | ||
| 232 | + return pattern.format(time); | ||
| 233 | + } catch (Exception e) { | ||
| 234 | + log.info("时间转换为字符串异常:" + e.getMessage()); | ||
| 235 | + } | ||
| 236 | + return null; | ||
| 237 | + } | ||
| 238 | + | ||
| 239 | + // 把字符串转换为时间 | ||
| 240 | + public static LocalDateTime str2date(String timeStr, String format) { | ||
| 241 | + try { | ||
| 242 | + DateTimeFormatter pattern = DateTimeFormatter.ofPattern(format); | ||
| 243 | + return LocalDateTime.parse(timeStr, pattern); | ||
| 244 | + } catch (Exception e) { | ||
| 245 | + log.info("字符串转换为时间异常:" + e.getMessage()); | ||
| 246 | + } | ||
| 247 | + return null; | ||
| 248 | + } | ||
| 249 | + | ||
| 250 | + // 把字符串转换为时间 | ||
| 251 | + public static LocalDateTime str2date(String timeStr) { | ||
| 252 | + try { | ||
| 253 | + DateTimeFormatter pattern = DateTimeFormatter.ofPattern(regex); | ||
| 254 | + return LocalDateTime.parse(timeStr, pattern); | ||
| 255 | + } catch (Exception e) { | ||
| 256 | + log.info("字符串转换为时间异常:" + e.getMessage()); | ||
| 257 | + } | ||
| 258 | + return null; | ||
| 259 | + } | ||
| 260 | + | ||
| 261 | + public static boolean isInTimeInterval(LocalDateTime nowTime,LocalDateTime startTime,LocalDateTime endTime){ | ||
| 262 | + if (startTime ==null){ | ||
| 263 | + return true; | ||
| 264 | + } | ||
| 265 | + if (endTime ==null){ | ||
| 266 | + return true; | ||
| 267 | + } | ||
| 268 | + if (nowTime.isAfter(startTime) && nowTime.isBefore(endTime)){ | ||
| 269 | + return true; | ||
| 270 | + } | ||
| 271 | + | ||
| 272 | + return false; | ||
| 273 | + } | ||
| 274 | + | ||
| 275 | + | ||
| 276 | + | ||
| 277 | + | ||
| 278 | + | ||
| 279 | + | ||
| 280 | + public static String secToTime(int time) { | ||
| 281 | + String timeStr; | ||
| 282 | + int hour; | ||
| 283 | + int minute; | ||
| 284 | + int second; | ||
| 285 | + if (time <= 0) { | ||
| 286 | + return "00:00:00"; | ||
| 287 | + } else { | ||
| 288 | + minute = time / 60; | ||
| 289 | + if (minute < 60) { | ||
| 290 | + second = time % 60; | ||
| 291 | + timeStr = "00:" + unitFormat(minute) + ":" + unitFormat(second); | ||
| 292 | + } else { | ||
| 293 | + hour = minute / 60; | ||
| 294 | + if (hour > 99) { | ||
| 295 | + return "99:59:59"; | ||
| 296 | + } | ||
| 297 | + minute = minute % 60; | ||
| 298 | + second = time - hour * 3600 - minute * 60; | ||
| 299 | + timeStr = unitFormat(hour) + ":" + unitFormat(minute) + ":" + unitFormat(second); | ||
| 300 | + } | ||
| 301 | + } | ||
| 302 | + return timeStr; | ||
| 303 | + } | ||
| 304 | + | ||
| 305 | + private static String unitFormat(int i) { | ||
| 306 | + String retStr = null; | ||
| 307 | + if (i >= 0 && i < 10) { | ||
| 308 | + retStr = "0" + Integer.toString(i); | ||
| 309 | + } else { | ||
| 310 | + retStr = "" + i; | ||
| 311 | + } | ||
| 312 | + return retStr; | ||
| 313 | + } | ||
| 314 | + | ||
| 315 | + public static List<String> listBetweenDays(String startTime, String endTime) { | ||
| 316 | + List<String> resultList = new ArrayList<>(16); | ||
| 317 | + | ||
| 318 | + DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd"); | ||
| 319 | + LocalDate startDate = LocalDate.parse(startTime, pattern); | ||
| 320 | + LocalDate endDate = LocalDate.parse(endTime, pattern); | ||
| 321 | + while (startDate.isBefore(endDate) || startDate.isEqual(endDate)) { | ||
| 322 | + resultList.add(pattern.format(startDate)); | ||
| 323 | + startDate = startDate.plusDays(1); | ||
| 324 | + } | ||
| 325 | + return resultList; | ||
| 326 | + } | ||
| 327 | + | ||
| 328 | + public static Long getTime(String content) { | ||
| 329 | + String regex = "yyyy-MM-dd HH:mm:ss"; | ||
| 330 | + if (isDate(content.trim(), regex)) { | ||
| 331 | + try { | ||
| 332 | + Date d = sdf.parse(content); | ||
| 333 | + return d.getTime(); | ||
| 334 | + } catch (ParseException e) { | ||
| 335 | + log.error("{},格式化异常:{}", regex, e.getMessage()); | ||
| 336 | + } | ||
| 337 | + } | ||
| 338 | + return null; | ||
| 339 | + } | ||
| 340 | + | ||
| 341 | + public static boolean compareStartEndTime(String startTime,String endTime){ | ||
| 342 | + boolean flag =true; | ||
| 343 | + int compareTo = startTime.compareTo(endTime); | ||
| 344 | + if(compareTo>0){ | ||
| 345 | + flag= false; | ||
| 346 | + } | ||
| 347 | + | ||
| 348 | + return flag; | ||
| 349 | + } | ||
| 350 | + | ||
| 351 | + | ||
| 352 | + | ||
| 353 | + | ||
| 354 | + | ||
| 355 | + | ||
| 356 | + public static boolean isDateVail(String date){ | ||
| 357 | + DateTimeFormatter dtf = DateTimeFormatter.ofPattern(regex); | ||
| 358 | + boolean flag =true; | ||
| 359 | + try { | ||
| 360 | + LocalDateTime.parse(date, dtf); | ||
| 361 | + }catch (Exception ex){ | ||
| 362 | + flag =false; | ||
| 363 | + } | ||
| 364 | + return false; | ||
| 365 | + } | ||
| 366 | + | ||
| 367 | + | ||
| 368 | + public static LocalDateTime toStartOfDay(LocalDateTime time) { | ||
| 369 | + return time.withHour(0).withMinute(0).withSecond(0).withNano(0); | ||
| 370 | + } | ||
| 371 | + | ||
| 372 | + public static String[] getLastMonthFirstAndLastDay(){ | ||
| 373 | + LocalDateTime time = LocalDateTime.now().minusMonths(6L); | ||
| 374 | + LocalDateTime dayStart = DateUtil.getDayStart(time); | ||
| 375 | + String format = DateUtil.format(dayStart); | ||
| 376 | + return new String[]{"",format}; | ||
| 377 | + } | ||
| 378 | + | ||
| 379 | + | ||
| 380 | + | ||
| 381 | + public static String[] getLastMonthFirstAndLastDays(){ | ||
| 382 | + SimpleDateFormat sm = new SimpleDateFormat("yyyyMMdd"); | ||
| 383 | + Calendar cal = Calendar.getInstance(); | ||
| 384 | + //上个月 | ||
| 385 | + cal.add(Calendar.MONTH, -3); | ||
| 386 | + cal.set(Calendar.DAY_OF_MONTH,1); | ||
| 387 | + String firstDay = sm.format(cal.getTime()); | ||
| 388 | + Calendar call = Calendar.getInstance(); | ||
| 389 | + //设置上个月最后一天 | ||
| 390 | + call.add(Calendar.MONTH, -2); | ||
| 391 | + call.set(Calendar.DAY_OF_MONTH,0); | ||
| 392 | + String lastDay = sm.format(call.getTime()); | ||
| 393 | + return new String[]{firstDay,lastDay}; | ||
| 394 | + } | ||
| 395 | + | ||
| 396 | + | ||
| 397 | + | ||
| 398 | + private static LocalDateTime getDate(String beforeDate) throws Exception{ | ||
| 399 | + | ||
| 400 | + SimpleDateFormat readFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); | ||
| 401 | + Date rdate = readFormat.parse(beforeDate); | ||
| 402 | + | ||
| 403 | + SimpleDateFormat writeFormat = new SimpleDateFormat(regex, Locale.US); | ||
| 404 | + String format = writeFormat.format(rdate); | ||
| 405 | + return asLocalDateTime(writeFormat.parse(format)); | ||
| 406 | + | ||
| 407 | + | ||
| 408 | + | ||
| 409 | + } | ||
| 410 | + | ||
| 411 | + | ||
| 412 | + | ||
| 413 | + // 获取一天的开始时间,2017,7,22 00:00 | ||
| 414 | + public static LocalDateTime getDayStart(LocalDateTime time) { | ||
| 415 | + return time.withHour(0).withMinute(0).withSecond(0).withNano(0); | ||
| 416 | + } | ||
| 417 | + | ||
| 418 | + // 获取一天的结束时间,2017,7,22 23:59:59.999999999 | ||
| 419 | + public static LocalDateTime getDayEnd(LocalDateTime time) { | ||
| 420 | + return time.withHour(23).withMinute(59).withSecond(59).withNano(999999999); | ||
| 421 | + } | ||
| 422 | + | ||
| 423 | + | ||
| 424 | + | ||
| 425 | +} |
| 1 | +package com.wondertek.util; | ||
| 2 | + | ||
| 3 | +import com.fasterxml.jackson.annotation.JsonInclude; | ||
| 4 | +import com.wondertek.enums.GlobalCodeEnum; | ||
| 5 | +import lombok.Data; | ||
| 6 | +import lombok.EqualsAndHashCode; | ||
| 7 | +import lombok.ToString; | ||
| 8 | + | ||
| 9 | +import java.util.ArrayList; | ||
| 10 | +import java.util.List; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * 分页对象 | ||
| 14 | + * | ||
| 15 | + * @param <T> | ||
| 16 | + */ | ||
| 17 | +@Data | ||
| 18 | +@ToString | ||
| 19 | +@EqualsAndHashCode(callSuper = true) | ||
| 20 | +@JsonInclude(JsonInclude.Include.NON_NULL) | ||
| 21 | +public class PageBean<T> extends ResultBean { | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * 总的页数 | ||
| 25 | + */ | ||
| 26 | + private Integer totalPage; | ||
| 27 | + /** | ||
| 28 | + * 总记录数 | ||
| 29 | + */ | ||
| 30 | + private Long totalCount; | ||
| 31 | + /** | ||
| 32 | + * 分页数据 | ||
| 33 | + */ | ||
| 34 | + private List<T> result; | ||
| 35 | + | ||
| 36 | + | ||
| 37 | + public PageBean() {} | ||
| 38 | + | ||
| 39 | + public PageBean(String code, String msg) { | ||
| 40 | + super(code, msg); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + /** | ||
| 44 | + * | ||
| 45 | + * @param totalPage 总页数 | ||
| 46 | + * @param totalCount 总数 | ||
| 47 | + * @param result | ||
| 48 | + */ | ||
| 49 | + public <K> PageBean(Integer totalPage, Long totalCount, List<T> result) { | ||
| 50 | + super(GlobalCodeEnum.SUCCESS.getCode(), GlobalCodeEnum.SUCCESS.getMsg()); | ||
| 51 | + this.totalPage = totalPage; | ||
| 52 | + this.totalCount = totalCount; | ||
| 53 | + this.result = result; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public static <T> PageBean<T> ok(Integer totalPage, Long totalCount, List<T> result){ | ||
| 57 | + return new PageBean<>(totalPage, totalCount, result); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + public static <T> PageBean<T> empty() { | ||
| 61 | + return new PageBean<>(0, 0L, new ArrayList<>()); | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | +} |
| 1 | +package com.wondertek.util; | ||
| 2 | + | ||
| 3 | +import com.fasterxml.jackson.annotation.JsonInclude; | ||
| 4 | +import lombok.Data; | ||
| 5 | +import lombok.ToString; | ||
| 6 | + | ||
| 7 | +import java.util.ArrayList; | ||
| 8 | +import java.util.List; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * 分页对象 | ||
| 12 | + * | ||
| 13 | + * @param <T> | ||
| 14 | + */ | ||
| 15 | +@Data | ||
| 16 | +@ToString | ||
| 17 | +@JsonInclude(JsonInclude.Include.NON_NULL) | ||
| 18 | +public class PageDTO<T> { | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * 总的页数 | ||
| 22 | + */ | ||
| 23 | + private Integer totalPage; | ||
| 24 | + /** | ||
| 25 | + * 总记录数 | ||
| 26 | + */ | ||
| 27 | + private Long totalCount; | ||
| 28 | + /** | ||
| 29 | + * 分页数据 | ||
| 30 | + */ | ||
| 31 | + private List<T> list; | ||
| 32 | + | ||
| 33 | + | ||
| 34 | + public PageDTO() {} | ||
| 35 | + | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * | ||
| 39 | + * @param totalPage 总页数 | ||
| 40 | + * @param totalCount 总数 | ||
| 41 | + * @param list | ||
| 42 | + */ | ||
| 43 | + public <K> PageDTO(Integer totalPage, Long totalCount, List<T> list) { | ||
| 44 | + this.totalPage = totalPage; | ||
| 45 | + this.totalCount = totalCount; | ||
| 46 | + this.list = list; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + public static <T> PageDTO<T> ok(Integer totalPage, Long totalCount, List<T> list){ | ||
| 50 | + return new PageDTO<>(totalPage, totalCount, list); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + public static <T> PageDTO<T> empty() { | ||
| 54 | + return new PageDTO<>(0, 0L, new ArrayList<>()); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | +} |
| 1 | +package com.wondertek.util; | ||
| 2 | + | ||
| 3 | +import com.fasterxml.jackson.annotation.JsonInclude; | ||
| 4 | +import com.wondertek.enums.GlobalCodeEnum; | ||
| 5 | +import lombok.Data; | ||
| 6 | +import lombok.ToString; | ||
| 7 | + | ||
| 8 | +@Data | ||
| 9 | +@ToString | ||
| 10 | +@JsonInclude(JsonInclude.Include.NON_NULL) | ||
| 11 | +public class PageResult<T> { | ||
| 12 | + /** | ||
| 13 | + * 信息代码 | ||
| 14 | + */ | ||
| 15 | + private String code; | ||
| 16 | + /** | ||
| 17 | + * 信息说明 | ||
| 18 | + */ | ||
| 19 | + private String msg; | ||
| 20 | + /** | ||
| 21 | + * 返回数据或jqgrid中的root | ||
| 22 | + */ | ||
| 23 | + private PageDTO result; | ||
| 24 | + | ||
| 25 | + public <K> PageResult() { | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + public PageResult(String code, String msg) { | ||
| 29 | + this.code = code; | ||
| 30 | + this.msg = msg; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + public PageResult(String code, String msg, PageDTO result) { | ||
| 34 | + this.code = code; | ||
| 35 | + this.msg = msg; | ||
| 36 | + this.result = result; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public static <T> PageResult<T> ok() { | ||
| 40 | + return new PageResult<>(GlobalCodeEnum.SUCCESS.getCode(), GlobalCodeEnum.SUCCESS.getMsg()); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public static <T> PageResult<T> ok(PageDTO result) { | ||
| 44 | + return new PageResult<T>(GlobalCodeEnum.SUCCESS.getCode(), GlobalCodeEnum.SUCCESS.getMsg(), result); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public boolean isSuccess() { | ||
| 48 | + return GlobalCodeEnum.SUCCESS.getCode().equals(this.code); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public static <T> PageResult<T> error() { | ||
| 52 | + return new PageResult<T>(GlobalCodeEnum.FAILURE.getCode(), GlobalCodeEnum.FAILURE.getMsg()); | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public static <T> PageResult<T> error(String msg) { | ||
| 56 | + return new PageResult<T>(GlobalCodeEnum.FAILURE.getCode(), msg); | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public static <T> PageResult<T> error(String code, String msg) { | ||
| 60 | + return new PageResult<T>(code, msg); | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public static <K> PageResult<K> error(String code, String msg, PageDTO k) { | ||
| 64 | + return new PageResult<K>(code, msg, k); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | +} |
| 1 | +package com.wondertek.util; | ||
| 2 | + | ||
| 3 | +import com.fasterxml.jackson.annotation.JsonInclude; | ||
| 4 | +import com.wondertek.enums.GlobalCodeEnum; | ||
| 5 | +import lombok.Data; | ||
| 6 | +import lombok.ToString; | ||
| 7 | + | ||
| 8 | +@Data | ||
| 9 | +@ToString | ||
| 10 | +@JsonInclude(JsonInclude.Include.NON_NULL) | ||
| 11 | +public class ResultBean<T> { | ||
| 12 | + /** | ||
| 13 | + * 信息代码 | ||
| 14 | + */ | ||
| 15 | + private String code; | ||
| 16 | + /** | ||
| 17 | + * 信息说明 | ||
| 18 | + */ | ||
| 19 | + private String msg; | ||
| 20 | + /** | ||
| 21 | + * 返回数据或jqgrid中的root | ||
| 22 | + */ | ||
| 23 | + private T result; | ||
| 24 | + | ||
| 25 | + public <K> ResultBean() { | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + public ResultBean(String code, String msg) { | ||
| 29 | + this.code = code; | ||
| 30 | + this.msg = msg; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + public ResultBean(String code, String msg, T result) { | ||
| 34 | + this.code = code; | ||
| 35 | + this.msg = msg; | ||
| 36 | + this.result = result; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public static <T> ResultBean<T> ok() { | ||
| 40 | + return new ResultBean<>(GlobalCodeEnum.SUCCESS.getCode(), GlobalCodeEnum.SUCCESS.getMsg()); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public static <T> ResultBean<T> ok(T result) { | ||
| 44 | + return new ResultBean<T>(GlobalCodeEnum.SUCCESS.getCode(), GlobalCodeEnum.SUCCESS.getMsg(), result); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public boolean isSuccess() { | ||
| 48 | + return GlobalCodeEnum.SUCCESS.getCode().equals(this.code); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public static <T> ResultBean<T> error() { | ||
| 52 | + return new ResultBean<T>(GlobalCodeEnum.FAILURE.getCode(), GlobalCodeEnum.FAILURE.getMsg()); | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public static <T> ResultBean<T> error(String msg) { | ||
| 56 | + return new ResultBean<T>(GlobalCodeEnum.FAILURE.getCode(), msg); | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public static <T> ResultBean<T> error(String code, String msg) { | ||
| 60 | + return new ResultBean<T>(code, msg); | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public static <K> ResultBean<K> error(String code, String msg, K k) { | ||
| 64 | + return new ResultBean<K>(code, msg, k); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | +} |
src/main/resources/application-dev.yml
0 → 100644
| 1 | +server: | ||
| 2 | + port: 8150 | ||
| 3 | + tomcat: | ||
| 4 | + threads: | ||
| 5 | + max: 1000 | ||
| 6 | + min-spare: 30 | ||
| 7 | + uri-encoding: UTF-8 | ||
| 8 | + | ||
| 9 | + | ||
| 10 | +spring: | ||
| 11 | + application: | ||
| 12 | + name: crp-operation | ||
| 13 | + datasource: | ||
| 14 | + type: com.alibaba.druid.pool.DruidDataSource | ||
| 15 | + url: jdbc:mysql://192.168.1.41:3306/crp_cloud?characterEncoding=UTF-8&useSSL=false&useUnicode=true&serverTimezone=GMT%2B8 | ||
| 16 | + username: root | ||
| 17 | + password: root | ||
| 18 | + driver-class-name: com.mysql.cj.jdbc.Driver | ||
| 19 | + druid: | ||
| 20 | + ##配置初始化大小、最小、最大 | ||
| 21 | + initial-size: 5 | ||
| 22 | + max-active: 100 | ||
| 23 | + min-idle: 5 | ||
| 24 | + #配置获取连接等待超时的时间 | ||
| 25 | + max-wait: 60000 | ||
| 26 | + ##打开PSCache,并且指定每个连接上PSCache的大小 | ||
| 27 | + pool-prepared-statements: true | ||
| 28 | + max-pool-prepared-statement-per-connection-size: 20 | ||
| 29 | + validation-query: SELECT 1 FROM DUAL | ||
| 30 | + validation-query-timeout: 60000 | ||
| 31 | + ##这里建议配置为TRUE,防止取到的连接不可用 | ||
| 32 | + test-on-borrow: true | ||
| 33 | + test-on-return: false | ||
| 34 | + test-while-idle: true | ||
| 35 | + ##配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 | ||
| 36 | + time-between-eviction-runs-millis: 60000 | ||
| 37 | + min-evictable-idle-time-millis: 100000 | ||
| 38 | + | ||
| 39 | + jackson: | ||
| 40 | + date-format: yyy-MM-dd HH:mm:ss | ||
| 41 | + time-zone: GMT+8 | ||
| 42 | + banner: | ||
| 43 | + charset: UTF-8 | ||
| 44 | + location: classpath:banner.txt | ||
| 45 | + servlet: | ||
| 46 | + multipart: | ||
| 47 | + location: /opt/upload/tmp | ||
| 48 | + max-file-size: 10MB | ||
| 49 | + max-request-size: 100MB | ||
| 50 | + | ||
| 51 | +mybatis-plus: | ||
| 52 | + mapper-locations: classpath*:/mapper/*Mapper.xml | ||
| 53 | + typeAliasesPackage: com.wondertek.entity #开启类型别名,降低冗余的全限定类名书写 | ||
| 54 | + configuration: | ||
| 55 | + mapUnderscoreToCamelCase: true #开启自动驼峰命名规则(camel case)映射 | ||
| 56 | +# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 配置sql打印日志 | ||
| 57 | + global-config: | ||
| 58 | + db-config: | ||
| 59 | + logic-not-delete-value: 1 | ||
| 60 | + logic-delete-value: 0 | ||
| 61 | + | ||
| 62 | + | ||
| 63 | +crp: | ||
| 64 | + log: | ||
| 65 | + open_console: true | ||
| 66 | + |
src/main/resources/application.yml
0 → 100644
src/main/resources/logback-spring.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<configuration debug="false" scan="false"> | ||
| 3 | + <springProperty scope="context" name="log_level" source="blog.log.level" defaultValue="INFO"/> | ||
| 4 | + <springProperty scope="context" name="log_open_console" source="crp.log.open_console" defaultValue="false"/> | ||
| 5 | + <springProperty scope="context" name="app_name" source="spring.application.name" | ||
| 6 | + defaultValue="crp-operation"/> | ||
| 7 | + <property name="log_path" value="/tools/logs"/> | ||
| 8 | + <property name="log.pattern" | ||
| 9 | + value="%d{yyyy-MM-dd HH:mm:ss.SSS}|%level|${PID:-}|%thread|${app_name:-}|%X{X-B3-TraceId:-}|%X{X-B3-SpanId:-}|%X{X-Span-Export:-}|%class.%method-%line|%msg%n"/> | ||
| 10 | + <!-- Console log output --> | ||
| 11 | + <appender name="console" class="ch.qos.logback.core.ConsoleAppender"> | ||
| 12 | + <encoder> | ||
| 13 | + <pattern>${log.pattern}</pattern> | ||
| 14 | + <charset>UTF-8</charset> | ||
| 15 | + </encoder> | ||
| 16 | + </appender> | ||
| 17 | + | ||
| 18 | + <!-- Log file debug output --> | ||
| 19 | + <appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender"> | ||
| 20 | + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | ||
| 21 | + <fileNamePattern>${log_path}/${app_name}/%d{yyyy-MM-dd}.info.log</fileNamePattern> | ||
| 22 | + <maxHistory>90</maxHistory> | ||
| 23 | + </rollingPolicy> | ||
| 24 | + <encoder> | ||
| 25 | + <pattern>${log.pattern}</pattern> | ||
| 26 | + <charset>UTF-8</charset> | ||
| 27 | + </encoder> | ||
| 28 | + </appender> | ||
| 29 | + | ||
| 30 | + <!-- Log file error output --> | ||
| 31 | + <appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender"> | ||
| 32 | + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | ||
| 33 | + <fileNamePattern>${log_path}/${app_name}/%d{yyyy-MM-dd}.error.log</fileNamePattern> | ||
| 34 | + <maxHistory>90</maxHistory> | ||
| 35 | + </rollingPolicy> | ||
| 36 | + <encoder> | ||
| 37 | + <pattern>${log.pattern}</pattern> | ||
| 38 | + <charset>UTF-8</charset> | ||
| 39 | + </encoder> | ||
| 40 | + <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> | ||
| 41 | + <level>ERROR</level> | ||
| 42 | + </filter> | ||
| 43 | + </appender> | ||
| 44 | + | ||
| 45 | + <!-- Feign log --> | ||
| 46 | + <appender name="feignFile" class="ch.qos.logback.core.rolling.RollingFileAppender"> | ||
| 47 | + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | ||
| 48 | + <fileNamePattern>${log_path}/${app_name}/%d{yyyy-MM-dd}.feign.log</fileNamePattern> | ||
| 49 | + <maxHistory>90</maxHistory> | ||
| 50 | + </rollingPolicy> | ||
| 51 | + <encoder> | ||
| 52 | + <pattern>${log.pattern}</pattern> | ||
| 53 | + <charset>UTF-8</charset> | ||
| 54 | + </encoder> | ||
| 55 | + </appender> | ||
| 56 | + | ||
| 57 | + <logger name="feign" level="INFO" addtivity="false"> | ||
| 58 | + <appender-ref ref="feignFile"/> | ||
| 59 | + </logger> | ||
| 60 | + | ||
| 61 | + <!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 --> | ||
| 62 | + <root level="${log_level}"> | ||
| 63 | + <if condition='property("log_open_console").contains("true")'> | ||
| 64 | + <then> | ||
| 65 | + <appender-ref ref="console"/> | ||
| 66 | + </then> | ||
| 67 | + </if> | ||
| 68 | + <appender-ref ref="file"/> | ||
| 69 | + <appender-ref ref="error"/> | ||
| 70 | + </root> | ||
| 71 | +</configuration> |
-
Please register or login to post a comment