package com.ruoyi.web.controller.portal;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.SysImplementationProgress;
import com.ruoyi.system.domain.SysMilestone;
import com.ruoyi.system.domain.SysProject;
import com.ruoyi.system.domain.SysProjectProgress;
import com.ruoyi.system.domain.SysRealtimeNews;
import com.ruoyi.system.service.ISysImplementationProgressService;
import com.ruoyi.system.service.ISysMilestoneService;
import com.ruoyi.system.service.ISysProjectService;
import com.ruoyi.system.service.ISysProjectProgressService;
import com.ruoyi.system.service.ISysRealtimeNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/portal/progress")
public class PortalProgressController extends BaseController {

    @Autowired
    private ISysProjectService projectService;

    @Autowired
    private ISysProjectProgressService projectProgressService;
    
    @Autowired
    private ISysRealtimeNewsService realtimeNewsService;

    @Autowired
    private ISysImplementationProgressService implementationProgressService;

    @Autowired
    private ISysMilestoneService milestoneService;

    @Anonymous
    @GetMapping("/list")
    public AjaxResult getProgressList() {
        List<SysRealtimeNews> list = realtimeNewsService.selectSysRealtimeNewsList(new SysRealtimeNews());
        return AjaxResult.success(list);
    }

    @GetMapping("/projects")
    public AjaxResult getProjectList() {
        List<SysProject> list = projectService.selectSysProjectList(new SysProject());
        return AjaxResult.success(list);
    }

    @GetMapping("/stats")
    public AjaxResult getProgressStats() {
        Map<String, Object> stats = new HashMap<>();
        stats.put("total", 120);
        stats.put("completed", 85);
        stats.put("ongoing", 28);
        stats.put("planned", 7);
        return AjaxResult.success(stats);
    }

    /**
     * 获取里程碑事件列表（来自管理后台进展情况管理/里程碑事件）
     */
    @Anonymous
    @GetMapping("/milestones")
    public AjaxResult getMilestoneList() {
        SysMilestone query = new SysMilestone();
        query.setStatus("0"); // 只查询正常状态的里程碑
        List<SysMilestone> list = milestoneService.selectSysMilestoneList(query);
        return AjaxResult.success(list);
    }

    /**
     * 获取项目实施进展信息（来自管理后台进展情况管理/项目实施进展）
     */
    @Anonymous
    @GetMapping("/implementation")
    public AjaxResult getImplementationProgress() {
        SysImplementationProgress progress = implementationProgressService.selectSysImplementationProgress();
        return AjaxResult.success(progress);
    }
}
