package com.gyee.frame.controller.gen;

import com.alibaba.druid.support.json.JSONUtils;
import com.google.gson.JsonObject;
import com.gyee.frame.model.auto.WeatherfdExample;
import com.gyee.frame.netty.websocket.util.SocketToolController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageInfo;
import com.gyee.frame.common.domain.AjaxResult;
import com.gyee.frame.model.auto.Weatherfd;
import com.gyee.frame.model.custom.TableSplitResult;
import com.gyee.frame.model.custom.Tablepar;
import com.gyee.frame.model.custom.TitleVo;
import com.gyee.frame.service.WeatherfdService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.servlet.ModelAndView;

import javax.jws.WebParam;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("WeatherfdController")
@CrossOrigin
@Api(value = "")
public class WeatherfdController extends SocketToolController {
	
	private String prefix = "gen/weatherfd";
	@Autowired
	private WeatherfdService weatherfdService;
	
	@GetMapping("view")
	@RequiresPermissions("gen:weatherfd:view")
    public String view(ModelMap model)
    {	
		String str="";
		setTitle(model, new TitleVo("列表", str+"管理", true,"欢迎进入"+str+"页面", true, false));
        return prefix + "/list";
    }


	//页面请求,跳转至按天统计气象模块矩阵,预测今天数据
	@GetMapping("/weatherProphet_1")
	public ModelAndView socket1() throws IOException {
		//ModelAndView modelAndView=new ModelAndView("socket/socket1");
		return goSocketPage("weatherProphet_1","weather/weatherProphet_1");
	}

	
	//页面请求,跳转至按天统计气象模块矩阵,预测未来7天数据，包括今天
	@GetMapping("/weatherProphet_7")
	public ModelAndView socket7() throws IOException {
		//ModelAndView modelAndView=new ModelAndView("socket/socket1");
		return goSocketPage("weatherProphet_7","weather/weatherProphet_7");
	}
	
	//页面请求，跳转至按天统计气象模块矩阵，预测未来8~15天的数据，包括今天
		@GetMapping("/weatherProphet_8_15")
		public ModelAndView socket8_15() throws IOException {
			//ModelAndView modelAndView=new ModelAndView("socket/socket1");
			return goSocketPage("weatherProphet_8_15","weather/weatherProphet_8_15");
	}

    //页面请求，跳转至按天统计气象模块矩阵，预测未来8~15天的数据，包括今天
    @GetMapping("/weatherInformationChangePictureName")
    @ResponseBody
    public List<String> weatherInformationChangePictureName (String[] model,String[] weatherInformation) throws IOException {
        List<String> listClassName = new ArrayList();
        List<String> weatherInformationPictureName = weatherfdService.weatherInformationChangePictureName(weatherInformation);
		String models = "";
		for(int k = 0 ;k < model.length ;k++){
            models = models + model[k] + "_" ;
        }
        for(int j=0;j<weatherInformationPictureName.size();j++){
			listClassName.add(models+weatherInformationPictureName.get(j));
		}
        return listClassName;
    }


    //页面请求，跳转至按天统计气象模块矩阵，预测未来8~15天的数据，包括今天
    @GetMapping("/windDirectionChangePictureName")
    @ResponseBody
    public List<String> windDirectionChangePictureName(String[] model,String[] windDirection) throws IOException {
        String models = "";
        for(int i = 0 ;i < model.length ;i++){
            models = models + model[i] + "_" ;
        }

        List<String> listClassName = new ArrayList();
        List<String> windDirectionChangePictureName = weatherfdService.windDirectionChangePictureName(windDirection);
        for(int j = 0 ; j < windDirectionChangePictureName.size() ; j++){
			listClassName.add(models + windDirectionChangePictureName.get(j));
        }
        return listClassName;
    }



	//页面请求,跳转至按天统计气象模块矩阵,预测未来40天数据，包括今天
	@GetMapping("/weatherProphet_40")
	public ModelAndView socket40() throws IOException {
		//ModelAndView modelAndView=new ModelAndView("socket/socket1");
		return goSocketPage("weatherProphet_40","weather/weatherProphet_40");
	}




	//@Log(title = "集合查询", action = "111")
	@GetMapping("list")
	@RequiresPermissions("gen:weatherfd:list")
	@ResponseBody
	public Object list(Tablepar tablepar,String searchText,String windpowerstationid) throws ParseException {
		PageInfo<Weatherfd> page=weatherfdService.list(tablepar,searchText,windpowerstationid) ;
		TableSplitResult<Weatherfd> result=new TableSplitResult<Weatherfd>(page.getPageNum(), page.getTotal(), page.getList()); 
		return  result;
	}



	//@Log(title = "集合查询", action = "111")
	@GetMapping("list90")
	@ResponseBody
	public Object list() throws ParseException {
		WeatherfdExample testExample=new WeatherfdExample();
		List<Weatherfd> weatherfds = weatherfdService.selectByExample(testExample);
		return  weatherfds;
	}


	/**
     * 新增
     */

    @GetMapping("/add")
    public String add(ModelMap modelMap)
    {
        return prefix + "/add";
    }
	
	//@Log(title = "新增", action = "111")
	@PostMapping("add")
	@RequiresPermissions("gen:weatherfd:add")
	@ResponseBody
	public AjaxResult add(Weatherfd weatherfd){
		int b=weatherfdService.insertSelective(weatherfd);
		if(b>0){
			return success();
		}else{
			return error();
		}
	}
	
	/**
	 * 删除用户
	 * @param ids
	 * @return
	 */
	//@Log(title = "删除", action = "111")
	@PostMapping("remove")
	@RequiresPermissions("gen:weatherfd:remove")
	@ResponseBody
	public AjaxResult remove(String ids){
		int b=weatherfdService.deleteByPrimaryKey(ids);
		if(b>0){
			return success();
		}else{
			return error();
		}
	}
	
	/**
	 * 检查用户
	 * @param weatherfd
	 * @return
	 */
	@PostMapping("checkNameUnique")
	@ResponseBody
	public int checkNameUnique(Weatherfd weatherfd){
		int b=weatherfdService.checkNameUnique(weatherfd);
		if(b>0){
			return 1;
		}else{
			return 0;
		}
	}
	
	
	/**
	 * 修改跳转
	 * @param id
	 * @param mmap
	 * @return
	 */
	@GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        mmap.put("Weatherfd", weatherfdService.selectByPrimaryKey(id));

        return prefix + "/edit";
    }
	
	/**
     * 修改保存
     */
    //@Log(title = "修改", action = "111")
    @RequiresPermissions("gen:weatherfd:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Weatherfd record)
    {
        return toAjax(weatherfdService.updateByPrimaryKeySelective(record));
    }

    
    /**
   	 * 根据主键查询
   	 * 
   	 * @param id
   	 * @return
   	 */
   	@PostMapping("/get/{id}")
   	@ApiOperation(value = "根据id查询唯一", notes = "根据id查询唯一")
   	public Weatherfd edit(@PathVariable("id") String id) {
   		return weatherfdService.selectByPrimaryKey(id);
   	}


	@Override
	public String convertmessage(Object message) {
		return "123456";
	}
}
