Commit 030ae06d by guojuxing

代码优化

parent cd5babc7
package com.gic.finance.exception;
import com.gic.api.base.commons.ServiceResponse;
/**
* 转账审批异常类
* @ClassName: FinanceException

* @Description: 

* @author guojuxing

* @date 2019/8/9 5:09 PM

*/
public class FinanceException extends RuntimeException{
private String errorCode;
public FinanceException(String errorCode, String message) {
super(message);
this.errorCode = errorCode;
}
public FinanceException(ServiceResponse serviceResponse) {
super(serviceResponse.getMessage());
this.errorCode = serviceResponse.getCode();
}
public String getErrorCode() {
return errorCode;
}
}
......@@ -7,10 +7,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.enterprise.utils.ResultControllerUtils;
import com.gic.finance.dto.InvoiceManageDTO;
import com.gic.finance.qo.InvoiceManageListQueryQO;
import com.gic.finance.service.InvoiceManageApiService;
import com.gic.finance.web.utils.ResultControllerUtils;
import com.gic.finance.web.vo.InvoiceManageListVO;
/**
......@@ -81,7 +81,7 @@ public class InvoiceManageController {
@RequestMapping("/list-invoice")
public RestResponse listInvoice(InvoiceManageListQueryQO params) {
return ResultControllerUtils.commonResult(
return ResultControllerUtils.commonPageResult(
invoiceManageApiService.listInvoiceManage(params), InvoiceManageListVO.class);
}
......
......@@ -7,10 +7,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.enterprise.utils.ResultControllerUtils;
import com.gic.finance.dto.TransferAccountsApprovalDTO;
import com.gic.finance.qo.TransferListQueryQO;
import com.gic.finance.service.TransferAccountsApprovalApiService;
import com.gic.finance.web.utils.ResultControllerUtils;
import com.gic.finance.web.vo.TransferApprovalListVO;
/**
......@@ -60,7 +60,7 @@ public class TransferAccountsApprovalController {
@RequestMapping("/list-approval")
public RestResponse listTransferAccountsApproval(TransferListQueryQO params) {
return ResultControllerUtils.commonResult(
return ResultControllerUtils.commonPageResult(
transferAccountsApprovalApiService.listTransferAccountsApproval(params), TransferApprovalListVO.class);
}
}
......@@ -19,7 +19,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.enterprise.error.ErrorCode;
import com.gic.finance.exception.FinanceException;
import com.gic.enterprise.exception.CommonException;
import com.gic.store.exception.StoreException;
/**
......@@ -91,8 +91,8 @@ public class GlobalExceptionHandler {
return getRestResponse(e.getErrorCode(), e.getMessage());
}
@ResponseBody
@ExceptionHandler(FinanceException.class)
public RestResponse customException(FinanceException e) {
@ExceptionHandler(CommonException.class)
public RestResponse customException(CommonException e) {
return getRestResponse(e.getErrorCode(), e.getMessage());
}
......
package com.gic.finance.web.utils;
import com.gic.api.base.commons.Page;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.commons.util.EntityUtil;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.finance.exception.FinanceException;
/**
* controller统一返回工具类
* @ClassName: ResultControllerUtils

* @Description: 

* @author guojuxing

* @date 2019/8/9 5:12 PM

*/
public class ResultControllerUtils {
/**
* 统一返回成功结果
* @Title: commonResult

* @Description:

 * @author guojuxing
* @param response

* @return java.lang.Object


 */
public static RestResponse commonResult(ServiceResponse response) {
if (response.isSuccess()) {
return RestResponse.success(response.getResult());
} else {
throw new FinanceException(response);
}
}
/**
* 统一返回成功结果(分页DTO转为VO)
* @Title: commonResultOfListVO

* @Description:

 * @author guojuxing
* @param response
* @param clazz

* @return com.gic.commons.webapi.reponse.RestResponse


 */
public static RestResponse commonResult(ServiceResponse response, Class<?> clazz) {
if (response.isSuccess()) {
Page page = (Page) response.getResult();
page.setResult(EntityUtil.changeEntityListNew(clazz, page.getResult()));
return RestResponse.success(page);
} else {
throw new FinanceException(response);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment