OwnSysUserController.java 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package com.tianhu.system.controller;
  2. import com.tianhu.common.core.constant.SalaryConstants;
  3. import com.tianhu.common.core.utils.CommonUtil;
  4. import com.tianhu.common.core.utils.StringUtils;
  5. import com.tianhu.common.core.utils.poi.ExcelUtil;
  6. import com.tianhu.common.core.web.controller.BaseController;
  7. import com.tianhu.common.core.web.domain.AjaxResult;
  8. import com.tianhu.common.core.web.page.TableDataInfo;
  9. import com.tianhu.common.log.annotation.Log;
  10. import com.tianhu.common.log.enums.BusinessType;
  11. import com.tianhu.common.security.annotation.PreAuthorize;
  12. import com.tianhu.common.security.service.TokenService;
  13. import com.tianhu.system.api.domain.SysUser;
  14. import com.tianhu.system.api.model.LoginUser;
  15. import com.tianhu.system.domain.OwnSysUser;
  16. import com.tianhu.system.service.*;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.web.bind.annotation.*;
  19. import javax.servlet.http.HttpServletResponse;
  20. import java.io.IOException;
  21. import java.util.HashMap;
  22. import java.util.List;
  23. import java.util.Map;
  24. /**
  25. * 用户信息
  26. *
  27. * @author tianhu
  28. */
  29. @RestController
  30. @RequestMapping("/ownUser")
  31. public class OwnSysUserController extends BaseController
  32. {
  33. @Autowired
  34. private IOwnSysUserService ownSysUserService;
  35. @Autowired
  36. private ISysUserService iSysUserService;
  37. @Autowired
  38. private TokenService tokenService;
  39. /**
  40. * 获取用户列表
  41. */
  42. @PreAuthorize(hasPermi = "system:ownUser:list")
  43. @GetMapping("/list")
  44. public TableDataInfo list(OwnSysUser ownSysUser)
  45. {
  46. startPage();
  47. //获取用户信息
  48. LoginUser userInfo = tokenService.getLoginUser();
  49. SysUser users = userInfo.getSysUser();
  50. String companyId = users.getCompanyId();
  51. if(ownSysUser.getParams() != null ){
  52. ownSysUser.setBeginTime(CommonUtil.objToString(ownSysUser.getParams().get("beginTime")));
  53. ownSysUser.setEndTime(CommonUtil.objToString(ownSysUser.getParams().get("endTime")));
  54. }
  55. //判断是否为运维管理员 000000:代表运维管理员
  56. if(!SalaryConstants.OPEX.equals(companyId)){
  57. ownSysUser.setCompanyId(companyId);
  58. }else{
  59. //未选择其他一级部门则只显示自己企业人员
  60. if(ownSysUser.getDeptId() == null){
  61. ownSysUser.setCompanyId(companyId);
  62. }
  63. }
  64. List<OwnSysUser> list = ownSysUserService.selectUserList(ownSysUser);
  65. return getDataTable(list);
  66. }
  67. /**
  68. * 导出用户列表
  69. */
  70. @PreAuthorize(hasPermi = "system:ownUser:export")
  71. @Log(title = "用户", businessType = BusinessType.EXPORT)
  72. @PostMapping("/export")
  73. public void export(HttpServletResponse response,
  74. @RequestParam(required=false) String deptId,
  75. @RequestParam(required=false) String userName,
  76. @RequestParam(required=false) String nickName,
  77. @RequestParam(required=false) String phonenumber,
  78. @RequestParam(required=false) String status,
  79. @RequestParam (required = false) Map dateRange) throws IOException
  80. {
  81. OwnSysUser ownSysUser = new OwnSysUser();
  82. if(!CommonUtil.isEmpty(userName)){
  83. ownSysUser.setUserName(userName);
  84. }
  85. if(!CommonUtil.isEmpty(nickName)){
  86. ownSysUser.setNickName(nickName);
  87. }
  88. if(!CommonUtil.isEmpty(status)){
  89. ownSysUser.setStatus(status);
  90. }
  91. if(!CommonUtil.isEmpty(deptId)){
  92. ownSysUser.setDeptId(Long.valueOf(deptId));
  93. }
  94. ownSysUser.setBeginTime(CommonUtil.objToString(dateRange.get("0")));
  95. ownSysUser.setEndTime(CommonUtil.objToString(dateRange.get("1")));
  96. //获取用户信息
  97. LoginUser userInfo = tokenService.getLoginUser();
  98. SysUser users = userInfo.getSysUser();
  99. String companyId = users.getCompanyId();
  100. //判断是否为运维管理员 000000:代表运维管理员
  101. if(!SalaryConstants.OPEX.equals(companyId)){
  102. ownSysUser.setCompanyId(companyId);
  103. }
  104. List<OwnSysUser> list = ownSysUserService.selectUserList(ownSysUser);
  105. ExcelUtil<OwnSysUser> util = new ExcelUtil<OwnSysUser>(OwnSysUser.class);
  106. util.exportExcel(response, list, "inf");
  107. }
  108. @GetMapping("/listUser/{userId}")
  109. public AjaxResult listUser(@PathVariable(value = "userId", required = false) Long userId){
  110. //查询当前操作员
  111. LoginUser userInfo = tokenService.getLoginUser();
  112. SysUser use = userInfo.getSysUser();
  113. SysUser user =null;
  114. if("000000".equals(userId)){
  115. user = iSysUserService.selectUserById(userId);
  116. }
  117. //获取企业
  118. String ssCompanyId = use.getCompanyId();
  119. Map map = new HashMap();
  120. if(!SalaryConstants.OPEX.equals(ssCompanyId)) {
  121. map.put("ssCompanyId",ssCompanyId);
  122. }
  123. if(StringUtils.isNotNull(user)){
  124. map.put("staffId",user.getStaffCode());
  125. }
  126. List<Map> list = ownSysUserService.selectUser(map);
  127. return AjaxResult.success(list);
  128. }
  129. }