DataInterfaceLogServiceImpl.java 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package jnpf.base.service.impl;
  2. import cn.hutool.core.util.ObjectUtil;
  3. import com.github.yulichang.toolkit.JoinWrappers;
  4. import com.github.yulichang.wrapper.MPJLambdaWrapper;
  5. import jnpf.base.entity.DataInterfaceEntity;
  6. import jnpf.base.service.SuperServiceImpl;
  7. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  8. import com.baomidou.mybatisplus.core.metadata.IPage;
  9. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  10. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  11. import jnpf.base.Pagination;
  12. import jnpf.base.entity.DataInterfaceLogEntity;
  13. import jnpf.base.mapper.DataInterfaceLogMapper;
  14. import jnpf.base.model.InterfaceOauth.PaginationIntrfaceLog;
  15. import jnpf.base.service.DataInterfaceLogService;
  16. import jnpf.util.*;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.stereotype.Service;
  19. import java.util.Date;
  20. import java.util.List;
  21. /**
  22. * @author JNPF开发平台组
  23. * @version V3.1.0
  24. * @copyright 引迈信息技术有限公司(https://www.jnpfsoft.com)
  25. * @date 2021-06-03
  26. */
  27. @Service
  28. public class DataInterfaceLogServiceImpl extends SuperServiceImpl<DataInterfaceLogMapper, DataInterfaceLogEntity> implements DataInterfaceLogService {
  29. @Override
  30. public void create(String dateInterfaceId, Integer invokWasteTime) {
  31. DataInterfaceLogEntity entity = new DataInterfaceLogEntity();
  32. entity.setId(RandomUtil.uuId());
  33. entity.setInvokTime(DateUtil.getNowDate());
  34. entity.setUserId(UserProvider.getUser().getUserId());
  35. entity.setInvokId(dateInterfaceId);
  36. entity.setInvokIp(IpUtil.getIpAddr());
  37. entity.setInvokType("GET");
  38. entity.setInvokDevice(ServletUtil.getUserAgent());
  39. entity.setInvokWasteTime(invokWasteTime);
  40. this.save(entity);
  41. }
  42. @Override
  43. public void create(String dateInterfaceId, Integer invokWasteTime,String appId,String invokType) {
  44. DataInterfaceLogEntity entity = new DataInterfaceLogEntity();
  45. entity.setId(RandomUtil.uuId());
  46. entity.setInvokTime(DateUtil.getNowDate());
  47. entity.setUserId(UserProvider.getUser().getUserId());
  48. entity.setInvokId(dateInterfaceId);
  49. entity.setInvokIp(IpUtil.getIpAddr());
  50. entity.setInvokType(invokType);
  51. entity.setInvokDevice(ServletUtil.getUserAgent());
  52. entity.setInvokWasteTime(invokWasteTime);
  53. entity.setOauthAppId(appId);
  54. this.save(entity);
  55. }
  56. @Override
  57. public List<DataInterfaceLogEntity> getList(String invokId, Pagination pagination) {
  58. QueryWrapper<DataInterfaceLogEntity> queryWrapper = new QueryWrapper<>();
  59. queryWrapper.lambda().eq(DataInterfaceLogEntity::getInvokId, invokId).orderByDesc(DataInterfaceLogEntity::getInvokTime);
  60. if (StringUtil.isNotEmpty(pagination.getKeyword())){
  61. queryWrapper.lambda().and(
  62. t->t.like(DataInterfaceLogEntity::getUserId, pagination.getKeyword())
  63. .or().like(DataInterfaceLogEntity::getInvokIp, pagination.getKeyword())
  64. .or().like(DataInterfaceLogEntity::getInvokDevice, pagination.getKeyword())
  65. .or().like(DataInterfaceLogEntity::getInvokType, pagination.getKeyword())
  66. );
  67. }
  68. // 排序
  69. queryWrapper.lambda().orderByDesc(DataInterfaceLogEntity::getInvokTime);
  70. Page<DataInterfaceLogEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
  71. IPage<DataInterfaceLogEntity> iPage = this.page(page, queryWrapper);
  72. return pagination.setData(iPage.getRecords(), page.getTotal());
  73. }
  74. @Override
  75. public List<DataInterfaceLogEntity> getListByIds(String appId,List<String> invokIds, PaginationIntrfaceLog pagination) {
  76. MPJLambdaWrapper<DataInterfaceLogEntity> queryWrapper = JoinWrappers
  77. .lambda(DataInterfaceLogEntity.class)
  78. .leftJoin(DataInterfaceEntity.class,DataInterfaceEntity::getId,DataInterfaceLogEntity::getInvokId);
  79. queryWrapper.eq(DataInterfaceLogEntity::getOauthAppId,appId);
  80. queryWrapper.in(DataInterfaceLogEntity::getInvokId, invokIds);
  81. if (StringUtil.isNotEmpty(pagination.getKeyword())){
  82. queryWrapper.and(
  83. t->t.like(DataInterfaceEntity::getEnCode, pagination.getKeyword())
  84. .or().like(DataInterfaceEntity::getFullName, pagination.getKeyword())
  85. );
  86. }
  87. //日期范围(近7天、近1月、近3月、自定义)
  88. if (ObjectUtil.isNotEmpty(pagination.getStartTime()) && ObjectUtil.isNotEmpty(pagination.getEndTime())) {
  89. queryWrapper.between(DataInterfaceLogEntity::getInvokTime, new Date(pagination.getStartTime()), new Date(pagination.getEndTime()));
  90. }
  91. // 排序
  92. queryWrapper.orderByDesc(DataInterfaceLogEntity::getInvokTime);
  93. Page<DataInterfaceLogEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
  94. IPage<DataInterfaceLogEntity> iPage = this.selectJoinListPage(page, DataInterfaceLogEntity.class,queryWrapper);
  95. return pagination.setData(iPage.getRecords(), page.getTotal());
  96. }
  97. }