lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(SysUserEntity::getUsername,username);
SysUserEntity sysUserEntity = userDao.selectOne(lambdaQueryWrapper);
+
if (Objects.isNull(sysUserEntity)) {
throw new UsernameNotFoundException("用户名不存在");
}
diff --git a/ym-admin/src/main/java/com/cnbm/admin/utils/BaseSupportUtils.java b/ym-admin/src/main/java/com/cnbm/admin/utils/BaseSupportUtils.java
new file mode 100644
index 0000000..4f86c50
--- /dev/null
+++ b/ym-admin/src/main/java/com/cnbm/admin/utils/BaseSupportUtils.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) 2018.
+ * http://www.ulabcare.com
+ */
+
+package com.cnbm.admin.utils;
+
+import com.cnbm.admin.entity.LoginUser;
+import com.cnbm.admin.entity.SysUserEntity;
+import com.cnbm.admin.enums.WhetherEnum;
+import lombok.Builder;
+import lombok.Data;
+import org.springframework.beans.BeanUtils;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.context.SecurityContextHolder;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+/**
+ * 接口支持基类
+ *
+ * @author jiff
+ * @date 2018/11/1
+ * @since 1.0
+ */
+public abstract class BaseSupportUtils {
+
+ /**
+ * 获取当前登录用户信息
+ *
+ * @return
+ */
+ private static SysUserEntity getLoginUser() {
+ //登录用户信息
+ UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
+ LoginUser loginUser = (LoginUser) authentication.getPrincipal();
+ return loginUser.getSysUserEntity();
+ }
+
+ /**
+ * 设置公共字段值,一般用于创建新记录,包含以下字段:
+ *
+ *
+ * {@link CommonField#enabled}
+ * {@link CommonField#valid}
+ * {@link CommonField#creatorId}
+ * {@link CommonField#creatorName}
+ * {@link CommonField#createTime}
+ * {@link CommonField#updaterId}
+ * {@link CommonField#updaterName}
+ * {@link CommonField#updateTime}
+ *
+ *
+ * @param t 需要设置的对象
+ * @param ignoreProperties 忽略的字段
+ * @param
+ */
+ public static T setCommonField(T t, String... ignoreProperties) {
+ CommonField commonField = CommonField.builder()
+ .enabled(WhetherEnum.YES.getValue())
+ .valid(WhetherEnum.YES.getValue())
+ .createTime(LocalDateTime.now())
+ .creatorId(getLoginUser().getId())
+ .creatorName(getLoginUser().getUsername())
+ .updateTime(LocalDateTime.now())
+ .updaterId(getLoginUser().getId())
+ .updaterName(getLoginUser().getUsername())
+ .build();
+ BeanUtils.copyProperties(commonField, t, ignoreProperties);
+ return t;
+ }
+
+ /**
+ * 设置更新的公共字段值,一般用于更新记录,包含以下字段:
+ *
+ *
+ * {@link CommonField#updaterId}
+ * {@link CommonField#updaterName}
+ * {@link CommonField#updateTime}
+ *
+ *
+ * @param t 需要设置的对象
+ * @param
+ */
+ public static T setUpdateCommonField(T t) {
+ CommonField commonField = CommonField.builder()
+ .updaterId(getLoginUser().getId())
+ .updaterName(getLoginUser().getUsername())
+ .updateTime(LocalDateTime.now())
+ .build();
+ BeanUtils.copyProperties(commonField, t, "enabled", "valid");
+ return t;
+ }
+
+ @Data
+ @Builder
+ private static class CommonField implements Serializable {
+ /**
+ * 启用状态:0 、停用,1、启用
+ */
+ private Integer enabled;
+ /**
+ * 删除标志,是否有效:1 可用 0不可用
+ */
+ private Integer valid;
+
+
+ /**
+ * 创建人
+ */
+ private Long creatorId;
+ /**
+ * 创建人
+ */
+ private String creatorName;
+ /**
+ * 创建时间
+ */
+ private LocalDateTime createTime;
+
+
+ /**
+ * 更新人
+ */
+ private Long updaterId;
+ /**
+ * 更新人
+ */
+ private String updaterName;
+ /**
+ * 更新时间
+ */
+ private LocalDateTime updateTime;
+ }
+}
diff --git a/ym-admin/src/main/resources/mapper/SysLogLoginDao.xml b/ym-admin/src/main/resources/mapper/SysLogLoginDao.xml
new file mode 100644
index 0000000..587044e
--- /dev/null
+++ b/ym-admin/src/main/resources/mapper/SysLogLoginDao.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ym-common/src/main/java/com/cnbm/common/interceptor/DataFilterInterceptor.java b/ym-common/src/main/java/com/cnbm/common/interceptor/DataFilterInterceptor.java
new file mode 100644
index 0000000..9c8db8d
--- /dev/null
+++ b/ym-common/src/main/java/com/cnbm/common/interceptor/DataFilterInterceptor.java
@@ -0,0 +1,76 @@
+package com.cnbm.common.interceptor;
+
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.toolkit.PluginUtils;
+import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
+import net.sf.jsqlparser.JSQLParserException;
+import net.sf.jsqlparser.expression.Expression;
+import net.sf.jsqlparser.expression.StringValue;
+import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
+import net.sf.jsqlparser.parser.CCJSqlParserUtil;
+import net.sf.jsqlparser.statement.select.PlainSelect;
+import net.sf.jsqlparser.statement.select.Select;
+import org.apache.ibatis.executor.Executor;
+import org.apache.ibatis.mapping.BoundSql;
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.session.ResultHandler;
+import org.apache.ibatis.session.RowBounds;
+
+import java.util.Map;
+
+public class DataFilterInterceptor implements InnerInterceptor {
+
+ @Override
+ public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {
+ DataScope scope = getDataScope(parameter);
+ // 不进行数据过滤
+ if(scope == null || StrUtil.isBlank(scope.getSqlFilter())){
+ return;
+ }
+
+ // 拼接新SQL
+ String buildSql = getSelect(boundSql.getSql(), scope);
+
+ // 重写SQL
+ PluginUtils.mpBoundSql(boundSql).sql(buildSql);
+ }
+
+ private DataScope getDataScope(Object parameter){
+ if (parameter == null){
+ return null;
+ }
+
+ // 判断参数里是否有DataScope对象
+ if (parameter instanceof Map) {
+ Map, ?> parameterMap = (Map, ?>) parameter;
+ for (Map.Entry entry : parameterMap.entrySet()) {
+ if (entry.getValue() != null && entry.getValue() instanceof DataScope) {
+ return (DataScope) entry.getValue();
+ }
+ }
+ } else if (parameter instanceof DataScope) {
+ return (DataScope) parameter;
+ }
+
+ return null;
+ }
+
+ private String getSelect(String buildSql, DataScope scope){
+ try {
+ Select select = (Select) CCJSqlParserUtil.parse(buildSql);
+ PlainSelect plainSelect = (PlainSelect) select.getSelectBody();
+
+ Expression expression = plainSelect.getWhere();
+ if(expression == null){
+ plainSelect.setWhere(new StringValue(scope.getSqlFilter()));
+ }else{
+ AndExpression andExpression = new AndExpression(expression, new StringValue(scope.getSqlFilter()));
+ plainSelect.setWhere(andExpression);
+ }
+
+ return select.toString().replaceAll("'", "");
+ }catch (JSQLParserException e){
+ return buildSql;
+ }
+ }
+}
diff --git a/ym-common/src/main/java/com/cnbm/common/interceptor/DataScope.java b/ym-common/src/main/java/com/cnbm/common/interceptor/DataScope.java
new file mode 100644
index 0000000..1f7f8a2
--- /dev/null
+++ b/ym-common/src/main/java/com/cnbm/common/interceptor/DataScope.java
@@ -0,0 +1,22 @@
+package com.cnbm.common.interceptor;
+
+public class DataScope {
+ private String sqlFilter;
+
+ public DataScope(String sqlFilter) {
+ this.sqlFilter = sqlFilter;
+ }
+
+ public String getSqlFilter() {
+ return sqlFilter;
+ }
+
+ public void setSqlFilter(String sqlFilter) {
+ this.sqlFilter = sqlFilter;
+ }
+
+ @Override
+ public String toString() {
+ return this.sqlFilter;
+ }
+}
diff --git a/ym-gateway/src/main/resources/application-dev.yml b/ym-gateway/src/main/resources/application-dev.yml
index 39984e5..be3f5ed 100644
--- a/ym-gateway/src/main/resources/application-dev.yml
+++ b/ym-gateway/src/main/resources/application-dev.yml
@@ -20,10 +20,36 @@ spring:
# url: jdbc:postgresql://192.168.10.10:5432/postgres
# username: postgres
# password: 123456
- hikari:
- pool-name: GrowUpHikariCP
- minimum-idle: 1
- maximum-pool-size: 10
+ initial-size: 10
+ max-active: 100
+ min-idle: 10
+ max-wait: 60000
+ pool-prepared-statements: true
+ max-pool-prepared-statement-per-connection-size: 20
+ time-between-eviction-runs-millis: 60000
+ min-evictable-idle-time-millis: 300000
+ #Oracle需要打开注释
+ #validation-query: SELECT 1 FROM DUAL
+ test-while-idle: true
+ test-on-borrow: false
+ test-on-return: false
+ stat-view-servlet:
+ enabled: true
+ url-pattern: /druid/*
+ #login-username: admin
+ #login-password: admin
+ filter:
+ stat:
+ log-slow-sql: true
+ slow-sql-millis: 1000
+ merge-sql: false
+ wall:
+ config:
+ multi-statement-allow: true
+# hikari:
+# pool-name: GrowUpHikariCP
+# minimum-idle: 1
+# maximum-pool-size: 10
##多数据源的配置,需要引用renren-dynamic-datasource
#dynamic:
diff --git a/ym-gateway/src/main/resources/logback-spring.xml b/ym-gateway/src/main/resources/logback-spring.xml
new file mode 100644
index 0000000..7111d2f
--- /dev/null
+++ b/ym-gateway/src/main/resources/logback-spring.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ym-generator/src/main/resources/templates/controller.java.vm b/ym-generator/src/main/resources/templates/controller.java.vm
index fc2f2b1..ebd19b7 100644
--- a/ym-generator/src/main/resources/templates/controller.java.vm
+++ b/ym-generator/src/main/resources/templates/controller.java.vm
@@ -68,26 +68,26 @@ public class ${table.controllerName} {
@ApiOperation("保存")
@LogOperation("保存")
@PreAuthorize("@ex.hasAuthority('${package.ModuleName}:${table.entityPath}:save')")
- public Result save(@RequestBody ${entity}DTO dto){
+ public Result save(@RequestBody ${entity}DTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
${table.entityPath}Service.save(dto);
- return new Result();
+ return new Result().ok(dto.getId());
}
@PutMapping
@ApiOperation("修改")
@LogOperation("修改")
@PreAuthorize("@ex.hasAuthority('${package.ModuleName}:${table.entityPath}:update')")
- public Result update(@RequestBody ${entity}DTO dto){
+ public Result update(@RequestBody ${entity}DTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
${table.entityPath}Service.update(dto);
- return new Result();
+ return new Result().ok(dto.getId());
}
@DeleteMapping
diff --git a/ym-generator/src/main/resources/templates/mapper.xml.vm b/ym-generator/src/main/resources/templates/mapper.xml.vm
index b0909e8..49be86c 100644
--- a/ym-generator/src/main/resources/templates/mapper.xml.vm
+++ b/ym-generator/src/main/resources/templates/mapper.xml.vm
@@ -1,39 +1,10 @@
-
-#if(${enableCache})
-
-
-
-#end
-#if(${baseResultMap})
-
-
-#foreach($field in ${table.fields})
-#if(${field.keyFlag})##生成主键排在第一位
-
-#end
-#end
-#foreach($field in ${table.commonFields})##生成公共字段
-
-#end
-#foreach($field in ${table.fields})
-#if(!${field.keyFlag})##生成普通字段
-
-#end
-#end
+
+ #foreach($field in ${table.fields})
+
+ #end
-#end
-#if(${baseColumnList})
-
-
-#foreach($field in ${table.commonFields})
- ${field.columnName},
-#end
- ${table.fieldNames}
-
-
-#end