This commit is contained in:
parent
53b2555838
commit
d69f5d9944
|
|
@ -0,0 +1,138 @@
|
|||
package com.bonus.config;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 分页索引
|
||||
*/
|
||||
public class ListPagingUtil {
|
||||
private Integer currentPage;//当前页
|
||||
private Integer pageSize;//每页显示记录条数
|
||||
private Integer totalPage;//总页数
|
||||
private Integer star;//开始数据
|
||||
private Integer total;//总条数
|
||||
private List<?> rows;//每页显示的数据
|
||||
|
||||
|
||||
public Integer getCurrentPage() {
|
||||
return currentPage;
|
||||
}
|
||||
|
||||
public void setCurrentPage(Integer currentPage) {
|
||||
this.currentPage = currentPage;
|
||||
}
|
||||
|
||||
public Integer getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(Integer pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public Integer getTotalPage() {
|
||||
return totalPage;
|
||||
}
|
||||
|
||||
public void setTotalPage(Integer totalPage) {
|
||||
this.totalPage = totalPage;
|
||||
}
|
||||
|
||||
public List<?> getRows() {
|
||||
return rows;
|
||||
}
|
||||
|
||||
public void setRows(List<?> rows) {
|
||||
this.rows = rows;
|
||||
}
|
||||
|
||||
public Integer getStar() {
|
||||
return star;
|
||||
}
|
||||
|
||||
public void setStar(Integer star) {
|
||||
this.star = star;
|
||||
}
|
||||
|
||||
public Integer getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(Integer total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ListPagingUtil{" +
|
||||
"currentPage=" + currentPage +
|
||||
", pageSize=" + pageSize +
|
||||
", totalPage=" + totalPage +
|
||||
", rows=" + rows +
|
||||
", star=" + star +
|
||||
", total=" + total +
|
||||
'}';
|
||||
}
|
||||
|
||||
public void pageStartInfo(Integer currentPage, Integer pageSize){
|
||||
//如果传入的pageNumber为null给pageNumber赋为1
|
||||
currentPage = currentPage == null ? 1 : currentPage;
|
||||
//如果传入的pageSize为null给pageSize赋为10
|
||||
pageSize = pageSize == null ? 10 : pageSize;
|
||||
this.setCurrentPage(currentPage);
|
||||
this.setPageSize(pageSize);
|
||||
}
|
||||
|
||||
/*public static ListPagingUtil paging(Integer currentPage, Integer pageSize, List<?> list) {
|
||||
ListPagingUtil pagingUtil = new ListPagingUtil();
|
||||
//初始化
|
||||
pagingUtil.pageStartInfo(currentPage, pageSize);
|
||||
//设置起始数据
|
||||
pagingUtil.setStar((pagingUtil.getCurrentPage()-1)*pagingUtil.getPageSize());
|
||||
//设置总数
|
||||
pagingUtil.setTotal(list.size());
|
||||
//设置总页数
|
||||
pagingUtil.setTotalPage(pagingUtil.getTotal() % pagingUtil.getPageSize() == 0 ? pagingUtil.getTotal()/pagingUtil.getPageSize() :pagingUtil.getTotal()/pagingUtil.getPageSize()+1);
|
||||
//截取list
|
||||
pagingUtil.setRows(list.subList(pagingUtil.getStar(), pagingUtil.getTotal()-pagingUtil.getStar()>pagingUtil.getPageSize()?pagingUtil.getStar()+pagingUtil.getPageSize():pagingUtil.getTotal()));
|
||||
return pagingUtil;
|
||||
}*/
|
||||
|
||||
public static ListPagingUtil paging(Integer currentPage, Integer pageSize, List<?> list) {
|
||||
ListPagingUtil pagingUtil = new ListPagingUtil();
|
||||
|
||||
// 初始化分页信息
|
||||
pagingUtil.pageStartInfo(currentPage, pageSize);
|
||||
|
||||
// 计算起始索引
|
||||
pagingUtil.setStar((pagingUtil.getCurrentPage() - 1) * pagingUtil.getPageSize());
|
||||
|
||||
// 设置总数
|
||||
pagingUtil.setTotal(list.size());
|
||||
|
||||
// 设置总页数
|
||||
int totalPage = pagingUtil.getTotal() / pagingUtil.getPageSize();
|
||||
if (pagingUtil.getTotal() % pagingUtil.getPageSize() != 0) {
|
||||
totalPage++; // 如果有余数,则总页数 +1
|
||||
}
|
||||
pagingUtil.setTotalPage(totalPage);
|
||||
|
||||
// 确保起始索引不会大于列表大小
|
||||
int fromIndex = pagingUtil.getStar();
|
||||
if (fromIndex >= pagingUtil.getTotal()) {
|
||||
// 当前页的起始索引超过了总数据,返回空数据
|
||||
pagingUtil.setRows(Collections.emptyList());
|
||||
return pagingUtil;
|
||||
}
|
||||
|
||||
// 计算结束索引,确保不超过总数据大小
|
||||
int toIndex = Math.min(fromIndex + pagingUtil.getPageSize(), pagingUtil.getTotal());
|
||||
|
||||
// 获取当前页的数据
|
||||
pagingUtil.setRows(list.subList(fromIndex, toIndex));
|
||||
|
||||
return pagingUtil;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
package com.bonus.system.controller;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.bonus.common.core.constant.CacheConstants;
|
||||
import com.bonus.common.core.domain.R;
|
||||
import com.bonus.common.core.utils.ServletUtils;
|
||||
import com.bonus.common.core.utils.StringUtils;
|
||||
import com.bonus.common.core.utils.poi.ExcelUtil;
|
||||
import com.bonus.common.core.web.controller.BaseController;
|
||||
|
|
@ -15,6 +17,7 @@ import com.bonus.common.security.annotation.PreventRepeatSubmit;
|
|||
import com.bonus.common.security.annotation.RequiresPermissions;
|
||||
import com.bonus.common.security.annotation.RequiresPermissionsOrInnerAuth;
|
||||
import com.bonus.common.security.utils.SecurityUtils;
|
||||
import com.bonus.config.ListPagingUtil;
|
||||
import com.bonus.system.api.domain.SysDept;
|
||||
import com.bonus.system.api.domain.SysRole;
|
||||
import com.bonus.system.api.domain.SysUser;
|
||||
|
|
@ -90,6 +93,25 @@ public class SysUserController extends BaseController {
|
|||
return getDataTableError(new ArrayList<>());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户列表
|
||||
*/
|
||||
@RequiresPermissionsOrInnerAuth(innerAuth = @InnerAuth(isUser = false), requiresPermissions = @RequiresPermissions("system:user:list"))
|
||||
@GetMapping("/getList")
|
||||
@SysLog(title = "用户管理", businessType = OperaType.QUERY, logType = 0, module = "系统管理->用户管理", details = "查询用户列表")
|
||||
public AjaxResult getList(SysUser user) {
|
||||
|
||||
try {
|
||||
Integer pageIndex = Convert.toInt(ServletUtils.getParameter("pageNum"), 1);
|
||||
Integer pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10);
|
||||
List<SysUser> list = userService.getList(user);
|
||||
return success(ListPagingUtil.paging(pageIndex, pageSize, list));
|
||||
} catch (Exception e) {
|
||||
logger.error(e.toString(), e);
|
||||
}
|
||||
return success();
|
||||
}
|
||||
|
||||
@RequiresPermissions("system:user:export")
|
||||
@PostMapping("/export")
|
||||
@SysLog(title = "用户管理", businessType = OperaType.EXPORT, logType = 0, module = "系统管理->用户管理", details = "导出用户信息")
|
||||
|
|
|
|||
|
|
@ -155,4 +155,6 @@ public interface SysUserMapper {
|
|||
Integer approvalStatus(Long userId);
|
||||
|
||||
int systemUpdateUser(SysUser user);
|
||||
|
||||
List<SysUser> getList(SysUser user);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -238,4 +238,5 @@ public interface ISysUserService {
|
|||
public AjaxResult systemUpdateUser(SysUser user);
|
||||
|
||||
|
||||
List<SysUser> getList(SysUser user);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -633,6 +633,30 @@ public class SysUserServiceImpl implements ISysUserService {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysUser> getList(SysUser user) {
|
||||
try {
|
||||
//临时获取开始时间和结束时间
|
||||
String beginTime = (String) user.getParams().get("beginTime");
|
||||
String endTime = (String) user.getParams().get("endTime");
|
||||
BaseEntity entity = CommonDataPermissionInfo.backMissionInfo(user.getParams().get("dataScope").toString());
|
||||
BeanUtils.copyProperties(entity, user);
|
||||
user.getParams().put("beginTime", beginTime);
|
||||
user.getParams().put("endTime", endTime);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
user.setCompanyId(SecurityUtils.getLoginUser().getSysUser().getCompanyId());
|
||||
List<SysUser> sysUsers = userMapper.getList(user);
|
||||
if (!CollectionUtils.isEmpty(sysUsers)) {
|
||||
if (StringUtils.isNotBlank(user.getPhonenumber())) {
|
||||
sysUsers = sysUsers.stream().filter(sysUser -> sysUser.getPhonenumber().contains(Sm4Utils.decrypt(user.getPhonenumber()))).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
return sysUsers;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送简单邮件
|
||||
*
|
||||
|
|
|
|||
|
|
@ -261,6 +261,55 @@
|
|||
and del_flag = '0' limit 1
|
||||
</select>
|
||||
|
||||
<select id="getList" parameterType="SysUser" resultMap="SysUserResult">
|
||||
select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber,u.sex, u.status,
|
||||
u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,u.approval_status,u.is_permanent,u.is_built_in, d.dept_name,
|
||||
d.leader,r.role_id,
|
||||
r.role_name,
|
||||
r.role_key,
|
||||
r.role_sort,
|
||||
r.data_scope,
|
||||
r.status as role_status
|
||||
from sys_user u
|
||||
left join sys_dept d on u.dept_id = d.dept_id
|
||||
left join sys_user_role ur on u.user_id = ur.user_id
|
||||
left join sys_role r on r.role_id = ur.role_id
|
||||
where u.del_flag = '0'
|
||||
<if test="userId != null and userId != 0">
|
||||
AND u.user_id = #{userId}
|
||||
</if>
|
||||
<if test="userName != null and userName != ''">
|
||||
AND u.user_name like concat('%', #{userName}, '%')
|
||||
</if>
|
||||
<if test="nickName != null and nickName != ''">
|
||||
AND u.nick_name like concat('%', #{nickName}, '%')
|
||||
</if>
|
||||
<if test="status != null and status != ''">
|
||||
AND u.status = #{status}
|
||||
</if>
|
||||
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
|
||||
AND date_format(u.create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d')
|
||||
</if>
|
||||
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
|
||||
AND date_format(u.create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')
|
||||
</if>
|
||||
<if test="companyId != null and companyId != 0">
|
||||
AND (find_in_set(#{companyId}, ancestors) or u.dept_id = #{companyId})
|
||||
</if>
|
||||
<if test="deptId != null and deptId != 0">
|
||||
AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId},
|
||||
ancestors) ))
|
||||
</if>
|
||||
<if test="roleIds != null and roleIds.length > 0">
|
||||
and ur.role_id in
|
||||
<foreach collection="roleIds" item="item" index="index" separator="," open="(" close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<include refid="com.bonus.system.mapper.DataScopeMapper.dataScopeFilter"/>
|
||||
GROUP BY u.user_id
|
||||
</select>
|
||||
|
||||
<insert id="insertUser" parameterType="SysUser" useGeneratedKeys="true" keyProperty="userId">
|
||||
insert into sys_user(
|
||||
<if test="userId != null and userId != 0">user_id,</if>
|
||||
|
|
|
|||
Loading…
Reference in New Issue