package cn.superdesk.uniorder.openapi.api._thirdpart.qchjc.accounting.customer;

import cn.superdesk.uniorder.common.exception.OpenApiException;
import cn.superdesk.uniorder.openapi.annotation.QchjcRequestLog;
import cn.superdesk.uniorder.openapi.api._thirdpart.qchjc._dto.accounting.QchjcCustomerStatementDto;
import cn.superdesk.uniorder.openapi.api._thirdpart.qchjc._dto.accounting.QchjcCustomerStatementStatusDto;
import cn.superdesk.uniorder.openapi.api.base.O;
import cn.superdesk.uniorder.openapi.config.exception.ParameterNotValidException;
import cn.superdesk.uniorder.openapi.service.qchjc.accounting.CustomerStatementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: Java类作用描述
 * @Author: linjinyu
 * @CreateDate: 2022/3/4 下午5:14
 * @UpdateUser: linjinyu
 * @UpdateDate: 2022/3/4 下午5:14
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Api(value = "thirdpart-qchjc-accounting-customer", tags = {"thirdpart-qchjc-accounting-customer"})
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/v0/thirdpart/qchjc/accounting/customer")
public class CustomerStatementRestApi {
    private final CustomerStatementService customerStatementService;

    @ApiOperation(value = "采购单位对账单接收")
    @RequestMapping(value = "receive", method = RequestMethod.POST)
    @ResponseBody
    @QchjcRequestLog(value = "采购单位对账单接收")
    public O<QchjcCustomerStatementDto> receive(@RequestBody @Validated QchjcCustomerStatementDto dto, BindingResult result) throws OpenApiException {

    	if (result.hasErrors()) {
            throw new ParameterNotValidException(result);
        }

        //log.info("receive qchjc customer statement, param : {}", JSON.toJSONString(dto));

        customerStatementService.receive(dto);

        return new O<QchjcCustomerStatementDto>()
                .setResultCode(200)
                .setResultMessage("同步成功")
                .setSuccess(true);
    }


    @ApiOperation(value = "采购单位对账单状态同步")
    @RequestMapping(value = "/syncStatus", method = RequestMethod.POST)
    @ResponseBody
    @QchjcRequestLog("采购单位对账单状态同步")
    public O<QchjcCustomerStatementStatusDto> syncStatus(@RequestBody @Validated QchjcCustomerStatementStatusDto dto, BindingResult result) {

    	if (result.hasErrors()) {
            throw new ParameterNotValidException(result);
        }

        customerStatementService.syncStatus(dto);

        return new O<QchjcCustomerStatementStatusDto>()
                .setResultCode(200)
                .setResultMessage("同步成功")
                .setSuccess(true);
    }

}
