mirror of
https://github.com/liuweijw/fw-cloud-framework.git
synced 2026-03-13 08:50:21 +08:00
增加日志模块接口、优化分页列表
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package com.github.liuweijw.business.admin.controller;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.github.liuweijw.business.admin.domain.LogInfo;
|
||||
import com.github.liuweijw.business.admin.service.LogInfoService;
|
||||
import com.github.liuweijw.business.commons.beans.PageBean;
|
||||
import com.github.liuweijw.business.commons.beans.PageParams;
|
||||
import com.github.liuweijw.business.commons.permission.Functional;
|
||||
import com.github.liuweijw.business.commons.permission.Module;
|
||||
import com.github.liuweijw.business.commons.web.BaseController;
|
||||
import com.github.liuweijw.business.commons.web.aop.PrePermissions;
|
||||
import com.github.liuweijw.core.utils.R;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/logs")
|
||||
@PrePermissions(value = Module.LOG)
|
||||
public class LogController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private LogInfoService logInfoService;
|
||||
|
||||
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
||||
@PrePermissions(value = Functional.VIEW)
|
||||
public R<PageBean<LogInfo>> list(HttpServletRequest request, LogInfo logInfo,
|
||||
PageParams pageParams) {
|
||||
PageBean<LogInfo> pageData = this.logInfoService.findAll(pageParams, logInfo);
|
||||
return new R<PageBean<LogInfo>>().data(pageData);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/del/{id}", method = RequestMethod.POST)
|
||||
@PrePermissions(value = Functional.DEL)
|
||||
public R<Boolean> del(HttpServletRequest request, @PathVariable Long id) {
|
||||
if (null == id || id.intValue() <= 0) return new R<Boolean>().failure("日志id为空");
|
||||
boolean isDel = this.logInfoService.delById(id);
|
||||
return new R<Boolean>().data(isDel);
|
||||
}
|
||||
}
|
||||
@@ -100,6 +100,11 @@ public class LogInfo implements Serializable {
|
||||
@Column(name = "update_time")
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* id = 18 丢失精度适配
|
||||
*/
|
||||
private transient String idView;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -220,4 +225,13 @@ public class LogInfo implements Serializable {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
public String getIdView() {
|
||||
if (null == idView) idView = id + "";
|
||||
return idView;
|
||||
}
|
||||
|
||||
public void setIdView(String idView) {
|
||||
this.idView = idView;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.github.liuweijw.business.admin.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
|
||||
|
||||
import com.github.liuweijw.business.admin.domain.LogInfo;
|
||||
|
||||
public interface LogInfoRepository extends JpaRepository<LogInfo, Integer> {
|
||||
public interface LogInfoRepository extends JpaRepository<LogInfo, Long>,
|
||||
QueryDslPredicateExecutor<LogInfo> {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,20 @@
|
||||
package com.github.liuweijw.business.admin.service;
|
||||
|
||||
import com.github.liuweijw.business.admin.domain.LogInfo;
|
||||
import com.github.liuweijw.business.commons.beans.PageBean;
|
||||
import com.github.liuweijw.business.commons.beans.PageParams;
|
||||
|
||||
public interface LogInfoService {
|
||||
|
||||
public void saveOrUpdate(LogInfo logInfo);
|
||||
|
||||
/**
|
||||
* 日志列表数据
|
||||
*/
|
||||
PageBean<LogInfo> findAll(PageParams pageParams, LogInfo logInfo);
|
||||
|
||||
/**
|
||||
* 日志删除
|
||||
*/
|
||||
boolean delById(Long id);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.github.liuweijw.business.admin.repository.DictRepository;
|
||||
import com.github.liuweijw.business.admin.service.DictService;
|
||||
import com.github.liuweijw.business.commons.beans.PageBean;
|
||||
import com.github.liuweijw.business.commons.beans.PageParams;
|
||||
import com.github.liuweijw.business.commons.beans.PageUtil;
|
||||
import com.github.liuweijw.business.commons.web.jpa.JPAFactoryImpl;
|
||||
import com.github.liuweijw.core.utils.StringHelper;
|
||||
import com.querydsl.core.types.Predicate;
|
||||
@@ -48,17 +49,9 @@ public class DictServiceImpl extends JPAFactoryImpl implements DictService {
|
||||
Predicate predicate = qDict.id.goe(0).and(qTypePredicate).and(qLabelPredicate);
|
||||
|
||||
Sort sort = new Sort(new Sort.Order(Sort.Direction.DESC, "id"));
|
||||
PageRequest pageRequest = new PageRequest(pageParams.getCurrentPage(), pageParams
|
||||
.getPageSize(), sort);
|
||||
PageRequest pageRequest = PageUtil.of(pageParams, sort);
|
||||
Page<Dict> pageList = dictRepository.findAll(predicate, pageRequest);
|
||||
|
||||
PageBean<Dict> pageData = new PageBean<Dict>();
|
||||
pageData.setCurrentPage(pageParams.getCurrentPage());
|
||||
pageData.setPageSize(pageParams.getPageSize());
|
||||
pageData.setTotal(pageList.getTotalElements());
|
||||
pageData.setList(pageList.getContent());
|
||||
|
||||
return pageData;
|
||||
return PageUtil.of(pageList);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,11 +1,21 @@
|
||||
package com.github.liuweijw.business.admin.service.impl;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.github.liuweijw.business.admin.domain.LogInfo;
|
||||
import com.github.liuweijw.business.admin.domain.QLogInfo;
|
||||
import com.github.liuweijw.business.admin.repository.LogInfoRepository;
|
||||
import com.github.liuweijw.business.admin.service.LogInfoService;
|
||||
import com.github.liuweijw.business.commons.beans.PageBean;
|
||||
import com.github.liuweijw.business.commons.beans.PageParams;
|
||||
import com.github.liuweijw.business.commons.beans.PageUtil;
|
||||
import com.github.liuweijw.core.utils.StringHelper;
|
||||
import com.querydsl.core.types.Predicate;
|
||||
|
||||
@Component
|
||||
public class LogInfoServiceImpl implements LogInfoService {
|
||||
@@ -14,6 +24,7 @@ public class LogInfoServiceImpl implements LogInfoService {
|
||||
private LogInfoRepository logInfoRepository;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void saveOrUpdate(LogInfo logInfo) {
|
||||
|
||||
if (null == logInfo) return;
|
||||
@@ -22,4 +33,34 @@ public class LogInfoServiceImpl implements LogInfoService {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageBean<LogInfo> findAll(PageParams pageParams, LogInfo logInfo) {
|
||||
QLogInfo qLogInfo = QLogInfo.logInfo;
|
||||
// 用户名查询条件
|
||||
Predicate qServiceIdPredicate = null;
|
||||
if (null != logInfo) {
|
||||
if (StringHelper.isNotBlank(logInfo.getServiceId())) {
|
||||
qServiceIdPredicate = qLogInfo.serviceId.like("%" + logInfo.getServiceId().trim()
|
||||
+ "%");
|
||||
}
|
||||
}
|
||||
|
||||
Predicate predicate = qLogInfo.statu.eq(0).and(qServiceIdPredicate);
|
||||
|
||||
Sort sort = new Sort(new Sort.Order(Sort.Direction.DESC, "id"));
|
||||
PageRequest pageRequest = PageUtil.of(pageParams, sort);
|
||||
Page<LogInfo> pageList = logInfoRepository.findAll(predicate, pageRequest);
|
||||
return PageUtil.of(pageList);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean delById(Long id) {
|
||||
if (null == id || id <= 0) return Boolean.FALSE;
|
||||
|
||||
logInfoRepository.delete(id);
|
||||
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.github.liuweijw.business.admin.repository.RoleRepository;
|
||||
import com.github.liuweijw.business.admin.service.RoleService;
|
||||
import com.github.liuweijw.business.commons.beans.PageBean;
|
||||
import com.github.liuweijw.business.commons.beans.PageParams;
|
||||
import com.github.liuweijw.business.commons.beans.PageUtil;
|
||||
import com.github.liuweijw.business.commons.web.jpa.JPAFactoryImpl;
|
||||
import com.github.liuweijw.core.utils.StringHelper;
|
||||
import com.querydsl.core.types.Predicate;
|
||||
@@ -77,17 +78,9 @@ public class RoleServiceImpl extends JPAFactoryImpl implements RoleService {
|
||||
Predicate predicate = qRole.roleId.goe(0).and(qCodePredicate).and(qNamePredicate);
|
||||
|
||||
Sort sort = new Sort(new Sort.Order(Sort.Direction.DESC, "roleId"));
|
||||
PageRequest pageRequest = new PageRequest(pageParams.getCurrentPage(), pageParams
|
||||
.getPageSize(), sort);
|
||||
PageRequest pageRequest = PageUtil.of(pageParams, sort);
|
||||
Page<Role> pageList = roleRepository.findAll(predicate, pageRequest);
|
||||
|
||||
PageBean<Role> pageData = new PageBean<Role>();
|
||||
pageData.setCurrentPage(pageParams.getCurrentPage());
|
||||
pageData.setPageSize(pageParams.getPageSize());
|
||||
pageData.setTotal(pageList.getTotalElements());
|
||||
pageData.setList(pageList.getContent());
|
||||
|
||||
return pageData;
|
||||
return PageUtil.of(pageList);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -32,6 +32,7 @@ import com.github.liuweijw.business.admin.service.PermissionService;
|
||||
import com.github.liuweijw.business.admin.service.UserService;
|
||||
import com.github.liuweijw.business.commons.beans.PageBean;
|
||||
import com.github.liuweijw.business.commons.beans.PageParams;
|
||||
import com.github.liuweijw.business.commons.beans.PageUtil;
|
||||
import com.github.liuweijw.business.commons.web.jpa.JPAFactoryImpl;
|
||||
import com.github.liuweijw.core.beans.system.AuthRole;
|
||||
import com.github.liuweijw.core.beans.system.AuthUser;
|
||||
@@ -189,23 +190,14 @@ public class UserServiceImpl extends JPAFactoryImpl implements UserService {
|
||||
Predicate predicate = qUser.statu.eq(0).and(qUserNamePredicate);
|
||||
|
||||
Sort sort = new Sort(new Sort.Order(Sort.Direction.DESC, "createTime"));
|
||||
PageRequest pageRequest = new PageRequest(pageParams.getCurrentPage(), pageParams
|
||||
.getPageSize(), sort);
|
||||
PageRequest pageRequest = PageUtil.of(pageParams, sort);
|
||||
Page<User> pageList = userRepository.findAll(predicate, pageRequest);
|
||||
|
||||
if (null != pageList && null != pageList.getContent()) {
|
||||
for (User dbUser : pageList.getContent()) {
|
||||
dbUser.setRoleList(findRoleListByUserId(dbUser.getUserId()));
|
||||
}
|
||||
}
|
||||
|
||||
PageBean<User> pageData = new PageBean<User>();
|
||||
pageData.setCurrentPage(pageParams.getCurrentPage());
|
||||
pageData.setPageSize(pageParams.getPageSize());
|
||||
pageData.setTotal(pageList.getTotalElements());
|
||||
pageData.setList(pageList.getContent());
|
||||
|
||||
return pageData;
|
||||
return PageUtil.of(pageList);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -46,7 +46,7 @@ public class PageBean<T> {
|
||||
|
||||
public Integer getCurrentPage() {
|
||||
currentPage = (null == currentPage || currentPage <= 0) ? 1 : currentPage;
|
||||
return currentPage - 1;
|
||||
return currentPage;
|
||||
}
|
||||
|
||||
public void setCurrentPage(Integer currentPage) {
|
||||
|
||||
@@ -21,7 +21,7 @@ public class PageParams {
|
||||
|
||||
public Integer getCurrentPage() {
|
||||
currentPage = (null == currentPage || currentPage <= 0) ? 1 : currentPage;
|
||||
return currentPage - 1;
|
||||
return currentPage;
|
||||
}
|
||||
|
||||
public void setCurrentPage(Integer currentPage) {
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.github.liuweijw.business.commons.beans;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
/**
|
||||
* 分页工具
|
||||
*
|
||||
* @author liuweijw
|
||||
*/
|
||||
public class PageUtil {
|
||||
|
||||
public static <T> PageBean<T> of(Page<T> pageList) {
|
||||
PageBean<T> pageData = new PageBean<T>();
|
||||
pageData.setCurrentPage(pageList.getNumber() + 1);
|
||||
pageData.setPageSize(pageList.getSize());
|
||||
pageData.setTotal(pageList.getTotalElements());
|
||||
pageData.setList(pageList.getContent());
|
||||
return pageData;
|
||||
}
|
||||
|
||||
public static PageRequest of(PageParams pageParams, Sort sort) {
|
||||
return new PageRequest(pageParams.getCurrentPage() - 1, pageParams.getPageSize(), sort);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,6 +32,11 @@ public interface Module {
|
||||
*/
|
||||
String DICT = "dict_";
|
||||
|
||||
/**
|
||||
* 日志模块
|
||||
*/
|
||||
String LOG = "logs_";
|
||||
|
||||
/**
|
||||
* 验证码模块
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user