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 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:06
 */
@RestController
@RequestMapping(value = "/api/Soil", produces = "application/json;charset=UTF-8")
@Api(tags = "土壤因子")
public class SoilFactorController
{
    @Resource
    private ISoilFactorService service;
    /**
     * 土壤沙化指数查询
     * @return  实体类
     */
    @ApiOperation(value = "查询方法",httpMethod = "GET")
    @RequestMapping(value = "/SelectDesert",method = {RequestMethod.GET})
    public AjaxResult SelectDesert(String zone, String year) {
        List<SoilDesertification> Seeding = service.sqlDesert(zone,year);
        return AjaxResult.success(Seeding);
    }

    /**
     * 土壤湿度查询
     * @return  实体类
     */
    @ApiOperation(value = "查询方法",httpMethod = "GET")
    @RequestMapping(value = "/SelectMoisture",method = {RequestMethod.GET})
    public AjaxResult SelectMoisture(String zone, String year) {
        List<SoilMoisture> Seeding = service.sqlMoisture(zone,year);
        return AjaxResult.success(Seeding);
    }

    /**
     * 土壤盐渍化查询
     * @return  实体类
     */
    @ApiOperation(value = "查询方法",httpMethod = "GET")
    @RequestMapping(value = "/SelectSalin",method = {RequestMethod.GET})
    public AjaxResult Selectv(String zone, String year) {
        List<SoilSalinization> Seeding = service.sqlSalin(zone,year);
        return AjaxResult.success(Seeding);
    }

    /**
     * 沙化指数添加
     * @return  实体类
     */
    @RequestMapping(value = "/InsertDesert",method = {RequestMethod.POST})
    public AjaxResult InsertDesert(@RequestBody UplodFile uplodFile) {
        List<SoilDesertification> value=uplodFile.getSoilDesertifications();
        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.InsertDesert(value.get(i));
        }

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

    /**
     * 土壤盐渍化添加
     * @return  实体类
     */
    @RequestMapping(value = "/InsertSalin",method = {RequestMethod.POST})
    public AjaxResult InsertSalin(@RequestBody UplodFile uplodFile) {
        List<SoilSalinization> value=uplodFile.getSoilSalinizations();
        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.InsertSalin(value.get(i));
        }
        return AjaxResult.success("成功！");
    }

    /**
     * 土壤湿度添加
     * @return  实体类
     */
    @RequestMapping(value = "/InsertMoisture",method = {RequestMethod.POST})
    public AjaxResult InsertMoisture(@RequestBody UplodFile uplodFile) {

        List<SoilMoisture> value=uplodFile.getSoilMoistures();
        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.InsertMoisture(value.get(i));
        }
        return AjaxResult.success("成功！");
    }

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

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

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