package cn.superdesk.uniorder.controller.accounting.qchjc;

import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.dto.param.accounting.qchjc.QchjcSupplierAccountingListRequest;
import cn.superdesk.uniorder.dto.param.accounting.qchjc.RemarkParam;
import cn.superdesk.uniorder.dto.vo.organisation.UnifiedSupplierVo;
import cn.superdesk.uniorder.dto.vo.thirdpart.qchjc.accounting.QchjcAccountingUnifiedSupplierVo;
import cn.superdesk.uniorder.dubbo.consumer.accounting.qchjc.QchjcSupplierAccountingDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author xc
 * @description 企业商城账单-供应商账单
 * @date 2022/4/14 20:03
 */
@Api(value = "企业商城账单-供应商账单", tags = "企业商城账单-供应商账单")
@RestController
@RequestMapping("/accounting/qchjc/supplier/statement")
@RequiredArgsConstructor
@Slf4j
public class QchjcSupplierAccountingController {

    private final QchjcSupplierAccountingDubboService qchjcSupplierAccountingDubboService;

    @ApiOperation(value = "企业商城账单-供应商账单列表", notes = "企业商城账单-供应商账单列表")
    @PostMapping("/list")
    public R<List<QchjcAccountingUnifiedSupplierVo>> list(@RequestBody @Validated QchjcSupplierAccountingListRequest request) {
        log.info("企业商城账单-供应商账单查询, request={}", request);


        return qchjcSupplierAccountingDubboService.list(request);
    }

    @ApiOperation(value = "供应商账单添加备注")
    @PostMapping("/addRemark")
    public R<String> remark(@RequestBody @Validated RemarkParam param, HttpServletRequest request) {
        String token = request.getHeader("token");
        log.info("采购单位账单添加备注，id={},remark={}", param.getId(),param.getRemark());
        return qchjcSupplierAccountingDubboService.remark(param.getId(),param.getRemark(),token);
    }

    @ApiOperation(value = "根据id查询供应商账单详情")
    @PostMapping("/{id}")
    public R<QchjcAccountingUnifiedSupplierVo> get(@Validated @PathVariable Long id) {
        log.info("根据id查询供应商账单详情，id={}", id);
        return qchjcSupplierAccountingDubboService.get(id);
    }

    @ApiOperation(value = "查询集采供应商下拉列表")
    @PostMapping("/getSupplierList")
    public R<List<UnifiedSupplierVo>> getSupplierList() {
        return qchjcSupplierAccountingDubboService.getSupplierList();
    }
}
