feat;增加角色模块
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
package com.tiesheng.util.pojos;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class DaoBase {
|
||||
|
||||
public static final String ID = "id";
|
||||
public static final String CREATE_TIME = "create_time";
|
||||
public static final String UPDATE_TIME = "update_time";
|
||||
public static final String IS_DELETED = "is_deleted";
|
||||
public static final String LIMIT_1 = "limit 1";
|
||||
|
||||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||
private String id;
|
||||
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private Date createTime;
|
||||
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
private Date updateTime;
|
||||
|
||||
@TableField(value = "is_deleted")
|
||||
private Integer isDeleted;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// setter\getter
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public Date getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(Date updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
public Integer getIsDeleted() {
|
||||
return isDeleted;
|
||||
}
|
||||
|
||||
public void setIsDeleted(Integer isDeleted) {
|
||||
this.isDeleted = isDeleted;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.tiesheng.util.pojos;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
public class IdDTO {
|
||||
|
||||
@NotEmpty(message = "需要ID")
|
||||
private String id;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// setter\getter
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
package com.tiesheng.util.pojos;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author hao
|
||||
*/
|
||||
public class PageDTO {
|
||||
|
||||
private Long pageNum;
|
||||
private Long pageSize;
|
||||
private String keyword;
|
||||
private String between;
|
||||
private String equals;
|
||||
private String order;
|
||||
|
||||
|
||||
/**
|
||||
* 启用分页
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public <T> Page<T> pageObj() {
|
||||
Page<T> page = new Page<>();
|
||||
page.setSize(getPageSize());
|
||||
page.setCurrent(getPageNum());
|
||||
return page;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 启用分页
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Page<Map<String, Object>> pageMap() {
|
||||
Page<Map<String, Object>> page = new Page<>();
|
||||
page.setSize(getPageSize());
|
||||
page.setCurrent(getPageNum());
|
||||
return page;
|
||||
}
|
||||
|
||||
/***
|
||||
* 启用排序
|
||||
* @param queryWrapper
|
||||
* @param <T>
|
||||
*/
|
||||
public <T> void doOrder(QueryWrapper<T> queryWrapper) {
|
||||
if (!StrUtil.isEmpty(order)) {
|
||||
if (order.contains("-")) {
|
||||
queryWrapper.orderByDesc(StrUtil.toUnderlineCase(order.replace("-", "")));
|
||||
} else {
|
||||
queryWrapper.orderByAsc(StrUtil.toUnderlineCase(order));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 关键字查询
|
||||
*
|
||||
* @param queryWrapper
|
||||
* @param columns
|
||||
* @param <T>
|
||||
*/
|
||||
public <T> void likeColumns(QueryWrapper<T> queryWrapper, String... columns) {
|
||||
keyword = StrUtil.trim(keyword);
|
||||
if (!StrUtil.isEmpty(keyword) && columns != null && columns.length > 0) {
|
||||
queryWrapper.and(s -> {
|
||||
for (String col : columns) {
|
||||
s.like(col, keyword).or();
|
||||
}
|
||||
});
|
||||
}
|
||||
betweenColumns(queryWrapper);
|
||||
equalsColumns(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 区间
|
||||
*
|
||||
* @param queryWrapper
|
||||
* @param <T>
|
||||
*/
|
||||
public <T> void betweenColumns(QueryWrapper<T> queryWrapper) {
|
||||
if (!StrUtil.isEmpty(between)) {
|
||||
String[] bets = between.split("=");
|
||||
if (bets.length == 2) {
|
||||
String[] vals = bets[1].split(",");
|
||||
if (vals.length == 2) {
|
||||
queryWrapper.between(StrUtil.toUnderlineCase(bets[0]), vals[0], vals[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 匹配列
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public <T> void equalsColumns(QueryWrapper<T> queryWrapper) {
|
||||
if (!StrUtil.isEmpty(equals)) {
|
||||
String[] kv = equals.split(",");
|
||||
for (String key : kv) {
|
||||
String[] cols = key.split("=");
|
||||
if (cols.length == 2) {
|
||||
queryWrapper.eq(StrUtil.toUnderlineCase(cols[0]), cols[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* between
|
||||
*
|
||||
* @param alias
|
||||
* @return
|
||||
*/
|
||||
public String betweenSql(String alias) {
|
||||
String sql = "";
|
||||
if (!StrUtil.isEmpty(between)) {
|
||||
String[] bets = between.split("=");
|
||||
if (bets.length == 2) {
|
||||
String[] vals = bets[1].split(",");
|
||||
if (vals.length == 2) {
|
||||
sql = sql + " and (" + alias + "." + StrUtil.toUnderlineCase(bets[0])
|
||||
+ " between '" + vals[0] + "' and '" + vals[1] + "')";
|
||||
}
|
||||
}
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取排序的sql
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getOrderSql(String alias) {
|
||||
String sql = "";
|
||||
if (!StrUtil.isEmpty(order)) {
|
||||
if (order.contains("-")) {
|
||||
sql = StrUtil.toUnderlineCase(order.replace("-", "")) + " desc";
|
||||
} else {
|
||||
sql = StrUtil.toUnderlineCase(order) + " asc";
|
||||
}
|
||||
sql = "order by " + alias + "." + sql;
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
|
||||
public String getEqualsSql(String alias) {
|
||||
StringBuilder sql = new StringBuilder();
|
||||
if (!StrUtil.isEmpty(equals)) {
|
||||
String[] kv = equals.split(",");
|
||||
for (String key : kv) {
|
||||
String[] cols = key.split("=");
|
||||
if (cols.length == 2) {
|
||||
sql.append(" and ").append(alias).append(".").append(StrUtil.toUnderlineCase(cols[0])).append("=").append(cols[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sql.toString();
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// setter\getter
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public Long getPageNum() {
|
||||
return pageNum == null ? 1 : pageNum;
|
||||
}
|
||||
|
||||
public void setPageNum(Long pageNum) {
|
||||
this.pageNum = pageNum;
|
||||
}
|
||||
|
||||
public Long getPageSize() {
|
||||
return pageSize == null ? 10 : pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(Long pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public String getKeyword() {
|
||||
return keyword;
|
||||
}
|
||||
|
||||
public void setKeyword(String keyword) {
|
||||
this.keyword = keyword;
|
||||
}
|
||||
|
||||
public String getBetween() {
|
||||
return between;
|
||||
}
|
||||
|
||||
public void setBetween(String between) {
|
||||
this.between = between;
|
||||
}
|
||||
|
||||
public String getEquals() {
|
||||
return equals;
|
||||
}
|
||||
|
||||
public void setEquals(String equals) {
|
||||
this.equals = equals;
|
||||
}
|
||||
|
||||
public String getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public void setOrder(String order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.tiesheng.util.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
/**
|
||||
* 基础Service
|
||||
*
|
||||
* @author hao
|
||||
*/
|
||||
public class TsServiceBase<M extends BaseMapper<T>, T> extends ServiceImpl<M, T> {
|
||||
|
||||
|
||||
/**
|
||||
* 通过属性获取一个对象
|
||||
*
|
||||
* @param column
|
||||
* @param val
|
||||
* @return
|
||||
*/
|
||||
public T getOneByColumn(String column, Object val) {
|
||||
QueryWrapper<T> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("is_deleted", 0);
|
||||
queryWrapper.eq(column, val);
|
||||
queryWrapper.last("limit 1");
|
||||
return getOne(queryWrapper);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user