Search in sources :

Example 6 with BaseResponse

use of com.tony.billing.response.BaseResponse in project BillingDubbo by TonyJiangWJ.

the class ExceptionResolver method doResolveException.

@ExceptionHandler
@Override
protected ModelAndView doResolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
    logger.error("biz error:", e);
    BaseResponse baseResponse = ResponseUtil.sysError();
    if (e instanceof BaseBusinessException) {
        baseResponse.setMsg(e.getMessage());
    } else if (e instanceof BindException) {
        baseResponse = ResponseUtil.paramError();
        List<ObjectError> errorList = ((BindException) e).getAllErrors();
        if (CollectionUtils.isNotEmpty(errorList)) {
            errorList.forEach((error -> {
                if (error instanceof FieldError) {
                    logger.error("[{}]参数错误:{}", ((FieldError) error).getField(), error.getDefaultMessage());
                } else {
                    logger.error("参数错误:{}", error.getDefaultMessage());
                }
            }));
        }
    }
    httpServletResponse.setContentType(MediaType.APPLICATION_JSON_VALUE);
    httpServletResponse.setCharacterEncoding("UTF-8");
    httpServletResponse.setHeader("Cache-Control", "no-cache, must-revalidate");
    try {
        httpServletResponse.getWriter().write(JSON.toJSONString(baseResponse));
    } catch (IOException ioe) {
        logger.error("与客户端通讯异常:" + ioe.getMessage(), ioe);
    }
    return new ModelAndView();
}
Also used : BaseResponse(com.tony.billing.response.BaseResponse) BaseBusinessException(com.tony.billing.exceptions.BaseBusinessException) ModelAndView(org.springframework.web.servlet.ModelAndView) BindException(org.springframework.validation.BindException) List(java.util.List) FieldError(org.springframework.validation.FieldError) IOException(java.io.IOException) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 7 with BaseResponse

use of com.tony.billing.response.BaseResponse in project BillingDubbo by TonyJiangWJ.

the class AdminController method login.

@RequestMapping(value = "/user/login", method = RequestMethod.POST)
public BaseResponse login(@ModelAttribute("request") @Validated AdminLoginRequest request, // 用于AOP获取IP地址等信息
HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
    BaseResponse response = new BaseResponse();
    try {
        Admin loginAdmin = new Admin();
        loginAdmin.setUserName(request.getUserName());
        loginAdmin.setPassword(request.getPassword());
        Admin admin = adminService.login(loginAdmin);
        if (admin != null) {
            authUtil.setCookieToken(admin.getTokenId(), httpServletResponse);
            ResponseUtil.success(response);
        } else {
            ResponseUtil.error(response);
        }
    } catch (Exception e) {
        logger.error("/user/login error", e);
        ResponseUtil.sysError(response);
    }
    return response;
}
Also used : BaseResponse(com.tony.billing.response.BaseResponse) ModifyAdmin(com.tony.billing.entity.ModifyAdmin) Admin(com.tony.billing.entity.Admin) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with BaseResponse

use of com.tony.billing.response.BaseResponse in project BillingDubbo by TonyJiangWJ.

the class AdminController method modifyPwd.

@RequestMapping(value = "/user/pwd/modify", method = RequestMethod.POST)
public BaseResponse modifyPwd(@ModelAttribute("request") @Validated AdminModifyPwdRequest request) {
    BaseResponse response = new BaseResponse();
    ModifyAdmin modifyAdmin = new ModifyAdmin();
    modifyAdmin.setId(request.getUserId());
    modifyAdmin.setNewPassword(request.getNewPassword());
    modifyAdmin.setPassword(request.getOldPassword());
    if (adminService.modifyPwd(modifyAdmin)) {
        return ResponseUtil.success(response);
    } else {
        return ResponseUtil.error(response);
    }
}
Also used : BaseResponse(com.tony.billing.response.BaseResponse) ModifyAdmin(com.tony.billing.entity.ModifyAdmin) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with BaseResponse

use of com.tony.billing.response.BaseResponse in project BillingDubbo by TonyJiangWJ.

the class BudgetController method addBudget.

@RequestMapping("/budget/put")
public BaseResponse addBudget(@ModelAttribute("request") @Validated BudgetPutRequest request) {
    BaseResponse response = new BaseResponse();
    try {
        Budget budget = new Budget();
        budget.setBelongMonth(request.getMonth());
        budget.setBelongYear(request.getYear());
        budget.setBudgetMoney(request.getAmount());
        budget.setUserId(request.getUserId());
        budget.setBudgetName(request.getName());
        if (budgetService.insert(budget) > 0) {
            ResponseUtil.success(response);
        } else {
            ResponseUtil.error(response);
        }
    } catch (Exception e) {
        logger.error("/budget/put error", e);
        ResponseUtil.sysError(response);
    }
    return response;
}
Also used : BaseResponse(com.tony.billing.response.BaseResponse) Budget(com.tony.billing.entity.Budget) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with BaseResponse

use of com.tony.billing.response.BaseResponse in project BillingDubbo by TonyJiangWJ.

the class CostRecordController method toggleHiddenStatus.

@RequestMapping(value = "/record/toggle/hide")
public BaseResponse toggleHiddenStatus(@ModelAttribute("request") @Validated CostRecordHideRequest request) {
    BaseResponse response = new BaseResponse();
    try {
        Map<String, Object> params = new HashMap<>();
        params.put("tradeNo", request.getTradeNo());
        params.put("nowStatus", request.getNowStatus());
        params.put("isHidden", request.getNowStatus().equals(0) ? 1 : 0);
        params.put("userId", request.getUserId());
        if (costRecordService.toggleHideStatus(params) > 0) {
            ResponseUtil.success(response);
        } else {
            ResponseUtil.error(response);
        }
    } catch (Exception e) {
        logger.error("/toggle/hide error", e);
        ResponseUtil.sysError(response);
    }
    return response;
}
Also used : BaseResponse(com.tony.billing.response.BaseResponse) HashMap(java.util.HashMap) ParseException(java.text.ParseException) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

BaseResponse (com.tony.billing.response.BaseResponse)15 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 CostRecord (com.tony.billing.entity.CostRecord)4 ModifyAdmin (com.tony.billing.entity.ModifyAdmin)3 TagInfo (com.tony.billing.entity.TagInfo)3 IOException (java.io.IOException)3 Admin (com.tony.billing.entity.Admin)2 ParseException (java.text.ParseException)2 Budget (com.tony.billing.entity.Budget)1 LoginLog (com.tony.billing.entity.LoginLog)1 TagCostRef (com.tony.billing.entity.TagCostRef)1 BaseBusinessException (com.tony.billing.exceptions.BaseBusinessException)1 AdminLoginRequest (com.tony.billing.request.admin.AdminLoginRequest)1 HashMap (java.util.HashMap)1 List (java.util.List)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 AfterReturning (org.aspectj.lang.annotation.AfterReturning)1 BindException (org.springframework.validation.BindException)1 FieldError (org.springframework.validation.FieldError)1 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)1