MgeAuditRptController.java 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. package com.dragoninfo.dcuc.authweb.restcontroller.audit;
  2. import com.dragoninfo.dcuc.authweb.restcontroller.audit.vo.MgeLogVo;
  3. import com.dragoninfo.dcuc.org.facade.IOrgInfoFacade;
  4. import com.dragoninfo.dcuc.user.admin.entity.MgeLog;
  5. import com.dragoninfo.dcuc.user.admin.enumresources.AdminObjectTypeEnum;
  6. import com.dragoninfo.dcuc.user.admin.facade.IMenuMtAuthFacade;
  7. import com.dragoninfo.dcuc.user.admin.facade.IMgeLogFacade;
  8. import com.dragoninfo.dcuc.user.user.vo.UserMgeLogRptVo;
  9. import com.dragoninfo.duceap.core.response.Result;
  10. import com.dragonsoft.duceap.base.entity.search.SearchDTO;
  11. import com.dragonsoft.duceap.commons.util.collections.CollectionUtils;
  12. import com.dragonsoft.duceap.commons.util.json.JsonUtils;
  13. import com.dragonsoft.duceap.commons.util.string.StringUtils;
  14. import com.dragonsoft.duceap.core.search.Searchable;
  15. import io.swagger.annotations.Api;
  16. import io.swagger.annotations.ApiImplicitParam;
  17. import io.swagger.annotations.ApiImplicitParams;
  18. import io.swagger.annotations.ApiOperation;
  19. import org.springframework.beans.BeanUtils;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.data.domain.Page;
  22. import org.springframework.data.domain.Sort;
  23. import org.springframework.web.bind.annotation.*;
  24. import java.util.*;
  25. @Api(tags = {"管理员审计报表"})
  26. @RestController
  27. @RequestMapping(value = "/auditsvr/manage/")
  28. public class MgeAuditRptController {
  29. @Autowired
  30. private IMgeLogFacade iMgeLogFacade;
  31. @Autowired
  32. private IOrgInfoFacade iOrgInfoFacade;
  33. @Autowired
  34. private IMenuMtAuthFacade iMenuMtAuthFacade;
  35. @ApiOperation(value = "查询管理员审计报表")
  36. @ApiImplicitParam(name = "SearchDTO", value = "查询条件")
  37. @PostMapping(value = "audits")
  38. public Result<List<UserMgeLogRptVo>> getMgeAuditRpt(SearchDTO searchDTO) {
  39. searchDTO.setSort("");
  40. Searchable searchable = Searchable.toSearchable(searchDTO);
  41. searchable.addSort(Sort.Direction.DESC, "operate_time");
  42. Page<com.dragoninfo.dcuc.user.user.vo.UserMgeLogRptVo> userMgeLogSummary = iMgeLogFacade.findUserMgeLogSummary(searchDTO);
  43. List<UserMgeLogRptVo> vos = new ArrayList<>();
  44. for (com.dragoninfo.dcuc.user.user.vo.UserMgeLogRptVo userMgeLogRptVo : userMgeLogSummary) {
  45. UserMgeLogRptVo vo = new UserMgeLogRptVo();
  46. BeanUtils.copyProperties(userMgeLogRptVo, vo);
  47. vos.add(vo);
  48. }
  49. Result result = Result.success(userMgeLogSummary.getTotalElements(), vos);
  50. return result;
  51. }
  52. @ApiOperation(value = "查询管理员审计详情")
  53. @ApiImplicitParams({@ApiImplicitParam(paramType = "path", name = "id", value = "审计详情ID", required = true
  54. , example = "40288a8b699fc2500169a33b20540000")})
  55. @GetMapping(value = "/detail/{id}")
  56. public Result<MgeLogVo> orgAuditDetail(@PathVariable("id") String id) {
  57. MgeLog mgeLog = iMgeLogFacade.getMgeLog(id);
  58. List<MgeLog> mgeLogList = new ArrayList<MgeLog>();
  59. mgeLogList.add(mgeLog);
  60. formatMgeLog(mgeLogList, "rpt");
  61. MgeLogVo mgeLogVo = new MgeLogVo();
  62. BeanUtils.copyProperties(mgeLog, mgeLogVo);
  63. return Result.success(mgeLogVo);
  64. }
  65. /**
  66. * 获取授权范围日志
  67. * -1:子节点未展开或无子节点,0:未勾选子节点,1:勾选部分子节点,2:勾选全部子节点
  68. * <p>
  69. * 操作业务类型 10:新增管理员 11:取消管理员
  70. * 20:新增平台菜单权限 21:取消平台菜单权限
  71. * 30:新增管理机构权限 31:取消管理机构权限
  72. * 40:新增管理人员权限 41:取消管理人员权限
  73. *
  74. * @param type 日志类型 10:管理员 20:平台菜单 30:机构管理 40:人员管理 50:授权管理 60:管理员管理
  75. * @param userId 用户ID
  76. * @return 授权范围日志
  77. */
  78. @ApiOperation(value = "获取授权范围日志")
  79. @ApiImplicitParams({
  80. @ApiImplicitParam(name = "type", value = "日志类型 10:管理员 20:平台菜单 30:机构管理 40:人员管理 50:授权管理 60:管理员管理"),
  81. @ApiImplicitParam(name = "userId", value = "用户ID"),
  82. })
  83. @GetMapping(value = "auditList/{type}/{userId}")
  84. public Result<List<MgeLogVo>> auditList(@PathVariable("type") String type, @PathVariable("userId") String userId) {
  85. List<MgeLog> mgeLogList = iMgeLogFacade.queryList(type, userId);
  86. mgeLogList = formatMgeLog(mgeLogList, "list");
  87. List<MgeLogVo> vos = new ArrayList<>();
  88. for (MgeLog mgeLog : mgeLogList) {
  89. MgeLogVo vo = new MgeLogVo();
  90. BeanUtils.copyProperties(mgeLog, vo);
  91. vos.add(vo);
  92. }
  93. return Result.success(vos);
  94. }
  95. /**
  96. * 格式化审计Log
  97. *
  98. * @param mgeLogList
  99. * @return
  100. */
  101. private List<MgeLog> formatMgeLog(List<MgeLog> mgeLogList, String listOrRpt) {
  102. for (MgeLog mgeLog : mgeLogList) {
  103. String type = mgeLog.getObjectType();//操作对象类型
  104. String ids = mgeLog.getObjectId();
  105. ids = StringUtils.isEmpty(ids) ? "" : ids;
  106. if (!AdminObjectTypeEnum.GLY.getValue().equals(type) && !AdminObjectTypeEnum.PTCD.getValue().equals(type)) {
  107. if (AdminObjectTypeEnum.JGGL.getValue().equals(type) || AdminObjectTypeEnum.RYGL.getValue().equals(type) || AdminObjectTypeEnum.SQGL.getValue().equals(type) || AdminObjectTypeEnum.GLYGL.getValue().equals(type)) {
  108. ids = iOrgInfoFacade.changeIdsToNames(ids);
  109. if(StringUtils.isNotBlank(ids)) {
  110. ids = ids.replace(":-1", "(及其下属机构)").replace(":0", "").replace(":1", "").replace(":2", "(及其下属机构)");
  111. }
  112. mgeLog.setObjectName(ids);
  113. }
  114. } else if (type.equals(AdminObjectTypeEnum.PTCD.getValue())) {
  115. Map<String, MgeLog> resultMap = new TreeMap<String, MgeLog>(new Comparator<String>() {
  116. @Override
  117. public int compare(String o1, String o2) {
  118. return o2.compareTo(o1);
  119. }
  120. });
  121. List<MgeLog> mgeLogListTemp = new ArrayList<MgeLog>();
  122. mgeLogListTemp.add(mgeLog);
  123. String s = JsonUtils.toJSONString(mgeLogListTemp);
  124. Map<Object, Object> mgeLogMap = new HashMap<>();
  125. mgeLogMap.put("mgeLogMap", s);
  126. mgeLogListTemp = iMenuMtAuthFacade.convertIdsToNames(mgeLogMap);
  127. if (listOrRpt.equals("list")) {
  128. mgeLog = mgeLogListTemp.get(0);
  129. String key = mgeLog.getOperateTime().toString() + mgeLog.getOperateUserId();
  130. if (resultMap.containsKey(key)) {
  131. MgeLog mge = resultMap.get(key);
  132. String objectName = mge.getObjectName() + "," + mgeLog.getObjectName();
  133. mge.setObjectName(objectName);
  134. resultMap.put(key, mge);
  135. } else {
  136. resultMap.put(key, mgeLog);
  137. }
  138. mgeLogListTemp.clear();
  139. for (Map.Entry<String, MgeLog> entry : resultMap.entrySet()) {
  140. mgeLogListTemp.add(entry.getValue());
  141. }
  142. mgeLog = mgeLogListTemp.get(0);
  143. } else {
  144. if (CollectionUtils.isNotEmpty(mgeLogListTemp)) {
  145. mgeLog.setObjectName(mgeLogListTemp.get(0).getObjectName());
  146. }
  147. }
  148. }
  149. if (StringUtils.isNotEmpty(mgeLog.getOperateOrgId())) {
  150. String operateOrgName = iOrgInfoFacade.changeIdsToNames(mgeLog.getOperateOrgId().trim());
  151. mgeLog.setOperateOrgName(operateOrgName);
  152. }
  153. }
  154. return mgeLogList;
  155. }
  156. }