Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
markliu2013 committed Mar 20, 2024
1 parent a49a5c9 commit 692bec3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/main/java/cn/biq/mn/account/AccountService.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ public boolean adjustBalance(Integer id, AdjustBalanceAddForm form) {
public boolean updateAdjustBalance(Integer id, AdjustBalanceUpdateForm form) {
BalanceFlow balanceFlow = baseService.findFlowById(id);
BalanceFlowMapper.updateEntity(form, balanceFlow);
if (form.getBookId() != null) {
balanceFlow.setBook(baseService.getBookInGroup(form.getBookId()));
if (form.getBook() != null) {
balanceFlow.setBook(baseService.getBookInGroup(form.getBook()));
}
balanceFlowRepository.save(balanceFlow);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@Getter @Setter
public class AdjustBalanceUpdateForm {

private Integer bookId;
private Integer book;

@NotNull
@TimeField
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/cn/biq/mn/balanceflow/BalanceFlowService.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,11 @@ public boolean add(BalanceFlowAddForm form) {
if (form.getTags() != null) {
tagRelationService.addRelation(form.getTags(), entity, book, entity.getAccount());
}
if (form.getPayee() != null) {
Payee payee = payeeRepository.findOneByBookAndId(book, form.getPayee()).orElseThrow(ItemNotFoundException::new);
entity.setPayee(payee);
if (form.getType() == FlowType.EXPENSE || form.getType() == FlowType.INCOME) {
if (form.getPayee() != null) {
Payee payee = payeeRepository.findOneByBookAndId(book, form.getPayee()).orElseThrow(ItemNotFoundException::new);
entity.setPayee(payee);
}
}
balanceFlowRepository.save(entity);
if (form.getConfirm()) {
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/cn/biq/mn/exception/GlobalExceptionHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseBody
public BaseResponse exceptionHandler(MethodArgumentNotValidException e) {
e.printStackTrace();
ValidationErrorResponse response = new ValidationErrorResponse(HttpStatus.UNPROCESSABLE_ENTITY.value(), messageSourceUtil.getMessage("valid.fail"));
for (FieldError fieldError : e.getBindingResult().getFieldErrors()) {
response.getViolations().add(new Violation(fieldError.getField(), fieldError.getDefaultMessage()));
Expand All @@ -42,6 +43,7 @@ public BaseResponse exceptionHandler(MethodArgumentNotValidException e) {
@ExceptionHandler(ConstraintViolationException.class)
@ResponseBody
ValidationErrorResponse exceptionHandler(ConstraintViolationException e) {
e.printStackTrace();
ValidationErrorResponse response = new ValidationErrorResponse(4221, messageSourceUtil.getMessage("valid.fail"));
for (ConstraintViolation<?> violation : e.getConstraintViolations()) {
response.getViolations().add(new Violation(violation.getPropertyPath().toString(), violation.getMessage()));
Expand All @@ -53,6 +55,7 @@ ValidationErrorResponse exceptionHandler(ConstraintViolationException e) {
@ExceptionHandler(BindException.class)
@ResponseBody
ValidationErrorResponse exceptionHandler(BindException e) {
e.printStackTrace();
ValidationErrorResponse response = new ValidationErrorResponse(4223, messageSourceUtil.getMessage("valid.fail"));
for (FieldError error : e.getBindingResult().getFieldErrors()) {
response.getViolations().add(new Violation(error.getField(), error.getDefaultMessage()));
Expand All @@ -66,6 +69,7 @@ ValidationErrorResponse exceptionHandler(BindException e) {
// @ExceptionHandler(TransactionSystemException.class)
@ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY)
public BaseResponse exceptionHandler(TransactionSystemException e) {
e.printStackTrace();
if (e.getRootCause() instanceof ConstraintViolationException) {
ConstraintViolationException constraintViolationException = (ConstraintViolationException) e.getRootCause();
ValidationErrorResponse response = new ValidationErrorResponse(4222, messageSourceUtil.getMessage("valid.fail"));
Expand All @@ -85,6 +89,7 @@ public BaseResponse exceptionHandler(TransactionSystemException e) {
@ExceptionHandler(DataIntegrityViolationException.class)
@ResponseBody
public BaseResponse exceptionHandler(DataIntegrityViolationException e) {
e.printStackTrace();
String rootMsg = "";
if (e.getRootCause() != null) {
rootMsg = e.getRootCause().getMessage();
Expand All @@ -95,6 +100,7 @@ public BaseResponse exceptionHandler(DataIntegrityViolationException e) {
@ExceptionHandler(ItemExistsException.class)
@ResponseBody
public BaseResponse exceptionHandler(ItemExistsException e) {
e.printStackTrace();
String errMsg;
if (StringUtils.hasText(e.getMessage())) {
errMsg = messageSourceUtil.getMessage(e.getMessage());
Expand All @@ -107,6 +113,7 @@ public BaseResponse exceptionHandler(ItemExistsException e) {
@ExceptionHandler(ItemNotFoundException.class)
@ResponseBody // 404
public BaseResponse exceptionHandler(ItemNotFoundException e) {
e.printStackTrace();
String errMsg;
if (StringUtils.hasText(e.getMessage())) {
errMsg = messageSourceUtil.getMessage(e.getMessage());
Expand All @@ -119,6 +126,7 @@ public BaseResponse exceptionHandler(ItemNotFoundException e) {
@ExceptionHandler(FailureMessageException.class)
@ResponseBody
public BaseResponse exceptionHandler(FailureMessageException e) {
e.printStackTrace();
return new SimpleResponse(false, messageSourceUtil.getMessage(e.getMessage()), e.getShowType());
}

Expand Down

0 comments on commit 692bec3

Please sign in to comment.