package com.ssj.sys.controller;


import com.ssj.bean.common.framework.core.domain.Response;
import com.ssj.bean.sys.menu.domain.Menu;
import com.ssj.bean.sys.role.domain.Admin;
import com.ssj.bean.weixin.libmy.domain.TbLibJoin;
import com.ssj.framework.core.common.controller.BaseController;
import com.ssj.service.sys.menu.service.MenuService;
import com.ssj.service.weixin.library.service.ILibJoinService;
import com.ssj.sys.utils.SystemResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

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


@RequestMapping("sys/login")
@Controller
public class IndexController extends BaseController {
	@Autowired
    private MenuService menuService;
	@Autowired
    private ILibJoinService libJoinService;
	
	
	
	 /**
	  * ******0000
	  * 后台登陆成功后跳转到后台首页
	  * @param model
	  * @return
	  */
	 @RequestMapping(value="/index")
	 public String index(Model model) {
		 HttpSession session = request.getSession();
		 Admin admin =(Admin) session.getAttribute("admin");
		 List<Menu> list= menuService.findByAll(admin);
		 model.addAttribute("list", list);
		 return "sys/login/index";
	 }
	 
	    /**
	     * 后台首页
	     * @param model
	     * @return
	     */
	    @RequestMapping(value="/home")
	    public String home(Model model) {
	    	String libId="ssj";
    	    List<TbLibJoin> list= libJoinService.getLibJoinByCode(orgcodeList());
    	    if(list!=null && list.size()==1){
    	    	libId=list.get(0).getId();
    	    }
    		model.addAttribute("libList",list);

    	    model.addAttribute("curLibId",libId);
	    	return "sys/login/home";
	    }
	    
	    
	     /**
	      * 刷新 tb_sys_config 数据缓存清空重新生成
	     * @return
	     * @throws Exception
	     * 创建人：ZhangCaibao 
	     * 2018年4月3日 下午3:48:04 
	     * @Response
	      */
	     @RequestMapping(value = "/refresh")
		 @ResponseBody
		 public Response refresh() throws Exception{
		    	Response response = new  Response();
			 SystemResource.refresh();
		    	response.success();
		    	return response;
		 }
}
