forked from github/dataease
feat: 使用fit2cloud-ui查询条件
This commit is contained in:
parent
ccb37e9ee8
commit
390eb53d1e
@ -1,9 +1,8 @@
|
||||
package io.dataease.base.mapper.ext;
|
||||
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
import io.dataease.base.mapper.ext.query.GridExample;
|
||||
import io.dataease.controller.sys.request.SimpleTreeNode;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -22,4 +21,9 @@ public interface ExtDeptMapper {
|
||||
" <foreach collection='ids' item='id' open='(' separator=',' close=')'>#{id}</foreach> " +
|
||||
"</script>")
|
||||
int batchDelete(@Param("ids") List<Long> ids);
|
||||
|
||||
|
||||
List<SimpleTreeNode> allNodes();
|
||||
|
||||
List<SimpleTreeNode> nodesByExample(GridExample example);
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
<?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="io.dataease.base.mapper.ext.ExtDeptMapper">
|
||||
|
||||
<resultMap id="simpleNode" type="io.dataease.controller.sys.request.SimpleTreeNode">
|
||||
<id property="id" column="id" javaType="java.lang.Long" />
|
||||
<result property="pid" column="pid" javaType="java.lang.Long"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="allNodes" resultMap="simpleNode">
|
||||
select dept_id as id, pid from sys_dept
|
||||
</select>
|
||||
|
||||
|
||||
<select id="nodesByExample" resultType="io.dataease.base.mapper.ext.query.GridExample" resultMap="simpleNode">
|
||||
select dept_id as id, pid from sys_dept
|
||||
<include refid="io.dataease.base.mapper.ext.query.GridSql.gridCondition" />
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
@ -1,6 +1,7 @@
|
||||
package io.dataease.base.mapper.ext;
|
||||
|
||||
import io.dataease.base.domain.SysRole;
|
||||
import io.dataease.base.mapper.ext.query.GridExample;
|
||||
import io.dataease.controller.sys.request.RoleGridRequest;
|
||||
import io.dataease.controller.sys.response.RoleUserItem;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@ -12,7 +13,7 @@ import java.util.Map;
|
||||
public interface ExtSysRoleMapper {
|
||||
|
||||
|
||||
List<SysRole> query(@Param("request")RoleGridRequest request);
|
||||
List<SysRole> query(GridExample example);
|
||||
|
||||
int deleteRoleMenu(@Param("roleId") Long roleId);
|
||||
|
||||
|
@ -9,15 +9,19 @@
|
||||
<result property="name" column="name"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="query" resultMap="io.dataease.base.mapper.SysRoleMapper.BaseResultMap">
|
||||
<select id="query" parameterType="io.dataease.base.mapper.ext.query.GridExample" resultMap="io.dataease.base.mapper.SysRoleMapper.BaseResultMap">
|
||||
select r.*
|
||||
from sys_role r
|
||||
<where>
|
||||
<if test="request.name != null">
|
||||
AND r.name like CONCAT('%', #{request.name},'%')
|
||||
</if>
|
||||
</where>
|
||||
order by r.update_time desc
|
||||
<if test="_parameter != null">
|
||||
<include refid="io.dataease.base.mapper.ext.query.GridSql.gridCondition" />
|
||||
</if>
|
||||
<if test="orderByClause != null">
|
||||
order by ${orderByClause}
|
||||
</if>
|
||||
<if test="orderByClause == null">
|
||||
order by r.update_time desc
|
||||
</if>
|
||||
|
||||
</select>
|
||||
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package io.dataease.base.mapper.ext;
|
||||
|
||||
import io.dataease.base.mapper.ext.query.GridExample;
|
||||
import io.dataease.controller.sys.base.BaseGridRequest;
|
||||
import io.dataease.controller.sys.request.UserGridRequest;
|
||||
import io.dataease.controller.sys.response.SysUserGridResponse;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@ -8,5 +10,5 @@ import java.util.List;
|
||||
|
||||
public interface ExtSysUserMapper {
|
||||
|
||||
List<SysUserGridResponse> query(@Param("request")UserGridRequest request);
|
||||
List<SysUserGridResponse> query(GridExample example);
|
||||
}
|
||||
|
@ -27,26 +27,24 @@
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
<select id="query" resultMap="BaseResultMap">
|
||||
|
||||
|
||||
<select id="query" parameterType="io.dataease.base.mapper.ext.query.GridExample" resultMap="BaseResultMap">
|
||||
select u.*,u.user_id as id, r.role_id,r.name as role_name , d.pid, d.name as dept_name
|
||||
from sys_user u left join sys_users_roles ur on u.user_id = ur.user_id
|
||||
left join sys_role r on r.role_id = ur.role_id
|
||||
left join sys_dept d on d.dept_id = u.dept_id
|
||||
<where>
|
||||
<if test="request.quick != null and request.name == null">
|
||||
AND u.nick_name like CONCAT('%', #{request.quick},'%')
|
||||
</if>
|
||||
<if test="request.name != null">
|
||||
AND u.nick_name like CONCAT('%', #{request.name},'%')
|
||||
</if>
|
||||
<if test="request.enabled != null">
|
||||
AND u.enabled = #{request.enabled}
|
||||
</if>
|
||||
<if test="request.deptId != null">
|
||||
AND u.dept_id = #{request.deptId}
|
||||
</if>
|
||||
</where>
|
||||
order by u.update_time desc
|
||||
|
||||
<if test="_parameter != null">
|
||||
<include refid="io.dataease.base.mapper.ext.query.GridSql.gridCondition" />
|
||||
</if>
|
||||
<if test="orderByClause != null">
|
||||
order by ${orderByClause}
|
||||
</if>
|
||||
<if test="orderByClause == null">
|
||||
order by u.update_time desc
|
||||
</if>
|
||||
|
||||
</select>
|
||||
|
||||
|
||||
|
@ -0,0 +1,259 @@
|
||||
package io.dataease.base.mapper.ext.query;
|
||||
|
||||
import io.dataease.controller.sys.base.ConditionEntity;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GridExample {
|
||||
protected String orderByClause;
|
||||
|
||||
protected boolean distinct;
|
||||
|
||||
protected List<Criteria> oredCriteria;
|
||||
|
||||
public GridExample() {
|
||||
oredCriteria = new ArrayList<Criteria>();
|
||||
}
|
||||
|
||||
public void setOrderByClause(String orderByClause) {
|
||||
this.orderByClause = orderByClause;
|
||||
}
|
||||
|
||||
public String getOrderByClause() {
|
||||
return orderByClause;
|
||||
}
|
||||
|
||||
public void setDistinct(boolean distinct) {
|
||||
this.distinct = distinct;
|
||||
}
|
||||
|
||||
public boolean isDistinct() {
|
||||
return distinct;
|
||||
}
|
||||
|
||||
public List<Criteria> getOredCriteria() {
|
||||
return oredCriteria;
|
||||
}
|
||||
|
||||
public void or(Criteria criteria) {
|
||||
oredCriteria.add(criteria);
|
||||
}
|
||||
|
||||
public Criteria or() {
|
||||
Criteria criteria = createCriteriaInternal();
|
||||
oredCriteria.add(criteria);
|
||||
return criteria;
|
||||
}
|
||||
|
||||
public Criteria createCriteria() {
|
||||
Criteria criteria = createCriteriaInternal();
|
||||
if (oredCriteria.size() == 0) {
|
||||
oredCriteria.add(criteria);
|
||||
}
|
||||
return criteria;
|
||||
}
|
||||
|
||||
protected Criteria createCriteriaInternal() {
|
||||
Criteria criteria = new Criteria();
|
||||
return criteria;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
oredCriteria.clear();
|
||||
orderByClause = null;
|
||||
distinct = false;
|
||||
}
|
||||
|
||||
protected abstract static class GeneratedCriteria {
|
||||
protected List<Criterion> criteria;
|
||||
|
||||
protected GeneratedCriteria() {
|
||||
super();
|
||||
criteria = new ArrayList<Criterion>();
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return criteria.size() > 0;
|
||||
}
|
||||
|
||||
public List<Criterion> getAllCriteria() {
|
||||
return criteria;
|
||||
}
|
||||
|
||||
public List<Criterion> getCriteria() {
|
||||
return criteria;
|
||||
}
|
||||
|
||||
protected void addCriterion(String condition) {
|
||||
if (condition == null) {
|
||||
throw new RuntimeException("Value for condition cannot be null");
|
||||
}
|
||||
criteria.add(new Criterion(condition));
|
||||
}
|
||||
|
||||
protected void addCriterion(String condition, Object value, String property) {
|
||||
if (value == null) {
|
||||
throw new RuntimeException("Value for " + property + " cannot be null");
|
||||
}
|
||||
criteria.add(new Criterion(condition, value));
|
||||
}
|
||||
|
||||
protected void addCriterion(String condition, Object value1, Object value2, String property) {
|
||||
if (value1 == null || value2 == null) {
|
||||
throw new RuntimeException("Between values for " + property + " cannot be null");
|
||||
}
|
||||
criteria.add(new Criterion(condition, value1, value2));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Criteria addCondtion(ConditionEntity conditionEntity){
|
||||
String field = conditionEntity.getField();
|
||||
Object value = conditionEntity.getValue();
|
||||
String operator = conditionEntity.getOperator();
|
||||
if (StringUtils.isEmpty(operator))
|
||||
operator = "like";
|
||||
switch (operator){
|
||||
case "eq":
|
||||
addCriterion(field+" = ", value, field);
|
||||
break;
|
||||
case "ne":
|
||||
addCriterion(field+" <> ", value, field);
|
||||
break;
|
||||
case "like":
|
||||
addCriterion(field+" like ", "%"+value+"%", field);
|
||||
break;
|
||||
case "not like":
|
||||
addCriterion(field+" not like ", value, field);
|
||||
break;
|
||||
case "in":
|
||||
List<Object> invalues = (List<Object>)value;
|
||||
addCriterion(field+" in", invalues, field);
|
||||
break;
|
||||
case "not in":
|
||||
List<Object> notinvalues = (List<Object>)value;
|
||||
addCriterion(field+" not in", notinvalues, field);
|
||||
break;
|
||||
case "between":
|
||||
List<Object> values = (List<Object>)value;
|
||||
Object v1 = values.get(0);
|
||||
Object v2 = values.get(1);
|
||||
addCriterion(field+" between", v1, v2, field);
|
||||
break;
|
||||
case "gt":
|
||||
addCriterion(field+" > ", value, field);
|
||||
break;
|
||||
case "ge":
|
||||
addCriterion(field+" >= ", value, field);
|
||||
break;
|
||||
case "lt":
|
||||
addCriterion(field+" < ", value, field);
|
||||
break;
|
||||
case "le":
|
||||
addCriterion(field+" <= ", value, field);
|
||||
break;
|
||||
}
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static class Criteria extends GeneratedCriteria {
|
||||
|
||||
protected Criteria() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Criterion {
|
||||
private String condition;
|
||||
|
||||
private Object value;
|
||||
|
||||
private Object secondValue;
|
||||
|
||||
private boolean noValue;
|
||||
|
||||
private boolean singleValue;
|
||||
|
||||
private boolean betweenValue;
|
||||
|
||||
private boolean listValue;
|
||||
|
||||
private String typeHandler;
|
||||
|
||||
public String getCondition() {
|
||||
return condition;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Object getSecondValue() {
|
||||
return secondValue;
|
||||
}
|
||||
|
||||
public boolean isNoValue() {
|
||||
return noValue;
|
||||
}
|
||||
|
||||
public boolean isSingleValue() {
|
||||
return singleValue;
|
||||
}
|
||||
|
||||
public boolean isBetweenValue() {
|
||||
return betweenValue;
|
||||
}
|
||||
|
||||
public boolean isListValue() {
|
||||
return listValue;
|
||||
}
|
||||
|
||||
public String getTypeHandler() {
|
||||
return typeHandler;
|
||||
}
|
||||
|
||||
protected Criterion(String condition) {
|
||||
super();
|
||||
this.condition = condition;
|
||||
this.typeHandler = null;
|
||||
this.noValue = true;
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value, String typeHandler) {
|
||||
super();
|
||||
this.condition = condition;
|
||||
this.value = value;
|
||||
this.typeHandler = typeHandler;
|
||||
if (value instanceof List<?>) {
|
||||
this.listValue = true;
|
||||
} else {
|
||||
this.singleValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value) {
|
||||
this(condition, value, null);
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
|
||||
super();
|
||||
this.condition = condition;
|
||||
this.value = value;
|
||||
this.secondValue = secondValue;
|
||||
this.typeHandler = typeHandler;
|
||||
this.betweenValue = true;
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value, Object secondValue) {
|
||||
this(condition, value, secondValue, null);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package io.dataease.base.mapper.ext.query;
|
||||
|
||||
public interface GridSql {
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
<?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="io.dataease.base.mapper.ext.query.GridSql">
|
||||
|
||||
<sql id="gridCondition">
|
||||
<where>
|
||||
<foreach collection="oredCriteria" item="criteria" separator="or">
|
||||
<if test="criteria.valid">
|
||||
<trim prefix="(" prefixOverrides="and" suffix=")">
|
||||
<foreach collection="criteria.criteria" item="criterion">
|
||||
<choose>
|
||||
<when test="criterion.noValue">
|
||||
and ${criterion.condition}
|
||||
</when>
|
||||
<when test="criterion.singleValue">
|
||||
and ${criterion.condition} #{criterion.value}
|
||||
</when>
|
||||
<when test="criterion.betweenValue">
|
||||
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
|
||||
</when>
|
||||
<when test="criterion.listValue">
|
||||
and ${criterion.condition}
|
||||
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
|
||||
#{listItem}
|
||||
</foreach>
|
||||
</when>
|
||||
</choose>
|
||||
</foreach>
|
||||
</trim>
|
||||
</if>
|
||||
</foreach>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
</mapper>
|
@ -3,6 +3,7 @@ package io.dataease.controller.sys;
|
||||
import io.dataease.base.domain.SysDept;
|
||||
import io.dataease.commons.utils.BeanUtils;
|
||||
import io.dataease.controller.ResultHolder;
|
||||
import io.dataease.controller.sys.base.BaseGridRequest;
|
||||
import io.dataease.controller.sys.request.DeptCreateRequest;
|
||||
import io.dataease.controller.sys.request.DeptDeleteRequest;
|
||||
import io.dataease.controller.sys.request.DeptStatusRequest;
|
||||
@ -39,6 +40,19 @@ public class SysDeptController extends ResultHolder {
|
||||
return nodeResponses;
|
||||
}
|
||||
|
||||
@PostMapping("/search")
|
||||
public List<DeptNodeResponse> search(@RequestBody BaseGridRequest request){
|
||||
List<SysDept> nodes = deptService.nodesTreeByCondition(request);
|
||||
//List<SysDept> nodes = deptService.nodesByPid(pid);
|
||||
List<DeptNodeResponse> nodeResponses = nodes.stream().map(node -> {
|
||||
DeptNodeResponse deptNodeResponse = BeanUtils.copyBean(new DeptNodeResponse(), node);
|
||||
deptNodeResponse.setHasChildren(node.getSubCount() > 0);
|
||||
deptNodeResponse.setTop(node.getPid() == deptService.DEPT_ROOT_PID);
|
||||
return deptNodeResponse;
|
||||
}).collect(Collectors.toList());
|
||||
return nodeResponses;
|
||||
}
|
||||
|
||||
@ApiOperation("查询部门")
|
||||
@PostMapping("/root")
|
||||
public ResultHolder rootData(){
|
||||
|
@ -6,6 +6,7 @@ import com.github.pagehelper.PageHelper;
|
||||
import io.dataease.base.domain.SysRole;
|
||||
import io.dataease.commons.utils.PageUtils;
|
||||
import io.dataease.commons.utils.Pager;
|
||||
import io.dataease.controller.sys.base.BaseGridRequest;
|
||||
import io.dataease.controller.sys.request.RoleGridRequest;
|
||||
import io.dataease.controller.sys.request.RoleMenusRequest;
|
||||
import io.dataease.controller.sys.response.RoleUserItem;
|
||||
@ -49,7 +50,7 @@ public class SysRoleController {
|
||||
|
||||
@ApiOperation("查询角色")
|
||||
@PostMapping("/roleGrid/{goPage}/{pageSize}")
|
||||
public Pager<List<SysRole>> roleGrid(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody RoleGridRequest request) {
|
||||
public Pager<List<SysRole>> roleGrid(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody BaseGridRequest request) {
|
||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||
Pager<List<SysRole>> listPager = PageUtils.setPageInfo(page, sysRoleService.query(request));
|
||||
return listPager;
|
||||
|
@ -5,6 +5,7 @@ import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import io.dataease.commons.utils.PageUtils;
|
||||
import io.dataease.commons.utils.Pager;
|
||||
import io.dataease.controller.sys.base.BaseGridRequest;
|
||||
import io.dataease.controller.sys.request.SysUserCreateRequest;
|
||||
import io.dataease.controller.sys.request.SysUserPwdRequest;
|
||||
import io.dataease.controller.sys.request.SysUserStateRequest;
|
||||
@ -27,10 +28,14 @@ public class SysUserController {
|
||||
|
||||
@ApiOperation("查询用户")
|
||||
@PostMapping("/userGrid/{goPage}/{pageSize}")
|
||||
public Pager<List<SysUserGridResponse>> userGrid(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody UserGridRequest request) {
|
||||
public Pager<List<SysUserGridResponse>> userGrid(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody BaseGridRequest request) {
|
||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||
return PageUtils.setPageInfo(page, sysUserService.query(request));
|
||||
}
|
||||
/*public Pager<List<SysUserGridResponse>> userGrid(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody UserGridRequest request) {
|
||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||
return PageUtils.setPageInfo(page, sysUserService.query(request));
|
||||
}*/
|
||||
|
||||
@ApiOperation("创建用户")
|
||||
@PostMapping("/create")
|
||||
|
@ -0,0 +1,24 @@
|
||||
package io.dataease.controller.sys.base;
|
||||
|
||||
import io.dataease.base.mapper.ext.query.GridExample;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Data
|
||||
public class BaseGridRequest implements Serializable {
|
||||
|
||||
private List<ConditionEntity> conditions;
|
||||
|
||||
public GridExample convertExample(){
|
||||
GridExample gridExample = new GridExample();
|
||||
if (CollectionUtils.isEmpty(conditions))return gridExample;
|
||||
|
||||
GridExample.Criteria criteria = gridExample.createCriteria();
|
||||
conditions.forEach(criteria::addCondtion);
|
||||
return gridExample;
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package io.dataease.controller.sys.base;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class ConditionEntity implements Serializable {
|
||||
|
||||
private String field;
|
||||
|
||||
private String operator;
|
||||
|
||||
private Object value;
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package io.dataease.controller.sys.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SimpleTreeNode {
|
||||
|
||||
private Long id;
|
||||
|
||||
private Long pid;
|
||||
}
|
@ -4,16 +4,20 @@ import io.dataease.base.domain.SysDept;
|
||||
import io.dataease.base.domain.SysDeptExample;
|
||||
import io.dataease.base.mapper.SysDeptMapper;
|
||||
import io.dataease.base.mapper.ext.ExtDeptMapper;
|
||||
import io.dataease.base.mapper.ext.query.GridExample;
|
||||
import io.dataease.commons.utils.BeanUtils;
|
||||
import io.dataease.commons.utils.CommonBeanFactory;
|
||||
import io.dataease.controller.sys.base.BaseGridRequest;
|
||||
import io.dataease.controller.sys.request.DeptCreateRequest;
|
||||
import io.dataease.controller.sys.request.DeptDeleteRequest;
|
||||
import io.dataease.controller.sys.request.DeptStatusRequest;
|
||||
import io.dataease.controller.sys.request.SimpleTreeNode;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@ -23,11 +27,11 @@ public class DeptService {
|
||||
private final static Integer DEFAULT_SUBCOUNT = 0;
|
||||
public final static Long DEPT_ROOT_PID = 0L;
|
||||
|
||||
@Resource
|
||||
@Autowired(required = false)
|
||||
private SysDeptMapper sysDeptMapper;
|
||||
|
||||
|
||||
@Resource
|
||||
@Autowired(required = false)
|
||||
private ExtDeptMapper extDeptMapper;
|
||||
|
||||
public List<SysDept> nodesByPid(Long pid){
|
||||
@ -120,4 +124,59 @@ public class DeptService {
|
||||
return sysDeptMapper.updateByPrimaryKeySelective(sysDept);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<SysDept> nodesTreeByCondition(BaseGridRequest request){
|
||||
//DeptService proxy = proxy();
|
||||
List<SimpleTreeNode> allNodes = allNodes();
|
||||
List<SimpleTreeNode> targetNodes = nodeByCondition(request);
|
||||
List<Long> ids = upTree(allNodes, targetNodes);
|
||||
SysDeptExample example = new SysDeptExample();
|
||||
SysDeptExample.Criteria criteria = example.createCriteria();
|
||||
criteria.andDeptIdIn(ids);
|
||||
example.setOrderByClause("dept_sort");
|
||||
List<SysDept> sysDepts = sysDeptMapper.selectByExample(example);
|
||||
return sysDepts;
|
||||
}
|
||||
|
||||
private DeptService proxy(){
|
||||
return CommonBeanFactory.getBean(DeptService.class);
|
||||
}
|
||||
|
||||
|
||||
private List<SimpleTreeNode> allNodes(){
|
||||
List<SimpleTreeNode> simpleTreeNodes = extDeptMapper.allNodes();
|
||||
return simpleTreeNodes;
|
||||
}
|
||||
|
||||
private List<SimpleTreeNode> nodeByCondition(BaseGridRequest request){
|
||||
GridExample gridExample = request.convertExample();
|
||||
List<SimpleTreeNode> simpleTreeNodes = extDeptMapper.nodesByExample(gridExample);
|
||||
return simpleTreeNodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* 找出目标节点所在路径上的所有节点 向上找
|
||||
* @param allNodes 所有节点
|
||||
* @param targetNodes 目标节点
|
||||
* @return
|
||||
*/
|
||||
private List<Long> upTree(List<SimpleTreeNode> allNodes, List<SimpleTreeNode> targetNodes){
|
||||
final Map<Long, SimpleTreeNode> map = targetNodes.stream().collect(Collectors.toMap(SimpleTreeNode::getId, node -> node));
|
||||
List<Long> results = targetNodes.parallelStream().flatMap(targetNode -> {
|
||||
//向上逐级找爹
|
||||
List<Long> ids = new ArrayList<>();
|
||||
SimpleTreeNode node = targetNode;
|
||||
while (node != null) {
|
||||
ids.add(node.getId());
|
||||
Long pid = node.getPid();
|
||||
node = map.get(pid);
|
||||
}
|
||||
return ids.stream();
|
||||
}).distinct().collect(Collectors.toList());
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import io.dataease.base.domain.SysUsersRolesExample;
|
||||
import io.dataease.base.mapper.SysRoleMapper;
|
||||
import io.dataease.base.mapper.SysUsersRolesMapper;
|
||||
import io.dataease.base.mapper.ext.ExtSysRoleMapper;
|
||||
import io.dataease.controller.sys.base.BaseGridRequest;
|
||||
import io.dataease.controller.sys.request.RoleGridRequest;
|
||||
import io.dataease.controller.sys.request.RoleMenusRequest;
|
||||
import io.dataease.controller.sys.response.RoleUserItem;
|
||||
@ -56,8 +57,8 @@ public class SysRoleService {
|
||||
}
|
||||
|
||||
|
||||
public List<SysRole> query(RoleGridRequest request){
|
||||
List<SysRole> result = extSysRoleMapper.query(request);
|
||||
public List<SysRole> query(BaseGridRequest request){
|
||||
List<SysRole> result = extSysRoleMapper.query(request.convertExample());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -7,8 +7,10 @@ import io.dataease.base.domain.SysUsersRolesKey;
|
||||
import io.dataease.base.mapper.SysUserMapper;
|
||||
import io.dataease.base.mapper.SysUsersRolesMapper;
|
||||
import io.dataease.base.mapper.ext.ExtSysUserMapper;
|
||||
import io.dataease.base.mapper.ext.query.GridExample;
|
||||
import io.dataease.commons.utils.BeanUtils;
|
||||
import io.dataease.commons.utils.CodingUtil;
|
||||
import io.dataease.controller.sys.base.BaseGridRequest;
|
||||
import io.dataease.controller.sys.request.SysUserCreateRequest;
|
||||
import io.dataease.controller.sys.request.SysUserPwdRequest;
|
||||
import io.dataease.controller.sys.request.SysUserStateRequest;
|
||||
@ -40,8 +42,10 @@ public class SysUserService {
|
||||
@Resource
|
||||
private ExtSysUserMapper extSysUserMapper;
|
||||
|
||||
public List<SysUserGridResponse> query(UserGridRequest request){
|
||||
List<SysUserGridResponse> lists = extSysUserMapper.query(request);
|
||||
|
||||
public List<SysUserGridResponse> query(BaseGridRequest request){
|
||||
GridExample gridExample = request.convertExample();
|
||||
List<SysUserGridResponse> lists = extSysUserMapper.query(gridExample);
|
||||
lists.forEach(item -> {
|
||||
List<SysUserRole> roles = item.getRoles();
|
||||
List<Long> roleIds = roles.stream().map(SysUserRole::getRoleId).collect(Collectors.toList());
|
||||
|
@ -8,6 +8,15 @@ export function getDeptTree(pid) {
|
||||
})
|
||||
}
|
||||
|
||||
export function loadTable(data) {
|
||||
return request({
|
||||
url: 'api/dept/search',
|
||||
method: 'post',
|
||||
data,
|
||||
loading: true
|
||||
})
|
||||
}
|
||||
|
||||
export function addDept(data) {
|
||||
return request({
|
||||
url: '/api/dept/create',
|
||||
@ -32,4 +41,4 @@ export function editDept(data) {
|
||||
})
|
||||
}
|
||||
|
||||
export default { addDept, delDept, editDept, getDeptTree }
|
||||
export default { addDept, delDept, editDept, getDeptTree, loadTable }
|
||||
|
@ -137,16 +137,28 @@ export function param2Obj(url) {
|
||||
)
|
||||
}
|
||||
|
||||
// export function formatCondition(param) {
|
||||
// if (!param) {
|
||||
// return null
|
||||
// }
|
||||
// const condition = {}
|
||||
// for (const key in param) {
|
||||
// if (Object.hasOwnProperty.call(param, key)) {
|
||||
// const element = param[key]
|
||||
// condition[element.field] = element.value
|
||||
// }
|
||||
// }
|
||||
// return condition
|
||||
// }
|
||||
|
||||
export function formatCondition(param) {
|
||||
if (!param) {
|
||||
return null
|
||||
}
|
||||
const condition = {}
|
||||
for (const key in param) {
|
||||
if (Object.hasOwnProperty.call(param, key)) {
|
||||
const element = param[key]
|
||||
condition[element.field] = element.value
|
||||
}
|
||||
const result = { conditions: [] }
|
||||
for (const [key, value] of Object.entries(param)) {
|
||||
console.log(`${key}`)
|
||||
result.conditions.push(value)
|
||||
}
|
||||
return condition
|
||||
return result
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
ref="table"
|
||||
:data="tableData"
|
||||
lazy
|
||||
:load="initTableData"
|
||||
:load="loadExpandDatas"
|
||||
:columns="columns"
|
||||
:buttons="buttons"
|
||||
:header="header"
|
||||
@ -13,7 +13,7 @@
|
||||
:pagination-config="paginationConfig"
|
||||
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
|
||||
row-key="deptId"
|
||||
@search="initTableData"
|
||||
@search="search"
|
||||
>
|
||||
<template #buttons>
|
||||
<fu-table-button icon="el-icon-circle-plus-outline" :label="$t('organization.create')" @click="create" />
|
||||
@ -107,10 +107,11 @@
|
||||
import LayoutContent from '@/components/business/LayoutContent'
|
||||
import ComplexTable from '@/components/business/complex-table'
|
||||
import Treeselect from '@riophae/vue-treeselect'
|
||||
import { formatCondition } from '@/utils/index'
|
||||
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
|
||||
import { LOAD_CHILDREN_OPTIONS, LOAD_ROOT_OPTIONS } from '@riophae/vue-treeselect'
|
||||
|
||||
import { getDeptTree, addDept, editDept, delDept } from '@/api/system/dept'
|
||||
import { getDeptTree, addDept, editDept, delDept, loadTable } from '@/api/system/dept'
|
||||
|
||||
export default {
|
||||
name: 'MsOrganization',
|
||||
@ -131,7 +132,6 @@ export default {
|
||||
changeStatusPath: '/api/dept/updateStatus',
|
||||
result: {},
|
||||
dialogOrgAddVisible: false,
|
||||
condition: {},
|
||||
tableData: [],
|
||||
maps: new Map(),
|
||||
oldPid: null,
|
||||
@ -160,9 +160,9 @@ export default {
|
||||
}
|
||||
],
|
||||
searchConfig: {
|
||||
useQuickSearch: false,
|
||||
useQuickSearch: true,
|
||||
useComplexSearch: false,
|
||||
quickPlaceholder: '按姓名搜索',
|
||||
quickPlaceholder: '按名称搜索',
|
||||
components: [
|
||||
|
||||
]
|
||||
@ -171,22 +171,23 @@ export default {
|
||||
currentPage: 1,
|
||||
pageSize: 10,
|
||||
total: 0
|
||||
},
|
||||
defaultCondition: {
|
||||
field: 'pid',
|
||||
operator: 'eq',
|
||||
value: 0
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
activated() {
|
||||
this.initTableData()
|
||||
this.search()
|
||||
},
|
||||
methods: {
|
||||
create() {
|
||||
this.dialogOrgAddVisible = true
|
||||
this.formType = 'add'
|
||||
},
|
||||
search(condition) {
|
||||
console.log(condition)
|
||||
},
|
||||
|
||||
edit(row) {
|
||||
this.dialogOrgAddVisible = true
|
||||
this.formType = 'modify'
|
||||
@ -236,31 +237,87 @@ export default {
|
||||
return roots
|
||||
},
|
||||
|
||||
initTableData(row, treeNode, resolve) {
|
||||
const _self = this
|
||||
const pid = (row && row.deptId) ? row.deptId : '0'
|
||||
getDeptTree(pid).then(response => {
|
||||
let data = response.data
|
||||
quick_condition(condition) {
|
||||
const result = {}
|
||||
if (condition && condition.quick) {
|
||||
for (const [key, value] of Object.entries(condition)) {
|
||||
// console.log(`${key}`)
|
||||
if (`${key}` === 'quick') {
|
||||
const v_new = Object.assign({}, value)
|
||||
v_new['field'] = 'name'
|
||||
result['name'] = v_new
|
||||
} else {
|
||||
result[`${key}`] = value
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
return Object.assign({}, condition)
|
||||
},
|
||||
// 加载表格数据
|
||||
search(condition) {
|
||||
let param = {}
|
||||
if (condition && condition.quick) {
|
||||
const con = this.quick_condition(condition)
|
||||
param = formatCondition(con)
|
||||
} else {
|
||||
param = { conditions: [this.defaultCondition] }
|
||||
}
|
||||
|
||||
// param.conditions.push(this.defaultCondition)
|
||||
loadTable(param).then(res => {
|
||||
let data = res.data
|
||||
data = data.map(obj => {
|
||||
if (obj.subCount > 0) {
|
||||
obj.hasChildren = true
|
||||
}
|
||||
return obj
|
||||
})
|
||||
if (!row) {
|
||||
data.some(node => {
|
||||
node.children = null
|
||||
})
|
||||
_self.tableData = data
|
||||
_self.depts = null
|
||||
} else {
|
||||
this.maps.set(row.deptId, { row, treeNode, resolve })
|
||||
resolve && resolve(data)
|
||||
}
|
||||
this.tableData = data
|
||||
this.depts = null
|
||||
})
|
||||
},
|
||||
|
||||
// 加载下一级子节点数据
|
||||
loadExpandDatas(row, treeNode, resolve) {
|
||||
getDeptTree(row.deptId).then(res => {
|
||||
let data = res.data
|
||||
data = data.map(obj => {
|
||||
if (obj.subCount > 0) {
|
||||
obj.hasChildren = true
|
||||
}
|
||||
return obj
|
||||
})
|
||||
this.maps.set(row.deptId, { row, treeNode, resolve })
|
||||
resolve && resolve(data)
|
||||
})
|
||||
},
|
||||
|
||||
// initTableData(row, treeNode, resolve) {
|
||||
// const _self = this
|
||||
// const pid = (row && row.deptId) ? row.deptId : '0'
|
||||
// getDeptTree(pid).then(response => {
|
||||
// let data = response.data
|
||||
// data = data.map(obj => {
|
||||
// if (obj.subCount > 0) {
|
||||
// obj.hasChildren = true
|
||||
// }
|
||||
// return obj
|
||||
// })
|
||||
// if (!row) {
|
||||
// data.some(node => {
|
||||
// node.children = null
|
||||
// })
|
||||
// _self.tableData = data
|
||||
// _self.depts = null
|
||||
// } else {
|
||||
// this.maps.set(row.deptId, { row, treeNode, resolve })
|
||||
// resolve && resolve(data)
|
||||
// }
|
||||
// })
|
||||
// },
|
||||
closeFunc() {
|
||||
this.initTableData()
|
||||
this.search()
|
||||
this.form = {}
|
||||
this.oldPid = null
|
||||
this.depts = null
|
||||
@ -329,7 +386,7 @@ export default {
|
||||
if (this.formType !== 'modify') {
|
||||
addDept(this.form).then(res => {
|
||||
this.$success(this.$t('commons.save_success'))
|
||||
this.initTableData()
|
||||
this.search()
|
||||
this.oldPid && this.reloadByPid(this.oldPid)
|
||||
this.reloadByPid(this.form['pid'])
|
||||
this.dialogOrgAddVisible = false
|
||||
@ -337,7 +394,7 @@ export default {
|
||||
} else {
|
||||
editDept(this.form).then(res => {
|
||||
this.$success(this.$t('commons.save_success'))
|
||||
this.initTableData()
|
||||
this.search()
|
||||
this.oldPid && this.reloadByPid(this.oldPid)
|
||||
this.reloadByPid(this.form['pid'])
|
||||
this.dialogOrgAddVisible = false
|
||||
@ -358,7 +415,7 @@ export default {
|
||||
const requests = [{ deptId: organization.deptId, pid: organization.pid }]
|
||||
delDept(requests).then(res => {
|
||||
this.$success(this.$t('commons.delete_success'))
|
||||
this.initTableData()
|
||||
this.search()
|
||||
this.reloadByPid(organization.pid)
|
||||
})
|
||||
}).catch(() => {
|
||||
@ -372,7 +429,7 @@ export default {
|
||||
if (pid !== 0 && this.maps.get(pid)) {
|
||||
const { row, treeNode, resolve } = this.maps.get(pid)
|
||||
this.$set(this.$refs.table.store.states.lazyTreeNodeMap, pid, [])
|
||||
this.initTableData(row, treeNode, resolve)
|
||||
this.loadExpandDatas(row, treeNode, resolve)
|
||||
}
|
||||
},
|
||||
array2Tree(arr) {
|
||||
|
@ -83,6 +83,7 @@
|
||||
|
||||
import LayoutContent from '@/components/business/LayoutContent'
|
||||
import ComplexTable from '@/components/business/complex-table'
|
||||
import { formatCondition } from '@/utils/index'
|
||||
import { addRole, editRole, delRole, roleGrid, addRoleMenus, menuIds } from '@/api/system/role'
|
||||
|
||||
import { getMenusTree, getChild } from '@/api/system/menu'
|
||||
@ -124,21 +125,13 @@ export default {
|
||||
}
|
||||
],
|
||||
searchConfig: {
|
||||
useQuickSearch: false,
|
||||
quickPlaceholder: '按名称搜索',
|
||||
components: [
|
||||
// { field: 'name', label: '姓名', component: 'FuComplexInput', defaultOperator: 'eq' },
|
||||
{ field: 'name', label: '名称', component: 'FuComplexInput' },
|
||||
{ field: 'name', label: '角色名称', component: 'FuComplexInput' },
|
||||
|
||||
{
|
||||
field: 'enabled',
|
||||
label: '状态',
|
||||
component: 'FuComplexSelect',
|
||||
options: [
|
||||
{ label: '启用', value: '1' },
|
||||
{ label: '禁用', value: '0' }
|
||||
],
|
||||
multiple: false
|
||||
}
|
||||
{ field: 'code', label: '角色代码', component: 'FuComplexInput', defaultOperator: 'eq' }
|
||||
// { field: 'deptId', label: '组织', component: conditionTable }
|
||||
]
|
||||
},
|
||||
@ -164,8 +157,10 @@ export default {
|
||||
this.formType = 'add'
|
||||
this.dialogVisible = true
|
||||
},
|
||||
search() {
|
||||
roleGrid(this.paginationConfig.currentPage, this.paginationConfig.pageSize, {}).then(response => {
|
||||
search(condition) {
|
||||
const temp = formatCondition(condition)
|
||||
const param = temp || {}
|
||||
roleGrid(this.paginationConfig.currentPage, this.paginationConfig.pageSize, param).then(response => {
|
||||
const data = response.data
|
||||
this.total = data.itemCount
|
||||
this.tableData = data.listObject
|
||||
|
@ -177,13 +177,14 @@ export default {
|
||||
}
|
||||
],
|
||||
searchConfig: {
|
||||
useQuickSearch: false,
|
||||
quickPlaceholder: '按姓名搜索',
|
||||
components: [
|
||||
// { field: 'name', label: '姓名', component: 'FuComplexInput', defaultOperator: 'eq' },
|
||||
{ field: 'name', label: '姓名', component: 'FuComplexInput' },
|
||||
{ field: 'nick_name', label: '姓名', component: 'FuComplexInput' },
|
||||
|
||||
{
|
||||
field: 'enabled',
|
||||
field: 'u.enabled',
|
||||
label: '状态',
|
||||
component: 'FuComplexSelect',
|
||||
options: [
|
||||
@ -295,13 +296,15 @@ export default {
|
||||
|
||||
search(condition) {
|
||||
console.log(condition) // demo只查看搜索条件,没有搜索的实现
|
||||
const param = formatCondition(condition)
|
||||
const temp = formatCondition(condition)
|
||||
const param = temp || {}
|
||||
const { currentPage, pageSize } = this.paginationConfig
|
||||
userLists(currentPage, pageSize, param || {}).then(response => {
|
||||
userLists(currentPage, pageSize, param).then(response => {
|
||||
this.data = response.data.listObject
|
||||
this.paginationConfig.total = response.data.itemCount
|
||||
})
|
||||
},
|
||||
|
||||
create() {
|
||||
this.formType = 'add'
|
||||
this.form = Object.assign({}, this.defaultForm)
|
||||
|
Loading…
Reference in New Issue
Block a user