Procházet zdrojové kódy

feat: full implementation of zzbusiness-user module

zj před 2 roky
rodič
revize
5b11206228
27 změnil soubory, kde provedl 1431 přidání a 41 odebrání
  1. 48 0
      doc/zz_business.sql
  2. 8 0
      zzbusiness-common/pom.xml
  3. 83 0
      zzbusiness-common/src/main/java/org/zhongzheng/common/doentity/Tenant.java
  4. 19 0
      zzbusiness-common/src/main/java/org/zhongzheng/common/env/RoleConstant.java
  5. 32 0
      zzbusiness-common/src/main/java/org/zhongzheng/common/env/ZhongZhengConstant.java
  6. 1 1
      zzbusiness-common/src/main/java/org/zhongzheng/common/feignclient/zzbusinessuser/entity/UserOauth.java
  7. 29 0
      zzbusiness-common/src/main/java/org/zhongzheng/common/mybatisplus/BaseEntityWrapper.java
  8. 15 0
      zzbusiness-common/src/main/java/org/zhongzheng/common/mybatisplus/BaseService.java
  9. 58 0
      zzbusiness-common/src/main/java/org/zhongzheng/common/mybatisplus/BaseServiceImpl.java
  10. 65 0
      zzbusiness-common/src/main/java/org/zhongzheng/common/mybatisplus/Condition.java
  11. 1 1
      zzbusiness-common/src/main/java/org/zhongzheng/common/mybatisplus/MybatisPlusConfig.java
  12. 147 0
      zzbusiness-common/src/main/java/org/zhongzheng/common/mybatisplus/Query.java
  13. 116 0
      zzbusiness-common/src/main/java/org/zhongzheng/common/mybatisplus/SqlKeyword.java
  14. 4 4
      zzbusiness-common/src/main/java/org/zhongzheng/common/secure/SecureUtil.java
  15. 1 1
      zzbusiness-common/src/main/java/org/zhongzheng/common/secure/ZhongZhengTokenProperties.java
  16. 21 0
      zzbusiness-common/src/main/java/org/zhongzheng/common/secure/annotation/PreAuth.java
  17. 8 0
      zzbusiness-user/pom.xml
  18. 3 0
      zzbusiness-user/src/main/java/org/zhongzheng/user/UserApplication.java
  19. 193 33
      zzbusiness-user/src/main/java/org/zhongzheng/user/controller/UserController.java
  20. 44 0
      zzbusiness-user/src/main/java/org/zhongzheng/user/feign/UserClient.java
  21. 79 0
      zzbusiness-user/src/main/java/org/zhongzheng/user/mapper/UserMapper.java
  22. 92 0
      zzbusiness-user/src/main/java/org/zhongzheng/user/mapper/UserMapper.xml
  23. 112 0
      zzbusiness-user/src/main/java/org/zhongzheng/user/service/IUserService.java
  24. 131 0
      zzbusiness-user/src/main/java/org/zhongzheng/user/service/impl/UserServiceImpl.java
  25. 62 0
      zzbusiness-user/src/main/java/org/zhongzheng/user/vo/UserVO.java
  26. 58 0
      zzbusiness-user/src/main/java/org/zhongzheng/user/wrapper/UserWrapper.java
  27. 1 1
      zzbusiness-user/src/main/resources/application.yml

+ 48 - 0
doc/zz_business.sql

