add:依赖mybatisplus
This commit is contained in:
@@ -71,6 +71,21 @@
|
|||||||
<version>0.9.10</version>
|
<version>0.9.10</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
|
<version>3.4.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.velocity</groupId>
|
||||||
|
<artifactId>velocity-engine-core</artifactId>
|
||||||
|
<version>2.3</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-generator</artifactId>
|
||||||
|
<version>3.4.0</version>
|
||||||
|
</dependency>
|
||||||
<!--Spring boot 安全框架-->
|
<!--Spring boot 安全框架-->
|
||||||
<!-- <dependency>-->
|
<!-- <dependency>-->
|
||||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import cn.dev33.satoken.annotation.SaIgnore;
|
|||||||
import com.alicp.jetcache.anno.config.EnableCreateCacheAnnotation;
|
import com.alicp.jetcache.anno.config.EnableCreateCacheAnnotation;
|
||||||
import com.alicp.jetcache.anno.config.EnableMethodCache;
|
import com.alicp.jetcache.anno.config.EnableMethodCache;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.nl.modules.wql.util.SpringContextHolder;
|
import org.nl.modules.wql.util.SpringContextHolder;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
@@ -35,6 +36,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
@EnableTransactionManagement
|
@EnableTransactionManagement
|
||||||
@EnableMethodCache(basePackages = "org.nl")
|
@EnableMethodCache(basePackages = "org.nl")
|
||||||
@EnableCreateCacheAnnotation
|
@EnableCreateCacheAnnotation
|
||||||
|
@MapperScan("org.nl.service.*.mapper")
|
||||||
public class AppRun {
|
public class AppRun {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@@ -0,0 +1,112 @@
|
|||||||
|
package org.nl.config.mybatis;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
|
||||||
|
import com.baomidou.mybatisplus.generator.AutoGenerator;
|
||||||
|
import com.baomidou.mybatisplus.generator.InjectionConfig;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.*;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class CodeGenerator {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 读取控制台内容
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
|
public static String scanner(String tip) {
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
StringBuilder help = new StringBuilder();
|
||||||
|
help.append("请输入" + tip + ":");
|
||||||
|
System.out.println(help.toString());
|
||||||
|
if (scanner.hasNext()) {
|
||||||
|
String ipt = scanner.next();
|
||||||
|
if (!StringUtils.isEmpty(ipt)) {
|
||||||
|
return ipt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new MybatisPlusException("请输入正确的" + tip + "!");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String moduleName = scanner("请输入模块名称");
|
||||||
|
// Mybatis代码生成器
|
||||||
|
AutoGenerator mpg = new AutoGenerator();
|
||||||
|
|
||||||
|
// 全局配置
|
||||||
|
GlobalConfig gc = new GlobalConfig();
|
||||||
|
// 默认不覆盖
|
||||||
|
gc.setFileOverride(false);
|
||||||
|
String projectPath = System.getProperty("user.dir");
|
||||||
|
gc.setOutputDir(projectPath + "/src/main/java/");
|
||||||
|
gc.setAuthor("generator");
|
||||||
|
gc.setOpen(false);
|
||||||
|
// gc.setSwagger2(true);
|
||||||
|
gc.setEntityName("%sDO");
|
||||||
|
gc.setServiceName("I%sService");
|
||||||
|
gc.setServiceImplName("%sServiceImpl");
|
||||||
|
mpg.setGlobalConfig(gc);
|
||||||
|
// 数据源配置
|
||||||
|
DataSourceConfig dsc = new DataSourceConfig();
|
||||||
|
dsc.setUrl("jdbc:mysql://192.168.81.252:3306/nl-sso-server?setUnicode=true&characterEncoding=utf8");
|
||||||
|
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
|
||||||
|
dsc.setUsername("root");
|
||||||
|
dsc.setPassword("Root.123456");
|
||||||
|
mpg.setDataSource(dsc);
|
||||||
|
// 包配置
|
||||||
|
PackageConfig pc = new PackageConfig();
|
||||||
|
// pc.setModuleName("");
|
||||||
|
pc.setParent("org.nl.generator");
|
||||||
|
pc.setController("controller." + moduleName);
|
||||||
|
pc.setMapper("dao.mapper." + moduleName);
|
||||||
|
pc.setService("service." + moduleName);
|
||||||
|
pc.setServiceImpl("service." + moduleName + ".impl");
|
||||||
|
pc.setEntity("dao.entity." + moduleName);
|
||||||
|
// pc.setXml("dao.mapper.xml");
|
||||||
|
mpg.setPackageInfo(pc);
|
||||||
|
// // 自定义配置
|
||||||
|
InjectionConfig cfg = new InjectionConfig() {
|
||||||
|
@Override
|
||||||
|
public void initMap() {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
List<FileOutConfig> focList = new ArrayList<>();
|
||||||
|
// 调整 xml 生成目录演示
|
||||||
|
focList.add(new FileOutConfig("/templates/mapper.xml.vm") {
|
||||||
|
@Override
|
||||||
|
public String outputFile(TableInfo tableInfo) {
|
||||||
|
return projectPath + "/src/main/resources/mapper/" + moduleName + "/" + tableInfo.getEntityName() + "Mapper.xml";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
cfg.setFileOutConfigList(focList);
|
||||||
|
mpg.setCfg(cfg);
|
||||||
|
// 关闭默认 xml 生成,调整生成 至 根目录
|
||||||
|
TemplateConfig tc = new TemplateConfig();
|
||||||
|
tc.setXml(null);
|
||||||
|
mpg.setTemplate(tc);
|
||||||
|
// 策略配置
|
||||||
|
StrategyConfig strategy = new StrategyConfig();
|
||||||
|
strategy.setNaming(NamingStrategy.underline_to_camel);
|
||||||
|
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
|
||||||
|
// strategy.setSuperEntityClass("你自己的父类实体,没有就不用设置!");
|
||||||
|
strategy.setEntityLombokModel(true);
|
||||||
|
strategy.setRestControllerStyle(true);
|
||||||
|
// 公共父类
|
||||||
|
// strategy.setSuperControllerClass("你自己的父类控制器,没有就不用设置!");
|
||||||
|
// 写于父类中的公共字段
|
||||||
|
// strategy.setSuperEntityColumns("id");
|
||||||
|
strategy.setInclude(scanner("表名,多个英文逗号分割").split(","));
|
||||||
|
strategy.setControllerMappingHyphenStyle(true);
|
||||||
|
strategy.setTablePrefix("dc_");
|
||||||
|
mpg.setStrategy(strategy);
|
||||||
|
// mpg.setTemplateEngine(new FreemarkerTemplateEngine());
|
||||||
|
mpg.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package org.nl.config.mybatis;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.DbType;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
|
@EnableTransactionManagement
|
||||||
|
@Configuration
|
||||||
|
public class MybatisPlusConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新的分页插件,一缓和二缓遵循mybatis的规则,需要设置 MybatisConfiguration#useDeprecatedExecutor = false 避免缓存出现问题(该属性会在旧插件移除后一同移除)
|
||||||
|
添加自增插件
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||||
|
|
||||||
|
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||||
|
// 分页插件
|
||||||
|
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
||||||
|
//乐观锁插件
|
||||||
|
interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
|
||||||
|
|
||||||
|
return interceptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ package org.nl.config.saconfig;
|
|||||||
import cn.dev33.satoken.config.SaSsoConfig;
|
import cn.dev33.satoken.config.SaSsoConfig;
|
||||||
import cn.hutool.http.HttpRequest;
|
import cn.hutool.http.HttpRequest;
|
||||||
import cn.hutool.http.HttpResponse;
|
import cn.hutool.http.HttpResponse;
|
||||||
|
import org.apache.http.client.HttpClient;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.web.servlet.ModelAndView;
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package org.nl.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import org.nl.service.user.ISysUserService;
|
||||||
|
import org.nl.service.user.dto.SysUserDO;
|
||||||
|
import org.nl.service.user.mapper.SysUserMapper;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 用户表 前端控制器
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author generator
|
||||||
|
* @since 2022-12-14
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/sys-user-do")
|
||||||
|
public class SysUserController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ISysUserService iSysUserService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
SysUserMapper sysUserMapper;
|
||||||
|
|
||||||
|
@RequestMapping("/1")
|
||||||
|
public String getDemo(){
|
||||||
|
List<SysUserDO> list = iSysUserService.list();
|
||||||
|
return JSON.toJSONString(list) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -3,6 +3,7 @@ package org.nl.modules.common.utils.dto;
|
|||||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.nl.modules.system.domain.User;
|
||||||
import org.nl.modules.system.service.dto.UserDto;
|
import org.nl.modules.system.service.dto.UserDto;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
@@ -25,7 +26,7 @@ public class CurrentUser implements Serializable {
|
|||||||
private String preson_name;
|
private String preson_name;
|
||||||
|
|
||||||
//用户详细信息
|
//用户详细信息
|
||||||
private UserDto user;
|
private User user;
|
||||||
|
|
||||||
private List<String> permissions = new ArrayList<>();
|
private List<String> permissions = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,8 +113,8 @@ public class AuthorizationController {
|
|||||||
CurrentUser user = new CurrentUser();
|
CurrentUser user = new CurrentUser();
|
||||||
user.setId(userInfo.getLong("user_id"));
|
user.setId(userInfo.getLong("user_id"));
|
||||||
user.setUsername(userInfo.getString("username"));
|
user.setUsername(userInfo.getString("username"));
|
||||||
user.setPermissions(Lists.newArrayList(userInfo.getString("person_name")));
|
user.setPreson_name((userInfo.getString("person_name")));
|
||||||
user.setUser(this.getById(userInfo.getLong("user_id")));
|
user.setUser(userService.findById(userInfo.getLong("user_id")));
|
||||||
user.setPermissions(permissionList);
|
user.setPermissions(permissionList);
|
||||||
|
|
||||||
// SaLoginModel 配置登录相关参数
|
// SaLoginModel 配置登录相关参数
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package org.nl.service.user;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import org.nl.service.user.dto.SysUserDO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 用户表 服务类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author generator
|
||||||
|
* @since 2022-12-14
|
||||||
|
*/
|
||||||
|
public interface ISysUserService extends IService<SysUserDO> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,133 @@
|
|||||||
|
package org.nl.service.user.dto;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 用户表
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author generator
|
||||||
|
* @since 2022-12-14
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@TableName("sys_user")
|
||||||
|
public class SysUserDO implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户标识
|
||||||
|
*/
|
||||||
|
@TableId(value = "user_id", type = IdType.AUTO)
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录账号
|
||||||
|
*/
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 姓名
|
||||||
|
*/
|
||||||
|
private String personName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 性别
|
||||||
|
*/
|
||||||
|
private String gender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 电话
|
||||||
|
*/
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 电子邮箱
|
||||||
|
*/
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 头像地址
|
||||||
|
*/
|
||||||
|
private String avatarName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 头像真实路径
|
||||||
|
*/
|
||||||
|
private String avatarPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否为admin账号
|
||||||
|
*/
|
||||||
|
private String isAdmin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否启用
|
||||||
|
*/
|
||||||
|
private String isUsed;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码重置者
|
||||||
|
*/
|
||||||
|
private String pwdResetUserId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码重置时间
|
||||||
|
*/
|
||||||
|
private String pwdResetTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建人标识
|
||||||
|
*/
|
||||||
|
private Long createId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建人
|
||||||
|
*/
|
||||||
|
private String createName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
private String createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改人标识
|
||||||
|
*/
|
||||||
|
private Long updateOptid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改人
|
||||||
|
*/
|
||||||
|
private String updateOptname;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改时间
|
||||||
|
*/
|
||||||
|
private String updateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 外部人员标识
|
||||||
|
*/
|
||||||
|
private String extpersonId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 外部用户标识
|
||||||
|
*/
|
||||||
|
private String extuserId;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package org.nl.service.user.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.nl.service.user.ISysUserService;
|
||||||
|
import org.nl.service.user.dto.SysUserDO;
|
||||||
|
import org.nl.service.user.mapper.SysUserMapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 用户表 服务实现类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author generator
|
||||||
|
* @since 2022-12-14
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUserDO> implements ISysUserService {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package org.nl.service.user.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.nl.service.user.dto.SysUserDO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 用户表 Mapper 接口
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author generator
|
||||||
|
* @since 2022-12-14
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface SysUserMapper extends BaseMapper<SysUserDO> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -54,6 +54,7 @@ security:
|
|||||||
- /auth/login
|
- /auth/login
|
||||||
- /auth/code
|
- /auth/code
|
||||||
- /auth/logout
|
- /auth/logout
|
||||||
|
- /sys-user-do/**
|
||||||
# swagger
|
# swagger
|
||||||
- /swagger-ui.html
|
- /swagger-ui.html
|
||||||
- /swagger-resources/**
|
- /swagger-resources/**
|
||||||
@@ -78,3 +79,12 @@ security:
|
|||||||
- /api/localStorage/pictures
|
- /api/localStorage/pictures
|
||||||
# 参数
|
# 参数
|
||||||
- /api/param/getValueByCode
|
- /api/param/getValueByCode
|
||||||
|
mybatis-plus:
|
||||||
|
configuration:
|
||||||
|
map-underscore-to-camel-case: true
|
||||||
|
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||||
|
mapper-locations:
|
||||||
|
- classpath:mapper/*.xml
|
||||||
|
global-config:
|
||||||
|
db-config:
|
||||||
|
id-type: INPUT
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?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.nl.service.user.mapper.SysUserMapper">
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
|
|
||||||
package org.nl.rest;
|
|
||||||
|
|
||||||
|
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.nl.modules.logging.annotation.Log;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
import io.swagger.annotations.*;
|
|
||||||
import java.util.Map;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author zzq
|
|
||||||
* @date 2022-11-28
|
|
||||||
**/
|
|
||||||
@RestController
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Api(tags = "userService管理")
|
|
||||||
@RequestMapping("/api/sysUser")
|
|
||||||
@Slf4j
|
|
||||||
public class SysUserController {
|
|
||||||
|
|
||||||
private final SysUserService sysUserService;
|
|
||||||
|
|
||||||
@GetMapping
|
|
||||||
@Log("查询userService")
|
|
||||||
@ApiOperation("查询userService")
|
|
||||||
//@SaCheckPermission("@el.check('sysUser:list')")
|
|
||||||
public ResponseEntity<Object> query(@RequestParam Map whereJson, Pageable page){
|
|
||||||
return new ResponseEntity<>(sysUserService.queryAll(whereJson,page),HttpStatus.OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping
|
|
||||||
@Log("新增userService")
|
|
||||||
@ApiOperation("新增userService")
|
|
||||||
//@SaCheckPermission("@el.check('sysUser:add')")
|
|
||||||
public ResponseEntity<Object> create(@Validated @RequestBody SysUserDto dto){
|
|
||||||
sysUserService.create(dto);
|
|
||||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
|
||||||
}
|
|
||||||
|
|
||||||
@PutMapping
|
|
||||||
@Log("修改userService")
|
|
||||||
@ApiOperation("修改userService")
|
|
||||||
//@SaCheckPermission("@el.check('sysUser:edit')")
|
|
||||||
public ResponseEntity<Object> update(@Validated @RequestBody SysUserDto dto){
|
|
||||||
sysUserService.update(dto);
|
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Log("删除userService")
|
|
||||||
@ApiOperation("删除userService")
|
|
||||||
//@SaCheckPermission("@el.check('sysUser:del')")
|
|
||||||
@DeleteMapping
|
|
||||||
public ResponseEntity<Object> delete(@RequestBody Long[] ids) {
|
|
||||||
sysUserService.deleteAll(ids);
|
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
|
|
||||||
package org.nl.service;
|
|
||||||
|
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.List;
|
|
||||||
import java.io.IOException;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description 服务接口
|
|
||||||
* @author zzq
|
|
||||||
* @date 2022-11-28
|
|
||||||
**/
|
|
||||||
public interface SysUserService {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询数据分页
|
|
||||||
* @param whereJson 条件
|
|
||||||
* @param page 分页参数
|
|
||||||
* @return Map<String,Object>
|
|
||||||
*/
|
|
||||||
Map<String,Object> queryAll(Map whereJson, Pageable page);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询所有数据不分页
|
|
||||||
* @param whereJson 条件参数
|
|
||||||
* @return List<SysUserDto>
|
|
||||||
*/
|
|
||||||
List<SysUserDto> queryAll(Map whereJson);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据ID查询
|
|
||||||
* @param user_id ID
|
|
||||||
* @return SysUser
|
|
||||||
*/
|
|
||||||
SysUserDto findById(Long user_id);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据编码查询
|
|
||||||
* @param code code
|
|
||||||
* @return SysUser
|
|
||||||
*/
|
|
||||||
SysUserDto findByCode(String code);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建
|
|
||||||
* @param dto /
|
|
||||||
*/
|
|
||||||
void create(SysUserDto dto);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 编辑
|
|
||||||
* @param dto /
|
|
||||||
*/
|
|
||||||
void update(SysUserDto dto);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 多选删除
|
|
||||||
* @param ids /
|
|
||||||
*/
|
|
||||||
void deleteAll(Long[] ids);
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
package org.nl.service.dto;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description /
|
|
||||||
* @author zzq
|
|
||||||
* @date 2022-11-28
|
|
||||||
**/
|
|
||||||
@Data
|
|
||||||
public class SysUserDto implements Serializable {
|
|
||||||
|
|
||||||
/** ID */
|
|
||||||
private Long user_id;
|
|
||||||
|
|
||||||
/** 部门名称 */
|
|
||||||
private Long dept_id;
|
|
||||||
|
|
||||||
/** 用户名 */
|
|
||||||
private String username;
|
|
||||||
|
|
||||||
/** 昵称 */
|
|
||||||
private String nick_name;
|
|
||||||
|
|
||||||
/** 性别 */
|
|
||||||
private String gender;
|
|
||||||
|
|
||||||
/** 手机号码 */
|
|
||||||
private String phone;
|
|
||||||
|
|
||||||
/** 邮箱 */
|
|
||||||
private String email;
|
|
||||||
|
|
||||||
/** 头像地址 */
|
|
||||||
private String avatar_name;
|
|
||||||
|
|
||||||
/** 头像真实路径 */
|
|
||||||
private String avatar_path;
|
|
||||||
|
|
||||||
/** 密码 */
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
/** 是否为admin账号 */
|
|
||||||
private Boolean is_admin;
|
|
||||||
|
|
||||||
/** 状态:1启用、0禁用 */
|
|
||||||
private Long enabled;
|
|
||||||
|
|
||||||
/** 创建者 */
|
|
||||||
private String create_by;
|
|
||||||
|
|
||||||
/** 更新者 */
|
|
||||||
private String update_by;
|
|
||||||
|
|
||||||
/** 修改密码的时间 */
|
|
||||||
private Date pwd_reset_time;
|
|
||||||
|
|
||||||
/** 创建日期 */
|
|
||||||
private Date create_time;
|
|
||||||
|
|
||||||
/** 更新时间 */
|
|
||||||
private Date update_time;
|
|
||||||
}
|
|
||||||
@@ -1,128 +0,0 @@
|
|||||||
|
|
||||||
package org.nl.service.impl;
|
|
||||||
|
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
|
||||||
import cn.hutool.core.util.IdUtil;
|
|
||||||
import com.alibaba.fastjson.JSONArray;
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import org.nl.modules.common.utils.SecurityUtils;
|
|
||||||
import org.nl.modules.wql.core.bean.ResultBean;
|
|
||||||
import org.nl.modules.wql.core.bean.WQLObject;
|
|
||||||
import org.nl.modules.wql.util.WqlUtil;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description 服务实现
|
|
||||||
* @author zzq
|
|
||||||
* @date 2022-11-28
|
|
||||||
**/
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Slf4j
|
|
||||||
public class SysUserServiceImpl implements SysUserService {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String,Object> queryAll(Map whereJson, Pageable page){
|
|
||||||
WQLObject wo = WQLObject.getWQLObject("sys_user");
|
|
||||||
ResultBean rb = wo.pagequery(WqlUtil.getHttpContext(page), "1=1", "update_time desc");
|
|
||||||
final JSONObject json = rb.pageResult();
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<SysUserDto> queryAll(Map whereJson){
|
|
||||||
WQLObject wo = WQLObject.getWQLObject("sys_user");
|
|
||||||
JSONArray arr = wo.query().getResultJSONArray(0);
|
|
||||||
if (ObjectUtil.isNotEmpty(arr)) return arr.toJavaList(SysUserDto.class);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SysUserDto findById(Long user_id) {
|
|
||||||
WQLObject wo = WQLObject.getWQLObject("sys_user");
|
|
||||||
JSONObject json = wo.query("user_id = '" + user_id + "'").uniqueResult(0);
|
|
||||||
if (ObjectUtil.isNotEmpty(json)){
|
|
||||||
return json.toJavaObject( SysUserDto.class);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SysUserDto findByCode(String code) {
|
|
||||||
WQLObject wo = WQLObject.getWQLObject("sys_user");
|
|
||||||
JSONObject json = wo.query("code ='" + code + "'").uniqueResult(0);
|
|
||||||
if (ObjectUtil.isNotEmpty(json)){
|
|
||||||
return json.toJavaObject( SysUserDto.class);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public void create(SysUserDto dto) {
|
|
||||||
Long currentUserId = SecurityUtils.getCurrentUserId();
|
|
||||||
String nickName = SecurityUtils.getCurrentNickName();
|
|
||||||
String now = DateUtil.now();
|
|
||||||
|
|
||||||
dto.setUser_id(IdUtil.getSnowflake(1, 1).nextId());
|
|
||||||
dto.setCreate_id(currentUserId);
|
|
||||||
dto.setCreate_name(nickName);
|
|
||||||
dto.setUpdate_optid(currentUserId);
|
|
||||||
dto.setUpdate_optname(nickName);
|
|
||||||
dto.setUpdate_time(now);
|
|
||||||
dto.setCreate_time(now);
|
|
||||||
|
|
||||||
WQLObject wo = WQLObject.getWQLObject("sys_user");
|
|
||||||
JSONObject json = JSONObject.parseObject(JSON.toJSONString(dto));
|
|
||||||
wo.insert(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public void update(SysUserDto dto) {
|
|
||||||
SysUserDto entity = this.findById(dto.getUser_id());
|
|
||||||
if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!");
|
|
||||||
|
|
||||||
Long currentUserId = SecurityUtils.getCurrentUserId();
|
|
||||||
String nickName = SecurityUtils.getCurrentNickName();
|
|
||||||
|
|
||||||
String now = DateUtil.now();
|
|
||||||
dto.setUpdate_time(now);
|
|
||||||
dto.setUpdate_optid(currentUserId);
|
|
||||||
dto.setUpdate_optname(nickName);
|
|
||||||
|
|
||||||
WQLObject wo = WQLObject.getWQLObject("sys_user");
|
|
||||||
JSONObject json = JSONObject.parseObject(JSON.toJSONString(dto));
|
|
||||||
wo.update(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public void deleteAll(Long[] ids) {
|
|
||||||
Long currentUserId = SecurityUtils.getCurrentUserId();
|
|
||||||
String nickName = SecurityUtils.getCurrentNickName();
|
|
||||||
String now = DateUtil.now();
|
|
||||||
|
|
||||||
WQLObject wo = WQLObject.getWQLObject("sys_user");
|
|
||||||
for (Long user_id: ids) {
|
|
||||||
JSONObject param = new JSONObject();
|
|
||||||
param.put("user_id", String.valueOf(user_id));
|
|
||||||
param.put("is_delete", "1");
|
|
||||||
param.put("update_optid", currentUserId);
|
|
||||||
param.put("update_optname", nickName);
|
|
||||||
param.put("update_time", now);
|
|
||||||
wo.update(param);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user