| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- package jnpf.base.service.impl;
- import cn.hutool.core.util.ObjectUtil;
- import com.github.yulichang.toolkit.JoinWrappers;
- import com.github.yulichang.wrapper.MPJLambdaWrapper;
- import jnpf.base.entity.DataInterfaceEntity;
- import jnpf.base.service.SuperServiceImpl;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import jnpf.base.Pagination;
- import jnpf.base.entity.DataInterfaceLogEntity;
- import jnpf.base.mapper.DataInterfaceLogMapper;
- import jnpf.base.model.InterfaceOauth.PaginationIntrfaceLog;
- import jnpf.base.service.DataInterfaceLogService;
- import jnpf.util.*;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.Date;
- import java.util.List;
- /**
- * @author JNPF开发平台组
- * @version V3.1.0
- * @copyright 引迈信息技术有限公司(https://www.jnpfsoft.com)
- * @date 2021-06-03
- */
- @Service
- public class DataInterfaceLogServiceImpl extends SuperServiceImpl<DataInterfaceLogMapper, DataInterfaceLogEntity> implements DataInterfaceLogService {
- @Override
- public void create(String dateInterfaceId, Integer invokWasteTime) {
- DataInterfaceLogEntity entity = new DataInterfaceLogEntity();
- entity.setId(RandomUtil.uuId());
- entity.setInvokTime(DateUtil.getNowDate());
- entity.setUserId(UserProvider.getUser().getUserId());
- entity.setInvokId(dateInterfaceId);
- entity.setInvokIp(IpUtil.getIpAddr());
- entity.setInvokType("GET");
- entity.setInvokDevice(ServletUtil.getUserAgent());
- entity.setInvokWasteTime(invokWasteTime);
- this.save(entity);
- }
- @Override
- public void create(String dateInterfaceId, Integer invokWasteTime,String appId,String invokType) {
- DataInterfaceLogEntity entity = new DataInterfaceLogEntity();
- entity.setId(RandomUtil.uuId());
- entity.setInvokTime(DateUtil.getNowDate());
- entity.setUserId(UserProvider.getUser().getUserId());
- entity.setInvokId(dateInterfaceId);
- entity.setInvokIp(IpUtil.getIpAddr());
- entity.setInvokType(invokType);
- entity.setInvokDevice(ServletUtil.getUserAgent());
- entity.setInvokWasteTime(invokWasteTime);
- entity.setOauthAppId(appId);
- this.save(entity);
- }
- @Override
- public List<DataInterfaceLogEntity> getList(String invokId, Pagination pagination) {
- QueryWrapper<DataInterfaceLogEntity> queryWrapper = new QueryWrapper<>();
- queryWrapper.lambda().eq(DataInterfaceLogEntity::getInvokId, invokId).orderByDesc(DataInterfaceLogEntity::getInvokTime);
- if (StringUtil.isNotEmpty(pagination.getKeyword())){
- queryWrapper.lambda().and(
- t->t.like(DataInterfaceLogEntity::getUserId, pagination.getKeyword())
- .or().like(DataInterfaceLogEntity::getInvokIp, pagination.getKeyword())
- .or().like(DataInterfaceLogEntity::getInvokDevice, pagination.getKeyword())
- .or().like(DataInterfaceLogEntity::getInvokType, pagination.getKeyword())
- );
- }
- // 排序
- queryWrapper.lambda().orderByDesc(DataInterfaceLogEntity::getInvokTime);
- Page<DataInterfaceLogEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
- IPage<DataInterfaceLogEntity> iPage = this.page(page, queryWrapper);
- return pagination.setData(iPage.getRecords(), page.getTotal());
- }
- @Override
- public List<DataInterfaceLogEntity> getListByIds(String appId,List<String> invokIds, PaginationIntrfaceLog pagination) {
- MPJLambdaWrapper<DataInterfaceLogEntity> queryWrapper = JoinWrappers
- .lambda(DataInterfaceLogEntity.class)
- .leftJoin(DataInterfaceEntity.class,DataInterfaceEntity::getId,DataInterfaceLogEntity::getInvokId);
- queryWrapper.eq(DataInterfaceLogEntity::getOauthAppId,appId);
- queryWrapper.in(DataInterfaceLogEntity::getInvokId, invokIds);
- if (StringUtil.isNotEmpty(pagination.getKeyword())){
- queryWrapper.and(
- t->t.like(DataInterfaceEntity::getEnCode, pagination.getKeyword())
- .or().like(DataInterfaceEntity::getFullName, pagination.getKeyword())
- );
- }
- //日期范围(近7天、近1月、近3月、自定义)
- if (ObjectUtil.isNotEmpty(pagination.getStartTime()) && ObjectUtil.isNotEmpty(pagination.getEndTime())) {
- queryWrapper.between(DataInterfaceLogEntity::getInvokTime, new Date(pagination.getStartTime()), new Date(pagination.getEndTime()));
- }
- // 排序
- queryWrapper.orderByDesc(DataInterfaceLogEntity::getInvokTime);
- Page<DataInterfaceLogEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
- IPage<DataInterfaceLogEntity> iPage = this.selectJoinListPage(page, DataInterfaceLogEntity.class,queryWrapper);
- return pagination.setData(iPage.getRecords(), page.getTotal());
- }
- }
|