package com.ruoyi.web.controller.shate;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain_shate.LandUse;
import com.ruoyi.system.domain_shate.PlantingSuitability;
import com.ruoyi.system.domain_shate.UplodFile;
import com.ruoyi.system.domain_shate.VegetationHealth;
import com.ruoyi.system.service_shate.ILandUseServices;
import com.ruoyi.system.service_shate.IPlantingSuitabilityService;
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 11:04
 */

@RestController
@RequestMapping(value = "/api/Planting", produces = "application/json;charset=UTF-8")
@Api(tags = "种植适宜性")
public class PlantingSuitabilityController
{
    @Resource
    private IPlantingSuitabilityService Service;
    /**
     * 查询方法
     * @return  实体类
     */
    @ApiOperation(value = "查询方法",httpMethod = "GET")
    @RequestMapping(value = "/SelectSeeding",method = {RequestMethod.GET})
    public AjaxResult SelectSeeding(String zone)
    {
        List<PlantingSuitability> Seeding= Service.sqlSeeding(zone);
        Double Number=0.0;
        Double Max=0.0;
        for (PlantingSuitability ce : Seeding)
        {
            Number =ce.getVerySuitable()+ce.getSuitable()+ce.getNotSuitable();
            if (Max<Number)
            {
                Max=Number;
            }
        }
        for (int i=0;i<Seeding.size();i++)
        {
            Seeding.get(i).setMax(Max);
        }
        return AjaxResult.success(Seeding);
    }

    @RequestMapping(value = "/InsertSuitability",method = {RequestMethod.POST})
    public AjaxResult InsertSuitability(@RequestBody UplodFile uplodFile) {
        for (int i=0;i<uplodFile.getPlantingSuitabilities().size();i++){
            uplodFile.getPlantingSuitabilities().get(i).setYear(uplodFile.getPlantingSuitabilities().get(i).getImageDate().substring(0,4));
            uplodFile.getPlantingSuitabilities().get(i).setImageDate(uplodFile.getPlantingSuitabilities().get(i).getImageDate().replace("-",""));
            Integer Seeding =Service.InsertSeeding(uplodFile.getPlantingSuitabilities().get(i));
        }
        return AjaxResult.success("成功！");
    }
    @RequestMapping(value = "/SelectYear",method = {RequestMethod.GET})
    public AjaxResult selectYear()
    {
        List<PlantingSuitability> Seeding= Service.sqlYear();
        return AjaxResult.success(Seeding);
    }
}
