Search in sources :

Example 1 with SignStatsRecord

use of com.itrus.portal.db.SignStatsRecord in project portal by ixinportal.

the class SignStatsController method excelExport.

// 导出Excel
@RequestMapping(value = "/excel")
public String excelExport(@RequestParam(value = "cycle_sel", required = false) Integer cycle, @RequestParam(value = "projectName", required = false) Long projectName, @RequestParam(value = "year1_sel", required = false) Integer year1, @RequestParam(value = "year2_sel", required = false) Integer year2, Model uiModel, HttpServletRequest request, HttpServletResponse response) throws Exception {
    Map param = new HashMap();
    Map param2 = new HashMap();
    Integer year3 = null;
    if (year1 != null) {
        year3 = year1;
    }
    List<Map<Integer, Integer>> list = new ArrayList<Map<Integer, Integer>>();
    java.util.Date nowdate = new java.util.Date();
    String[] monthList = { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" };
    String[] seasonList = { "S1", "S2", "S3", "S4" };
    String month = null;
    String season = null;
    String year = null;
    Calendar calendar = Calendar.getInstance();
    Calendar calendar2 = Calendar.getInstance();
    String projectName1 = null;
    if (null != cycle && cycle == 12) {
        while (year1 <= year2) {
            for (int j = 0; j <= 11; j++) {
                calendar.set(Calendar.YEAR, year1);
                calendar.set(Calendar.MONTH, j);
                calendar.set(Calendar.DAY_OF_MONTH, 1);
                calendar.set(Calendar.HOUR_OF_DAY, 0);
                calendar.set(Calendar.MINUTE, 0);
                calendar.set(Calendar.SECOND, 0);
                calendar.set(Calendar.MILLISECOND, 0);
                // calendar.add(Calendar.MILLISECOND, -1);
                Date dt1 = calendar.getTime();
                calendar2.set(Calendar.YEAR, year1);
                calendar2.set(Calendar.MONTH, j + 1);
                calendar2.set(Calendar.DAY_OF_MONTH, 1);
                calendar2.set(Calendar.HOUR_OF_DAY, 0);
                calendar2.set(Calendar.MINUTE, 0);
                calendar2.set(Calendar.SECOND, 0);
                calendar2.set(Calendar.MILLISECOND, 0);
                // calendar2.add(Calendar.MILLISECOND, -1);
                Date dt2 = calendar2.getTime();
                if (projectName != null && projectName != 0) {
                    Project project = sqlSession.selectOne("com.itrus.portal.db.ProjectMapper.selectByPrimaryKey", projectName);
                    projectName1 = project.getName();
                    param.put("projectName", projectName);
                }
                param2.put("projectName", projectName);
                if (dt2.before(nowdate)) {
                    month = year1 + "-" + monthList[j];
                    param2.put("month", month);
                    SignStatsRecord ssr = sqlSession.selectOne("com.itrus.portal.db.SignStatsRecordMapper.selectByMonth1", param2);
                    if (null != ssr) {
                        Integer count = ssr.getCount1();
                        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
                        map.put(count, year1);
                        list.add(map);
                    } else {
                        param.put("queryDate1", dt1);
                        param.put("queryDate2", dt2);
                        Integer count = sqlSession.selectOne("com.itrus.portal.db.SignRecordMapper.selectCountByPeriod", param);
                        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
                        map.put(count, year1);
                        list.add(map);
                        SignStatsRecord ssr2 = new SignStatsRecord();
                        ssr2.setMonth1(month);
                        ssr2.setProjectId(projectName);
                        ssr2.setCount1(count);
                        ssr2.setCreateTime(new Date());
                        sqlSession.insert("com.itrus.portal.db.SignStatsRecordMapper.insert", ssr2);
                    }
                } else {
                    param.put("queryDate1", dt1);
                    param.put("queryDate2", dt2);
                    Integer count = sqlSession.selectOne("com.itrus.portal.db.SignRecordMapper.selectCountByPeriod", param);
                    Map<Integer, Integer> map = new HashMap<Integer, Integer>();
                    map.put(count, year1);
                    list.add(map);
                }
            }
            year1++;
        }
    }
    if (null != cycle && cycle == 4) {
        while (year1 <= year2) {
            for (int j = 0; j <= 9; j = j + 3) {
                calendar.set(Calendar.YEAR, year1);
                calendar.set(Calendar.MONTH, j);
                calendar.set(Calendar.DAY_OF_MONTH, 1);
                calendar.set(Calendar.HOUR_OF_DAY, 0);
                calendar.set(Calendar.MINUTE, 0);
                calendar.set(Calendar.SECOND, 0);
                calendar.set(Calendar.MILLISECOND, 0);
                // calendar.add(Calendar.MILLISECOND, -1);
                Date dt1 = calendar.getTime();
                calendar2.set(Calendar.YEAR, year1);
                calendar2.set(Calendar.MONTH, j + 3);
                calendar2.set(Calendar.DAY_OF_MONTH, 1);
                calendar2.set(Calendar.HOUR_OF_DAY, 0);
                calendar2.set(Calendar.MINUTE, 0);
                calendar2.set(Calendar.SECOND, 0);
                calendar2.set(Calendar.MILLISECOND, 0);
                // calendar2.add(Calendar.MILLISECOND, -1);
                Date dt2 = calendar2.getTime();
                if (projectName != null && projectName != 0) {
                    Project project = sqlSession.selectOne("com.itrus.portal.db.ProjectMapper.selectByPrimaryKey", projectName);
                    projectName1 = project.getName();
                    param.put("projectName", projectName);
                }
                param2.put("projectName", projectName);
                if (dt2.before(nowdate)) {
                    season = year1 + "-" + seasonList[j / 3];
                    param2.put("season", season);
                    SignStatsRecord ssr = sqlSession.selectOne("com.itrus.portal.db.SignStatsRecordMapper.selectBySeason1", param2);
                    if (null != ssr) {
                        Integer count = ssr.getCount1();
                        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
                        map.put(count, year1);
                        list.add(map);
                    } else {
                        param.put("queryDate1", dt1);
                        param.put("queryDate2", dt2);
                        Integer count = sqlSession.selectOne("com.itrus.portal.db.SignRecordMapper.selectCountByPeriod", param);
                        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
                        map.put(count, year1);
                        list.add(map);
                        SignStatsRecord ssr2 = new SignStatsRecord();
                        ssr2.setSeason1(season);
                        ssr2.setProjectId(projectName);
                        ssr2.setCount1(count);
                        ssr2.setCreateTime(new Date());
                        sqlSession.insert("com.itrus.portal.db.SignStatsRecordMapper.insert", ssr2);
                    }
                } else {
                    param.put("queryDate1", dt1);
                    param.put("queryDate2", dt2);
                    Integer count = sqlSession.selectOne("com.itrus.portal.db.SignRecordMapper.selectCountByPeriod", param);
                    Map<Integer, Integer> map = new HashMap<Integer, Integer>();
                    map.put(count, year1);
                    list.add(map);
                }
            }
            year1++;
        }
    }
    if (null != cycle && cycle == 1) {
        while (year1 <= year2) {
            calendar.set(Calendar.YEAR, year1);
            calendar.set(Calendar.MONTH, 0);
            calendar.set(Calendar.DATE, 1);
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            // calendar.add(Calendar.MILLISECOND, -1);
            Date dt1 = calendar.getTime();
            calendar2.set(Calendar.YEAR, year1 + 1);
            calendar2.set(Calendar.MONTH, 0);
            calendar2.set(Calendar.DAY_OF_MONTH, 1);
            calendar2.set(Calendar.HOUR_OF_DAY, 0);
            calendar2.set(Calendar.MINUTE, 0);
            calendar2.set(Calendar.SECOND, 0);
            calendar2.set(Calendar.MILLISECOND, 0);
            // calendar2.add(Calendar.MILLISECOND, -1);
            Date dt2 = calendar2.getTime();
            if (projectName != null && projectName != 0) {
                Project project = sqlSession.selectOne("com.itrus.portal.db.ProjectMapper.selectByPrimaryKey", projectName);
                projectName1 = project.getName();
                param.put("projectName", projectName);
            }
            param2.put("projectName", projectName);
            if (dt2.before(nowdate)) {
                year = year1 + "Y";
                param2.put("year", year);
                SignStatsRecord ssr = sqlSession.selectOne("com.itrus.portal.db.SignStatsRecordMapper.selectByYear1", param2);
                if (null != ssr) {
                    Integer count = ssr.getCount1();
                    Map<Integer, Integer> map = new HashMap<Integer, Integer>();
                    map.put(count, year1);
                    list.add(map);
                } else {
                    param.put("queryDate1", dt1);
                    param.put("queryDate2", dt2);
                    Integer count = sqlSession.selectOne("com.itrus.portal.db.SignRecordMapper.selectCountByPeriod", param);
                    Map<Integer, Integer> map = new HashMap<Integer, Integer>();
                    map.put(count, year1);
                    list.add(map);
                    SignStatsRecord ssr2 = new SignStatsRecord();
                    ssr2.setYear1(year);
                    ssr2.setProjectId(projectName);
                    ssr2.setCount1(count);
                    ssr2.setCreateTime(new Date());
                    sqlSession.insert("com.itrus.portal.db.SignStatsRecordMapper.insert", ssr2);
                }
            } else {
                param.put("queryDate1", dt1);
                param.put("queryDate2", dt2);
                Integer count = sqlSession.selectOne("com.itrus.portal.db.SignRecordMapper.selectCountByPeriod", param);
                Map<Integer, Integer> map = new HashMap<Integer, Integer>();
                map.put(count, year1);
                list.add(map);
            }
            year1++;
        }
    }
    if (null == projectName || 0 == projectName) {
        projectName1 = "所有项目";
    }
    ArrayList<String> fieldName = signStatsService.excelFieldName();
    ArrayList<ArrayList<String>> fieldDatas = signStatsService.excelFieldData(list, projectName1, cycle);
    ExcelFileGenerator generator = new ExcelFileGenerator(fieldName, fieldDatas);
    try {
        // 重置response对象中的缓冲区,该方法可以不写,但是你要保证response缓冲区没有其他数据,否则导出可能会出现问题,建议加上
        response.reset();
        String filename = "签名统计信息" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + // 设置下载时客户端Excel的名称,此处需要用到encodeFilename()方法来转换编码,否则中文会被过滤掉
        ".xls";
        filename = generator.encodeFilename(filename, request);
        response.setHeader("Content-disposition", "attachment;filename=" + filename);
        response.setCharacterEncoding("utf-8");
        // 由于导出格式是excel的文件,设置导出文件的响应头部信息
        response.setContentType("application/vnd.ms-excel");
        // 生成excel,传递输出流
        // 用response对象获取输出流
        OutputStream os = response.getOutputStream();
        generator.expordExcel(os);
        // 清理刷新缓冲区,将缓存中的数据将数据导出excel
        os.flush();
        // 关闭os
        if (os != null) {
            os.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : OutputStream(java.io.OutputStream) ExcelFileGenerator(com.itrus.portal.utils.ExcelFileGenerator) SignStatsRecord(com.itrus.portal.db.SignStatsRecord) Project(com.itrus.portal.db.Project) java.util(java.util) SimpleDateFormat(java.text.SimpleDateFormat) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with SignStatsRecord

use of com.itrus.portal.db.SignStatsRecord in project portal by ixinportal.

the class SignStatsController method list.

@RequestMapping(produces = "text/html")
public String list(@RequestParam(value = "cycle", required = false) Integer cycle, @RequestParam(value = "projectName", required = false) Long projectName, @RequestParam(value = "year1", required = false) Integer year1, @RequestParam(value = "year2", required = false) Integer year2, Model uiModel) throws Exception {
    Map param = new HashMap();
    Map param2 = new HashMap();
    // List<Integer> years = new ArrayList<Integer>();
    /*       int a = year1 - year2;
        if (a ==0){
            years.add(year1);
        }
        else{
            for (int i =0; i <=a; i++){
                years.add(year1+i);
            }
        } */
    Integer year3 = null;
    if (year1 != null) {
        year3 = year1;
    }
    List<Map<Integer, Integer>> list = new ArrayList<Map<Integer, Integer>>();
    java.util.Date nowdate = new java.util.Date();
    String[] monthList = { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" };
    String[] seasonList = { "S1", "S2", "S3", "S4" };
    String month = null;
    String season = null;
    String year = null;
    Calendar calendar = Calendar.getInstance();
    Calendar calendar2 = Calendar.getInstance();
    String projectName1 = null;
    if (null != cycle && cycle == 12) {
        while (year1 <= year2) {
            for (int j = 0; j <= 11; j++) {
                calendar.set(Calendar.YEAR, year1);
                calendar.set(Calendar.MONTH, j);
                calendar.set(Calendar.DAY_OF_MONTH, 1);
                calendar.set(Calendar.HOUR_OF_DAY, 0);
                calendar.set(Calendar.MINUTE, 0);
                calendar.set(Calendar.SECOND, 0);
                calendar.set(Calendar.MILLISECOND, 0);
                // calendar.add(Calendar.MILLISECOND, -1);
                Date dt1 = calendar.getTime();
                calendar2.set(Calendar.YEAR, year1);
                calendar2.set(Calendar.MONTH, j + 1);
                calendar2.set(Calendar.DAY_OF_MONTH, 1);
                calendar2.set(Calendar.HOUR_OF_DAY, 0);
                calendar2.set(Calendar.MINUTE, 0);
                calendar2.set(Calendar.SECOND, 0);
                calendar2.set(Calendar.MILLISECOND, 0);
                // calendar2.add(Calendar.MILLISECOND, -1);
                Date dt2 = calendar2.getTime();
                if (projectName != null && projectName != 0) {
                    Project project = sqlSession.selectOne("com.itrus.portal.db.ProjectMapper.selectByPrimaryKey", projectName);
                    projectName1 = project.getName();
                    param.put("projectName", projectName);
                }
                param2.put("projectName", projectName);
                if (dt2.before(nowdate)) {
                    month = year1 + "-" + monthList[j];
                    param2.put("month", month);
                    SignStatsRecord ssr = sqlSession.selectOne("com.itrus.portal.db.SignStatsRecordMapper.selectByMonth1", param2);
                    if (null != ssr) {
                        Integer count = ssr.getCount1();
                        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
                        map.put(count, year1);
                        list.add(map);
                    } else {
                        param.put("queryDate1", dt1);
                        param.put("queryDate2", dt2);
                        Integer count = sqlSession.selectOne("com.itrus.portal.db.SignRecordMapper.selectCountByPeriod", param);
                        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
                        map.put(count, year1);
                        list.add(map);
                        SignStatsRecord ssr2 = new SignStatsRecord();
                        ssr2.setMonth1(month);
                        ssr2.setProjectId(projectName);
                        ssr2.setCount1(count);
                        ssr2.setCreateTime(new Date());
                        sqlSession.insert("com.itrus.portal.db.SignStatsRecordMapper.insert", ssr2);
                    }
                } else {
                    param.put("queryDate1", dt1);
                    param.put("queryDate2", dt2);
                    Integer count = sqlSession.selectOne("com.itrus.portal.db.SignRecordMapper.selectCountByPeriod", param);
                    Map<Integer, Integer> map = new HashMap<Integer, Integer>();
                    map.put(count, year1);
                    list.add(map);
                }
            }
            year1++;
        }
    }
    if (null != cycle && cycle == 4) {
        while (year1 <= year2) {
            for (int j = 0; j <= 9; j = j + 3) {
                calendar.set(Calendar.YEAR, year1);
                calendar.set(Calendar.MONTH, j);
                calendar.set(Calendar.DAY_OF_MONTH, 1);
                calendar.set(Calendar.HOUR_OF_DAY, 0);
                calendar.set(Calendar.MINUTE, 0);
                calendar.set(Calendar.SECOND, 0);
                calendar.set(Calendar.MILLISECOND, 0);
                // calendar.add(Calendar.MILLISECOND, -1);
                Date dt1 = calendar.getTime();
                calendar2.set(Calendar.YEAR, year1);
                calendar2.set(Calendar.MONTH, j + 3);
                calendar2.set(Calendar.DAY_OF_MONTH, 1);
                calendar2.set(Calendar.HOUR_OF_DAY, 0);
                calendar2.set(Calendar.MINUTE, 0);
                calendar2.set(Calendar.SECOND, 0);
                calendar2.set(Calendar.MILLISECOND, 0);
                // calendar2.add(Calendar.MILLISECOND, -1);
                Date dt2 = calendar2.getTime();
                if (projectName != null && projectName != 0) {
                    Project project = sqlSession.selectOne("com.itrus.portal.db.ProjectMapper.selectByPrimaryKey", projectName);
                    projectName1 = project.getName();
                    param.put("projectName", projectName);
                }
                param2.put("projectName", projectName);
                if (dt2.before(nowdate)) {
                    season = year1 + "-" + seasonList[j / 3];
                    param2.put("season", season);
                    SignStatsRecord ssr = sqlSession.selectOne("com.itrus.portal.db.SignStatsRecordMapper.selectBySeason1", param2);
                    if (null != ssr) {
                        Integer count = ssr.getCount1();
                        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
                        map.put(count, year1);
                        list.add(map);
                    } else {
                        param.put("queryDate1", dt1);
                        param.put("queryDate2", dt2);
                        Integer count = sqlSession.selectOne("com.itrus.portal.db.SignRecordMapper.selectCountByPeriod", param);
                        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
                        map.put(count, year1);
                        list.add(map);
                        SignStatsRecord ssr2 = new SignStatsRecord();
                        ssr2.setSeason1(season);
                        ssr2.setProjectId(projectName);
                        ssr2.setCount1(count);
                        ssr2.setCreateTime(new Date());
                        sqlSession.insert("com.itrus.portal.db.SignStatsRecordMapper.insert", ssr2);
                    }
                } else {
                    param.put("queryDate1", dt1);
                    param.put("queryDate2", dt2);
                    Integer count = sqlSession.selectOne("com.itrus.portal.db.SignRecordMapper.selectCountByPeriod", param);
                    Map<Integer, Integer> map = new HashMap<Integer, Integer>();
                    map.put(count, year1);
                    list.add(map);
                }
            }
            year1++;
        }
    }
    if (null != cycle && cycle == 1) {
        while (year1 <= year2) {
            calendar.set(Calendar.YEAR, year1);
            calendar.set(Calendar.MONTH, 0);
            calendar.set(Calendar.DAY_OF_MONTH, 1);
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            // calendar.add(Calendar.MILLISECOND, -1);
            Date dt1 = calendar.getTime();
            calendar2.set(Calendar.YEAR, year1 + 1);
            calendar2.set(Calendar.MONTH, 0);
            calendar2.set(Calendar.DAY_OF_MONTH, 1);
            calendar2.set(Calendar.HOUR_OF_DAY, 0);
            calendar2.set(Calendar.MINUTE, 0);
            calendar2.set(Calendar.SECOND, 0);
            calendar2.set(Calendar.MILLISECOND, 0);
            // calendar2.add(Calendar.MILLISECOND, -1);
            Date dt2 = calendar2.getTime();
            if (projectName != null && projectName != 0) {
                Project project = sqlSession.selectOne("com.itrus.portal.db.ProjectMapper.selectByPrimaryKey", projectName);
                projectName1 = project.getName();
                param.put("projectName", projectName);
            }
            param2.put("projectName", projectName);
            if (dt2.before(nowdate)) {
                year = year1 + "Y";
                param2.put("year", year);
                SignStatsRecord ssr = sqlSession.selectOne("com.itrus.portal.db.SignStatsRecordMapper.selectByYear1", param2);
                if (null != ssr) {
                    Integer count = ssr.getCount1();
                    Map<Integer, Integer> map = new HashMap<Integer, Integer>();
                    map.put(count, year1);
                    list.add(map);
                } else {
                    param.put("queryDate1", dt1);
                    param.put("queryDate2", dt2);
                    Integer count = sqlSession.selectOne("com.itrus.portal.db.SignRecordMapper.selectCountByPeriod", param);
                    Map<Integer, Integer> map = new HashMap<Integer, Integer>();
                    map.put(count, year1);
                    list.add(map);
                    SignStatsRecord ssr2 = new SignStatsRecord();
                    ssr2.setYear1(year);
                    ssr2.setProjectId(projectName);
                    ssr2.setCount1(count);
                    ssr2.setCreateTime(new Date());
                    sqlSession.insert("com.itrus.portal.db.SignStatsRecordMapper.insert", ssr2);
                }
            } else {
                param.put("queryDate1", dt1);
                param.put("queryDate2", dt2);
                Integer count = sqlSession.selectOne("com.itrus.portal.db.SignRecordMapper.selectCountByPeriod", param);
                Map<Integer, Integer> map = new HashMap<Integer, Integer>();
                map.put(count, year1);
                list.add(map);
            }
            year1++;
        }
    }
    if (null == projectName || 0 == projectName) {
        projectName1 = "所有项目";
    }
    uiModel.addAttribute("list", list);
    uiModel.addAttribute("year1", year3);
    uiModel.addAttribute("year2", year2);
    uiModel.addAttribute("cycle", cycle);
    uiModel.addAttribute("projectName", projectName);
    uiModel.addAttribute("projects", getProjectMapOfAdmin());
    uiModel.addAttribute("projectN", projectName1);
    return "signstats/list";
}
Also used : SignStatsRecord(com.itrus.portal.db.SignStatsRecord) Project(com.itrus.portal.db.Project) java.util(java.util) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Project (com.itrus.portal.db.Project)2 SignStatsRecord (com.itrus.portal.db.SignStatsRecord)2 java.util (java.util)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ExcelFileGenerator (com.itrus.portal.utils.ExcelFileGenerator)1 OutputStream (java.io.OutputStream)1 SimpleDateFormat (java.text.SimpleDateFormat)1