package cn.superdesk.uniorder.openapi.api._thirdpart.qchjc.organisation;

import cn.superdesk.uniorder.openapi.annotation.QchjcRequestLog;
import cn.superdesk.uniorder.openapi.api._thirdpart.qchjc._dto.organisation.QchjcSupplierDto;
import cn.superdesk.uniorder.openapi.api.base.O;
import cn.superdesk.uniorder.openapi.config.exception.ParameterNotValidException;
import cn.superdesk.uniorder.openapi.service.qchjc.organisation.SupplierService;
import com.alibaba.fastjson2.JSON;
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 下午3:54
 * @UpdateUser: linjinyu
 * @UpdateDate: 2022/3/4 下午3:54
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Api(value = "thirdpart-qchjc-supplier", tags = {"thirdpart-qchjc-supplier"})
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/v0/thirdpart/qchjc/supplier")
public class SupplierRestApi {

    private final SupplierService supplierService;

    @ApiOperation(value = "供应商(供货单位)接收")
    @RequestMapping(value = "receive", method = RequestMethod.POST)
    @ResponseBody
    @QchjcRequestLog("供应商(供货单位)接收")
    public O receive(@RequestBody @Validated QchjcSupplierDto dto, BindingResult result) {

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

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

        supplierService.receiveSupplierData(dto);

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