feat:在编非编统计
This commit is contained in:
1 parent
53d6dfd551
commit
05480e806b
7 files changed
+269
-37
No files matched your search
+40
@@ -0,0 +1,40 @@
|
||||
package com.bsd.pjcloud.admin.api.vo.total;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class UserStaffingTotalVo {
|
||||
|
||||
/**
|
||||
* 部门id
|
||||
*/
|
||||
private Long deptId;
|
||||
|
||||
/**
|
||||
* 部门名
|
||||
*/
|
||||
private String deptName;
|
||||
|
||||
/**
|
||||
* 部门总人数
|
||||
*/
|
||||
private Long deptTotalPerson = 0L;
|
||||
|
||||
/**
|
||||
* 在编人数
|
||||
*/
|
||||
private Long staffingPerson = 0L;
|
||||
|
||||
/**
|
||||
* 非在编人数
|
||||
*/
|
||||
private Long noneStaffingPerson = 0L;
|
||||
|
||||
/**
|
||||
* 统计人数
|
||||
*/
|
||||
private Long totalPerson = 0L;
|
||||
|
||||
}
|
||||
+11
-10
@@ -133,16 +133,16 @@ public class SysUserController {
|
||||
@GetMapping("/get-name-or-mobile")
|
||||
public R<List<UserDeptSimpleInfo>> getUserByNameOrMobile(@RequestParam("keyword") String keyword) {
|
||||
List<SysUser> users = userService.list(
|
||||
Wrappers.<SysUser>query().lambda()
|
||||
.eq(SysUser::getName, keyword)
|
||||
.or()
|
||||
.eq(SysUser::getPhone, keyword)
|
||||
Wrappers.<SysUser>query().lambda()
|
||||
.eq(SysUser::getName, keyword)
|
||||
.or()
|
||||
.eq(SysUser::getPhone, keyword)
|
||||
);
|
||||
if (CollectionUtils.isEmpty(users)) {
|
||||
return R.failed(MsgUtils.getMessage(ErrorCodes.SYS_USER_USERINFO_EMPTY, keyword));
|
||||
}
|
||||
Map<Long, SysDept> deptListByDeptIds = sysDeptService.getDeptListByDeptIds(
|
||||
users.stream().map(SysUser::getDeptId).collect(Collectors.toList())
|
||||
users.stream().map(SysUser::getDeptId).collect(Collectors.toList())
|
||||
);
|
||||
List<UserDeptSimpleInfo> userDeptSimpleInfos = users.stream().map(user -> {
|
||||
UserDeptSimpleInfo userDeptSimpleInfo = new UserDeptSimpleInfo();
|
||||
@@ -419,14 +419,15 @@ public class SysUserController {
|
||||
|
||||
/**
|
||||
* 根据部门id查询用户列表
|
||||
*
|
||||
* @param deptId
|
||||
* @return
|
||||
*/
|
||||
// @Inner
|
||||
@GetMapping("/getUserIdListByDeptId")
|
||||
public R<List<SimpleUserListVO>> getUserIdListByDeptId(@RequestParam("deptId")Long deptId,
|
||||
@RequestParam(value = "name",required = false) String name) {
|
||||
return R.ok(userService.listUserIdByDeptId(deptId,name));
|
||||
public R<List<SimpleUserListVO>> getUserIdListByDeptId(@RequestParam("deptId") Long deptId,
|
||||
@RequestParam(value = "name", required = false) String name) {
|
||||
return R.ok(userService.listUserIdByDeptId(deptId, name));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -497,7 +498,7 @@ public class SysUserController {
|
||||
@Schema(description = "根据ids获取用户map")
|
||||
public R<Map<Long, SysUser>> getUserMap(@RequestParam(value = "userIds") Set<Long> userIds) {
|
||||
LambdaQueryWrapper<SysUser> sysUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysUserLambdaQueryWrapper.in(SysUser::getUserId, userIds);
|
||||
sysUserLambdaQueryWrapper.in(ObjectUtil.isNotEmpty(userIds), SysUser::getUserId, userIds);
|
||||
List<SysUser> list = userService.list(sysUserLambdaQueryWrapper);
|
||||
Map<Long, SysUser> userMap = list.stream().collect(Collectors.toMap(SysUser::getUserId, user -> user));
|
||||
return R.ok(userMap);
|
||||
@@ -544,7 +545,7 @@ public class SysUserController {
|
||||
}
|
||||
List<SysUserRole> list = sysUserRoleService.list(Wrappers.<SysUserRole>lambdaQuery().eq(SysUserRole::getRoleId, sysRole.getRoleId()));
|
||||
List<Long> userIds = list.stream().map(sysUserRole -> sysUserRole.getUserId()).collect(Collectors.toList());
|
||||
List<SysUser> listData = userService.list(Wrappers.<SysUser>lambdaQuery().in(SysUser::getUserId, userIds));
|
||||
List<SysUser> listData = userService.list(Wrappers.<SysUser>lambdaQuery().in(SysUser::getUserId, userIds));
|
||||
//转换成vo,只返回id+手机号+姓名,安全考虑
|
||||
List<UserSimpleVo> userVOList = listData.stream().map(sysUser -> {
|
||||
UserSimpleVo userVO = new UserSimpleVo();
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package com.bsd.pjcloud.admin.controller.total;
|
||||
|
||||
import com.bsd.pjcloud.admin.api.dto.UserDTO;
|
||||
import com.bsd.pjcloud.admin.api.vo.total.UserStaffingTotalVo;
|
||||
import com.bsd.pjcloud.admin.service.SysUserTotalService;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 用户相关统计
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/user/total")
|
||||
@Tag(description = "connect", name = "用户相关统计")
|
||||
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
|
||||
public class SysUserTotalController {
|
||||
|
||||
private final SysUserTotalService sysUserTotalService;
|
||||
|
||||
@Operation(summary = "用户在/非编人员统计", description = "用户在/非编人员统计")
|
||||
@PostMapping("/staffing-total")
|
||||
public R<List<UserStaffingTotalVo>> staffingTotal(@RequestBody UserDTO dto) {
|
||||
DataScope dataScope = null;
|
||||
return R.ok(sysUserTotalService.staffingTotal(dto, dataScope));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+36
-27
@@ -24,6 +24,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.bsd.pjcloud.admin.api.dto.UserDTO;
|
||||
import com.bsd.pjcloud.admin.api.entity.SysUser;
|
||||
import com.bsd.pjcloud.admin.api.vo.UserVO;
|
||||
import com.bsd.pjcloud.admin.api.vo.total.UserStaffingTotalVo;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.common.data.datascope.PjcloudBaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@@ -42,35 +43,43 @@ import java.util.List;
|
||||
@Mapper
|
||||
public interface SysUserMapper extends PjcloudBaseMapper<SysUser> {
|
||||
|
||||
/**
|
||||
* 通过用户名查询用户信息(含有角色信息)
|
||||
* @param username 用户名
|
||||
* @return userVo
|
||||
*/
|
||||
UserVO getUserVoByUsername(String username);
|
||||
/**
|
||||
* 通过用户名查询用户信息(含有角色信息)
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return userVo
|
||||
*/
|
||||
UserVO getUserVoByUsername(String username);
|
||||
|
||||
/**
|
||||
* 分页查询用户信息(含角色)
|
||||
* @param page 分页
|
||||
* @param userDTO 查询参数
|
||||
* @param dataScope
|
||||
* @return list
|
||||
*/
|
||||
IPage<UserVO> getUserVosPage(Page page, @Param("query") UserDTO userDTO, DataScope dataScope);
|
||||
/**
|
||||
* 分页查询用户信息(含角色)
|
||||
*
|
||||
* @param page 分页
|
||||
* @param userDTO 查询参数
|
||||
* @param dataScope
|
||||
* @return list
|
||||
*/
|
||||
IPage<UserVO> getUserVosPage(Page page, @Param("query") UserDTO userDTO, DataScope dataScope);
|
||||
|
||||
/**
|
||||
* 通过ID查询用户信息
|
||||
* @param id 用户ID
|
||||
* @return userVo
|
||||
*/
|
||||
UserVO getUserVoById(Long id);
|
||||
/**
|
||||
* 通过ID查询用户信息
|
||||
*
|
||||
* @param id 用户ID
|
||||
* @return userVo
|
||||
*/
|
||||
UserVO getUserVoById(Long id);
|
||||
|
||||
/**
|
||||
* 查询用户列表
|
||||
* @param userDTO 查询条件
|
||||
* @param dataScope 数据权限声明
|
||||
* @return
|
||||
*/
|
||||
List<UserVO> selectVoListByScope(@Param("query") UserDTO userDTO, @Param("ids") Long[] ids, DataScope dataScope);
|
||||
/**
|
||||
* 查询用户列表
|
||||
*
|
||||
* @param userDTO 查询条件
|
||||
* @param dataScope 数据权限声明
|
||||
* @return
|
||||
*/
|
||||
List<UserVO> selectVoListByScope(@Param("query") UserDTO userDTO, @Param("ids") Long[] ids, DataScope dataScope);
|
||||
|
||||
/**
|
||||
* 用户在/非编人员统计
|
||||
*/
|
||||
List<UserStaffingTotalVo> staffingListByDept(@Param("dto") UserDTO dto, DataScope dataScope);
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.bsd.pjcloud.admin.service;
|
||||
|
||||
import com.bsd.pjcloud.admin.api.dto.UserDTO;
|
||||
import com.bsd.pjcloud.admin.api.vo.total.UserStaffingTotalVo;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SysUserTotalService {
|
||||
|
||||
/**
|
||||
* 用户在/非编人员统计
|
||||
*/
|
||||
List<UserStaffingTotalVo> staffingTotal(UserDTO dto, DataScope dataScope);
|
||||
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
package com.bsd.pjcloud.admin.service.impl.total;
|
||||
|
||||
|
||||
import cn.hutool.core.collection.IterUtil;
|
||||
import cn.hutool.core.collection.IterableIter;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.bsd.pjcloud.admin.api.dto.DeptAllListDto;
|
||||
import com.bsd.pjcloud.admin.api.dto.UserDTO;
|
||||
import com.bsd.pjcloud.admin.api.entity.SysDept;
|
||||
import com.bsd.pjcloud.admin.api.vo.total.UserStaffingTotalVo;
|
||||
import com.bsd.pjcloud.admin.mapper.SysDeptMapper;
|
||||
import com.bsd.pjcloud.admin.mapper.SysUserMapper;
|
||||
import com.bsd.pjcloud.admin.service.SysDeptService;
|
||||
import com.bsd.pjcloud.admin.service.SysUserTotalService;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.flow.task.constant.TaskCheckStatusEnum;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.core.parameters.P;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SysUserTotalServiceImpl implements SysUserTotalService {
|
||||
|
||||
private final SysUserMapper sysUserMapper;
|
||||
private final SysDeptMapper sysDeptMapper;
|
||||
|
||||
private final SysDeptService sysDeptService;
|
||||
|
||||
/**
|
||||
* 用户在/非编人员统计
|
||||
*/
|
||||
@Override
|
||||
public List<UserStaffingTotalVo> staffingTotal(UserDTO dto, DataScope dataScope) {
|
||||
// 查询部门
|
||||
DeptAllListDto deptDto = new DeptAllListDto();
|
||||
deptDto.setIsInclude(dto.getIsInclude());
|
||||
if (ObjectUtil.isNotEmpty(dto.getDeptId())) {
|
||||
deptDto.setDeptId(dto.getDeptId());
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(dto.getDeptIds())) {
|
||||
deptDto.setDeptId(null);
|
||||
deptDto.setDeptIds(dto.getDeptIds());
|
||||
}
|
||||
List<SysDept> deptList = sysDeptMapper.allList(deptDto);
|
||||
if (ObjectUtil.isEmpty(deptList)) return null;
|
||||
List<UserStaffingTotalVo> disposeDeptList = deptList.stream().map(item -> {
|
||||
UserStaffingTotalVo entity = new UserStaffingTotalVo();
|
||||
entity.setDeptId(item.getDeptId());
|
||||
entity.setDeptName(item.getName());
|
||||
return entity;
|
||||
}).toList();
|
||||
|
||||
dto.setProcessStatus(TaskCheckStatusEnum.RESULT.getCode());
|
||||
List<UserStaffingTotalVo> list = sysUserMapper.staffingListByDept(dto, dataScope);
|
||||
// 查询部门名字
|
||||
disposeStaffingTotal(list);
|
||||
Map<Long, UserStaffingTotalVo> sqlMap = IterUtil.toMap(list, UserStaffingTotalVo::getDeptId);
|
||||
|
||||
for (UserStaffingTotalVo vo : disposeDeptList) {
|
||||
UserStaffingTotalVo targetMap = sqlMap.get(vo.getDeptId());
|
||||
if (ObjectUtil.isEmpty(targetMap)) continue;
|
||||
vo.setDeptTotalPerson(targetMap.getDeptTotalPerson());
|
||||
vo.setStaffingPerson(targetMap.getStaffingPerson());
|
||||
vo.setNoneStaffingPerson(targetMap.getNoneStaffingPerson());
|
||||
vo.setTotalPerson(targetMap.getTotalPerson());
|
||||
}
|
||||
|
||||
return disposeDeptList;
|
||||
}
|
||||
|
||||
private void disposeStaffingTotal(List<UserStaffingTotalVo> list) {
|
||||
if (ObjectUtil.isEmpty(list)) return;
|
||||
List<Long> dpetIdList = list.stream().map(UserStaffingTotalVo::getDeptId).distinct().filter(ObjectUtil::isNotEmpty).toList();
|
||||
if (ObjectUtil.isNotEmpty(dpetIdList)) {
|
||||
Map<Long, SysDept> deptMaps = sysDeptService.getDeptListByDeptIds(dpetIdList);
|
||||
if (ObjectUtil.isNotEmpty(deptMaps)) {
|
||||
for (UserStaffingTotalVo v : list) {
|
||||
SysDept sysDept = deptMaps.get(v.getDeptId());
|
||||
if (ObjectUtil.isEmpty(sysDept)) continue;
|
||||
v.setDeptName(sysDept.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -318,4 +318,36 @@
|
||||
ORDER BY u.create_time DESC
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="staffingListByDept" resultType="com.bsd.pjcloud.admin.api.vo.total.UserStaffingTotalVo">
|
||||
select a.dept_id,
|
||||
count(0) as deptTotalPerson,
|
||||
sum(if(a.staffing_type = '1', 1, 0)) as staffingPerson,
|
||||
sum(if(a.staffing_type = '2', 1, 0)) as noneStaffingPerson,
|
||||
sum(if(a.staffing_type is not null, 1, 0)) as totalPerson
|
||||
from sys_user a
|
||||
<where>
|
||||
a.del_flag = '0'
|
||||
and a.dept_id is not null
|
||||
<if test="dto.deptIds != null and dto.deptIds.size() != 0">
|
||||
<choose>
|
||||
<when test="dto.isInclude != null and dto.isInclude == true">
|
||||
and a.dept_id IN
|
||||
</when>
|
||||
<when test="dto.isInclude != null and dto.isInclude == false">
|
||||
and a.dept_id NOT IN
|
||||
</when>
|
||||
<otherwise>
|
||||
and a.dept_id IN
|
||||
</otherwise>
|
||||
</choose>
|
||||
<foreach collection="dto.deptIds" index="index" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
group by a.dept_id
|
||||
order by a.dept_id
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Reference in new issue
Block a user