package com.ruixuan.jinniu.controller;


import com.alibaba.fastjson.JSONObject;
import com.ruixuan.common.core.controller.BaseController;
import com.ruixuan.common.core.domain.AjaxResult;
import com.ruixuan.common.core.page.TableDataInfo;
import com.ruixuan.common.utils.Result;
import com.ruixuan.jinniu.entity.KuaishouProject;
import com.ruixuan.jinniu.service.IKuaishouProjectMemberService;
import com.ruixuan.jinniu.service.IKuaishouProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 项目信息Controller
 *
 * @author ruoyi
 * @date 2023-03-14
 */
@Api(tags = "项目信息Controller")
@RestController
@RequestMapping("/kuaishou/project")
public class KuaishouProjectController extends BaseController {
    @Autowired
    private IKuaishouProjectService KuaishouProjectService;

    @Autowired
    private IKuaishouProjectMemberService kuaishouProjectMemberService;

    /**
     * 项目管理页面
     */
    @ApiOperation(value = "项目管理页面")
    @GetMapping("/list")
    public TableDataInfo list(KuaishouProject kuaishouProject) {
        List<KuaishouProject> list = KuaishouProjectService.selectKuaishouProjectList(kuaishouProject);
        return getDataTable(list);
    }

    /**
     * 我的项目
     */
    @ApiOperation(value = "我的项目")
    @GetMapping("/getMyProjects")
    public TableDataInfo getMyProjects(KuaishouProject kuaishouProject) {
        List<KuaishouProject> list = KuaishouProjectService.getMyProjects(kuaishouProject);
        return getDataTable(list);
    }

    /**
     * 新增项目信息
     */
    @ApiOperation(value = "新增项目信息")
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestBody KuaishouProject kuaishouProject) {
        return toAjax(KuaishouProjectService.insertKuaishouProject(kuaishouProject));
    }

    /**
     * 修改项目信息
     */
    @ApiOperation(value = "修改项目信息")
    @PostMapping(value = "/edit")
    public AjaxResult edit(@RequestBody KuaishouProject kuaishouProject) {
        return toAjax(KuaishouProjectService.updateKuaishouProject(kuaishouProject));
    }

    /**
     * 获取项目信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(KuaishouProjectService.selectKuaishouProjectById(id));
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除")
    @GetMapping(value = "/deleteById")
    public AjaxResult deleteById(@ApiParam("id") @RequestParam(value = "id", required = true) Long id) {
        return AjaxResult.success(KuaishouProjectService.deleteKuaishouProjectById(id));
    }

    /**
     * 查询优化目标
     */
    @ApiOperation(value = "查询优化目标")
    @GetMapping("/getOcpxActionType")
    public Result<Object> getOcpxActionType() {
        return KuaishouProjectService.getOcpxActionType();
    }

    /**
     * 查询项目的参与人员名称
     */
    @ApiOperation(value = "查询项目的参与人员名称")
    @GetMapping("/queryProjectUsers")
    public Result<Object> queryProjectUsers(@ApiParam("项目ID") @RequestParam(value = "projectId", required = true) Long projectId) {
        return kuaishouProjectMemberService.queryProjectUsers(projectId);
    }

    /**
     * 增加参与项目人员
     */
    @ApiOperation(value = "增加参与项目人员")
    @PostMapping("/addProjectUsers")
    public Result<Object> addProjectUsers(@RequestBody JSONObject o) {
        return kuaishouProjectMemberService.addProjectUsers(o);
    }

    /**
     * 删除项目参与人员
     */
    @ApiOperation(value = "删除项目参与人员")
    @PostMapping("/deleteProjectUsers")
    public Result<Object> deleteProjectUsers(@ApiParam("项目ID") @RequestParam(value = "projectId", required = true) Long projectId,
                                             @ApiParam("成员Id") @RequestParam(value = "userId", required = true) Long userId) {
        return kuaishouProjectMemberService.deleteProjectUsers(projectId, userId);
    }

    /**
     * 项目&账户树形关系数据
     */
    @ApiOperation(value = "项目&账户树形关系数据")
    @GetMapping("/getProjectAndAccountByUserId")
    public Result<Object> getProjectAndAccountByUserId(@ApiParam("userId") @RequestParam(value = "userId", required = true) Long userId,
                                                       @ApiParam("mediaCode") @RequestParam(value = "mediaCode", required = false) String mediaCode) {
        return KuaishouProjectService.getProjectAndAccountByUserId(userId, mediaCode);
    }
}