package com.ruixuan.jinniu.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

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.page.TableDataInfo;
import com.ruixuan.common.enums.BusinessType;
import com.ruixuan.common.utils.Check;
import com.ruixuan.common.utils.poi.ExcelUtil;
import com.ruixuan.jinniu.entity.KuaishouAgentAccountList;
import com.ruixuan.jinniu.service.IKuaishouAgentAccountListService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 【请填写功能名称】Controller
 *
 * @author ruoyi
 * @date 2023-03-15
 */
@RestController
@RequestMapping("/agent/account")
public class KuaishouAgentAccountListController extends BaseController {
    @Autowired
    private IKuaishouAgentAccountListService kuaishouAgentAccountListService;


    @GetMapping("/syncAccounts")
    public void syncAccounts() {
        List<String> cookies = kuaishouAgentAccountListService.getCookie();
        if (!Check.isNull(cookies)) {
            for (int i = 0; i < cookies.size(); i++) {
                String cookie = cookies.get(i);
                kuaishouAgentAccountListService.kuaishouAgentAccountListService(cookie,1, 500, null, null);

            }

        }


    }


    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:list:list')")
    @GetMapping("/list")
    public TableDataInfo list(KuaishouAgentAccountList kuaishouAgentAccountList) {
        startPage();
        List<KuaishouAgentAccountList> list = kuaishouAgentAccountListService.selectKuaishouAgentAccountListList(kuaishouAgentAccountList);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:list:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KuaishouAgentAccountList kuaishouAgentAccountList) {
        List<KuaishouAgentAccountList> list = kuaishouAgentAccountListService.selectKuaishouAgentAccountListList(kuaishouAgentAccountList);
        ExcelUtil<KuaishouAgentAccountList> util = new ExcelUtil<KuaishouAgentAccountList>(KuaishouAgentAccountList.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:list:query')")
    @GetMapping(value = "/{accountId}")
    public AjaxResult getInfo(@PathVariable("accountId") Long accountId) {
        return AjaxResult.success(kuaishouAgentAccountListService.selectKuaishouAgentAccountListByAccountId(accountId));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:list:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KuaishouAgentAccountList kuaishouAgentAccountList) {
        return toAjax(kuaishouAgentAccountListService.insertKuaishouAgentAccountList(kuaishouAgentAccountList));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:list:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KuaishouAgentAccountList kuaishouAgentAccountList) {
        return toAjax(kuaishouAgentAccountListService.updateKuaishouAgentAccountList(kuaishouAgentAccountList));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:list:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{accountIds}")
    public AjaxResult remove(@PathVariable Long[] accountIds) {
        return toAjax(kuaishouAgentAccountListService.deleteKuaishouAgentAccountListByAccountIds(accountIds));
    }
}

