package com.project.zcustom.controller.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.project.zcustom.controller.core.AjaxResult;
import com.project.zcustom.controller.core.BaseController;
import com.project.zcustom.controller.core.StringUtils;
import com.project.zcustom.domain.smart.PlatGreenSmart;
import com.project.zcustom.service.smart.*;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 绿智食堂Controller
 *
 * @author change
 * @date 2024-10-21
 */
@RestController
@RequestMapping("/large/smart")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class PlatGreenSmartController extends BaseController {

    private final IPlatGreenSmartService platGreenSmartService;
    private final IPlatGreenSmartOtherService iPlatGreenSmartOtherService;
    private final IPlatGreenSmartEnergyService iPlatGreenSmartEnergyService;
    private final IPlatGreenSmartRankService iPlatGreenSmartRankService;
    private final IPlatGreenSmartSafetyService iPlatGreenSmartSafetyService;
    private final IPlatGreenFoodsService iPlatGreenFoodsService;

    @RequestMapping("/getCanteenData")
    public AjaxResult getCanteenData(@RequestParam String appOrg) {
        return AjaxResult.success("查询成功", platGreenSmartService.getCanteenData(appOrg));
    }

    @RequestMapping("/getSafetyData")
    public AjaxResult getSafetyData(@RequestParam String appOrg) {
        return AjaxResult.success("查询成功", iPlatGreenSmartSafetyService.getSafetyData(appOrg));
    }

    @RequestMapping("/getCanteenNameList")
    public AjaxResult getCanteenNameList(@RequestParam String appOrg) {
        QueryWrapper<PlatGreenSmart> queryWrapper = new QueryWrapper<>();
        List<PlatGreenSmart> smartList = new ArrayList<>();
        if(Objects.equals(appOrg,"0000")){
            queryWrapper.select("canteen_num").ne("app_org","10001").groupBy("canteen_num").last("limit 3");
            smartList = platGreenSmartService.list(queryWrapper);
            PlatGreenSmart smartInfo = platGreenSmartService.getOne((new QueryWrapper<PlatGreenSmart>()).eq("app_org","10001").select("canteen_num").last("limit 1"));
            if(StringUtils.isNotNull(smartInfo)){
                smartList.add(0,smartInfo);
            }
        }else{
            queryWrapper.select("canteen_num").eq("app_org", appOrg).groupBy("canteen_num").last("limit 4");
            smartList = platGreenSmartService.list(queryWrapper);
        }
        return AjaxResult.success("查询成功", smartList);
    }

    @RequestMapping("/getCanteenScoreData")
    public AjaxResult getCanteenScoreData(@RequestParam String appOrg,@RequestParam String canteenName) {
        return AjaxResult.success("查询成功", platGreenSmartService.getCanteenScoreData(appOrg, canteenName));
    }

    @RequestMapping("/getPowerData")
    public AjaxResult getPowerData(@RequestParam String appOrg) {
        return AjaxResult.success("查询成功", iPlatGreenSmartEnergyService.getPowerData(appOrg));
    }

    @RequestMapping("/getFoodRankData")
    public AjaxResult getFoodRankData(@RequestParam String appOrg) {
        return AjaxResult.success("查询成功", iPlatGreenSmartRankService.getRankData(appOrg));
    }

    @RequestMapping("/getCanteenDegreeData")
    public AjaxResult getCanteenDegreeData(@RequestParam String appOrg) {
        return AjaxResult.success("查询成功", platGreenSmartService.getCanteenDegreeData(appOrg));
    }

    @RequestMapping("/getCanteenTotalRank")
    public AjaxResult getCanteenTotalRank(@RequestParam String appOrg) {
        return AjaxResult.success("查询成功", platGreenSmartService.getCanteenTotalRank(appOrg));
    }

    @RequestMapping("/geParticipateData")
    public AjaxResult geParticipateData(@RequestParam String appOrg) {
        return AjaxResult.success("查询成功", iPlatGreenSmartOtherService.geParticipateData(appOrg));
    }

    @RequestMapping("/getDiningPieData")
    public AjaxResult getDiningPieData(@RequestParam String appOrg) {
        return AjaxResult.success("查询成功", iPlatGreenSmartOtherService.getDiningPieData(appOrg));
    }

    @RequestMapping("/getQualificationData")
    public AjaxResult getLicenceData(@RequestParam String appOrg,@RequestParam String canteenName) {
        return AjaxResult.success("查询成功", platGreenSmartService.getQualificationData(appOrg, canteenName));
    }

    @RequestMapping("/getSmartCanteenPieData")
    public AjaxResult getSmartCanteenPieData(@RequestParam String appOrg) {
        return AjaxResult.success("查询成功", iPlatGreenSmartOtherService.getSmartCanteenPieData(appOrg));
    }

    @RequestMapping("/getEmployeePieData")
    public AjaxResult getEmployeePieData(@RequestParam String appOrg) {
        return AjaxResult.success("查询成功", iPlatGreenSmartOtherService.getEmployeePieData(appOrg));
    }

    @RequestMapping("/getFoodData")
    public AjaxResult getFoodData(@RequestParam String appOrg) {
        return AjaxResult.success("查询成功", iPlatGreenSmartOtherService.getFoodData(appOrg));
    }

    @RequestMapping("/getOtherData")
    public AjaxResult getOtherData(@RequestParam String appOrg) {
        return AjaxResult.success("查询成功", iPlatGreenSmartOtherService.getOtherData(appOrg));
    }

    @RequestMapping("/getElectronicVouchersData")
    public AjaxResult getElectronicVouchersData(@RequestParam String appOrg) {
        return AjaxResult.success("查询成功", iPlatGreenSmartOtherService.getElectronicVouchersData(appOrg));
    }

    @RequestMapping("/getFoodsList")
    public AjaxResult getFoodsList(@RequestParam String appOrg) {
        return AjaxResult.success("查询成功", iPlatGreenFoodsService.getPlatGreenFoodsByField("app_org",appOrg));
    }

}
