部门名称模糊查询、分页数量bug
This commit is contained in:
parent
82a0b3537b
commit
775ca92c02
|
@ -28,7 +28,6 @@ import org.springframework.web.bind.annotation.*;
|
|||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 部门管理
|
||||
|
@ -58,20 +57,11 @@ public class SysDeptController {
|
|||
@ApiOperation("分页")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType = "int"),
|
||||
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query", required = true, dataType = "int")
|
||||
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query", required = true, dataType = "int"),
|
||||
@ApiImplicitParam(name = "deptName", value = "部门名称", paramType = "query", dataType = "String")
|
||||
})
|
||||
public Result<PageData<SysDeptDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params) {
|
||||
long curPage = 1;
|
||||
long limit = 10;
|
||||
if (params.get(Constant.PAGE) != null) {
|
||||
curPage = Long.parseLong((String) params.get(Constant.PAGE));
|
||||
}
|
||||
if (params.get(Constant.LIMIT) != null) {
|
||||
limit = Long.parseLong((String) params.get(Constant.LIMIT));
|
||||
}
|
||||
List<SysDeptDTO> dtoList = sysDeptService.list(new HashMap<>(1));
|
||||
List<SysDeptDTO> result = dtoList.stream().skip((curPage - 1) * limit).limit(limit).collect(Collectors.toList());
|
||||
return new Result<PageData<SysDeptDTO>>().ok(new PageData(result, dtoList.size()));
|
||||
return new Result<PageData<SysDeptDTO>>().ok(sysDeptService.page(params));
|
||||
}
|
||||
|
||||
@GetMapping("listForRegion")
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package io.renren.modules.sys.service;
|
||||
|
||||
import io.renren.common.page.PageData;
|
||||
import io.renren.common.service.BaseService;
|
||||
import io.renren.modules.sys.dto.SysDeptDTO;
|
||||
import io.renren.modules.sys.entity.SysDeptEntity;
|
||||
|
@ -12,6 +13,8 @@ import java.util.Map;
|
|||
*/
|
||||
public interface SysDeptService extends BaseService<SysDeptEntity> {
|
||||
|
||||
PageData<SysDeptDTO> page(Map<String, Object> params);
|
||||
|
||||
List<SysDeptDTO> list(Map<String, Object> params);
|
||||
|
||||
SysDeptDTO get(Long id);
|
||||
|
|
|
@ -3,6 +3,7 @@ package io.renren.modules.sys.service.impl;
|
|||
import io.renren.common.constant.Constant;
|
||||
import io.renren.common.exception.ErrorCode;
|
||||
import io.renren.common.exception.RenException;
|
||||
import io.renren.common.page.PageData;
|
||||
import io.renren.common.service.impl.BaseServiceImpl;
|
||||
import io.renren.common.utils.ConvertUtils;
|
||||
import io.renren.common.utils.TreeUtils;
|
||||
|
@ -23,6 +24,7 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@Service
|
||||
|
@ -30,6 +32,28 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit
|
|||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
|
||||
@Override
|
||||
public PageData<SysDeptDTO> page(Map<String, Object> params) {
|
||||
long curPage = 1;
|
||||
long limit = 10;
|
||||
if (params.get(Constant.PAGE) != null) {
|
||||
curPage = Long.parseLong((String) params.get(Constant.PAGE));
|
||||
}
|
||||
if (params.get(Constant.LIMIT) != null) {
|
||||
limit = Long.parseLong((String) params.get(Constant.LIMIT));
|
||||
}
|
||||
//普通管理员,只能查询所属部门及子部门的数据
|
||||
UserDetail user = SecurityUser.getUser();
|
||||
if (user.getSuperAdmin() == SuperAdminEnum.NO.value()) {
|
||||
params.put("deptIdList", getSubDeptIdList(user.getDeptId()));
|
||||
}
|
||||
//查询部门列表
|
||||
List<SysDeptEntity> entityList = baseDao.getList(params);
|
||||
List<SysDeptDTO> dtoList = ConvertUtils.sourceToTarget(entityList, SysDeptDTO.class);
|
||||
List<SysDeptDTO> result = dtoList.stream().skip((curPage - 1) * limit).limit(limit).collect(Collectors.toList());
|
||||
return new PageData( TreeUtils.build(result), dtoList.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysDeptDTO> list(Map<String, Object> params) {
|
||||
//普通管理员,只能查询所属部门及子部门的数据
|
||||
|
|
|
@ -12,6 +12,9 @@
|
|||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="deptName != null and deptName.trim() != ''">
|
||||
and t1.name LIKE CONCAT( '%', #{deptName}, '%' )
|
||||
</if>
|
||||
order by t1.sort asc
|
||||
</select>
|
||||
|
||||
|
|
Loading…
Reference in New Issue