| | |
| | | |
| | | import cn.hutool.core.codec.Base64; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.gkhy.exam.common.annotation.DataScope; |
| | | import com.gkhy.exam.common.api.CommonPage; |
| | |
| | | import javax.validation.Validator; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | | |
| | | /** |
| | |
| | | } |
| | | return CommonPage.restPage(users); |
| | | } |
| | | |
| | | /** |
| | | * 根据条件分页查询已分配用户角色列表 |
| | | * |
| | |
| | | */ |
| | | @Override |
| | | @DataScope( userAlias = "u") |
| | | public List<SysUser> selectAllocatedList(SysUser user) |
| | | { |
| | | public List<SysUser> selectAllocatedList(SysUser user) { |
| | | return baseMapper.selectAllocatedList(user); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | @DataScope( userAlias = "u") |
| | | public List<SysUser> selectUnallocatedList(SysUser user) |
| | | { |
| | | public List<SysUser> selectUnallocatedList(SysUser user) { |
| | | return baseMapper.selectUnallocatedList(user); |
| | | } |
| | | |
| | |
| | | return row; |
| | | } |
| | | |
| | | @Override |
| | | public int updateSpecialCertificate(SysUser user) { |
| | | SysUser existUser = checkUserDataScope(user.getId()); |
| | | SysUser su = new SysUser().setId(user.getId()).setOperationCertificate(user.getOperationCertificate()); |
| | | su.setUpdateBy(SecurityUtils.getUsername()); |
| | | |
| | | int row = baseMapper.updateById(su); |
| | | if (row < 1) { |
| | | throw new ApiException("更新用户状态失败"); |
| | | } |
| | | return row; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public boolean resetUserPwd(SysUser user) { |
| | |
| | | public boolean checkUsernameUnique(SysUser user) { |
| | | Long userId = user.getId()==null? -1L : user.getId(); |
| | | SysUser info = baseMapper.checkLoginNameUnique(user.getUsername()); |
| | | if (info!=null && info.getId().longValue() != userId.longValue()) |
| | | { |
| | | if (info != null && info.getId().longValue() != userId.longValue()) { |
| | | return UserConstant.NOT_UNIQUE; |
| | | } |
| | | return UserConstant.UNIQUE; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> getUserData(Long companyId) { |
| | | List<SysUser> sysUsers = baseMapper.selectList(new LambdaQueryWrapper<>( |
| | | SysUser.class |
| | | ).eq(SysUser::getCompanyId, companyId).eq(SysUser::getDelFlag, UserConstant.ENABLE)); |
| | | int totalUser = sysUsers.size(); |
| | | |
| | | Map<String, Object> map = new HashMap<>(); |
| | | //总人数 |
| | | map.put("totalUser", totalUser); |
| | | //专业 |
| | | map.put("post", sysUsers.stream() |
| | | .map(SysUser::getPost) |
| | | .filter(Objects::nonNull) |
| | | .distinct() |
| | | .collect(Collectors.joining(","))); |
| | | //学历硕士以上 |
| | | // 统计学历为硕士(4)和博士及以上(5)的人数 |
| | | long count = sysUsers.stream() |
| | | .filter(user -> user.getQualification() != null) |
| | | .filter(user -> user.getQualification() >= 4) // 4: 硕士, 5: 博士及以上 |
| | | .count(); |
| | | map.put("qualification", count); |
| | | |
| | | long qualification1 = sysUsers.stream() |
| | | .filter(user -> user.getQualification() != null) |
| | | .filter(user -> user.getQualification().equals("1")) |
| | | .count(); |
| | | map.put("qualification1", qualification1);//学历1、高中及以下 |
| | | long qualification2 = sysUsers.stream() |
| | | .filter(user -> user.getQualification() != null) |
| | | .filter(user -> user.getQualification().equals("2")) |
| | | .count(); |
| | | map.put("qualification2", qualification2);//学历2、专科 |
| | | long qualification3 = sysUsers.stream() |
| | | .filter(user -> user.getQualification() != null) |
| | | .filter(user -> user.getQualification().equals("3")) |
| | | .count(); |
| | | map.put("qualification3", qualification3);//学历3本科 |
| | | long qualification4 = sysUsers.stream() |
| | | .filter(user -> user.getQualification() != null) |
| | | .filter(user -> user.getQualification().equals("4")) |
| | | .count(); |
| | | map.put("qualification4", qualification4);//学历4硕士 |
| | | |
| | | long qualification5 = sysUsers.stream() |
| | | .filter(user -> user.getQualification() != null) |
| | | .filter(user -> user.getQualification().equals("5")) |
| | | .count(); |
| | | map.put("qualification5", qualification5);//学历5博士及以上 |
| | | |
| | | //高级职称人数 |
| | | long positionalCount = sysUsers.stream() |
| | | .filter(user -> user.getPositional() != null) |
| | | .filter(user -> user.getPositional().equals("3")) // 4: 硕士, 5: 博士及以上 |
| | | .count(); |
| | | map.put("positional3", positionalCount); |
| | | long positionalCount2 = sysUsers.stream() |
| | | .filter(user -> user.getPositional() != null) |
| | | .filter(user -> user.getPositional().equals("2")) // 4: 硕士, 5: 博士及以上 |
| | | .count(); |
| | | map.put("positional2", positionalCount2);//中级 |
| | | long positionalCount1 = sysUsers.stream() |
| | | .filter(user -> user.getPositional() != null) |
| | | .filter(user -> user.getPositional().equals("1")) // 4: 硕士, 5: 博士及以上 |
| | | .count(); |
| | | map.put("positional1", positionalCount1);//初级 |
| | | |
| | | map.put("positional12", positionalCount2 + positionalCount1);//中级+初级 |
| | | |
| | | long countBk = sysUsers.stream() |
| | | .filter(user -> user.getQualification() != null) |
| | | .filter(user -> user.getQualification() >= 3) // 本科以上 |
| | | .count(); |
| | | //本科人数 |
| | | map.put("qualificationBK", countBk); |
| | | double bachelorRatio = totalUser > 0 ? (double) countBk / totalUser * 100 : 0; |
| | | //本科占比 |
| | | map.put("qualificationBKRatio", String.format("%.2f%%", bachelorRatio)); |
| | | |
| | | long countJS = sysUsers.stream() |
| | | .filter(user -> user.getPersonType() != null) |
| | | .filter(user -> user.getPersonType() == 1) // 技术类 |
| | | .count(); |
| | | map.put("personTypeJS", countJS); |
| | | double jsRatio = totalUser > 0 ? (double) countJS / totalUser * 100 : 0; |
| | | map.put("jsRatio", String.format("%.2f%%", jsRatio)); |
| | | double averageAge = sysUsers.stream() |
| | | .filter(user -> user.getAge() != null) // 过滤年龄为null的用户 |
| | | .mapToInt(SysUser::getAge) // 提取年龄值 |
| | | .average() // 计算平均值 |
| | | .orElse(0.0); |
| | | map.put("avgAge", String.format("%.1f", averageAge));//平均年龄 |
| | | |
| | | long countAge40 = sysUsers.stream() |
| | | .filter(user -> user.getAge() != null) |
| | | .filter(user -> user.getAge() >= 40) // 40以上人数 |
| | | .count(); |
| | | map.put("age40", countAge40); |
| | | double age40Ratio = totalUser > 0 ? (double) countAge40 / totalUser * 100 : 0; |
| | | map.put("age40Ratio", String.format("%.2f%%", age40Ratio)); |
| | | long countAge30 = totalUser - countAge40; |
| | | map.put("age1840", countAge30);//18-40 |
| | | double age30Ratio = totalUser > 0 ? (double) countAge30 / totalUser * 100 : 0; |
| | | map.put("age1840Ratio", String.format("%.2f%%", age30Ratio)); |
| | | |
| | | return Collections.emptyMap(); |
| | | } |
| | | |
| | | @Override |
| | | public boolean checkPhoneUnique(SysUser user) { |
| | | Long userId = user.getId()==null ? -1L : user.getId(); |
| | | SysUser info = baseMapper.checkPhoneUnique(user.getPhone()); |
| | | if (info!=null && info.getId().longValue() != userId.longValue()) |
| | | { |
| | | if (info != null && info.getId().longValue() != userId.longValue()) { |
| | | return UserConstant.NOT_UNIQUE; |
| | | } |
| | | return UserConstant.UNIQUE; |
| | |
| | | throw new ApiException("用户id为空!"); |
| | | } |
| | | SysUser user = getById(userId); |
| | | if (ObjectUtil.isNull(user)) |
| | | { |
| | | if (ObjectUtil.isNull(user)) { |
| | | throw new ApiException("用户数据不存在!"); |
| | | } |
| | | checkUserAllowed(user); |