package com.sckw.manage.controller;

import com.sckw.core.model.enums.CooperateStatusEnum;
import com.sckw.core.web.constant.HttpStatus;
import com.sckw.core.web.response.HttpResult;
import com.sckw.manage.model.vo.req.*;
import com.sckw.manage.service.KwmCooperateManageService;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
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/10
 */
@RestController
@RequestMapping("/cooperateManage")
public class KwmCooperateManageController {

    @Autowired
    private KwmCooperateManageService kwmCooperateManageService;

    /**
     * @param reqVo 分页入参
     * @return HttpResult
     * @desc: 查询合作企业列表
     * @author: czh
     * @date: 2023/7/10
     */
    @PostMapping("/queryByPage")
    public HttpResult queryByPage(@Valid @RequestBody CooperateManageQueryReqVo reqVo) {
        return HttpResult.ok(kwmCooperateManageService.queryByPage(reqVo));
    }

    /**
     * @param reqVo 详情入参
     * @return HttpResult
     * @desc: 查询详情
     * @author: czh
     * @date: 2023/7/10
     */
    @PostMapping("queryDetail")
    public HttpResult queryDetail(@Valid @RequestBody QueryDetailReqVo reqVo) {
        return HttpResult.ok(kwmCooperateManageService.queryDetail(reqVo.getEntId()));
    }

    /**
     * @param reqVo 绑定入参
     * @return HttpResult
     * @desc: 设置客户经理
     * @author: czh
     * @date: 2023/7/10
     */
    @PostMapping("bindManager")
    public HttpResult bindManager(@Valid @RequestBody BindManagerReqVo reqVo) {
        kwmCooperateManageService.bindManager(reqVo);
        return HttpResult.ok(HttpStatus.MSG_010);
    }

    /**
     * @param reqVo ids
     * @return HttpResult
     * @desc: 解除合作
     * @author: czh
     * @date: 2023/7/11
     */
    @PostMapping("dissolve")
    public HttpResult dissolve(@Valid @RequestBody IdsReqVo reqVo) {
        kwmCooperateManageService.dissolve(reqVo.getIds(), CooperateStatusEnum.PASS.getCode());
        return HttpResult.ok(HttpStatus.MSG_023);
    }

    /**
     * @param reqVo ids
     * @return HttpResult
     * @desc: 恢复合作
     * @author: czh
     * @date: 2023/7/11
     */
    @PostMapping("restore")
    public HttpResult restore(@Valid @RequestBody IdsReqVo reqVo) {
        kwmCooperateManageService.restore(reqVo.getIds(), CooperateStatusEnum.OK.getCode());
        return HttpResult.ok(HttpStatus.MSG_005);
    }


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

    /**
     * @param reqVo 查询入参
     * @desc: 导出
     * @author: czh
     * @date: 2023/7/11
     */
    @PostMapping(value = "export", produces = MediaType.APPLICATION_JSON_VALUE)
    public void export(@Valid @RequestBody CooperateManageQueryReqVo reqVo, HttpServletResponse response) {
        kwmCooperateManageService.export(reqVo, response);
    }

    /**
     * @param reqVo 查询入参
     * @return HttpResult
     * @desc: 分组查询
     * @author: czh
     * @date: 2023/7/17
     */
    @PostMapping("/findListGroup")
    public HttpResult findListGroup(@Valid @RequestBody CooperateManageQueryReqVo reqVo) {
        return HttpResult.ok(kwmCooperateManageService.findListGroup(reqVo));
    }

    /**
     * @param reqVo 企业id
     * @return HttpResult
     * @desc: 查询企业的合作单位
     * @author: czh
     * @date: 2023/7/22
     */
    @PostMapping("findEntCooperate")
    public HttpResult findEntCooperate(@Valid @RequestBody FindEntCooperateReqVo reqVo) {
        return HttpResult.ok(kwmCooperateManageService.findEntCooperate(reqVo));
    }


    /**
     * @param reqVo 企业id
     * @return HttpResult
     * @desc: 根据企业查合作信息
     * @author: czh
     * @date: 2023/8/1
     */
    @PostMapping("findCooperateByEnt")
    public HttpResult findCooperateByEnt(@Valid @RequestBody FindCooperateByEntReqVo reqVo) {
        return HttpResult.ok(kwmCooperateManageService.findCooperateByEnt(reqVo));
    }

    /**
     * @param reqVo 企业id
     * @return HttpResult
     * @desc: 查询对方企业的合作单位有哪些是我方的
     * @author: czh
     * @date: 2023/7/22
     */
    @PostMapping("findTargetEntCooperateInOur")
    public HttpResult findTargetEntCooperateInOur(@Valid @RequestBody FindCooperateByEntReqVo reqVo) {
        return HttpResult.ok(kwmCooperateManageService.findTargetEntCooperateInOur(reqVo));
    }

    /**
     * @param reqVo 分页入参
     * @return HttpResult
     * @desc: 运营端查合作信息
     * @author: czh
     * @date: 2023/9/15
     */
    @PostMapping("queryAllCooperateInfoByPage")
    public HttpResult queryAllCooperateInfoByPage(@RequestBody CooperateManageQueryReqVo reqVo) {
        return HttpResult.ok(kwmCooperateManageService.queryAllCooperateInfoByPage(reqVo));
    }

    /**
     * @param reqVo 查询入参
     * @desc: 导出
     * @author: czh
     * @date: 2023/7/11
     */
    @PostMapping(value = "exportAllCooperateInfo", produces = MediaType.APPLICATION_JSON_VALUE)
    public void exportAllCooperateInfo(@RequestBody CooperateManageQueryReqVo reqVo, HttpServletResponse response) {
        kwmCooperateManageService.exportAllCooperateInfo(reqVo, response);
    }

}