@@ -34,3 +34,51 @@ CREATE TABLE `zhongzheng_user`  (
 BEGIN;
 INSERT INTO `zhongzheng_user` VALUES (1123598821738675201, '000000', NULL, 'admin', '90b9aa7e25f80cf4f64e990b78a9fc5ebd6cecad', '管理员', '管理员', '', 'admin@bladex.vip', '22233322', '2018-08-08 00:00:00', 1, '1123598816738675201', '1123598813738675201', '1123598817738675201', 1123598821738675201, 1123598813738675201, '2018-08-08 00:00:00', 1123598821738675201, '2018-08-08 00:00:00', 1, 0);
 COMMIT;
+
+
+-- ----------------------------
+-- Table structure for zhongzheng_role
+-- ----------------------------
+DROP TABLE IF EXISTS `zhongzheng_role`;
+CREATE TABLE `zhongzheng_role`  (
+  `id` bigint(20) NOT NULL COMMENT '主键',
+  `tenant_id` varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '000000' COMMENT '租户ID',
+  `parent_id` bigint(20) NULL DEFAULT 0 COMMENT '父主键',
+  `role_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '角色名',
+  `sort` int(11) NULL DEFAULT NULL COMMENT '排序',
+  `role_alias` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '角色别名',
+  `is_deleted` int(2) NULL DEFAULT 0 COMMENT '是否已删除',
+  PRIMARY KEY (`id`) USING BTREE
+) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '角色表';
+
+-- ----------------------------
+-- Records of zhongzheng_role
+-- ----------------------------
+BEGIN;
+INSERT INTO `zhongzheng_role` VALUES (1123598816738675201, '000000', 0, '超级管理员', 1, 'administrator', 0), (1123598816738675202, '000000', 0, '用户', 2, 'user', 0);
+COMMIT;
+
+
+-- ----------------------------
+-- Table structure for zhongzheng_dept
+-- ----------------------------
+DROP TABLE IF EXISTS `zhongzheng_dept`;
+CREATE TABLE `zhongzheng_dept`  (
+  `id` bigint(20) NOT NULL COMMENT '主键',
+  `tenant_id` varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '000000' COMMENT '租户ID',
+  `parent_id` bigint(20) NULL DEFAULT 0 COMMENT '父主键',
+  `ancestors` varchar(2000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '祖级列表',
+  `dept_name` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '部门名',
+  `full_name` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '部门全称',
+  `sort` int(11) NULL DEFAULT NULL COMMENT '排序',
+  `remark` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '备注',
+  `is_deleted` int(2) NULL DEFAULT 0 COMMENT '是否已删除',
+  PRIMARY KEY (`id`) USING BTREE
+) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '部门表';
+
+-- ----------------------------
+-- Records of zhongzheng_dept
+-- ----------------------------
+BEGIN;
+INSERT INTO `zhongzheng_dept` VALUES (1123598813738675201, '000000', 0, '0', '中正教育科技', '广州中正教育科技有限公司', 1, NULL, 0), (1123598813738675202, '000000', 1123598813738675201, '0,1123598813738675201', '深圳中正教育', '深圳中正教育科技有限公司', 1, NULL, 0);
+COMMIT;

+ 8 - 0
zzbusiness-common/pom.xml

@@ -155,6 +155,14 @@
             <artifactId>easypoi-base</artifactId>
             <version>4.1.0</version>
         </dependency>
+
+        <!-- validation-api -->
+        <dependency>
+            <groupId>javax.validation</groupId>
+            <artifactId>validation-api</artifactId>
+            <version>2.0.1.Final</version>
+        </dependency>
+
     </dependencies>
 
     <build>

+ 83 - 0
zzbusiness-common/src/main/java/org/zhongzheng/common/doentity/Tenant.java

@@ -0,0 +1,83 @@
+package org.zhongzheng.common.doentity;
+
+/**
+ * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.zhongzheng.common.doentity.BaseEntity;
+
+/**
+ * 实体类
+ *
+ * @author Chill
+ */
+@Data
+@TableName("zhongzheng_tenant")
+@EqualsAndHashCode(callSuper = true)
+@ApiModel(value = "Tenant对象", description = "Tenant对象")
+public class Tenant extends BaseEntity {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键id
+     */
+    @ApiModelProperty(value = "主键")
+    @TableId(value = "id", type = IdType.ASSIGN_ID)
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long id;
+
+    /**
+     * 租户ID
+     */
+    @ApiModelProperty(value = "租户ID")
+    private String tenantId;
+    /**
+     * 租户名称
+     */
+    @ApiModelProperty(value = "租户名称")
+    private String tenantName;
+    /**
+     * 域名地址
+     */
+    @ApiModelProperty(value = "域名地址")
+    private String domain;
+    /**
+     * 联系人
+     */
+    @ApiModelProperty(value = "联系人")
+    private String linkman;
+    /**
+     * 联系电话
+     */
+    @ApiModelProperty(value = "联系电话")
+    private String contactNumber;
+    /**
+     * 联系地址
+     */
+    @ApiModelProperty(value = "联系地址")
+    private String address;
+
+
+}

+ 19 - 0
zzbusiness-common/src/main/java/org/zhongzheng/common/env/RoleConstant.java

@@ -0,0 +1,19 @@
+package org.zhongzheng.common.env;
+
+//
+// Source code recreated from a .class file by IntelliJ IDEA
+// (powered by FernFlower decompiler)
+//
+
+public class RoleConstant {
+    public static final String ADMIN = "administrator";
+    public static final String HAS_ROLE_ADMIN = "hasRole('administrator')";
+    public static final String USER = "user";
+    public static final String HAS_ROLE_USER = "hasRole('user')";
+    public static final String TEST = "test";
+    public static final String HAS_ROLE_TEST = "hasRole('test')";
+    public static final String HAS_CRYPTO = "hasCrypto()";
+
+    public RoleConstant() {
+    }
+}

+ 32 - 0
zzbusiness-common/src/main/java/org/zhongzheng/common/env/ZhongZhengConstant.java

@@ -0,0 +1,32 @@
+package org.zhongzheng.common.env;
+
+//
+// Source code recreated from a .class file by IntelliJ IDEA
+// (powered by FernFlower decompiler)
+//
+
+public interface ZhongZhengConstant {
+    String UTF_8 = "UTF-8";
+    String CONTENT_TYPE_NAME = "Content-type";
+    String CONTENT_TYPE = "application/json;charset=utf-8";
+    String SECURITY_ROLE_PREFIX = "ROLE_";
+    String DB_PRIMARY_KEY = "id";
+    int DB_STATUS_NORMAL = 1;
+    int DB_NOT_DELETED = 0;
+    int DB_IS_DELETED = 1;
+    int DB_ADMIN_NON_LOCKED = 0;
+    int DB_ADMIN_LOCKED = 1;
+    Long TOP_PARENT_ID = 0L;
+    String TOP_PARENT_NAME = "顶级";
+    String ADMIN_TENANT_ID = "000000";
+    String LOG_NORMAL_TYPE = "1";
+    String DEFAULT_NULL_MESSAGE = "暂无承载数据";
+    String DEFAULT_SUCCESS_MESSAGE = "操作成功";
+    String DEFAULT_FAILURE_MESSAGE = "操作失败";
+    String DEFAULT_UNAUTHORIZED_MESSAGE = "签名认证失败";
+
+    /**
+     * 默认密码
+     */
+    String DEFAULT_PASSWORD = "123456";
+}

+ 1 - 1
zzbusiness-common/src/main/java/org/zhongzheng/common/feignclient/zzbusinessuser/entity/UserOauth.java

@@ -31,7 +31,7 @@ import java.io.Serializable;
  * @author Chill
  */
 @Data
-@TableName("blade_user_oauth")
+@TableName("zhongzheng_user_oauth")
 public class UserOauth implements Serializable {
 
 	private static final long serialVersionUID = 1L;

+ 29 - 0
zzbusiness-common/src/main/java/org/zhongzheng/common/mybatisplus/BaseEntityWrapper.java

@@ -0,0 +1,29 @@
+package org.zhongzheng.common.mybatisplus;
+
+//
+// Source code recreated from a .class file by IntelliJ IDEA
+// (powered by FernFlower decompiler)
+//
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public abstract class BaseEntityWrapper<E, V> {
+    public BaseEntityWrapper() {
+    }
+
+    public abstract V entityVO(E entity);
+
+    public List<V> listVO(List<E> list) {
+        return (List)list.stream().map(this::entityVO).collect(Collectors.toList());
+    }
+
+    public IPage<V> pageVO(IPage<E> pages) {
+        List<V> records = this.listVO(pages.getRecords());
+        IPage<V> pageVo = new Page(pages.getCurrent(), pages.getSize(), pages.getTotal());
+        pageVo.setRecords(records);
+        return pageVo;
+    }
+}

+ 15 - 0
zzbusiness-common/src/main/java/org/zhongzheng/common/mybatisplus/BaseService.java

@@ -0,0 +1,15 @@
+package org.zhongzheng.common.mybatisplus;
+
+//
+// Source code recreated from a .class file by IntelliJ IDEA
+// (powered by FernFlower decompiler)
+//
+
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import java.util.List;
+import javax.validation.constraints.NotEmpty;
+
+public interface BaseService<T> extends IService<T> {
+    boolean deleteLogic(@NotEmpty List<Long> ids);
+}

+ 58 - 0
zzbusiness-common/src/main/java/org/zhongzheng/common/mybatisplus/BaseServiceImpl.java

@@ -0,0 +1,58 @@
+package org.zhongzheng.common.mybatisplus;
+
+//
+// Source code recreated from a .class file by IntelliJ IDEA
+// (powered by FernFlower decompiler)
+//
+
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import java.util.Date;
+import java.util.List;
+import javax.validation.constraints.NotEmpty;
+
+import org.zhongzheng.common.doentity.BaseEntity;
+import org.zhongzheng.common.secure.ZhongZhengUser;
+import org.zhongzheng.common.secure.SecureUtil;
+import org.zhongzheng.common.utils.DateUtil;
+import org.springframework.validation.annotation.Validated;
+
+@Validated
+public class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseEntity> extends ServiceImpl<M, T> implements BaseService<T> {
+    public BaseServiceImpl() {
+    }
+
+    public boolean save(T entity) {
+        ZhongZhengUser user = SecureUtil.getUser();
+        if (user != null) {
+            entity.setCreateUser(user.getUserId());
+            entity.setUpdateUser(user.getUserId());
+        }
+
+        Date now = DateUtil.now();
+        entity.setCreateTime(now);
+        entity.setUpdateTime(now);
+        if (entity.getStatus() == null) {
+            entity.setStatus(1);
+        }
+
+        entity.setIsDeleted(0);
+        return super.save(entity);
+    }
+
+    public boolean updateById(T entity) {
+        ZhongZhengUser user = SecureUtil.getUser();
+        if (user != null) {
+            entity.setUpdateUser(user.getUserId());
+        }
+
+        entity.setUpdateTime(DateUtil.now());
+        return super.updateById(entity);
+    }
+
+    public boolean deleteLogic(@NotEmpty List<Long> ids) {
+        return super.removeByIds(ids);
+    }
+}
+

+ 65 - 0
zzbusiness-common/src/main/java/org/zhongzheng/common/mybatisplus/Condition.java

@@ -0,0 +1,65 @@
+package org.zhongzheng.common.mybatisplus;
+
+//
+// Source code recreated from a .class file by IntelliJ IDEA
+// (powered by FernFlower decompiler)
+//
+
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.metadata.OrderItem;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import java.util.Map;
+import org.zhongzheng.common.utils.Kv;
+import org.zhongzheng.common.utils.BeanUtil;
+import org.zhongzheng.common.utils.Func;
+import org.zhongzheng.common.utils.StringUtil;
+
+public class Condition {
+    public Condition() {
+    }
+
+    public static <T> IPage<T> getPage(Query query) {
+        Page<T> page = new Page((long)Func.toInt(query.getCurrent(), 1), (long)Func.toInt(query.getSize(), 10));
+        String[] ascArr = Func.toStrArray(query.getAscs());
+        String[] descArr = ascArr;
+        int var4 = ascArr.length;
+
+        int var5;
+        for(var5 = 0; var5 < var4; ++var5) {
+            String asc = descArr[var5];
+            page.addOrder(new OrderItem[]{OrderItem.asc(StringUtil.cleanIdentifier(asc))});
+        }
+
+        descArr = Func.toStrArray(query.getDescs());
+        String[] var8 = descArr;
+        var5 = descArr.length;
+
+        for(int var9 = 0; var9 < var5; ++var9) {
+            String desc = var8[var9];
+            page.addOrder(new OrderItem[]{OrderItem.desc(StringUtil.cleanIdentifier(desc))});
+        }
+
+        return page;
+    }
+
+    public static <T> QueryWrapper<T> getQueryWrapper(T entity) throws java.sql.SQLException {
+        return new QueryWrapper(entity);
+    }
+
+    public static <T> QueryWrapper<T> getQueryWrapper(Map<String, Object> query, Class<T> clazz) throws java.sql.SQLException {
+        Kv exclude = Kv.init().set("zhongzheng-auth", "zhongzheng-auth").set("current", "current").set("size", "size").set("ascs", "ascs").set("descs", "descs");
+        return getQueryWrapper(query, exclude, clazz);
+    }
+
+    public static <T> QueryWrapper<T> getQueryWrapper(Map<String, Object> query, Map<String, Object> exclude, Class<T> clazz) throws java.sql.SQLException {
+        exclude.forEach((k, v) -> {
+            query.remove(k);
+        });
+        QueryWrapper<T> qw = new QueryWrapper();
+        qw.setEntity(BeanUtil.newInstance(clazz));
+        SqlKeyword.buildCondition(query, qw);
+        return qw;
+    }
+}

+ 1 - 1
zzbusiness-common/src/main/java/org/zhongzheng/common/mybatisplus/MybatisPlusConfig.java

@@ -8,7 +8,7 @@ import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
 @Configuration
-//@MapperScan("org.zhongzheng.*.domian")
+@MapperScan("org.zhongzheng.**.mapper.**")
 public class MybatisPlusConfig {
 
 	@Bean

+ 147 - 0
zzbusiness-common/src/main/java/org/zhongzheng/common/mybatisplus/Query.java

@@ -0,0 +1,147 @@
+package org.zhongzheng.common.mybatisplus;
+
+//
+// Source code recreated from a .class file by IntelliJ IDEA
+// (powered by FernFlower decompiler)
+//
+
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+@ApiModel(
+        description = "查询条件"
+)
+public class Query {
+    @ApiModelProperty("当前页")
+    private Integer current;
+    @ApiModelProperty("每页的数量")
+    private Integer size;
+    @ApiModelProperty(
+            hidden = true
+    )
+    private String ascs;
+    @ApiModelProperty(
+            hidden = true
+    )
+    private String descs;
+
+    public Query() {
+    }
+
+    public Integer getCurrent() {
+        return this.current;
+    }
+
+    public Integer getSize() {
+        return this.size;
+    }
+
+    public String getAscs() {
+        return this.ascs;
+    }
+
+    public String getDescs() {
+        return this.descs;
+    }
+
+    public Query setCurrent(final Integer current) {
+        this.current = current;
+        return this;
+    }
+
+    public Query setSize(final Integer size) {
+        this.size = size;
+        return this;
+    }
+
+    public Query setAscs(final String ascs) {
+        this.ascs = ascs;
+        return this;
+    }
+
+    public Query setDescs(final String descs) {
+        this.descs = descs;
+        return this;
+    }
+
+    public boolean equals(final Object o) {
+        if (o == this) {
+            return true;
+        } else if (!(o instanceof Query)) {
+            return false;
+        } else {
+            Query other = (Query)o;
+            if (!other.canEqual(this)) {
+                return false;
+            } else {
+                label59: {
+                    Object this$current = this.getCurrent();
+                    Object other$current = other.getCurrent();
+                    if (this$current == null) {
+                        if (other$current == null) {
+                            break label59;
+                        }
+                    } else if (this$current.equals(other$current)) {
+                        break label59;
+                    }
+
+                    return false;
+                }
+
+                Object this$size = this.getSize();
+                Object other$size = other.getSize();
+                if (this$size == null) {
+                    if (other$size != null) {
+                        return false;
+                    }
+                } else if (!this$size.equals(other$size)) {
+                    return false;
+                }
+
+                Object this$ascs = this.getAscs();
+                Object other$ascs = other.getAscs();
+                if (this$ascs == null) {
+                    if (other$ascs != null) {
+                        return false;
+                    }
+                } else if (!this$ascs.equals(other$ascs)) {
+                    return false;
+                }
+
+                Object this$descs = this.getDescs();
+                Object other$descs = other.getDescs();
+                if (this$descs == null) {
+                    if (other$descs != null) {
+                        return false;
+                    }
+                } else if (!this$descs.equals(other$descs)) {
+                    return false;
+                }
+
+                return true;
+            }
+        }
+    }
+
+    protected boolean canEqual(final Object other) {
+        return other instanceof Query;
+    }
+
+    public int hashCode() {
+        int result = 1;
+        Object $current = this.getCurrent();
+        result = result * 59 + ($current == null ? 43 : $current.hashCode());
+        Object $size = this.getSize();
+        result = result * 59 + ($size == null ? 43 : $size.hashCode());
+        Object $ascs = this.getAscs();
+        result = result * 59 + ($ascs == null ? 43 : $ascs.hashCode());
+        Object $descs = this.getDescs();
+        result = result * 59 + ($descs == null ? 43 : $descs.hashCode());
+        return result;
+    }
+
+    public String toString() {
+        return "Query(current=" + this.getCurrent() + ", size=" + this.getSize() + ", ascs=" + this.getAscs() + ", descs=" + this.getDescs() + ")";
+    }
+}

+ 116 - 0
zzbusiness-common/src/main/java/org/zhongzheng/common/mybatisplus/SqlKeyword.java

@@ -0,0 +1,116 @@
+package org.zhongzheng.common.mybatisplus;
+
+//
+// Source code recreated from a .class file by IntelliJ IDEA
+// (powered by FernFlower decompiler)
+//
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import java.sql.SQLException;
+import java.util.Map;
+import java.util.regex.Pattern;
+import org.zhongzheng.common.utils.DateUtil;
+import org.zhongzheng.common.utils.Func;
+import org.zhongzheng.common.utils.StringUtil;
+
+public class SqlKeyword {
+    private static final String SQL_REGEX = "(?i)(?<![a-z])('|%|--|insert|delete|select|sleep|count|updatexml|group|union|drop|truncate|alter|grant|execute|exec|xp_cmdshell|call|declare|sql)(?![a-z])";
+    private static final Pattern PATTERN = Pattern.compile("(?:--|[\"';%]|\\binsert\\b|\\bdelete\\b|\\bselect\\b|\\bcount\\b|\\bupdatexml\\b|\\bsleep\\b|group\\s+by|\\bunion\\b|\\bdrop\\b|\\btruncate\\b|\\balter\\b|\\bgrant\\b|\\bexecute\\b|\\bxp_cmdshell\\b|\\bcall\\b|\\bdeclare\\b|\\bsql\\b)");
+    private static final String SQL_INJECTION_MESSAGE = "SQL keyword injection prevention processing!";
+    private static final String EQUAL = "_equal";
+    private static final String NOT_EQUAL = "_notequal";
+    private static final String LIKE = "_like";
+    private static final String LIKE_LEFT = "_likeleft";
+    private static final String LIKE_RIGHT = "_likeright";
+    private static final String NOT_LIKE = "_notlike";
+    private static final String GE = "_ge";
+    private static final String LE = "_le";
+    private static final String GT = "_gt";
+    private static final String LT = "_lt";
+    private static final String DATE_GE = "_datege";
+    private static final String DATE_GT = "_dategt";
+    private static final String DATE_EQUAL = "_dateequal";
+    private static final String DATE_LT = "_datelt";
+    private static final String DATE_LE = "_datele";
+    private static final String IS_NULL = "_null";
+    private static final String NOT_NULL = "_notnull";
+    private static final String IGNORE = "_ignore";
+
+    public SqlKeyword() {
+    }
+
+    public static void buildCondition(Map<String, Object> query, QueryWrapper<?> qw) throws  java.sql.SQLException {
+        if (!Func.isEmpty(query)) {
+            query.forEach((k, v) -> {
+                if (!Func.hasEmpty(new Object[]{k, v}) && !k.endsWith("_ignore")) {
+                    try {
+                        k = filter(k);
+                    } catch (SQLException e) {
+                        throw new RuntimeException(e);
+                    }
+                    if (k.endsWith("_equal")) {
+                        qw.eq(getColumn(k, "_equal"), v);
+                    } else if (k.endsWith("_notequal")) {
+                        qw.ne(getColumn(k, "_notequal"), v);
+                    } else if (k.endsWith("_likeleft")) {
+                        qw.likeLeft(getColumn(k, "_likeleft"), v);
+                    } else if (k.endsWith("_likeright")) {
+                        qw.likeRight(getColumn(k, "_likeright"), v);
+                    } else if (k.endsWith("_notlike")) {
+                        qw.notLike(getColumn(k, "_notlike"), v);
+                    } else if (k.endsWith("_ge")) {
+                        qw.ge(getColumn(k, "_ge"), v);
+                    } else if (k.endsWith("_le")) {
+                        qw.le(getColumn(k, "_le"), v);
+                    } else if (k.endsWith("_gt")) {
+                        qw.gt(getColumn(k, "_gt"), v);
+                    } else if (k.endsWith("_lt")) {
+                        qw.lt(getColumn(k, "_lt"), v);
+                    } else if (k.endsWith("_datege")) {
+                        qw.ge(getColumn(k, "_datege"), DateUtil.parse(String.valueOf(v), "yyyy-MM-dd HH:mm:ss"));
+                    } else if (k.endsWith("_dategt")) {
+                        qw.gt(getColumn(k, "_dategt"), DateUtil.parse(String.valueOf(v), "yyyy-MM-dd HH:mm:ss"));
+                    } else if (k.endsWith("_dateequal")) {
+                        qw.eq(getColumn(k, "_dateequal"), DateUtil.parse(String.valueOf(v), "yyyy-MM-dd HH:mm:ss"));
+                    } else if (k.endsWith("_datele")) {
+                        qw.le(getColumn(k, "_datele"), DateUtil.parse(String.valueOf(v), "yyyy-MM-dd HH:mm:ss"));
+                    } else if (k.endsWith("_datelt")) {
+                        qw.lt(getColumn(k, "_datelt"), DateUtil.parse(String.valueOf(v), "yyyy-MM-dd HH:mm:ss"));
+                    } else if (k.endsWith("_null")) {
+                        qw.isNull(getColumn(k, "_null"));
+                    } else if (k.endsWith("_notnull")) {
+                        qw.isNotNull(getColumn(k, "_notnull"));
+                    } else {
+                        qw.like(getColumn(k, "_like"), v);
+                    }
+
+                }
+            });
+        }
+    }
+
+    private static String getColumn(String column, String keyword) {
+        return StringUtil.humpToUnderline(StringUtil.removeSuffix(column, keyword));
+    }
+
+    public static String filter(String param) throws  java.sql.SQLException{
+        try {
+            if (param == null) {
+                return null;
+            } else {
+                String sql = param.replaceAll("(?i)(?<![a-z])('|%|--|insert|delete|select|sleep|count|updatexml|group|union|drop|truncate|alter|grant|execute|exec|xp_cmdshell|call|declare|sql)(?![a-z])", "");
+                if (match(sql)) {
+                    throw new SQLException("SQL keyword injection prevention processing!");
+                } else {
+                    return sql;
+                }
+            }
+        } catch (SQLException var2) {
+            throw var2;
+        }
+    }
+
+    public static Boolean match(String param) {
+        return Func.isNotEmpty(param) && PATTERN.matcher(param).find();
+    }
+}

+ 4 - 4
zzbusiness-common/src/main/java/org/zhongzheng/common/secure/SecureUtil.java

@@ -36,7 +36,7 @@ import org.zhongzheng.common.utils.WebUtil;
 
 public class SecureUtil {
     private static final String ZHONGZHENG_USER_REQUEST_ATTR = "_ZHONGZHENG_USER_REQUEST_ATTR_";
-    private static final String HEADER = "blade-auth";
+    private static final String HEADER = "zhongzheng-auth";
     private static final String BEARER = "bearer";
     private static final String CRYPTO = "crypto";
     private static final String ACCOUNT = "account";
@@ -187,8 +187,8 @@ public class SecureUtil {
     }
 
     public static Claims getClaims(HttpServletRequest request) {
-        String auth = request.getHeader("blade-auth");
-        String token = getToken(StringUtil.isNotBlank(auth) ? auth : request.getParameter("blade-auth"));
+        String auth = request.getHeader("zhongzheng-auth");
+        String token = getToken(StringUtil.isNotBlank(auth) ? auth : request.getParameter("zhongzheng-auth"));
         return parseJWT(token);
     }
 
@@ -223,7 +223,7 @@ public class SecureUtil {
     }
 
     public static String getHeader(HttpServletRequest request) {
-        return request.getHeader("blade-auth");
+        return request.getHeader("zhongzheng-auth");
     }
 
     public static Claims parseJWT(String jsonWebToken) {

+ 1 - 1
zzbusiness-common/src/main/java/org/zhongzheng/common/secure/ZhongZhengTokenProperties.java

@@ -11,7 +11,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 
-@ConfigurationProperties("blade.token")
+@ConfigurationProperties("zhongzheng.token")
 public class ZhongZhengTokenProperties {
     private static final Logger log = LoggerFactory.getLogger(ZhongZhengTokenProperties.class);
     private String signKey = "";

+ 21 - 0
zzbusiness-common/src/main/java/org/zhongzheng/common/secure/annotation/PreAuth.java

@@ -0,0 +1,21 @@
+package org.zhongzheng.common.secure.annotation;
+
+//
+// Source code recreated from a .class file by IntelliJ IDEA
+// (powered by FernFlower decompiler)
+//
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target({ElementType.METHOD, ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+@Inherited
+@Documented
+public @interface PreAuth {
+    String value();
+}

+ 8 - 0
zzbusiness-user/pom.xml

@@ -37,6 +37,14 @@
             <version>${mysql.connector.version}</version>
         </dependency>
 
+
+        <dependency>
+            <groupId>com.github.xiaoymin</groupId>
+            <artifactId>knife4j-annotations</artifactId>
+            <version>3.0.3</version>
+        </dependency>
+
+
         <dependency>
             <groupId>org.zhongzheng</groupId>
             <artifactId>zzbusiness-common</artifactId>

+ 3 - 0
zzbusiness-user/src/main/java/org/zhongzheng/user/UserApplication.java

@@ -1,6 +1,7 @@
 package org.zhongzheng.user;
 
 
+import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -8,6 +9,7 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
 import org.springframework.cloud.client.loadbalancer.LoadBalanced;
 import org.springframework.cloud.openfeign.EnableFeignClients;
 import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.client.RestTemplate;
@@ -17,6 +19,7 @@ import org.springframework.web.client.RestTemplate;
 @EnableFeignClients
 @EnableDiscoveryClient  //开启服务注册发现功能
 @RestController
+@ComponentScan(basePackages = {"org.zhongzheng.common","org.zhongzheng.user"})
 public class UserApplication {
 
     public static void main(String[] args) {

+ 193 - 33
zzbusiness-user/src/main/java/org/zhongzheng/user/controller/UserController.java

@@ -1,41 +1,201 @@
+/**
+ * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.zhongzheng.user.controller;
 
 
-import org.zhongzheng.common.feignclient.zzbusinessuser.IUserClient;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import lombok.AllArgsConstructor;
+import lombok.SneakyThrows;
+import org.zhongzheng.common.mybatisplus.Condition;
+import org.zhongzheng.common.mybatisplus.Query;
+import org.zhongzheng.common.secure.ZhongZhengUser;
+import org.zhongzheng.common.secure.annotation.PreAuth;
+import org.zhongzheng.common.secure.SecureUtil;
 import org.zhongzheng.common.utils.R;
+import org.zhongzheng.common.env.ZhongZhengConstant;
+import org.zhongzheng.common.env.RoleConstant;
+import org.zhongzheng.common.utils.Func;
 import org.zhongzheng.common.feignclient.zzbusinessuser.entity.User;
-import org.zhongzheng.common.feignclient.zzbusinessuser.entity.UserInfo;
-import org.zhongzheng.common.feignclient.zzbusinessuser.entity.UserOauth;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.bind.annotation.RequestMapping;
+import org.zhongzheng.user.service.IUserService;
+import org.zhongzheng.user.vo.UserVO;
+import org.zhongzheng.user.wrapper.UserWrapper;
+import org.springframework.util.StringUtils;
+import org.springframework.web.bind.annotation.*;
+import springfox.documentation.annotations.ApiIgnore;
 
+import javax.servlet.http.HttpServletResponse;
+import javax.validation.Valid;
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 控制器
+ *
+ * @author Chill
+ */
 @RestController
-@RequestMapping("/user")
-public class UserController implements IUserClient {
-    //private IUserService service;
-
-    @Override
-    public R<UserInfo> userInfo(Long userId) {
-        return R.data( new UserInfo());
-    }
-
-    @Override
-    @GetMapping(API_PREFIX + "/user-info")
-    public R<UserInfo> userInfo(String tenantId, String account, String password) {
-        return R.data( new UserInfo());
-    }
-
-    @Override
-    @PostMapping(API_PREFIX + "/user-auth-info")
-    public R<UserInfo> userAuthInfo(UserOauth userOauth) {
-        return R.data( new UserInfo());
-    }
-
-    @Override
-    @PostMapping(API_PREFIX + "/save-user")
-    public R<Boolean> saveUser(User user) {
-        return R.data( false );
-    }
+@RequestMapping
+@AllArgsConstructor
+public class UserController {
+
+	private IUserService userService;
+
+	/**
+	 * 查询单条
+	 */
+	@ApiOperationSupport(order = 1)
+	@ApiOperation(value = "查看详情", notes = "传入id")
+	@GetMapping("/detail")
+	public R<UserVO> detail(User user) throws SQLException {
+		User detail = userService.getOne(Condition.getQueryWrapper(user));
+		return R.data(UserWrapper.build().entityVO(detail));
+	}
+
+	/**
+	 * 查询单条
+	 */
+	@ApiOperationSupport(order =2)
+	@ApiOperation(value = "查看详情", notes = "传入id")
+	@GetMapping("/info")
+	public R<UserVO> info(ZhongZhengUser user) {
+		User detail = userService.getById(user.getUserId());
+		return R.data(UserWrapper.build().entityVO(detail));
+	}
+
+	/**
+	 * 用户列表
+	 */
+	@GetMapping("/list")
+	@ApiImplicitParams({
+		@ApiImplicitParam(name = "account", value = "账号名", paramType = "query", dataType = "string"),
+		@ApiImplicitParam(name = "realName", value = "姓名", paramType = "query", dataType = "string")
+	})
+	@ApiOperationSupport(order = 3)
+	@ApiOperation(value = "列表", notes = "传入account和realName")
+	public R<IPage<UserVO>> list(@ApiIgnore @RequestParam Map<String, Object> user, Query query, ZhongZhengUser zzUser) throws SQLException {
+		System.out.println("list user 1:" + user.toString());
+		QueryWrapper<User> queryWrapper = Condition.getQueryWrapper(user, User.class);
+		System.out.println("list user 2:" + query.toString());
+		System.out.println("list user 3:" + zzUser.toString());
+		IPage<User> pages = userService.page(Condition.getPage(query), (!zzUser.getTenantId().equals(ZhongZhengConstant.ADMIN_TENANT_ID)) ? queryWrapper.lambda().eq(User::getTenantId, zzUser.getTenantId()) : queryWrapper);
+		return R.data(UserWrapper.build().pageVO(pages));
+	}
+
+	/**
+	 * 新增或修改
+	 */
+	@PostMapping("/submit")
+	@ApiOperationSupport(order = 4)
+	@ApiOperation(value = "新增或修改", notes = "传入User")
+	public R submit(@Valid @RequestBody User user) {
+		System.out.println("submit user:" + user.toString());
+
+		return R.status(userService.submit(user));
+	}
+
+	/**
+	 * 修改
+	 */
+	@PostMapping("/update")
+	@ApiOperationSupport(order = 5)
+	@ApiOperation(value = "修改", notes = "传入User")
+	public R update(@Valid @RequestBody User user) {
+		return R.status(userService.updateById(user));
+	}
+
+	/**
+	 * 删除
+	 */
+	@PostMapping("/remove")
+	@ApiOperationSupport(order = 6)
+	@ApiOperation(value = "删除", notes = "传入地基和")
+	public R remove(@RequestParam String ids) {
+		return R.status(userService.deleteLogic(Func.toLongList(ids)));
+	}
+
+
+	/**
+	 * 设置菜单权限
+	 *
+	 * @param userIds
+	 * @param roleIds
+	 * @return
+	 */
+	@PostMapping("/grant")
+	@ApiOperationSupport(order = 7)
+	@ApiOperation(value = "权限设置", notes = "传入roleId集合以及menuId集合")
+	public R grant(@ApiParam(value = "userId集合", required = true) @RequestParam String userIds,
+				   @ApiParam(value = "roleId集合", required = true) @RequestParam String roleIds) {
+		boolean temp = userService.grant(userIds, roleIds);
+		return R.status(temp);
+	}
+
+	@PostMapping("/reset-password")
+	@ApiOperationSupport(order = 8)
+	@ApiOperation(value = "初始化密码", notes = "传入userId集合")
+	public R resetPassword(@ApiParam(value = "userId集合", required = true) @RequestParam String userIds) {
+		boolean temp = userService.resetPassword(userIds);
+		return R.status(temp);
+	}
+
+	/**
+	 * 修改密码
+	 *
+	 * @param oldPassword
+	 * @param newPassword
+	 * @param newPassword1
+	 * @return
+	 */
+	@PostMapping("/update-password")
+	@ApiOperationSupport(order = 9)
+	@ApiOperation(value = "修改密码", notes = "传入密码")
+	public R updatePassword(ZhongZhengUser user, @ApiParam(value = "旧密码", required = true) @RequestParam String oldPassword,
+							@ApiParam(value = "新密码", required = true) @RequestParam String newPassword,
+							@ApiParam(value = "新密码", required = true) @RequestParam String newPassword1) {
+		boolean temp = userService.updatePassword(user.getUserId(), oldPassword, newPassword, newPassword1);
+		return R.status(temp);
+	}
+
+	/**
+	 * 用户列表
+	 *
+	 * @param user
+	 * @return
+	 */
+	@GetMapping("/user-list")
+	@ApiOperationSupport(order = 10)
+	@ApiOperation(value = "用户列表", notes = "传入user")
+	public R<List<User>> userList(User user) throws SQLException {
+		List<User> list = userService.list(Condition.getQueryWrapper(user));
+		return R.data(list);
+	}
+
+
+
 }

+ 44 - 0
zzbusiness-user/src/main/java/org/zhongzheng/user/feign/UserClient.java

@@ -0,0 +1,44 @@
+package org.zhongzheng.user.feign;
+
+
+import lombok.AllArgsConstructor;
+import org.zhongzheng.common.feignclient.zzbusinessuser.IUserClient;
+import org.zhongzheng.common.utils.R;
+import org.zhongzheng.common.feignclient.zzbusinessuser.entity.User;
+import org.zhongzheng.common.feignclient.zzbusinessuser.entity.UserInfo;
+import org.zhongzheng.common.feignclient.zzbusinessuser.entity.UserOauth;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import org.zhongzheng.user.service.IUserService;
+
+@RestController
+@AllArgsConstructor
+public class UserClient implements IUserClient {
+    private IUserService service;
+
+    @Override
+    public R<UserInfo> userInfo(Long userId) {
+        return R.data(service.userInfo(userId));
+    }
+
+    @Override
+    @GetMapping(API_PREFIX + "/user-info")
+    public R<UserInfo> userInfo(String tenantId, String account, String password) {
+        return R.data( service.userInfo(tenantId, account, password));
+    }
+
+    @Override
+    @PostMapping(API_PREFIX + "/user-auth-info")
+    public R<UserInfo> userAuthInfo(UserOauth userOauth) {
+        return R.data( new UserInfo());
+    }
+
+    @Override
+    @PostMapping(API_PREFIX + "/save-user")
+    public R<Boolean> saveUser(User user) {
+        return R.data( service.save(user) );
+    }
+}

+ 79 - 0
zzbusiness-user/src/main/java/org/zhongzheng/user/mapper/UserMapper.java

@@ -0,0 +1,79 @@
+/**
+ * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.zhongzheng.user.mapper;
+
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Service;
+import org.zhongzheng.common.feignclient.zzbusinessuser.entity.User;
+
+import java.util.List;
+
+/**
+ * Mapper 接口
+ *
+ * @author Chill
+ */
+@Mapper
+public interface UserMapper extends BaseMapper<User> {
+
+	/**
+	 * 自定义分页
+	 *
+	 * @param page
+	 * @param user
+	 * @return
+	 */
+	List<User> selectUserPage(IPage page, User user);
+
+	/**
+	 * 获取用户
+	 *
+	 * @param tenantId
+	 * @param account
+	 * @param password
+	 * @return
+	 */
+	User getUser(String tenantId, String account, String password);
+
+	/**
+	 * 获取角色名
+	 *
+	 * @param ids
+	 * @return
+	 */
+	List<String> getRoleName(String[] ids);
+
+	/**
+	 * 获取角色别名
+	 *
+	 * @param ids
+	 * @return
+	 */
+	List<String> getRoleAlias(String[] ids);
+
+	/**
+	 * 获取部门名
+	 *
+	 * @param ids
+	 * @return
+	 */
+	List<String> getDeptName(String[] ids);
+
+}

+ 92 - 0
zzbusiness-user/src/main/java/org/zhongzheng/user/mapper/UserMapper.xml

@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.zhongzheng.user.mapper.UserMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="userResultMap" type="org.zhongzheng.common.feignclient.zzbusinessuser.entity.User">
+        <result column="id" property="id"/>
+        <result column="tenant_id" property="tenantId"/>
+        <result column="create_user" property="createUser"/>
+        <result column="create_time" property="createTime"/>
+        <result column="update_user" property="updateUser"/>
+        <result column="update_time" property="updateTime"/>
+        <result column="status" property="status"/>
+        <result column="is_deleted" property="isDeleted"/>
+        <result column="code" property="code"/>
+        <result column="account" property="account"/>
+        <result column="password" property="password"/>
+        <result column="name" property="name"/>
+        <result column="real_name" property="realName"/>
+        <result column="email" property="email"/>
+        <result column="phone" property="phone"/>
+        <result column="birthday" property="birthday"/>
+        <result column="sex" property="sex"/>
+        <result column="role_id" property="roleId"/>
+        <result column="dept_id" property="deptId"/>
+    </resultMap>
+
+    <!-- 通用查询结果列 -->
+    <sql id="baseColumnList">
+        select id,
+        create_user AS createUser,
+        create_time AS createTime,
+        update_user AS updateUser,
+        update_time AS updateTime,
+        status,
+        is_deleted AS isDeleted,
+        account, password, name, real_name, email, phone, birthday, sex, role_id, dept_id
+    </sql>
+
+    <select id="selectUserPage" resultMap="userResultMap">
+        select * from zhongzheng_user where is_deleted = 0
+    </select>
+
+    <select id="getUser" resultMap="userResultMap">
+        SELECT
+            *
+        FROM
+            zhongzheng_user
+        WHERE
+            tenant_id = #{param1} and account = #{param2} and password = #{param3} and is_deleted = 0
+    </select>
+
+    <select id="getRoleName" resultType="java.lang.String">
+        SELECT
+        role_name
+        FROM
+        zhongzheng_role
+        WHERE
+        id IN
+        <foreach collection="array" item="ids" index="index" open="(" close=")" separator=",">
+            #{ids}
+        </foreach>
+        and is_deleted = 0
+    </select>
+
+    <select id="getRoleAlias" resultType="java.lang.String">
+        SELECT
+            role_alias
+        FROM
+            zhongzheng_role
+        WHERE
+            id IN
+        <foreach collection="array" item="ids" index="index" open="(" close=")" separator=",">
+            #{ids}
+        </foreach>
+        and is_deleted = 0
+    </select>
+
+    <select id="getDeptName" resultType="java.lang.String">
+        SELECT
+            dept_name
+        FROM
+            zhongzheng_dept
+        WHERE
+            id IN
+        <foreach collection="array" item="ids" index="index" open="(" close=")" separator=",">
+            #{ids}
+        </foreach>
+        and is_deleted = 0
+    </select>
+
+</mapper>

+ 112 - 0
zzbusiness-user/src/main/java/org/zhongzheng/user/service/IUserService.java

@@ -0,0 +1,112 @@
+/**
+ * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.zhongzheng.user.service;
+
+
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.zhongzheng.common.mybatisplus.BaseService;
+import org.zhongzheng.common.feignclient.zzbusinessuser.entity.User;
+import org.zhongzheng.common.feignclient.zzbusinessuser.entity.UserInfo;
+
+import java.util.List;
+
+/**
+ * 服务类
+ *
+ * @author Chill
+ */
+public interface IUserService extends BaseService<User> {
+
+	/**
+	 * 新增或修改用户
+	 * @param user
+	 * @return
+	 */
+	boolean submit(User user);
+
+	/**
+	 * 自定义分页
+	 *
+	 * @param page
+	 * @param user
+	 * @return
+	 */
+	IPage<User> selectUserPage(IPage<User> page, User user);
+
+	/**
+	 * 用户信息
+	 *
+	 * @param userId
+	 * @return
+	 */
+	UserInfo userInfo(Long userId);
+
+	/**
+	 * 用户信息
+	 *
+	 * @param tenantId
+	 * @param account
+	 * @param password
+	 * @return
+	 */
+	UserInfo userInfo(String tenantId, String account, String password);
+
+	/**
+	 * 给用户设置角色
+	 *
+	 * @param userIds
+	 * @param roleIds
+	 * @return
+	 */
+	boolean grant(String userIds, String roleIds);
+
+	/**
+	 * 初始化密码
+	 *
+	 * @param userIds
+	 * @return
+	 */
+	boolean resetPassword(String userIds);
+
+	/**
+	 * 修改密码
+	 *
+	 * @param userId
+	 * @param oldPassword
+	 * @param newPassword
+	 * @param newPassword1
+	 * @return
+	 */
+	boolean updatePassword(Long userId, String oldPassword, String newPassword, String newPassword1);
+
+	/**
+	 * 获取角色名
+	 *
+	 * @param roleIds
+	 * @return
+	 */
+	List<String> getRoleName(String roleIds);
+
+	/**
+	 * 获取部门名
+	 *
+	 * @param deptIds
+	 * @return
+	 */
+	List<String> getDeptName(String deptIds);
+
+}

+ 131 - 0
zzbusiness-user/src/main/java/org/zhongzheng/user/service/impl/UserServiceImpl.java

@@ -0,0 +1,131 @@
+/**
+ * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.zhongzheng.user.service.impl;
+
+
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import lombok.AllArgsConstructor;
+import org.zhongzheng.common.env.ZhongZhengConstant;
+import org.zhongzheng.common.utils.*;
+import org.zhongzheng.common.mybatisplus.BaseServiceImpl;
+import org.zhongzheng.common.doentity.Tenant;
+
+import org.zhongzheng.common.feignclient.zzbusinessuser.entity.User;
+import org.zhongzheng.common.feignclient.zzbusinessuser.entity.UserInfo;
+import org.zhongzheng.user.mapper.UserMapper;
+import org.zhongzheng.user.service.IUserService;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.PostConstruct;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * 服务实现类
+ *
+ * @author Chill
+ */
+@Service
+@AllArgsConstructor
+public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implements IUserService {
+	private static final String GUEST_NAME = "guest";
+	private static final String MINUS_ONE = "-1";
+
+	@Override
+	public boolean submit(User user) {
+		if (Func.isNotEmpty(user.getPassword())) {
+			user.setPassword(DigestUtil.encrypt(user.getPassword()));
+		}
+		Long cnt = Long.valueOf(baseMapper.selectCount(Wrappers.<User>query().lambda().eq(User::getTenantId, user.getTenantId()).eq(User::getAccount, user.getAccount())));
+		if (cnt > 0) {
+			throw new ServiceException("当前用户已存在!");
+		}
+		return saveOrUpdate(user);
+	}
+
+	@Override
+	public IPage<User> selectUserPage(IPage<User> page, User user) {
+		return page.setRecords(baseMapper.selectUserPage(page, user));
+	}
+
+	@Override
+	public UserInfo userInfo(Long userId) {
+		UserInfo userInfo = new UserInfo();
+		User user = baseMapper.selectById(userId);
+		userInfo.setUser(user);
+		if (Func.isNotEmpty(user)) {
+			List<String> roleAlias = baseMapper.getRoleAlias(Func.toStrArray(user.getRoleId()));
+			userInfo.setRoles(roleAlias);
+		}
+		return userInfo;
+	}
+
+	@Override
+	public UserInfo userInfo(String tenantId, String account, String password) {
+		UserInfo userInfo = new UserInfo();
+		User user = baseMapper.getUser(tenantId, account, password);
+		userInfo.setUser(user);
+		if (Func.isNotEmpty(user)) {
+			List<String> roleAlias = baseMapper.getRoleAlias(Func.toStrArray(user.getRoleId()));
+			userInfo.setRoles(roleAlias);
+		}
+		return userInfo;
+	}
+
+	@Override
+	public boolean grant(String userIds, String roleIds) {
+		User user = new User();
+		user.setRoleId(roleIds);
+		return this.update(user, Wrappers.<User>update().lambda().in(User::getId, Func.toLongList(userIds)));
+	}
+
+	@Override
+	public boolean resetPassword(String userIds) {
+		User user = new User();
+		user.setPassword(DigestUtil.encrypt(ZhongZhengConstant.DEFAULT_PASSWORD));
+		user.setUpdateTime(DateUtil.now());
+		return this.update(user, Wrappers.<User>update().lambda().in(User::getId, Func.toLongList(userIds)));
+	}
+
+	@Override
+	public boolean updatePassword(Long userId, String oldPassword, String newPassword, String newPassword1) {
+		User user = getById(userId);
+		if (!newPassword.equals(newPassword1)) {
+			throw new ServiceException("请输入正确的确认密码!");
+		}
+		if (!user.getPassword().equals(DigestUtil.encrypt(oldPassword))) {
+			throw new ServiceException("原密码不正确!");
+		}
+		return this.update(Wrappers.<User>update().lambda().set(User::getPassword, DigestUtil.encrypt(newPassword)).eq(User::getId, userId));
+	}
+
+	@Override
+	public List<String> getRoleName(String roleIds) {
+		return baseMapper.getRoleName(Func.toStrArray(roleIds));
+	}
+
+	@Override
+	public List<String> getDeptName(String deptIds) {
+		return baseMapper.getDeptName(Func.toStrArray(deptIds));
+	}
+
+
+
+}

+ 62 - 0
zzbusiness-user/src/main/java/org/zhongzheng/user/vo/UserVO.java

@@ -0,0 +1,62 @@
+package org.zhongzheng.user.vo;
+
+/**
+ * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.zhongzheng.common.feignclient.zzbusinessuser.entity.User;
+
+/**
+ * 视图实体类
+ *
+ * @author Chill
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ApiModel(value = "UserVO对象", description = "UserVO对象")
+public class UserVO extends User {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键ID
+     */
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long id;
+
+    /**
+     * 角色名
+     */
+    private String roleName;
+
+    /**
+     * 部门名
+     */
+    private String deptName;
+
+    /**
+     * 岗位名
+     */
+    private String postName;
+
+    /**
+     * 性别
+     */
+    private String sexName;
+}

+ 58 - 0
zzbusiness-user/src/main/java/org/zhongzheng/user/wrapper/UserWrapper.java

@@ -0,0 +1,58 @@
+/**
+ * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.zhongzheng.user.wrapper;
+
+import org.zhongzheng.common.mybatisplus.BaseEntityWrapper;
+import org.zhongzheng.common.utils.R;
+import org.zhongzheng.common.utils.BeanUtil;
+import org.zhongzheng.common.utils.Func;
+import org.zhongzheng.common.utils.SpringUtil;
+import org.zhongzheng.common.feignclient.zzbusinessuser.entity.User;
+import org.zhongzheng.user.service.IUserService;
+import org.zhongzheng.user.vo.UserVO;
+
+import java.util.List;
+
+/**
+ * 包装类,返回视图层所需的字段
+ *
+ * @author Chill
+ */
+public class UserWrapper extends BaseEntityWrapper<User, UserVO> {
+
+	private static IUserService userService;
+
+	static {
+		userService = SpringUtil.getBean(IUserService.class);
+	}
+
+	public static UserWrapper build() {
+		return new UserWrapper();
+	}
+
+	@Override
+	public UserVO entityVO(User user) {
+		UserVO userVO = BeanUtil.copy(user, UserVO.class);
+		List<String> roleName = userService.getRoleName(user.getRoleId());
+		List<String> deptName = userService.getDeptName(user.getDeptId());
+		userVO.setRoleName(Func.join(roleName));
+		userVO.setDeptName(Func.join(deptName));
+		userVO.setSexName((user.getSex()==0) ? "Male" : "Female");
+
+		return userVO;
+	}
+
+}

+ 1 - 1
zzbusiness-user/src/main/resources/application.yml

@@ -4,7 +4,7 @@ spring:
   application:
     name: ZZBUSINESS-USER
   datasource:
-    url: jdbc:mysql://192.168.1.222:3306/test_saas?useUnicode=true&characterEncoding=UTF-8&useSSL=false
+    url: jdbc:mysql://192.168.1.222:3306/zz_business?useUnicode=true&characterEncoding=UTF-8&useSSL=false
     username: root
     password: zhongzheng2021
     driver-class-name: com.mysql.cj.jdbc.Driver