AccidentCarController.java 2.22 KB
package cn.fw.valhalla.controller.app;

import cn.fw.common.web.auth.LoginAuthBean;
import cn.fw.common.web.auth.annotation.CurrentUser;
import cn.fw.data.base.domain.common.Message;
import cn.fw.security.auth.client.annotation.Authorization;
import cn.fw.security.auth.client.enums.AuthType;
import cn.fw.valhalla.domain.dto.AccidentPoolDTO;
import cn.fw.valhalla.service.bus.cust.AccidentPoolBizService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

import static cn.fw.common.web.util.ExceptionHandler.handleException;
import static cn.fw.common.web.util.ResultBuilder.failureWithMessage;
import static cn.fw.common.web.util.ResultBuilder.success;
import static cn.fw.valhalla.common.constant.MessageStr.SAVE_FAILURE;

/**
 * @author : kurisu
 * @className : AccidentCarController
 * @description : 事故车处理控制器
 * @date: 2020-08-15 14:52
 */
@Slf4j
@RestController
@Authorization(AuthType.APP)
@Validated
@RequestMapping("/app/accident")
public class AccidentCarController {

    private final AccidentPoolBizService accidentPoolBizService;

    @Autowired
    public AccidentCarController(final AccidentPoolBizService accidentPoolBizService) {
        this.accidentPoolBizService = accidentPoolBizService;
    }

    @PostMapping("/pool/save")
    public Message<Void> save(@CurrentUser LoginAuthBean currentUser,
                              @RequestBody @Valid final AccidentPoolDTO accidentPoolDTO) {
        final String msg = "手动新增事故池[app/accident/pool/save]";
        try {
            log.info("{}: param[{}]", msg, accidentPoolDTO);
            accidentPoolBizService.add2Pool(currentUser, accidentPoolDTO);
            return success();
        } catch (Exception ex) {
            handleException(ex, e -> log.error("{}失败:param[{}]", msg, accidentPoolDTO, e));
            return failureWithMessage(SAVE_FAILURE);
        }
    }
}