package com.ruoyi.web.controller.shate;

import com.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain_shate.AustraliaMiddleEastVO;
import com.ruoyi.system.domain_shate.SeedingSuccessRate;
import com.ruoyi.system.domain_shate.UplodFile;
import com.ruoyi.system.service_shate.IAustraliaMiddleEastService;
import com.ruoyi.system.service_shate.ISeedingSuccessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
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.text.DecimalFormat;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author: JinSheng Song
 * @Date: 2022/7/8 9:46
 */
@RestController
@RequestMapping(value = "/api/Seeding", produces = "application/json;charset=UTF-8")
@Api(tags = "播种成功率")
public class SeedingSuccessController
{

    @Resource
    private ISeedingSuccessService seedingService;
    /**
     * 查询方法
     * @return  实体类
     */
    @ApiOperation(value = "查询方法",httpMethod = "GET")
    @RequestMapping(value = "/SelectSeeding",method = {RequestMethod.GET})
    public AjaxResult SelectSeeding(String zone,String year)
    {
        List<SeedingSuccessRate> Seeding= seedingService.sqlSeeding(zone,year);
        for (int i=0;i<Seeding.size();i++)
        {
            DecimalFormat df = new DecimalFormat(".00");
            Double rate=Seeding.get(i).getSeedingSuccessArea()/Seeding.get(i).getSeedingSuccess()*100;
            Seeding.get(i).setPlantingArea(Double.parseDouble(df.format(rate)));
        }
        return AjaxResult.success(Seeding);
    }

    @RequestMapping(value = "/insertSeeding1",method = {RequestMethod.POST})
    public void addSeedingSucces1(@RequestBody UplodFile uplodFile)
    {
        List<SeedingSuccessRate> value=uplodFile.getInformation();
        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("-",""));
            seedingService.InsertSeeding1(value.get(i));
        }

    }

    @RequestMapping(value = "/insertSeeding2",method = {RequestMethod.POST})
    public void addSeedingSucces2(@RequestBody UplodFile uplodFile)
    {
        List<SeedingSuccessRate> value=uplodFile.getInformation();
        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("-",""));
            seedingService.InsertSeeding2(value.get(i));
        }

    }

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