List of usage examples for java.util Calendar clone
@Override
public Object clone()
From source file:tw.edu.chit.struts.action.deptassist.ReportPrintAction.java
/** * ???/*from w ww . ja va 2 s . c om*/ * * @param mapping org.apache.struts.action.ActionMapping object * @param form org.apache.struts.action.ActionForm object * @param request request javax.servlet.http.HttpServletRequest object * @param response response javax.servlet.http.HttpServletResponse object * @param sterm */ @SuppressWarnings("unchecked") private void printDeptStdSkillList2(ActionMapping mapping, DynaActionForm form, HttpServletRequest request, HttpServletResponse response, String sterm) throws Exception { HttpSession session = request.getSession(false); AdminManager am = (AdminManager) getBean(IConstants.ADMIN_MANAGER_BEAN_NAME); MemberManager mm = (MemberManager) getBean(MEMBER_MANAGER_BEAN_NAME); Member member = (Member) getUserCredential(session).getMember(); Empl empl = mm.findEmplByOid(member.getOid()); ServletContext context = request.getSession().getServletContext(); CodeEmpl codeEmpl = new CodeEmpl(); codeEmpl.setIdno(empl.getUnit()); Example example4CodeEmpl = Example.create(codeEmpl).ignoreCase().enableLike(MatchMode.START); List<CodeEmpl> codeEmpls = (List<CodeEmpl>) am.findSQLWithCriteria(CodeEmpl.class, example4CodeEmpl, null, null); DateFormat df = new SimpleDateFormat("yyyy/MM/dd"); Calendar cal = Calendar.getInstance(); Calendar cal1 = (Calendar) cal.clone(); Calendar cal2 = (Calendar) cal.clone(); if (StringUtils.isNotBlank(form.getString("licenseValidDateStart")) || StringUtils.isNotBlank(form.getString("licenseValidDateEnd"))) { Date from = StringUtils.isBlank(form.getString("licenseValidDateStart")) ? null : Toolket.parseNativeDate(form.getString("licenseValidDateStart")); // ??? Date to = StringUtils.isBlank(form.getString("licenseValidDateEnd")) ? Calendar.getInstance().getTime() : Toolket.parseNativeDate(form.getString("licenseValidDateEnd")); cal1.setTime(from); cal1.set(Calendar.HOUR_OF_DAY, 0); cal1.set(Calendar.MINUTE, 0); cal1.set(Calendar.SECOND, 0); cal1.set(Calendar.MILLISECOND, 0); cal2.setTime(to); cal2.set(Calendar.HOUR_OF_DAY, 23); cal2.set(Calendar.MINUTE, 59); cal2.set(Calendar.SECOND, 59); cal2.set(Calendar.MILLISECOND, 999); } // Y boolean flag = form.getString("amountDateType").equalsIgnoreCase("y"); String hql = ""; if (flag) hql = "FROM StdSkill s WHERE s.amountDate IS NOT NULL AND s.deptNo = ? " + "AND s.licenseValidDate BETWEEN ? AND ? ORDER BY s.studentNo"; else // ? hql = "FROM StdSkill s WHERE s.amountDate IS NULL AND s.deptNo = ? " + "AND s.licenseValidDate BETWEEN ? AND ? ORDER BY s.studentNo"; /* List<StdSkill> skills = (List<StdSkill>) am.find(hql, new Object[] { codeEmpls.get(0).getIdno2().trim(), cal1.getTime(), cal2.getTime() }); */ codeEmpl.setIdno(empl.getUnit()); List<StdSkill> skills = (List<StdSkill>) am.find(hql, new Object[] { codeEmpl.getIdno().trim(), cal1.getTime(), cal2.getTime() }); File templateXLS = new File(context.getRealPath("/WEB-INF/reports/DeptStdSkillList2.xls")); HSSFWorkbook workbook = Toolket.getHSSFWorkbook(templateXLS); HSSFSheet sheet = workbook.getSheetAt(0); // Header Toolket.setCellValue(sheet, 0, 0, "?" + Toolket.getEmpUnit(empl.getUnit()) + "??? (" + df.format(cal1.getTime()) + "~" + df.format(cal2.getTime()) + ") - " + (flag ? "" : "")); int index = 2; Student student = null; Graduate graduate = null; List<LicenseCode> codes = null; List<LicenseCode961> code961s = null; LicenseCode code = null; LicenseCode961 code961 = null; String checkStr1 = "???\n?\n???"; String checkStr2 = "?\n?"; for (StdSkill skill : skills) { student = mm.findStudentByNo(skill.getStudentNo()); if (student == null) { graduate = mm.findGraduateByStudentNo(skill.getStudentNo()); if (graduate != null) { Toolket.setCellValue(sheet, index, 13, Toolket.getStatus(graduate.getOccurStatus(), true)); Toolket.setCellValue(sheet, index, 14, df.format(graduate.getOccurDate())); student = new Student(); BeanUtils.copyProperties(graduate, student); } } if (student != null || graduate != null) { Toolket.setCellValue(sheet, index, 0, String.valueOf(index - 1)); Toolket.setCellValue(sheet, index, 1, StringUtils.isBlank(student.getDepartClass()) ? "" : Toolket.getSchoolName(student.getDepartClass())); Toolket.setCellValue(sheet, index, 2, Toolket.getClassFullName(student.getDepartClass())); Toolket.setCellValue(sheet, index, 3, student.getStudentNo()); Toolket.setCellValue(sheet, index, 4, student.getStudentName()); Toolket.setCellValue(sheet, index, 5, student.getIdno()); Toolket.setCellValue(sheet, index, 9, String.valueOf(skill.getAmount())); Toolket.setCellValue(sheet, index, 10, ""); Toolket.setCellValue(sheet, index, 11, checkStr1); Toolket.setCellValue(sheet, index, 12, checkStr2); codes = (List<LicenseCode>) am .findLicenseCodesBy(new LicenseCode(String.valueOf(skill.getLicenseCode()))); if (!codes.isEmpty()) { code = codes.get(0); Toolket.setCellValue(sheet, index, 6, code.getName()); Toolket.setCellValue(sheet, index, 7, code.getDeptName()); Toolket.setCellValue(sheet, index, 8, code.getLevel()); } else { code961s = (List<LicenseCode961>) am .findLicenseCode961sBy(new LicenseCode961(String.valueOf(skill.getLicenseCode()))); if (!code961s.isEmpty()) { code961 = code961s.get(0); Toolket.setCellValue(sheet, index, 6, code961.getName()); Toolket.setCellValue(sheet, index, 7, code961.getDeptName()); Toolket.setCellValue(sheet, index, 8, code961.getLevel()); } } index++; } } File tempDir = new File( context.getRealPath("/WEB-INF/reports/temp/" + getUserCredential(session).getMember().getIdno() + (new SimpleDateFormat("yyyyMMdd").format(new Date())))); if (!tempDir.exists()) tempDir.mkdirs(); File output = new File(tempDir, "DeptStdSkillList2.xls"); FileOutputStream fos = new FileOutputStream(output); workbook.write(fos); fos.close(); JasperReportUtils.printXlsToFrontEnd(response, output); output.delete(); tempDir.delete(); }
From source file:tw.edu.chit.struts.action.deptassist.ReportPrintAction.java
/** * ?/*from w w w. j a v a 2 s . c o m*/ * * @param mapping org.apache.struts.action.ActionMapping object * @param form org.apache.struts.action.ActionForm object * @param request request javax.servlet.http.HttpServletRequest object * @param response response javax.servlet.http.HttpServletResponse object * @param sterm */ @SuppressWarnings("unchecked") private void printDeptGStdSkillList(ActionMapping mapping, DynaActionForm form, HttpServletRequest request, HttpServletResponse response, String sterm) throws Exception { HttpSession session = request.getSession(false); AdminManager am = (AdminManager) getBean(IConstants.ADMIN_MANAGER_BEAN_NAME); CourseManager cm = (CourseManager) getBean(IConstants.COURSE_MANAGER_BEAN_NAME); MemberManager mm = (MemberManager) getBean(MEMBER_MANAGER_BEAN_NAME); Member member = (Member) getUserCredential(session).getMember(); Empl empl = mm.findEmplByOid(member.getOid()); ServletContext context = request.getSession().getServletContext(); CodeEmpl codeEmpl = new CodeEmpl(); codeEmpl.setIdno(empl.getUnit()); Example example4CodeEmpl = Example.create(codeEmpl).ignoreCase().enableLike(MatchMode.START); List<CodeEmpl> codeEmpls = (List<CodeEmpl>) am.findSQLWithCriteria(CodeEmpl.class, example4CodeEmpl, null, null); List<StdSkill> skills = null; StdSkill skill = new StdSkill(); skill.setAmount(null); // ?? Example example = Example.create(skill).ignoreCase().enableLike(MatchMode.ANYWHERE); List<Order> orders = new LinkedList<Order>(); orders.add(Order.asc("schoolYear")); orders.add(Order.asc("schoolTerm")); orders.add(Order.asc("studentNo")); Criterion deptNo = Restrictions.eq("deptNo", codeEmpls.get(0).getIdno2().trim()); // DateFormat df = new SimpleDateFormat("yyyy/MM/dd"); if (StringUtils.isNotBlank(form.getString("licenseValidDateStart")) || StringUtils.isNotBlank(form.getString("licenseValidDateEnd"))) { Calendar cal = Calendar.getInstance(); Calendar cal1 = (Calendar) cal.clone(); Calendar cal2 = (Calendar) cal.clone(); Date from = StringUtils.isBlank(form.getString("licenseValidDateStart")) ? null : Toolket.parseNativeDate(form.getString("licenseValidDateStart")); // ??? Date to = StringUtils.isBlank(form.getString("licenseValidDateEnd")) ? Calendar.getInstance().getTime() : Toolket.parseNativeDate(form.getString("licenseValidDateEnd")); cal1.setTime(from); cal1.set(Calendar.HOUR_OF_DAY, 0); cal1.set(Calendar.MINUTE, 0); cal1.set(Calendar.SECOND, 0); cal1.set(Calendar.MILLISECOND, 0); cal2.setTime(to); cal2.set(Calendar.HOUR_OF_DAY, 23); cal2.set(Calendar.MINUTE, 59); cal2.set(Calendar.SECOND, 59); cal2.set(Calendar.MILLISECOND, 999); Criterion licenseValidDate = Restrictions.between("licenseValidDate", cal1.getTime(), cal2.getTime()); skills = (List<StdSkill>) am.findSQLWithCriteria(StdSkill.class, example, null, orders, deptNo, licenseValidDate); } else skills = (List<StdSkill>) am.findSQLWithCriteria(StdSkill.class, example, null, orders, deptNo); File templateXLS = new File(context.getRealPath("/WEB-INF/reports/DeptStdSkillList.xls")); HSSFWorkbook workbook = Toolket.getHSSFWorkbook(templateXLS); HSSFSheet sheet = workbook.getSheetAt(0); Toolket.setCellValue(sheet, 0, 0, "?"); int index = 2; List<LicenseCode> codes = null; Student student = null; Graduate graduate = null; DEmpl dempl = null; Csno csno = null; DateFormat df1 = new SimpleDateFormat("yyyy/MM"); for (StdSkill ss : skills) { codes = (List<LicenseCode>) am.findLicenseCodesBy(new LicenseCode(String.valueOf(ss.getLicenseCode()))); if (!codes.isEmpty()) ss.setLicense(codes.get(0)); student = mm.findStudentByNo(ss.getStudentNo().trim()); if (student == null) { graduate = mm.findGraduateByStudentNo(ss.getStudentNo().trim()); if (graduate != null) { ss.setStudentName(graduate.getStudentName().trim()); ss.setDepartClass(Toolket.getClassFullName(graduate.getDepartClass())); } } else { ss.setStudentName(student.getStudentName().trim()); ss.setDepartClass(Toolket.getClassFullName(student.getDepartClass())); } Toolket.setCellValue(sheet, index, 0, ss.getSchoolYear() + "." + ss.getSchoolTerm()); Toolket.setCellValue(sheet, index, 1, ss.getStudentNo().toUpperCase()); Toolket.setCellValue(sheet, index, 2, ss.getStudentName()); Toolket.setCellValue(sheet, index, 3, ss.getDepartClass()); Toolket.setCellValue(sheet, index, 4, ss.getLicense().getCode().trim()); Toolket.setCellValue(sheet, index, 5, ss.getLicense().getDeptName().trim()); Toolket.setCellValue(sheet, index, 6, ss.getLicense().getName().trim()); Toolket.setCellValue(sheet, index, 7, ss.getLicense().getLocale().toString()); Toolket.setCellValue(sheet, index, 8, ss.getLicense().getLevel().trim()); Toolket.setCellValue(sheet, index, 9, ss.getLicense().getType().toString()); Toolket.setCellValue(sheet, index, 10, ss.getAmount().toString()); Toolket.setCellValue(sheet, index, 11, Toolket.getAmountType(ss.getAmountType())); Toolket.setCellValue(sheet, index, 12, ss.getAmountDate() == null ? "" : df1.format(ss.getAmountDate())); Toolket.setCellValue(sheet, index, 13, ss.getLicenseNo()); Toolket.setCellValue(sheet, index, 14, df.format(ss.getLicenseValidDate())); if (StringUtils.isNotBlank(ss.getCscode())) { csno = cm.findCourseInfoByCscode(ss.getCscode()); if (csno != null) Toolket.setCellValue(sheet, index, 15, csno.getChiName().trim()); } else Toolket.setCellValue(sheet, index, 15, ""); if (StringUtils.isNotBlank(ss.getTechIdno())) { empl = mm.findEmplByIdno(ss.getTechIdno()); if (empl != null) Toolket.setCellValue(sheet, index, 16, empl.getCname().trim()); else { dempl = mm.findDEmplByIdno(ss.getTechIdno()); if (dempl != null) Toolket.setCellValue(sheet, index, 16, dempl.getCname().trim()); } } else Toolket.setCellValue(sheet, index, 16, ""); Toolket.setCellValue(sheet, index, 17, ss.getSerialNo()); Toolket.setCellValue(sheet, index, 18, Toolket.getCustomNo(ss.getCustomNo())); Toolket.setCellValue(sheet, index, 19, Toolket.getPass(ss.getPass())); Toolket.setCellValue(sheet, index++, 20, Toolket.getApplyType(ss.getApplyType())); } File tempDir = new File( context.getRealPath("/WEB-INF/reports/temp/" + getUserCredential(session).getMember().getIdno() + (new SimpleDateFormat("yyyyMMdd").format(new Date())))); if (!tempDir.exists()) tempDir.mkdirs(); File output = new File(tempDir, "DeptStdSkillList.xls"); FileOutputStream fos = new FileOutputStream(output); workbook.write(fos); fos.close(); JasperReportUtils.printXlsToFrontEnd(response, output); output.delete(); tempDir.delete(); }
From source file:tw.edu.chit.struts.action.deptassist.ReportPrintAction.java
/** * ?//from ww w . java2s . c o m * * @param mapping org.apache.struts.action.ActionMapping object * @param form org.apache.struts.action.ActionForm object * @param request request javax.servlet.http.HttpServletRequest object * @param response response javax.servlet.http.HttpServletResponse object * @param sterm */ @SuppressWarnings("unchecked") private void DeptStdSkill4EnglishList(ActionMapping mapping, DynaActionForm form, HttpServletRequest request, HttpServletResponse response, String sterm) throws Exception { HttpSession session = request.getSession(false); AdminManager am = (AdminManager) getBean(IConstants.ADMIN_MANAGER_BEAN_NAME); CourseManager cm = (CourseManager) getBean(IConstants.COURSE_MANAGER_BEAN_NAME); MemberManager mm = (MemberManager) getBean(MEMBER_MANAGER_BEAN_NAME); Member member = (Member) getUserCredential(session).getMember(); Empl empl = mm.findEmplByOid(member.getOid()); ServletContext context = request.getSession().getServletContext(); CodeEmpl codeEmpl = new CodeEmpl(); codeEmpl.setIdno(empl.getUnit()); Example example4CodeEmpl = Example.create(codeEmpl).ignoreCase().enableLike(MatchMode.START); List<CodeEmpl> codeEmpls = (List<CodeEmpl>) am.findSQLWithCriteria(CodeEmpl.class, example4CodeEmpl, null, null); List<Object> ret = null; DateFormat df = new SimpleDateFormat("yyyy/MM/dd"); if (StringUtils.isNotBlank(form.getString("licenseValidDateStart")) || StringUtils.isNotBlank(form.getString("licenseValidDateEnd"))) { String hql = "SELECT ss, s FROM StdSkill ss, Student s " + "WHERE ss.deptNo = '0' AND ss.studentNo = s.studentNo " + "AND s.departClass LIKE ? AND ss.licenseValidDate BETWEEN ? AND ? " + "ORDER BY s.departClass"; Calendar cal = Calendar.getInstance(); Calendar cal1 = (Calendar) cal.clone(); Calendar cal2 = (Calendar) cal.clone(); Date from = StringUtils.isBlank(form.getString("licenseValidDateStart")) ? null : Toolket.parseNativeDate(form.getString("licenseValidDateStart")); // ??? Date to = StringUtils.isBlank(form.getString("licenseValidDateEnd")) ? Calendar.getInstance().getTime() : Toolket.parseNativeDate(form.getString("licenseValidDateEnd")); cal1.setTime(from); cal1.set(Calendar.HOUR_OF_DAY, 0); cal1.set(Calendar.MINUTE, 0); cal1.set(Calendar.SECOND, 0); cal1.set(Calendar.MILLISECOND, 0); cal2.setTime(to); cal2.set(Calendar.HOUR_OF_DAY, 23); cal2.set(Calendar.MINUTE, 59); cal2.set(Calendar.SECOND, 59); cal2.set(Calendar.MILLISECOND, 999); ret = (List<Object>) am.find(hql, new Object[] { "___" + codeEmpls.get(0).getIdno2().trim() + "__", from, to }); } else { String hql = "SELECT ss, s FROM StdSkill ss, Student s " + "WHERE ss.deptNo = '0' AND ss.studentNo = s.studentNo " + "AND s.departClass LIKE ? ORDER BY s.departClass"; ret = (List<Object>) am.find(hql, new Object[] { "___" + codeEmpls.get(0).getIdno2().trim() + "__", }); } File templateXLS = new File(context.getRealPath("/WEB-INF/reports/DeptStdSkillList.xls")); HSSFWorkbook workbook = Toolket.getHSSFWorkbook(templateXLS); HSSFSheet sheet = workbook.getSheetAt(0); Toolket.setCellValue(sheet, 0, 0, "?"); int index = 2; List<LicenseCode> codes = null; Student student = null; Graduate graduate = null; DEmpl dempl = null; Csno csno = null; DateFormat df1 = new SimpleDateFormat("yyyy/MM"); Object[] o = null; StdSkill ss = null; if (!ret.isEmpty()) { for (Object obj : ret) { o = (Object[]) obj; ss = (StdSkill) o[0]; student = (Student) o[1]; codes = (List<LicenseCode>) am .findLicenseCodesBy(new LicenseCode(String.valueOf(ss.getLicenseCode()))); if (!codes.isEmpty()) ss.setLicense(codes.get(0)); if (student == null) { graduate = mm.findGraduateByStudentNo(ss.getStudentNo().trim()); if (graduate != null) { ss.setStudentName(graduate.getStudentName().trim()); ss.setDepartClass(Toolket.getClassFullName(graduate.getDepartClass())); } } else { ss.setStudentName(student.getStudentName().trim()); ss.setDepartClass(Toolket.getClassFullName(student.getDepartClass())); } Toolket.setCellValue(sheet, index, 0, ss.getSchoolYear() + "." + ss.getSchoolTerm()); Toolket.setCellValue(sheet, index, 1, ss.getStudentNo().toUpperCase()); Toolket.setCellValue(sheet, index, 2, ss.getStudentName()); Toolket.setCellValue(sheet, index, 3, ss.getDepartClass()); Toolket.setCellValue(sheet, index, 4, ss.getLicense().getCode().trim()); Toolket.setCellValue(sheet, index, 5, ss.getLicense().getDeptName().trim()); Toolket.setCellValue(sheet, index, 6, ss.getLicense().getName().trim()); Toolket.setCellValue(sheet, index, 7, ss.getLicense().getLocale().toString()); Toolket.setCellValue(sheet, index, 8, ss.getLicense().getLevel().trim()); Toolket.setCellValue(sheet, index, 9, ss.getLicense().getType().toString()); Toolket.setCellValue(sheet, index, 10, ss.getAmount().toString()); Toolket.setCellValue(sheet, index, 11, Toolket.getAmountType(ss.getAmountType())); Toolket.setCellValue(sheet, index, 12, ss.getAmountDate() == null ? "" : df1.format(ss.getAmountDate())); Toolket.setCellValue(sheet, index, 13, ss.getLicenseNo()); Toolket.setCellValue(sheet, index, 14, df.format(ss.getLicenseValidDate())); if (StringUtils.isNotBlank(ss.getCscode())) { csno = cm.findCourseInfoByCscode(ss.getCscode()); if (csno != null) Toolket.setCellValue(sheet, index, 15, csno.getChiName().trim()); } else Toolket.setCellValue(sheet, index, 15, ""); if (StringUtils.isNotBlank(ss.getTechIdno())) { empl = mm.findEmplByIdno(ss.getTechIdno()); if (empl != null) Toolket.setCellValue(sheet, index, 16, empl.getCname().trim()); else { dempl = mm.findDEmplByIdno(ss.getTechIdno()); if (dempl != null) Toolket.setCellValue(sheet, index, 16, dempl.getCname().trim()); } } else Toolket.setCellValue(sheet, index, 16, ""); Toolket.setCellValue(sheet, index, 17, ss.getSerialNo()); Toolket.setCellValue(sheet, index, 18, Toolket.getCustomNo(ss.getCustomNo())); Toolket.setCellValue(sheet, index, 19, Toolket.getPass(ss.getPass())); Toolket.setCellValue(sheet, index++, 20, Toolket.getApplyType(ss.getApplyType())); } } File tempDir = new File( context.getRealPath("/WEB-INF/reports/temp/" + getUserCredential(session).getMember().getIdno() + (new SimpleDateFormat("yyyyMMdd").format(new Date())))); if (!tempDir.exists()) tempDir.mkdirs(); File output = new File(tempDir, "DeptStdSkill4EnglishList.xls"); FileOutputStream fos = new FileOutputStream(output); workbook.write(fos); fos.close(); JasperReportUtils.printXlsToFrontEnd(response, output); output.delete(); tempDir.delete(); }
From source file:tw.edu.chit.struts.action.deptassist.ReportPrintAction.java
/** * ?/* w w w . j av a2 s.com*/ * * @param mapping org.apache.struts.action.ActionMapping object * @param form org.apache.struts.action.ActionForm object * @param request request javax.servlet.http.HttpServletRequest object * @param response response javax.servlet.http.HttpServletResponse object * @param sterm */ @SuppressWarnings("unchecked") private void printDeptStdSkillList5(ActionMapping mapping, DynaActionForm form, HttpServletRequest request, HttpServletResponse response, String sterm) throws Exception { HttpSession session = request.getSession(false); AdminManager am = (AdminManager) getBean(IConstants.ADMIN_MANAGER_BEAN_NAME); MemberManager mm = (MemberManager) getBean(MEMBER_MANAGER_BEAN_NAME); Member member = (Member) getUserCredential(session).getMember(); Empl empl = mm.findEmplByOid(member.getOid()); ServletContext context = request.getSession().getServletContext(); CodeEmpl codeEmpl = new CodeEmpl(); codeEmpl.setIdno(empl.getUnit()); Example example4CodeEmpl = Example.create(codeEmpl).ignoreCase().enableLike(MatchMode.START); List<CodeEmpl> codeEmpls = (List<CodeEmpl>) am.findSQLWithCriteria(CodeEmpl.class, example4CodeEmpl, null, null); DateFormat df = new SimpleDateFormat("yyyy/MM/dd"); Calendar cal = Calendar.getInstance(); Calendar cal1 = (Calendar) cal.clone(); Calendar cal2 = (Calendar) cal.clone(); if (StringUtils.isNotBlank(form.getString("licenseValidDateStart")) || StringUtils.isNotBlank(form.getString("licenseValidDateEnd"))) { Date from = StringUtils.isBlank(form.getString("licenseValidDateStart")) ? null : Toolket.parseNativeDate(form.getString("licenseValidDateStart")); // ??? Date to = StringUtils.isBlank(form.getString("licenseValidDateEnd")) ? Calendar.getInstance().getTime() : Toolket.parseNativeDate(form.getString("licenseValidDateEnd")); cal1.setTime(from); cal1.set(Calendar.HOUR_OF_DAY, 0); cal1.set(Calendar.MINUTE, 0); cal1.set(Calendar.SECOND, 0); cal1.set(Calendar.MILLISECOND, 0); cal2.setTime(to); cal2.set(Calendar.HOUR_OF_DAY, 23); cal2.set(Calendar.MINUTE, 59); cal2.set(Calendar.SECOND, 59); cal2.set(Calendar.MILLISECOND, 999); } String hql = "SELECT COUNT(*), s.techIdno, s.licenseCode FROM StdSkill s " + "WHERE s.deptNo = ? AND s.techIdno IS NOT NULL " + "AND s.licenseValidDate BETWEEN ? AND ? " + "GROUP BY s.techIdno, s.licenseCode"; List<Object> ret = (List<Object>) am.find(hql, new Object[] { codeEmpls.get(0).getIdno2().trim(), cal1.getTime(), cal2.getTime() }); HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("?"); sheet.setColumnWidth(0, 4000); sheet.setColumnWidth(1, 6000); sheet.setColumnWidth(2, 4000); sheet.setColumnWidth(3, 3000); sheet.setColumnWidth(4, 4000); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 4)); HSSFFont fontSize12 = workbook.createFont(); fontSize12.setFontHeightInPoints((short) 12); fontSize12.setFontName("Arial Unicode MS"); HSSFFont fontSize10 = workbook.createFont(); fontSize10.setFontHeightInPoints((short) 10); fontSize10.setFontName("Arial Unicode MS"); // Header Toolket.setCellValue(workbook, sheet, 0, 0, "?" + Toolket.getEmpUnit(empl.getUnit()) + "? (" + df.format(cal1.getTime()) + "~" + df.format(cal2.getTime()) + ")", fontSize12, HSSFCellStyle.ALIGN_CENTER, false, 35.0F, null); // Column Header Toolket.setCellValue(workbook, sheet, 1, 0, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 1, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 2, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 3, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 4, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); int index = 2; Object[] data = null; DEmpl dempl = null; for (Object o : ret) { data = (Object[]) o; sheet.addMergedRegion(new CellRangeAddress(index, index + 2, 0, 0)); empl = mm.findEmplByIdno((String) data[1]); if (empl == null) { dempl = mm.findDEmplByIdno((String) data[1]); //Toolket.setCellValue(workbook, sheet, index, 0, dempl // .getCname(), fontSize10, HSSFCellStyle.ALIGN_CENTER, // true, null); } else { Toolket.setCellValue(workbook, sheet, index, 0, empl.getCname(), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); } Toolket.setCellValue(workbook, sheet, index + 1, 0, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index + 2, 0, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index, 1, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index + 1, 1, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index + 2, 1, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index, 2, "10", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index + 1, 2, "5", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index + 2, 2, "2", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index, 3, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index + 1, 3, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); //((Integer) data[0]).toString() ?? "" ?? Toolket.setCellValue(workbook, sheet, index + 2, 3, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); /*??? Toolket.setCellValue(workbook, sheet, index + 2, 3, ((Integer) data[0]).toString(), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); */ Toolket.setCellValue(workbook, sheet, index, 4, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index + 1, 4, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index + 2, 4, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); index += 3; } index++; sheet.addMergedRegion(new CellRangeAddress(index, index, 0, 1)); Toolket.setCellValue(workbook, sheet, index, 0, " : ?20", fontSize10, HSSFCellStyle.ALIGN_LEFT, false, null); File tempDir = new File( context.getRealPath("/WEB-INF/reports/temp/" + getUserCredential(session).getMember().getIdno() + (new SimpleDateFormat("yyyyMMdd").format(new Date())))); if (!tempDir.exists()) tempDir.mkdirs(); File output = new File(tempDir, "DeptStdSkillList5.xls"); FileOutputStream fos = new FileOutputStream(output); workbook.write(fos); fos.close(); JasperReportUtils.printXlsToFrontEnd(response, output); output.delete(); tempDir.delete(); }
From source file:tw.edu.chit.struts.action.deptassist.ReportPrintAction.java
/** * /* ww w .jav a 2 s.c o m*/ * * @param mapping org.apache.struts.action.ActionMapping object * @param form org.apache.struts.action.ActionForm object * @param request request javax.servlet.http.HttpServletRequest object * @param response response javax.servlet.http.HttpServletResponse object * @param sterm */ @SuppressWarnings("unchecked") private void printDeptStdSkillList1(ActionMapping mapping, DynaActionForm form, HttpServletRequest request, HttpServletResponse response, String sterm) throws Exception { HttpSession session = request.getSession(false); AdminManager am = (AdminManager) getBean(IConstants.ADMIN_MANAGER_BEAN_NAME); MemberManager mm = (MemberManager) getBean(MEMBER_MANAGER_BEAN_NAME); Member member = (Member) getUserCredential(session).getMember(); Empl empl = mm.findEmplByOid(member.getOid()); ServletContext context = request.getSession().getServletContext(); CodeEmpl codeEmpl = new CodeEmpl(); codeEmpl.setIdno(empl.getUnit()); Example example4CodeEmpl = Example.create(codeEmpl).ignoreCase().enableLike(MatchMode.START); List<CodeEmpl> codeEmpls = (List<CodeEmpl>) am.findSQLWithCriteria(CodeEmpl.class, example4CodeEmpl, null, null); DateFormat df = new SimpleDateFormat("yyyy/MM/dd"); Calendar cal = Calendar.getInstance(); Calendar cal1 = (Calendar) cal.clone(); Calendar cal2 = (Calendar) cal.clone(); if (StringUtils.isNotBlank(form.getString("licenseValidDateStart")) || StringUtils.isNotBlank(form.getString("licenseValidDateEnd"))) { Date from = StringUtils.isBlank(form.getString("licenseValidDateStart")) ? null : Toolket.parseNativeDate(form.getString("licenseValidDateStart")); // ??? Date to = StringUtils.isBlank(form.getString("licenseValidDateEnd")) ? Calendar.getInstance().getTime() : Toolket.parseNativeDate(form.getString("licenseValidDateEnd")); cal1.setTime(from); cal1.set(Calendar.HOUR_OF_DAY, 0); cal1.set(Calendar.MINUTE, 0); cal1.set(Calendar.SECOND, 0); cal1.set(Calendar.MILLISECOND, 0); cal2.setTime(to); cal2.set(Calendar.HOUR_OF_DAY, 23); cal2.set(Calendar.MINUTE, 59); cal2.set(Calendar.SECOND, 59); cal2.set(Calendar.MILLISECOND, 999); } String hql = "SELECT count(*), s FROM StdSkill s WHERE s.deptNo = ? " + "AND s.licenseValidDate BETWEEN ? AND ? " + "GROUP BY s.licenseCode"; List<Object> ret = (List<Object>) am.find(hql, new Object[] { //codeEmpls.get(0).getIdno2().trim(), cal1.getTime(),cal2.getTime() }); empl.getUnit(), cal1.getTime(), cal2.getTime() }); HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet(""); sheet.setColumnWidth(0, 1500); sheet.setColumnWidth(1, 10000); sheet.setColumnWidth(2, 3000); sheet.setColumnWidth(3, 3000); sheet.setColumnWidth(4, 8000); sheet.setColumnWidth(5, 1800); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 5)); HSSFFont fontSize12 = workbook.createFont(); fontSize12.setFontHeightInPoints((short) 12); fontSize12.setFontName("Arial Unicode MS"); HSSFFont fontSize10 = workbook.createFont(); fontSize10.setFontHeightInPoints((short) 10); fontSize10.setFontName("Arial Unicode MS"); // Header Toolket.setCellValue(workbook, sheet, 0, 0, "?" + Toolket.getEmpUnit(empl.getUnit()) + " (" + df.format(cal1.getTime()) + "~" + df.format(cal2.getTime()) + ")", fontSize12, HSSFCellStyle.ALIGN_CENTER, false, 35.0F, null); // Column Header Toolket.setCellValue(workbook, sheet, 1, 0, "?", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 1, "??", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 2, "/", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 3, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 4, "?", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 5, "?", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); int index = 2, totals = 0; StdSkill skill = null; List<LicenseCode> codes = null; List<LicenseCode961> code961s = null; LicenseCode code = null; LicenseCode961 code961 = null; Object[] data = null; for (Object o : ret) { data = (Object[]) o; totals += (Long) data[0]; skill = (StdSkill) data[1]; Toolket.setCellValue(workbook, sheet, index, 0, String.valueOf(index - 1), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index, 5, ((Long) data[0]).toString(), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); CourseManager cm = (CourseManager) getBean(IConstants.COURSE_MANAGER_BEAN_NAME); LicenseCode c = (LicenseCode) cm .hqlGetBy("FROM LicenseCode WHERE code='" + skill.getLicenseCode() + "'").get(0); //System.out.println("FROM LicenseCode WHERE code='"+skill.getLicenseCode()+"'"); codes = (List<LicenseCode>) am.findLicenseCodesBy(c); LicenseType type = new LicenseType(); if (!codes.isEmpty()) { code = codes.get(0); Toolket.setCellValue(workbook, sheet, index, 1, code.getName(), fontSize10, HSSFCellStyle.ALIGN_LEFT, true, null); Toolket.setCellValue(workbook, sheet, index, 2, code.getLevel(), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); try { Toolket.setCellValue(workbook, sheet, index, 3, code.getType(), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index, 4, code.getDeptName(), fontSize10, HSSFCellStyle.ALIGN_LEFT, true, null); } catch (Exception e) { e.printStackTrace(); Toolket.setCellValue(workbook, sheet, index, 3, null, fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index, 4, null, fontSize10, HSSFCellStyle.ALIGN_LEFT, true, null); } } else { code961s = (List<LicenseCode961>) am .findLicenseCode961sBy(new LicenseCode961(String.valueOf(skill.getLicenseCode()))); if (!code961s.isEmpty()) { code961 = code961s.get(0); Toolket.setCellValue(workbook, sheet, index, 1, code961.getName(), fontSize10, HSSFCellStyle.ALIGN_LEFT, true, null); Toolket.setCellValue(workbook, sheet, index, 2, code961.getLevel(), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index, 3, code961.getType().toString(), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index, 4, code961.getDeptName(), fontSize10, HSSFCellStyle.ALIGN_LEFT, true, null); } } index++; } sheet.addMergedRegion(new CellRangeAddress(index, index, 0, 4)); Toolket.setCellValue(workbook, sheet, index, 0, "?", fontSize12, HSSFCellStyle.ALIGN_CENTER, false, 35.0F, null); Toolket.setCellValue(workbook, sheet, index, 5, String.valueOf(totals), fontSize12, HSSFCellStyle.ALIGN_CENTER, false, 35.0F, null); File tempDir = new File( context.getRealPath("/WEB-INF/reports/temp/" + getUserCredential(session).getMember().getIdno() + (new SimpleDateFormat("yyyyMMdd").format(new Date())))); if (!tempDir.exists()) tempDir.mkdirs(); File output = new File(tempDir, "DeptStdSkillList1.xls"); FileOutputStream fos = new FileOutputStream(output); workbook.write(fos); fos.close(); JasperReportUtils.printXlsToFrontEnd(response, output); output.delete(); tempDir.delete(); }
From source file:tw.edu.chit.struts.action.deptassist.ReportPrintAction.java
/** * ?()//w w w .j a v a 2s .co m * * @param mapping org.apache.struts.action.ActionMapping object * @param form org.apache.struts.action.ActionForm object * @param request request javax.servlet.http.HttpServletRequest object * @param response response javax.servlet.http.HttpServletResponse object * @param sterm */ @SuppressWarnings("unchecked") private void printDeptStdSkillList(ActionMapping mapping, DynaActionForm form, HttpServletRequest request, HttpServletResponse response, String sterm) throws Exception { HttpSession session = request.getSession(false); AdminManager am = (AdminManager) getBean(IConstants.ADMIN_MANAGER_BEAN_NAME); CourseManager cm = (CourseManager) getBean(IConstants.COURSE_MANAGER_BEAN_NAME); MemberManager mm = (MemberManager) getBean(MEMBER_MANAGER_BEAN_NAME); CourseManager manager = (CourseManager) getBean("courseManager"); Member member = (Member) getUserCredential(session).getMember(); Empl empl = mm.findEmplByOid(member.getOid()); ServletContext context = request.getSession().getServletContext(); CodeEmpl codeEmpl = new CodeEmpl(); codeEmpl.setIdno(empl.getUnit()); Example example4CodeEmpl = Example.create(codeEmpl).ignoreCase().enableLike(MatchMode.START); List<CodeEmpl> codeEmpls = (List<CodeEmpl>) am.findSQLWithCriteria(CodeEmpl.class, example4CodeEmpl, null, null); List<StdSkill> skills = null; StdSkill skill = new StdSkill(); skill.setAmount(null); // ?? Example example = Example.create(skill).ignoreCase().enableLike(MatchMode.ANYWHERE); List<Order> orders = new LinkedList<Order>(); orders.add(Order.asc("schoolYear")); orders.add(Order.asc("schoolTerm")); orders.add(Order.asc("studentNo")); Criterion deptNo = Restrictions.eq("deptNo", codeEmpls.get(0).getIdno2().trim()); // DateFormat df = new SimpleDateFormat("yyyy/MM/dd"); if (StringUtils.isNotBlank(form.getString("licenseValidDateStart")) || StringUtils.isNotBlank(form.getString("licenseValidDateEnd"))) { Calendar cal = Calendar.getInstance(); Calendar cal1 = (Calendar) cal.clone(); Calendar cal2 = (Calendar) cal.clone(); Date from = StringUtils.isBlank(form.getString("licenseValidDateStart")) ? null : Toolket.parseNativeDate(form.getString("licenseValidDateStart")); // ??? Date to = StringUtils.isBlank(form.getString("licenseValidDateEnd")) ? Calendar.getInstance().getTime() : Toolket.parseNativeDate(form.getString("licenseValidDateEnd")); cal1.setTime(from); cal1.set(Calendar.HOUR_OF_DAY, 0); cal1.set(Calendar.MINUTE, 0); cal1.set(Calendar.SECOND, 0); cal1.set(Calendar.MILLISECOND, 0); cal2.setTime(to); cal2.set(Calendar.HOUR_OF_DAY, 23); cal2.set(Calendar.MINUTE, 59); cal2.set(Calendar.SECOND, 59); cal2.set(Calendar.MILLISECOND, 999); Criterion licenseValidDate = Restrictions.between("licenseValidDate", cal1.getTime(), cal2.getTime()); skills = (List<StdSkill>) am.findSQLWithCriteria(StdSkill.class, example, null, orders, deptNo, licenseValidDate); } else skills = (List<StdSkill>) am.findSQLWithCriteria(StdSkill.class, example, null, orders, deptNo); File templateXLS = new File(context.getRealPath("/WEB-INF/reports/DeptStdSkillList.xls")); HSSFWorkbook workbook = Toolket.getHSSFWorkbook(templateXLS); HSSFSheet sheet = workbook.getSheetAt(0); Toolket.setCellValue(sheet, 0, 0, "?()"); int index = 2; List<LicenseCode> codes = null; Student student = null; Graduate graduate = null; DEmpl dempl = null; Csno csno = null; DateFormat df1 = new SimpleDateFormat("yyyy/MM"); for (StdSkill ss : skills) { codes = (List<LicenseCode>) am.findLicenseCodesBy(new LicenseCode(String.valueOf(ss.getLicenseCode()))); if (!codes.isEmpty()) ss.setLicense(codes.get(0)); student = mm.findStudentByNo(ss.getStudentNo().trim()); if (student == null) { graduate = mm.findGraduateByStudentNo(ss.getStudentNo().trim()); if (graduate != null) { ss.setStudentName(graduate.getStudentName().trim()); ss.setDepartClass(Toolket.getClassFullName(graduate.getDepartClass())); } } else { ss.setStudentName(student.getStudentName().trim()); ss.setDepartClass(Toolket.getClassFullName(student.getDepartClass())); } Toolket.setCellValue(sheet, index, 0, ss.getSchoolYear() + "." + ss.getSchoolTerm()); Toolket.setCellValue(sheet, index, 1, ss.getStudentNo().toUpperCase()); Toolket.setCellValue(sheet, index, 2, ss.getStudentName()); Toolket.setCellValue(sheet, index, 3, ss.getDepartClass()); Toolket.setCellValue(sheet, index, 4, ss.getLicense().getCode().trim()); Toolket.setCellValue(sheet, index, 5, ss.getLicense().getDeptName().trim()); Toolket.setCellValue(sheet, index, 6, ss.getLicense().getName().trim()); //Toolket.setCellValue(sheet, index, 7, ss.getLicense().getLocale() // .toString()); String locale = manager .ezGetString("SELECT Locale FROM LicenseCode WHERE Code='" + ss.getLicenseCode() + "'"); String localename = ""; if (locale.equals("1")) localename = ""; if (locale.equals("2")) localename = ""; if (locale.equals("3")) localename = "??"; Toolket.setCellValue(sheet, index, 7, localename); Toolket.setCellValue(sheet, index, 8, ss.getLicense().getLevel().trim()); //Toolket.setCellValue(sheet, index, 9, ss.getLicense().getType() // .toString()); String Type = manager .ezGetString("SELECT Type FROM LicenseCode WHERE Code='" + ss.getLicenseCode() + "'"); String Typename = ""; if (Type.equals("1")) Typename = "?"; if (Type.equals("2")) Typename = ""; if (Type.equals("3")) Typename = ""; if (Type.equals("4")) Typename = ""; Toolket.setCellValue(sheet, index, 9, Typename); Toolket.setCellValue(sheet, index, 10, ss.getAmount().toString()); Toolket.setCellValue(sheet, index, 11, Toolket.getAmountType(ss.getAmountType())); Toolket.setCellValue(sheet, index, 12, ss.getAmountDate() == null ? "" : df1.format(ss.getAmountDate())); Toolket.setCellValue(sheet, index, 13, ss.getLicenseNo()); Toolket.setCellValue(sheet, index, 14, df.format(ss.getLicenseValidDate())); if (StringUtils.isNotBlank(ss.getCscode())) { csno = cm.findCourseInfoByCscode(ss.getCscode()); if (csno != null) Toolket.setCellValue(sheet, index, 15, csno.getChiName().trim()); } else Toolket.setCellValue(sheet, index, 15, ""); if (StringUtils.isNotBlank(ss.getTechIdno())) { empl = mm.findEmplByIdno(ss.getTechIdno()); if (empl != null) Toolket.setCellValue(sheet, index, 16, empl.getCname().trim()); else { dempl = mm.findDEmplByIdno(ss.getTechIdno()); if (dempl != null) Toolket.setCellValue(sheet, index, 16, dempl.getCname().trim()); } } else Toolket.setCellValue(sheet, index, 16, ""); Toolket.setCellValue(sheet, index, 17, ss.getSerialNo()); Toolket.setCellValue(sheet, index, 18, Toolket.getCustomNo(ss.getCustomNo())); Toolket.setCellValue(sheet, index, 19, Toolket.getPass(ss.getPass())); Toolket.setCellValue(sheet, index++, 20, Toolket.getApplyType(ss.getApplyType())); } File tempDir = new File( context.getRealPath("/WEB-INF/reports/temp/" + getUserCredential(session).getMember().getIdno() + (new SimpleDateFormat("yyyyMMdd").format(new Date())))); if (!tempDir.exists()) tempDir.mkdirs(); File output = new File(tempDir, "DeptStdSkillList.xls"); FileOutputStream fos = new FileOutputStream(output); workbook.write(fos); fos.close(); JasperReportUtils.printXlsToFrontEnd(response, output); output.delete(); tempDir.delete(); }
From source file:tw.edu.chit.struts.action.deptassist.ReportPrintAction.java
/** * ???//from ww w. jav a 2 s .c o m * * @param mapping org.apache.struts.action.ActionMapping object * @param form org.apache.struts.action.ActionForm object * @param request request javax.servlet.http.HttpServletRequest object * @param response response javax.servlet.http.HttpServletResponse object * @param sterm */ @SuppressWarnings("unchecked") private void printDeptStdSkillList4(ActionMapping mapping, DynaActionForm form, HttpServletRequest request, HttpServletResponse response, String sterm) throws Exception { HttpSession session = request.getSession(false); AdminManager am = (AdminManager) getBean(IConstants.ADMIN_MANAGER_BEAN_NAME); MemberManager mm = (MemberManager) getBean(MEMBER_MANAGER_BEAN_NAME); Member member = (Member) getUserCredential(session).getMember(); Empl empl = mm.findEmplByOid(member.getOid()); ServletContext context = request.getSession().getServletContext(); CodeEmpl codeEmpl = new CodeEmpl(); codeEmpl.setIdno(empl.getUnit()); Example example4CodeEmpl = Example.create(codeEmpl).ignoreCase().enableLike(MatchMode.START); List<CodeEmpl> codeEmpls = (List<CodeEmpl>) am.findSQLWithCriteria(CodeEmpl.class, example4CodeEmpl, null, null); DateFormat df = new SimpleDateFormat("yyyy/MM/dd"); Calendar cal = Calendar.getInstance(); Calendar cal1 = (Calendar) cal.clone(); Calendar cal2 = (Calendar) cal.clone(); if (StringUtils.isNotBlank(form.getString("licenseValidDateStart")) || StringUtils.isNotBlank(form.getString("licenseValidDateEnd"))) { Date from = StringUtils.isBlank(form.getString("licenseValidDateStart")) ? null : Toolket.parseNativeDate(form.getString("licenseValidDateStart")); // ??? Date to = StringUtils.isBlank(form.getString("licenseValidDateEnd")) ? Calendar.getInstance().getTime() : Toolket.parseNativeDate(form.getString("licenseValidDateEnd")); cal1.setTime(from); cal1.set(Calendar.HOUR_OF_DAY, 0); cal1.set(Calendar.MINUTE, 0); cal1.set(Calendar.SECOND, 0); cal1.set(Calendar.MILLISECOND, 0); cal2.setTime(to); cal2.set(Calendar.HOUR_OF_DAY, 23); cal2.set(Calendar.MINUTE, 59); cal2.set(Calendar.SECOND, 59); cal2.set(Calendar.MILLISECOND, 999); } // Y boolean flag = form.getString("amountDateType").equalsIgnoreCase("y"); String hql = ""; if (flag) hql = "SELECT COUNT(*), SUM(s.amount), s FROM StdSkill s " + "WHERE s.amountDate IS NOT NULL AND s.deptNo = ? " + "AND s.amountDate IS NOT NULL AND s.licenseValidDate BETWEEN ? AND ? " + "GROUP BY s.licenseCode"; else // ? hql = "SELECT COUNT(*), SUM(s.amount), s FROM StdSkill s " + "WHERE s.amountDate IS NULL AND s.deptNo = ? " + "AND s.amountDate IS NULL AND s.licenseValidDate BETWEEN ? AND ? " + "GROUP BY s.licenseCode"; List<Object> ret = (List<Object>) am.find(hql, new Object[] { codeEmpls.get(0).getIdno2().trim(), cal1.getTime(), cal2.getTime() }); HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("???"); sheet.setColumnWidth(0, 1500); sheet.setColumnWidth(1, 3000); sheet.setColumnWidth(2, 10000); sheet.setColumnWidth(3, 3000); sheet.setColumnWidth(4, 5000); sheet.setColumnWidth(5, 2400); sheet.setColumnWidth(6, 8000); sheet.setColumnWidth(7, 1800); sheet.setColumnWidth(8, 2200); sheet.setColumnWidth(9, 2400); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 9)); HSSFFont fontSize12 = workbook.createFont(); fontSize12.setFontHeightInPoints((short) 12); fontSize12.setFontName("Arial Unicode MS"); HSSFFont fontSize10 = workbook.createFont(); fontSize10.setFontHeightInPoints((short) 10); fontSize10.setFontName("Arial Unicode MS"); // Header Toolket.setCellValue(workbook, sheet, 0, 0, "?" + Toolket.getEmpUnit(empl.getUnit()) + "??? (" + df.format(cal1.getTime()) + "~" + df.format(cal2.getTime()) + ") - " + (flag ? "" : ""), fontSize12, HSSFCellStyle.ALIGN_CENTER, false, 35.0F, null); // Column Header Toolket.setCellValue(workbook, sheet, 1, 0, "?", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 1, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 2, "??", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 3, "/", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 4, "/", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 5, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 6, "?", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 7, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 8, "?", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 9, "?", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); int index = 2, totals = 0, sum = 0; StdSkill skill = null; List<LicenseCode> codes = null; List<LicenseCode961> code961s = null; LicenseCode code = null; LicenseCode961 code961 = null; Object[] data = null; for (Object o : ret) { data = (Object[]) o; totals += (Integer) data[0]; sum += (Integer) data[1]; skill = (StdSkill) data[2]; Toolket.setCellValue(workbook, sheet, index, 0, String.valueOf(index - 1), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index, 7, ((Integer) data[0]).toString(), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index, 8, skill.getAmount().toString(), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index, 9, ((Integer) data[1]).toString(), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); codes = (List<LicenseCode>) am .findLicenseCodesBy(new LicenseCode(String.valueOf(skill.getLicenseCode()))); if (!codes.isEmpty()) { code = codes.get(0); Toolket.setCellValue(workbook, sheet, index, 1, code.getCode(), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index, 2, code.getName(), fontSize10, HSSFCellStyle.ALIGN_LEFT, true, null); Toolket.setCellValue(workbook, sheet, index, 3, code.getLocale().toString(), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index, 4, code.getLevel(), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index, 5, code.getType().toString(), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index, 6, code.getDeptName(), fontSize10, HSSFCellStyle.ALIGN_LEFT, true, null); } else { code961s = (List<LicenseCode961>) am .findLicenseCode961sBy(new LicenseCode961(String.valueOf(skill.getLicenseCode()))); if (!code961s.isEmpty()) { code961 = code961s.get(0); Toolket.setCellValue(workbook, sheet, index, 1, code961.getCode().toString(), fontSize10, HSSFCellStyle.ALIGN_LEFT, true, null); Toolket.setCellValue(workbook, sheet, index, 2, code961.getName(), fontSize10, HSSFCellStyle.ALIGN_LEFT, true, null); Toolket.setCellValue(workbook, sheet, index, 3, code961.getLocale().toString(), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index, 4, code961.getLevel(), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index, 5, code961.getType().toString(), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index, 6, code961.getDeptName(), fontSize10, HSSFCellStyle.ALIGN_LEFT, true, null); } } index++; } Toolket.setCellValue(workbook, sheet, index, 6, "?", fontSize12, HSSFCellStyle.ALIGN_CENTER, false, 35.0F, null); Toolket.setCellValue(workbook, sheet, index, 7, String.valueOf(totals), fontSize12, HSSFCellStyle.ALIGN_CENTER, false, 35.0F, null); Toolket.setCellValue(workbook, sheet, index, 9, String.valueOf(sum), fontSize12, HSSFCellStyle.ALIGN_CENTER, false, 35.0F, null); File tempDir = new File( context.getRealPath("/WEB-INF/reports/temp/" + getUserCredential(session).getMember().getIdno() + (new SimpleDateFormat("yyyyMMdd").format(new Date())))); if (!tempDir.exists()) tempDir.mkdirs(); File output = new File(tempDir, "DeptStdSkillList4.xls"); FileOutputStream fos = new FileOutputStream(output); workbook.write(fos); fos.close(); JasperReportUtils.printXlsToFrontEnd(response, output); output.delete(); tempDir.delete(); }
From source file:tw.edu.chit.struts.action.deptassist.ReportPrintAction.java
/** * //from w ww . j a va 2s. c o m * * @param mapping org.apache.struts.action.ActionMapping object * @param form org.apache.struts.action.ActionForm object * @param request request javax.servlet.http.HttpServletRequest object * @param response response javax.servlet.http.HttpServletResponse object * @param sterm */ @SuppressWarnings("unchecked") private void printDeptStdSkillList3(ActionMapping mapping, DynaActionForm form, HttpServletRequest request, HttpServletResponse response, String sterm) throws Exception { HttpSession session = request.getSession(false); AdminManager am = (AdminManager) getBean(IConstants.ADMIN_MANAGER_BEAN_NAME); MemberManager mm = (MemberManager) getBean(MEMBER_MANAGER_BEAN_NAME); Member member = (Member) getUserCredential(session).getMember(); Empl empl = mm.findEmplByOid(member.getOid()); ServletContext context = request.getSession().getServletContext(); CodeEmpl codeEmpl = new CodeEmpl(); codeEmpl.setIdno(empl.getUnit()); Example example4CodeEmpl = Example.create(codeEmpl).ignoreCase().enableLike(MatchMode.START); List<CodeEmpl> codeEmpls = (List<CodeEmpl>) am.findSQLWithCriteria(CodeEmpl.class, example4CodeEmpl, null, null); Calendar cal = Calendar.getInstance(); Calendar cal1 = (Calendar) cal.clone(); Calendar cal2 = (Calendar) cal.clone(); if (StringUtils.isNotBlank(form.getString("licenseValidDateStart")) || StringUtils.isNotBlank(form.getString("licenseValidDateEnd"))) { Date from = StringUtils.isBlank(form.getString("licenseValidDateStart")) ? null : Toolket.parseNativeDate(form.getString("licenseValidDateStart")); // ??? Date to = StringUtils.isBlank(form.getString("licenseValidDateEnd")) ? Calendar.getInstance().getTime() : Toolket.parseNativeDate(form.getString("licenseValidDateEnd")); cal1.setTime(from); cal1.set(Calendar.HOUR_OF_DAY, 0); cal1.set(Calendar.MINUTE, 0); cal1.set(Calendar.SECOND, 0); cal1.set(Calendar.MILLISECOND, 0); cal2.setTime(to); cal2.set(Calendar.HOUR_OF_DAY, 23); cal2.set(Calendar.MINUTE, 59); cal2.set(Calendar.SECOND, 59); cal2.set(Calendar.MILLISECOND, 999); } String hql = "SELECT COUNT(*) CT, ss.licenseValidDate LVD, ss.licenseCode LC, " + "s.depart_class DC1, s.sex S1, gs.depart_class DC2, gs.sex S2 " + "FROM StdSkill ss LEFT JOIN stmd s ON ss.studentNo = s.student_no " + "LEFT JOIN Gstmd gs ON ss.studentNo = gs.student_no " + "WHERE ss.deptNo = ? AND ss.licenseValidDate >= ? AND ss.licenseValidDate <= ? " + "GROUP BY ss.licenseValidDate, s.depart_class, s.sex, " + "gs.depart_class, gs.sex " + "ORDER BY ss.licenseValidDate, s.depart_class, " + "s.sex, gs.depart_class, gs.sex"; List<Map> ret = (List<Map>) am.findBySQL(hql, new Object[] { //codeEmpls.get(0).getIdno().trim(), cal1.getTime(),cal2.getTime() }); empl.getUnit(), cal1.getTime(), cal2.getTime() }); DateFormat df = new SimpleDateFormat("yyyy/MM/dd"); HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet(""); sheet.setColumnWidth(0, 1800); sheet.setColumnWidth(1, 2000); sheet.setColumnWidth(2, 2000); sheet.setColumnWidth(3, 3000); sheet.setColumnWidth(4, 5000); sheet.setColumnWidth(5, 3000); sheet.setColumnWidth(6, 8000); sheet.setColumnWidth(7, 3000); sheet.setColumnWidth(8, 4000); sheet.setColumnWidth(9, 2200); sheet.setColumnWidth(10, 2200); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 10)); HSSFFont fontSize12 = workbook.createFont(); fontSize12.setFontHeightInPoints((short) 12); fontSize12.setFontName("Arial Unicode MS"); HSSFFont fontSize10 = workbook.createFont(); fontSize10.setFontHeightInPoints((short) 10); fontSize10.setFontName("Arial Unicode MS"); // Header Toolket.setCellValue(workbook, sheet, 0, 0, "?" + Toolket.getEmpUnit(empl.getUnit()) + " (" + df.format(cal1.getTime()) + "~" + df.format(cal2.getTime()) + ")", fontSize12, HSSFCellStyle.ALIGN_CENTER, false, 35.0F, null); // Column Header Toolket.setCellValue(workbook, sheet, 1, 0, "?", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 1, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 2, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 3, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 4, "?", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 5, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 6, "??", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 7, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 8, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 9, "()", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, 1, 10, "()", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); // Toolket.setCellValue(workbook, sheet, 1, 11, "?", fontSize10, // HSSFCellStyle.ALIGN_CENTER, true, null); int index = 2; boolean isGraduate = false; String departClass = null; List<LicenseCode> codes = null; List<LicenseCode961> code961s = null; List<DeptCode4Yun> yuns = null; LicenseCode code = null; LicenseCode961 code961 = null; DeptCode4Yun yun = null; Example example = null; for (Map data : ret) { Toolket.setCellValue(workbook, sheet, index, 0, String.valueOf(index - 1), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); if (data.get("DC1") != null) { departClass = (String) data.get("DC1"); isGraduate = false; } else { departClass = (String) data.get("DC2"); isGraduate = true; } yun = new DeptCode4Yun(); yun.setClassNo(StringUtils.substring(departClass, 0, 4)); example = Example.create(yun).ignoreCase().enableLike(MatchMode.START); yuns = (List<DeptCode4Yun>) am.findSQLWithCriteria(DeptCode4Yun.class, example, null, null); if (!yuns.isEmpty() && yuns.size() == 1) { yun = yuns.get(0); Toolket.setCellValue(workbook, sheet, index, 1, yun.getDeptCode(), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index, 2, yun.getCampusCode(), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index, 3, yun.getCampusName(), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); } Toolket.setCellValue(workbook, sheet, index, 4, Toolket.getClassFullName(departClass), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index, 5, (String) data.get("LC"), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); codes = (List<LicenseCode>) am .findLicenseCodesBy(new LicenseCode(String.valueOf((String) data.get("LC")))); if (!codes.isEmpty()) { code = codes.get(0); Toolket.setCellValue(workbook, sheet, index, 6, code.getName(), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index, 7, code.getLevel(), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); } else { code961s = (List<LicenseCode961>) am .findLicenseCode961sBy(new LicenseCode961(String.valueOf((String) data.get("LC")))); if (!code961s.isEmpty()) { code961 = code961s.get(0); Toolket.setCellValue(workbook, sheet, index, 6, code961.getName(), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index, 7, code961.getLevel(), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); } } Toolket.setCellValue(workbook, sheet, index, 8, df.format((Date) data.get("LVD")), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); if (!isGraduate) { if ("1".equals((String) data.get("S1"))) { Toolket.setCellValue(workbook, sheet, index, 9, ((Long) data.get("CT")).toString(), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index, 10, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); } else if ("2".equals((String) data.get("S1"))) { Toolket.setCellValue(workbook, sheet, index, 9, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index, 10, ((Long) data.get("CT")).toString(), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); } } else { if ("1".equals((String) data.get("S2"))) { Toolket.setCellValue(workbook, sheet, index, 9, ((Long) data.get("CT")).toString(), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index, 10, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); } else if ("2".equals((String) data.get("S2"))) { Toolket.setCellValue(workbook, sheet, index, 9, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); Toolket.setCellValue(workbook, sheet, index, 10, ((Long) data.get("CT")).toString(), fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null); } } index++; // Toolket.setCellValue(workbook, sheet, index++, 11, ((Long) m // .get("CT")).toString(), fontSize10, // HSSFCellStyle.ALIGN_CENTER, true, null); } File tempDir = new File( context.getRealPath("/WEB-INF/reports/temp/" + getUserCredential(session).getMember().getIdno() + (new SimpleDateFormat("yyyyMMdd").format(new Date())))); if (!tempDir.exists()) tempDir.mkdirs(); File output = new File(tempDir, "DeptStdSkillList3.xls"); FileOutputStream fos = new FileOutputStream(output); workbook.write(fos); fos.close(); JasperReportUtils.printXlsToFrontEnd(response, output); output.delete(); tempDir.delete(); }
From source file:org.sakaiproject.sitestats.impl.StatsManagerImpl.java
public SummaryActivityTotals getSummaryActivityTotals(String siteId, PrefsData prefsdata) { SummaryActivityTotals sat = new SummaryActivityTotalsImpl(); Date now = new Date(); Calendar c = Calendar.getInstance(); Calendar cl = null;//from w ww . j a v a 2 s . c o m c.set(Calendar.HOUR_OF_DAY, 23); c.set(Calendar.MINUTE, 59); c.set(Calendar.SECOND, 59); cl = (Calendar) c.clone(); cl.add(Calendar.DATE, -6); Date lastWeek = cl.getTime(); cl = (Calendar) c.clone(); cl.add(Calendar.DATE, -29); Date lastMonth = cl.getTime(); cl = (Calendar) c.clone(); c.add(Calendar.MONTH, -11); Date lastYear = cl.getTime(); double last7DaysActivityAverage = Util .round(getTotalSiteActivity(siteId, prefsdata.getToolEventsStringList(), lastWeek, now) / 7.0, 1); double last30DaysActivityAverage = Util .round(getTotalSiteActivity(siteId, prefsdata.getToolEventsStringList(), lastMonth, now) / 30.0, 1); double last365DaysActivityAverage = Util .round(getTotalSiteActivity(siteId, prefsdata.getToolEventsStringList(), lastYear, now) / 365.0, 1); sat.setLast7DaysActivityAverage(last7DaysActivityAverage); sat.setLast30DaysActivityAverage(last30DaysActivityAverage); sat.setLast365DaysActivityAverage(last365DaysActivityAverage); long totalActivity = getTotalSiteActivity(siteId, prefsdata.getToolEventsStringList()); sat.setTotalActivity(totalActivity); return sat; }
From source file:org.sakaiproject.sitestats.impl.StatsManagerImpl.java
public SummaryVisitsTotals getSummaryVisitsTotals(String siteId) { SummaryVisitsTotals svt = new SummaryVisitsTotalsImpl(); Date now = new Date(); Calendar c = Calendar.getInstance(); Calendar cl = null;//from w ww . j a v a 2 s . c om c.set(Calendar.HOUR_OF_DAY, 23); c.set(Calendar.MINUTE, 59); c.set(Calendar.SECOND, 59); cl = (Calendar) c.clone(); cl.add(Calendar.DATE, -6); Date lastWeek = cl.getTime(); cl = (Calendar) c.clone(); cl.add(Calendar.DATE, -29); Date lastMonth = cl.getTime(); cl = (Calendar) c.clone(); c.add(Calendar.MONTH, -11); Date lastYear = cl.getTime(); double last7DaysVisitsAverage = Util.round(getTotalSiteVisits(siteId, lastWeek, now) / 7.0, 1); double last30DaysVisitsAverage = Util.round(getTotalSiteVisits(siteId, lastMonth, now) / 30.0, 1); double last365DaysVisitsAverage = Util.round(getTotalSiteVisits(siteId, lastYear, now) / 365.0, 1); svt.setLast7DaysVisitsAverage(last7DaysVisitsAverage); svt.setLast30DaysVisitsAverage(last30DaysVisitsAverage); svt.setLast365DaysVisitsAverage(last365DaysVisitsAverage); long totalSiteUniqueVisits = getTotalSiteUniqueVisits(siteId); long totalSiteVisits = getTotalSiteVisits(siteId); int totalSiteUsers = getTotalSiteUsers(siteId); double percentageOfUsersThatVisitedSite = totalSiteUsers == 0 ? 0 : (100 * totalSiteUniqueVisits) / (double) totalSiteUsers; svt.setTotalUniqueVisits(totalSiteUniqueVisits); svt.setTotalVisits(totalSiteVisits); svt.setTotalUsers(totalSiteUsers); svt.setPercentageOfUsersThatVisitedSite(Util.round(percentageOfUsersThatVisitedSite, 1)); return svt; }