merge
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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<String, Object> page(JSONArray array, int currentPage, int pageSize) {
|
||||
Map<String, Object> 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;
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ public class TestControl {
|
||||
@GetMapping("listShipperCode")
|
||||
public JSONObject listShipperCode() {
|
||||
List<JSONObject> 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("生成二维码")
|
||||
|
||||
@@ -93,7 +93,7 @@ public class SysAuthorityControl {
|
||||
@GetMapping("listByEnable")
|
||||
public JSONObject listByEnable(String enable) {
|
||||
List<SysAuthority> 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<SysAuthority> 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, "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<SysConfig> byEnable = sysConfigService.listByEnable(enable);
|
||||
return JSONObjResult.toJSONObj(byEnable, true, "");
|
||||
return JSONObjResult.toJSONObj(byEnable, "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<SysRole> 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<SysAuthority> authoritys = sysAuthorityService.listByRoleIdEnable(roleId, enable);
|
||||
return JSONObjResult.toJSONObj(authoritys, true, "");
|
||||
return JSONObjResult.toJSONObj(authoritys, "");
|
||||
}
|
||||
|
||||
@LogInfo("保存角色权限")
|
||||
|
||||
@@ -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<SysUser> 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<SysRole> 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<SysAuthority> list = sysUserService.listAuthorityByIdAndEnable(userId, enable);
|
||||
return JSONObjResult.toJSONObj(list, true, "");
|
||||
return JSONObjResult.toJSONObj(list, "");
|
||||
}
|
||||
|
||||
@LogInfo("导出用户excel表")
|
||||
|
||||
@@ -33,6 +33,6 @@ public class SysUserLoginInOutControl {
|
||||
@GetMapping("listByType")
|
||||
public JSONObject listByType(@RequestParam int inout) {
|
||||
List<SysUserLoginInOut> sysUserLoginInOuts = inOutService.listByType(inout);
|
||||
return JSONObjResult.toJSONObj(sysUserLoginInOuts, true, "获取列表成功");
|
||||
return JSONObjResult.toJSONObj(sysUserLoginInOuts, "获取列表成功");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user