package com.sunxung.factoring.web;

import java.util.Date;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
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 com.sunxung.factoring.component.util.DateUtil;
import com.sunxung.factoring.component.util.ThreadLocalUtil;
import com.sunxung.factoring.dict.impl.MsgTypeDict;
import com.sunxung.factoring.entity.sys.User;
import com.sunxung.factoring.service.sys.DictionaryService;
import com.sunxung.factoring.service.sys.OrgService;
import com.sunxung.factoring.service.sys.UserService;

/**
 * @Description:主页
 * @Author:JingJiang
 * @E-mail:254702920@qq.com
 * @Date:2017年6月6日 上午11:09:52
 */
@Controller
public class IndexController {

    private static Logger log = LogManager.getLogger(IndexController.class);
    @Autowired
    private UserService userService;
    @Autowired
    private OrgService orgService;
    @Autowired
    private DictionaryService dicService;

    @RequestMapping("/") // 主页
    public String index(Model model) {
        log.debug("index！");
        User userOrg = ThreadLocalUtil.getUser();
        Long orgId = userService.getOrgIdByUserId(userOrg.getId()).get(0);
        model.addAttribute("user", userOrg);
        model.addAttribute("id", orgId);
        model.addAttribute("org", orgService.get(orgId));
        model.addAttribute("msgTypeList", dicService.findByParentCode(MsgTypeDict.CODE));
        return "index";
    }

    @RequestMapping("/index/getSystemNowDate")
    @ResponseBody
    public Object do_getSystemNowDate() {
        return DateUtil.dateToString(new Date(), "yyyy-MM-dd");
    }
}
