package com.ruoyi.web.controller.shate;

import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain_shate.SeedingSuccessRate;
import com.ruoyi.system.domain_shate.UplodFile;
import com.ruoyi.system.domain_shate.VegetationHealth;
import com.ruoyi.system.domain_shate.WaterFactor;
import com.ruoyi.system.service_shate.ISeedingSuccessService;
import com.ruoyi.system.service_shate.IVegetationHealthServices;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: JinSheng Song
 * @Date: 2022/7/8 10:25
 */
@RestController
@RequestMapping(value = "/api/Vegetation", produces = "application/json;charset=UTF-8")
@Api(tags = "植被健康状况")
public class VegetationHealthController {

    @Resource
    private IVegetationHealthServices VegetationService;
    /**
     * 查询方法
     * @return  实体类
     */
    @ApiOperation(value = "查询方法",httpMethod = "GET")
    @RequestMapping(value = "/SelectVegetation",method = {RequestMethod.GET})
    public AjaxResult SelectVegetation(String zone,String type,String year)
    {
        String name="";
        if (type!=null && type !=""){
            if (type.equals("1")){
                name="Medium%";
            }
            else if(type.equals("2")){
                name="High%";
            }
        }
        List<VegetationHealth> Seeding= VegetationService.sqlSeeding(zone,name,year);
        Double Number=0.0;
        Double Max=0.0;
        for (VegetationHealth ce : Seeding)
        {
            Number =ce.getNormal()+ce.getHealthy()+ce.getNotHealthy();
            if (Max<Number)
            {
                Max=Number;
            }
        }
        for (int i=0;i<Seeding.size();i++)
        {
            Seeding.get(i).setMax(Max);
        }
        return AjaxResult.success(Seeding);
    }


    @RequestMapping(value = "/InsertVegetation",method = {RequestMethod.POST})
    public AjaxResult InsertVegetation(@RequestBody UplodFile uplodFile) {
        List<VegetationHealth> value=uplodFile.getVegetationHealths();
        for (int i=0;i<value.size();i++){
            String year=value.get(i).getImageDate().substring(0,4);
            value.get(i).setYear(year);
            value.get(i).setImageDate(value.get(i).getImageDate().replace("-",""));
//            uplodFile.getVegetationHealths().get(i).
//                    setYear(uplodFile.getVegetationHealths().get(i).getImageDate().substring(0,4));

            Integer Seeding =VegetationService.insertSeeding(value.get(i));
        }
        return AjaxResult.success("成功！");
    }

    @RequestMapping(value = "/SelectYear",method = {RequestMethod.GET})
    public AjaxResult selectYear()
    {
        List<VegetationHealth> Seeding= VegetationService.sqlYear();
        return AjaxResult.success(Seeding);
    }
}
