package com.dsk.cscec.controller;


import com.dsk.common.core.controller.BaseController;
import com.dsk.common.core.domain.PageQuery;
import com.dsk.common.core.domain.R;
import com.dsk.common.core.page.TableDataInfo;
import com.dsk.cscec.domain.AdvisoryBodyCustomForm;
import com.dsk.cscec.domain.bo.*;
import com.dsk.cscec.domain.vo.*;
import com.dsk.cscec.service.AdvisoryBodyCustomFormService;
import com.dsk.cscec.service.AdvisoryBodyProjectService;
import com.dsk.cscec.service.AdvisoryBodyService;
import com.dsk.cscec.service.IDProjectService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * 咨询机构管理控制层
 *
 * @author sxk
 * @since 2023-12-10 15:34:46
 */
@Validated
@RestController
@RequestMapping("advisory/body")
public class AdvisoryBodyManageController extends BaseController {
    @Resource
    private IDProjectService baseService;
    @Resource
    private AdvisoryBodyService advisoryBodyService;
    @Resource
    private AdvisoryBodyProjectService advisoryBodyProjectService;
    @Resource
    private AdvisoryBodyCustomFormService advisoryBodyCustomFormService;

    /**
     * 获取所有项目列表数据
     */
    @GetMapping("/getProjectList")
    public TableDataInfo<ProjectSearchVo> getProjectList(ProjectSearchBo projectSearchBo, PageQuery pageQuery) {
        return baseService.queryProjectList(projectSearchBo, pageQuery);
    }

    /**
     * 获取所有企业列表(咨询机构)数据
     */
    @GetMapping("/getAdvisoryBodyList")
    public TableDataInfo<AdvisoryBodySearchVo> getAdvisoryBodyList(AdvisoryBodySearchBo advisoryBodySearchBo, PageQuery pageQuery) {
        return advisoryBodyService.queryAdvisoryBodyList(advisoryBodySearchBo, pageQuery);
    }

    /**
     * 获取合作项目明细
     */
    @GetMapping("/getCooperateProjectDetailList")
    public TableDataInfo<CooperateProjectDetailSearchVo> getCooperateProjectDetailList(CooperateProjectDetailSearchBo cooperateProjectDetailSearchBo, PageQuery pageQuery) {
        return baseService.queryCooperateProjectDetailList(cooperateProjectDetailSearchBo, pageQuery);
    }

    /**
     * 获取项目详情
     */
    @GetMapping("/getProjectDetail")
    public R<ProjectDetailVo> getProjectDetail(ProjectDetailBo projectDetailBo) {
        return R.ok(baseService.queryProjectDetail(projectDetailBo));
    }

    /**
     * 校验咨询机构是否存在
     */
    @GetMapping("/checkAdvisoryBodyExist")
    public R<AdvisoryBodyExistVo> checkAdvisoryBodyExist(@NotBlank(message = "咨询机构名称不能为空") String advisoryBodyName) {
        return R.ok(advisoryBodyService.checkAdvisoryBodyExist(advisoryBodyName));
    }

    /**
     * 新增咨询机构
     */
    @PostMapping("/addAdvisoryBody")
    public R<Void> addAdvisoryBody(AddAdvisoryBodyBo addAdvisoryBodyBo) {
        return toAjax(advisoryBodyService.addAdvisoryBody(addAdvisoryBodyBo));
    }

    /**
     * 获取咨询机构自定义表单
     */
    @GetMapping("/getAdvisoryBodyCustomForm/{projectKey}")
    public R<AdvisoryBodyCustomForm> getAdvisoryBodyCustomForm(@NotNull(message = "项目主键不能为空") @PathVariable Long projectKey) {
        return R.ok(advisoryBodyCustomFormService.getById(projectKey));
    }

    /**
     * 新增咨询机构自定义表单
     */
    @PostMapping("/addAdvisoryBodyCustomForm")
    public R<Void> addAdvisoryBodyCustomForm(AdvisoryBodyCustomForm advisoryBodyCustomForm) {
        return toAjax(advisoryBodyCustomFormService.save(advisoryBodyCustomForm));
    }

    /**
     * 更新咨询机构自定义表单
     */
    @PutMapping("/updateAdvisoryBodyCustomForm")
    public R<Void> updateAdvisoryBodyCustomForm(AdvisoryBodyCustomForm advisoryBodyCustomForm) {
        return toAjax(advisoryBodyCustomFormService.updateById(advisoryBodyCustomForm));
    }
}