package com.dragoninfo.dcuc.authweb.restcontroller.audit; import com.dragoninfo.dcuc.authweb.restcontroller.audit.vo.MgeLogVo; import com.dragoninfo.dcuc.org.facade.IOrgInfoFacade; import com.dragoninfo.dcuc.user.admin.entity.MgeLog; import com.dragoninfo.dcuc.user.admin.enumresources.AdminObjectTypeEnum; import com.dragoninfo.dcuc.user.admin.facade.IMenuMtAuthFacade; import com.dragoninfo.dcuc.user.admin.facade.IMgeLogFacade; import com.dragoninfo.dcuc.user.user.vo.UserMgeLogRptVo; import com.dragoninfo.duceap.core.response.Result; import com.dragonsoft.duceap.base.entity.search.SearchDTO; import com.dragonsoft.duceap.commons.util.collections.CollectionUtils; import com.dragonsoft.duceap.commons.util.json.JsonUtils; import com.dragonsoft.duceap.commons.util.string.StringUtils; import com.dragonsoft.duceap.core.search.Searchable; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Sort; import org.springframework.web.bind.annotation.*; import java.util.*; @Api(tags = {"管理员审计报表"}) @RestController @RequestMapping(value = "/auditsvr/manage/") public class MgeAuditRptController { @Autowired private IMgeLogFacade iMgeLogFacade; @Autowired private IOrgInfoFacade iOrgInfoFacade; @Autowired private IMenuMtAuthFacade iMenuMtAuthFacade; @ApiOperation(value = "查询管理员审计报表") @ApiImplicitParam(name = "SearchDTO", value = "查询条件") @PostMapping(value = "audits") public Result> getMgeAuditRpt(SearchDTO searchDTO) { searchDTO.setSort(""); Searchable searchable = Searchable.toSearchable(searchDTO); searchable.addSort(Sort.Direction.DESC, "operate_time"); Page userMgeLogSummary = iMgeLogFacade.findUserMgeLogSummary(searchDTO); List vos = new ArrayList<>(); for (com.dragoninfo.dcuc.user.user.vo.UserMgeLogRptVo userMgeLogRptVo : userMgeLogSummary) { UserMgeLogRptVo vo = new UserMgeLogRptVo(); BeanUtils.copyProperties(userMgeLogRptVo, vo); vos.add(vo); } Result result = Result.success(userMgeLogSummary.getTotalElements(), vos); return result; } @ApiOperation(value = "查询管理员审计详情") @ApiImplicitParams({@ApiImplicitParam(paramType = "path", name = "id", value = "审计详情ID", required = true , example = "40288a8b699fc2500169a33b20540000")}) @GetMapping(value = "/detail/{id}") public Result orgAuditDetail(@PathVariable("id") String id) { MgeLog mgeLog = iMgeLogFacade.getMgeLog(id); List mgeLogList = new ArrayList(); mgeLogList.add(mgeLog); formatMgeLog(mgeLogList, "rpt"); MgeLogVo mgeLogVo = new MgeLogVo(); BeanUtils.copyProperties(mgeLog, mgeLogVo); return Result.success(mgeLogVo); } /** * 获取授权范围日志 * -1:子节点未展开或无子节点,0:未勾选子节点,1:勾选部分子节点,2:勾选全部子节点 *

* 操作业务类型 10:新增管理员 11:取消管理员 * 20:新增平台菜单权限 21:取消平台菜单权限 * 30:新增管理机构权限 31:取消管理机构权限 * 40:新增管理人员权限 41:取消管理人员权限 * * @param type 日志类型 10:管理员 20:平台菜单 30:机构管理 40:人员管理 50:授权管理 60:管理员管理 * @param userId 用户ID * @return 授权范围日志 */ @ApiOperation(value = "获取授权范围日志") @ApiImplicitParams({ @ApiImplicitParam(name = "type", value = "日志类型 10:管理员 20:平台菜单 30:机构管理 40:人员管理 50:授权管理 60:管理员管理"), @ApiImplicitParam(name = "userId", value = "用户ID"), }) @GetMapping(value = "auditList/{type}/{userId}") public Result> auditList(@PathVariable("type") String type, @PathVariable("userId") String userId) { List mgeLogList = iMgeLogFacade.queryList(type, userId); mgeLogList = formatMgeLog(mgeLogList, "list"); List vos = new ArrayList<>(); for (MgeLog mgeLog : mgeLogList) { MgeLogVo vo = new MgeLogVo(); BeanUtils.copyProperties(mgeLog, vo); vos.add(vo); } return Result.success(vos); } /** * 格式化审计Log * * @param mgeLogList * @return */ private List formatMgeLog(List mgeLogList, String listOrRpt) { for (MgeLog mgeLog : mgeLogList) { String type = mgeLog.getObjectType();//操作对象类型 String ids = mgeLog.getObjectId(); ids = StringUtils.isEmpty(ids) ? "" : ids; if (!AdminObjectTypeEnum.GLY.getValue().equals(type) && !AdminObjectTypeEnum.PTCD.getValue().equals(type)) { if (AdminObjectTypeEnum.JGGL.getValue().equals(type) || AdminObjectTypeEnum.RYGL.getValue().equals(type) || AdminObjectTypeEnum.SQGL.getValue().equals(type) || AdminObjectTypeEnum.GLYGL.getValue().equals(type)) { ids = iOrgInfoFacade.changeIdsToNames(ids); if(StringUtils.isNotBlank(ids)) { ids = ids.replace(":-1", "(及其下属机构)").replace(":0", "").replace(":1", "").replace(":2", "(及其下属机构)"); } mgeLog.setObjectName(ids); } } else if (type.equals(AdminObjectTypeEnum.PTCD.getValue())) { Map resultMap = new TreeMap(new Comparator() { @Override public int compare(String o1, String o2) { return o2.compareTo(o1); } }); List mgeLogListTemp = new ArrayList(); mgeLogListTemp.add(mgeLog); String s = JsonUtils.toJSONString(mgeLogListTemp); Map mgeLogMap = new HashMap<>(); mgeLogMap.put("mgeLogMap", s); mgeLogListTemp = iMenuMtAuthFacade.convertIdsToNames(mgeLogMap); if (listOrRpt.equals("list")) { mgeLog = mgeLogListTemp.get(0); String key = mgeLog.getOperateTime().toString() + mgeLog.getOperateUserId(); if (resultMap.containsKey(key)) { MgeLog mge = resultMap.get(key); String objectName = mge.getObjectName() + "," + mgeLog.getObjectName(); mge.setObjectName(objectName); resultMap.put(key, mge); } else { resultMap.put(key, mgeLog); } mgeLogListTemp.clear(); for (Map.Entry entry : resultMap.entrySet()) { mgeLogListTemp.add(entry.getValue()); } mgeLog = mgeLogListTemp.get(0); } else { if (CollectionUtils.isNotEmpty(mgeLogListTemp)) { mgeLog.setObjectName(mgeLogListTemp.get(0).getObjectName()); } } } if (StringUtils.isNotEmpty(mgeLog.getOperateOrgId())) { String operateOrgName = iOrgInfoFacade.changeIdsToNames(mgeLog.getOperateOrgId().trim()); mgeLog.setOperateOrgName(operateOrgName); } } return mgeLogList; } }