|
@@ -1,9 +1,35 @@
|
|
|
package com.citu.module.menduner.system.service.api;
|
|
|
|
|
|
+import com.citu.framework.common.pojo.PageResult;
|
|
|
+import com.citu.module.infra.api.logger.ApiAccessLogApi;
|
|
|
+import com.citu.module.infra.api.logger.dto.ApiAccessLogPageReqDTO;
|
|
|
+import com.citu.module.infra.api.logger.dto.ApiAccessLogRespDTO;
|
|
|
+import com.citu.module.menduner.system.api.user.MendunerUserApi;
|
|
|
+import com.citu.module.menduner.system.api.user.UserInfoRespDTO;
|
|
|
+import com.citu.module.menduner.system.controller.base.api.MdeApiAccessLogInfoSaveVo;
|
|
|
+import com.citu.module.menduner.system.controller.base.api.MdeApiAccessLogPageReqVO;
|
|
|
+import com.citu.module.menduner.system.controller.base.api.MdeApiAccessLogRespVO;
|
|
|
+import com.citu.module.menduner.system.dal.dataobject.api.MdeApiAccessLogInfoDO;
|
|
|
+import com.citu.module.menduner.system.dal.dataobject.enterprise.EnterpriseUserBindDO;
|
|
|
import com.citu.module.menduner.system.dal.mysql.api.MdeApiAccessLogInfoMapper;
|
|
|
+import com.citu.module.menduner.system.service.enterprise.bind.EnterpriseUserBindService;
|
|
|
+import com.citu.module.system.api.dict.DictDataApi;
|
|
|
+import com.citu.module.system.api.dict.dto.DictDataRespDTO;
|
|
|
+import com.citu.module.system.api.user.AdminUserApi;
|
|
|
+import com.citu.module.system.api.user.dto.AdminUserRespDTO;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
@Service
|
|
|
public class MdeApiAccessLogInfoServiceImpl implements MdeApiAccessLogInfoService{
|
|
|
|
|
@@ -11,4 +37,107 @@ public class MdeApiAccessLogInfoServiceImpl implements MdeApiAccessLogInfoServi
|
|
|
MdeApiAccessLogInfoMapper mdeApiAccessLogInfoMapper;
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
+ ApiAccessLogApi apiAccessLogApi;
|
|
|
+
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ MendunerUserApi mendunerUserApi;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ AdminUserApi adminUserApi;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ DictDataApi dictDataApi;
|
|
|
+
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ EnterpriseUserBindService enterpriseUserBindService;
|
|
|
+
|
|
|
+ @Async
|
|
|
+ @Override
|
|
|
+ public void apiAccessLogInfoSave(MdeApiAccessLogInfoSaveVo apiAccessLogInfoSaveVo) {
|
|
|
+ MdeApiAccessLogInfoDO mdeApiAccessLogInfo = new MdeApiAccessLogInfoDO();
|
|
|
+ BeanUtils.copyProperties(apiAccessLogInfoSaveVo,mdeApiAccessLogInfo);
|
|
|
+ mdeApiAccessLogInfoMapper.insert(mdeApiAccessLogInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageResult<MdeApiAccessLogRespVO> getApiAccessLogPage(MdeApiAccessLogPageReqVO pageReqVO) {
|
|
|
+ ApiAccessLogPageReqDTO reqDTO =new ApiAccessLogPageReqDTO();
|
|
|
+ BeanUtils.copyProperties(pageReqVO, reqDTO);
|
|
|
+ PageResult<ApiAccessLogRespDTO> apiAccessLogPage = apiAccessLogApi.getApiAccessLogPage(reqDTO);
|
|
|
+ List<String> requestIds = apiAccessLogPage.getList().stream().filter(item -> StringUtils.isBlank(item.getRequestId())).map(ApiAccessLogRespDTO::getRequestId).collect(Collectors.toList());
|
|
|
+ List<MdeApiAccessLogInfoDO> mdeApiAccessLogInfoDOS = mdeApiAccessLogInfoMapper.selectRequestIds(requestIds);
|
|
|
+ Map<String, MdeApiAccessLogInfoDO> collect = mdeApiAccessLogInfoDOS.stream().collect(Collectors.toMap(item -> item.getRequestId(), item -> item));
|
|
|
+ List<MdeApiAccessLogRespVO> res =new ArrayList<>(apiAccessLogPage.getList().size()+1);
|
|
|
+ List<DictDataRespDTO> datas = dictDataApi.getDictDataList("user_type").getData();
|
|
|
+ Map<String, Map<Long,String>> userTypeMap =new HashMap<>();
|
|
|
+ for (DictDataRespDTO data : datas) {
|
|
|
+ userTypeMap.put(data.getValue(), new HashMap<>());
|
|
|
+ }
|
|
|
+ for (ApiAccessLogRespDTO apiAccessLogRespDTO : apiAccessLogPage.getList()) {
|
|
|
+ userTypeMap.putIfAbsent(apiAccessLogRespDTO.getUserType().toString(),new HashMap<>());
|
|
|
+ MdeApiAccessLogRespVO mdeApiAccessLogRespVO = new MdeApiAccessLogRespVO();
|
|
|
+ BeanUtils.copyProperties(apiAccessLogRespDTO,mdeApiAccessLogRespVO);
|
|
|
+ if(collect.containsKey(apiAccessLogRespDTO.getRequestId())){
|
|
|
+ MdeApiAccessLogInfoDO mdeApiAccessLogInfoDO = collect.get(apiAccessLogRespDTO.getRequestId());
|
|
|
+ BeanUtils.copyProperties(mdeApiAccessLogInfoDO,mdeApiAccessLogRespVO);
|
|
|
+ }
|
|
|
+ if(null == mdeApiAccessLogRespVO.getEnterpriseId()){
|
|
|
+ userTypeMap.get(apiAccessLogRespDTO.getUserType().toString()).put(null==apiAccessLogRespDTO.getUserId()?-1L:apiAccessLogRespDTO.getUserId(),"");
|
|
|
+ }else{
|
|
|
+ // 企业用户
|
|
|
+ userTypeMap.get("1-"+mdeApiAccessLogRespVO.getEnterpriseId()).put(null==apiAccessLogRespDTO.getUserId()?-1L:apiAccessLogRespDTO.getUserId(),"");
|
|
|
+ }
|
|
|
+ res.add(mdeApiAccessLogRespVO);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ userTypeMap.forEach((key, value) -> {
|
|
|
+ value.remove(-1L);
|
|
|
+ value.remove(0L);
|
|
|
+ if(value.keySet().isEmpty()){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 企业用户
|
|
|
+ if(key.startsWith("1-") ){
|
|
|
+ Long enterpriseId = Long.valueOf(key.split("-")[1]);
|
|
|
+ value.keySet().forEach(userId -> {
|
|
|
+ EnterpriseUserBindDO enterpriseUserBind = enterpriseUserBindService.selectByEnterpriseIdAndUserId(enterpriseId,userId);
|
|
|
+ value.put(userId,enterpriseUserBind.getName());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 会员用户
|
|
|
+ if(key.equals("1") ){
|
|
|
+ // 需要考虑 企业用户情况
|
|
|
+ List<UserInfoRespDTO> data = mendunerUserApi.getUserList(value.keySet()).getData();
|
|
|
+ for (UserInfoRespDTO datum : data) {
|
|
|
+ value.put(datum.getUserId(),datum.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 管理员用户
|
|
|
+ if(key.equals("2")){
|
|
|
+ List<AdminUserRespDTO> data = adminUserApi.getUserList(value.keySet()).getData();
|
|
|
+ for (AdminUserRespDTO datum : data) {
|
|
|
+ value.put(datum.getId(),datum.getNickname());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ res.forEach(item->{
|
|
|
+ if(null!=item.getEnterpriseId()){
|
|
|
+ item.setUserNickName(userTypeMap.get("1-"+item.getEnterpriseId()).get(item.getUserId()));
|
|
|
+ }else {
|
|
|
+ item.setUserNickName(userTypeMap.get(item.getUserType().toString()).get(item.getUserId()));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ PageResult<MdeApiAccessLogRespVO> resApiAccessLogPage = new PageResult<>();
|
|
|
+ resApiAccessLogPage.setList(res);
|
|
|
+ resApiAccessLogPage.setTotal(apiAccessLogPage.getTotal());
|
|
|
+ return resApiAccessLogPage;
|
|
|
+ }
|
|
|
}
|