倪影Alone
2024-09-03 507d193d16bc32a7cacfd2bf2c19e1db24390414
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.itstyle.log.service.impl;
 
import com.itstyle.log.entity.InterfaceLogEntity;
import com.itstyle.log.service.InterfaceLogService;
import com.itstyle.quartz.dynamicquery.DynamicQuery;
import com.itstyle.quartz.entity.PageBean;
import com.itstyle.quartz.entity.QuartzEntity;
import com.itstyle.quartz.entity.Result;
import com.itstyle.quartz.entity.SysConfigEntity;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.List;
 
@Service("interfaceLogService")
public class InterfaceLogServiceImpl implements InterfaceLogService {
 
    @Autowired
    private DynamicQuery dynamicQuery;
 
    @Override
    public Result list(InterfaceLogEntity interfaceLog, Integer pageNo, Integer pageSize) throws SchedulerException {
        String countSql = "SELECT COUNT(*) FROM interface_log AS sys ";
        if(!StringUtils.isEmpty(interfaceLog.getInterfaceName())){
            countSql+=" WHERE sys.interfaceName = "+interfaceLog.getInterfaceName();
        }
        Long totalCount = dynamicQuery.nativeQueryCount(countSql);
        PageBean<QuartzEntity> data = new PageBean<>();
        if(totalCount>0){
            StringBuffer nativeSql = new StringBuffer();
            nativeSql.append("SELECT sys.uuid,sys.interfaceName,sys.url,sys.createTime,sys.prams,sys.result ");
            nativeSql.append("FROM interface_log AS sys ");
            Object[] params = new  Object[]{};
            if(!StringUtils.isEmpty(interfaceLog.getInterfaceName())){
                nativeSql.append(" AND sys.interfaceName = ?");
                params = new Object[]{interfaceLog.getInterfaceName()};
            }
            Pageable pageable = PageRequest.of(pageNo-1,pageSize);
            List<InterfaceLogEntity> list = dynamicQuery.nativeQueryPagingList(InterfaceLogEntity.class,pageable, nativeSql.toString(), params);
            data = new PageBean(list, totalCount);
        }
        return Result.ok(data);
    }
}