Browse Source

项目部署优化调整

master
zhangyeguang 2 weeks ago
parent
commit
4affc78c00
  1. 1
      .gitignore
  2. 54
      pom.xml
  3. 4
      src/main/java/com/jiagutech/common/Knife4jConfig.java
  4. 7
      src/main/java/com/jiagutech/controller/UserController.java
  5. 4
      src/main/java/com/jiagutech/entity/UserEntity.java
  6. 3
      src/main/java/com/jiagutech/service/UserService.java
  7. 14
      src/main/java/com/jiagutech/service/UserServiceImpl.java
  8. 18
      src/main/resources/application-dev.yml
  9. 19
      src/main/resources/application-pro.yml
  10. 31
      src/main/resources/application.yml
  11. 103
      src/main/resources/logback-spring.xml

1
.gitignore

@ -54,3 +54,4 @@ MANIFEST
.idea/
.DS_Store
log/

54
pom.xml

@ -25,6 +25,29 @@
<hutool.version>5.8.22</hutool.version>
</properties>
<profiles>
<profile>
<id>dev</id>
<properties>
<!-- 环境标识,需要与配置文件的名称相对应 -->
<profiles.active>dev</profiles.active>
<logging.level>debug</logging.level>
</properties>
<activation>
<!-- 默认环境 -->
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>pro</id>
<properties>
<profiles.active>pro</profiles.active>
<logging.level>info</logging.level>
</properties>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
@ -35,12 +58,6 @@
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-devtools</artifactId>-->
<!-- <scope>runtime</scope>-->
<!-- <optional>true</optional>-->
<!-- </dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
@ -161,21 +178,11 @@
<artifactId>log4j-api</artifactId>
<version>2.23.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>2.0.8</version>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
@ -185,6 +192,19 @@
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.xml</include>
<include>application.yml</include>
<include>application-${profiles.active}.yml</include>
<include>*.xml</include>
<include>*.json</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>

4
src/main/java/com/jiagutech/common/Knife4jConfig.java

