87d335e7aa25f467e42915792e2ea16964531a21.svn-base 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. package cn.com.goldenwater.dcproj.controller.base;
  2. import cn.com.goldenwater.dcproj.dto.PersGroupDto;
  3. import cn.com.goldenwater.dcproj.model.AttUserBase;
  4. import cn.com.goldenwater.dcproj.param.AttUserBaseParam;
  5. import cn.com.goldenwater.dcproj.param.UserRoleParam;
  6. import cn.com.goldenwater.dcproj.service.AttUserBaseService;
  7. import cn.com.goldenwater.core.web.BaseController;
  8. import cn.com.goldenwater.core.web.BaseResponse;
  9. import cn.com.goldenwater.dcproj.utils.MD5;
  10. import com.github.pagehelper.PageInfo;
  11. import io.swagger.annotations.Api;
  12. import io.swagger.annotations.ApiOperation;
  13. import io.swagger.annotations.ApiParam;
  14. import org.apache.commons.lang3.StringUtils;
  15. import org.slf4j.Logger;
  16. import org.slf4j.LoggerFactory;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.util.Assert;
  19. import org.springframework.web.bind.annotation.PathVariable;
  20. import org.springframework.web.bind.annotation.RequestBody;
  21. import org.springframework.web.bind.annotation.RequestMapping;
  22. import org.springframework.web.bind.annotation.RequestMethod;
  23. import org.springframework.web.bind.annotation.RequestParam;
  24. import org.springframework.web.bind.annotation.RestController;
  25. import java.util.ArrayList;
  26. import java.util.Date;
  27. import java.util.List;
  28. import java.util.UUID;
  29. /**
  30. * @author lune
  31. * @date 2019-2-18
  32. */
  33. @Api(value = "用户管理",tags="007用户管理(新)")
  34. @RestController
  35. @RequestMapping("/dc/user")
  36. public class AttUserBaseController extends BaseController {
  37. private Logger logger = LoggerFactory.getLogger(getClass());
  38. @Autowired
  39. private AttUserBaseService attUserBaseService;
  40. @ApiOperation(value = "添加")
  41. @RequestMapping(value = "/insertUser", method = RequestMethod.POST)
  42. public BaseResponse<String> insert(@ApiParam(name = "attUserBase", value = "AttUserBase", required = true) @RequestBody AttUserBase attUserBase) {
  43. String uuid = UUID.randomUUID().toString().replaceAll("-",""); // 生成uuid
  44. attUserBase.setGuid(uuid);
  45. attUserBase.setUserGuid(uuid);
  46. attUserBase.setFromDate(new Date());
  47. if (StringUtils.isNotBlank(attUserBase.getPassword())){
  48. attUserBase.setPassword(MD5.getMD5(attUserBase.getPassword()));
  49. }
  50. ArrayList<UserRoleParam> userRoleParams = new ArrayList<>();
  51. if (null != attUserBase.getRoleIds() && attUserBase.getRoleIds().size() > 0){
  52. for (String roleId : attUserBase.getRoleIds()) {
  53. UserRoleParam userRoleParam = new UserRoleParam();
  54. userRoleParam.setUserId(attUserBase.getGuid());
  55. userRoleParam.setRoleId(roleId);
  56. userRoleParams.add(userRoleParam);
  57. }
  58. }
  59. UserRoleParam param = new UserRoleParam();
  60. param.setUserId(attUserBase.getGuid());
  61. attUserBaseService.insertUser(attUserBase, userRoleParams, param);
  62. return buildSuccessResponse(uuid);
  63. }
  64. @ApiOperation(value = "修改用户(关联角色)")
  65. @RequestMapping(value = "updateUser", method = RequestMethod.POST)
  66. public BaseResponse<String> updateUser(@ApiParam(name = "attUserBase", value = "AttUserBase", required = true) @RequestBody AttUserBase attUserBase) {
  67. Assert.notNull(attUserBase, "用户对象不能为空");
  68. attUserBase.setPassword(null);
  69. ArrayList<UserRoleParam> userRoleParams = new ArrayList<>();
  70. if (null != attUserBase.getRoleIds() && attUserBase.getRoleIds().size() > 0){
  71. for (String roleId : attUserBase.getRoleIds()) {
  72. UserRoleParam userRoleParam = new UserRoleParam();
  73. userRoleParam.setUserId(attUserBase.getGuid());
  74. userRoleParam.setRoleId(roleId);
  75. userRoleParams.add(userRoleParam);
  76. }
  77. }
  78. UserRoleParam param = new UserRoleParam();
  79. param.setUserId(attUserBase.getGuid());
  80. attUserBaseService.updateUser(attUserBase, userRoleParams, param);
  81. return buildSuccessResponse();
  82. }
  83. @ApiOperation(value = "根据ID删除")
  84. @RequestMapping(value = "/{guid}", method = RequestMethod.POST)
  85. public BaseResponse delete(@ApiParam(name = "guid", value = "guid", required = true) @PathVariable String guid) {
  86. int ret = attUserBaseService.delete(guid);
  87. return buildSuccessResponse();
  88. }
  89. @ApiOperation(value = "更新信息")
  90. @RequestMapping(value = "/update", method = RequestMethod.POST)
  91. public BaseResponse update(@ApiParam(name = "attUserBase", value = "AttUserBase", required = true) @RequestBody AttUserBase attUserBase) {
  92. Assert.notNull(attUserBase.getGuid(), "主键guid为必填参数");
  93. int ret = attUserBaseService.update(attUserBase);
  94. return buildSuccessResponse();
  95. }
  96. @ApiOperation(value = "根据ID获取")
  97. @RequestMapping(value = "/{guid}", method = RequestMethod.GET)
  98. public BaseResponse<AttUserBase> get(@ApiParam(name = "guid", value = "guid", required = true) @PathVariable String guid) {
  99. AttUserBase attUserBase = attUserBaseService.get(guid);
  100. return buildSuccessResponse(attUserBase);
  101. }
  102. @ApiOperation(value = "分页获取用户列表-包含分页信息")
  103. @RequestMapping(value = "/pageInfo", method = RequestMethod.GET)
  104. public BaseResponse<PageInfo<AttUserBase>> getMenuPageInfo(@ApiParam(name = "attUserBaseParam", value = "attUserBaseParam", required = false) AttUserBaseParam attUserBaseParam) {
  105. PageInfo<AttUserBase> page = attUserBaseService.findPageInfo(attUserBaseParam);
  106. return buildSuccessResponse(page);
  107. }
  108. /**
  109. *
  110. * @param persid 用户ID
  111. * @param ptype 督查类型
  112. * @param groupName 督查组名称
  113. * @param plnaId 督查计划节点Id
  114. * @param tabType 页签 0全部 1当前 2历史
  115. * @return
  116. */
  117. @ApiOperation(value = "获取用户所在组")
  118. @RequestMapping(value = "/getGroupByPersid", method = RequestMethod.GET)
  119. public BaseResponse<List<PersGroupDto>> getGroupByPersid(@ApiParam(name = "persid", value = "persid", required = true) @RequestParam String persid,
  120. @ApiParam(name = "ptype", value = "ptype", required = false) @RequestParam String ptype,
  121. @ApiParam(name = "groupName", value = "groupName", required = false) @RequestParam(required = false) String groupName,
  122. @ApiParam(name = "plnaId", value = "plnaId", required = false) @RequestParam(required = false) String plnaId,
  123. @ApiParam(name = "tabType", value = "tabType", required = false) @RequestParam(required = false,defaultValue = "0") String tabType) {
  124. List<PersGroupDto> persGroupDtoList = attUserBaseService.getGroupByPersid(persid,ptype,groupName,getCurrentOrgId(),tabType,plnaId);
  125. return buildSuccessResponse(persGroupDtoList);
  126. }
  127. @ApiOperation(value = "获取所有最后一级分组")
  128. @RequestMapping(value = "/getGroupByPersidNew", method = RequestMethod.GET)
  129. public BaseResponse<List<PersGroupDto>> getGroupByPersidNew(@ApiParam(name = "persid", value = "persid", required = true) @RequestParam String persid,
  130. @ApiParam(name = "ptype", value = "ptype", required = false) @RequestParam String ptype,
  131. @ApiParam(name = "groupName", value = "groupName", required = false) @RequestParam(required = false) String groupName) {
  132. List<PersGroupDto> persGroupDtoList = attUserBaseService.getGroupByPersidNew(persid,ptype,groupName,getCurrentOrgId());
  133. return buildSuccessResponse(persGroupDtoList);
  134. }
  135. }