StaffManageServiceImpl.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package com.ruoyi.system.service.impl;
  2. import com.ruoyi.common.constant.UserConstants;
  3. import com.ruoyi.common.core.domain.AjaxResult;
  4. import com.ruoyi.common.core.domain.entity.SysRole;
  5. import com.ruoyi.common.core.domain.entity.SysUser;
  6. import com.ruoyi.common.utils.DateUtils;
  7. import com.ruoyi.common.core.domain.entity.StaffManage;
  8. import com.ruoyi.common.utils.SecurityUtils;
  9. import com.ruoyi.common.utils.StringUtils;
  10. import com.ruoyi.system.mapper.StaffManageMapper;
  11. import com.ruoyi.system.mapper.SysRoleMapper;
  12. import com.ruoyi.system.service.IStaffManageService;
  13. import com.ruoyi.system.service.ISysDictDataService;
  14. import com.ruoyi.system.service.ISysUserService;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.stereotype.Service;
  17. import java.util.List;
  18. /**
  19. * 员工管理Service业务层处理
  20. *
  21. * @author boman
  22. * @date 2025-02-18
  23. */
  24. @Service
  25. public class StaffManageServiceImpl implements IStaffManageService
  26. {
  27. @Autowired
  28. private StaffManageMapper staffManageMapper;
  29. @Autowired
  30. private SysRoleMapper roleMapper;
  31. @Autowired
  32. private ISysUserService userService;
  33. @Autowired
  34. private ISysDictDataService dictDataService;
  35. /**
  36. * 查询员工管理
  37. *
  38. * @param staffId 员工管理主键
  39. * @return 员工管理
  40. */
  41. @Override
  42. public StaffManage selectStaffManageByStaffId(Long staffId)
  43. {
  44. return staffManageMapper.selectStaffManageByStaffId(staffId);
  45. }
  46. /**
  47. * 查询员工管理列表
  48. *
  49. * @param staffManage 员工管理
  50. * @return 员工管理
  51. */
  52. @Override
  53. public List<StaffManage> selectStaffManageList(StaffManage staffManage)
  54. {
  55. return staffManageMapper.selectStaffManageList(staffManage);
  56. }
  57. /**
  58. * 新增员工管理
  59. *
  60. * @param staffManage 员工管理
  61. * @return 结果
  62. */
  63. @Override
  64. public AjaxResult insertStaffManage(StaffManage staffManage)
  65. {
  66. //新增账号信息
  67. SysUser user = new SysUser();
  68. user.setUserName(staffManage.getPhoneNumber());
  69. if (!userService.checkUserNameUnique(user))
  70. {
  71. return AjaxResult.error(user.getUserName() + "'失败,手机号已存在");
  72. }
  73. user.setPassword(SecurityUtils.encryptPassword(UserConstants.PASSWORD));
  74. user.setPhonenumber(staffManage.getPhoneNumber());
  75. user.setNickName(staffManage.getStaffName());
  76. //todo 部门 岗位
  77. user.setSex(staffManage.getGender());
  78. user.setStatus(UserConstants.DEPT_NORMAL);
  79. //查询角色id
  80. String roleKey = dictDataService.selectDictLabel(UserConstants.SYS_EMP_ROLE_TYPE, staffManage.getStaffCategory());
  81. SysRole info = roleMapper.checkRoleKeyUnique(roleKey);
  82. Long[] roleIds = {info.getRoleId()};
  83. user.setRoleIds(roleIds);
  84. userService.insertUser(user);
  85. staffManage.setUserId(user.getUserId());
  86. staffManage.setCreateTime(DateUtils.getNowDate());
  87. int i = staffManageMapper.insertStaffManage(staffManage);
  88. return i > 0 ? AjaxResult.success() : AjaxResult.error();
  89. }
  90. /**
  91. * 修改员工管理
  92. *
  93. * @param staffManage 员工管理
  94. * @return 结果
  95. */
  96. @Override
  97. public int updateStaffManage(StaffManage staffManage)
  98. {
  99. staffManage.setUpdateTime(DateUtils.getNowDate());
  100. return staffManageMapper.updateStaffManage(staffManage);
  101. }
  102. /**
  103. * 批量删除员工管理
  104. *
  105. * @param staffIds 需要删除的员工管理主键
  106. * @return 结果
  107. */
  108. @Override
  109. public int deleteStaffManageByStaffIds(Long[] staffIds)
  110. {
  111. return staffManageMapper.deleteStaffManageByStaffIds(staffIds);
  112. }
  113. /**
  114. * 删除员工管理信息
  115. *
  116. * @param staffId 员工管理主键
  117. * @return 结果
  118. */
  119. @Override
  120. public int deleteStaffManageByStaffId(Long staffId)
  121. {
  122. return staffManageMapper.deleteStaffManageByStaffId(staffId);
  123. }
  124. /**
  125. * 根据userId查询员工信息
  126. * @param userId
  127. * @return
  128. */
  129. @Override
  130. public StaffManage selectStaffManageByUserId(Long userId) {
  131. return staffManageMapper.selectStaffManageByUserId(userId);
  132. }
  133. }