【fix sonar】返回对象与属性重名修改
This commit is contained in:
+16
-16
@@ -15,7 +15,7 @@ import lombok.Data;
|
||||
*/
|
||||
@Data
|
||||
@ApiModel(value="接口返回对象", description="接口返回对象")
|
||||
public class Result<T> implements Serializable {
|
||||
public class Results<T> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -49,36 +49,36 @@ public class Result<T> implements Serializable {
|
||||
@ApiModelProperty(value = "时间戳")
|
||||
private long timestamp = System.currentTimeMillis();
|
||||
|
||||
public Result() {
|
||||
public Results() {
|
||||
// do other
|
||||
}
|
||||
|
||||
public static<T> Result<T> OK() {
|
||||
Result<T> r = new Result<>();
|
||||
public static<T> Results<T> OK() {
|
||||
Results<T> r = new Results<>();
|
||||
r.setSuccess(true);
|
||||
r.setCode(CommonConstant.SC_OK_200);
|
||||
r.setMessage("成功");
|
||||
return r;
|
||||
}
|
||||
|
||||
public static<T> Result<T> OK(String message) {
|
||||
Result<T> r = new Result<>();
|
||||
public static<T> Results<T> OK(String message) {
|
||||
Results<T> r = new Results<>();
|
||||
r.setSuccess(true);
|
||||
r.setCode(CommonConstant.SC_OK_200);
|
||||
r.setMessage(message);
|
||||
return r;
|
||||
}
|
||||
|
||||
public static<T> Result<T> OK(T data) {
|
||||
Result<T> r = new Result<>();
|
||||
public static<T> Results<T> OK(T data) {
|
||||
Results<T> r = new Results<>();
|
||||
r.setSuccess(true);
|
||||
r.setCode(CommonConstant.SC_OK_200);
|
||||
r.setResult(data);
|
||||
return r;
|
||||
}
|
||||
|
||||
public static<T> Result<T> OK(String msg, T data) {
|
||||
Result<T> r = new Result<>();
|
||||
public static<T> Results<T> OK(String msg, T data) {
|
||||
Results<T> r = new Results<>();
|
||||
r.setSuccess(true);
|
||||
r.setCode(CommonConstant.SC_OK_200);
|
||||
r.setMessage(msg);
|
||||
@@ -86,8 +86,8 @@ public class Result<T> implements Serializable {
|
||||
return r;
|
||||
}
|
||||
|
||||
public static<T> Result<T> error(String msg, T data) {
|
||||
Result<T> r = new Result<>();
|
||||
public static<T> Results<T> error(String msg, T data) {
|
||||
Results<T> r = new Results<>();
|
||||
r.setSuccess(false);
|
||||
r.setCode(CommonConstant.SC_INTERNAL_SERVER_ERROR_500);
|
||||
r.setMessage(msg);
|
||||
@@ -95,12 +95,12 @@ public class Result<T> implements Serializable {
|
||||
return r;
|
||||
}
|
||||
|
||||
public static<T> Result<T> error(String msg) {
|
||||
public static<T> Results<T> error(String msg) {
|
||||
return error(CommonConstant.SC_INTERNAL_SERVER_ERROR_500, msg);
|
||||
}
|
||||
|
||||
public static<T> Result<T> error(int code, String msg) {
|
||||
Result<T> r = new Result<>();
|
||||
public static<T> Results<T> error(int code, String msg) {
|
||||
Results<T> r = new Results<>();
|
||||
r.setCode(code);
|
||||
r.setMessage(msg);
|
||||
r.setSuccess(false);
|
||||
@@ -110,7 +110,7 @@ public class Result<T> implements Serializable {
|
||||
/**
|
||||
* 无权限访问返回结果
|
||||
*/
|
||||
public static Result<Object> noauth(String msg) {
|
||||
public static Results<Object> noauth(String msg) {
|
||||
return error(CommonConstant.SC_JERO_NO_AUTHZ, msg);
|
||||
}
|
||||
|
||||
+3
-3
@@ -3,7 +3,7 @@ package com.jero.common.aspect;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.serializer.PropertyFilter;
|
||||
import com.jero.common.api.dto.LogDTO;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.aspect.annotation.AutoLog;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.constant.enums.ModuleType;
|
||||
@@ -198,8 +198,8 @@ public class AutoLogAspect {
|
||||
* @return
|
||||
*/
|
||||
private String getOnlineLogContent(Object obj, String content){
|
||||
if (obj instanceof Result){
|
||||
Result<T> res = (Result)obj;
|
||||
if (obj instanceof Results){
|
||||
Results<T> res = (Results)obj;
|
||||
String msg = res.getMessage();
|
||||
String tableName = res.getOnlTable();
|
||||
if(oConvertUtils.isNotEmpty(tableName)){
|
||||
|
||||
+5
-5
@@ -7,7 +7,7 @@ import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.jero.common.api.CommonAPI;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.aspect.annotation.Dict;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.system.vo.DictModel;
|
||||
@@ -89,7 +89,7 @@ public class DictAspect {
|
||||
* @param result
|
||||
*/
|
||||
private void parseDictText(Object result) {
|
||||
if (result instanceof Result && ((Result) result).getResult() instanceof IPage) {
|
||||
if (result instanceof Results && ((Results) result).getResult() instanceof IPage) {
|
||||
List<JSONObject> items = new ArrayList<>();
|
||||
|
||||
//step.1 筛选出加了 Dict 注解的字段列表
|
||||
@@ -97,7 +97,7 @@ public class DictAspect {
|
||||
// 字典数据列表, key = 字典code,value=数据列表
|
||||
Map<String, List<String>> dataListMap = new HashMap<>();
|
||||
|
||||
addItems((Result) result, items, dictFieldList, dataListMap);
|
||||
addItems((Results) result, items, dictFieldList, dataListMap);
|
||||
|
||||
//step.2 调用翻译方法,一次性翻译
|
||||
Map<String, List<DictModel>> translText = this.translateAllDict(dataListMap);
|
||||
@@ -105,7 +105,7 @@ public class DictAspect {
|
||||
//step.3 将翻译结果填充到返回结果里
|
||||
putItems(items, dictFieldList, translText);
|
||||
|
||||
((IPage) ((Result) result).getResult()).setRecords(items);
|
||||
((IPage) ((Results) result).getResult()).setRecords(items);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ public class DictAspect {
|
||||
}
|
||||
}
|
||||
|
||||
private void addItems(Result<IPage<T>> result, List<JSONObject> items, List<Field> dictFieldList, Map<String, List<String>> dataListMap) {
|
||||
private void addItems(Results<IPage<T>> result, List<JSONObject> items, List<Field> dictFieldList, Map<String, List<String>> dataListMap) {
|
||||
for (Object obj : result.getResult().getRecords()) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String json="{}";
|
||||
|
||||
+19
-19
@@ -1,6 +1,6 @@
|
||||
package com.jero.common.exception;
|
||||
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.apache.shiro.authz.AuthorizationException;
|
||||
@@ -28,33 +28,33 @@ public class JeroBootExceptionHandler {
|
||||
* 处理自定义异常
|
||||
*/
|
||||
@ExceptionHandler(JeroBootException.class)
|
||||
public Result<T> handleJeroBootException(JeroBootException e){
|
||||
public Results<T> handleJeroBootException(JeroBootException e){
|
||||
log.error(e.getMessage(), e);
|
||||
return Result.error(e.getMessage());
|
||||
return Results.error(e.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(NoHandlerFoundException.class)
|
||||
public Result<T> handlerNoFoundException(Exception e) {
|
||||
public Results<T> handlerNoFoundException(Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Result.error(404, "路径不存在,请检查路径是否正确");
|
||||
return Results.error(404, "路径不存在,请检查路径是否正确");
|
||||
}
|
||||
|
||||
@ExceptionHandler(DuplicateKeyException.class)
|
||||
public Result<T> handleDuplicateKeyException(DuplicateKeyException e){
|
||||
public Results<T> handleDuplicateKeyException(DuplicateKeyException e){
|
||||
log.error(e.getMessage(), e);
|
||||
return Result.error("数据库中已存在该记录");
|
||||
return Results.error("数据库中已存在该记录");
|
||||
}
|
||||
|
||||
@ExceptionHandler({UnauthorizedException.class, AuthorizationException.class})
|
||||
public Result<Object> handleAuthorizationException(AuthorizationException e){
|
||||
public Results<Object> handleAuthorizationException(AuthorizationException e){
|
||||
log.error(e.getMessage(), e);
|
||||
return Result.noauth("没有权限,请联系管理员授权");
|
||||
return Results.noauth("没有权限,请联系管理员授权");
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
public Result<T> handleException(Exception e){
|
||||
public Results<T> handleException(Exception e){
|
||||
log.error(e.getMessage(), e);
|
||||
return Result.error("操作失败,"+e.getMessage());
|
||||
return Results.error("操作失败,"+e.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +63,7 @@ public class JeroBootExceptionHandler {
|
||||
* @return
|
||||
*/
|
||||
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
|
||||
public Result<T> httpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e){
|
||||
public Results<T> httpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e){
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("不支持");
|
||||
sb.append(e.getMethod());
|
||||
@@ -77,28 +77,28 @@ public class JeroBootExceptionHandler {
|
||||
}
|
||||
}
|
||||
log.error(sb.toString(), e);
|
||||
return Result.error(405,sb.toString());
|
||||
return Results.error(405,sb.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* spring默认上传大小100MB 超出大小捕获异常MaxUploadSizeExceededException
|
||||
*/
|
||||
@ExceptionHandler(MaxUploadSizeExceededException.class)
|
||||
public Result<T> handleMaxUploadSizeExceededException(MaxUploadSizeExceededException e) {
|
||||
public Results<T> handleMaxUploadSizeExceededException(MaxUploadSizeExceededException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Result.error("文件大小超出10MB限制, 请压缩或降低文件质量! ");
|
||||
return Results.error("文件大小超出10MB限制, 请压缩或降低文件质量! ");
|
||||
}
|
||||
|
||||
@ExceptionHandler(DataIntegrityViolationException.class)
|
||||
public Result<T> handleDataIntegrityViolationException(DataIntegrityViolationException e) {
|
||||
public Results<T> handleDataIntegrityViolationException(DataIntegrityViolationException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Result.error("字段太长,超出数据库字段的长度");
|
||||
return Results.error("字段太长,超出数据库字段的长度");
|
||||
}
|
||||
|
||||
@ExceptionHandler(PoolException.class)
|
||||
public Result<T> handlePoolException(PoolException e) {
|
||||
public Results<T> handlePoolException(PoolException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Result.error("Redis 连接异常!");
|
||||
return Results.error("Redis 连接异常!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+5
-5
@@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
@@ -162,7 +162,7 @@ public class JeroController<T, S extends IService<T>> {
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
protected Result<T> importExcel(HttpServletRequest request,HttpServletResponse response, Class<T> clazz) {
|
||||
protected Results<T> importExcel(HttpServletRequest request, HttpServletResponse response, Class<T> clazz) {
|
||||
if(Objects.isNull(response)){
|
||||
log.info("打印未使用参数");
|
||||
}
|
||||
@@ -184,10 +184,10 @@ public class JeroController<T, S extends IService<T>> {
|
||||
//1200条 saveBatch消耗时间3687毫秒 循环插入消耗时间5212毫秒
|
||||
log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
|
||||
//update-end-author:taoyan date:20190528 for:批量插入数据
|
||||
return Result.OK("文件导入成功!数据行数:" + list.size());
|
||||
return Results.OK("文件导入成功!数据行数:" + list.size());
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Result.error("文件导入失败:" + e.getMessage());
|
||||
return Results.error("文件导入失败:" + e.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
file.getInputStream().close();
|
||||
@@ -196,6 +196,6 @@ public class JeroController<T, S extends IService<T>> {
|
||||
}
|
||||
}
|
||||
}
|
||||
return Result.error("文件导入失败!");
|
||||
return Results.error("文件导入失败!");
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -2,7 +2,7 @@ package com.jero.common.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -19,9 +19,9 @@ public class ImportExcelUtil {
|
||||
|
||||
}
|
||||
|
||||
public static Result<JSONObject> imporReturnRes(int errorLines, int successLines, List<String> errorMessage){
|
||||
public static Results<JSONObject> imporReturnRes(int errorLines, int successLines, List<String> errorMessage){
|
||||
if (errorLines == 0) {
|
||||
return Result.OK("共" + successLines + "行数据全部导入成功!");
|
||||
return Results.OK("共" + successLines + "行数据全部导入成功!");
|
||||
} else {
|
||||
JSONObject result = new JSONObject(5);
|
||||
int totalCount = successLines + errorLines;
|
||||
@@ -34,7 +34,7 @@ public class ImportExcelUtil {
|
||||
String fileName = fileUrl.substring(lastIndex + 1);
|
||||
result.put("fileUrl", "/sys/common/static/" + fileUrl);
|
||||
result.put("fileName", fileName);
|
||||
Result<JSONObject> res = Result.OK(result);
|
||||
Results<JSONObject> res = Results.OK(result);
|
||||
res.setCode(201);
|
||||
res.setMessage("文件导入成功,但有错误。");
|
||||
return res;
|
||||
|
||||
+9
-9
@@ -1,7 +1,7 @@
|
||||
package com.jero.common.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -37,7 +37,7 @@ public class RestDesformUtil {
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
public static Result<T> queryOne(String desformCode, String dataId, String token) {
|
||||
public static Results<T> queryOne(String desformCode, String dataId, String token) {
|
||||
String url = getBaseUrl(desformCode, dataId).toString();
|
||||
HttpHeaders headers = getHeaders(token);
|
||||
ResponseEntity<JSONObject> result = RestUtil.request(url, HttpMethod.GET, headers, null, null, JSONObject.class);
|
||||
@@ -52,7 +52,7 @@ public class RestDesformUtil {
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
public static Result<T> addOne(String desformCode, JSONObject formData, String token) {
|
||||
public static Results<T> addOne(String desformCode, JSONObject formData, String token) {
|
||||
return addOrEditOne(desformCode, formData, token, HttpMethod.POST);
|
||||
}
|
||||
|
||||
@@ -64,11 +64,11 @@ public class RestDesformUtil {
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
public static Result<T> editOne(String desformCode, JSONObject formData, String token) {
|
||||
public static Results<T> editOne(String desformCode, JSONObject formData, String token) {
|
||||
return addOrEditOne(desformCode, formData, token, HttpMethod.PUT);
|
||||
}
|
||||
|
||||
private static Result<T> addOrEditOne(String desformCode, JSONObject formData, String token, HttpMethod method) {
|
||||
private static Results<T> addOrEditOne(String desformCode, JSONObject formData, String token, HttpMethod method) {
|
||||
String url = getBaseUrl(desformCode).toString();
|
||||
HttpHeaders headers = getHeaders(token);
|
||||
ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, formData, JSONObject.class);
|
||||
@@ -83,19 +83,19 @@ public class RestDesformUtil {
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
public static Result<T> removeOne(String desformCode, String dataId, String token) {
|
||||
public static Results<T> removeOne(String desformCode, String dataId, String token) {
|
||||
String url = getBaseUrl(desformCode, dataId).toString();
|
||||
HttpHeaders headers = getHeaders(token);
|
||||
ResponseEntity<JSONObject> result = RestUtil.request(url, HttpMethod.DELETE, headers, null, null, JSONObject.class);
|
||||
return packageReturn(result);
|
||||
}
|
||||
|
||||
private static Result<T> packageReturn(ResponseEntity<JSONObject> result) {
|
||||
private static Results<T> packageReturn(ResponseEntity<JSONObject> result) {
|
||||
JSONObject json = result.getBody();
|
||||
if (!Objects.isNull(json)) {
|
||||
return json.toJavaObject(Result.class);
|
||||
return json.toJavaObject(Results.class);
|
||||
}
|
||||
return Result.error("操作失败");
|
||||
return Results.error("操作失败");
|
||||
}
|
||||
|
||||
private static StringBuilder getBaseUrl() {
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@ package com.jero.config;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -66,7 +66,7 @@ public class CsrfFilter implements Filter {
|
||||
log = "跨站请求---->>>" + ip + "||" + date + "||" + referurl + "||" + url;
|
||||
LOGGER.warn(log);
|
||||
//发送错误信息
|
||||
JSONObject json = JSONUtil.parseObj(Result.error("监测到跨站请求,请求失败"), false);
|
||||
JSONObject json = JSONUtil.parseObj(Results.error("监测到跨站请求,请求失败"), false);
|
||||
res.setCharacterEncoding("UTF-8");
|
||||
res.setContentType("application/json; charset=utf-8");
|
||||
PrintWriter out = res.getWriter();
|
||||
|
||||
+2
-2
@@ -6,7 +6,7 @@ import java.util.SortedMap;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.util.DateUtils;
|
||||
import com.jero.config.sign.util.BodyReaderHttpServletRequestWrapper;
|
||||
@@ -64,7 +64,7 @@ public class SignAuthInterceptor implements HandlerInterceptor {
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setContentType("application/json; charset=utf-8");
|
||||
PrintWriter out = response.getWriter();
|
||||
Result<?> result = Result.error("Sign签名校验失败!");
|
||||
Results<?> result = Results.error("Sign签名校验失败!");
|
||||
out.print(JSON.toJSON(result));
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user