Java tutorial
package com.dz.module.charge; import com.dz.common.factory.HibernateSessionFactory; import com.dz.common.global.DateUtil; import com.dz.common.global.MD5; import com.dz.common.global.TimePass; import com.dz.common.other.ObjectAccess; import com.dz.module.contract.BankCard; import com.dz.module.contract.Contract; import com.dz.module.contract.ContractDao; import com.dz.module.contract.ContractService; import com.dz.module.vehicle.Vehicle; import com.dz.module.vehicle.VehicleDao; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; import com.sun.mail.iap.Response; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.Predicate; import org.apache.commons.collections.Transformer; import org.apache.struts2.ServletActionContext; import org.hibernate.HibernateException; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction; import org.jxls.common.Context; import org.jxls.util.JxlsHelper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; import java.io.*; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.*; import javax.servlet.http.HttpServletRequest; /** * @author doggy * Created on 15-11-8. */ @Controller @Scope(value = "prototype") public class ChargeAction extends ActionSupport { private static final int EVERYPAGE = 20; /** * */ private static final long serialVersionUID = -8426604215311846476L; private static final String STRING_RESULT = "string_result"; private static final String JSON_RESULT = "json_result"; private static final String DISPATCH = "dispatch"; @Autowired private ChargeService service; @Autowired private ContractService contractService; private String jspPage; private String nextAction; private String ajax_message; private Object jsonObject; private ChargePlan chargePlan; private BatchPlan batchPlan; private String licenseNum; private Date time; private TimePass timePass; private String message; private String visitType; private String jsonStr; private String filename; private String department; private String feeType; private String recorder; private int status; private int id; private InputStream txtFile; private String fileName; //???? private String isToEnd; //?. private int currentPage; //. private int pageLimit; private BankRecordTmp tmp; /*********************************************************************************************************************/ /**************************************Add the method that need page limit here.**************************************/ /*********************************************************************************************************************/ // public String mainCharge() { Date current = service.getCurrentTime("total"); // if(currentPage == 0) // currentPage = 1; // Page page = PageUtil.createPage(EVERYPAGE,(int)contractService.searchAllAvaliableCount(current,""),currentPage); // pageLimit = page.getTotalPage(); List<CheckChargeTable> tables = service.getAllCheckChargeTable(current, "", null, 4); ActionContext context = ActionContext.getContext(); @SuppressWarnings("unchecked") Map<String, Object> request = (Map<String, Object>) context.get("request"); request.put("tables", tables); jspPage = "show/getCheckChargeTableByDept.jsp"; return SUCCESS; } /** * ?. * @return SUCCESS */ public String planDetailMulCar() { List<PlanDetail> details = new ArrayList<>(); if (!(time == null || department == null)) { details = service.planDetailMultiplyCar(department, time, null); } ActionContext context = ActionContext.getContext(); @SuppressWarnings("unchecked") Map<String, Object> request = (Map<String, Object>) context.get("request"); request.put("table", details); jspPage = "plan_detail_mul_car_show.jsp"; return SUCCESS; } // file:bankfile_export.jsp public String exportBankFile() { // if(currentPage == 0) // currentPage = 1; // Page page = PageUtil.createPage(EVERYPAGE*2,(int)contractService.searchAllAvaliableCount(time,department),currentPage); // pageLimit = page.getTotalPage(); // List<BankRecord> records = service.exportBankFile(time,department,page); List<BankRecord> records = service.exportBankFile(time, department); ActionContext context = ActionContext.getContext(); @SuppressWarnings("unchecked") Map<String, Object> request = (Map<String, Object>) context.get("request"); request.put("bankRecords", records); jspPage = "bankfile_export.jsp"; return SUCCESS; } //?? public String getCheckChargeTable() { // if(currentPage == 0) // currentPage = 1; // Page page = PageUtil.createPage(EVERYPAGE,(int)contractService.searchAllAvaliableCount(time,department),currentPage); // pageLimit = page.getTotalPage(); List<CheckChargeTable> tables = service.getAllCheckChargeTable(time, department, null, 4); ActionContext context = ActionContext.getContext(); @SuppressWarnings("unchecked") Map<String, Object> request = (Map<String, Object>) context.get("request"); request.put("tables", tables); jspPage = "check_charge_table.jsp"; return SUCCESS; } // public String tongji(){ // if(currentPage == 0) // currentPage = 1; // Page page = PageUtil.createPage(EVERYPAGE,(int)contractService.searchAllAvaliableCount(time,department),currentPage); // pageLimit = page.getTotalPage(); // if(licenseNum != null) // page = null; // System.out.println(licenseNum); // List<CheckChargeTable> tables = service.getAllCheckChargeTable(time,department,page); // ActionContext context = ActionContext.getContext(); // @SuppressWarnings("unchecked") // Map<String,Object> request = (Map<String,Object>)context.get("request"); // CollectionUtils.filter(tables, new Predicate() { // @Override // public boolean evaluate(Object o) { // CheckChargeTable cct = (CheckChargeTable) o; // if (licenseNum != null && !cct.getCarNumber().contains(licenseNum)) return false; // // // if (status == 0) { // if (cct.getThisMonthTotalOwe().doubleValue() >= 0) // return false; // // // } else if (status == 1) { // if (cct.getThisMonthTotalOwe().doubleValue() < 0) // return false; // // // } else if (status == 2) { // if (cct.getBank().doubleValue() > 0) // return false; // // // } else if (status == 3) { // if (cct.getBank().doubleValue() <= 0) // return false; // } // return true; // } // }); // request.put("tables", tables); // jspPage="show/tongji.jsp"; // return SUCCESS; // } public String tongji() { //? // if(currentPage == 0) // currentPage = 1; //status 0,1,2,3,4 ,,,, // int count; // if(licenseNum != null&&licenseNum.length()==7) // count = 1; // else // count = (int) contractService.searchAllAvaliableCount(time,department,licenseNum); // Page page = PageUtil.createPage(EVERYPAGE,count,currentPage); // pageLimit = page.getTotalPage(); List<CheckChargeTable> tables = service.getAllCheckChargeTable(time, department, licenseNum, status); HttpServletRequest request = ServletActionContext.getRequest(); request.setAttribute("tables", tables); request.setAttribute("currentClearTime", time); jspPage = "show/tongji.jsp"; return SUCCESS; } /***********************************************************************************************************/ /*********************************************END***********************************************************/ /***********************************************************************************************************/ /** * ?. * @return SUCCESS */ public String planDetailOneCar() { List<PlanDetail> details = new ArrayList<>(); if (!(timePass == null || timePass.getStartTime() == null || timePass.getEndTime() == null)) { details = service.planDetailOneCar(licenseNum, timePass.getStartTime(), timePass.getEndTime()); } ActionContext context = ActionContext.getContext(); @SuppressWarnings("unchecked") Map<String, Object> request = (Map<String, Object>) context.get("request"); request.put("table", details); jspPage = "plan_detail_one_car_show.jsp"; return SUCCESS; } public String getCheckChargeTableToExcel() { try (InputStream is = new FileInputStream(System.getProperty("com.dz.root") + "charge/check_table.xls")) { File file = File.createTempFile("", "xls"); try (OutputStream os = new FileOutputStream(file)) { Context context = new Context(); List<CheckChargeTable> tables = service.getAllCheckChargeTable(time, department, null, 4); context.putVar("checks", tables); JxlsHelper.getInstance().processTemplate(is, os, context); fileName = new String(".xls".getBytes(), "iso8859-1"); this.setTxtFile(new FileInputStream(file)); } catch (IOException e) { // TODO ? catch ? e.printStackTrace(); } } catch (FileNotFoundException e1) { // TODO ? catch ? e1.printStackTrace(); } catch (IOException e1) { // TODO ? catch ? e1.printStackTrace(); } return "stream"; } //? public String getCheckChargeTableByDept() { Date current = service.getCurrentTime(department); List<CheckChargeTable> tables = service.getAllCheckChargeTable(current, department, null, 4); ActionContext context = ActionContext.getContext(); @SuppressWarnings("unchecked") Map<String, Object> request = (Map<String, Object>) context.get("request"); request.put("tables", tables); jspPage = "show/getCheckChargeTableByDept.jsp"; return SUCCESS; } //?? file:a_car_check_charge_table public String getACarChargeTable() { List<CheckTablePerCar> tables = service.getACarChargeTable(licenseNum, timePass); ActionContext context = ActionContext.getContext(); @SuppressWarnings("unchecked") Map<String, Object> request = (Map<String, Object>) context.get("request"); request.put("a_car_table", tables); jspPage = "show/a_car_check_charge_table.jsp"; return SUCCESS; } //? public String exportACarChargeTable() { try (InputStream is = new FileInputStream( System.getProperty("com.dz.root") + "charge/a_car_check_table.xls")) { File file = File.createTempFile("?", "xls"); try (OutputStream os = new FileOutputStream(file)) { Context context = new Context(); List<CheckTablePerCar> tables = service.getACarChargeTable(licenseNum, timePass); context.putVar("checks", tables); JxlsHelper.getInstance().processTemplate(is, os, context); fileName = new String("?.xls".getBytes(), "iso8859-1"); this.setTxtFile(new FileInputStream(file)); } catch (IOException e) { // TODO ? catch ? e.printStackTrace(); } } catch (FileNotFoundException e1) { // TODO ? catch ? e1.printStackTrace(); } catch (IOException e1) { // TODO ? catch ? e1.printStackTrace(); } return "stream"; } //txt public String exportTxt() throws Exception { List<BankRecord> records = service.exportBankFile(time, department); File f = new File("bankFile.txt"); PrintWriter pw = new PrintWriter(f); for (BankRecord br : records) { if (br.getMoney().intValue() == 0) continue; BankCard bc = br.getBankCards().get("hrb"); if (bc == null) { continue; } String s = br.getLicenseNum() + "|"; s += br.getDriverName().trim() + "|"; s += (bc == null ? " " : bc.getCardNumber()) + "|"; s += br.getMoney().setScale(3).doubleValue(); pw.println(s); } pw.close(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM-" + department + "-"); fileName = sdf.format(time) + ".txt"; fileName = new String(fileName.getBytes(), "ISO8859-1"); txtFile = new FileInputStream(f); return "stream"; } //?? public String clearDirtyTmp() { service.clearBadBankRecords(); jspPage = "bankfile_import.jsp"; return SUCCESS; } //? public String fromTmpToSql() { service.fromTmpToSql(); jspPage = "bankfile_import.jsp"; return SUCCESS; } public String reimportFromTmp() { BankRecordTmp tmp = ObjectAccess.getObject(BankRecordTmp.class, id); if (tmp == null || tmp.getStatus() != 2) { jsonObject = false; } else { tmp.setError(null); tmp.setStatus(0); ObjectAccess.saveOrUpdate(tmp); service.fromTmpToSql(); jsonObject = true; } return JSON_RESULT; } public String updateTmp() { BankRecordTmp r = ObjectAccess.getObject(BankRecordTmp.class, tmp.getId()); if (r == null || r.getStatus() != 2) { jsonObject = false; } else { r.setLicenseNum(tmp.getLicenseNum()); r.setDriverName(tmp.getDriverName()); r.setBankCardNum(tmp.getBankCardNum()); ObjectAccess.saveOrUpdate(r); jsonObject = true; } return JSON_RESULT; } public void rollbackImport() throws IOException { ServletActionContext.getResponse().setContentType("text/plain"); ServletActionContext.getResponse().setCharacterEncoding("utf-8"); PrintWriter out = ServletActionContext.getResponse().getWriter(); JSONArray jarray = JSONArray.fromObject(jsonStr); Session session = HibernateSessionFactory.getSession(); Transaction tx = null; String msg = "???"; int fid = 0; try { tx = session.beginTransaction(); for (int i = 0; i < jarray.size(); i++) { int id = Integer.parseInt(jarray.get(i).toString()); BankRecordTmp bt = (BankRecordTmp) session.get(BankRecordTmp.class, id); String licenseNum = bt.getLicenseNum(); fid = bt.getFid(); Query q_v = session.createQuery("select carframeNum from Vehicle where licenseNum=:carnum"); q_v.setString("carnum", licenseNum); q_v.setMaxResults(1); String carframeNum = q_v.uniqueResult().toString(); Query q_dept = session.createQuery("select branchFirm from Contract where carframeNum=:id "); q_dept.setString("id", carframeNum); q_dept.setMaxResults(1); String dept = q_dept.uniqueResult().toString(); Query query = session.createQuery("from ClearTime where department = :dept"); query.setString("dept", dept); Object obj = query.uniqueResult(); ClearTime ct = (ClearTime) obj; Date current = ct.getCurrent(); if (isYearAndMonth(current, bt.getInTime())) { Query q_c = session .createQuery("delete from ChargePlan where feeType='add_bank' and comment=:id"); q_c.setString("id", "" + id); q_c.executeUpdate(); session.delete(bt); } else { msg = "???"; } } Query q_f = session.createQuery("select count(*) from BankRecordTmp where fid=:id "); q_f.setInteger("id", fid); long ct = (long) q_f.uniqueResult(); if (ct == 0) { BankFile bf = (BankFile) session.get(BankFile.class, fid); session.delete(bf); } tx.commit(); } catch (HibernateException ex) { ex.printStackTrace(); if (tx != null) { tx.rollback(); } msg = "?" + ex.getMessage(); } finally { HibernateSessionFactory.closeSession(); } out.print(msg); out.flush(); out.close(); } //? public String showBankRecords() { ActionContext context = ActionContext.getContext(); @SuppressWarnings("unchecked") Map<String, Object> request = (Map<String, Object>) context.get("request"); List<BankRecordTmp> brts = service.getBankRecordByTimeAndStatus(time, status); request.put("tables", brts); System.out.println(brts); jspPage = "show/showBankRecoeds.jsp"; return SUCCESS; } //? public String getAMonthRecords() { jsonObject = service.getAMonthRecords(licenseNum, time); System.out.println(jsonObject); return JSON_RESULT; } public String getAMonthGetMoney() { ActionContext context = ActionContext.getContext(); @SuppressWarnings("unchecked") Map<String, Object> request = (Map<String, Object>) context.get("request"); List<ChargePlan> plans = service.getAMonthRecords(licenseNum, time); CollectionUtils.filter(plans, new Predicate() { @Override public boolean evaluate(Object o) { ChargePlan cp = (ChargePlan) o; if (cp.getFeeType().startsWith("sub")) { return true; } return false; } }); request.put("plans", plans); jspPage = "show/show_get_money_records.jsp"; return SUCCESS; } public String finalClear() { ActionContext context = ActionContext.getContext(); @SuppressWarnings("unchecked") Map<String, Object> request = (Map<String, Object>) context.get("request"); boolean result = service.finalClearAll(department); if (result) { message = "??"; } else { message = "???"; } request.put("message", message); nextAction = "showClearPage"; return DISPATCH; } //? public String showClearPage() { department = department == null ? "" : department; Date date = service.getCurrentTime(department); System.out.println(date); // List<BankRecord> unClears = service.getUnClearRecord(date,department,null); ActionContext context = ActionContext.getContext(); @SuppressWarnings("unchecked") Map<String, Object> request = (Map<String, Object>) context.get("request"); jspPage = "showClearPage.jsp"; // request.put("unClears",unClears); request.put("message", request.get("message")); return SUCCESS; } public String getCurrentTime() { if ("".equals(department)) department = "total"; jsonObject = service.getCurrentTime(department); return JSON_RESULT; } public String getCurrentMonth() { Date current = service.getCurrentTime(department); Calendar cal = Calendar.getInstance(); cal.setTime(current); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; ajax_message = year + "" + month + ""; return STRING_RESULT; } @SuppressWarnings("deprecation") private boolean isYearAndMonth(Date date1, Date date2) { if (date1 == null || date2 == null) return false; return date1.getYear() == date2.getYear() && date1.getMonth() == date2.getMonth(); } @SuppressWarnings("deprecation") private boolean isYM1BGYM2(Date date1, Date date2) { int year1 = date1.getYear(); int month1 = date1.getMonth(); int year2 = date2.getYear(); int month2 = date2.getMonth(); if (year1 > year2) return true; if (year1 == year2 && month1 >= month2) return true; return false; } private boolean useContractEnd; @Autowired private VehicleDao vehicleDao; @Autowired private ContractDao contractDao; public void setVehicleDao(VehicleDao vehicleDao) { this.vehicleDao = vehicleDao; } public void setContractService(ContractService contractService) { this.contractService = contractService; } public void setContractDao(ContractDao contractDao) { this.contractDao = contractDao; } //??? //??? public String singleCarAndMuiltyMonthCheckShow() { ActionContext context = ActionContext.getContext(); @SuppressWarnings("unchecked") Map<String, Object> request = (Map<String, Object>) context.get("request"); List<CheckChargeTable> tables = new ArrayList<>(); block: { if (timePass == null || licenseNum == null || timePass.getStartTime() == null) { } else { Date start = timePass.getStartTime(); Date end = timePass.getEndTime(); if (useContractEnd || timePass.getEndTime() == null) { Vehicle vehicle = new Vehicle(); vehicle.setLicenseNum(licenseNum); vehicle = vehicleDao.selectByLicense(vehicle); if (vehicle == null) { break block; } Contract contract = contractDao.selectByCarId(vehicle.getCarframeNum(), timePass.getStartTime()); if (contract == null) { break block; } end = contract.getContractEndDate(); } while (isYM1BGYM2(end, start)) { CheckChargeTable cct = service.getSingleCarAndMonthCheckTableByLicenseNum(licenseNum, start); if (cct != null) { tables.add(cct); } start = DateUtil.getNextMonth(start); } } } jspPage = "show/singleCarAndMuiltyMonthCheckShow.jsp"; request.put("tables", tables); return SUCCESS; } //? public String singleCarAndMuiltyMonthDetailShow() { Map<Date, List<ChargePlan>> map = new HashMap<>(); ActionContext context = ActionContext.getContext(); @SuppressWarnings("unchecked") Map<String, Object> request = (Map<String, Object>) context.get("request"); Date start = timePass.getStartTime(); Date end = timePass.getEndTime(); if (end == null || start == null) ; else { while (isYM1BGYM2(end, start)) { List<ChargePlan> plans = service.getAMonthRecords(licenseNum, start); if (start.getDate() > 26) { Calendar dt = Calendar.getInstance(); dt.setTime(start); dt.add(Calendar.MONTH, 1); plans = service.getAMonthRecords(licenseNum, dt.getTime()); } else { plans = service.getAMonthRecords(licenseNum, start); } CollectionUtils.filter(plans, new Predicate() { @Override public boolean evaluate(Object o) { if (o == null) return false; ChargePlan cp = (ChargePlan) o; if (!cp.getFeeType().startsWith("plan")) return false; return true; } }); map.put(start, plans); start = DateUtil.getNextMonth(start); } } request.put("map", map); jspPage = "show/singleCarAndMuiltyMonthDetailShow.jsp"; return SUCCESS; } /**??*/ public String getACarAndAMonthCheckTable() { TimePass tp = new TimePass(); tp.setStartTime(time); tp.setEndTime(time); List<CheckTablePerCar> tables = service.getACarChargeTable(licenseNum, tp); ActionContext context = ActionContext.getContext(); @SuppressWarnings("unchecked") Map<String, Object> request = (Map<String, Object>) context.get("request"); request.put("a_car_table", tables); jspPage = "show/a_car_a_month_check_charge_table.jsp"; return SUCCESS; } /** * . * @return */ public String getChargeCount() { System.out.println("Invoked."); ActionContext context = ActionContext.getContext(); @SuppressWarnings("unchecked") Map<String, Object> request = (Map<String, Object>) context.get("request"); Map<String, List<ChargePlan>> map = new HashMap<>(); List<ChargePlan> plans = service.getAll(time, feeType); List<ChargePlan> p_cash = new ArrayList<>(); List<ChargePlan> p_bank = new ArrayList<>(); List<ChargePlan> p_insurance = new ArrayList<>(); List<ChargePlan> p_oil = new ArrayList<>(); List<ChargePlan> p_other = new ArrayList<>(); BigDecimal bd_cash = new BigDecimal(0.00); BigDecimal bd_bank = new BigDecimal(0.00); BigDecimal bd_insurance = new BigDecimal(0.00); BigDecimal bd_oil = new BigDecimal(0.00); BigDecimal bd_other = new BigDecimal(0.00); for (ChargePlan p : plans) { switch (p.getFeeType()) { case "add_insurance": p_insurance.add(p); bd_insurance = bd_insurance.add(p.getFee()); break; case "add_bank": p_bank.add(p); bd_bank = bd_bank.add(p.getFee()); break; case "add_oil": p_oil.add(p); bd_oil = bd_oil.add(p.getFee()); break; case "add_cash": p_cash.add(p); bd_cash = bd_cash.add(p.getFee()); break; case "add_other": p_other.add(p); bd_other = bd_other.add(p.getFee()); break; } } if (p_oil.size() > 0) { ChargePlan cp_oil = new ChargePlan(); cp_oil.setFeeType("total"); cp_oil.setFee(bd_oil); p_oil.add(cp_oil); map.put("oil", p_oil); } if (p_bank.size() > 0) { ChargePlan cp_bank = new ChargePlan(); cp_bank.setFeeType("total"); cp_bank.setFee(bd_bank); p_bank.add(cp_bank); map.put("bank", p_bank); } if (p_insurance.size() > 0) { ChargePlan cp_insurance = new ChargePlan(); cp_insurance.setFeeType("total"); cp_insurance.setFee(bd_insurance); p_insurance.add(cp_insurance); map.put("insurance", p_insurance); } if (p_cash.size() > 0) { ChargePlan cp_cash = new ChargePlan(); cp_cash.setFeeType("total"); cp_cash.setFee(bd_cash); p_cash.add(cp_cash); map.put("cash", p_cash); } if (p_other.size() > 0) { ChargePlan cp_other = new ChargePlan(); cp_other.setFeeType("total"); cp_other.setFee(bd_other); p_other.add(cp_other); map.put("other", p_other); } request.put("map", map); System.out.println(map.size()); jspPage = "chargeCount.jsp"; return SUCCESS; } /************** Stable and changeless methods below. **************/ /**? file:none.jsp*/ public String analyseFile() { ActionContext context = ActionContext.getContext(); @SuppressWarnings("unchecked") Map<String, Object> request = (Map<String, Object>) context.get("request"); jspPage = "bankfile_import.jsp"; if (!isYearAndMonth(time, service.getCurrentTime("total"))) { message = "???\n"; request.put("message", message); return SUCCESS; } // MD5 md5 = MD5.getInstance(); // String md5Str = md5.GetMD5Code(brs.toString()); // boolean isFileExisted = service.isFileExisted(md5Str); boolean isFileExisted = service.isFileExisted(filename); if (isFileExisted == true) { message = "?"; } else { JSONArray json = JSONArray.fromObject(jsonStr); // json.toArray(); @SuppressWarnings("unchecked") List<BankRecord> brs = (List<BankRecord>) CollectionUtils.collect(json, new Transformer() { @Override public Object transform(Object obj) { JSONObject jso = (JSONObject) obj; BankRecord ai = new BankRecord(); ai.setDriverName(jso.getString("name")); ai.setLicenseNum(jso.getString("licenseNum")); ai.setMoney(BigDecimal.valueOf(Double.parseDouble(jso.getString("Money")))); Map<String, BankCard> map = new HashMap<String, BankCard>(); BankCard bc = new BankCard(); bc.setCardNumber(jso.getString("cardNum")); System.out.println("bc --> " + bc.getCardNumber()); map.put("hrb", bc); ai.setBankCards(map); return ai; } }); Calendar nm = Calendar.getInstance(); nm.setTime(time); if (nm.get(Calendar.DATE) > 26) { nm.add(Calendar.MONTH, 1); } nm.set(Calendar.DATE, 1); int fid = service.writeMd5(filename, nm.getTime()); service.importFile(brs, recorder, fid); message = " ??\n"; // service.writeMd5(md5Str); } request.put("message", message); return SUCCESS; } /** * ??? * @return SUCCESS */ public String searchBPS() { List<BatchPlan> bps = service.searchBatchPlans(licenseNum); Collections.sort(bps, new Comparator<BatchPlan>() { @Override public int compare(BatchPlan o1, BatchPlan o2) { if (o1.getStartTime().getTime() >= o2.getStartTime().getTime()) { return 1; } else { return -1; } } }); for (BatchPlan bp : bps) { String type = bp.getFeeType(); if (type.equals("plan_base_contract")) { bp.setFeeType("??"); } else if (type.equals("plan_add_insurance")) { bp.setFeeType("?"); } else if (type.equals("plan_sub_insurance")) { bp.setFeeType("??"); } else if (type.equals("plan_add_contract")) { bp.setFeeType("??"); } else if (type.equals("plan_sub_contract")) { bp.setFeeType("???"); } else if (type.equals("plan_add_other")) { bp.setFeeType(""); } else if (type.equals("plan_sub_other")) { bp.setFeeType("?"); } } ActionContext context = ActionContext.getContext(); @SuppressWarnings("unchecked") Map<String, Object> request = (Map<String, Object>) context.get("request"); request.put("bps", bps); System.out.println(bps); jspPage = "bps_show.jsp"; return SUCCESS; } /** * ??. * @return JSON_RESULT. */ public String getOweByLicenseNumAndMonth() { jsonObject = service.getSingleCarAndMonthCheckTableByLicenseNum(licenseNum, time); return JSON_RESULT; } /** * . * @return SUCCESS. */ public String getOweDeleteList() { ActionContext context = ActionContext.getContext(); @SuppressWarnings("unchecked") Map<String, Object> request = (Map<String, Object>) context.get("request"); List<ChargePlan> plans = service.getAMonthRecords(licenseNum, time); CollectionUtils.filter(plans, new Predicate() { @Override public boolean evaluate(Object o) { if (o == null) return false; ChargePlan cp = (ChargePlan) o; if (!cp.getFeeType().startsWith("add")) return false; return true; } }); request.put("plans", plans); jspPage = "oweDeletePage.jsp"; return SUCCESS; } public String addChargePlan() { boolean success = service.addChargePlan(chargePlan); if (success) { jspPage = "success.jsp"; } else { jspPage = "error.jsp"; } return SUCCESS; } public String addChargePlanByLicenseNum() { boolean success = service.addChargePlanByLicenseNum(chargePlan, licenseNum); ActionContext context = ActionContext.getContext(); @SuppressWarnings("unchecked") Map<String, Object> request = (Map<String, Object>) context.get("request"); if ("get_money".equals(visitType)) { if (success) { jspPage = "get_money.jsp"; message = "??"; } else { jspPage = "get_money.jsp"; message = "?,????"; } } else if ("charge_add".equals(visitType)) { if (success) { jspPage = "charge_add.jsp"; message = "?"; } else { jspPage = "charge_add.jsp"; message = "????"; } } else { if (success) { jspPage = "success.jsp"; message = "?"; } else { jspPage = "error.jsp"; message = "????"; } } request.put("message", message); return SUCCESS; } public String deleteChargePlan() { boolean success = service.deleteChargePlan(chargePlan); if (success) { ajax_message = "success"; } else { ajax_message = "error"; } return STRING_RESULT; } public String addBatchPlan() { boolean success = false; if ("on".equals(isToEnd)) { batchPlan.setEndTime(null); success = service.addBatchPlan(batchPlan, true); } else { success = service.addBatchPlan(batchPlan, false); } ActionContext context = ActionContext.getContext(); @SuppressWarnings("unchecked") Map<String, Object> request = (Map<String, Object>) context.get("request"); jspPage = "batch_add.jsp"; request.put("message", message); return SUCCESS; } public String addBatchPlanPerCar() { boolean success = false; if ("on".equals(isToEnd)) { batchPlan.setEndTime(null); success = service.addBatchPlanPerCar(batchPlan, licenseNum, true); } else { success = service.addBatchPlanPerCar(batchPlan, licenseNum, false); } ActionContext context = ActionContext.getContext(); context.get("request"); if (success) { jspPage = "percar_add.jsp"; message = "?"; } else { jspPage = "percar_add.jsp"; message = ",?"; } return SUCCESS; } public String deleteBatchPlan() { boolean success = service.deleteBatchPlan(batchPlan); if (success) { ajax_message = "success"; } else { ajax_message = "error"; } return STRING_RESULT; } // public String couldGetMoney() { jsonObject = service.couldGetMoney(licenseNum, time); return JSON_RESULT; } /************** Setter and getter methods below. ******************/ public ChargeService getService() { return service; } public void setService(ChargeService service) { this.service = service; } public ChargePlan getChargePlan() { return chargePlan; } public void setChargePlan(ChargePlan chargePlan) { this.chargePlan = chargePlan; } public String getJspPage() { return jspPage; } public void setJspPage(String jspPage) { this.jspPage = jspPage; } public String getAjax_message() { return ajax_message; } public void setAjax_message(String ajax_message) { this.ajax_message = ajax_message; } public Object getJsonObject() { return jsonObject; } public void setJsonObject(Object jsonObject) { this.jsonObject = jsonObject; } public BatchPlan getBatchPlan() { return batchPlan; } public void setBatchPlan(BatchPlan batchPlan) { this.batchPlan = batchPlan; } public String getLicenseNum() { return licenseNum; } public void setLicenseNum(String licenseNum) { this.licenseNum = licenseNum; } public Date getTime() { return time; } public void setTime(Date time) { this.time = time; } public TimePass getTimePass() { return timePass; } public void setTimePass(TimePass timePass) { this.timePass = timePass; } public String getNextAction() { return nextAction; } public void setNextAction(String nextAction) { this.nextAction = nextAction; } public String getMessage() { return message; } public String getVisitType() { return visitType; } public void setVisitType(String visitType) { this.visitType = visitType; } public void setMessage(String message) { this.message = message; } public String getDepartment() { return department; } public ChargeAction setDepartment(String department) { this.department = department; return this; } public String getRecorder() { return recorder; } public void setRecorder(String recorder) { this.recorder = recorder; } public String getFeeType() { return feeType; } public void setFeeType(String feeType) { this.feeType = feeType; } public String getJsonStr() { return jsonStr; } public void setJsonStr(String jsonStr) { this.jsonStr = jsonStr; } public int getStatus() { return status; } public void setStatus(int status) { this.status = status; } public InputStream getTxtFile() { return txtFile; } public void setTxtFile(InputStream txtFile) { this.txtFile = txtFile; } public String getFileName() { return fileName; } public void setFileName(String fileName) { this.fileName = fileName; } public String getIsToEnd() { return isToEnd; } public void setIsToEnd(String isToEnd) { this.isToEnd = isToEnd; } public int getCurrentPage() { return currentPage; } public void setCurrentPage(int currentPage) { this.currentPage = currentPage; } public int getPageLimit() { return pageLimit; } public void setPageLimit(int pageLimit) { this.pageLimit = pageLimit; } public int getId() { return id; } public void setId(int id) { this.id = id; } public BankRecordTmp getTmp() { return tmp; } public void setTmp(BankRecordTmp tmp) { this.tmp = tmp; } public boolean getUseContractEnd() { return useContractEnd; } public void setUseContractEnd(boolean useContractEnd) { this.useContractEnd = useContractEnd; } public String getFilename() { return filename; } public void setFilename(String filename) { this.filename = filename; } }