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();
}
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;
}
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);
}
}
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;
}
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;
}
Aggregations