package com.ruoyi.project.business.controller.board;

import com.ruoyi.common.utils.MessageUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.annotation.DataUpdateCheck;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.business.domain.TcAccount;
import com.ruoyi.project.business.domain.TcAccountForRelated;
import com.ruoyi.project.business.domain.vo.account.AgentAddAccount;
import com.ruoyi.project.business.domain.vo.account.AgentAddProject;
import com.ruoyi.project.business.domain.vo.account.CancelMergeReq;
import com.ruoyi.project.business.domain.vo.selectParam.AccountParam;
import com.ruoyi.project.business.service.ITcAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 客户管理Controller
 *
 * @author ruoyi
 * @date 2024-04-10
 */
@RestController
@RequestMapping("/business/agent4ProjectAndAccount")
public class Agent4ProjectAndAccountController extends BaseController {
    @Resource
    private ITcAccountService tcAccountService;


    /**
     * 代理商新建客户统计（周更新）
     */
    @GetMapping("/listAgentAddAccount")
    public TableDataInfo listAgentAddAccount(AccountParam tcAccount) {
        startPage();
        List<AgentAddAccount> list = tcAccountService.selectAgentAddAccount(tcAccount);
        return getDataTable(list);
    }

    /**
     * 导出代理商新建客户统计（周更新）
     */
    @Log(title = "客户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/exportAgentAddAccount")
    public void exportAgentAddAccount(HttpServletResponse response, AccountParam tcAccount) {
        List<AgentAddAccount> list = tcAccountService.selectAgentAddAccount(tcAccount);
        list.stream()
                .filter(item -> item.getOwnerAgent() == 0)
                .forEach(item -> item.setOwnerAgentName("总部"));
        ExcelUtil<AgentAddAccount> util = new ExcelUtil<AgentAddAccount>(AgentAddAccount.class);
        util.exportExcel(response, list, MessageUtils.message("account.exportSheetName"));
    }


    /**
     * 客户新建项目统计（周更新）
     */
    @GetMapping("/listAgentAddProject")
    public TableDataInfo listAgentAddProject(AccountParam tcAccount) {
        startPage();
        List<AgentAddProject> list = tcAccountService.selectAgentAddProject(tcAccount);
        return getDataTable(list);
    }


    /**
     * 导出客户新建项目统计（周更新）
     */
    @Log(title = "客户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/exportAgentAddProject")
    public void exportAgentAddProject(HttpServletResponse response, AccountParam tcAccount) {
        List<AgentAddProject> list = tcAccountService.selectAgentAddProject(tcAccount);
        list.stream()
                .filter(item -> item.getOwnerAgent() == 0)
                .forEach(item -> item.setOwnerAgentName("总部"));
        ExcelUtil<AgentAddProject> util = new ExcelUtil<AgentAddProject>(AgentAddProject.class);
        util.exportExcel(response, list, MessageUtils.message("account.exportSheetName"));
    }


}
