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

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.TcProject;
import com.ruoyi.project.business.domain.vo.board.BarChartVo;
import com.ruoyi.project.business.domain.vo.board.ProjectFollowReq;
import com.ruoyi.project.business.service.ITcAccountService;
import com.ruoyi.project.business.service.ITcLeadService;
import com.ruoyi.project.business.service.ITcProjectService;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.List;


/**
 * @author fangk
 * @date 2024/4/25
 * @desc BoardController
 */
@RequestMapping("/board")
@RestController
@RequiredArgsConstructor
public class BoardController extends BaseController {

    private final ITcLeadService tcLeadService;

    private final ITcAccountService tcAccountService;
    
    private final ITcProjectService tcProjectService;

    /**
     * 近半年内线索数量
     */
    @GetMapping("/leadCountStat")
    public AjaxResult getLeadCountStat(
            @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate,
            @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate,
            String statMode) {
        BarChartVo vo = tcLeadService.getLeadCountStat(startDate, endDate, statMode);
        return AjaxResult.success(vo);
    }

    /**
     * 近半年内客户数量
     */
    //@GetMapping("/customerCountStat")
    //public AjaxResult getCustomerCountStat(List<LocalDate> leadDateRange) {
    //    BarChartVo vo = tcAccountService.getCustomerCountStat();
    //    return AjaxResult.success(vo);
    //}
    @GetMapping("/customerCountStat")
    public AjaxResult getCustomerCountStat( @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate,
                                            @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate,
                                            String statMode) {
        BarChartVo vo = tcAccountService.getCustomerCountStat(startDate, endDate, statMode);
        return AjaxResult.success(vo);
    }

    /**
     * 项目跟进记录统计
     */
    @GetMapping("/getCountAndPieData")
    public AjaxResult getCountAndPieData(ProjectFollowReq req) {
        //return AjaxResult.success(tcProjectService.getCountAndPieData(req));
        return null;
    }

    ////getUnFollowedList
    //@GetMapping("/getUnFollowedList")
    //public AjaxResult getUnFollowedList() {
    //    return AjaxResult.success(tcProjectService.getUnFollowedList());
    //}

    /**
     *  查询 未跟进 项目列表 分页
     * @param unfollowedMode    ：查询模式：1：最近一周未跟进；2：最近一月未跟进；3：最近半年未跟进
     * @return
     */
    @GetMapping("/getUnFollowedList")
    public TableDataInfo getUnFollowedList(String unfollowedMode) {
        startPage();
        List<TcProject> list = tcProjectService.getUnFollowedList(unfollowedMode);
        return getDataTable(list);
    }

}