commit
This commit is contained in:
@@ -146,20 +146,22 @@ public class SysUnitController {
|
||||
@At
|
||||
@ApiOperation("按关键字查询单位下的人员")
|
||||
@Ok("json:{ignoreNull:true}")
|
||||
public Result listUserSelect(@Valid String unitId, @Valid String keyWord) {
|
||||
Sql sql = Sqls.create("select id,loginname,username,unitname from vw_user $condition");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and(View_user::getUnitId, "=", unitId);
|
||||
SqlExpressionGroup seg = new SqlExpressionGroup();
|
||||
seg.orLike(View_user::getLoginname, keyWord, true);
|
||||
seg.orLike(View_user::getUsername, keyWord, true);
|
||||
cnd.and(seg);
|
||||
cnd.limit(1, 10);
|
||||
sql.setCondition(cnd);
|
||||
sql.setCallback(Sqls.callback.entities());
|
||||
sql.setEntity(sysUnitService.dao().getEntity(View_user.class));
|
||||
sysUnitService.dao().execute(sql);
|
||||
List<View_user> list = sql.getList(View_user.class);
|
||||
public Result listUserSelect(@Valid String unitId, @Valid String keyWord, @Valid String roleCode) {
|
||||
// Sql sql = Sqls.create("select id,loginname,username,unitname from vw_user $condition");
|
||||
// Cnd cnd = Cnd.NEW();
|
||||
// cnd.and(View_user::getUnitId, "=", unitId);
|
||||
// SqlExpressionGroup seg = new SqlExpressionGroup();
|
||||
// seg.orLike(View_user::getLoginname, keyWord, true);
|
||||
// seg.orLike(View_user::getUsername, keyWord, true);
|
||||
// cnd.and(seg);
|
||||
// cnd.limit(1, 10);
|
||||
// sql.setCondition(cnd);
|
||||
// sql.setCallback(Sqls.callback.entities());
|
||||
// sql.setEntity(sysUnitService.dao().getEntity(View_user.class));
|
||||
// sysUnitService.dao().execute(sql);
|
||||
// List<View_user> list = sql.getList(View_user.class);
|
||||
// 人员范围判断放到 service 层,便于按单位干部角色复用同一套查询规则。
|
||||
List<View_user> list = sysUnitService.listUserSelect(unitId, keyWord, roleCode);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,9 @@ package com.budwk.app.sys.services;
|
||||
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.sys.models.Sys_unit;
|
||||
import com.budwk.app.sys.views.View_user;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/12/22.
|
||||
@@ -22,6 +25,16 @@ public interface SysUnitService extends BaseService<Sys_unit> {
|
||||
*/
|
||||
void deleteAndChild(Sys_unit unit);
|
||||
|
||||
/**
|
||||
* 按单位干部角色查询可选择人员。
|
||||
*
|
||||
* @param unitId 当前单位ID
|
||||
* @param keyWord 人员工号或姓名关键字
|
||||
* @param roleCode 当前选择的单位干部角色编码
|
||||
* @return 可选择人员列表
|
||||
*/
|
||||
List<View_user> listUserSelect(String unitId, String keyWord, String roleCode);
|
||||
|
||||
/**
|
||||
* 清空缓存
|
||||
*/
|
||||
|
||||
@@ -1,21 +1,27 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.base.constant.RoleConstant;
|
||||
import com.budwk.app.base.constant.RedisConstant;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.models.Sys_unit;
|
||||
import com.budwk.app.sys.services.SysUnitService;
|
||||
import com.budwk.app.sys.views.View_user;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.dao.util.cri.SqlExpressionGroup;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheDefaults;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheRemoveAll;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/12/22.
|
||||
*/
|
||||
@@ -69,6 +75,71 @@ public class SysUnitServiceImpl extends BaseServiceImpl<Sys_unit> implements Sys
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 按单位干部角色查询可选择人员。
|
||||
* 选择单位党委书记时,人员范围放大到当前单位所属分工会下所有单位的人员;
|
||||
* 选择单位分管校领导时,查询已关联单位分管校领导角色的人员;其他角色保持当前单位范围。
|
||||
*
|
||||
* @param unitId 当前单位ID
|
||||
* @param keyWord 人员工号或姓名关键字
|
||||
* @param roleCode 当前选择的单位干部角色编码
|
||||
* @return 可选择人员列表
|
||||
*/
|
||||
@Override
|
||||
public List<View_user> listUserSelect(String unitId, String keyWord, String roleCode) {
|
||||
Sql sql;
|
||||
Cnd cnd = Cnd.NEW();
|
||||
if ("UNIT_SCHOOL_LEADER".equals(roleCode)) {
|
||||
sql = Sqls.create("""
|
||||
select distinct
|
||||
u.id,
|
||||
u.loginname,
|
||||
u.username,
|
||||
u.unitname
|
||||
from vw_user u
|
||||
inner join sys_user_role ur on ur.userId = u.id
|
||||
inner join sys_role r on r.id = ur.roleId
|
||||
$condition
|
||||
""");
|
||||
// 单位分管校领导从已绑定 UNIT_SCHOOL_LEADER 角色的人员中选择。
|
||||
cnd.and("r.code", "=", "UNIT_SCHOOL_LEADER");
|
||||
} else {
|
||||
sql = Sqls.create("select id,loginname,username,unitname from vw_user $condition");
|
||||
}
|
||||
if (RoleConstant.UNIT_PARTY_SECRETARY.name().equals(roleCode)) {
|
||||
Sys_unit unit = this.fetch(unitId);
|
||||
if (unit != null && Strings.isNotBlank(unit.getUnionId())) {
|
||||
SqlExpressionGroup scopeGroup = new SqlExpressionGroup();
|
||||
// 单位党委书记可从当前单位所属分工会下选择人员,同时保留本单位人员兜底。
|
||||
scopeGroup.or(View_user::getUnionId, "=", unit.getUnionId());
|
||||
scopeGroup.or(View_user::getUnitId, "=", unitId);
|
||||
cnd.and(scopeGroup);
|
||||
} else {
|
||||
// 当前单位未维护分工会时,至少保留本单位人员可选。
|
||||
cnd.and(View_user::getUnitId, "=", unitId);
|
||||
}
|
||||
} else if ("UNIT_SCHOOL_LEADER".equals(roleCode)) {
|
||||
// 角色范围已经通过 sys_user_role 与 sys_role 关联限定,这里不再叠加单位范围。
|
||||
} else {
|
||||
cnd.and(View_user::getUnitId, "=", unitId);
|
||||
}
|
||||
SqlExpressionGroup seg = new SqlExpressionGroup();
|
||||
if ("UNIT_SCHOOL_LEADER".equals(roleCode)) {
|
||||
seg.orLike("u.loginname", keyWord, true);
|
||||
seg.orLike("u.username", keyWord, true);
|
||||
} else {
|
||||
seg.orLike(View_user::getLoginname, keyWord, true);
|
||||
seg.orLike(View_user::getUsername, keyWord, true);
|
||||
}
|
||||
cnd.and(seg);
|
||||
cnd.limit(1, 10);
|
||||
sql.setCondition(cnd);
|
||||
sql.setCallback(Sqls.callback.entities());
|
||||
sql.setEntity(dao().getEntity(View_user.class));
|
||||
dao().execute(sql);
|
||||
return sql.getList(View_user.class);
|
||||
}
|
||||
|
||||
@CacheRemoveAll
|
||||
public void clearCache() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user