更新1.2.0版本,新增登录接口和菜单生成接口
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -10,7 +10,7 @@
|
||||
</parent>
|
||||
<groupId>com.common.base</groupId>
|
||||
<artifactId>base</artifactId>
|
||||
<version>1.1.0-beta1</version>
|
||||
<version>1.2.0-beta1</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>common-base</name>
|
||||
<description>基础包</description>
|
||||
|
||||
@@ -1,18 +1,25 @@
|
||||
package com.common.base.common.utils;
|
||||
|
||||
|
||||
import com.common.base.common.ServiceException;
|
||||
import com.common.base.module.data.annotation.DataIgnore;
|
||||
import com.common.base.module.data.module.DataMap;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ObjectUtil {
|
||||
|
||||
private static final String SERIAL_VERSION_UID = "serialVersionUID";
|
||||
private static final String STRING = "class java.lang.String";
|
||||
private static final String INTEGER = "class java.lang.Integer";
|
||||
private static final String LONG = "class java.lang.LONG";
|
||||
|
||||
public static Map<String, Object> objToMap(Object obj) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
@@ -32,9 +39,10 @@ public class ObjectUtil {
|
||||
return map;
|
||||
}
|
||||
|
||||
public static<T> void objToSqlMap(Object obj, DataMap<T> dataMap) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
public static <T> void objToSqlMap(Object obj, DataMap<T> dataMap) {
|
||||
Class<?> clazz = obj.getClass();
|
||||
Map<String, Object> map = new HashMap<String, Object>(clazz.getDeclaredFields().length);
|
||||
List<String> fieldList = new ArrayList<>();
|
||||
if (clazz.getAnnotation(Table.class) != null) {
|
||||
Table table = clazz.getAnnotation(Table.class);
|
||||
dataMap = dataMap.toBuilder().tableName(table.name()).build();
|
||||
@@ -46,20 +54,26 @@ public class ObjectUtil {
|
||||
dataMap = dataMap.toBuilder().pkName(com.common.base.common.utils.StringUtils.toUnderScoreUpperCase(fieldName)).build();
|
||||
}
|
||||
try {
|
||||
if (!StringUtils.isEmpty(field.get(obj)) && !fieldName.equals(SERIAL_VERSION_UID)) {
|
||||
Object value = field.get(obj);
|
||||
map.put(com.common.base.common.utils.StringUtils.toUnderScoreUpperCase(fieldName), value);
|
||||
if (!fieldName.equals(SERIAL_VERSION_UID)) {
|
||||
if (!StringUtils.isEmpty(field.get(obj))) {
|
||||
Object value = field.get(obj);
|
||||
map.put(com.common.base.common.utils.StringUtils.toUnderScoreUpperCase(fieldName), value);
|
||||
}
|
||||
if (field.getAnnotation(DataIgnore.class) == null) {
|
||||
fieldList.add(com.common.base.common.utils.StringUtils.toUnderScoreUpperCase(fieldName));
|
||||
}
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
dataMap = dataMap.toBuilder().data(map).build();
|
||||
dataMap.toBuilder().data(map).fieldList(fieldList).build();
|
||||
}
|
||||
|
||||
public static<T> void objToSqlMap(Object obj, DataMap.DataMapBuilder<T> dataMap) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
public static <T> void objToSqlMap(Object obj, DataMap.DataMapBuilder<T> dataMap) {
|
||||
Class<?> clazz = obj.getClass();
|
||||
Map<String, Object> map = new HashMap<String, Object>(clazz.getDeclaredFields().length);
|
||||
List<String> fieldList = new ArrayList<>();
|
||||
if (clazz.getAnnotation(Table.class) != null) {
|
||||
Table table = clazz.getAnnotation(Table.class);
|
||||
dataMap = dataMap.tableName(table.name());
|
||||
@@ -71,14 +85,46 @@ public class ObjectUtil {
|
||||
dataMap = dataMap.pkName(com.common.base.common.utils.StringUtils.toUnderScoreUpperCase(fieldName));
|
||||
}
|
||||
try {
|
||||
if (!StringUtils.isEmpty(field.get(obj)) && !fieldName.equals(SERIAL_VERSION_UID)) {
|
||||
Object value = field.get(obj);
|
||||
map.put(com.common.base.common.utils.StringUtils.toUnderScoreUpperCase(fieldName), value);
|
||||
if (!fieldName.equals(SERIAL_VERSION_UID)) {
|
||||
if (!StringUtils.isEmpty(field.get(obj))) {
|
||||
Object value = field.get(obj);
|
||||
map.put(com.common.base.common.utils.StringUtils.toUnderScoreUpperCase(fieldName), value);
|
||||
}
|
||||
if (field.getAnnotation(DataIgnore.class) == null) {
|
||||
fieldList.add(com.common.base.common.utils.StringUtils.toUnderScoreUpperCase(fieldName));
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
dataMap.data(map);
|
||||
dataMap.data(map).fieldList(fieldList);
|
||||
}
|
||||
|
||||
public static void setField(Object obj, String key, Object value) {
|
||||
Class<?> clazz = obj.getClass();
|
||||
try {
|
||||
Field field = clazz.getDeclaredField(key);
|
||||
field.setAccessible(true);
|
||||
String str = field.getGenericType().toString();
|
||||
if (STRING.equals(str)) {
|
||||
value = value.toString();
|
||||
}
|
||||
if (INTEGER.equals(str)) {
|
||||
value = Integer.valueOf(value.toString());
|
||||
}
|
||||
if (LONG.equals(str)) {
|
||||
value = Long.valueOf(value.toString());
|
||||
}
|
||||
try {
|
||||
field.set(obj, value);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new ServiceException("字段类型不匹配", e);
|
||||
}
|
||||
} catch (NoSuchFieldException e) {
|
||||
throw new ServiceException("无法找到相应的字段", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -411,6 +411,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(toUnderScoreUpperCase("userId"));
|
||||
Long l = 1l;
|
||||
System.out.println(l.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.common.base.module.auth.constants;
|
||||
|
||||
/**
|
||||
* @author lhc
|
||||
* @date 2020-12-10
|
||||
* @decription 权限常亮信息
|
||||
*/
|
||||
public class AuthConstants {
|
||||
/**
|
||||
* 平台内系统用户的唯一标志
|
||||
*/
|
||||
public static final String SYS_USER = "SYS_USER";
|
||||
|
||||
/**
|
||||
* 正常状态
|
||||
*/
|
||||
public static final String NORMAL = "0";
|
||||
|
||||
/**
|
||||
* 异常状态
|
||||
*/
|
||||
public static final String EXCEPTION = "1";
|
||||
|
||||
/**
|
||||
* 用户封禁状态
|
||||
*/
|
||||
public static final String USER_DISABLE = "1";
|
||||
|
||||
/**
|
||||
* 角色封禁状态
|
||||
*/
|
||||
public static final String ROLE_DISABLE = "1";
|
||||
|
||||
/**
|
||||
* 部门正常状态
|
||||
*/
|
||||
public static final String DEPT_NORMAL = "0";
|
||||
|
||||
/**
|
||||
* 部门停用状态
|
||||
*/
|
||||
public static final String DEPT_DISABLE = "1";
|
||||
|
||||
/**
|
||||
* 字典正常状态
|
||||
*/
|
||||
public static final String DICT_NORMAL = "0";
|
||||
|
||||
/**
|
||||
* 是否为系统默认(是)
|
||||
*/
|
||||
public static final String YES = "Y";
|
||||
|
||||
/**
|
||||
* 是否菜单外链(是)
|
||||
*/
|
||||
public static final String YES_FRAME = "1";
|
||||
|
||||
/**
|
||||
* 是否菜单外链(否)
|
||||
*/
|
||||
public static final String NO_FRAME = "0";
|
||||
|
||||
/**
|
||||
* 菜单类型(目录)
|
||||
*/
|
||||
public static final String TYPE_DIR = "M";
|
||||
|
||||
/**
|
||||
* 菜单类型(菜单)
|
||||
*/
|
||||
public static final String TYPE_MENU = "C";
|
||||
|
||||
/**
|
||||
* 菜单类型(按钮)
|
||||
*/
|
||||
public static final String TYPE_BUTTON = "F";
|
||||
|
||||
/**
|
||||
* Layout组件标识
|
||||
*/
|
||||
public final static String LAYOUT = "Layout";
|
||||
|
||||
/**
|
||||
* 非Layout菜单组件标识
|
||||
*/
|
||||
public final static String UN_LAYOUT = "un-layout/index.vue";
|
||||
|
||||
/**
|
||||
* 校验返回结果码
|
||||
*/
|
||||
public final static String UNIQUE = "0";
|
||||
public final static String NOT_UNIQUE = "1";
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.common.base.module.auth.controller;
|
||||
|
||||
import com.common.base.common.ResultVO;
|
||||
import com.common.base.module.auth.entity.OsSysMenu;
|
||||
import com.common.base.module.auth.service.AuthFunctionService;
|
||||
import com.common.base.module.auth.service.MenuService;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author lhc
|
||||
* @date 2020-12-09
|
||||
* @decription 权限接口
|
||||
*/
|
||||
@RestController
|
||||
@Api(tags = "权限管理")
|
||||
@RequestMapping("auth/function")
|
||||
public class AuthFunctionController {
|
||||
|
||||
@Autowired
|
||||
AuthFunctionService authService;
|
||||
|
||||
@Autowired
|
||||
MenuService menuService;
|
||||
|
||||
|
||||
@GetMapping("menu")
|
||||
public ResultVO getMenuResult() {
|
||||
List<OsSysMenu> menus = menuService.getMenuResult();
|
||||
return ResultVO.getSuccess(menuService.formatMenu(menus));
|
||||
}
|
||||
|
||||
@PostMapping("menu")
|
||||
public ResultVO addAuthResult(OsSysMenu osSysMenu) {
|
||||
return ResultVO.getSuccess(menuService.add(osSysMenu));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.common.base.module.auth.controller;
|
||||
|
||||
import com.common.base.common.ResultVO;
|
||||
import com.common.base.module.auth.service.FtUserService;
|
||||
import com.common.base.module.log.annotation.LogAnno;
|
||||
import com.common.base.module.shiro.service.ShiroService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* (FtUser)表控制层
|
||||
*
|
||||
* @author lhc
|
||||
* @since 2020-02-11 19:29:10
|
||||
*/
|
||||
@RestController
|
||||
@Api(tags = "用户相关接口")
|
||||
@RequestMapping("ftUser")
|
||||
public class FtUserController {
|
||||
/**
|
||||
* 服务对象
|
||||
*/
|
||||
@Autowired
|
||||
private FtUserService ftUserService;
|
||||
|
||||
@Autowired
|
||||
ShiroService shiroService;
|
||||
|
||||
@ApiOperation(value = "用户登陆")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "username", value = "用户名", required = true),
|
||||
@ApiImplicitParam(name = "password", value = "密码", required = true),
|
||||
})
|
||||
//@LogAnno(operateType = "用户登录")
|
||||
@PostMapping("login")
|
||||
public ResultVO login(HttpServletRequest request, String username, String password) {
|
||||
return ftUserService.login(request, username, password);
|
||||
}
|
||||
|
||||
@LogAnno(operateType = "用户登出", isBefore = true)
|
||||
@ApiOperation(value = "用户登出")
|
||||
@PostMapping("/logout")
|
||||
public ResultVO logOut(HttpServletRequest request) {
|
||||
String token = request.getHeader("X-Access-Token");
|
||||
shiroService.logout(token);
|
||||
return ResultVO.getSuccess();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
14
src/main/java/com/common/base/module/auth/dao/FtUserDao.java
Normal file
14
src/main/java/com/common/base/module/auth/dao/FtUserDao.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.common.base.module.auth.dao;
|
||||
|
||||
import com.common.base.common.Mapper;
|
||||
import com.common.base.module.auth.entity.FtUser;
|
||||
|
||||
/**
|
||||
* (FtUser)表数据库访问层
|
||||
*
|
||||
* @author lhc
|
||||
* @since 2020-02-11 19:29:10
|
||||
*/
|
||||
public interface FtUserDao extends Mapper<FtUser> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.common.base.module.auth.dao;
|
||||
|
||||
import com.common.base.common.Mapper;
|
||||
import com.common.base.module.auth.entity.OsSysMenu;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 菜单权限表(OsSysMenu)表数据库访问层
|
||||
*
|
||||
* @author makejava
|
||||
* @since 2020-12-09 09:57:20
|
||||
*/
|
||||
public interface OsSysMenuDao extends Mapper<OsSysMenu> {
|
||||
|
||||
List<OsSysMenu> selectMenu();
|
||||
}
|
||||
74
src/main/java/com/common/base/module/auth/entity/FtUser.java
Normal file
74
src/main/java/com/common/base/module/auth/entity/FtUser.java
Normal file
@@ -0,0 +1,74 @@
|
||||
package com.common.base.module.auth.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* (FtUser)实体类
|
||||
*
|
||||
* @author lhc
|
||||
* @since 2020-09-23 13:49:30
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder(toBuilder = true)
|
||||
@Data
|
||||
@Table(name = "FT_USER")
|
||||
public class FtUser implements Serializable {
|
||||
private static final long serialVersionUID = -44415286580890701L;
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(generator="JDBC")
|
||||
private Integer userId;
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String username;
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
private String phone;
|
||||
/**
|
||||
* 用户类型,0未验证用户,1外部,2内部,3企业
|
||||
*/
|
||||
private Integer userType;
|
||||
/**
|
||||
* 启用/禁用
|
||||
*/
|
||||
private Integer enabled;
|
||||
/**
|
||||
* 用户信息主键
|
||||
*/
|
||||
private Integer userInfoId;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createTime;
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date updateTime;
|
||||
|
||||
private Integer orgId;
|
||||
|
||||
}
|
||||
114
src/main/java/com/common/base/module/auth/entity/OsSysMenu.java
Normal file
114
src/main/java/com/common/base/module/auth/entity/OsSysMenu.java
Normal file
@@ -0,0 +1,114 @@
|
||||
package com.common.base.module.auth.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.Table;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 菜单权限表(OsSysMenu)实体类
|
||||
*
|
||||
* @author makejava
|
||||
* @since 2020-12-09 09:57:20
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder(toBuilder = true)
|
||||
@Data
|
||||
@Table(name = "OS_SYS_MENU")
|
||||
public class OsSysMenu implements Serializable {
|
||||
private static final long serialVersionUID = -36592644935215591L;
|
||||
|
||||
public static final String M = "M";
|
||||
public static final String C = "C";
|
||||
public static final String F = "F";
|
||||
public static final String I = "I";
|
||||
|
||||
|
||||
/**
|
||||
* 菜单ID
|
||||
*/
|
||||
private Long menuId;
|
||||
/**
|
||||
* 菜单名称
|
||||
*/
|
||||
private String menuName;
|
||||
/**
|
||||
* 父菜单ID
|
||||
*/
|
||||
private Long parentId;
|
||||
/**
|
||||
* 显示顺序
|
||||
*/
|
||||
private Integer orderNum;
|
||||
/**
|
||||
* 路由地址
|
||||
*/
|
||||
private String path;
|
||||
/**
|
||||
* 组件路径
|
||||
*/
|
||||
private String component;
|
||||
/**
|
||||
* 是否为外链(0是 1否)
|
||||
*/
|
||||
private String isFrame;
|
||||
/**
|
||||
* 是否缓存(0缓存 1不缓存)
|
||||
*/
|
||||
private String isCache;
|
||||
/**
|
||||
* 菜单类型(M目录 C菜单 F按钮)
|
||||
*/
|
||||
private String menuType;
|
||||
/**
|
||||
* 菜单状态(0显示 1隐藏)
|
||||
*/
|
||||
private String visible;
|
||||
/**
|
||||
* 菜单状态(0正常 1停用)
|
||||
*/
|
||||
private String status;
|
||||
/**
|
||||
* 权限标识
|
||||
*/
|
||||
private String perms;
|
||||
/**
|
||||
* 菜单图标
|
||||
*/
|
||||
private String icon;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
/**
|
||||
* if true, will always show the root menu (default is false)
|
||||
* if false, hide the root menu when has less or equal than one children route
|
||||
*/
|
||||
private String alwaysShow;
|
||||
|
||||
/**
|
||||
* if false, the item will be hidden in breadcrumb (default is true)
|
||||
*/
|
||||
private String breadcrumb;
|
||||
/**
|
||||
* if true, the tag will affix in the tags-view
|
||||
*/
|
||||
private String affix;
|
||||
|
||||
private List<OsSysMenu> children;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.common.base.module.auth.service;
|
||||
|
||||
public interface AuthFunctionService {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.common.base.module.auth.service;
|
||||
|
||||
|
||||
import com.common.base.common.ResultVO;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* (FtUser)表服务接口
|
||||
*
|
||||
* @author lhc
|
||||
* @since 2020-02-11 19:29:10
|
||||
*/
|
||||
public interface FtUserService {
|
||||
|
||||
ResultVO login(HttpServletRequest request, String username, String password);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.common.base.module.auth.service;
|
||||
|
||||
|
||||
import com.common.base.module.auth.entity.OsSysMenu;
|
||||
import com.common.base.module.auth.vo.RouterVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface MenuService {
|
||||
|
||||
List<OsSysMenu> getMenuResult();
|
||||
|
||||
List<RouterVo> formatMenu(List<OsSysMenu> menus);
|
||||
|
||||
Object add(OsSysMenu osSysMenu);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.common.base.module.auth.service.impl;
|
||||
|
||||
import com.common.base.module.auth.service.AuthFunctionService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
@Service
|
||||
public class AuthFunctionServiceImpl implements AuthFunctionService {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.common.base.module.auth.service.impl;
|
||||
|
||||
import com.common.base.common.ResultVO;
|
||||
import com.common.base.common.ServiceException;
|
||||
import com.common.base.common.config.FrameConfig;
|
||||
import com.common.base.common.utils.MD5Util;
|
||||
import com.common.base.common.utils.TokenProccessor;
|
||||
import com.common.base.module.auth.dao.FtUserDao;
|
||||
import com.common.base.module.auth.entity.FtUser;
|
||||
import com.common.base.module.auth.service.FtUserService;
|
||||
import com.common.base.module.shiro.dao.FtTokenDao;
|
||||
import com.common.base.module.shiro.service.ShiroService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* (FtUser)表服务实现类
|
||||
*
|
||||
* @author lhc
|
||||
* @since 2020-02-11 19:29:10
|
||||
*/
|
||||
@Service("ftUserService")
|
||||
public class FtUserServiceImpl implements FtUserService {
|
||||
|
||||
|
||||
/**
|
||||
* 用户失效时间
|
||||
*/
|
||||
private static int EXPIRE;
|
||||
|
||||
private final FtTokenDao ftTokenDao;
|
||||
private final FtUserDao ftUserDao;
|
||||
|
||||
|
||||
final
|
||||
ShiroService shiroService;
|
||||
|
||||
|
||||
|
||||
public FtUserServiceImpl(FtUserDao ftUserDao, ShiroService shiroService, FtTokenDao ftTokenDao) {
|
||||
this.ftUserDao = ftUserDao;
|
||||
this.shiroService = shiroService;
|
||||
this.ftTokenDao = ftTokenDao;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setHost(FrameConfig config) {
|
||||
FtUserServiceImpl.EXPIRE = config.getLoginTimeout() * 3600 * 1000;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public ResultVO login(HttpServletRequest request, String username, String password) {
|
||||
FtUser ftUser = FtUser.builder().username(username).build();
|
||||
ftUser = ftUserDao.selectOne(ftUser);
|
||||
if (ftUser == null) {
|
||||
throw new ServiceException("用户名不存在");
|
||||
}
|
||||
if (ftUser.getEnabled() != 2) {
|
||||
if (MD5Util.isEqual(password, ftUser.getPassword())) {
|
||||
TokenProccessor tokenProccessor = TokenProccessor.getInstance();
|
||||
//生成一个token
|
||||
String token = tokenProccessor.makeToken();
|
||||
//过期时间
|
||||
Date now = new Date();
|
||||
Date expireTime = new Date(now.getTime() + EXPIRE);
|
||||
ResultVO resultVO = shiroService.createToken(String.valueOf(ftUser.getUserId()),token,expireTime);
|
||||
Map<String, Object> map = (Map<String, Object>) resultVO.getData();
|
||||
return ResultVO.getSuccess(map);
|
||||
} else {
|
||||
throw new ServiceException("用户名或密码错误!");
|
||||
}
|
||||
} else {
|
||||
throw new ServiceException("用户已被禁用,请联系管理员");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
package com.common.base.module.auth.service.impl;
|
||||
|
||||
import com.common.base.common.utils.StringUtils;
|
||||
import com.common.base.module.auth.constants.AuthConstants;
|
||||
import com.common.base.module.auth.dao.OsSysMenuDao;
|
||||
import com.common.base.module.auth.entity.OsSysMenu;
|
||||
import com.common.base.module.auth.service.MenuService;
|
||||
import com.common.base.module.auth.vo.MetaVo;
|
||||
import com.common.base.module.auth.vo.RouterVo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class MenuServiceImpl implements MenuService {
|
||||
|
||||
@Autowired
|
||||
OsSysMenuDao osSysMenuDao;
|
||||
|
||||
@Override
|
||||
public List<OsSysMenu> getMenuResult() {
|
||||
List<OsSysMenu> osSysMenus = osSysMenuDao.selectMenu();
|
||||
return getChildPerms(osSysMenus, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据父节点的ID获取所有子节点
|
||||
*
|
||||
* @param list 分类表
|
||||
* @param parentId 传入的父节点ID
|
||||
* @return String
|
||||
*/
|
||||
public List<OsSysMenu> getChildPerms(List<OsSysMenu> list, int parentId) {
|
||||
List<OsSysMenu> returnList = new ArrayList<OsSysMenu>();
|
||||
for (Iterator<OsSysMenu> iterator = list.iterator(); iterator.hasNext(); ) {
|
||||
OsSysMenu t = iterator.next();
|
||||
// 一、根据传入的某个父节点ID,遍历该父节点的所有子节点
|
||||
if (t.getParentId() == parentId) {
|
||||
recursionFn(list, t);
|
||||
returnList.add(t);
|
||||
}
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归列表
|
||||
*
|
||||
* @param list
|
||||
* @param t
|
||||
*/
|
||||
private void recursionFn(List<OsSysMenu> list, OsSysMenu t) {
|
||||
// 得到子节点列表
|
||||
List<OsSysMenu> childList = getChildList(list, t);
|
||||
t.setChildren(childList);
|
||||
for (OsSysMenu tChild : childList) {
|
||||
if (hasChild(list, tChild)) {
|
||||
recursionFn(list, tChild);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到子节点列表
|
||||
*/
|
||||
private List<OsSysMenu> getChildList(List<OsSysMenu> list, OsSysMenu t) {
|
||||
List<OsSysMenu> tlist = new ArrayList<OsSysMenu>();
|
||||
Iterator<OsSysMenu> it = list.iterator();
|
||||
while (it.hasNext()) {
|
||||
OsSysMenu n = it.next();
|
||||
if (n.getParentId().longValue() == t.getMenuId().longValue()) {
|
||||
tlist.add(n);
|
||||
}
|
||||
}
|
||||
return tlist;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否有子节点
|
||||
*/
|
||||
private boolean hasChild(List<OsSysMenu> list, OsSysMenu t) {
|
||||
return getChildList(list, t).size() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RouterVo> formatMenu(List<OsSysMenu> menus) {
|
||||
List<RouterVo> routers = new LinkedList<RouterVo>();
|
||||
for (OsSysMenu menu : menus) {
|
||||
RouterVo router = new RouterVo();
|
||||
router.setName(getRouteName(menu));
|
||||
router.setPath(getRouterPath(menu));
|
||||
router.setComponent(getComponent(menu));
|
||||
MetaVo metaVo = MetaVo
|
||||
.builder()
|
||||
.title(menu.getMenuName())
|
||||
.icon(menu.getIcon())
|
||||
.noCache(StringUtils.equals("0", menu.getIsCache()))
|
||||
.hidden("0".equals(menu.getVisible()))
|
||||
.breadcrumb("1".equals(menu.getBreadcrumb()))
|
||||
.affix("1".equals(menu.getAffix()))
|
||||
.alwaysShow("1".equals(menu.getAlwaysShow()))
|
||||
.build();
|
||||
List<OsSysMenu> cMenus = menu.getChildren();
|
||||
if (cMenus != null && !cMenus.isEmpty() && AuthConstants.TYPE_DIR.equals(menu.getMenuType())) {
|
||||
router.setRedirect("noredirect");
|
||||
router.setChildren(formatMenu(cMenus));
|
||||
} else if (isMeunFrame(menu)) {
|
||||
List<RouterVo> childrenList = new ArrayList<RouterVo>();
|
||||
RouterVo children = new RouterVo();
|
||||
children.setPath(menu.getPath());
|
||||
children.setComponent(menu.getComponent());
|
||||
children.setName(StringUtils.capitalize(menu.getPath()));
|
||||
metaVo = metaVo.toBuilder()
|
||||
.title(menu.getMenuName())
|
||||
.icon(menu.getIcon())
|
||||
.noCache(StringUtils.equals("0", menu.getIsCache()))
|
||||
.alwaysShow("1".equals(menu.getAlwaysShow()))
|
||||
.build();
|
||||
childrenList.add(children);
|
||||
router.setChildren(childrenList);
|
||||
} else if (cMenus == null || cMenus.isEmpty()) {
|
||||
metaVo.setAlwaysShow(false);
|
||||
}
|
||||
router.setMeta(metaVo);
|
||||
routers.add(router);
|
||||
}
|
||||
return routers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object add(OsSysMenu osSysMenu) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取路由名称
|
||||
*
|
||||
* @param menu 菜单信息
|
||||
* @return 路由名称
|
||||
*/
|
||||
public String getRouteName(OsSysMenu menu) {
|
||||
String routerName = StringUtils.capitalize(menu.getPath());
|
||||
// 非外链并且是一级目录(类型为目录)
|
||||
if (isMeunFrame(menu)) {
|
||||
routerName = StringUtils.EMPTY;
|
||||
}
|
||||
return routerName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取路由地址
|
||||
*
|
||||
* @param menu 菜单信息
|
||||
* @return 路由地址
|
||||
*/
|
||||
public String getRouterPath(OsSysMenu menu) {
|
||||
String routerPath = menu.getPath();
|
||||
// 非外链并且是一级目录(类型为目录)
|
||||
if (0 == menu.getParentId().intValue() && AuthConstants.TYPE_DIR.equals(menu.getMenuType())
|
||||
&& AuthConstants.NO_FRAME.equals(menu.getIsFrame())) {
|
||||
routerPath = "/" + menu.getPath();
|
||||
}
|
||||
// 非外链并且是一级目录(类型为菜单)
|
||||
else if (isMeunFrame(menu)) {
|
||||
routerPath = "/";
|
||||
}
|
||||
return routerPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取组件信息
|
||||
*
|
||||
* @param menu 菜单信息
|
||||
* @return 组件信息
|
||||
*/
|
||||
public String getComponent(OsSysMenu menu) {
|
||||
String component = AuthConstants.LAYOUT;
|
||||
if (StringUtils.isNotEmpty(menu.getComponent()) && !isMeunFrame(menu)) {
|
||||
component = menu.getComponent();
|
||||
}
|
||||
if (StringUtils.isEmpty(menu.getComponent())&&isNotParentMenuFrame(menu)) {
|
||||
component = AuthConstants.UN_LAYOUT;
|
||||
}
|
||||
return component;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为菜单内部跳转
|
||||
*
|
||||
* @param menu 菜单信息
|
||||
* @return 结果
|
||||
*/
|
||||
public boolean isMeunFrame(OsSysMenu menu) {
|
||||
return menu.getParentId().intValue() == 0 && AuthConstants.TYPE_MENU.equals(menu.getMenuType())
|
||||
&& menu.getIsFrame().equals(AuthConstants.NO_FRAME);
|
||||
}
|
||||
|
||||
public boolean isNotParentMenuFrame(OsSysMenu menu) {
|
||||
return menu.getParentId().intValue() != 0 && AuthConstants.TYPE_DIR.equals(menu.getMenuType())
|
||||
&& menu.getIsFrame().equals(AuthConstants.NO_FRAME);
|
||||
}
|
||||
}
|
||||
59
src/main/java/com/common/base/module/auth/vo/MetaVo.java
Normal file
59
src/main/java/com/common/base/module/auth/vo/MetaVo.java
Normal file
@@ -0,0 +1,59 @@
|
||||
/**/
|
||||
package com.common.base.module.auth.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 路由显示信息
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder(toBuilder = true)
|
||||
@Data
|
||||
public class MetaVo implements Serializable {
|
||||
private static final long serialVersionUID = -4261993881269135509L;
|
||||
/**
|
||||
* 设置该路由在侧边栏和面包屑中展示的名字
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 设置该路由的图标,对应路径src/assets/icons/svg
|
||||
*/
|
||||
private String icon;
|
||||
|
||||
/**
|
||||
* 设置为true,则不会被 <keep-alive>缓存
|
||||
*/
|
||||
private boolean noCache;
|
||||
|
||||
/**
|
||||
* 设置为是否隐藏,true为隐藏
|
||||
*/
|
||||
private boolean hidden;
|
||||
|
||||
/**
|
||||
* if true, will always show the root menu (default is false)
|
||||
* if false, hide the root menu when has less or equal than one children route
|
||||
*/
|
||||
private boolean alwaysShow;
|
||||
|
||||
/**
|
||||
* if false, the item will be hidden in breadcrumb (default is true)
|
||||
*/
|
||||
private boolean breadcrumb;
|
||||
/**
|
||||
* if true, the tag will affix in the tags-view
|
||||
*/
|
||||
private boolean affix;
|
||||
|
||||
|
||||
|
||||
}
|
||||
55
src/main/java/com/common/base/module/auth/vo/RouterVo.java
Normal file
55
src/main/java/com/common/base/module/auth/vo/RouterVo.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package com.common.base.module.auth.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 路由配置信息
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder(toBuilder = true)
|
||||
@Data
|
||||
public class RouterVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 8361861823516461515L;
|
||||
/**
|
||||
* 路由名字
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 路由地址
|
||||
*/
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* 重定向地址,当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
|
||||
*/
|
||||
private String redirect;
|
||||
|
||||
/**
|
||||
* 组件地址
|
||||
*/
|
||||
private String component;
|
||||
|
||||
/**
|
||||
* 其他元素
|
||||
*/
|
||||
private MetaVo meta;
|
||||
|
||||
/**
|
||||
* 子路由
|
||||
*/
|
||||
private List<RouterVo> children;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.common.base.module.data.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 忽略字段
|
||||
*
|
||||
* @author lhc
|
||||
*/
|
||||
// 方法注解
|
||||
@Target(ElementType.FIELD)
|
||||
// 运行时可见
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface DataIgnore {
|
||||
}
|
||||
@@ -7,89 +7,98 @@ import com.github.pagehelper.PageInfo;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author lhc
|
||||
*/
|
||||
public interface BaseMapper {
|
||||
|
||||
int save(DataMap dataMap);
|
||||
<E> int save(DataMap<E> dataMap);
|
||||
|
||||
int save(String tableName,String pkName , Map<String, Object> data);
|
||||
int save(String tableName, String pkName, Map<String, Object> data);
|
||||
|
||||
int updateByPk(DataMap dataMap);
|
||||
<E> int save(E e);
|
||||
|
||||
int updateByPk(String tableName, String pkName, Object pkValue, Map<String, Object> data);
|
||||
<E> int updateByPk(DataMap<E> dataMap);
|
||||
|
||||
int updateByPk(OsSysTable osSysTable, Object pkValue, Map<String, Object> data);
|
||||
int updateByPk(String tableName, String pkName, Map<String, Object> data);
|
||||
|
||||
int updateInPk(DataMap dataMap);
|
||||
int updateByPk(OsSysTable osSysTable, Map<String, Object> data);
|
||||
|
||||
<E> int updateByPk(E e);
|
||||
|
||||
<E> int updateInPk(DataMap<E> dataMap);
|
||||
|
||||
<E, A> int updateInPk(E e, List<A> ids);
|
||||
|
||||
<E> int updateInPk(String tableName, String pkName, List<E> ids, Map<String, Object> data);
|
||||
|
||||
<E> int updateInPk(OsSysTable osSysTable, List<E> ids, Map<String, Object> data);
|
||||
|
||||
int updateByCondition(DataMap dataMap, Condition condition);
|
||||
<E> int updateByCondition(DataMap<E> dataMap, Condition condition);
|
||||
|
||||
int updateByCondition(String tableName,Map<String,Object> data, Condition condition);
|
||||
int updateByCondition(String tableName, Map<String, Object> data, Condition condition);
|
||||
|
||||
int deleteByPk(DataMap dataMap);
|
||||
<E> int deleteByPk(DataMap<E> dataMap);
|
||||
|
||||
int deleteByPk(String tableName, String pkName,Object pkValue);
|
||||
int deleteByPk(String tableName, String pkName, Object pkValue);
|
||||
|
||||
int deleteByPk(OsSysTable osSysTable,Object pkValue);
|
||||
int deleteByPk(OsSysTable osSysTable, Object pkValue);
|
||||
|
||||
<E> int deleteInPk(String tableName, String pkName,List<E> ids);
|
||||
<E> int deleteInPk(String tableName, String pkName, List<E> ids);
|
||||
|
||||
int deleteInPk(DataMap dataMap);
|
||||
<E> int deleteInPk(DataMap<E> dataMap);
|
||||
|
||||
<E> int deleteInPk(OsSysTable osSysTable,List<E> ids);
|
||||
<E> int deleteInPk(OsSysTable osSysTable, List<E> ids);
|
||||
|
||||
int deleteByCondition(DataMap dataMap, Condition condition);
|
||||
<E> int deleteByCondition(DataMap<E> dataMap, Condition condition);
|
||||
|
||||
int deleteByCondition(String tableName, Condition condition);
|
||||
|
||||
List<Map<String, Object>> selectAll(String tableName);
|
||||
|
||||
List<Map<String,Object>> selectByEqual(DataMap dataMap, Map<String,Object> map);
|
||||
<E> List<Map<String, Object>> selectByEqual(DataMap<E> dataMap, Map<String, Object> map);
|
||||
|
||||
List<Map<String,Object>> selectByEqual(String tableName, Map<String,Object> map);
|
||||
List<Map<String, Object>> selectByEqual(String tableName, Map<String, Object> map);
|
||||
|
||||
PageInfo<Map<String,Object>> selectByEqual(DataMap dataMap, Map<String,Object> map, WebPageInfo webPageInfo);
|
||||
<E> PageInfo<Map<String, Object>> selectByEqual(DataMap<E> dataMap, Map<String, Object> map, WebPageInfo webPageInfo);
|
||||
|
||||
PageInfo<Map<String,Object>> selectByEqual(String tableName, Map<String,Object> map, WebPageInfo webPageInfo);
|
||||
PageInfo<Map<String, Object>> selectByEqual(String tableName, Map<String, Object> map, WebPageInfo webPageInfo);
|
||||
|
||||
Map<String,Object> selectOneByEqual(DataMap dataMap,Map<String,Object> map);
|
||||
<E> Map<String, Object> selectOneByEqual(DataMap<E> dataMap, Map<String, Object> map);
|
||||
|
||||
Map<String, Object> selectByPk(DataMap dataMap);
|
||||
<E> Map<String, Object> selectByPk(DataMap<E> dataMap);
|
||||
|
||||
Map<String, Object> selectByPk(OsSysTable osSysTable,Object pkValue);
|
||||
Map<String, Object> selectByPk(OsSysTable osSysTable, Object pkValue);
|
||||
|
||||
Map<String, Object> selectByPk(String tableName,String pkName,Object pkValue);
|
||||
Map<String, Object> selectByPk(String tableName, String pkName, Object pkValue);
|
||||
|
||||
List<Map<String, Object>> selectByCondition(Condition condition);
|
||||
|
||||
List<Map<String, Object>> selectByCondition(DataMap dataMap, Condition condition);
|
||||
<E> List<Map<String, Object>> selectByCondition(DataMap<E> dataMap, Condition condition);
|
||||
|
||||
List<Map<String, Object>> selectByCondition(String tableName, Condition condition);
|
||||
|
||||
List<Map<String, Object>> selectByCondition(String tableName,List<String> fieldList, Condition condition);
|
||||
List<Map<String, Object>> selectByCondition(String tableName, List<String> fieldList, Condition condition);
|
||||
|
||||
List<Map<String, Object>> selectByCondition(String tableName,String fieldList, Condition condition);
|
||||
List<Map<String, Object>> selectByCondition(String tableName, String fieldList, Condition condition);
|
||||
|
||||
PageInfo<Map<String, Object>> selectByCondition(Condition condition, WebPageInfo webPageInfo);
|
||||
|
||||
PageInfo<Map<String, Object>> selectByCondition(DataMap dataMap, Condition condition, WebPageInfo webPageInfo);
|
||||
<E> PageInfo<Map<String, Object>> selectByCondition(DataMap<E> dataMap, Condition condition, WebPageInfo webPageInfo);
|
||||
|
||||
PageInfo<Map<String, Object>> selectByCondition(String tableName, Condition condition, WebPageInfo webPageInfo);
|
||||
|
||||
PageInfo<Map<String, Object>> selectByCondition(String tableName,List<String> fieldList, Condition condition, WebPageInfo webPageInfo);
|
||||
PageInfo<Map<String, Object>> selectByCondition(String tableName, List<String> fieldList, Condition condition, WebPageInfo webPageInfo);
|
||||
|
||||
PageInfo<Map<String, Object>> selectByCondition(String tableName,String fieldList, Condition condition, WebPageInfo webPageInfo);
|
||||
PageInfo<Map<String, Object>> selectByCondition(String tableName, String fieldList, Condition condition, WebPageInfo webPageInfo);
|
||||
|
||||
Map<String, Object> selectOneByCondition(DataMap dataMap, Condition condition);
|
||||
<E> Map<String, Object> selectOneByCondition(DataMap<E> dataMap, Condition condition);
|
||||
|
||||
Map<String, Object> selectOneByCondition(String tableName, Condition condition);
|
||||
|
||||
Map<String, Object> selectOneByCondition(String tableName,List<String> fieldList, Condition condition);
|
||||
Map<String, Object> selectOneByCondition(String tableName, List<String> fieldList, Condition condition);
|
||||
|
||||
Map<String, Object> selectOneByCondition(String tableName,String fieldList, Condition condition);
|
||||
Map<String, Object> selectOneByCondition(String tableName, String fieldList, Condition condition);
|
||||
|
||||
Map<String, Object> selectOneByCondition(Condition condition);
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@ import java.util.Map;
|
||||
@Qualifier("base")
|
||||
public class BaseMapperImpl implements BaseMapper {
|
||||
|
||||
|
||||
|
||||
public static final String BASE = "base";
|
||||
|
||||
final TableMapper tableMapper;
|
||||
@@ -33,7 +35,7 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public int save(DataMap dataMap) {
|
||||
public <E> int save(DataMap<E> dataMap) {
|
||||
String key;
|
||||
key = DBContextHolder.getDataSource();
|
||||
DatasourceConfig datasourceConfig = DataSourceUtil.get(key);
|
||||
@@ -45,12 +47,16 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
int i;
|
||||
if (datasourceConfig.getCommonType().equals(DataUnit.ORACLE)||datasourceConfig.getCommonType().equals(DataUnit.DAMENG)) {
|
||||
if (org.springframework.util.StringUtils.isEmpty(dataMap.get(dataMap.getPkName()))) {
|
||||
dataMap.toBuilder().add(dataMap.getPkName(), getSequence(dataMap.getTableName(), dataMap.getPkName()));
|
||||
Object id = getSequence(dataMap.getTableName(), dataMap.getPkName());
|
||||
dataMap.toBuilder().add(dataMap.getPkName(), id);
|
||||
dataMap.setPkValue(id);
|
||||
}
|
||||
i = tableMapper.saveInfoWithOracle(dataMap.getData(), dataMap.getTableName());
|
||||
} else {
|
||||
i = tableMapper.saveInfoWithNull(dataMap.getData(), dataMap.getTableName());
|
||||
dataMap.toBuilder().add(dataMap.getPkName(), dataMap.getData().get("id")).build();
|
||||
Object id = dataMap.getData().get("id");
|
||||
dataMap.toBuilder().add(dataMap.getPkName(), id).build();
|
||||
dataMap.setPkValue(id);
|
||||
}
|
||||
SqlException.base(i, "保存失败");
|
||||
dataMap.toBuilder().remove("id");
|
||||
@@ -82,9 +88,19 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> int save(E e) {
|
||||
DataMap<E> dataMap = DataMap.<E>builder().obj(e).build();
|
||||
int i = save(dataMap);
|
||||
dataMap.set(StringUtils.toCamelCase(dataMap.getPkName()),dataMap.getPkValue());
|
||||
OsSysTable sysTable = (OsSysTable) dataMap.getObj();
|
||||
System.out.println(sysTable.getTableId()+"++++++++++++");
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int updateByPk(DataMap dataMap) {
|
||||
public <E> int updateByPk(DataMap<E> dataMap) {
|
||||
JudgesNull(dataMap.getData(), "data can not be null!");
|
||||
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
||||
JudgesNull(dataMap.getPkName(), "pkName can not be null!");
|
||||
@@ -98,36 +114,53 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateByPk(String tableName, String pkName, Object pkValue, Map<String, Object> data) {
|
||||
public int updateByPk(String tableName, String pkName, Map<String, Object> data) {
|
||||
JudgesNull(data, "data can not be null!");
|
||||
JudgesNull(tableName, "tableName can not be null!");
|
||||
JudgesNull(pkName, "pkName can not be null!");
|
||||
JudgesNull(pkValue, "pkValue can not be null!");
|
||||
JudgesNull(data.get(pkName), "pkValue can not be null!");
|
||||
Condition condition = Condition.creatCriteria()
|
||||
.andEqual(pkName, pkValue)
|
||||
.andEqual(pkName, data.get(pkName))
|
||||
.build();
|
||||
data.remove(pkName);
|
||||
int i = tableMapper.updateByWhere(data, tableName, condition.getSql());
|
||||
SqlException.base(i, "更新失败");
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateByPk(OsSysTable osSysTable, Object pkValue, Map<String, Object> data) {
|
||||
public int updateByPk(OsSysTable osSysTable, Map<String, Object> data) {
|
||||
JudgesNull(data, "data can not be null!");
|
||||
JudgesNull(osSysTable.getTableName(), "tableName can not be null!");
|
||||
JudgesNull(osSysTable.getTablePk(), "pkName can not be null!");
|
||||
JudgesNull(pkValue, "pkValue can not be null!");
|
||||
JudgesNull(data.get(osSysTable.getTablePk()), "pkValue can not be null!");
|
||||
Condition condition = Condition.creatCriteria()
|
||||
.andEqual(osSysTable.getTablePk(), pkValue)
|
||||
.andEqual(osSysTable.getTablePk(), data.get(osSysTable.getTablePk()))
|
||||
.build();
|
||||
int i = tableMapper.updateByWhere(data, osSysTable.getTableName(), condition.getSql());
|
||||
SqlException.base(i, "更新失败");
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> int updateByPk(E e) {
|
||||
return updateByPk(DataMap.<E>builder().obj(e).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateInPk(DataMap dataMap) {
|
||||
public <E, A> int updateInPk(E e, List<A> ids) {
|
||||
DataMap<E> dataMap = DataMap.<E>builder().obj(e).build();
|
||||
Condition condition = Condition.creatCriteria()
|
||||
.andIn(dataMap.getPkName(), ids)
|
||||
.build();
|
||||
int i = tableMapper.updateByWhere(dataMap.getData(), dataMap.getTableName(), condition.getSql());
|
||||
SqlException.base(i, "更新失败");
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public <E> int updateInPk(DataMap<E> dataMap) {
|
||||
JudgesNull(dataMap.getData(), "data can not be null!");
|
||||
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
||||
JudgesNull(dataMap.getPkName(), "pkName can not be null!");
|
||||
@@ -170,7 +203,7 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
|
||||
|
||||
@Override
|
||||
public int updateByCondition(DataMap dataMap, Condition condition) {
|
||||
public <E> int updateByCondition(DataMap<E> dataMap, Condition condition) {
|
||||
JudgesNull(dataMap.getData(), "data can not be null!");
|
||||
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
||||
int i = tableMapper.updateByWhere(dataMap.getData(), dataMap.getTableName(), condition.getSql());
|
||||
@@ -188,7 +221,7 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteByPk(DataMap dataMap) {
|
||||
public <E> int deleteByPk(DataMap<E> dataMap) {
|
||||
JudgesNull(dataMap.getPkValue(), "pkValue can not be null!");
|
||||
JudgesNull(dataMap.getPkName(), "pkName can not be null!");
|
||||
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
||||
@@ -240,7 +273,7 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteInPk(DataMap dataMap) {
|
||||
public <E> int deleteInPk(DataMap<E> dataMap) {
|
||||
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
||||
JudgesNull(dataMap.getPkName(), "pkName can not be null!");
|
||||
JudgesNull(dataMap.getIds(), "ids can not be null!");
|
||||
@@ -266,7 +299,7 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteByCondition(DataMap dataMap, Condition condition) {
|
||||
public <E> int deleteByCondition(DataMap<E> dataMap, Condition condition) {
|
||||
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
||||
int i = tableMapper.deleteByWhere(dataMap.getTableName(), condition.getSql());
|
||||
SqlException.base(i, "删除失败");
|
||||
@@ -288,7 +321,7 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> selectByEqual(DataMap dataMap, Map<String, Object> map) {
|
||||
public <E> List<Map<String, Object>> selectByEqual(DataMap<E> dataMap, Map<String, Object> map) {
|
||||
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
||||
Condition condition = equal(dataMap, map);
|
||||
return tableMapper.useSql(condition.getSql());
|
||||
@@ -301,7 +334,8 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
return tableMapper.useSql(condition.getSql());
|
||||
}
|
||||
|
||||
private Condition equal(DataMap dataMap, Map<String, Object> map) {
|
||||
|
||||
private <E> Condition equal(DataMap<E> dataMap, Map<String, Object> map) {
|
||||
Condition condition = Condition.creatCriteria(dataMap).build();
|
||||
if (map != null && !map.isEmpty()) {
|
||||
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
||||
@@ -315,7 +349,7 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo<Map<String, Object>> selectByEqual(DataMap dataMap, Map<String, Object> map, WebPageInfo webPageInfo) {
|
||||
public <E> PageInfo<Map<String, Object>> selectByEqual(DataMap<E> dataMap, Map<String, Object> map, WebPageInfo webPageInfo) {
|
||||
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
||||
MyPageHelper.start(webPageInfo);
|
||||
Condition condition = equal(dataMap, map);
|
||||
@@ -331,14 +365,14 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> selectOneByEqual(DataMap dataMap, Map<String, Object> map) {
|
||||
public <E> Map<String, Object> selectOneByEqual(DataMap<E> dataMap, Map<String, Object> map) {
|
||||
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
||||
Condition condition = equal(dataMap, map);
|
||||
return tableMapper.userSqlByOne(condition.getSql());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> selectByPk(DataMap dataMap) {
|
||||
public <E> Map<String, Object> selectByPk(DataMap<E> dataMap) {
|
||||
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
||||
JudgesNull(dataMap.getPkName(), "pkName can not be null!");
|
||||
JudgesNull(dataMap.getPkValue(), "pkValue can not be null!");
|
||||
@@ -373,7 +407,7 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> selectByCondition(DataMap dataMap, Condition condition) {
|
||||
public <E> List<Map<String, Object>> selectByCondition(DataMap<E> dataMap, Condition condition) {
|
||||
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
||||
return tableMapper.useSql(condition.toCreatCriteria(dataMap).build().getSql());
|
||||
}
|
||||
@@ -409,7 +443,7 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo<Map<String, Object>> selectByCondition(DataMap dataMap, Condition condition, WebPageInfo webPageInfo) {
|
||||
public <E> PageInfo<Map<String, Object>> selectByCondition(DataMap<E> dataMap, Condition condition, WebPageInfo webPageInfo) {
|
||||
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
||||
MyPageHelper.start(webPageInfo);
|
||||
condition = condition.toCreatCriteria(dataMap).build();
|
||||
@@ -441,7 +475,7 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> selectOneByCondition(DataMap dataMap, Condition condition) {
|
||||
public <E> Map<String, Object> selectOneByCondition(DataMap<E> dataMap, Condition condition) {
|
||||
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
||||
return tableMapper.userSqlByOne(condition.toCreatCriteria(dataMap).build().getSql());
|
||||
}
|
||||
@@ -556,7 +590,7 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
id = tableMapper.getSequence(tableName);
|
||||
} catch (Exception e) {
|
||||
MyPageHelper.start(WebPageInfo.builder().pageNum(1).pageSize(1).order(WebPageInfo.DESC).sortField(pkName).build());
|
||||
DataMap dataMap = DataMap.builder().tableName(tableName).pkName(pkName).fields(pkName).build();
|
||||
DataMap<Object> dataMap = DataMap.builder().tableName(tableName).pkName(pkName).fields(pkName).build();
|
||||
Condition condition = Condition.creatCriteria(dataMap).build();
|
||||
Map<String, Object> map = selectOneByCondition(condition);
|
||||
tableMapper.createSequence(tableName, map.get(pkName));
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package com.common.base.module.data.module;
|
||||
|
||||
import com.common.base.common.ServiceException;
|
||||
import com.common.base.common.utils.ObjectUtil;
|
||||
import com.common.base.module.shiro.FtToken;
|
||||
import com.common.base.module.tableconfig.entity.OsSysTable;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -34,9 +38,13 @@ public class DataMap<T> implements Serializable {
|
||||
return obj;
|
||||
}
|
||||
|
||||
public void set(String key, Object value) {
|
||||
ObjectUtil.setField(this.obj, key, value);
|
||||
}
|
||||
|
||||
public void setObj(T obj) {
|
||||
this.obj = obj;
|
||||
ObjectUtil.objToSqlMap(obj,this);
|
||||
ObjectUtil.objToSqlMap(obj, this);
|
||||
}
|
||||
|
||||
public DataMap(OsSysTable osSysTable) {
|
||||
@@ -244,7 +252,7 @@ public class DataMap<T> implements Serializable {
|
||||
public DataMap() {
|
||||
}
|
||||
|
||||
public DataMap(final Map<String, Object> data, final String ids, final List<String> idList, final String tableName, final String pkName, final Object pkValue, final String fields, final List<String> fieldList, final String subData, final String selectSql, final SelectCondition selectCondition,final T obj) {
|
||||
public DataMap(final Map<String, Object> data, final String ids, final List<String> idList, final String tableName, final String pkName, final Object pkValue, final String fields, final List<String> fieldList, final String subData, final String selectSql, final SelectCondition selectCondition, final T obj) {
|
||||
this.data = data;
|
||||
this.ids = ids;
|
||||
this.idList = idList;
|
||||
@@ -349,9 +357,14 @@ public class DataMap<T> implements Serializable {
|
||||
DataMapBuilder() {
|
||||
}
|
||||
|
||||
public DataMapBuilder<T> obj(Object object) {
|
||||
this.obj = obj;
|
||||
ObjectUtil.objToSqlMap(object,this);
|
||||
public DataMapBuilder<T> obj(T object) {
|
||||
this.obj = object;
|
||||
ObjectUtil.objToSqlMap(object, this);
|
||||
return this;
|
||||
}
|
||||
|
||||
public <E> DataMapBuilder<T> set(String key, Object value) {
|
||||
ObjectUtil.setField(this.obj, key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -436,8 +449,15 @@ public class DataMap<T> implements Serializable {
|
||||
}
|
||||
|
||||
public DataMap<T> build() {
|
||||
return new DataMap<>(this.data, this.ids, this.idList, this.tableName, this.pkName, this.pkValue, this.fields, this.fieldList, this.subData, this.selectSql, this.selectCondition,this.obj);
|
||||
return new DataMap<>(this.data, this.ids, this.idList, this.tableName, this.pkName, this.pkValue, this.fields, this.fieldList, this.subData, this.selectSql, this.selectCondition, this.obj);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Long l = 1L;
|
||||
FtToken ftToken = new FtToken();
|
||||
DataMap<FtToken> dataMap = DataMap.<FtToken>builder().obj(ftToken).build();
|
||||
System.out.println(dataMap.getSelectSql());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.common.base.module.shiro;
|
||||
|
||||
import com.common.base.module.data.annotation.DataIgnore;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
@@ -35,4 +36,7 @@ public class FtToken implements Serializable {
|
||||
|
||||
private Date expireTime;
|
||||
|
||||
@DataIgnore
|
||||
private String test;
|
||||
|
||||
}
|
||||
|
||||
@@ -77,10 +77,11 @@ public class TableConfigServiceImpl implements TableConfigService {
|
||||
if (list != null && list.size() > 0) {
|
||||
return ResultVO.getFailed("表别名重复,请修改后提交!");
|
||||
}
|
||||
DataMap<OsSysTable> dataMap = DataMap.<OsSysTable>builder().obj(osSysTable).build();
|
||||
baseMapper.save(dataMap);
|
||||
// DataMap<OsSysTable> dataMap = DataMap.<OsSysTable>builder().obj(osSysTable).build();
|
||||
// baseMapper.save(dataMap);
|
||||
baseMapper.save(osSysTable);
|
||||
tableCache.save(CacheType.tableCache, osSysTable.getTableAlias(), osSysTable, OsSysTable.class);
|
||||
return ResultVO.getSuccess();
|
||||
return ResultVO.getSuccess(osSysTable);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user