diff --git a/pig-admin-service/pom.xml b/pig-admin-service/pom.xml index 2baf7ec3..c1095b85 100644 --- a/pig-admin-service/pom.xml +++ b/pig-admin-service/pom.xml @@ -29,11 +29,6 @@ mysql-connector-java - - com.baomidou - mybatis-plus - 2.1.4 - com.baomidou mybatisplus-spring-boot-starter diff --git a/pig-admin-service/src/main/java/com/github/pig/admin/controller/DictController.java b/pig-admin-service/src/main/java/com/github/pig/admin/controller/DictController.java index 8fe78217..613c79ba 100644 --- a/pig-admin-service/src/main/java/com/github/pig/admin/controller/DictController.java +++ b/pig-admin-service/src/main/java/com/github/pig/admin/controller/DictController.java @@ -6,15 +6,14 @@ import com.baomidou.mybatisplus.plugins.Page; import com.github.pig.admin.entity.SysDict; import com.github.pig.admin.service.SysDictService; import com.github.pig.common.constant.CommonConstant; +import com.github.pig.common.util.Query; import com.github.pig.common.web.BaseController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.Cacheable; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; +import java.util.Map; /** *

@@ -44,17 +43,13 @@ public class DictController extends BaseController { /** * 分页查询字典信息 * - * @param page 分页对象 - * @param limit 每页限制 + * @param params 分页对象 * @return 分页对象 */ @RequestMapping("/dictPage") - public Page dictPage(Integer page, Integer limit) { - SysDict condition = new SysDict(); - condition.setDelFlag(CommonConstant.STATUS_NORMAL); - EntityWrapper wrapper = new EntityWrapper(condition); - wrapper.orderBy("createTime", false); - return sysDictService.selectPage(new Page<>(page, limit), wrapper); + public Page dictPage(@RequestParam Map params) { + params.put(CommonConstant.DEL_FLAG, CommonConstant.STATUS_NORMAL); + return sysDictService.selectPage(new Query<>(params),new EntityWrapper<>()); } /** diff --git a/pig-admin-service/src/main/java/com/github/pig/admin/controller/LogController.java b/pig-admin-service/src/main/java/com/github/pig/admin/controller/LogController.java index c1743337..6547e8d3 100644 --- a/pig-admin-service/src/main/java/com/github/pig/admin/controller/LogController.java +++ b/pig-admin-service/src/main/java/com/github/pig/admin/controller/LogController.java @@ -6,12 +6,14 @@ import com.baomidou.mybatisplus.plugins.Page; import com.github.pig.admin.service.SysLogService; import com.github.pig.common.constant.CommonConstant; import com.github.pig.common.entity.SysLog; +import com.github.pig.common.util.Query; import com.github.pig.common.util.UserUtils; import com.github.pig.common.web.BaseController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.Date; +import java.util.Map; /** *

@@ -36,17 +38,13 @@ public class LogController extends BaseController { /** * 分页查询日志信息 * - * @param page 分页对象 - * @param limit 每页限制 + * @param params 分页对象 * @return 分页对象 */ @RequestMapping("/logPage") - public Page logPage(Integer page, Integer limit) { - SysLog condition = new SysLog(); - condition.setDelFlag(CommonConstant.STATUS_NORMAL); - EntityWrapper wrapper = new EntityWrapper(condition); - wrapper.orderBy("createTime", false); - return sysLogService.selectPage(new Page<>(page, limit), wrapper); + public Page logPage(@RequestParam Map params) { + params.put(CommonConstant.DEL_FLAG, CommonConstant.STATUS_NORMAL); + return sysLogService.selectPage(new Query<>(params),new EntityWrapper<>()); } /** diff --git a/pig-admin-service/src/main/java/com/github/pig/admin/controller/RoleController.java b/pig-admin-service/src/main/java/com/github/pig/admin/controller/RoleController.java index 593b11cb..a56dab02 100644 --- a/pig-admin-service/src/main/java/com/github/pig/admin/controller/RoleController.java +++ b/pig-admin-service/src/main/java/com/github/pig/admin/controller/RoleController.java @@ -7,6 +7,7 @@ import com.github.pig.admin.entity.SysRoleMenu; import com.github.pig.admin.service.SysRoleMenuService; import com.github.pig.admin.service.SysRoleService; import com.github.pig.common.constant.CommonConstant; +import com.github.pig.common.util.Query; import com.github.pig.common.web.BaseController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; @@ -14,6 +15,7 @@ import org.springframework.web.bind.annotation.*; import java.util.ArrayList; import java.util.List; +import java.util.Map; /** * @author lengleng @@ -85,15 +87,13 @@ public class RoleController extends BaseController { /** * 分页查询角色信息 * - * @param page 分页对象 - * @param limit 每页限制 + * @param params 分页对象 * @return 分页对象 */ @RequestMapping("/rolePage") - public Page rolePage(Integer page, Integer limit) { - SysRole condition = new SysRole(); - condition.setDelFlag(CommonConstant.STATUS_NORMAL); - return sysRoleService.selectPage(new Page<>(page, limit), new EntityWrapper<>(condition)); + public Page rolePage(@RequestParam Map params) { + params.put(CommonConstant.DEL_FLAG, CommonConstant.STATUS_NORMAL); + return sysRoleService.selectPage(new Query<>(params),new EntityWrapper<>()); } /** @@ -104,7 +104,7 @@ public class RoleController extends BaseController { * @return success、false */ @PutMapping("/roleMenuUpd") - @CacheEvict(value = "menu_details",allEntries = true) + @CacheEvict(value = "menu_details", allEntries = true) public Boolean roleMenuUpd(Integer roleId, @RequestParam("menuIds[]") Integer[] menuIds) { SysRoleMenu condition = new SysRoleMenu(); condition.setRoleId(roleId); diff --git a/pig-admin-service/src/main/java/com/github/pig/admin/controller/UserController.java b/pig-admin-service/src/main/java/com/github/pig/admin/controller/UserController.java index 1a35c9b8..4e9465f3 100644 --- a/pig-admin-service/src/main/java/com/github/pig/admin/controller/UserController.java +++ b/pig-admin-service/src/main/java/com/github/pig/admin/controller/UserController.java @@ -11,6 +11,7 @@ import com.github.pig.admin.service.SysMenuService; import com.github.pig.admin.service.SysUserRoleService; import com.github.pig.admin.service.UserService; import com.github.pig.common.constant.CommonConstant; +import com.github.pig.common.util.Query; import com.github.pig.common.util.UserUtils; import com.github.pig.common.vo.UserVo; import com.github.pig.common.web.BaseController; @@ -165,8 +166,8 @@ public class UserController extends BaseController { * @return 用户集合 */ @RequestMapping("/userPage") - public Page userPage(Integer page, Integer limit, SysUser sysUser) { - return userService.selectWithRolePage(new Page<>(page, limit), sysUser); + public Page userPage(@RequestParam Map params) { + return userService.selectWithRolePage(new Query(params)); } /** diff --git a/pig-admin-service/src/main/java/com/github/pig/admin/mapper/SysUserMapper.java b/pig-admin-service/src/main/java/com/github/pig/admin/mapper/SysUserMapper.java index 022315d9..dcd9e9ef 100644 --- a/pig-admin-service/src/main/java/com/github/pig/admin/mapper/SysUserMapper.java +++ b/pig-admin-service/src/main/java/com/github/pig/admin/mapper/SysUserMapper.java @@ -1,11 +1,12 @@ package com.github.pig.admin.mapper; import com.baomidou.mybatisplus.mapper.BaseMapper; -import com.baomidou.mybatisplus.plugins.Page; import com.github.pig.admin.entity.SysUser; +import com.github.pig.common.util.Query; import com.github.pig.common.vo.UserVo; import java.util.List; +import java.util.Map; /** *

@@ -27,9 +28,8 @@ public interface SysUserMapper extends BaseMapper { /** * 分页查询用户信息(含角色) * - * @param page - * @param sysUser + * @param query 查询条件 * @return */ - List selectUserVoPage(Page page, SysUser sysUser); + List selectUserVoPage(Query query, Map params); } \ No newline at end of file diff --git a/pig-admin-service/src/main/java/com/github/pig/admin/service/UserService.java b/pig-admin-service/src/main/java/com/github/pig/admin/service/UserService.java index adf433f0..3e5e1ffc 100644 --- a/pig-admin-service/src/main/java/com/github/pig/admin/service/UserService.java +++ b/pig-admin-service/src/main/java/com/github/pig/admin/service/UserService.java @@ -3,6 +3,7 @@ package com.github.pig.admin.service; import com.baomidou.mybatisplus.plugins.Page; import com.baomidou.mybatisplus.service.IService; import com.github.pig.admin.entity.SysUser; +import com.github.pig.common.util.Query; import com.github.pig.common.vo.UserVo; /** @@ -21,11 +22,10 @@ public interface UserService extends IService { /** * 分页查询用户信息(含有角色信息) * - * @param page 分页对象 - * @param sysUser 查询条件 + * @param query 查询条件 * @return */ - Page selectWithRolePage(Page page, SysUser sysUser); + Page selectWithRolePage(Query query); /** * 清除用户缓存 diff --git a/pig-admin-service/src/main/java/com/github/pig/admin/service/impl/UserServiceImpl.java b/pig-admin-service/src/main/java/com/github/pig/admin/service/impl/UserServiceImpl.java index b1f69807..bb49b224 100644 --- a/pig-admin-service/src/main/java/com/github/pig/admin/service/impl/UserServiceImpl.java +++ b/pig-admin-service/src/main/java/com/github/pig/admin/service/impl/UserServiceImpl.java @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.github.pig.admin.entity.SysUser; import com.github.pig.admin.mapper.SysUserMapper; import com.github.pig.admin.service.UserService; +import com.github.pig.common.util.Query; import com.github.pig.common.vo.UserVo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; @@ -27,9 +28,9 @@ public class UserServiceImpl extends ServiceImpl impleme } @Override - public Page selectWithRolePage(Page page, SysUser sysUser) { - page.setRecords(sysUserMapper.selectUserVoPage(page, sysUser)); - return page; + public Page selectWithRolePage(Query query) { + query.setRecords(sysUserMapper.selectUserVoPage(query,query.getCondition())); + return query; } @Override diff --git a/pig-common/pom.xml b/pig-common/pom.xml index dfb12713..7ccbd172 100644 --- a/pig-common/pom.xml +++ b/pig-common/pom.xml @@ -56,6 +56,12 @@ jasypt-spring-boot-starter 1.16 + + + com.baomidou + mybatis-plus + 2.1.4 + diff --git a/pig-common/src/main/java/com/github/pig/common/constant/CommonConstant.java b/pig-common/src/main/java/com/github/pig/common/constant/CommonConstant.java index 2524adbb..c294f0a8 100644 --- a/pig-common/src/main/java/com/github/pig/common/constant/CommonConstant.java +++ b/pig-common/src/main/java/com/github/pig/common/constant/CommonConstant.java @@ -41,4 +41,9 @@ public interface CommonConstant { * log rabbit队列名称 */ String LOG_QUEUE = "log"; + + /** + * 删除标记 + */ + String DEL_FLAG = "del_flag"; } diff --git a/pig-common/src/main/java/com/github/pig/common/util/Query.java b/pig-common/src/main/java/com/github/pig/common/util/Query.java new file mode 100644 index 00000000..5a3f67a0 --- /dev/null +++ b/pig-common/src/main/java/com/github/pig/common/util/Query.java @@ -0,0 +1,35 @@ +package com.github.pig.common.util; + +import com.baomidou.mybatisplus.plugins.Page; +import org.apache.commons.lang.StringUtils; + +import java.util.Map; + +/** + * @author lengleng + * @date 2017/12/10 + */ +public class Query extends Page { + private static final String PAGE = "page"; + private static final String LIMIT = "limit"; + private static final String ORDER_BY_FIELD = "orderByField"; + private static final String IS_ASC = "isAsc"; + + public Query(Map params) { + super(Integer.parseInt(params.getOrDefault(PAGE, 1).toString()) + , Integer.parseInt(params.getOrDefault(LIMIT, 10).toString())); + params.remove(PAGE); + params.remove(LIMIT); + params.remove(ORDER_BY_FIELD); + params.remove(IS_ASC); + this.setCondition(params); + + String orderByField = params.getOrDefault(ORDER_BY_FIELD, "").toString(); + if (StringUtils.isNotEmpty(orderByField)) { + this.setOrderByField(orderByField); + } + + Boolean isAsc = Boolean.parseBoolean(params.getOrDefault(IS_ASC, Boolean.TRUE).toString()); + this.setAsc(isAsc); + } +} diff --git a/pig-common/src/main/java/com/github/pig/common/util/R.java b/pig-common/src/main/java/com/github/pig/common/util/R.java new file mode 100644 index 00000000..74b96651 --- /dev/null +++ b/pig-common/src/main/java/com/github/pig/common/util/R.java @@ -0,0 +1,62 @@ +package com.github.pig.common.util; + +import java.io.Serializable; + + +public class R implements Serializable { + + private static final long serialVersionUID = 1L; + + public static final int NO_LOGIN = -1; + + public static final int SUCCESS = 0; + + public static final int FAIL = 1; + + public static final int NO_PERMISSION = 2; + + private String msg = "success"; + + private int code = SUCCESS; + + private T data; + + public R() { + super(); + } + + public R(T data) { + super(); + this.data = data; + } + + public R(Throwable e) { + super(); + this.msg = e.toString(); + this.code = FAIL; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } +} diff --git a/pig-common/src/main/java/com/github/pig/common/web/BaseController.java b/pig-common/src/main/java/com/github/pig/common/web/BaseController.java index 293b053f..34013eb8 100644 --- a/pig-common/src/main/java/com/github/pig/common/web/BaseController.java +++ b/pig-common/src/main/java/com/github/pig/common/web/BaseController.java @@ -15,10 +15,9 @@ import java.util.List; * @date 2017/10/28 */ public class BaseController { - public org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(this.getClass()); - @Autowired private HttpServletRequest request; + protected org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(this.getClass()); /** * 根据请求heard中的token获取用户角色