添加部门用户排序功能
This commit is contained in:
parent
58a1671fc2
commit
15b0ec994a
@ -5,6 +5,7 @@ import ink.wgink.pojo.dtos.department.DepartmentUserDTO;
|
|||||||
import ink.wgink.pojo.result.SuccessResultList;
|
import ink.wgink.pojo.result.SuccessResultList;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When you feel like quitting. Think about why you started
|
* When you feel like quitting. Think about why you started
|
||||||
@ -18,6 +19,30 @@ import java.util.List;
|
|||||||
**/
|
**/
|
||||||
public interface IDepartmentUserBaseService {
|
public interface IDepartmentUserBaseService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 机构用户列表
|
||||||
|
*
|
||||||
|
* @param params
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<DepartmentUserDTO> list(Map<String, Object> params);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 机构用户列表
|
||||||
|
*
|
||||||
|
* @param departmentId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<DepartmentUserDTO> list(String departmentId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 机构用户列表
|
||||||
|
*
|
||||||
|
* @param departmentIds
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<DepartmentUserDTO> list(List<String> departmentIds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户ID列表
|
* 用户ID列表
|
||||||
*
|
*
|
||||||
@ -26,6 +51,7 @@ public interface IDepartmentUserBaseService {
|
|||||||
*/
|
*/
|
||||||
List<String> listUserId(String departmentId);
|
List<String> listUserId(String departmentId);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户ID列表
|
* 用户ID列表
|
||||||
*
|
*
|
||||||
|
@ -27,7 +27,8 @@ public class DepartmentUserDTO implements Serializable {
|
|||||||
private String departmentName;
|
private String departmentName;
|
||||||
private String userSort;
|
private String userSort;
|
||||||
|
|
||||||
public DepartmentUserDTO() {}
|
public DepartmentUserDTO() {
|
||||||
|
}
|
||||||
|
|
||||||
public DepartmentUserDTO(UserDTO userDTO) {
|
public DepartmentUserDTO(UserDTO userDTO) {
|
||||||
this.userId = userDTO.getUserId();
|
this.userId = userDTO.getUserId();
|
||||||
@ -41,6 +42,18 @@ public class DepartmentUserDTO implements Serializable {
|
|||||||
this.userAvatar = userDTO.getUserAvatar();
|
this.userAvatar = userDTO.getUserAvatar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUser(UserDTO userDTO) {
|
||||||
|
this.userId = userDTO.getUserId();
|
||||||
|
this.userUsername = userDTO.getUserUsername();
|
||||||
|
this.userName = userDTO.getUserName();
|
||||||
|
this.userPhone = userDTO.getUserPhone();
|
||||||
|
this.userEmail = userDTO.getUserEmail();
|
||||||
|
this.loginType = userDTO.getLoginType();
|
||||||
|
this.userType = userDTO.getUserType();
|
||||||
|
this.userState = userDTO.getUserState();
|
||||||
|
this.userAvatar = userDTO.getUserAvatar();
|
||||||
|
}
|
||||||
|
|
||||||
public String getUserId() {
|
public String getUserId() {
|
||||||
return userId == null ? "" : userId;
|
return userId == null ? "" : userId;
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import ink.wgink.exceptions.RemoveException;
|
|||||||
import ink.wgink.exceptions.SaveException;
|
import ink.wgink.exceptions.SaveException;
|
||||||
import ink.wgink.exceptions.SearchException;
|
import ink.wgink.exceptions.SearchException;
|
||||||
import ink.wgink.exceptions.UpdateException;
|
import ink.wgink.exceptions.UpdateException;
|
||||||
|
import ink.wgink.pojo.dtos.department.DepartmentUserDTO;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -53,6 +54,15 @@ public interface IDepartmentUserDao {
|
|||||||
*/
|
*/
|
||||||
void updateSort(Map<String, Object> params) throws UpdateException;
|
void updateSort(Map<String, Object> params) throws UpdateException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门用户ID列表
|
||||||
|
*
|
||||||
|
* @param params
|
||||||
|
* @return
|
||||||
|
* @throws SearchException
|
||||||
|
*/
|
||||||
|
List<DepartmentUserDTO> list(Map<String, Object> params) throws SearchException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户ID列表
|
* 用户ID列表
|
||||||
*
|
*
|
||||||
|
@ -134,6 +134,25 @@ public class DepartmentUserServiceImpl extends DefaultBaseService implements IDe
|
|||||||
return departmentService.listPO(departmentIds);
|
return departmentService.listPO(departmentIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DepartmentUserDTO> list(Map<String, Object> params) {
|
||||||
|
return departmentUserDao.list(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DepartmentUserDTO> list(String departmentId) {
|
||||||
|
Map<String, Object> params = getHashMap(2);
|
||||||
|
params.put("departmentId", departmentId);
|
||||||
|
return list(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DepartmentUserDTO> list(List<String> departmentIds) {
|
||||||
|
Map<String, Object> params = getHashMap(2);
|
||||||
|
params.put("departmentIds", departmentIds);
|
||||||
|
return list(params);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> listUserId(String departmentId) {
|
public List<String> listUserId(String departmentId) {
|
||||||
Map<String, Object> params = getHashMap(2);
|
Map<String, Object> params = getHashMap(2);
|
||||||
@ -166,20 +185,10 @@ public class DepartmentUserServiceImpl extends DefaultBaseService implements IDe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SuccessResultList<List<DepartmentUserDTO>> listPage(String departmentId, ListPage page) {
|
public SuccessResultList<List<DepartmentUserDTO>> listPage(String departmentId, ListPage page) {
|
||||||
SuccessResultList<List<UserDTO>> successResultList;
|
|
||||||
if (StringUtils.equals(departmentId, ISystemConstant.TREE_BASE_ROOT_ID_VALUE)) {
|
if (StringUtils.equals(departmentId, ISystemConstant.TREE_BASE_ROOT_ID_VALUE)) {
|
||||||
successResultList = listPageUserByExcludeDepartment(page);
|
return listPageUserByExcludeDepartment(page);
|
||||||
} else {
|
|
||||||
successResultList = listPageUser(departmentId, page);
|
|
||||||
}
|
}
|
||||||
List<UserDTO> userDTOs = successResultList.getRows();
|
return listPageUser(departmentId, page);
|
||||||
List<DepartmentUserDTO> departmentUserDTOs = new ArrayList<>();
|
|
||||||
for (UserDTO userDTO : userDTOs) {
|
|
||||||
DepartmentUserDTO departmentUserDTO = new DepartmentUserDTO(userDTO);
|
|
||||||
departmentUserDTO.setDepartmentId(departmentId);
|
|
||||||
departmentUserDTOs.add(departmentUserDTO);
|
|
||||||
}
|
|
||||||
return new SuccessResultList<>(departmentUserDTOs, successResultList.getPage(), successResultList.getTotal());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> listGroupUserId(Map<String, Object> params) {
|
private List<String> listGroupUserId(Map<String, Object> params) {
|
||||||
@ -192,9 +201,17 @@ public class DepartmentUserServiceImpl extends DefaultBaseService implements IDe
|
|||||||
* @param page
|
* @param page
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private SuccessResultList<List<UserDTO>> listPageUserByExcludeDepartment(ListPage page) {
|
private SuccessResultList<List<DepartmentUserDTO>> listPageUserByExcludeDepartment(ListPage page) {
|
||||||
List<String> hasDepartmentUserIds = listGroupUserId(new HashMap<>(0));
|
List<DepartmentUserDTO> hasDepartmentUsers = list(getHashMap(0));
|
||||||
return userBaseService.listPageByExcludeIds(hasDepartmentUserIds, page);
|
if (hasDepartmentUsers.isEmpty()) {
|
||||||
|
return new SuccessResultList<>(new ArrayList<>(), 1, 0L);
|
||||||
|
}
|
||||||
|
List<String> userIds = new ArrayList<>();
|
||||||
|
for (DepartmentUserDTO hasDepartmentUserId : hasDepartmentUsers) {
|
||||||
|
userIds.add(hasDepartmentUserId.getUserId());
|
||||||
|
}
|
||||||
|
SuccessResultList<List<UserDTO>> successResultList = userBaseService.listPageByExcludeIds(userIds, page);
|
||||||
|
return listPageDepartmentUser(successResultList, hasDepartmentUsers, page);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -204,11 +221,42 @@ public class DepartmentUserServiceImpl extends DefaultBaseService implements IDe
|
|||||||
* @param page
|
* @param page
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private SuccessResultList<List<UserDTO>> listPageUser(String departmentId, ListPage page) {
|
private SuccessResultList<List<DepartmentUserDTO>> listPageUser(String departmentId, ListPage page) {
|
||||||
List<String> userIds = listUserId(departmentId);
|
List<DepartmentUserDTO> hasDepartmentUsers = list(getHashMap(0));
|
||||||
if (userIds.isEmpty()) {
|
if (hasDepartmentUsers.isEmpty()) {
|
||||||
return new SuccessResultList<>(new ArrayList<>(), 1, 0L);
|
return new SuccessResultList<>(new ArrayList<>(), 1, 0L);
|
||||||
}
|
}
|
||||||
return userBaseService.listPageByIds(userIds, page);
|
List<String> userIds = new ArrayList<>();
|
||||||
|
for (DepartmentUserDTO hasDepartmentUserId : hasDepartmentUsers) {
|
||||||
|
userIds.add(hasDepartmentUserId.getUserId());
|
||||||
|
}
|
||||||
|
SuccessResultList<List<UserDTO>> successResultList = userBaseService.listPageByIds(userIds, page);
|
||||||
|
return listPageDepartmentUser(successResultList, hasDepartmentUsers, page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 机构用户分页列表
|
||||||
|
*
|
||||||
|
* @param userIds
|
||||||
|
* @param hasDepartmentUsers
|
||||||
|
* @param page
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private SuccessResultList<List<DepartmentUserDTO>> listPageDepartmentUser(SuccessResultList<List<UserDTO>> successResultList, List<DepartmentUserDTO> hasDepartmentUsers, ListPage page) {
|
||||||
|
// 查询用户排序
|
||||||
|
List<UserDTO> userDTOs = successResultList.getRows();
|
||||||
|
List<DepartmentUserDTO> departmentUserDTOs = new ArrayList<>();
|
||||||
|
for (DepartmentUserDTO hasDepartmentUserDTO : hasDepartmentUsers) {
|
||||||
|
for (UserDTO userDTO : userDTOs) {
|
||||||
|
if (StringUtils.equals(userDTO.getUserId(), hasDepartmentUserDTO.getUserId())) {
|
||||||
|
DepartmentUserDTO departmentUserDTO = new DepartmentUserDTO(userDTO);
|
||||||
|
departmentUserDTO.setDepartmentId(hasDepartmentUserDTO.getDepartmentId());
|
||||||
|
departmentUserDTO.setUserSort(hasDepartmentUserDTO.getUserSort());
|
||||||
|
departmentUserDTOs.add(departmentUserDTO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SuccessResultList<>(departmentUserDTOs, successResultList.getPage(), successResultList.getTotal());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,12 @@
|
|||||||
|
|
||||||
<cache flushInterval="3600000"/>
|
<cache flushInterval="3600000"/>
|
||||||
|
|
||||||
|
<resultMap id="departmentUserDTO" type="ink.wgink.pojo.dtos.department.DepartmentUserDTO">
|
||||||
|
<result column="department_id" property="departmentId"/>
|
||||||
|
<result column="user_id" property="userId"/>
|
||||||
|
<result column="user_sort" property="userSort"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
<!-- 建表 -->
|
<!-- 建表 -->
|
||||||
<update id="createTable">
|
<update id="createTable">
|
||||||
CREATE TABLE IF NOT EXISTS `sys_department_user` (
|
CREATE TABLE IF NOT EXISTS `sys_department_user` (
|
||||||
@ -67,9 +73,40 @@
|
|||||||
WHERE
|
WHERE
|
||||||
department_id = #{departmentId}
|
department_id = #{departmentId}
|
||||||
AND
|
AND
|
||||||
user_sort = #{userSort}
|
user_id = #{userId}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
<!-- 机构用户列表 -->
|
||||||
|
<select id="list" parameterType="map" resultMap="departmentUserDTO" useCache="true">
|
||||||
|
SELECT
|
||||||
|
department_id,
|
||||||
|
user_id,
|
||||||
|
user_sort
|
||||||
|
FROM
|
||||||
|
sys_department_user
|
||||||
|
<where>
|
||||||
|
<if test="departmentId != null and departmentId != ''">
|
||||||
|
department_id = #{departmentId}
|
||||||
|
</if>
|
||||||
|
<if test="departmentIds != null and departmentIds.size > 0">
|
||||||
|
AND
|
||||||
|
department_id IN
|
||||||
|
<foreach collection="departmentIds" index="index" open="(" separator="," close=")">
|
||||||
|
#{departmentIds[${index}]}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
<if test="userIds != null and userIds.size > 0">
|
||||||
|
AND
|
||||||
|
user_id IN
|
||||||
|
<foreach collection="userIds" index="index" open="(" separator="," close=")">
|
||||||
|
#{userIds[${index}]}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
ORDER BY
|
||||||
|
user_sort
|
||||||
|
</select>
|
||||||
|
|
||||||
<!-- 用户ID列表 -->
|
<!-- 用户ID列表 -->
|
||||||
<select id="listUserId" parameterType="map" resultType="java.lang.String">
|
<select id="listUserId" parameterType="map" resultType="java.lang.String">
|
||||||
SELECT
|
SELECT
|
||||||
@ -82,19 +119,17 @@
|
|||||||
</if>
|
</if>
|
||||||
<if test="departmentIds != null and departmentIds.size > 0">
|
<if test="departmentIds != null and departmentIds.size > 0">
|
||||||
AND
|
AND
|
||||||
department_id IN (
|
department_id IN
|
||||||
<foreach collection="departmentIds" index="index" open="(" separator="," close=")">
|
<foreach collection="departmentIds" index="index" open="(" separator="," close=")">
|
||||||
#{departmentIds[${index}]}
|
#{departmentIds[${index}]}
|
||||||
</foreach>
|
</foreach>
|
||||||
)
|
|
||||||
</if>
|
</if>
|
||||||
<if test="userIds != null and userIds.size > 0">
|
<if test="userIds != null and userIds.size > 0">
|
||||||
AND
|
AND
|
||||||
user_id IN (
|
user_id IN
|
||||||
<foreach collection="userIds" index="index" open="(" separator="," close=")">
|
<foreach collection="userIds" index="index" open="(" separator="," close=")">
|
||||||
#{userIds[${index}]}
|
#{userIds[${index}]}
|
||||||
</foreach>
|
</foreach>
|
||||||
)
|
|
||||||
</if>
|
</if>
|
||||||
</where>
|
</where>
|
||||||
ORDER BY
|
ORDER BY
|
||||||
|
@ -80,11 +80,7 @@
|
|||||||
{field:'rowNum', width:80, title: '序号', align:'center', templet: '<span>{{d.LAY_INDEX}}</span>'},
|
{field:'rowNum', width:80, title: '序号', align:'center', templet: '<span>{{d.LAY_INDEX}}</span>'},
|
||||||
{field:'userUsername', width:140, title: '用户名', align:'center'},
|
{field:'userUsername', width:140, title: '用户名', align:'center'},
|
||||||
{field:'userName', width:140, title: '昵称', align:'center'},
|
{field:'userName', width:140, title: '昵称', align:'center'},
|
||||||
{field:'userSort', width:140, title: '排序', align:'center',
|
{field:'userSort', width:140, title: '排序[编辑更新]', align:'center', edit: 'text'},
|
||||||
templet: function(item) {
|
|
||||||
return '<a href="javascript:void(0);" lay-event="sortEvent"'+ item.userSort +'</a>';
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{field:'userPhone', width:140, title: '手机', align:'center',
|
{field:'userPhone', width:140, title: '手机', align:'center',
|
||||||
templet: function(item) {
|
templet: function(item) {
|
||||||
if(!item.userPhone) {
|
if(!item.userPhone) {
|
||||||
@ -264,13 +260,38 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
table.on('tool(dataTable)', function(obj) {
|
|
||||||
var data = obj.data;
|
|
||||||
var event = obj.event;
|
|
||||||
if(event === 'sortEvent') {
|
|
||||||
|
|
||||||
|
function userSortFormat(value) {
|
||||||
|
if(/^[a-zA-Z0-9]{3}\-[a-zA-Z0-9]{3}$/g.test(value)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
table.on('edit(dataTable)', function(obj) {
|
||||||
|
if(obj.field === 'userSort') {
|
||||||
|
if(!userSortFormat(obj.value)) {
|
||||||
|
top.dialog.msg('排序格式不正确,格式应为XXX-XXX,其中X为0-9、a-z、A-Z');
|
||||||
|
reloadTable();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var loadLayerIndex;
|
||||||
|
top.restAjax.put(top.restAjax.path('api/department/user/update-sort/{departmentId}', [departmentId]), {
|
||||||
|
userId: obj.data.userId,
|
||||||
|
userSort: obj.value
|
||||||
|
}, null, function(code, data) {
|
||||||
|
top.dialog.msg('更新成功');
|
||||||
|
reloadTable();
|
||||||
|
}, function(code, data) {
|
||||||
|
top.dialog.msg(data.msg);
|
||||||
|
}, function() {
|
||||||
|
loadLayerIndex = top.dialog.msg(top.dataMessage.committing, {icon: 16, time: 0, shade: 0.3});
|
||||||
|
}, function() {
|
||||||
|
top.dialog.close(loadLayerIndex);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
Loading…
Reference in New Issue
Block a user