package com.nokia.hb.Controller;

import com.nokia.hb.Pojo.RetData;
import com.nokia.hb.Pojo.TreeNode;
import com.nokia.hb.utils.DbUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/")
public class TemplateController {
    /**
     * 用户登录
     */
    @PostMapping("userLogin")
    @ResponseBody
    public Object userLogin(String username, String password, HttpSession session) {
        return DbUtil.userLogin(username, password, session);
    }

    @GetMapping("initTreeCitys")
    @ResponseBody
    public List<TreeNode> initTreeCitys() {
        return DbUtil.initTreeCitys();
    }

    @GetMapping("initTreeIndicator")
    @ResponseBody
    public List<TreeNode> initTreeIndicator() {
        return DbUtil.initTreeIndicator();
    }


    @PostMapping("renderTable")
    @ResponseBody
    public RetData renderTable(String citys, String indicators, String ttype, String sdate) {

        return DbUtil.renderTable(citys,indicators,ttype,sdate);
    }
    
    @PostMapping({"conditionRenderTable"})
    @ResponseBody
    public RetData conditionRenderTable(String condition, String searchType, String indicators, String ttype, String sdate)
    {
      String[] split = condition.split("\n");
      String c = "";
      for (String s : split) {
        c = c + "'" + s + "',";
      }
      c = c.substring(0, c.length() - 1);
      return DbUtil.conditionRenderTable(c, searchType, indicators, ttype, sdate);
    }
}
