diff --git a/luoo_common/src/main/java/util/JwtUtil.java b/luoo_common/src/main/java/util/JwtUtil.java index 5f4ac97..bed8c63 100644 --- a/luoo_common/src/main/java/util/JwtUtil.java +++ b/luoo_common/src/main/java/util/JwtUtil.java @@ -8,8 +8,13 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import constants.Constants; import dto.UserLoginDto; +import org.springframework.web.context.request.RequestAttributes; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; +import javax.servlet.http.HttpServletRequest; import java.util.Date; +import java.util.Objects; /** * Created by Administrator on 2018/4/11. @@ -86,4 +91,47 @@ public class JwtUtil { return null; } } + + public UserLoginDto getUser() { + return getUserLoginDto(getToken()); + } + + public static String getToken() + { + return getToken(Objects.requireNonNull(getRequest())); + } + + /** + * 根据request获取请求token + */ + public static String getToken(HttpServletRequest request) + { + // 从header获取token标识 + return request.getHeader("Authorization"); + } + + public static HttpServletRequest getRequest() + { + try + { + return getRequestAttributes().getRequest(); + } + catch (Exception e) + { + return null; + } + } + + public static ServletRequestAttributes getRequestAttributes() + { + try + { + RequestAttributes attributes = RequestContextHolder.getRequestAttributes(); + return (ServletRequestAttributes) attributes; + } + catch (Exception e) + { + return null; + } + } } diff --git a/luoo_user/src/main/java/com/luoo/user/config/MyBatisPlusConfig.java b/luoo_user/src/main/java/com/luoo/user/config/MyBatisPlusConfig.java new file mode 100644 index 0000000..8019ff5 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/config/MyBatisPlusConfig.java @@ -0,0 +1,28 @@ +package com.luoo.user.config; + +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.core.config.GlobalConfig; +import com.baomidou.mybatisplus.core.toolkit.GlobalConfigUtils; +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean; +import org.apache.ibatis.session.SqlSessionFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import javax.sql.DataSource; + +@Configuration +public class MyBatisPlusConfig { + + /** + * 分页插件 + */ + @Bean + public MybatisPlusInterceptor mybatisPlusInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); + return interceptor; + } + +} diff --git a/luoo_user/src/main/java/com/luoo/user/config/MyMetaObjectHandler.java b/luoo_user/src/main/java/com/luoo/user/config/MyMetaObjectHandler.java new file mode 100644 index 0000000..b388119 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/config/MyMetaObjectHandler.java @@ -0,0 +1,52 @@ +package com.luoo.user.config; + +import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; +import lombok.extern.slf4j.Slf4j; +import org.apache.ibatis.reflection.MetaObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import util.JwtUtil; + +import java.time.LocalDateTime; + +@Slf4j +@Component +public class MyMetaObjectHandler implements MetaObjectHandler { + + @Autowired + private JwtUtil jwtUtil; + + @Override + public void insertFill(MetaObject metaObject) { + String operator = null; + String operatorName = ""; + try { + operator = jwtUtil.getUser().getUserId(); + operatorName = jwtUtil.getUser().getNickName(); + } catch (Exception e) { + log.error(e.getMessage(), e); + } + this.setFieldValByName("createUser", operator, metaObject); + this.setFieldValByName("createUserName", operatorName, metaObject); + this.setFieldValByName("createTime", LocalDateTime.now(), metaObject); + this.setFieldValByName("updateUser", operator, metaObject); + this.setFieldValByName("updateUserName", operatorName, metaObject); + this.setFieldValByName("updateTime", LocalDateTime.now(), metaObject); + this.setFieldValByName("delFlag", 0, metaObject); + } + + @Override + public void updateFill(MetaObject metaObject) { + String operator = null; + String operatorName = ""; + try { + operator = jwtUtil.getUser().getUserId(); + operatorName = jwtUtil.getUser().getNickName(); + } catch (Exception e) { + log.error(e.getMessage(), e); + } + this.setFieldValByName("updateUser", operator, metaObject); + this.setFieldValByName("updateUserName", operatorName, metaObject); + this.setFieldValByName("updateTime", LocalDateTime.now(), metaObject); + } +} diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/WithdrawMybatis.java b/luoo_user/src/main/java/com/luoo/user/pojo/WithdrawMybatis.java index 0cc9cc0..37b6504 100644 --- a/luoo_user/src/main/java/com/luoo/user/pojo/WithdrawMybatis.java +++ b/luoo_user/src/main/java/com/luoo/user/pojo/WithdrawMybatis.java @@ -1,13 +1,14 @@ package com.luoo.user.pojo; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.*; +import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Builder; import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; import java.io.Serializable; import java.math.BigDecimal; +import java.time.LocalDateTime; import java.util.Date; /** @@ -42,79 +43,31 @@ public class WithdrawMybatis implements Serializable { /** * 创建时间 */ - private Date createTime; + @TableField(fill = FieldFill.INSERT, value = "create_time") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime createTime; /** * 修改时间 */ - private Date updateTime; + @TableField(fill = FieldFill.INSERT_UPDATE, value = "update_time") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime updateTime; /** * 创建人 */ + @TableField(fill = FieldFill.INSERT, value = "create_user") private String createUser; /** * 修改人 */ + @TableField(fill = FieldFill.INSERT_UPDATE, value = "update_user") private String updateUser; @TableField(exist = false) private static final long serialVersionUID = 1L; - - @Override - public boolean equals(Object that) { - if (this == that) { - return true; - } - if (that == null) { - return false; - } - if (getClass() != that.getClass()) { - return false; - } - Withdraw other = (Withdraw) that; - return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) - && (this.getState() == null ? other.getState() == null : this.getState().equals(other.getState())) - && (this.getAmount() == null ? other.getAmount() == null : this.getAmount().equals(other.getAmount())) - && (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId())) - && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())) - && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime())) - && (this.getCreateUser() == null ? other.getCreateUser() == null : this.getCreateUser().equals(other.getCreateUser())) - && (this.getUpdateUser() == null ? other.getUpdateUser() == null : this.getUpdateUser().equals(other.getUpdateUser())); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); - result = prime * result + ((getState() == null) ? 0 : getState().hashCode()); - result = prime * result + ((getAmount() == null) ? 0 : getAmount().hashCode()); - result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode()); - result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); - result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode()); - result = prime * result + ((getCreateUser() == null) ? 0 : getCreateUser().hashCode()); - result = prime * result + ((getUpdateUser() == null) ? 0 : getUpdateUser().hashCode()); - return result; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append(getClass().getSimpleName()); - sb.append(" ["); - sb.append("Hash = ").append(hashCode()); - sb.append(", id=").append(id); - sb.append(", state=").append(state); - sb.append(", amount=").append(amount); - sb.append(", userId=").append(userId); - sb.append(", createTime=").append(createTime); - sb.append(", updateTime=").append(updateTime); - sb.append(", createUser=").append(createUser); - sb.append(", updateUser=").append(updateUser); - sb.append(", serialVersionUID=").append(serialVersionUID); - sb.append("]"); - return sb.toString(); - } } \ No newline at end of file diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java b/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java index a507ff1..6f0ac9d 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java @@ -195,7 +195,7 @@ public class UserPointLogService { * @param token 用户token */ public void dailySign(String token) { - UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); + UserLoginDto userLoginDto = jwtUtil.getUser(); UserPointLog todayByUserIdAndTaskPointId = userPointLogDao.findTodayByUserIdAndTaskPointId(userLoginDto.getUserId(), TaskPointIdConstants.DAILY_SIGN); if (todayByUserIdAndTaskPointId == null) { diff --git a/luoo_user/src/main/resources/bootstrap.yml b/luoo_user/src/main/resources/bootstrap.yml index 07bcb4e..a6cd465 100644 --- a/luoo_user/src/main/resources/bootstrap.yml +++ b/luoo_user/src/main/resources/bootstrap.yml @@ -15,30 +15,24 @@ oauth2: secret: 741727f12d1b262ac855b905bf2e60e2 appidShare: wx667f580d1605650b secretShare: 4bb42de98cb422d733ac7d50e7cade3b -#mybatis-plus + mybatis-plus: - ## 这个可以不用配置,因其默认就是这个路径 - mapper-locations: classpath:/mapper/*Mapper.xml - #实体扫描,多个package用逗号或者分号分隔 - typeAliasesPackage: com.luoo.user.pojo + mapper-locations: classpath*:mapper/**/*Mapper.xml + type-aliases-package: com.luoo.user.pojo + checkConfigLocation : true + configuration: + map-underscore-to-camel-case: true + jdbc-type-for-null: null + log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl global-config: - # 数据库相关配置 + banner: true db-config: - #主键类型 AUTO:"数据库ID自增", INPUT:"用户输入ID",ID_WORKER:"全局唯一ID (数字类型唯一ID)", UUID:"全局唯一ID UUID"; id-type: ASSIGN_ID - #字段策略 IGNORED:"忽略判断",NOT_NULL:"非 NULL 判断"),NOT_EMPTY:"非空判断" - field-strategy: not_empty - #驼峰下划线转换 - column-underline: true - #数据库大写下划线转换 - #capital-mode: true - #逻辑删除配置 - logic-delete-value: 2 + table-underline: true logic-not-delete-value: 0 - db-type: h2 - #刷新mapper 调试神器 - refresh: true - # 原生配置 - configuration: - map-underscore-to-camel-case: true - cache-enabled: false \ No newline at end of file + logic-delete-value: 2 + +pagehelper: + helperDialect: mysql + supportMethodsArguments: true + params: count=countSql \ No newline at end of file