| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.basic.PageInfo; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.domain.entity.SysDept; |
| | | import com.ruoyi.common.core.domain.entity.SysRole; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.utils.CodeGenerateUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.dto.SysUserUpdateStatusDTO; |
| | | import com.ruoyi.system.model.*; |
| | | import com.ruoyi.system.query.SysUserQuery; |
| | | import com.ruoyi.system.service.*; |
| | | import com.ruoyi.system.vo.SysUserVO; |
| | |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.time.LocalDateTime; |
| | |
| | | */ |
| | | @Api(tags = "用户信息") |
| | | @RestController |
| | | @RequestMapping("/system/user") |
| | | @RequestMapping("") |
| | | public class SysUserController extends BaseController |
| | | { |
| | | @Autowired |
| | |
| | | private ISysDeptService deptService; |
| | | @Autowired |
| | | private TokenService tokenService; |
| | | |
| | | @Autowired |
| | | private TProjectTeamService projectTeamService; |
| | | @Autowired |
| | | private TProjectTeamStaffService projectTeamStaffService; |
| | | @Autowired |
| | | private TClinicalTrialPointsService clinicalTrialPointsService; |
| | | @Autowired |
| | | private TExperimentDispatchParticipantsService experimentDispatchParticipantsService; |
| | | @Autowired |
| | | private TExperimentSchemePersonService experimentSchemePersonService; |
| | | @Autowired |
| | | private TNoticeService noticeService; |
| | | @Autowired |
| | | private TProjectProposalService projectProposalService; |
| | | @Autowired |
| | | private TQaProduceReportService qaProduceReportService; |
| | | @Autowired |
| | | private TQaTestItemService qaTestItemService; |
| | | @Autowired |
| | | private TResultWorkEvaluateService resultWorkEvaluateService; |
| | | @Autowired |
| | | private TSamplingRecordOperationService samplingRecordOperationService; |
| | | @Autowired |
| | | private TTestMethodConfirmSheetService testMethodConfirmSheetService; |
| | | @Autowired |
| | | private TTesterOtherTaskService testerOtherTaskService; |
| | | /** |
| | | * 获取用户列表 |
| | | */ |
| | | @ApiOperation(value = "获取用户列表") |
| | | @PostMapping("/list") |
| | | @PreAuthorize("@ss.hasPermi('system:user')") |
| | | @PostMapping("/system/user/list") |
| | | // @PreAuthorize("@ss.hasPermi('system:user')") |
| | | public AjaxResult list(@RequestBody SysUserQuery query) |
| | | { |
| | | PageInfo<SysUserVO> list = userService.pageList(query); |
| | |
| | | } |
| | | |
| | | @ApiOperation(value = "获取用户列表-不分页") |
| | | @PostMapping("/listNotPage") |
| | | @PreAuthorize("@ss.hasPermi('system:user')") |
| | | |
| | | @PostMapping("/system/user/listNotPage") |
| | | // @PreAuthorize("@ss.hasPermi('system:user')") |
| | | public AjaxResult listNotPage() |
| | | { |
| | | List<SysUser> list = userService.selectList(); |
| | | return AjaxResult.success(list); |
| | | } |
| | | |
| | | @ApiOperation(value = "获取用户列表-不分页-根据角色筛选") |
| | | @GetMapping("/system/user/listByRole") |
| | | public AjaxResult listByRole(@RequestParam(value = "roleId",required = false) Long roleId, |
| | | @RequestParam(value = "nickName",required = false) String nickName) |
| | | { |
| | | // 获取当前用户项目组 |
| | | Long userId = tokenService.getLoginUser().getUserId(); |
| | | List<TProjectTeamStaff> staffs = projectTeamStaffService.list(Wrappers.lambdaQuery(TProjectTeamStaff.class) |
| | | .eq(TProjectTeamStaff::getUserId, userId)); |
| | | if (CollectionUtils.isEmpty(staffs)){ |
| | | return AjaxResult.success(new ArrayList<>()); |
| | | } |
| | | List<String> teamIds = staffs.stream().map(TProjectTeamStaff::getTeamId).collect(Collectors.toList()); |
| | | LambdaQueryWrapper<TProjectTeamStaff> wrapper = new LambdaQueryWrapper<>(); |
| | | if(Objects.nonNull(roleId)){ |
| | | wrapper.eq(TProjectTeamStaff::getRoleType,Integer.parseInt(roleId.toString())); |
| | | } |
| | | wrapper.in(TProjectTeamStaff::getTeamId, teamIds); |
| | | List<TProjectTeamStaff> teamStaffs = projectTeamStaffService.list(wrapper); |
| | | List<Long> userIds = teamStaffs.stream().map(TProjectTeamStaff::getUserId).collect(Collectors.toList()); |
| | | |
| | | List<SysUser> list = userService.listByRole(userIds,nickName); |
| | | return AjaxResult.success(list); |
| | | } |
| | | |
| | |
| | | * 获取用户详情 |
| | | */ |
| | | @ApiOperation(value = "获取用户详情") |
| | | @GetMapping("/getDetail") |
| | | @GetMapping("/system/user/getDetail") |
| | | public AjaxResult getDetail(@RequestParam Long userId) |
| | | { |
| | | SysUser sysUser = userService.selectUserById(userId); |
| | |
| | | * 获取用户详情 |
| | | */ |
| | | @ApiOperation(value = "获取用户详情") |
| | | @GetMapping("/queryDetail") |
| | | @GetMapping("/system/user/queryDetail") |
| | | public AjaxResult queryDetail() |
| | | { |
| | | Long userId = tokenService.getLoginUser().getUserId(); |
| | |
| | | * 获取用户数量统计 |
| | | */ |
| | | @ApiOperation(value = "获取用户数量统计") |
| | | @PostMapping("/getUserCount") |
| | | @PostMapping("/system/user/getUserCount") |
| | | public AjaxResult getUserCount() |
| | | { |
| | | Map<String,Integer> map = new HashMap<>(); |
| | |
| | | /** |
| | | * 移除黑名单 |
| | | */ |
| | | @GetMapping("/removeBlackList") |
| | | @GetMapping("/system/user/removeBlackList") |
| | | public AjaxResult removeBlackList(@RequestParam String ids) |
| | | { |
| | | String[] split = ids.split(","); |
| | |
| | | * 新增用户 |
| | | */ |
| | | // @PreAuthorize("@ss.hasPermi('system:user:add')") |
| | | @ApiOperation(value = "新增用户管理") |
| | | @ApiOperation(value = "新增用户管理",response = SysUser.class) |
| | | @Log(title = "用户信息-新增用户", businessType = BusinessType.INSERT) |
| | | @PostMapping("/add") |
| | | public AjaxResult add(@Validated @RequestBody SysUser user) |
| | | @PostMapping("/api/system/user/add") |
| | | public R<String> add(@RequestBody String param) |
| | | { |
| | | SysUser user = JSON.parseObject(param,SysUser.class); |
| | | user.setUserName(user.getUserName()); |
| | | if (!userService.checkUserNameUnique(user)) |
| | | { |
| | | return error("新增用户'" + user.getUserName() + "'失败,登录账号已存在"); |
| | | return R.fail("新增用户'" + user.getUserName() + "'失败,登录账号已存在"); |
| | | } |
| | | else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) |
| | | { |
| | | return error("新增用户'" + user.getUserName() + "'失败,手机号码已存在"); |
| | | return R.fail("新增用户'" + user.getUserName() + "'失败,手机号码已存在"); |
| | | } |
| | | user.setCreateBy(getUsername()); |
| | | user.setPassword(SecurityUtils.encryptPassword("123456")); |
| | | user.setRoleType(Integer.parseInt(user.getRoleId().toString())); |
| | | user.setUserIdentification(CodeGenerateUtils.generateVolumeSn()); |
| | | userService.insertUser(user); |
| | | return AjaxResult.success(); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 账号继承 |
| | | */ |
| | | // @PreAuthorize("@ss.hasPermi('system:user:add')") |
| | | @ApiOperation(value = "账号继承,userId:继承账号id,oldUserId:老账号id",response = SysUser.class) |
| | | @Log(title = "用户信息-账号继承", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/open/system/user/inherit") |
| | | public R<String> inherit(@RequestParam Long userId, |
| | | @RequestParam Long oldUserId) |
| | | { |
| | | // 查询老帐号 |
| | | SysUser oldUser = userService.selectUserById(oldUserId); |
| | | if (Objects.isNull(oldUser)){ |
| | | return R.fail("原始账号不存在"); |
| | | } |
| | | if ("0".equals(oldUser.getStatus())){ |
| | | return R.fail("原始账号未停用,无法继承"); |
| | | } |
| | | SysUser user = userService.selectUserById(userId); |
| | | if (Objects.isNull(user)){ |
| | | return R.fail("继承账号不存在"); |
| | | } |
| | | if(!oldUser.getRoleType().equals(user.getRoleType())){ |
| | | return R.fail("原始账号和继承账号角色不一致"); |
| | | } |
| | | |
| | | Integer roleType = oldUser.getRoleType(); |
| | | Long oldUserUserId = oldUser.getUserId(); |
| | | switch (roleType){ |
| | | case 3: |
| | | // 工艺工程师 |
| | | // 临床试验积分 |
| | | clinicalTrialPointsService.update(Wrappers.lambdaUpdate(TClinicalTrialPoints.class) |
| | | .eq(TClinicalTrialPoints::getProcessEngineerId,oldUserUserId) |
| | | .set(TClinicalTrialPoints::getProcessEngineerId,userId)); |
| | | // QA检测项 |
| | | qaTestItemService.update(Wrappers.lambdaUpdate(TQaTestItem.class) |
| | | .eq(TQaTestItem::getCommitPersonId,oldUserUserId) |
| | | .set(TQaTestItem::getCommitPersonId,userId)); |
| | | break; |
| | | case 4: |
| | | // 化验师 |
| | | // 中试、生产验证分析报告;辅料;产品报告 |
| | | qaProduceReportService.update(Wrappers.lambdaUpdate(TQaProduceReport.class) |
| | | .eq(TQaProduceReport::getCommitPersonId,oldUserUserId) |
| | | .set(TQaProduceReport::getCommitPersonId,userId)); |
| | | break; |
| | | case 5: |
| | | // 实验员 |
| | | // 实验方案实验人员管理 |
| | | experimentSchemePersonService.update(Wrappers.lambdaUpdate(TExperimentSchemePerson.class) |
| | | .eq(TExperimentSchemePerson::getUserId,oldUserUserId) |
| | | .set(TExperimentSchemePerson::getUserId,userId)); |
| | | // 实验员其他任务 |
| | | testerOtherTaskService.update(Wrappers.lambdaUpdate(TTesterOtherTask.class) |
| | | .eq(TTesterOtherTask::getTesterId,oldUserUserId) |
| | | .set(TTesterOtherTask::getTesterId,userId)); |
| | | break; |
| | | } |
| | | // 实验调度参与人员 |
| | | experimentDispatchParticipantsService.update(Wrappers.lambdaUpdate(TExperimentDispatchParticipants.class) |
| | | .eq(TExperimentDispatchParticipants::getUserId,oldUserUserId) |
| | | .set(TExperimentDispatchParticipants::getUserId,userId)); |
| | | // 公告 |
| | | noticeService.update(Wrappers.lambdaUpdate(TNotice.class) |
| | | .eq(TNotice::getUserId,oldUserUserId) |
| | | .set(TNotice::getUserId,userId)); |
| | | // 项目课题 |
| | | projectProposalService.update(Wrappers.lambdaUpdate(TProjectProposal.class) |
| | | .eq(TProjectProposal::getCommitUserId,oldUserUserId) |
| | | .set(TProjectProposal::getCommitUserId,userId)); |
| | | // 项目组 |
| | | projectTeamStaffService.update(Wrappers.lambdaUpdate(TProjectTeamStaff.class) |
| | | .eq(TProjectTeamStaff::getUserId,oldUserUserId) |
| | | .set(TProjectTeamStaff::getUserId,userId)); |
| | | // 实验结果汇报 |
| | | resultWorkEvaluateService.update(Wrappers.lambdaUpdate(TResultWorkEvaluate.class) |
| | | .eq(TResultWorkEvaluate::getUserId,oldUserUserId) |
| | | .set(TResultWorkEvaluate::getUserId,userId)); |
| | | // 取样操作管理 |
| | | samplingRecordOperationService.update(Wrappers.lambdaUpdate(TSamplingRecordOperation.class) |
| | | .eq(TSamplingRecordOperation::getHandlePersonId,oldUserUserId) |
| | | .set(TSamplingRecordOperation::getHandlePersonId,userId)); |
| | | samplingRecordOperationService.update(Wrappers.lambdaUpdate(TSamplingRecordOperation.class) |
| | | .eq(TSamplingRecordOperation::getSendPersonId,oldUserUserId) |
| | | .set(TSamplingRecordOperation::getSendPersonId,userId)); |
| | | samplingRecordOperationService.update(Wrappers.lambdaUpdate(TSamplingRecordOperation.class) |
| | | .eq(TSamplingRecordOperation::getReceiptsPersonId,oldUserUserId) |
| | | .set(TSamplingRecordOperation::getReceiptsPersonId,userId)); |
| | | // 检验方法确认单 |
| | | testMethodConfirmSheetService.update(Wrappers.lambdaUpdate(TTestMethodConfirmSheet.class) |
| | | .eq(TTestMethodConfirmSheet::getCommitUserId,oldUserUserId) |
| | | .set(TTestMethodConfirmSheet::getCommitUserId,userId)); |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | |
| | | // @PreAuthorize("@ss.hasPermi('system:user:edit')") |
| | | @ApiOperation(value = "修改用户管理") |
| | | @Log(title = "用户信息-修改用户", businessType = BusinessType.UPDATE) |
| | | @PostMapping("/edit") |
| | | public AjaxResult edit(@Validated @RequestBody SysUser user) |
| | | @PostMapping("/api/system/user/edit") |
| | | public R edit(@RequestBody String param) |
| | | { |
| | | SysUser user = JSON.parseObject(param,SysUser.class); |
| | | user.setUserName(user.getPhonenumber()); |
| | | // userService.checkUserAllowed(user); |
| | | // userService.checkUserDataScope(user.getUserId()); |
| | | if (!userService.checkUserNameUnique(user)) |
| | | { |
| | | return error("修改用户'" + user.getUserName() + "'失败,登录账号已存在"); |
| | | return R.fail("修改用户'" + user.getUserName() + "'失败,登录账号已存在"); |
| | | } |
| | | else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) |
| | | { |
| | | return error("修改用户'" + user.getUserName() + "'失败,手机号码已存在"); |
| | | return R.fail("修改用户'" + user.getUserName() + "'失败,手机号码已存在"); |
| | | } |
| | | |
| | | user.setUpdateBy(getUsername()); |
| | | if(StringUtils.isNotEmpty(user.getPassword())){ |
| | | user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); |
| | | } |
| | | return AjaxResult.success(userService.updateUser(user)); |
| | | user.setRoleType(Integer.parseInt(user.getRoleId().toString())); |
| | | return R.ok(userService.updateUser(user)); |
| | | } |
| | | |
| | | /** |
| | | * 修改用户签名 |
| | | */ |
| | | // @PreAuthorize("@ss.hasPermi('system:user:edit')") |
| | | @ApiOperation(value = "修改用户签名") |
| | | @Log(title = "用户信息-修改用户签名", businessType = BusinessType.UPDATE) |
| | | @PostMapping("/api/system/user/editSignPicture") |
| | | public R editSignPicture(@RequestBody String param) |
| | | { |
| | | Long userId = tokenService.getLoginUser().getUserId(); |
| | | SysUser user = JSON.parseObject(param,SysUser.class); |
| | | user.setUserId(userId); |
| | | return R.ok(userService.editSignPicture(user)); |
| | | } |
| | | |
| | | /** |
| | |
| | | // @PreAuthorize("@ss.hasPermi('system:user:remove')") |
| | | @ApiOperation(value = "批量删除用户") |
| | | @Log(title = "用户信息-批量删除用户", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/deleteById/{ids}") |
| | | @DeleteMapping("/system/user/deleteById/{ids}") |
| | | public AjaxResult remove(@PathVariable String ids) |
| | | { |
| | | String[] split = ids.split(","); |
| | |
| | | // @PreAuthorize("@ss.hasPermi('system:user:resetPwd')") |
| | | @ApiOperation(value = "重置密码") |
| | | @Log(title = "用户信息-重置密码", businessType = BusinessType.UPDATE) |
| | | @PostMapping("/resetPwd") |
| | | public AjaxResult resetPwd(@RequestBody SysUser user) |
| | | @PostMapping("/api/system/user/resetPwd") |
| | | public AjaxResult resetPwd(@RequestBody String param) |
| | | { |
| | | SysUser user = JSON.parseObject(param,SysUser.class); |
| | | userService.checkUserAllowed(user); |
| | | // userService.checkUserDataScope(user.getUserId()); |
| | | user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); |
| | |
| | | */ |
| | | @ApiOperation(value = "状态修改") |
| | | @Log(title = "用户信息-状态修改", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/changeStatus") |
| | | @PutMapping("/system/user/changeStatus") |
| | | public AjaxResult changeStatus(@RequestBody SysUserUpdateStatusDTO dto) |
| | | { |
| | | SysUser loginUser = tokenService.getLoginUser().getUser(); |
| | |
| | | * 根据用户编号获取授权角色 |
| | | */ |
| | | // @PreAuthorize("@ss.hasPermi('system:user:query')") |
| | | @GetMapping("/authRole/{userId}") |
| | | @GetMapping("/system/user/authRole/{userId}") |
| | | public AjaxResult authRole(@PathVariable("userId") Long userId) |
| | | { |
| | | AjaxResult ajax = AjaxResult.success(); |
| | |
| | | */ |
| | | // @PreAuthorize("@ss.hasPermi('system:user:edit')") |
| | | @Log(title = "用户管理", businessType = BusinessType.GRANT) |
| | | @PutMapping("/authRole") |
| | | @PutMapping("/system/user/authRole") |
| | | public AjaxResult insertAuthRole(Long userId, Long[] roleIds) |
| | | { |
| | | userService.checkUserDataScope(userId); |
| | |
| | | * 获取部门树列表 |
| | | */ |
| | | // @PreAuthorize("@ss.hasPermi('system:user:list')") |
| | | @GetMapping("/deptTree") |
| | | @GetMapping("/system/user/deptTree") |
| | | public AjaxResult deptTree(SysDept dept) |
| | | { |
| | | return AjaxResult.success(deptService.selectDeptTreeList(dept)); |