package com.ruixuan.live.controller;

import com.alibaba.fastjson.JSONObject;
import com.ruixuan.common.annotation.Log;
import com.ruixuan.common.core.controller.BaseController;
import com.ruixuan.common.core.domain.AjaxResult;
import com.ruixuan.common.core.domain.ResultResponse;
import com.ruixuan.common.core.page.TableDataInfo;
import com.ruixuan.common.enums.BusinessType;
import com.ruixuan.live.entity.KuaishouLiveUserAccount;
import com.ruixuan.live.service.IKuaishouLiveUserAccountService;
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.DeleteMapping;
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 org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 快手直播账户Controller
 *
 * @author ruoyi
 * @date 2022-05-31
 */
@Api(tags = "操盘手——直播账户")
@RestController
@RequestMapping("/live/account")
public class KuaishouLiveUserAccountController extends BaseController {
    @Autowired
    private IKuaishouLiveUserAccountService kuaishouLiveUserAccountService;

    /**
     * 查询快手直播账户列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "操盘手——查询快手直播账户列表")
    public TableDataInfo list(KuaishouLiveUserAccount kuaishouLiveUserAccount) {
        List<KuaishouLiveUserAccount> list = kuaishouLiveUserAccountService.selectKuaishouLiveUserAccountList(kuaishouLiveUserAccount);
        return getDataTable(list);
    }

    /**
     * 查询快手直播账户列表
     */
    @GetMapping("/queryAllList")
    @ApiOperation(value = "账户管理——查询快手直播账户列表")
    public TableDataInfo queryAllList(KuaishouLiveUserAccount kuaishouLiveUserAccount) {
        List<KuaishouLiveUserAccount> list = kuaishouLiveUserAccountService.queryAllList(kuaishouLiveUserAccount);
        return getDataTable(list);
    }

    /**
     * 查询账户关联人员
     */
    @GetMapping("/queryAccountAllUsers")
    @ApiOperation(value = "查询账户关联人员")
    public ResultResponse queryAccountAllUsers(@ApiParam("快手ID") @RequestParam(value = "ksId", required = true) Long ksId,
                                               @ApiParam("账户ID") @RequestParam(value = "accountId", required = true) Long accountId) {
        try {
            return kuaishouLiveUserAccountService.queryAccountAllUsers(ksId, accountId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultResponse.error("查询异常");
    }

    /**
     * 删除账户关联人员
     */
    @GetMapping("/deleteAccountUser")
    @ApiOperation(value = "删除账户关联人员")
    public ResultResponse deleteAccountUser(
            @ApiParam("快手ID") @RequestParam(value = "ksId", required = true) Long ksId,
            @ApiParam("账户ID") @RequestParam(value = "accountId", required = true) Long accountId,
            @ApiParam("角色code") @RequestParam(value = "role", required = true) String role,
            @ApiParam("用户ID") @RequestParam(value = "userId", required = true) Long userId) {
        try {
            return kuaishouLiveUserAccountService.deleteAccountAllUser(ksId, accountId, role, userId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultResponse.error("查询异常");
    }

    /**
     * 查询快手昵称
     */
    @GetMapping("/queryNicknameList")
    @ApiOperation(value = "查询快手昵称集合")
    public TableDataInfo queryNicknameList() {
        // startPage();
        List<JSONObject> list = kuaishouLiveUserAccountService.queryNicknameList();
        return getDataTable(list);
    }

    /**
     * 查询快手账户集合
     */
    @GetMapping("/queryAccountListByKsId")
    @ApiOperation(value = "查询快手账户集合")
    public TableDataInfo queryAccountListByKsId(@ApiParam("快手ID") @RequestParam(value = "ksId", required = true) Long ksId) {
        // startPage();
        List<JSONObject> list = kuaishouLiveUserAccountService.queryAccountListByKsId(ksId);
        return getDataTable(list);
    }

    /**
     * 查询运营/销售
     */
    @GetMapping("/queryRoles")
    @ApiOperation(value = "查询(1-运营/2-销售/3-设计)人员集")
    public ResultResponse queryRoles(@ApiParam("类型：1-运营/2-销售/3-设计") @RequestParam(value = "type", required = false) String type) {
        return kuaishouLiveUserAccountService.queryRoles(type);
    }

    /**
     * 新增快手直播账户
     */
    @PostMapping(value = "/add")
    @ApiOperation(value = "新增快手直播账户")
    public ResultResponse add(@RequestBody KuaishouLiveUserAccount kuaishouLiveUserAccount) {
        return kuaishouLiveUserAccountService.insertKuaishouLiveUserAccount(kuaishouLiveUserAccount);
    }

    /**
     * 通过excel导入账户
     */
    @PostMapping(value = "/insertByExcel")
    @ApiOperation(value = "通过excel导入账户")
    public ResultResponse insertByExcel(@ApiParam("excel文档") @RequestParam(value = "file", required = false) MultipartFile file,
                                        @ApiParam("创建人ID") @RequestParam(value = "createrId", required = false) Long createrId
    ) {
        return kuaishouLiveUserAccountService.insertByExcel(file, createrId);
    }

    /**
     * 修改快手直播账户
     */
    @PostMapping(value = "/edit")
    @ApiOperation(value = "修改快手直播账户")
    public ResultResponse edit(@RequestBody KuaishouLiveUserAccount kuaishouLiveUserAccount) {
        return kuaishouLiveUserAccountService.updateKuaishouLiveUserAccount(kuaishouLiveUserAccount);
    }

    /**
     * 获取快手直播账户详细信息
     */
    @GetMapping(value = "getById")
    @ApiOperation(value = "获取快手直播账户详细信息")
    public AjaxResult getInfo(@ApiParam("账户id") @RequestParam(value = "id", required = true) String id) {
        return AjaxResult.success(kuaishouLiveUserAccountService.selectKuaishouLiveUserAccountById(id));
    }

    /**
     * 删除快手直播账户
     */
    @Log(title = "快手直播账户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(kuaishouLiveUserAccountService.deleteKuaishouLiveUserAccountByIds(ids));
    }
}
