package com.ruoyi.web.controller.system;

import java.util.List;
import com.ruoyi.system.domain.MaterialStatsDaily;
import com.ruoyi.system.service.IMaterialStatsDailyService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system/material/stats")
public class MaterialStatsDailyController extends BaseController
{
    @Autowired
    private IMaterialStatsDailyService statsService;

    /**
     * 分页查询素材转化统计
     */
    @PostMapping("/list")
    public TableDataInfo list(@RequestParam(value = "appName", required = false) String appName,
                              @RequestParam(value = "appSource", required = false) String appSource,
                              @RequestParam(value = "startDate", required = false) String startDate,
                              @RequestParam(value = "endDate", required = false) String endDate)
    {
        startPage();
        List<MaterialStatsDaily> list = statsService.selectStats(appName, appSource, startDate, endDate);
        for (MaterialStatsDaily item : list) {
            item.setAppSource(mapSource(item.getAppSource()));
        }
        return getDataTable(list);
    }

    private String mapSource(String code) {
        if (code == null || code.trim().isEmpty()) return "未知";
        switch (code.trim()) {
            case "1": return "OPPO";
            case "2": return "vivo";
            case "3": return "华为";
            case "4": return "小米";
            case "5": return "应用宝";
            case "6": return "百度";
            default: return code;
        }
    }
}
