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 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 list = dynamicQuery.nativeQueryPagingList(InterfaceLogEntity.class,pageable, nativeSql.toString(), params); data = new PageBean(list, totalCount); } return Result.ok(data); } }