package com.docus.server.collection.controller;

import com.docus.core.util.Func;
import com.docus.infrastructure.web.api.CommonResult;
import com.docus.infrastructure.web.api.ResultCode;
import com.docus.server.collection.converter.FirstPageCheckoutConverter;
import com.docus.server.collection.dto.FirstPageCheckoutInDTO;
import com.docus.server.collection.dto.FirstPageCheckoutRequest;
import com.docus.server.collection.service.MzZyHisService;
import com.docus.server.collection.validator.RequestValidator;
import com.docus.server.collection.validator.ValidateResult;
import com.docus.server.collection.validator.impl.FirstPageCheckoutRequestValidator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
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.annotation.Resource;

@Api("梅州中西HIS相关接口")
@Slf4j
@RestController
@RequestMapping("/his")
public class MzZyHisController {
    @Resource
    private MzZyHisService mzZyHisService;

    @ApiOperation("首页签出")
    @PostMapping("/firstPageCheckout")
    public CommonResult<String> firstPageCheckout(@RequestBody FirstPageCheckoutRequest firstPageCheckoutRequest) {
        log.info("首页签出接口参数：{}", Func.toJson(firstPageCheckoutRequest));
        // 验证数据
        RequestValidator validator = new FirstPageCheckoutRequestValidator(firstPageCheckoutRequest);
        ValidateResult validateResult = validator.validate();
        if (validateResult.getResultCode() == ResultCode.FAILED) {
            return CommonResult.failed(validateResult.getMsg());
        }
        // 转换数据，业务处理
        FirstPageCheckoutConverter converter = new FirstPageCheckoutConverter(firstPageCheckoutRequest);
        FirstPageCheckoutInDTO checkoutInDTO = converter.req2dto();
        mzZyHisService.firstPageCheckout(checkoutInDTO);
        return CommonResult.success("操作成功！");
    }

}
