package com.sckw.contract.controller;


import com.github.pagehelper.PageInfo;
import com.sckw.contract.model.dto.req.*;
import com.sckw.contract.model.vo.res.LogisticsScoreDetailResVo;
import com.sckw.contract.model.vo.res.LogisticsScoreResVo;
import com.sckw.core.web.context.LoginUserHolder;
import com.sckw.core.web.controller.BaseController;
import com.sckw.core.web.page.PageDomain;
import com.sckw.core.web.page.TableSupport;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.sckw.contract.service.IKwcContractLogisticsScoreService;

/**
 * 物流企业评分Controller
 * 
 * @author tangyishan
 * @date 2025-12-05
 */
@Tag(name = "物流企业评分接口")
@RestController
@RequestMapping("/logisticsScore")
public class KwcContractLogisticsScoreController extends BaseController
{
    @Autowired
    private IKwcContractLogisticsScoreService kwcContractLogisticsScoreService;

    /**
     * 查询物流企业评分列表
     */
    @PostMapping("/queryListByPage")
    @Operation(summary = "分页查询供应商物流企业评分",parameters =  {
            @Parameter(name = "pageNum", description = "页码"),
            @Parameter(name = "pageSize", description = "每页数量")
    })
    public BaseResult<PageDataResult<LogisticsScoreResVo>> queryListByPage(@RequestBody @Validated LogisticsScoreQueryDto query)
    {
        query.setProviderEntId(LoginUserHolder.getEntId());
        PageInfo<LogisticsScoreResVo> list = kwcContractLogisticsScoreService.selectLogisticsScoreWithPendingSocreList(query);
        return BaseResult.success(getDataTable(list));
    }

    /**
     * 查询物流企业评分明细列表
     */
    @PostMapping("/queryDetailListByPage")
    @Operation(summary = "分页查指定评分的明细记录",parameters =  {
            @Parameter(name = "pageNum", description = "页码"),
            @Parameter(name = "pageSize", description = "每页数量")
    })
    public BaseResult<PageDataResult<LogisticsScoreDetailResVo>> queryDetailListByPage(@Validated @RequestBody LogisticsScoreDetailQueryDto detailReqDto)
    {
        detailReqDto.setProviderEntId(LoginUserHolder.getEntId());
        PageInfo<LogisticsScoreDetailResVo> list = kwcContractLogisticsScoreService.selectKwcContractLogisticsScoreDetailList(detailReqDto);
        return BaseResult.success(getDataTable(list));
    }

    /**
     * 查询物流企业待审评分明细
     */
    @GetMapping("/queryLogisticsPendingScore")
    @Operation(summary = "查询物流企业待审评分明细")
    public BaseResult<LogisticsScoreDetailResVo> queryLogisticsPendingScore(@RequestParam Long scoreId)
    {
        LogisticsScoreDetailResVo logisticsScoreDetailResVo = kwcContractLogisticsScoreService.selectLogisticsPendingScoreDetail(scoreId,LoginUserHolder.getEntId());
        return BaseResult.success(logisticsScoreDetailResVo);
    }

    /**
     * 用户修改物流企业评分
     */
    @PostMapping("/updateLogisticsScore")
    @Operation(summary = "用户修改物流企业评分")
    public BaseResult<Boolean> updateLogisticsScore(@Validated @RequestBody LogisticsScoreDetailAddDto detailDto) {
        return BaseResult.success(kwcContractLogisticsScoreService.insertLogisticsScoreDetailByUser(detailDto,LoginUserHolder.getEntId()));
    }


    /**
     * 审核物流企业评分
     */
    @PostMapping("/approvalLogisticsScore")
    @Operation(summary = "审核物流企业评分")
    public BaseResult<Boolean> approvalLogisticsScore(@Validated @RequestBody LogisticsScoreApprovalDto approvalDto) {
        kwcContractLogisticsScoreService.approvalLogisticsScoreDetail(approvalDto,LoginUserHolder.getEntId());
        return BaseResult.success();
    }


    /**
     * 重置物流企业评分
     */
    @PostMapping("/resetLogisticsScore")
    @Operation(summary = "重置物流企业评分")
    public BaseResult<Boolean> resetLogisticsScore(@RequestParam Long scoreId) {
        kwcContractLogisticsScoreService.resetLogisticsScore(scoreId,LoginUserHolder.getEntId());
        return BaseResult.success();
    }
}
