package com.sckw.contract.controller;

import com.sckw.contract.api.model.dto.req.TradeEntListQueryFeignDto;
import com.sckw.contract.api.model.dto.res.TradeEntInfoResVo;
import com.sckw.contract.model.vo.req.ContractDetailReq;
import com.sckw.contract.model.vo.req.LogisticListReq;
import com.sckw.contract.model.vo.req.QueryLogisticListReq;
import com.sckw.contract.model.vo.req.UpdateLogisticsReq;
import com.sckw.contract.model.vo.res.*;
import com.sckw.contract.service.operateService.KwcContractLogisticsService;
import com.sckw.core.web.response.BaseResult;
import com.sckw.core.web.response.result.PageDataResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author :chenXiaoFei
 * @version :1.0
 * @description : 物流合同相关接口
 * @create :2025-11-06 09:34:00
 */
@RestController
@RequestMapping("logisticsContract")
@RequiredArgsConstructor
@Tag(name = "物流合同接口")
public class KwcLogisticsContractController {
    private final KwcContractLogisticsService kwcContractLogisticsService;

    /**
     * @return HttpResult
     * @desc: 分页查询
     * @param: reqVo 分页入参
     * @author: sky
     * @date 2023/7/13
     */
    @PostMapping("/queryListByPage")
    @Operation(summary = "分页查询物流合同")
    public BaseResult<PageDataResult<QueryLogisticListResp>> queryListByPage(@RequestBody QueryLogisticListReq req) {
        return BaseResult.success(kwcContractLogisticsService.queryLogisticsContractListByPage(req));
    }

    @PostMapping("queryTradeEntList")
    public BaseResult<List<TradeEntInfoResVo>> queryTradeEntList(@RequestBody TradeEntListQueryFeignDto queryFeignDto) {
        return BaseResult.success(kwcContractLogisticsService.queryTradeEntList(queryFeignDto));
    }

    /**
     * 新增物流合同
     */
    @Operation(summary = "新增或者修改物流合同")
    @PostMapping("/addOrUpdateLogisticsContract")
    public BaseResult<Boolean> addOrUpdateLogisticsContract(@RequestBody LogisticListReq req) {
        return BaseResult.success(kwcContractLogisticsService.addOrUpdateLogisticsContract(req));
    }

    /**
     * 查询物流合同明细
     */
    @PostMapping("/queryLogisticsContractDetail")
    @Operation(summary = "查询物流合同明细")
    public BaseResult<QueryLogisticDetailResp> queryLogisticsContractDetail(@RequestBody ContractDetailReq req) {
        return BaseResult.success(kwcContractLogisticsService.queryLogisticsContractDetail(req));
    }

    /**
     * 修改合同状态、签约
     */
    @PostMapping("/updateLogistics")
    @Operation(summary = "手动完结")
    public BaseResult<Boolean> updateLogistics(@RequestBody UpdateLogisticsReq req) {
        return BaseResult.success(kwcContractLogisticsService.updateLogistics(req));
    }

    /**
     * 统计物流合同状态
     */
    @PostMapping("/queryLogisticContractStatusCount")
    @Operation(summary = "统计物流合同状态")
    public BaseResult<ContractStatusCountResp> queryLogisticContractStatusCount(@RequestBody QueryLogisticListReq req) {
        return BaseResult.success(kwcContractLogisticsService.queryLogisticContractStatusCount(req));
    }

    /**
     * 查询物流合同明细
     */
    @GetMapping("/queryLogisticsContract")
    @Operation(summary = "查询原矿物流合同")
    @Parameter(name = "keyword", description = "筛选参数")
    public BaseResult<List<LogisticsEntDto>> queryLogisticsContract(@RequestParam(value = "keyword", required = false) String keyword) {
        return BaseResult.success(kwcContractLogisticsService.queryLogisticsContract(keyword));
    }

    /**
     * 查询物流合同明细
     */
    @GetMapping("/queryLogisticsGoods")
    @Operation(summary = "查询物流合同下的商品信息")
    @Parameter(name = "contractId", description = "物流合同id", required = true)
    @Parameter(name = "keyword", description = "筛选参数")
    public BaseResult<List<ContractGoodsVo>> queryLogisticsGoods(@RequestParam("contractId") Long contractId, @RequestParam(value = "keyword",required = false) String keyword) {
        return BaseResult.success(kwcContractLogisticsService.queryLogisticsGoods(contractId, keyword));
    }
}
