Java tutorial
package com.aisino2.icksystem.action; import java.io.ByteArrayOutputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.apache.struts2.ServletActionContext; import org.codehaus.xfire.client.Client; import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.Element; import sun.misc.BASE64Decoder; import com.aisino2.basicsystem.service.IXctbService; import com.aisino2.cache.CacheManager; import com.aisino2.common.QjblUtil; import com.aisino2.common.StringUtil; import com.aisino2.core.dao.Page; import com.aisino2.core.util.EncryptUtil; import com.aisino2.core.web.PageAction; import com.aisino2.icksystem.domain.Icksl; import com.aisino2.icksystem.domain.Ickyj; import com.aisino2.icksystem.domain.Qyryskjl; import com.aisino2.icksystem.service.IIckslService; import com.aisino2.icksystem.service.IIckyjService; import com.aisino2.icksystem.service.IQyryskjlService; import com.aisino2.publicsystem.domain.Qyjbxx; import com.aisino2.publicsystem.domain.Qyryxx; import com.aisino2.publicsystem.domain.Wgcyryxx; import com.aisino2.publicsystem.service.IQyjbxxService; import com.aisino2.publicsystem.service.IQyryxxService; import com.aisino2.publicsystem.service.IWgcyryxxService; import com.aisino2.sysadmin.Constants; import com.aisino2.sysadmin.domain.Department; import com.aisino2.sysadmin.domain.Dict; import com.aisino2.sysadmin.domain.Dict_item; import com.aisino2.sysadmin.domain.Globalpar; import com.aisino2.sysadmin.domain.User; import com.aisino2.sysadmin.service.IDepartmentService; import com.aisino2.sysadmin.service.IDictService; import com.aisino2.sysadmin.service.IDict_itemService; import com.aisino2.sysadmin.service.ISystemService; import com.aisino2.sysadmin.service.IUserService; public class KongJianDiaoYongAction extends PageAction { private IIckslService ickslService; private IDict_itemService dict_itemService; private IQyjbxxService qyjbxxService; private IQyryskjlService qyryskjlService; // ? private IQyryxxService qyryxxService; // ? private IWgcyryxxService wgcyryxxService; private IXctbService xctbService; private IUserService userService; private IDepartmentService departmentService; private IDictService dictService; private IIckyjService ickyjService; private ISystemService systemService; private String type; private String cardid; private String value; private String cyrybh; private String id; private String pwd; private String coid; // dict_id private String devicetype; private String jcz; private String gajg; private String gmsfhm;//???? private String url; //URL public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } public void kongJianDiaoYong() { HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse response = ServletActionContext.getResponse(); try { if (isUserStr(type) && "verifycardid".equals(type)) { // ??? // --- if (isUserStr(cardid)) { // modify on 2010-08-13 by mds begin //cardid = cardid.replace("-", ""); // ?? - ? // modify on 2010-08-13 by mds end Icksl icksl = new Icksl(); icksl.setIckh(cardid); String isDxr = ickslService.sfDxr(icksl); if (isUserStr(isDxr)) { renderText(response, isDxr); } } else { renderText(response, "FALSE"); // } renderText(response, ""); } // ???? - OK if (isUserStr(type) && "islogout".equals(type)) { if (isUserStr(cardid)) { // modify on 2010-08-13 by mds begin //cardid = cardid.replace("-", ""); // ?? - ? // modify on 2010-08-13 by mds end Icksl icksl = new Icksl(); icksl.setIckh(cardid); icksl = ickslService.getIcksl(icksl); // ?? ?? if ("7".equals(icksl.getZkztbs()) || "8".equals(icksl.getZkztbs()) || "9".equals(icksl.getZkztbs())) { renderText(response, "TRUE"); } } else { renderText(response, ""); // 09.06.09 ?? ? } renderText(response, ""); } // ?? - OK if (isUserStr(type) && "offlineversion".equals(type)) { Globalpar globalpar = new Globalpar(); Globalpar temp = null; // globalpar.setGlobalparcode("offline-bbhtest"); // globalpar.setGlobalparcode("offline-bbh"); List globList = CacheManager.getCacheGlobalpar(globalpar); if (globList != null && globList.size() > 0) { temp = (Globalpar) globList.get(0); } String OfflineVersion = temp.getGlobalparvalue().trim().replaceAll(",", "").substring(0, 4); renderText(response, OfflineVersion); } // prjwebcontrol.ocx - OK if (isUserStr(type) && "prjwebcontrol".equals(type)) { // String httpHead = request.getScheme() + "://" // + request.getServerName() + ":" // + request.getServerPort() + request.getContextPath() // + "/"; // String prjWebControlPatch = httpHead // + "active/prjWebControl.ocx"; String activePatch = "";// active? activePatch = QjblUtil.queryQjblVal("active-url"); String prjWebControlPatch = activePatch + "prjWebControl.ocx"; String exeDataString = ""; try { URL fileurl = new URL(prjWebControlPatch); exeDataString = fileToBase64(fileurl); } catch (Exception e) { e.printStackTrace(); } if (exeDataString == null) { exeDataString = ""; } renderText(response, exeDataString); } // - OK if (isUserStr(type) && "offline".equals(type)) { // String httpHead = request.getScheme() + "://" // + request.getServerName() + ":" // + request.getServerPort() + request.getContextPath() // + "/"; // String offlineExePatch = httpHead + "active/offline.exe"; String activePatch = "";// active? activePatch = QjblUtil.queryQjblVal("active-url"); String offlineExePatch = activePatch + "offline.exe"; String exeDataString = ""; try { URL fileurl = new URL(offlineExePatch); exeDataString = fileToBase64(fileurl); } catch (Exception e) { e.printStackTrace(); } if (exeDataString == null) { exeDataString = ""; } renderText(response, exeDataString); } // prjupdate.exe - OK if (isUserStr(type) && "prjupdate".equals(type)) { // String httpHead = request.getScheme() + "://" // + request.getServerName() + ":" // + request.getServerPort() + request.getContextPath() // + "/"; // String offlineExePatch = httpHead + "active/prjupdate.exe"; String activePatch = "";// active? activePatch = QjblUtil.queryQjblVal("active-url"); String prjupdateExePatch = activePatch + "prjupdate.exe"; String exeDataString = ""; try { URL fileurl = new URL(prjupdateExePatch); exeDataString = fileToBase64(fileurl); } catch (Exception e) { e.printStackTrace(); } if (exeDataString == null) { exeDataString = ""; } renderText(response, exeDataString); } // ?? - ?? ?? - OK if (isUserStr(type) && "upload".equals(type)) { //? Icksl icksl = null; Date sksjDates = null; String yjFlag = ""; // 0 1 2?? 3 ? String yjyy = ""; // String dwlb = ""; //?? ? String dwlbdm = ""; //??? ? Dict_item dict_item = new Dict_item(); dict_item.setDict_code("dm_ickyjyy"); SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss"); if (isUserStr(value)) { value = value.replace('_', '+'); value = value.replace('$', '='); value = getFromBASE64(value); String[] valueArray = value.split("%"); String skzdzc = QjblUtil.queryQjblVal("skzdzc");//? 0-? 1- for (int index = 0; index < valueArray.length; index++) { yjFlag = "";// ? yjyy = "";// ? icksl = null;// ? sksjDates = null;// ? String dantiaoString = valueArray[index]; dantiaoString = dantiaoString.replace("$", "%"); String[] dantiaoArray = dantiaoString.split("%"); // String eg = // "CHN$??$J024103030004000253$$$$$$20090615155236$2048070716$?$J023200000003$"; // String eg = // "CHN$$J014103020003090001$310106197709090823$2$$$20090619134629$690744610$$J044101050005$"; String qybm = String.valueOf(dantiaoArray[11]); //qybm=qybm.substring(1, 12); Qyjbxx qyjbxx = new Qyjbxx(); if (qybm.startsWith("N")) { qyjbxx.setQybm(qybm.substring(1, 12)); } else { qyjbxx.setQybm(qybm); } qyjbxx = qyjbxxService.getQyjbxx(qyjbxx); Date sxsj = null;// ? ,? Integer ryid = null; // ,? String kh = null; String sksj = String.valueOf(dantiaoArray[8]); sksj = sksj.substring(0, 4) + "-" + sksj.substring(4, 6) + "-" + sksj.substring(6, 8) + " " + sksj.substring(8, 10) + ":" + sksj.substring(10, 12) + ":" + sksj.substring(12, 14); sksjDates = stringToDate(sksj, "yyyy-MM-dd HH:mm:ss"); String ickh = String.valueOf(dantiaoArray[9]); String cyrybh = dantiaoArray[2]; String zjhm = dantiaoArray[3]; int qyryid = 0; //?? 20100903?? if (skzdzc == null || "".equals(skzdzc) || "1".equals(skzdzc)) { if (qyjbxx != null) { int qyid = qyjbxx.getQyid(); Qyryxx qyryxx = new Qyryxx(); //?14????????? 20110131 mds if (StringUtil.isNotEmpty(cyrybh) && cyrybh.length() == 14) qyryxx.setZjhm(zjhm); else qyryxx.setCyrybh(cyrybh); qyryxx = qyryxxService.getQyryxx(qyryxx); if (qyryxx != null) { qyryid = qyryxx.getRyid(); int qyrrxxQyid = qyryxx.getQyid(); dwlb = qyryxx.getCylb(); dwlbdm = qyryxx.getCylbdm(); //? if (Integer.parseInt(qyryxx.getZt()) < 90 && qyrrxxQyid != qyid) { qyryxx.setQyid(qyid); Date rzrq = modifyCyryRzrq(qyryxx, sksjDates); qyryxx.setRzrq(rzrq); qyryxx.setCyryzt(""); qyryxx.setCyryztdm("11"); qyryxx.setKh(ickh); ickslService.updateIckslByryzc(qyryxx);//t_icksl } else if (Integer.parseInt(qyryxx.getZt()) < 90 && qyrrxxQyid == qyid) { if (qyryxx.getRzrq() == null) { Date rzrq = modifyCyryRzrq(qyryxx, sksjDates); qyryxx.setRzrq(rzrq); qyryxx.setCzlx(""); qyryxx.setCzr(qyryxx.getQybm()); qyryxxService.updateQyryxxOnly(qyryxx); } } } } } else { if (qyjbxx != null) { int qyid = qyjbxx.getQyid(); Qyryxx qyryxx = new Qyryxx(); //?14????????? 20110131 mds if (StringUtil.isNotEmpty(cyrybh) && cyrybh.length() == 14) qyryxx.setZjhm(zjhm); else qyryxx.setCyrybh(cyrybh); qyryxx = qyryxxService.getQyryxx(qyryxx); if (qyryxx != null) { qyryid = qyryxx.getRyid(); int qyrrxxQyid = qyryxx.getQyid(); dwlb = qyryxx.getCylb(); dwlbdm = qyryxx.getCylbdm(); if (Integer.parseInt(qyryxx.getZt()) < 90 && qyryxx.getRzrq() == null) { Date rzrq = modifyCyryRzrq(qyryxx, sksjDates); qyryxx.setRzrq(rzrq); qyryxx.setCzlx(""); qyryxx.setCzr(qyryxx.getQybm()); qyryxxService.updateQyryxxOnly(qyryxx); } } } } // ????14??,?ICKH? --modify at 20100610 /* 20100817????????????IC?????? if (cyrybh != null && cyrybh.length() == 14) { // service?ickh?? icksl = new Icksl(); icksl.setIckh(ickh); icksl = ickslService.getIckslCyrybh(icksl); if (icksl != null) { cyrybh = icksl.getCyrybh(); kh = icksl.getKh(); icksllsh = icksl.getIckslid(); } }*/ /** * ?20100817?IC??????? * ?? ---start--- */ int icksllsh = 0; // service?ickh?? icksl = new Icksl(); icksl.setIckh(ickh); icksl = ickslService.getIckslCyrybh(icksl); if (icksl != null) { cyrybh = icksl.getCyrybh(); kh = icksl.getKh(); icksllsh = icksl.getIckslid(); } /** * IC????????? * 2010-08-16 mds */ else { Icksl ickslTemp = new Icksl(); ickslTemp.setIckh(ickh); ickslService.updateIckslIckh(ickslTemp); } /** * ?20100817?IC??????? * ?? ---end--- */ if (dantiaoArray.length > 12) { kh = dantiaoArray[12]; } // String jczt =dantiaoArray[dantiaoArray.length]; if (qyjbxx != null) { int qyid = qyjbxx.getQyid(); Qyryskjl qyryskjl = new Qyryskjl(); qyryskjl.setQyid(qyid); qyryskjl.setIckh(ickh); // ?? - ? , qyryskjl.setSksj(sksjDates); qyryskjl.setScsj(new Date()); qyryskjl.setCyrybh(cyrybh); if (dantiaoArray.length > 12) { qyryskjl.setKh(dantiaoArray[12]); } // 102025start qyryskjl.setQybm(qyjbxx.getQybm()); qyryskjl.setHylb(qyjbxx.getHylb()); qyryskjl.setHylbdm(qyjbxx.getHylbdm()); // end // --modify on 20100610 if (icksl != null) { qyryskjl.setKh(kh); qyryskjl.setIcksllsh(icksllsh); } // --modify on 20100610 if ("N".equals(qyjbxx.getHylbdm())) { qyryskjl.setJczt(dantiaoArray[dantiaoArray.length - 1]); qyryskjl.setDwlb(dwlb); qyryskjl.setDwlbdm(dwlbdm); qyryskjl = qyryskjlService.insertQyryskjl(qyryskjl); Qyskfbxx qyskfbxx = new Qyskfbxx(); qyryskjl.setRyid(qyryid); qyryskjl.setGxdwbm(qyjbxx.getGxdwbm()); qyryskjl.setGxdwmc(qyjbxx.getGxdwmc()); qyryskjl.setQymc(qyjbxx.getQymc()); qyskfbxx.insertqyskfb(qyryskjl); } else { qyryskjl = qyryskjlService.insertQyryskjl(qyryskjl); } // ?? Integer ickslid = null; String ickslslh = null;// ?? Icksl ickslOne = new Icksl(); // modify on 2010-08-13 by mds begin //ickslOne.setIckh(String.valueOf(dantiaoArray[9]).replace("-", "")); ickslOne.setIckh(String.valueOf(dantiaoArray[9])); // modify on 2010-08-13 by mds end List list = ickslService.getListIcksl(ickslOne); if (list == null || list.size() == 0) { yjFlag = "2";// ? ?? //?? } else { icksl = new Icksl(); // modify on 2010-08-13 by mds begin //icksl.setIckh(String.valueOf(dantiaoArray[9]).replace("-", "")); // ?? - ? icksl.setIckh(String.valueOf(dantiaoArray[9])); // modify on 2010-08-13 by mds end icksl.setCyrybh(dantiaoArray[2]); icksl = ickslService.getIckslyj(icksl); if (icksl == null) { yjFlag = "2"; } // ? ?? //?? else { ickslid = icksl.getIckslid(); // sxsj = icksl.getIckzxsj(); // ickslh = icksl.getIckslh(); ryid = icksl.getRyid(); Qyryxx qyryxx = new Qyryxx(); qyryxx.setRyid(ryid); qyryxx.setScbz(0); qyryxx = qyryxxService.getQyryxx(qyryxx); if (kh == null) { kh = icksl.getKh(); } if ("7".equals(icksl.getZkztbs()) || "8".equals(icksl.getZkztbs()) || "9".equals(icksl.getZkztbs())) { if ("9".equals(icksl.getZkztbs())) { yjFlag = "3"; // ? sxsj = icksl.getYxqhzrq(); } else { yjFlag = "0"; // ? sxsj = icksl.getIckzxsj(); } } else if (!"7".equals(icksl.getZkztbs()) && !"8".equals(icksl.getZkztbs()) && !"9".equals(icksl.getZkztbs())) { String sksjtemp = sksj.substring(0, 10); Date sksjDate = stringToDate(sksjtemp, "yyyy-MM-dd"); if (sksjDate.compareTo(icksl.getYxqhzrq()) >= 0) { yjFlag = "1"; // ? sxsj = icksl.getYxqhzrq(); } } else if ("1".endsWith(qyryxx.getYjbz())) { yjFlag = "4"; // ?? sxsj = qyryxx.getYjsj(); } // ???icksl??qyryskjl if (qyryskjl.getKh() == null) { qyryskjl.setKh(kh); } qyryskjl.setIcksllsh(ickslid); qyryskjlService.updateQyryskjl(qyryskjl); } } } else { yjFlag = "2"; // ? //?? } if (!"".equals(yjFlag)) { // ? Ickyj tempIckyj = new Ickyj(); // Qyryxx cyryxx = new Qyryxx(); Wgcyryxx wgcyryxx = new Wgcyryxx(); if (icksl != null) { cyryxx.setRyid(icksl.getRyid()); cyryxx = qyryxxService.getQyryxx(cyryxx); tempIckyj.setIckh(icksl.getIckh()); } if ("2".equals(yjFlag)) { // ?? cyryxx.setCyrybh(dantiaoArray[2]); cyryxx = qyryxxService.getQyryxx(cyryxx); tempIckyj.setCyrybh(dantiaoArray[2]); // modify on 2010-08-13 by mds begin //tempIckyj.setIckh(String.valueOf(dantiaoArray[9]).replace("-", "")); // ??- ? tempIckyj.setIckh(String.valueOf(dantiaoArray[9])); // modify on 2010-08-13 by mds end } if (cyryxx != null) { tempIckyj.setXmpy(cyryxx.getXm()); tempIckyj.setXb(cyryxx.getXb()); tempIckyj.setCyzj(cyryxx.getCyzj()); tempIckyj.setZjhm(cyryxx.getZjhm()); tempIckyj.setCylb(cyryxx.getCylb()); tempIckyj.setCylbdm(cyryxx.getCylbdm()); tempIckyj.setXmpy(cyryxx.getXmpy()); tempIckyj.setCyrybh(cyryxx.getCyrybh()); tempIckyj.setXm(cyryxx.getXm()); tempIckyj.setCyzjdm(cyryxx.getCyzjdm()); ryid = cyryxx.getRyid(); wgcyryxx.setRyid(cyryxx.getRyid()); wgcyryxx = wgcyryxxService.getWgcyryxx(wgcyryxx); if (wgcyryxx != null) { tempIckyj.setYwm(wgcyryxx.getYwm()); tempIckyj.setYwx(wgcyryxx.getYwx()); tempIckyj.setWgrjyxkz(wgcyryxx.getWgrjyxkz()); } } qybm = "?"; String qymc = "?"; String gxdwdm = "?"; String gxdwmc = "?"; String dsjgdm = "?"; String fxjdm = "?"; String dsjgmc = "?"; String fxjmc = "?"; if (qyjbxx != null) { qybm = qyjbxx.getQybm(); qymc = qyjbxx.getQymc(); gxdwdm = qyjbxx.getGxdwbm(); gxdwmc = qyjbxx.getGxdwmc(); String qybmTemp = qybm.substring(3, qybm.length()); dsjgdm = qybmTemp.substring(0, 4) + "00000000"; fxjdm = qybmTemp.substring(0, 6) + "000000"; dsjgmc = ""; fxjmc = ""; // ? ? >>> ??? = N; // N?4?+80=??N?6?+60=?(6.19?) Department userDepartment = new Department(); userDepartment.setDepartcode(dsjgdm); // userDepartment = departmentService.getDepartment(userDepartment); dsjgmc = (userDepartment != null) ? userDepartment.getDepartname() : "?"; userDepartment = new Department(); userDepartment.setDepartcode(fxjdm); // userDepartment = departmentService.getDepartment(userDepartment); fxjmc = (userDepartment != null) ? userDepartment.getDepartname() : "?"; tempIckyj.setQyid(qyjbxx.getQyid()); } // ??? tempIckyj.setQybm(qybm); tempIckyj.setQymc(qymc); tempIckyj.setGxdwdm(gxdwdm); tempIckyj.setGxdwmc(gxdwmc); tempIckyj.setDsjgdm(dsjgdm); tempIckyj.setDsjgmc(dsjgmc); tempIckyj.setFxjdm(fxjdm); tempIckyj.setFxjmc(fxjmc); if (!"".equals(yjFlag)) { // dict_item.setFact_value(yjFlag); List list = CacheManager.getCacheDictitem(dict_item); if (list != null && list.size() > 0) { yjyy = ((Dict_item) list.get(0)).getDisplay_name(); } } tempIckyj.setSksj(sksjDates); tempIckyj.setYjyy(yjyy); tempIckyj.setSxsj(sxsj); tempIckyj.setRyid(ryid); tempIckyj.setKh(kh); ickyjService.insertIckyj(tempIckyj); tempIckyj = null; } } } renderText(response, "OK"); } // - OK if (isUserStr(type) && "reg".equals(type)) { Qyjbxx qyjbxx = new Qyjbxx(); qyjbxx.setQybm(id); qyjbxx = qyjbxxService.getQyjbxx(qyjbxx); if (qyjbxx != null) { int qyid = qyjbxx.getQyid(); Qyryxx qyryxx = new Qyryxx(); Icksl icksl = new Icksl(); //?14????????? 20110131 mds if (StringUtil.isNotEmpty(cyrybh) && cyrybh.length() == 14) qyryxx.setZjhm(gmsfhm); else qyryxx.setCyrybh(cyrybh); try { qyryxx = qyryxxService.getQyryxx(qyryxx); icksl.setRyid(qyryxx.getRyid()); icksl.setIckh(cardid); icksl.setZxbz("0"); icksl = ickslService.getIckslyj(icksl); if (icksl != null) { if (qyryxx != null) { int qyrrxxQyid = qyryxx.getQyid(); // ??? 20100914 if (90 > Integer.parseInt(qyryxx.getZt())) { if (qyrrxxQyid == qyid) { renderText(response, ""); } else { qyryxx.setQyid(qyid); qyryxx.setRzrq(new Date()); ickslService.updateIckslByryzc(qyryxx);// t_icksl, renderText(response, "?"); } } else { renderText(response, "???"); } } else { renderText(response, "?"); } } else { renderText(response, "????"); } } catch (Exception e) { renderText(response, "??"); } } else { renderText(response, "?"); } } // ? - ? - OK if (isUserStr(type) && "message".equals(type)) { Map map = new HashMap(); map.put("jsdwbm", id); // ? - jsdwbm map.put("csck", "0"); // / map.put("gqbs", "0"); Page page = xctbService.getcsListForPage(map, 1, 10, null, null); if (page.getData().size() > 0) { renderText(response, "TRUE"); } else { renderText(response, "FALSE"); } } // IC? 20?? - OK if (isUserStr(type) && "history".equals(type)) { String skkssj1 = RespDateByDay(-20); Date sksjf = stringToDate(skkssj1, "yyyy-MM-dd"); Date sksjt = new Date(); Qyjbxx qyjbxx = new Qyjbxx(); qyjbxx.setQybm(id); qyjbxx = qyjbxxService.getQyjbxx(qyjbxx); if (qyjbxx == null) { renderText(response, "<CSMC></CSMC>", 1); } else { /** ****************modify on 20100721********************* */ /* * int csid = qyjbxx.getQyid(); Map map = new HashMap(); * map.put("qybm", id); map.put("cyrybh", cyrybh); * map.put("sksjf", sksjf); map.put("sksjt", sksjt); Page * page = qyryskjlService.getListForPage(map, 1, 10, null, * null); int total = page.getTotalRows(); page = * qyryskjlService .getListForPage(map, 1, total, null, * null); List list = page.getData(); */ Qyryskjl setQyryskjl = new Qyryskjl(); setQyryskjl.setQybm(id); setQyryskjl.setCyrybh(cyrybh); setQyryskjl.setSksjf(sksjf); setQyryskjl.setSksjt(sksjt); List list = qyryskjlService.getListQyryskjl(setQyryskjl); /** ****************modify on 20100721********************* */ String fanhuiString = "<CSMC></CSMC>"; if (list != null && list.size() > 0) { fanhuiString = "<CSMC>" + qyjbxx.getQymc() + "</CSMC>"; for (int index = 0; index < list.size(); index++) { Qyryskjl qyryskjl = (Qyryskjl) list.get(index); fanhuiString += "<RECORD>" + dateToString(qyryskjl.getSksj(), "yyyy-MM-dd HH:mm:ss") + kongGe(6) + qyryskjl.getCyrybh() + kongGe(6) + qyryskjl.getXm() + "</RECORD>"; } } renderText(response, fanhuiString, 1); } } // ? - OK if (isUserStr(type) && "connect".equals(type)) { renderText(response, "OK"); } // ?? -OK if (isUserStr(type) && "date".equals(type)) { try { String fanhuiString = dateToString(new Date(), "yyyyMMddHHmmss"); Globalpar globalpar = new Globalpar(); Globalpar temp = null; // globalpar.setGlobalparcode("offline-bbhtest"); // globalpar.setGlobalparcode("offline-bbh"); // List globList = CacheManager.getCacheGlobalpar(globalpar); if (globList != null && globList.size() > 0) { temp = (Globalpar) globList.get(0); } fanhuiString += "$" + temp.getGlobalparvalue().replaceAll(",", ""); // globalpar.setGlobalparcode("prjweb-bbhtest"); globalpar.setGlobalparcode("prjweb-bbh"); globList = CacheManager.getCacheGlobalpar(globalpar); if (globList != null && globList.size() > 0) { temp = (Globalpar) globList.get(0); } fanhuiString += "$" + temp.getGlobalparvalue().replaceAll(",", ""); globalpar.setGlobalparcode("gsweb-bbh"); globList = CacheManager.getCacheGlobalpar(globalpar); if (globList != null && globList.size() > 0) { temp = (Globalpar) globList.get(0); } fanhuiString += "$" + temp.getGlobalparvalue().replaceAll(",", ""); renderText(response, fanhuiString); } catch (Exception e) { e.printStackTrace(); response.getWriter().write(""); } } // 13 - login 14 - login2 - OK if ((isUserStr(type) && "login".equals(type)) || (isUserStr(type) && "login2".equals(type))) { String userType = ""; if ("login".equals(type)) { userType = "13"; } if ("login2".equals(type)) { userType = "14"; } User user = new User(); user.setUseraccount(id); user = userService.checkUser(user); if (user != null) { String password = user.getPassword(); String type = user.getUsertype(); if (password.equals(EncryptUtil.getMD5Code(pwd))) { // ? if (type.contains(userType)) { // ? if ("13".equals(type)) { String qykfkg = QjblUtil.queryQjblVal("qykf-kg"); if ("1".equals(qykfkg)) { // ? try { String content = wsdlResult(user.getUseraccount()); Document doc = DocumentHelper.parseText(content); Element root = doc.getRootElement(); String isright = root.element("ISVERIFY").getText(); if ("1".equals(isright)) { renderText(response, "OK"); } else { renderText(response, "ERROR??"); } } catch (Exception e) { e.printStackTrace(); renderText(response, "ERROR???"); } } else { renderText(response, "OK"); } } else { renderText(response, "OK"); } } else { // ?? renderText(response, "NOTOK"); } } else { renderText(response, "FALSE"); } } else { renderText(response, "FALSE"); } } // 2009-12-11 add // type=verify&id=&devicetype= // <OUTPUT>TRUE</OUTPUT><OUTPUT></OUTPUT> // ????<OUTPUT>TRUE???</OUTPUT> // ???????? if (isUserStr(type) && "verify".equals(type)) { User user = new User(); user.setUseraccount(id); try { user = userService.checkUser(user); } catch (Exception e) { e.printStackTrace(); renderText(response, ""); } if (user != null) { String qykfkg = QjblUtil.queryQjblVal("qykf-kg"); String sksblx = QjblUtil.queryQjblVal("deviceType");// ? if (!sksblx.equals(devicetype)) { renderText(response, "?"); } else { if ("1".equals(qykfkg)) { // ? try { String content = wsdlResult(user.getUseraccount()); Document doc = DocumentHelper.parseText(content); Element root = doc.getRootElement(); String isright = root.element("ISVERIFY").getText(); String endDate = root.element("ENDDATE").getText(); if ("1".equals(isright)) { int difday = difDay(endDate); if (difday < 31) { renderText(response, "TRUE???"); } else { renderText(response, "TRUE"); } } else { renderText(response, "??"); } } catch (Exception e) { e.printStackTrace(); renderText(response, "???"); } } else { renderText(response, "TRUE"); } } } else { renderText(response, "???"); } } // ??- OK if (isUserStr(type) && "coding".equals(type)) { StringBuffer condingString = new StringBuffer("<output>"); Dict dict = new Dict(); dict.setKongjianDicts("'dm_mz','dm_gj(lgy)','dm_xzqh'"); List list = dictService.getListDict(dict); if (list != null && list.size() > 0) { for (int index = 0; index < list.size(); index++) { dict = (Dict) list.get(index); // 15342003,???,DICTIONARY,DI_SN,DI_CVALUE,DI_SELNO,DI_MNEMONIC,DI_PROMPT,DI_DFID=1330,,,,WLGLZT,,1 condingString.append(nullCheck(String.valueOf(dict.getDict_id())) + "," + nullCheck(dict.getDict_name()) + "," + nullCheck(dict.getDict_itemtablename()) + "," + "DI_SN" + "," + "DI_CVALUE" + "," + "DI_SELNO" + "," + "DI_MNEMONIC" + "," + "DI_PROMPT" + "," + "DI_DFID=" + dict.getDict_id() + "," + "" + "," + "" + "," + "" + "," + nullCheck(dict.getDict_simplepin()) + "," + "" + "," + nullCheck(dict.getDict_versionid() + "\r\n")); } } condingString.append("</output>"); renderText(response, condingString.toString(), 1); } // ????- OK if (isUserStr(type) && "dict".equals(type)) { Dict dict = new Dict(); dict.setDict_id(Integer.parseInt(coid)); List list = dict_itemService.getOfflineDict_item(dict); StringBuffer returnString = new StringBuffer("<output>"); if (list != null && list.size() > 0) { for (int index = 0; index < list.size(); index++) { Dict_item dict_item = (Dict_item) list.get(index); returnString.append(nullCheck(String.valueOf(dict_item.getItem_id())) + "," + nullCheck(dict_item.getDisplay_name()) + "," + nullCheck(dict_item.getItem_simplepin()) + "," + nullCheck(dict_item.getFact_value()) + "," + coid + "\r\n"); } } returnString.append("</output>"); renderText(response, returnString.toString(), 1); } // ??config?? if (isUserStr(type) && "password".equals(type)) { String password = QjblUtil.queryQjblVal("offline-config-password"); renderText(response, password); } // ?offline?(0??1??) if (isUserStr(type) && "logintype".equals(type)) { String logintype = QjblUtil.queryQjblVal("login-type"); renderText(response, logintype); } //?? if (isUserStr(type) && "policecardlogin".equals(type) || "culturecardlogin".equals(type)) { Map map = new HashMap(); map.put("tableName", "t_mjjczsl"); map.put("zkztbs", "5"); map.put("mjjczbh", jcz); map.put("xgbz", "0"); boolean jczexit = systemService.isExit(map); if (jczexit) { String deptJcz = StringUtil.trimEven0(gajg); Qyjbxx qyjbxx = new Qyjbxx(); qyjbxx.setQybm(id); qyjbxx = qyjbxxService.getQyjbxx(qyjbxx); String deptQyxx = qyjbxx.getGxdwbm(); String mjjcqxms = QjblUtil.queryQjblVal("mjjcqxms"); String kzxljcqk = QjblUtil.queryQjblVal("kzxljcqk"); if (mjjcqxms.equals("2")) { if (deptQyxx.indexOf(deptJcz) == 0) { if ("0".equals(url)) { renderText(response, "OK"); } else { if ("1".equals(kzxljcqk)) { renderText(response, "URL=basic/jfglsystem/JcqkAdd-offline.jsp"); } else { renderText(response, "URL=basic/mjjczsystem/RcjcMjjczSk.jsp"); } } } else { renderText(response, "???"); } } else { if ("0".equals(url)) { renderText(response, "OK"); } else { if ("1".equals(kzxljcqk)) { renderText(response, "URL=basic/jfglsystem/JcqkAdd-offline.jsp"); } else { renderText(response, "URL=basic/mjjczsystem/RcjcMjjczSk.jsp"); } } } } else { if ("policecardlogin".equals(type)) { renderText(response, "??"); } else { renderText(response, "??"); } } } //???? if (isUserStr(type) && "unioncardlogin".equals(type)) { Map map = new HashMap(); map.put("tableName", "t_mjjczsl"); map.put("zkztbs", "5"); map.put("mjjczbh", jcz); map.put("xgbz", "0"); boolean jczexit = systemService.isExit(map); if (jczexit) { String deptJcz = StringUtil.trimEven0(gajg); Qyjbxx qyjbxx = new Qyjbxx(); qyjbxx.setQybm(id); qyjbxx = qyjbxxService.getQyjbxx(qyjbxx); String deptQyxx = qyjbxx.getGxdwbm(); String mjjcqxms = QjblUtil.queryQjblVal("mjjcqxms"); String kzxljcqk = QjblUtil.queryQjblVal("kzxljcqk"); if (mjjcqxms.equals("2")) { if (deptQyxx.indexOf(deptJcz) == 0) { if ("1".equals(url)) { renderText(response, "UNION=basic/jfglsystem/JcqkUnionAdd-offline.jsp"); } else { renderText(response, "OK"); } } else { renderText(response, "???"); } } else { if ("1".equals(url)) { renderText(response, "UNION=basic/jfglsystem/JcqkUnionAdd-offline.jsp"); } else { renderText(response, "OK"); } } } else { renderText(response, "??"); } } //?offline?connect?config??offline? if (isUserStr(type) && "para".equals(type)) { //?connect? String timeControl = QjblUtil.queryQjblVal("offline-config-timeControl"); //?config?? String password = QjblUtil.queryQjblVal("offline-config-password"); //?offline? String logintype = QjblUtil.queryQjblVal("login-type"); StringBuffer returnString = new StringBuffer("<OUTPUT>"); returnString.append(timeControl); returnString.append("$"); returnString.append(password); returnString.append("$"); returnString.append(logintype); returnString.append("</OUTPUT>"); renderText(response, returnString.toString(), 1); } } catch (Exception e) { e.printStackTrace(); renderText(response, "??"); } } public String creatKongJianSession() { HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse response = ServletActionContext.getResponse(); HttpSession session = request.getSession(); String resultRed = ""; String userType = ""; if ("vlogin".equals(type)) { // userType = "13"; } if ("plogin".equals(type)) { // userType = "14"; } User user = new User(); user.setUseraccount(id); user = userService.checkUser(user); if (user != null) { String password = user.getPassword(); String type = user.getUsertype(); if (password.equals(EncryptUtil.getMD5Code(pwd)) && type.contains(userType)) { Department userDepartment = new Department(); userDepartment.setDepartid(user.getDepartid()); userDepartment = departmentService.getDepartment(userDepartment); user.setDepartment(userDepartment); session.setAttribute(Constants.userKey, user); resultRed = "OK"; } else { removeSession(session); } } else { removeSession(session); } session.setAttribute("ret", resultRed); session.setAttribute("redirectFlag", "Y"); return "success"; } public void removeSession(HttpSession session) { if (session.getAttribute(Constants.userKey) != null) { session.removeAttribute(Constants.userKey); } if (session.getAttribute("ret") != null) { session.removeAttribute("ret"); } if (session.getAttribute("redirectFlag") != null) { session.removeAttribute("redirectFlag"); } } protected void renderText(HttpServletResponse response, String text) { StringBuffer result = new StringBuffer(""); result.append("<OUTPUT>"); result.append(text); result.append("</OUTPUT>"); renderText(response, result.toString(), "UTF-8"); } protected void renderText(HttpServletResponse response, String text, int flag) { StringBuffer result = new StringBuffer(""); result.append(text); renderText(response, result.toString(), "UTF-8"); } protected void renderText(HttpServletResponse response, String text, String encoding) { renderContent(response, text, (new StringBuilder("text/plain;charset=")).append(encoding).toString()); } private void renderContent(HttpServletResponse response, String text, String contentType) { try { response.setContentType(contentType); response.getWriter().write(text); } catch (IOException e) { log.error(e.getMessage(), e); } } /** * ?? * * @return true:???false?? */ public static boolean isUserStr(String str) { boolean temp = false; if (str != null) { str = str.trim(); if (!"".equals(str)) { temp = true; } } return temp; } public String nullCheck(String string) { if (string == null) { return ""; } else { return string; } } public static String fileToBase64(URL sPath) throws IOException { String ret = new String(); try { byte[] bytes = new byte[1024]; InputStream in = sPath.openStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(2048); int size = 0; size = in.read(bytes); while (size != -1) { baos.write(bytes, 0, size); size = in.read(bytes); } ret = new sun.misc.BASE64Encoder().encode(baos.toByteArray()); // ? in.close(); baos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (java.io.IOException ex) { ex.printStackTrace(); } ret = ret.replaceAll("\r\n", ""); ret = ret.replaceAll("\n", ""); return ret; } // BASE64 ? s ? public static String getFromBASE64(String s) { if (s == null) return null; BASE64Decoder decoder = new BASE64Decoder(); try { byte[] b = decoder.decodeBuffer(s); return new String(b); } catch (Exception e) { return null; } } public String kongGe(int leng) { String kongGe = ""; for (int i = 0; i < leng; i++) { kongGe += " "; } return kongGe; } /* * ? * */ public static String RespDateByDay(int iDays) { if (iDays == 0) iDays = -1; if (iDays == 1) iDays = 0; SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); Calendar dCurrDate = Calendar.getInstance(); dCurrDate.add(Calendar.DATE, iDays); String sDate = formatter.format(dCurrDate.getTime()); return sDate; } public static Date stringToDate(String yyyymmdd, String style) { Date date = null; try { return new java.text.SimpleDateFormat(style).parse(yyyymmdd); } catch (ParseException ex) { return null; } } public static String dateToString(Date yyyymmdd, String style) { try { SimpleDateFormat formatter = new SimpleDateFormat(style); String sDate = formatter.format(yyyymmdd); return sDate; } catch (Exception ex) { return null; } } /** * ?webserver? XML?? --- * * @param qybm * @return * @throws Exception */ public String wsdlResult(String qybm) throws Exception { String qykfwsdl = QjblUtil.queryQjblVal("qykf-wsdl"); Client client = new Client(new java.net.URL(qykfwsdl)); return client.invoke("licenseVerifyByID", new String[] { qybm })[0].toString(); } /** * --- * * @param endDate * @return * @throws Exception */ public int difDay(String endDate) throws Exception { SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date nowDate = new Date(); String dateNowStr = dateFormat.format(nowDate); Date dateEnd = formatter.parse(endDate); Date dateNow = formatter.parse(dateNowStr); int day1 = (int) dateEnd.getTime() / 24 * 60 * 1000; int day2 = (int) dateNow.getTime() / 24 * 60 * 1000; return (day1 - day2); } /** * ??????? * @return */ public Date modifyCyryRzrq(Qyryxx qyryxx, Date sksjDate) throws Exception { if (qyryxx.getRzrq() == null || "".equals(qyryxx.getRzrq())) { Qyryskjl setQyryskjl = new Qyryskjl(); setQyryskjl.setCyrybh(qyryxx.getCyrybh()); setQyryskjl.setQyid(qyryxx.getQyid()); List qyryskjlList = qyryskjlService.getListQyryskjl(setQyryskjl); if (qyryskjlList != null && qyryskjlList.size() > 0) { setQyryskjl = (Qyryskjl) qyryskjlList.get(0); return setQyryskjl.getSksj(); } else { return sksjDate; } } else { return qyryxx.getRzrq(); } } public String getType() { return type; } public void setType(String type) { this.type = type; } public String getCardid() { return cardid; } public void setCardid(String cardid) { this.cardid = cardid; } public void setIckslService(IIckslService ickslService) { this.ickslService = ickslService; } public void setDict_itemService(IDict_itemService dict_itemService) { this.dict_itemService = dict_itemService; } public String getValue() { return value; } public void setValue(String value) { this.value = value; } public void setQyjbxxService(IQyjbxxService qyjbxxService) { this.qyjbxxService = qyjbxxService; } public void setQyryskjlService(IQyryskjlService qyryskjlService) { this.qyryskjlService = qyryskjlService; } public String getCyrybh() { return cyrybh; } public void setCyrybh(String cyrybh) { this.cyrybh = cyrybh; } public String getId() { return id; } public void setId(String id) { this.id = id; } public void setQyryxxService(IQyryxxService qyryxxService) { this.qyryxxService = qyryxxService; } public String getPwd() { return pwd; } public void setPwd(String pwd) { this.pwd = pwd; } public void setDepartmentService(IDepartmentService departmentService) { this.departmentService = departmentService; } public void setDictService(IDictService dictService) { this.dictService = dictService; } public String getCoid() { return coid; } public void setCoid(String coid) { this.coid = coid; } public String getJcz() { return jcz; } public void setJcz(String jcz) { this.jcz = jcz; } public String getGajg() { return gajg; } public void setGajg(String gajg) { this.gajg = gajg; } public void setXctbService(IXctbService xctbService) { this.xctbService = xctbService; } public void setUserService(IUserService userService) { this.userService = userService; } public void setWgcyryxxService(IWgcyryxxService wgcyryxxService) { this.wgcyryxxService = wgcyryxxService; } public void setIckyjService(IIckyjService ickyjService) { this.ickyjService = ickyjService; } public void setSystemService(ISystemService systemService) { this.systemService = systemService; } public String getDevicetype() { return devicetype; } public void setDevicetype(String devicetype) { this.devicetype = devicetype; } public String getGmsfhm() { return gmsfhm; } public void setGmsfhm(String gmsfhm) { this.gmsfhm = gmsfhm; } }