package com.gyee.frame.controller.gen;

import com.gyee.frame.model.auto.Weatherfh;
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.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.github.pagehelper.PageInfo;
import com.gyee.frame.common.domain.AjaxResult;
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.netty.websocket.util.SocketToolController;
import com.gyee.frame.service.WeatherfhService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.io.IOException;
import java.text.ParseException;

@Controller
@RequestMapping("WeatherfhController")
@Api(value = "")
public class WeatherfhController extends SocketToolController{
	
	private String prefix = "gen/weatherfh";
	@Autowired
	private WeatherfhService weatherfhService;
	
	@GetMapping("view")
	@RequiresPermissions("gen:weatherfh:view")
    public String view(ModelMap model)
    {	
		String str="";
		setTitle(model, new TitleVo("列表", str+"管理", true,"欢迎进入"+str+"页面", true, false));
        return prefix + "/list";
    }
	
	
	//页面请求,跳转至按天统计气象模块矩阵,预测未来16小时数据，包含当前小时
	@GetMapping("/weatherProphet_7Day_17Hour")
	public ModelAndView socket_17() throws IOException {
		//ModelAndView modelAndView=new ModelAndView("socket/socket1");
		return goSocketPage("weatherProphet_7Day_17Hour","weather/weatherProphet_7Day_17hour");
	}
	
	//@Log(title = "集合查询", action = "111")
	@GetMapping("list")
	@RequiresPermissions("gen:weatherfh:list")
	@ResponseBody
	public Object list(Tablepar tablepar,String searchText,String windpowerstationid) throws ParseException {
		PageInfo<Weatherfh> page=weatherfhService.list(tablepar,searchText,windpowerstationid) ;
		TableSplitResult<Weatherfh> result=new TableSplitResult<Weatherfh>(page.getPageNum(), page.getTotal(), page.getList()); 
		return  result;
	}
	
	/**
     * 新增
     */

    @GetMapping("/add")
    public String add(ModelMap modelMap)
    {
        return prefix + "/add";
    }
	
	//@Log(title = "新增", action = "111")
	@PostMapping("add")
	@RequiresPermissions("gen:weatherfh:add")
	@ResponseBody
	public AjaxResult add(Weatherfh weatherfh){
		int b=weatherfhService.insertSelective(weatherfh);
		if(b>0){
			return success();
		}else{
			return error();
		}
	}
	
	/**
	 * 删除用户
	 * @param ids
	 * @return
	 */
	//@Log(title = "删除", action = "111")
	@PostMapping("remove")
	@RequiresPermissions("gen:weatherfh:remove")
	@ResponseBody
	public AjaxResult remove(String ids){
		int b=weatherfhService.deleteByPrimaryKey(ids);
		if(b>0){
			return success();
		}else{
			return error();
		}
	}
	
	/**
	 * 检查用户
	 * @return
	 */
	@PostMapping("checkNameUnique")
	@ResponseBody
	public int checkNameUnique(Weatherfh weatherfh){
		int b=weatherfhService.checkNameUnique(weatherfh);
		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("Weatherfh", weatherfhService.selectByPrimaryKey(id));

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

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

	
}
