com.esd.cs.statistics.ReportController.java Source code

Java tutorial

Introduction

Here is the source code for com.esd.cs.statistics.ReportController.java

Source

/*
 * Copyright (c) 2013 ????www.hrbesd.com. All rights reserved.
 * 
 * HRBESD PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.esd.cs.statistics;

import java.io.File;
import java.util.List;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.esd.cs.Constants;
import com.esd.cs.common.CommonUtil;
import com.esd.cs.common.PoiCreateExcel;
import com.esd.cs.worker.WorkerController;
import com.esd.hesf.service.ReportViewService;
import com.esd.hesf.viewmodels.ReportViewModel;

/**
 * 
 * 
 * @author Administrator
 * 
 */
@Controller
@RequestMapping(value = "/security/report")
public class ReportController {
    private static final Logger logger = LoggerFactory.getLogger(WorkerController.class);
    @Autowired
    private ReportViewService reportViewService;

    @RequestMapping(value = "/createExcle", method = RequestMethod.GET)
    public ModelAndView createExcle(HttpServletRequest request) {

        return new ModelAndView("report/dowanloadArea");
    }

    // 
    @Value("${uploadPath}")
    String uploadPath;

    // 
    @Value("${companyPath}")
    String companyPath;

    // ??
    @Value("${createTabCompany}")
    String createTabCompany;

    /**
     *  ?
     * 
     * @param request
     * @return
     */
    @RequestMapping(value = "/nature", method = RequestMethod.GET)
    public ModelAndView nature(HttpServletRequest request, HttpSession session) {
        String nowYear = (String) session.getAttribute(Constants.YEAR);
        request.setAttribute("year", nowYear);
        request.setAttribute("currentTime", CommonUtil.formatData());
        request.setAttribute("createTabCompany", createTabCompany);// ?
        request.setAttribute("createPeople", session.getAttribute(Constants.USER_REAL_NAME).toString());// 
        return new ModelAndView("report/nature");
    }

    /**
     * ? ? ?
     * 
     * @param year
     * @param request
     * @return
     */
    @RequestMapping(value = "/notice/{year}", method = RequestMethod.POST)
    @ResponseBody
    public Object get_company(@PathVariable(value = "year") String year, HttpServletRequest request) {
        logger.debug("printNoticeParamsYear:{}", year);
        List<ReportViewModel> list = reportViewService.getByCompanyType(year);
        System.out.println(list.size());
        logger.debug("printNoticeResult:{}", list.size());
        return list;
    }

    /**
     *  
     * 
     * @param request
     * @return
     */
    @RequestMapping(value = "/area", method = RequestMethod.GET)
    public ModelAndView area(HttpServletRequest request, HttpSession session) {
        String nowYear = (String) session.getAttribute(Constants.YEAR);
        request.setAttribute("year", nowYear);
        request.setAttribute("currentTime", CommonUtil.formatData());
        request.setAttribute("createTabCompany", createTabCompany);// ?
        request.setAttribute("createPeople", session.getAttribute(Constants.USER_REAL_NAME).toString());// 

        return new ModelAndView("report/area");
    }

    /**
     * ?  ?
     * 
     * @param year
     * @param request
     * @return
     */
    @RequestMapping(value = "/area/{year}", method = RequestMethod.POST)
    @ResponseBody
    public Object getarea(@PathVariable(value = "year") String year, HttpServletRequest request) {
        logger.debug("printareaParamsYear:{}", year);
        List<ReportViewModel> list = reportViewService.getByArea(year);
        logger.debug("printareaResult:{}", list.size());
        return list;
    }

    /**
     *  ? 
     * 
     * @param request
     * @return
     */
    @RequestMapping(value = "/economytype", method = RequestMethod.GET)
    public ModelAndView economytype(HttpServletRequest request, HttpSession session) {
        String nowYear = (String) session.getAttribute(Constants.YEAR);
        request.setAttribute("year", nowYear);
        request.setAttribute("currentTime", CommonUtil.formatData());
        request.setAttribute("createTabCompany", createTabCompany);// ?
        request.setAttribute("createPeople", session.getAttribute(Constants.USER_REAL_NAME).toString());// 
        return new ModelAndView("report/economytype");
    }

    /**
     * ? ? ?
     * 
     * @param year
     * @param request
     * @return
     */
    @RequestMapping(value = "/economytype/{year}", method = RequestMethod.POST)
    @ResponseBody
    public Object geteconomytype(@PathVariable(value = "year") String year, HttpServletRequest request) {
        logger.debug("printarEconomytypeParamsYear:{}", year);
        List<ReportViewModel> list = reportViewService.getByCompanyEconomyType(year);
        logger.debug("printEconomytypeResult:{}", list.size());
        return list;
    }

    /**
     * 
     * 
     * @param type
     * @param year
     * @param request
     * @return
     */
    @RequestMapping(value = "/export/{type}/{year}", method = RequestMethod.POST)
    @ResponseBody
    public String export(@PathVariable(value = "type") String type, @PathVariable(value = "year") String year,
            HttpServletRequest request, HttpSession session) {

        List<ReportViewModel> list = null;
        // ??
        String url = request.getServletContext().getRealPath("/");
        // 
        CommonUtil.chineseFolder(url, uploadPath, companyPath);
        // ??
        String uuid = UUID.randomUUID().toString();
        // ?
        String exportPath = url + uploadPath + File.separator + companyPath + File.separator + uuid + ".xls";

        // ???
        ReportModel model = new ReportModel();
        model.setCreateCompany(createTabCompany);// ?
        model.setCreateData("" + CommonUtil.formatData());// 
        model.setCreatePeople("" + session.getAttribute(Constants.USER_REAL_NAME).toString());// 

        // 
        // ??
        if (StringUtils.equals("nature", type)) {
            list = reportViewService.getByCompanyType(year);
            model.setType("??");// 
            model.setTitle("??");// 
        }
        // 
        if (StringUtils.equals("area", type)) {
            list = reportViewService.getByArea(year);
            model.setType("");// 
            model.setTitle("");// 
        }
        // ?
        if (StringUtils.equals("economytype", type)) {
            list = reportViewService.getByArea(year);
            model.setType("?");// 
            model.setTitle("?");// 
        }

        // ?
        PoiCreateExcel.createRepeaExcel(exportPath, list, model);

        String destPath = request.getLocalAddr() + ":" + request.getLocalPort() + request.getContextPath();
        // ?
        String loaddown = "http://" + destPath + "/" + uploadPath + "/" + companyPath + "/" + uuid + ".xls";
        return loaddown;
    }

}