| | |
| | | import cn.hutool.core.codec.Base64; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.gkhy.exam.common.annotation.DataScope; |
| | | import com.gkhy.exam.common.api.CommonPage; |
| | |
| | | import com.gkhy.exam.common.utils.RedisUtils; |
| | | import com.gkhy.exam.common.utils.SecurityUtils; |
| | | import com.gkhy.exam.common.utils.StringUtils; |
| | | import com.gkhy.exam.system.domain.EmployeeRecord; |
| | | import com.gkhy.exam.system.domain.ExStudent; |
| | | import com.gkhy.exam.system.domain.SysUserRole; |
| | | import com.gkhy.exam.system.domain.req.EmployeeRecordReq; |
| | | import com.gkhy.exam.system.domain.vo.EmployeeRecordVO; |
| | | import com.gkhy.exam.system.domain.vo.SpSysUser; |
| | | import com.gkhy.exam.system.mapper.EmployeeRecordMapper; |
| | | import com.gkhy.exam.system.mapper.SysUserMapper; |
| | | import com.gkhy.exam.system.mapper.SysUserRoleMapper; |
| | | import com.gkhy.exam.system.service.ExStudentService; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.validation.Validator; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | |
| | | @Autowired |
| | | private ExStudentService exStudentService; |
| | | |
| | | @Autowired |
| | | private EmployeeRecordMapper employeeRecordMapper; |
| | | |
| | | |
| | | @Override |
| | | public CommonPage<SysUser> selectUserList(SysUser user) { |
| | | SysUser currentUser = SecurityUtils.getLoginUser().getUser(); |
| | |
| | | } |
| | | PageUtils.startPage(); |
| | | users = baseMapper.userList(user); |
| | | } |
| | | return CommonPage.restPage(users); |
| | | } |
| | | |
| | | @Override |
| | | public CommonPage selectSpUserList(SysUser user) { |
| | | SysUser currentUser = SecurityUtils.getLoginUser().getUser(); |
| | | List<SpSysUser> users = new ArrayList<>(); |
| | | if (!currentUser.getUserType().equals(UserTypeEnum.WORKSHOP_USER.getCode())) { |
| | | if (!currentUser.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())) { |
| | | user.setCompanyId(currentUser.getCompanyId()); |
| | | Map<String, Object> paramsMap = new HashMap<>(); |
| | | // paramsMap.put("userType",currentUser.getUserType()); |
| | | user.setParams(paramsMap); |
| | | } |
| | | PageUtils.startPage(); |
| | | users = baseMapper.userSpList(user); |
| | | } |
| | | return CommonPage.restPage(users); |
| | | } |
| | |
| | | |
| | | @Override |
| | | public SysUser selectUserById(Long userId) { |
| | | |
| | | |
| | | |
| | | |
| | | return baseMapper.getUserById(userId); |
| | | } |
| | | |
| | |
| | | throw new ApiException("管理员用户不能被删除"); |
| | | } |
| | | delCacheByUsername(user.getUsername()); |
| | | return baseMapper.deleteUserById(userId); |
| | | int i = baseMapper.deleteUserById(userId); |
| | | if (i > 0){ |
| | | delEmployeeRecord(userId); |
| | | } |
| | | return i; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = RuntimeException.class) |
| | | public int addUser(SysUser user) { |
| | | ExStudent exStudent = new ExStudent(); |
| | | exStudent.setCompanyId(user.getCompanyId()); |
| | | exStudent.setName(user.getName()); |
| | | exStudent.setPassword(user.getPassword()); |
| | | exStudent.setDeptId(user.getDeptId()); |
| | | exStudent.setDuty(user.getDuty()); |
| | | exStudent.setSex(user.getSex()); |
| | | exStudent.setPhone(user.getPhone()); |
| | | |
| | | |
| | | checkRequestData(user); |
| | | checkUserAllowed(user); |
| | | user.setCreateBy(SecurityUtils.getUsername()); |
| | |
| | | |
| | | batchSaveRole(user.getRoles(), user.getId(), false); |
| | | |
| | | ExStudent exStudent = new ExStudent(); |
| | | exStudent.setCompanyId(user.getCompanyId()); |
| | | exStudent.setName(user.getName()); |
| | | exStudent.setPassword(user.getPassword()); |
| | | exStudent.setDeptId(user.getDeptId()); |
| | | exStudent.setDuty(user.getDuty()); |
| | | exStudent.setSex(user.getSex()); |
| | | exStudent.setPhone(user.getPhone()); |
| | | exStudent.setUserId(user.getId()); |
| | | exStudentService.insertStudent(exStudent); |
| | | |
| | | Integer internal = user.getInternal(); |
| | | if (internal == 0){ |
| | | EmployeeRecord employeeRecord = new EmployeeRecord(); |
| | | employeeRecord.setCompanyId(user.getCompanyId()); |
| | | employeeRecord.setUserId(user.getId()); |
| | | employeeRecord.setCreateBy(SecurityUtils.getUsername()); |
| | | employeeRecord.setCreateTime(LocalDateTime.now()); |
| | | saveEmployeeRecord(employeeRecord); |
| | | } |
| | | |
| | | if (row < 1) { |
| | | throw new ApiException("新增用户失败"); |
| | | } |
| | | return row; |
| | | } |
| | | |
| | | private void saveEmployeeRecord( EmployeeRecord employeeRecord){ |
| | | employeeRecordMapper.insert( employeeRecord); |
| | | } |
| | | |
| | | private void delEmployeeRecord(Long userId){ |
| | | LambdaUpdateWrapper<EmployeeRecord> updateWrapper = new LambdaUpdateWrapper<>(); |
| | | updateWrapper.eq(EmployeeRecord::getUserId,userId).set(EmployeeRecord::getDelFlag,1) |
| | | .set(EmployeeRecord::getUpdateBy,SecurityUtils.getUsername()).set(EmployeeRecord::getUpdateTime,LocalDateTime.now()); |
| | | employeeRecordMapper.update(new EmployeeRecord() ,updateWrapper); |
| | | } |
| | | |
| | | |
| | | public void batchSaveRole(List<SysRole> roleIds, Long userId, boolean isUpdate) { |
| | | |
| | |
| | | |
| | | @Override |
| | | public int updateUser(SysUser user) { |
| | | SysUser sysUser = selectUserById(user.getId()); |
| | | checkRequestData(user); |
| | | checkUserAllowed(user); |
| | | user.setUpdateBy(SecurityUtils.getUsername()); |
| | | user.setPassword(null); |
| | | int row = baseMapper.updateById(user); |
| | | batchSaveRole(user.getRoles(), user.getId(), true); |
| | | |
| | | if (sysUser.getInternal() == 0 && sysUser.getInternal() == 1){ |
| | | delEmployeeRecord(user.getId()); |
| | | }else if (sysUser.getInternal() == 1 && user.getInternal() == 0){ |
| | | EmployeeRecord employeeRecord = new EmployeeRecord(); |
| | | employeeRecord.setCompanyId(user.getCompanyId()); |
| | | employeeRecord.setUserId(user.getId()); |
| | | employeeRecord.setCreateBy(SecurityUtils.getUsername()); |
| | | employeeRecord.setCreateTime(LocalDateTime.now()); |
| | | saveEmployeeRecord(employeeRecord); |
| | | } |
| | | |
| | | if (row < 1) { |
| | | throw new ApiException("更新用户信息失败"); |
| | |
| | | |
| | | @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)); |
| | | EmployeeRecordReq req = new EmployeeRecordReq(); |
| | | req.setCompanyId(companyId); |
| | | List<EmployeeRecordVO> sysUsers = employeeRecordMapper.selectEmployeeRecordList(req); |
| | | int totalUser = sysUsers.size(); |
| | | |
| | | Map<String, Object> map = new HashMap<>(); |
| | |
| | | map.put("totalUser", totalUser); |
| | | //专业 |
| | | map.put("post", sysUsers.stream() |
| | | .map(SysUser::getPost) |
| | | .map(EmployeeRecordVO::getPost) |
| | | .filter(Objects::nonNull) |
| | | .distinct() |
| | | .collect(Collectors.joining(","))); |
| | |
| | | |
| | | long qualification1 = sysUsers.stream() |
| | | .filter(user -> user.getQualification() != null) |
| | | .filter(user -> user.getQualification().equals("1")) |
| | | .filter(user -> ("1").equals(user.getQualification().toString())) |
| | | .count(); |
| | | map.put("qualification1", qualification1);//学历1、高中及以下 |
| | | long qualification2 = sysUsers.stream() |
| | | .filter(user -> user.getQualification() != null) |
| | | .filter(user -> user.getQualification().equals("2")) |
| | | .filter(user -> ("2").equals(user.getQualification().toString())) |
| | | .count(); |
| | | map.put("qualification2", qualification2);//学历2、专科 |
| | | long qualification3 = sysUsers.stream() |
| | | .filter(user -> user.getQualification() != null) |
| | | .filter(user -> user.getQualification().equals("3")) |
| | | .filter(user -> ("3").equals(user.getQualification().toString())) |
| | | .count(); |
| | | map.put("qualification3", qualification3);//学历3本科 |
| | | long qualification4 = sysUsers.stream() |
| | | .filter(user -> user.getQualification() != null) |
| | | .filter(user -> user.getQualification().equals("4")) |
| | | .filter(user -> ("4").equals(user.getQualification().toString())) |
| | | .count(); |
| | | map.put("qualification4", qualification4);//学历4硕士 |
| | | |
| | | long qualification5 = sysUsers.stream() |
| | | .filter(user -> user.getQualification() != null) |
| | | .filter(user -> user.getQualification().equals("5")) |
| | | .filter(user -> ("5").equals(user.getQualification().toString())) |
| | | .count(); |
| | | map.put("qualification5", qualification5);//学历5博士及以上 |
| | | |
| | |
| | | map.put("qualificationBK", countBk); |
| | | double bachelorRatio = totalUser > 0 ? (double) countBk / totalUser * 100 : 0; |
| | | //本科占比 |
| | | map.put("qualificationBKRatio", String.format("%.2f%%", bachelorRatio)); |
| | | map.put("qualificationBKRatio", String.format("%.2f", bachelorRatio)); |
| | | |
| | | long countJS = sysUsers.stream() |
| | | .filter(user -> user.getPersonType() != null) |
| | |
| | | .count(); |
| | | map.put("personTypeJS", countJS); |
| | | double jsRatio = totalUser > 0 ? (double) countJS / totalUser * 100 : 0; |
| | | map.put("jsRatio", String.format("%.2f%%", jsRatio)); |
| | | map.put("jsRatio", String.format("%.2f", jsRatio)); |
| | | double averageAge = sysUsers.stream() |
| | | .filter(user -> user.getAge() != null) // 过滤年龄为null的用户 |
| | | .mapToInt(SysUser::getAge) // 提取年龄值 |
| | | .mapToInt(EmployeeRecordVO::getAge) // 提取年龄值 |
| | | .average() // 计算平均值 |
| | | .orElse(0.0); |
| | | map.put("avgAge", String.format("%.1f", averageAge));//平均年龄 |
| | |
| | | .count(); |
| | | map.put("age40", countAge40); |
| | | double age40Ratio = totalUser > 0 ? (double) countAge40 / totalUser * 100 : 0; |
| | | map.put("age40Ratio", String.format("%.2f%%", age40Ratio)); |
| | | 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)); |
| | | map.put("age1840Ratio", String.format("%.2f", age30Ratio)); |
| | | |
| | | return Collections.emptyMap(); |
| | | return map; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public boolean checkPhoneUnique(SysUser user) { |
| | | Long userId = user.getId() == null ? -1L : user.getId(); |