package cn.com.liandisys.ycjt.ggcx.eventTotal.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.liandisys.ycjt.ggcx.common.constant.SystemConstant;
import cn.com.liandisys.ycjt.ggcx.common.service.DataDicService;
import cn.com.liandisys.ycjt.ggcx.common.util.MessageUtil;
import cn.com.liandisys.ycjt.ggcx.eventTotal.service.EventTotalService;
import cn.com.liandisys.ycjt.ggcx.eventTotal.vo.EventTotalVo;

/**
 * 
 *     
 * 项目名称：ycjt-zhxt-dp    
 * 类名称：EventTotalController   
 * 类描述：    
 * 创建人：zhangyn    
 * 创建时间：2016年12月22日 下午18:25:50    
 * 修改人：zhangyn   
 * 修改时间：2016年12月22日 下午18:25:50    
 * 修改备注：    
 * @version     
 *
 */
@Controller
public class EventTotalController {

    private Logger logger = LoggerFactory.getLogger(EventTotalController.class);

    @Autowired
    private EventTotalService eventTotalService;

    @Autowired
    private DataDicService dataDicService;

    @RequestMapping(value = "getEventSum.do")
    @ResponseBody
    public Map<String, Object> getEventSum() {

        Map<String, Object> retMap = new HashMap<String, Object>();
        try {

            List<EventTotalVo> allList = eventTotalService.getEventSum();

            List<Map<String, Object>> rows = new ArrayList<Map<String, Object>>();

            if (allList != null) {
                Iterator iterator = allList.iterator();
                while (iterator.hasNext()) {
                    Map<String, Object> row = new HashMap<String, Object>();
                    Object[] tempObj = (Object[]) iterator.next();
                    row.put("name", tempObj[0]);
                    row.put("sum", tempObj[1]);
                    String ab = dataDicService.getDataDicName(SystemConstant.SHIJLX, tempObj[0].toString());
                    row.put("sjlxname", ab);
                    rows.add(row);
                }
            }
            retMap.put("rows", rows);
            return MessageUtil.buildResponseMap(true, retMap);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return MessageUtil.buildResponseMap(false, MessageUtil.buildSystemErrorMessage(e), retMap);
        }

    }

    @RequestMapping(value = "getEventTypeList.do")
    @ResponseBody
    public Map<String, Object> getEventTypeList(String sjlxid) {

        Map<String, Object> retMap = new HashMap<String, Object>();
        try {

            List<EventTotalVo> allList = eventTotalService.getEventTypeList(sjlxid);

            List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();

            if (allList != null) {
                Iterator iterator = allList.iterator();
                while (iterator.hasNext()) {
                    Map<String, Object> row = new HashMap<String, Object>();
                    Object[] tempObj = (Object[]) iterator.next();
                    if(tempObj[0]!=null)
                    { row.put("sjlx", tempObj[0]);}
                    else{row.put("sjlx", "暂无");}
                    if(tempObj[1]!=null)
                    {  row.put("time", tempObj[1]);}
                    else{ row.put("time", "暂无");}
                    if(tempObj[2]!=null)
                    {  row.put("ldmc", tempObj[2]);}
                    else{ row.put("ldmc", "暂无");}
                    if(tempObj[3]!=null)
                    {  row.put("sjlyname", tempObj[3]);}
                    else{ row.put("sjlyname", "暂无");}
                    if(tempObj[4]!=null)
                    {  row.put("content", tempObj[4]);}
                    else{ row.put("content", "暂无");}
                    String fname = dataDicService.getDataDicName(SystemConstant.SHIJLX, tempObj[0].toString());
                    if(fname!=null)
                    {   row.put("sjlxname", fname);}
                    else{ row.put("sjlxname", "暂无");}
                    String sname = dataDicService.getDataDicName(SystemConstant.EVENT_SOURCE, tempObj[3].toString());
                    if(fname!=null)
                    {  row.put("sname", sname);}
                    else{ row.put("sname", "暂无");}
                    result.add(row);
                }
            }
            retMap.put("result", result);
            return MessageUtil.buildResponseMap(true, retMap);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return MessageUtil.buildResponseMap(false, MessageUtil.buildSystemErrorMessage(e), retMap);
        }

    }
}
