diff --git a/boot-service/src/main/java/com/xwbing/util/JSONObjResult.java b/boot-service/src/main/java/com/xwbing/util/JSONObjResult.java index da56fd2..f99cbe6 100644 --- a/boot-service/src/main/java/com/xwbing/util/JSONObjResult.java +++ b/boot-service/src/main/java/com/xwbing/util/JSONObjResult.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.serializer.SerializerFeature; import lombok.Data; +import org.apache.commons.lang3.StringUtils; /** * 说明: 封装对象结果的json结果 @@ -24,16 +25,17 @@ public class JSONObjResult { /** * 消息体 */ - private String message = ""; + private String message = "操作成功"; /** * 返回数据 */ private Object data; - public static JSONObject toJSONObj(Object o, boolean success, String message) { + public static JSONObject toJSONObj(Object o, String message) { JSONObjResult jsonObjResult = new JSONObjResult(); - jsonObjResult.setSuccess(success); - jsonObjResult.setMessage(message); + jsonObjResult.setSuccess(true); + if (StringUtils.isNotEmpty(message)) + jsonObjResult.setMessage(message); jsonObjResult.setData(JSONUtil.beanToMap(o)); return JSON.parseObject(JSON.toJSONString(jsonObjResult, SerializerFeature.WriteMapNullValue)); } diff --git a/boot-service/src/main/java/com/xwbing/util/PageUtil.java b/boot-service/src/main/java/com/xwbing/util/PageUtil.java new file mode 100644 index 0000000..31cb345 --- /dev/null +++ b/boot-service/src/main/java/com/xwbing/util/PageUtil.java @@ -0,0 +1,34 @@ +package com.xwbing.util; + +import com.alibaba.fastjson.JSONArray; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +/** + * 项目名称: cloud-control-demonstration + * 创建时间: 2017/10/18 8:55 + * 作者: xiangwb + * 说明: + */ +public class PageUtil { + public static Map page(JSONArray array, int currentPage, int pageSize) { + Map pageMap = new HashMap<>(); + int size = array.size(); + pageMap.put("count", size); + int start = (currentPage - 1) * pageSize; + int end = pageSize * currentPage; + if (start >= end || start >= size) { + pageMap.put("data", Collections.emptyList()); + } else { + if (start < size && end > size) { + end = size; + } + pageMap.put("data", array.subList(start, end)); + } + int totalPage = size % pageSize == 0 ? size / pageSize : size / pageSize + 1; + pageMap.put("totalPage", totalPage); + return pageMap; + } +} diff --git a/boot-web/src/main/java/com/xwbing/controller/TestControl.java b/boot-web/src/main/java/com/xwbing/controller/TestControl.java index 97b56bd..81afbfe 100644 --- a/boot-web/src/main/java/com/xwbing/controller/TestControl.java +++ b/boot-web/src/main/java/com/xwbing/controller/TestControl.java @@ -63,7 +63,7 @@ public class TestControl { @GetMapping("listShipperCode") public JSONObject listShipperCode() { List list = expressDeliveryService.listShipperCode(); - return JSONObjResult.toJSONObj(list, true, ""); + return JSONObjResult.toJSONObj(list, ""); } @LogInfo("快递查询") @@ -72,7 +72,7 @@ public class TestControl { if (StringUtils.isEmpty(info.getLogisticCode()) || StringUtils.isEmpty(info.getShipperCode())) return JSONObjResult.toJSONObj("快递公司或物流单号不能为空"); ExpressInfoVo infoVo = expressDeliveryService.queryOrderTraces(info); - return JSONObjResult.toJSONObj(infoVo, true, "查询快递信息成功"); + return JSONObjResult.toJSONObj(infoVo, "查询快递信息成功"); } @LogInfo("生成二维码") diff --git a/boot-web/src/main/java/com/xwbing/controller/sys/SysAuthorityControl.java b/boot-web/src/main/java/com/xwbing/controller/sys/SysAuthorityControl.java index 0eb4dc9..2d336dc 100644 --- a/boot-web/src/main/java/com/xwbing/controller/sys/SysAuthorityControl.java +++ b/boot-web/src/main/java/com/xwbing/controller/sys/SysAuthorityControl.java @@ -93,7 +93,7 @@ public class SysAuthorityControl { @GetMapping("listByEnable") public JSONObject listByEnable(String enable) { List authoritys = sysAuthorityService.listByEnable(enable); - return JSONObjResult.toJSONObj(authoritys, true, ""); + return JSONObjResult.toJSONObj(authoritys, ""); } @LogInfo("根据父节点查询子节点") @@ -101,12 +101,12 @@ public class SysAuthorityControl { @ApiOperation(value = "根据父节点查询子节点") @ApiImplicitParam(name = "parentId", value = "父id,可为空", paramType = "query", dataType = "string") public JSONObject listByParentId(String parentId) { - if(StringUtils.isEmpty(parentId)) - parentId=CommonConstant.ROOT; + if (StringUtils.isEmpty(parentId)) + parentId = CommonConstant.ROOT; if (!CommonConstant.ROOT.equals(parentId) && sysAuthorityService.getById(parentId) == null) return JSONObjResult.toJSONObj("父节点不存在"); List queryByParentId = sysAuthorityService.listByParentEnable(parentId, null); - return JSONObjResult.toJSONObj(queryByParentId, true, ""); + return JSONObjResult.toJSONObj(queryByParentId, ""); } @LogInfo("递归查询所有权限") @@ -125,6 +125,6 @@ public class SysAuthorityControl { // 设置缓存 redisService.set(CommonConstant.AUTHORITY_THREE, JSONArray.toJSONString(authoritys)); } - return JSONObjResult.toJSONObj(authoritys, true, ""); + return JSONObjResult.toJSONObj(authoritys, ""); } } diff --git a/boot-web/src/main/java/com/xwbing/controller/sys/SysConfigControl.java b/boot-web/src/main/java/com/xwbing/controller/sys/SysConfigControl.java index fe3c8bd..42ae425 100644 --- a/boot-web/src/main/java/com/xwbing/controller/sys/SysConfigControl.java +++ b/boot-web/src/main/java/com/xwbing/controller/sys/SysConfigControl.java @@ -94,7 +94,7 @@ public class SysConfigControl { if (one == null) { return JSONObjResult.toJSONObj("该配置不存在"); } - return JSONObjResult.toJSONObj(one, true, ""); + return JSONObjResult.toJSONObj(one, ""); } @LogInfo("根据是否启用查找配置列表") @@ -108,6 +108,6 @@ public class SysConfigControl { return JSONObjResult.toJSONObj("是否启用不能为空"); } List byEnable = sysConfigService.listByEnable(enable); - return JSONObjResult.toJSONObj(byEnable, true, ""); + return JSONObjResult.toJSONObj(byEnable, ""); } } diff --git a/boot-web/src/main/java/com/xwbing/controller/sys/SysRoleControl.java b/boot-web/src/main/java/com/xwbing/controller/sys/SysRoleControl.java index 2a584c4..c6af564 100644 --- a/boot-web/src/main/java/com/xwbing/controller/sys/SysRoleControl.java +++ b/boot-web/src/main/java/com/xwbing/controller/sys/SysRoleControl.java @@ -74,7 +74,7 @@ public class SysRoleControl { SysRole sysRole = sysRoleService.getById(id); if (sysRole == null) return JSONObjResult.toJSONObj("该角色不存在"); - return JSONObjResult.toJSONObj(sysRole, true, ""); + return JSONObjResult.toJSONObj(sysRole, ""); } @LogInfo("根据是否启用查询所有角色") @@ -83,7 +83,7 @@ public class SysRoleControl { @GetMapping("listByEnable") public JSONObject listByEnable(String enable) { List sysRoles = sysRoleService.listAllByEnable(enable); - return JSONObjResult.toJSONObj(sysRoles, true, ""); + return JSONObjResult.toJSONObj(sysRoles, ""); } @LogInfo("根据角色主键查找权限") @@ -97,7 +97,7 @@ public class SysRoleControl { if (sysRole == null) return JSONObjResult.toJSONObj("该角色不存在"); List authoritys = sysAuthorityService.listByRoleIdEnable(roleId, enable); - return JSONObjResult.toJSONObj(authoritys, true, ""); + return JSONObjResult.toJSONObj(authoritys, ""); } @LogInfo("保存角色权限") diff --git a/boot-web/src/main/java/com/xwbing/controller/sys/SysUserControl.java b/boot-web/src/main/java/com/xwbing/controller/sys/SysUserControl.java index 889df4f..bf9b074 100644 --- a/boot-web/src/main/java/com/xwbing/controller/sys/SysUserControl.java +++ b/boot-web/src/main/java/com/xwbing/controller/sys/SysUserControl.java @@ -85,7 +85,7 @@ public class SysUserControl { SysUser sysUser = sysUserService.getById(id); if (sysUser == null) return JSONObjResult.toJSONObj("未查到该对象"); - return JSONObjResult.toJSONObj(sysUser, true, ""); + return JSONObjResult.toJSONObj(sysUser, ""); } @LogInfo("列表查询所有用户") @@ -93,7 +93,7 @@ public class SysUserControl { @GetMapping("listAll") public JSONObject listAll() { List list = sysUserService.listAll(); - return JSONObjResult.toJSONObj(list, true, ""); + return JSONObjResult.toJSONObj(list, ""); } @LogInfo("登录") @@ -162,7 +162,7 @@ public class SysUserControl { } sysUser.setMenus(menu); sysUser.setButtons(button); - return JSONObjResult.toJSONObj(sysUser, true, ""); + return JSONObjResult.toJSONObj(sysUser, ""); } @LogInfo("保存用户角色") @@ -199,7 +199,7 @@ public class SysUserControl { if (StringUtils.isEmpty(userId)) return JSONObjResult.toJSONObj("用户主键不能为空"); List list = sysRoleService.listByUserIdEnable(userId, enable); - return JSONObjResult.toJSONObj(list, true, ""); + return JSONObjResult.toJSONObj(list, ""); } @LogInfo("根据用户主键查找所拥有的权限") @@ -210,7 +210,7 @@ public class SysUserControl { if (StringUtils.isEmpty(userId)) return JSONObjResult.toJSONObj("用户主键不能为空"); List list = sysUserService.listAuthorityByIdAndEnable(userId, enable); - return JSONObjResult.toJSONObj(list, true, ""); + return JSONObjResult.toJSONObj(list, ""); } @LogInfo("导出用户excel表") diff --git a/boot-web/src/main/java/com/xwbing/controller/sys/SysUserLoginInOutControl.java b/boot-web/src/main/java/com/xwbing/controller/sys/SysUserLoginInOutControl.java index 3550566..b37a18a 100644 --- a/boot-web/src/main/java/com/xwbing/controller/sys/SysUserLoginInOutControl.java +++ b/boot-web/src/main/java/com/xwbing/controller/sys/SysUserLoginInOutControl.java @@ -33,6 +33,6 @@ public class SysUserLoginInOutControl { @GetMapping("listByType") public JSONObject listByType(@RequestParam int inout) { List sysUserLoginInOuts = inOutService.listByType(inout); - return JSONObjResult.toJSONObj(sysUserLoginInOuts, true, "获取列表成功"); + return JSONObjResult.toJSONObj(sysUserLoginInOuts, "获取列表成功"); } }