package com.ruoyi.tjfx.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import com.ruoyi.tjfx.entity.TjfxAnalysisDataDTO;
import com.ruoyi.tjfx.service.TjfxAnalysisDataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

@SaIgnore
@Slf4j
@RestController
@RequestMapping("/tjfx/analysis-data")
public class TjfxAnalysisDataController {
    @Autowired
    private TjfxAnalysisDataService tjfxAnalysisDataService;


    //查看展示所有数据结合
    @SaIgnore
    @GetMapping("/product-analysis")
    public List<Map<String, Object>> getProductAnalysisData(
        @RequestParam String startDate,
        @RequestParam String endDate,
        @RequestParam(required = false) String category

    ) throws Exception {
        TjfxAnalysisDataDTO tjfxAnalysisDataDTO = new TjfxAnalysisDataDTO();
        tjfxAnalysisDataDTO.setStartDate(startDate);
        tjfxAnalysisDataDTO.setEndDate(endDate);
        tjfxAnalysisDataDTO.setCategory(category);

        return tjfxAnalysisDataService.selectByProductCode(tjfxAnalysisDataDTO);
    }


    //查询数据集合，按产品编号展示
    @SaIgnore
    @GetMapping("/filter-options")
    public Map<String, List<String>> getFilterOptions(
        @RequestParam String startDate,
        @RequestParam String endDate,
        @RequestParam(required = false) String category
    ) throws Exception {
        TjfxAnalysisDataDTO tjfxAnalysisDataDTO = new TjfxAnalysisDataDTO();
        tjfxAnalysisDataDTO.setStartDate(startDate);
        tjfxAnalysisDataDTO.setEndDate(endDate);
        tjfxAnalysisDataDTO.setCategory(category);

        return tjfxAnalysisDataService.select(tjfxAnalysisDataDTO);
    }

    //查看根据月份分组进行查询，可以支持多选值的情况进行查询
    @SaIgnore
    @GetMapping("/monthly-analysis")
    public List<Map<String, Object>> getMonthlyAnalysisData(
        @RequestParam String startDate,
        @RequestParam String endDate,
        @RequestParam(required = false) String categorySpecs,
        @RequestParam(required = false) String category,
        @RequestParam(required = false) String productCode,
        @RequestParam(required = false) String customerName,
        @RequestParam(required = false) String brand,
        @RequestParam(required = false) String shopName
    ) throws Exception {
        TjfxAnalysisDataDTO tjfxAnalysisDataDTO = new TjfxAnalysisDataDTO();
        tjfxAnalysisDataDTO.setStartDate(startDate);
        tjfxAnalysisDataDTO.setEndDate(endDate);
        tjfxAnalysisDataDTO.setCategorySpecs(categorySpecs);
        tjfxAnalysisDataDTO.setCategory(category);
        tjfxAnalysisDataDTO.setProductCode(productCode);
        tjfxAnalysisDataDTO.setCustomerName(customerName);
        tjfxAnalysisDataDTO.setBrand(brand);
        tjfxAnalysisDataDTO.setShopName(shopName);
        return tjfxAnalysisDataService.selectMonth(tjfxAnalysisDataDTO);
    }


  //查看，按品牌，客户名称，产品编号分组查询对应的所有分类规格
    @SaIgnore
    @GetMapping("/comprehensive-analysis")
    public Map<String, Object> getComprehensiveAnalysisData(
        @RequestParam String startDate,
        @RequestParam String endDate,
        @RequestParam(required = false) String  categorySpecs,
        @RequestParam(required = false) String category,
        @RequestParam(required = false) String productCode,
        @RequestParam(required = false) String customerName,
        @RequestParam(required = false) String brand,
        @RequestParam(required = false) String shopName
    ) throws Exception {
        TjfxAnalysisDataDTO tjfxAnalysisDataDTO = new TjfxAnalysisDataDTO();
        tjfxAnalysisDataDTO.setStartDate(startDate);
        tjfxAnalysisDataDTO.setEndDate(endDate);
        tjfxAnalysisDataDTO.setCategorySpecs(categorySpecs);
        tjfxAnalysisDataDTO.setCategory(category);
        tjfxAnalysisDataDTO.setProductCode(productCode);
        tjfxAnalysisDataDTO.setCustomerName(customerName);
        tjfxAnalysisDataDTO.setBrand(brand);
        tjfxAnalysisDataDTO.setShopName(shopName);
        return tjfxAnalysisDataService.selectByProductAndShopAndSpecification(tjfxAnalysisDataDTO);
    }


}
