package com.sckw.contract.controller;

import com.sckw.contract.model.vo.req.*;
import com.sckw.contract.service.operateService.KwcContractLogisticsService;
import com.sckw.core.model.enums.EntTypeEnum;
import com.sckw.core.web.constant.HttpStatus;
import com.sckw.core.web.response.HttpResult;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author czh
 * @desc 托运合同
 * @date 2023/7/13
 */
@RestController
@RequestMapping("kwcChecked")
public class KwcCheckedController {

    @Autowired
    private KwcContractLogisticsService kwcContractLogisticsService;

    /**
     * @desc 分页查询
     * @param reqVo 分页入参
     * @author czh
     * @date 2023/7/17
     * @return HttpResult
     */
    @RequestMapping("queryListByPage")
    public HttpResult queryListByPage(@RequestBody QueryListReqVo reqVo) {
        reqVo.setEntType(EntTypeEnum.LOGISTICS3.getCode());
        return HttpResult.ok(kwcContractLogisticsService.queryListByPage(reqVo));
    }

    /**
     * @param reqVo 新增入参
     * @return HttpResult
     * @desc 新增托运合同
     * @author czh
     * @date 2023/7/13
     */
    @RequestMapping("add")
    public HttpResult addCheckedContract(@RequestBody ContractLogisticsReqVo reqVo) {
        kwcContractLogisticsService.addCheckedContract(reqVo);
        return HttpResult.ok(HttpStatus.MSG_003);
    }

    /**
     * @param reqVo 补充入参
     * @desc: 补充合同
     * @author: czh
     * @date: 2023/7/14
     */
    @PostMapping("supplement")
    public HttpResult supplement(@Valid @RequestBody ContractLogisticsReqVo reqVo) {
        kwcContractLogisticsService.supplement(reqVo);
        return HttpResult.ok(HttpStatus.MSG_003);
    }

    /**
     * @desc: 合同详情
     * @param reqVo id
     * @author: czh
     * @date 2023/7/16
     * @return HttpResult
     */
    @PostMapping("detail")
    public HttpResult detail(@Valid @RequestBody IdReqVo reqVo) {
        return HttpResult.ok(kwcContractLogisticsService.detail(reqVo.getId()));
    }

    /**
     * @desc: 发起签约
     * @param reqVo id
     * @author: czh
     * @date 2023/7/16
     * @return HttpResult
     */
    @PostMapping("submit")
    public HttpResult submit(@Valid @RequestBody ContractLogisticsReqVo reqVo) {
        return HttpResult.ok(kwcContractLogisticsService.submit(reqVo));
    }

    /**
     * @desc: 修改草稿
     * @param reqVo id
     * @author: czh
     * @date 2023/7/16
     * @return HttpResult
     */
    @PostMapping("update")
    public HttpResult update(@Valid @RequestBody ContractLogisticsReqVo reqVo) {
        kwcContractLogisticsService.update(reqVo);
        return HttpResult.ok();
    }


    /**
     * @desc: 手动完结
     * @param reqVo ids
     * @author: czh
     * @date 2023/7/16
     * @return HttpResult
     */
    @PostMapping("complete")
    public HttpResult complete(@Valid @RequestBody CompleteReqVo reqVo) {
        kwcContractLogisticsService.complete(reqVo);
        return HttpResult.ok();
    }


    /**
     * @desc: 删除
     * @param reqVo ids
     * @author: czh
     * @date 2023/7/16
     * @return HttpResult
     */
    @PostMapping("delete")
    public HttpResult delete(@Valid @RequestBody IdsReqVo reqVo) {
        kwcContractLogisticsService.delete(reqVo.getIds());
        return HttpResult.ok();
    }


    /**
     * @desc: 导出
     * @param reqVo 查询入参
     * @author: czh
     * @date 2023/7/17
     */
    @PostMapping(value = "export", produces = MediaType.APPLICATION_JSON_VALUE)
    public void export(@Valid @RequestBody QueryListReqVo reqVo, HttpServletResponse response) {
        reqVo.setEntType(EntTypeEnum.LOGISTICS3.getCode());
        kwcContractLogisticsService.export(reqVo, response);
    }


    /**
     * @return HttpResult
     * @desc: 查询当前企业的托运合同
     * @author: czh
     * @date: 2023/7/18
     */
    @PostMapping("queryCurrentEntCheckedContractList")
    public HttpResult queryCurrentEntCheckedContractList() {
        return HttpResult.ok(kwcContractLogisticsService.queryCurrentEntCheckedContractList());
    }

    /**
     * @return HttpResult
     * @desc: 分组查询
     * @author: czh
     * @date: 2023/7/18
     */
    @PostMapping("findListGroup")
    public HttpResult findListGroup(@RequestBody QueryListReqVo reqVo) {
        reqVo.setEntType(EntTypeEnum.LOGISTICS3.getCode());
        return HttpResult.ok(kwcContractLogisticsService.findListGroup(reqVo));
    }


    /**
     * @param reqVo 分页查询
     * @return HttpResult
     * @desc: 运营端查物流合同
     * @author: czh
     * @date: 2023/9/13
     */
    @PostMapping("queryLogisticsByPage")
    public HttpResult queryLogisticsByPage(@RequestBody QueryListReqVo reqVo) {
        return HttpResult.ok(kwcContractLogisticsService.queryLogisticsByPage(reqVo));
    }

    /**
     * @return HttpResult
     * @desc: 分组查询
     * @author: czh
     * @date: 2023/9/13
     */
    @PostMapping("findLogisticsListGroup")
    public HttpResult findLogisticsListGroup(@RequestBody QueryListReqVo reqVo) {
        return HttpResult.ok(kwcContractLogisticsService.findLogisticsListGroup(reqVo));
    }

    /**
     * @param reqVo 查询参数
     * @desc: 运营端查物流合同导出
     * @author: czh
     * @date: 2023/9/13
     */
    @PostMapping(value = "/exportLogisticsList", produces = MediaType.APPLICATION_JSON_VALUE)
    public void exportLogisticsList(@RequestBody QueryListReqVo reqVo, HttpServletResponse response) {
        kwcContractLogisticsService.exportLogisticsList(reqVo, response);
    }


}
