首页 > 代码库 > oper

oper

package main.java.com.zte.controller.ems;

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

import javax.annotation.Resource;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import main.java.com.zte.controller.base.BaseController;
import main.java.com.zte.entity.Page;
import main.java.com.zte.service.ems.OperationService;
import main.java.com.zte.util.DateUtil;
import main.java.com.zte.util.PageData;
import main.java.com.zte.util.Tools;

/**
 * EMS上用户操作日志处理类
 * 
 * @author 10183302
 *
 */
@Controller
@RequestMapping(value = "/ems/operation")
public class OperationController extends BaseController {
    private static final String FAILD = "Failed";
    private static final String OPERATION_RESULT = "operationResult";
    private static final String OPER_COUNT = "OPER_COUNT";
    private static final String EMS_USER_OPERATION_CHARTS = "ems/user_operation_charts";
    private static final String USER_OPERATION_FAILED_COUNT = "userOperationFailedCount";
    private static final String USER_OPERATION_NAME_COUNT = "userOperationNameCount";
    private static final String USER_COUNT = "userCount";
    private static final String OPERATION_NAME_LIST = "operationNameList";
    private static final String IP_LIST = "ipList";
    private static final String START_TIME = "START_TIME";
    private static final String TASK_ID_STR = "taskId";
    private static final String TASK_ID_NUM_STR = "1470880530369";
    private static final String HOST_STR_UPPER = "HOST";
    private static final String HOST_STR_LOWER = "ip";
    private static final String OPERATION_NAME_STR_LOWER = "operationName";
    private static final String LOG_NAME_STR_UPPER = "OPERATION_NAME";

    @Resource(name = "operationService")
    private OperationService operationService;

    @RequestMapping(value = "/to_user_operation_charts")
    public ModelAndView toUserOperationCharts(Page page,
            @RequestParam(value = TASK_ID_STR, required = false) String taskId)
            throws Exception {
        ModelAndView mv = this.getModelAndView();
        PageData pd = new PageData();
        List<PageData> ipList = null;
        List<PageData> operationNameList = null;
        List<PageData> userCount = null;
        List<PageData> userOperationNameCount = null;
        List<PageData> userOperationFailedCount = null;
        try {
            pd = this.getPageData();
            if (!Tools.notEmpty(taskId)) {
                taskId = TASK_ID_NUM_STR;
            }
            pd.put(TASK_ID_STR, taskId);
            ipList = operationService.getOperationIp(pd);
            if (null != ipList) {
                pd.put(HOST_STR_LOWER, ipList.get(0).get(HOST_STR_UPPER));
                operationNameList = operationService.getOperationName(pd);
                pd.put(OPERATION_NAME_STR_LOWER,
                        operationNameList.get(0).get(LOG_NAME_STR_UPPER));
                page.setPd(pd);
                userCount = operationService.userCount(pd);
                userOperationNameCount = operationService
                        .userOperationNameCount(pd);
                pd.put(OPERATION_RESULT, FAILD);
                userOperationFailedCount = operationService
                        .userOperationFailedCount(pd);
            }
        } catch (Exception e) {
            logger.error(e.toString(), e);
        }
        mv.addObject(IP_LIST, ipList);
        mv.addObject(OPERATION_NAME_LIST, operationNameList);
        mv.addObject(USER_COUNT, userCount);
        mv.addObject(USER_OPERATION_NAME_COUNT, userOperationNameCount);
        mv.addObject(USER_OPERATION_FAILED_COUNT, userOperationFailedCount);
        mv.setViewName(EMS_USER_OPERATION_CHARTS);
        return mv;
    }

    @RequestMapping(value = "/user_operation_charts")
    @ResponseBody
    public Map userOperationCharts(Page page,
            @RequestParam(value = TASK_ID_STR, required = false) String taskId) {
        PageData pd = new PageData();
        List<PageData> userOperDatas = null;
        JSONObject chartsUserOperJson = new JSONObject();
        Map<String, Double> userOperDataMap = new HashMap<String, Double>();
        try {
            pd = this.getPageData();
            if (!Tools.notEmpty(taskId)) {
                taskId = TASK_ID_NUM_STR;
            }
            pd.put(TASK_ID_STR, taskId);
            /*
             * pd.put(HOST_STR_LOWER, ip); pd.put(OPERATION_NAME_STR_LOWER,
             * operationName);
             */
            userOperDatas = operationService.userOperationCharts(pd);
            // 存放一个图表OPER_COUNT,START_TIME
            if (!userOperDatas.isEmpty()) {
                String time = "";
                double operCount = 0;
                for (PageData userOperData : userOperDatas) {
                    time = DateUtil.convertUTCTimeMillis(userOperData.get(
                            START_TIME).toString());
                    operCount = Double.valueOf(userOperData.get(OPER_COUNT)
                            .toString());
                    userOperDataMap.put(time, operCount);
                }
                chartsUserOperJson = JSONObject.fromObject(userOperDataMap);
            }
        } catch (Exception e) {
            logger.error(e.toString(), e);
        }

        Map<String, Double> map = new HashMap<String, Double>();
        map.put("1", 21.1);
        map.put("2", 33.3);
        map.put("3", 44.4);
        JSONObject jsonObject = JSONObject.fromObject(map);
        return userOperDataMap;
    }

    @RequestMapping(value = "/get_operation_name")
    @ResponseBody
    public String getOperationName(
            @RequestParam(value = HOST_STR_LOWER, required = false) String ip) {
        PageData pd = new PageData();
        List<PageData> operationNameList = null;
        try {
            pd = this.getPageData();
            pd.put(HOST_STR_LOWER, ip);
            operationNameList = operationService.getOperationName(pd);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        }
        return JSONArray.fromObject(operationNameList).toString();
    }
}

 

oper