@ -11,14 +11,14 @@ import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
/**
* 自定义 Knife4j 接口文档的配置
*/
@Configuration
@EnableSwagger2
@EnableKnife4j
@Profile({"dev","pro"})
public class Knife4jConfig {
@Bean(value = "defaultApi2")

7
src/main/java/com/jiagutech/controller/UserController.java

@ -7,6 +7,7 @@ import com.jiagutech.dto.request.LoginRequest;
import com.jiagutech.dto.request.UserRequest;
import com.jiagutech.dto.response.LoginResponse;
import com.jiagutech.dto.response.UserItem;
import com.jiagutech.entity.UserEntity;
import com.jiagutech.service.UserService;
import com.jiagutech.utils.LoginUtil;
import io.swagger.annotations.Api;
@ -75,4 +76,10 @@ public class UserController {
public R<List<UserItem>> approvalUserList() {
return R.ok(userService.approvalUserList());
}
@ApiOperation(value = "修改用户密码/信息")
@PutMapping(value = "/update", consumes = "application/json")
public R<Boolean> update(@RequestBody UserEntity userEntity) {
return userService.update(userEntity) ? R.ok() : R.fail();
}
}

4
src/main/java/com/jiagutech/entity/UserEntity.java

@ -15,14 +15,16 @@ public class UserEntity {
private long id;
private String phone;
private String password;
private String realName;
private String unitName;
private LocalDateTime createTime;
private int status;
private Integer status;
private Integer role;

3
src/main/java/com/jiagutech/service/UserService.java

@ -4,6 +4,7 @@ import com.jiagutech.dto.request.LoginRequest;
import com.jiagutech.dto.response.LoginResponse;
import com.jiagutech.dto.response.UserItem;
import com.jiagutech.dto.request.UserRequest;
import com.jiagutech.entity.UserEntity;
import java.util.List;
@ -15,4 +16,6 @@ public interface UserService {
void approval(Long userId);
List<UserItem> approvalUserList();
Boolean update(UserEntity userEntity);
}

14
src/main/java/com/jiagutech/service/UserServiceImpl.java

@ -3,6 +3,7 @@ package com.jiagutech.service;
import cn.dev33.satoken.secure.BCrypt;
import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.jiagutech.common.UserConstants;
import com.jiagutech.common.exception.BizCode;
@ -82,4 +83,17 @@ public class UserServiceImpl implements UserService {
List<UserEntity> userEntities = userMapper.selectList(wrapper);
return UserMapping.INSTANCE.convertToUserItems(userEntities);
}
@Override
public Boolean update(UserEntity userEntity) {
if (userEntity != null && StringUtils.isNotBlank(userEntity.getPassword())) {
userEntity.setPassword(BCrypt.hashpw(userEntity.getPassword()));
}
int res = userMapper.updateById(userEntity);
if (res > 0) {
assert userEntity != null;
StpUtil.logout();
}
return res > 0;
}
}

18
src/main/resources/application-dev.yml

@ -0,0 +1,18 @@
spring:
datasource:
url: jdbc:mysql://101.34.243.138:7306/siliqua_recognition?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true
username: ams
password: ams@1234
redis:
host: 192.168.10.111
port: 6379
email:
to: yeguangzhang@126.com
recognition:
model:
url: http://api.camacloud.org.cn/recognition

19
src/main/resources/application-pro.yml

@ -0,0 +1,19 @@
spring:
datasource:
url: jdbc:mysql://192.168.1.232:3306/siliqua_recognition?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true
username: root
password: Njsszxs1!
redis:
host: 192.168.1.182
port: 6379
password: guwei2018
email:
to: 120059323@qq.com
recognition:
model:
url: http://localhost:9199

31
src/main/resources/application.yml

@ -1,14 +1,14 @@
server:
port: 9196
spring:
profiles:
active: @profiles.active@
application:
name: siliqua_recognition
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://101.34.243.138:7306/siliqua_recognition?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true
username: ams
password: ams@1234
type: com.zaxxer.hikari.HikariDataSource
hikari:
maximum-pool-size: 10
@ -18,6 +18,11 @@ spring:
max-lifetime: 1800000
pool-name: siliqua-recognition
redis:
database: 8
# host: 192.168.10.111
# port: 6379
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
@ -27,10 +32,6 @@ spring:
enabled: true
max-file-size: 20MB
max-request-size: 500MB
redis:
host: 192.168.10.111
port: 6379
database: 8
mail:
host: smtpdm.aliyun.com
port: 465
@ -43,8 +44,7 @@ spring:
auth: true
ssl:
enable: true
email:
to: yeguangzhang@126.com
mybatis-plus:
mapper-locations: classpath*:mapper/*.xml
type-aliases-package: com.jiagutech.entity
@ -55,9 +55,6 @@ mybatis-plus:
db-config:
update-strategy: not_null
recognition:
model:
url: http://api.camacloud.org.cn/recognition
sa-token:
# token名称 (同时也是cookie名称)
@ -81,6 +78,7 @@ huawei:
path-prefix: recognition
thread:
enabled: true
pool:
@ -100,7 +98,14 @@ http:
read-timeout: 20000
logging:
level:
com.jiagutech.mapper: debug
com.jiagutech.mapper: @logging.level@
root: info
tmp:
path: /tmp/
knife4j:
basic:
enable: true
username: admin
password: admin123
enable: true

103
src/main/resources/logback-spring.xml

@ -0,0 +1,103 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<springProperty scope="context" name="springAppName" source="spring.application.name"/>
<!--<springProperty scope="context" name="serverIp" source="spring.cloud.client.hostname" />-->
<!-- Example for logging into the build folder of your project -->
<property name="LOG_FILE" value="log"/>
<property name="LOG_PATTERN"
value="%d{yyyy-MM-dd HH:mm:ss.SSS} %highlight(%.-5level) -- %X{traceId:-} -- [%10.10t] %cyan(%-36.36logger{32}) : %m%n"/>
<!-- Appender to log to console -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<!-- Minimum logging level to be presented in the console logs-->
<level>DEBUG</level>
</filter>
<encoder>
<pattern>${LOG_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
</appender>
<!-- INFO日志 appender: 按照每天生成日志文件 -->
<appender name="INFO-APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 写入的日志文件名,可以使相对目录也可以是绝对目录,如果上级目录不存在则自动创建 -->
<file>${LOG_FILE}/${springAppName}-info.log</file>
<!-- 如果为true表示日志被追加到文件结尾,如果是false表示清空文件 -->
<append>true</append>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- 日志文件输出的文件名: %d可以包含一个Java.text.SimpleDateFormat指定的时间格式 -->
<fileNamePattern>${LOG_FILE}/${springAppName}-info.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<!-- 日志文件保存历史数量:控制保留的归档文件的最大数量,如果超出数量就删除旧文件 -->
<maxHistory>20</maxHistory>
<!-- 文件大小超过100MB归档 -->
<maxFileSize>100MB</maxFileSize>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${LOG_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
</appender>
<appender name="ASYNC-INFO-APPENDER" class="ch.qos.logback.classic.AsyncAppender">
<!-- 不丢失日志.默认的,如果队列的80%已满,则会丢弃TRACT、DEBUG、INFO级别的日志 -->
<discardingThreshold>0</discardingThreshold>
<!-- 更改默认的队列的深度,该值会影响性能.默认值为256 -->
<queueSize>256</queueSize>
<!-- 添加附加的appender,最多只能添加一个 -->
<appender-ref ref="INFO-APPENDER"/>
</appender>
<!-- 错误日志 appender: 按照每天生成日志文件 -->
<appender name="ERROR-APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 过滤器,只记录error级别的日志 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<!-- 日志名称 -->
<file>${LOG_FILE}/${springAppName}-error.log</file>
<append>true</append>
<!-- 每天生成一个日志文件,保存30天的日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- 日志文件输出的文件名:按天回滚 daily -->
<fileNamePattern>${LOG_FILE}/${springAppName}-error.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<!-- 日志文件保留天数 -->
<maxHistory>20</maxHistory>
<!-- 文件大小超过100MB归档 -->
<maxFileSize>100MB</maxFileSize>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${LOG_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
</appender>
<appender name="ASYNC-ERROR-APPENDER" class="ch.qos.logback.classic.AsyncAppender">
<!-- 不丢失日志.默认的,如果队列的80%已满,则会丢弃TRACT、DEBUG、INFO级别的日志 -->
<discardingThreshold>0</discardingThreshold>
<!-- 更改默认的队列的深度,该值会影响性能.默认值为256 -->
<queueSize>256</queueSize>
<!-- 添加附加的appender,最多只能添加一个 -->
<appender-ref ref="ERROR-APPENDER"/>
</appender>
<logger name="com.jiaguatech.oper.mapper" level="DEBUG">
<appender-ref ref="console"/>
<appender-ref ref="ASYNC-INFO-APPENDER"/>
</logger>
<root level="INFO">
<appender-ref ref="console"/>
<appender-ref ref="ASYNC-INFO-APPENDER"/>
<appender-ref ref="ASYNC-ERROR-APPENDER"/>
</root>
<springProfile name="local">
<root level="INFO">
<appender-ref ref="console"/>
</root>
</springProfile>
</configuration>
Loading…
Cancel
Save