package com.ruoyi.web.controller.shate;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain_shate.*;
import com.ruoyi.system.service_shate.ISoilFactorService;
import com.ruoyi.system.service_shate.ITopographicFactorService;
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/Topographic", produces = "application/json;charset=UTF-8")
@Api(tags = "地形因子")
public class TopographicFactorController {

    @Resource
    private ITopographicFactorService service;
    /**
     *  海拔
     * @return  实体类
     */
    @ApiOperation(value = "查询方法",httpMethod = "GET")
    @RequestMapping(value = "/SelectAltitude",method = {RequestMethod.GET})
    public AjaxResult SelectAltitude(String zone,String year) {
        List<Altitude> Seeding = service.sqlAltitude(zone,year);
        Double Max=0.0;
        for (Altitude ce : Seeding)
        {
           if (Max<ce.getLevel1())
           {
               Max= ce.getLevel1();
           }
           if (Max<ce.getLevel2())
           {
               Max=ce.getLevel2();
           }
            if (Max<ce.getLevel3())
           {
               Max=ce.getLevel3();
           }
            if (Max<ce.getLevel4())
           {
               Max=ce.getLevel4();
           }
           if (Max<ce.getLevel5())
           {
               Max=ce.getLevel5();
           }

        }
        for (int i=0;i<Seeding.size();i++)
        {
            Seeding.get(i).setMax(Max);
        }
        return AjaxResult.success(Seeding);
    }

    /**
     * 坡度
     * @return  实体类
     */
    @ApiOperation(value = "查询方法",httpMethod = "GET")
    @RequestMapping(value = "/SelectSlope",method = {RequestMethod.GET})
    public AjaxResult SelectSlope(String zone,String year) {
        List<Slope> Seeding = service.sqlSlope(zone,year);
        return AjaxResult.success(Seeding);
    }

    /**
     * 坡向
     * @return  实体类
     */
    @ApiOperation(value = "查询方法",httpMethod = "GET")
    @RequestMapping(value = "/SelectAspect",method = {RequestMethod.GET})
    public AjaxResult SelectAspect(String zone,String year) {
        List<Aspect> Seeding = service.sqlAspect(zone,year);
        Double Max=0.0;
        for (Aspect ce : Seeding)
        {
            if (Max<ce.getEast())
            {
                Max= ce.getEast();
            }
            if (Max<ce.getNorth())
            {
                Max= ce.getNorth();
            }
            if (Max< ce.getNortheast())
            {
                Max= ce.getNortheast();
            }
            if (Max<ce.getNorthwest())
            {
                Max= ce.getNorthwest();
            }
            if (Max<ce.getSouth())
            {
                Max= ce.getSouth();
            }
            if (Max<ce.getSoutheast())
            {
                Max= ce.getSoutheast();
            }
            if (Max<ce.getSouthwest())
            {
                Max= ce.getSouthwest();
            }
            if (Max<ce.getWest())
            {
                Max= ce.getWest();
            }
        }
        for (int i=0;i<Seeding.size();i++)
        {
            Seeding.get(i).setMax(Max);
        }
        return AjaxResult.success(Seeding);
    }

    /**
     * 海拔
     * @return  实体类
     */
    @RequestMapping(value = "/InsertAltitude",method = {RequestMethod.POST})
    public AjaxResult InsertAltitude(@RequestBody UplodFile uplodFile) {
        List<Altitude> value=uplodFile.getAltitudes();
        for (int i=0;i<value.size();i++){
            value.get(i).setYear(value.get(i).getImageDate().substring(0,4));
            value.get(i).setImageDate(value.get(i).getImageDate().replace("-",""));
            Integer Seeding = service.InsertAltitude(value.get(i));
        }

        return AjaxResult.success("成功！");
    }

    /**
     * 坡向
     * @return  实体类
     */
    @RequestMapping(value = "/InsertAspect",method = {RequestMethod.POST})
    public AjaxResult InsertAspect(@RequestBody UplodFile uplodFile) {
        List<Aspect> value=uplodFile.getAspects();
        for (int i=0;i<value.size();i++){
            value.get(i).setYear(value.get(i).getImageDate().substring(0,4));
            value.get(i).setImageDate(value.get(i).getImageDate().replace("-",""));
            Integer Seeding = service.InsertAspect(value.get(i));
        }
        return AjaxResult.success("成功！");
    }

    /**
     * 坡度
     * @return  实体类
     */
    @RequestMapping(value = "/InsertSlope",method = {RequestMethod.POST})
    public AjaxResult InsertSlope(@RequestBody UplodFile uplodFile) {

        List<Slope> value = uplodFile.getSlopes();
        for (int i = 0; i < value.size(); i++) {
            value.get(i).setYear(value.get(i).getImageDate().substring(0,4));
            value.get(i).setImageDate(value.get(i).getImageDate().replace("-",""));
            Integer Seeding = service.InsertSlope(value.get(i));
        }
        return AjaxResult.success("成功！");
    }

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

    @RequestMapping(value = "/SelectYear1",method = {RequestMethod.GET})
    public AjaxResult selectYear1()
    {
        List<Slope> Seeding= service.sqlYear1();
        return AjaxResult.success(Seeding);
    }

    @RequestMapping(value = "/SelectYear2",method = {RequestMethod.GET})
    public AjaxResult selectYear2()
    {
        List<Aspect> Seeding= service.sqlYear2();
        return AjaxResult.success(Seeding);
    }

}
