package com.finstone.app.common.controller; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintWriter; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import javax.annotation.Resource; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.shiro.SecurityUtils; import org.apache.shiro.subject.Subject; import org.springframework.stereotype.Controller; import org.springframework.util.FileCopyUtils; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.multipart.commons.CommonsMultipartFile; import com.fins.html.view.data.OutData; import com.finstone.app.common.service.DatabaseInitService; import com.finstone.app.common.service.SystemInitService; import com.finstone.app.common.support.SystemInitLogEntity; import com.finstone.app.common.support.User; @Controller public class SystemInitCon { @Resource SystemInitService systemInitService; @Resource DatabaseInitService databaseInitService; private MultipartFile file; boolean pd=true; public MultipartFile getFile() { return file; } public void setFile(MultipartFile file) { this.file = file; } @SuppressWarnings("finally") @RequestMapping("doUpgrade") public void doAutoUpgradeImp(HttpServletRequest request, HttpServletResponse response) { Subject subject = SecurityUtils.getSubject(); User user = (User)subject.getPrincipal(); FileOutputStream fos = null; BufferedInputStream bfis = null; BufferedOutputStream bfos = null; String keyval = request.getParameter("keyval"); String de022 = user.getSjzonecode(); SystemInitLogEntity log = new SystemInitLogEntity(); String returnStr = ""; PrintWriter out = null; try { //titanCoreService.checkLoadDataUser(request); response.setHeader("Cache-Control", "no-cache"); response.setContentType("text/html; charset=utf-8"); out = response.getWriter(); systemInitService.checkKeyVal(keyval, user); } catch (Exception e) { returnStr = "<script>parent.setTSValue('口令错误,数据上传失败,请输入正确的口令!', 'red');</script>"; //renderHtml(response, returnStr); out.println(returnStr); out.flush(); out.close(); return ; } try { // 转型为MultipartHttpRequest MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; // 获得文件 Map map = multipartRequest.getFileMap(); CommonsMultipartFile cfile = null; for (Iterator i = map.keySet().iterator(); i.hasNext();) { cfile = (CommonsMultipartFile) map.get(i.next()); } String webroot= request.getSession().getServletContext().getRealPath("/") ; File file_ = new File(webroot+"/systemInit/"+"autoUpgradeImp.zip"); file_.createNewFile(); fos = new FileOutputStream(file_); bfis = new BufferedInputStream(cfile.getInputStream()); bfos = new BufferedOutputStream(fos); FileCopyUtils.copy(bfis, bfos); String filePath=webroot+"systemInit/autoUpgradeImp.zip"; ServletContext servletContext=request.getSession().getServletContext(); //判断版本号 systemInitService.doAutoUpgradeImport_BBH(filePath, de022, log); //页面程序升级 Map rmap=systemInitService.doAutoUpgradeImport_YM(filePath, de022, log); //map.get("code"); //数据库升级 systemInitService.doAutoUpgradeImport(filePath, de022, log); if(log.getBS().startsWith("0")){//处理有异常 //model.addAttribute("code", "-1"); //model.addAttribute("text", "升级失败.明细信息查看日志"); returnStr = "<script>parent.setTSValue('数据库升级失败.明细信息查看日志','red');</script>"; out.println(returnStr); out.flush(); out.close(); return ; }else{ //model.addAttribute("code", "1"); //model.addAttribute("text", "自动升级完成,请查看升级日志,核对升级内容是否完全正确!"); returnStr = "<script>parent.setTSValue('数据库自动升级完成,请查看升级日志,核对升级内容是否完全正确!', 'blue');</script>"; out.println(returnStr); out.flush(); systemInitService.excuteProcedure(log); } file_.delete(); } catch (Exception e) { e.printStackTrace(); log.setFunname("系统升级"); log.setBS("0"); log.setLx(3); log.setDE022(de022); if(e.getMessage().length()>=1000){ log.setSM(e.getMessage().substring(0, 1000)); }else{ log.setSM(e.getMessage()); } log.setTimedata( new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); //model.addAttribute("code", "-1"); //model.addAttribute("text", "升级失败请查看日志"); returnStr = "<script>parent.setTSValue('升级失败请查看日志', 'red');</script>"; out.println(returnStr); out.flush(); } finally { if (file != null) { try { fos.close(); bfos.close(); bfis.close(); } catch (Exception e) { bfis = null; bfos = null; fos = null; } } this.systemInitService.insertLog(log); returnStr += "<script>parent.refreshParent();</script>"; //renderHtml(response, returnStr); out.println(returnStr); out.flush(); out.close(); return ; } } @RequestMapping("/initXmlCreate") public void initXmlCreate(HttpServletRequest request, HttpServletResponse response) { try { databaseInitService.initXmlCreate(request, response); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @SuppressWarnings("finally") @RequestMapping("doDatabaseInit") public void doDatabaseImp(HttpServletRequest request, HttpServletResponse response) { Subject subject = SecurityUtils.getSubject(); User user = (User)subject.getPrincipal(); FileOutputStream fos = null; BufferedInputStream bfis = null; BufferedOutputStream bfos = null; String keyval = request.getParameter("keyval"); //String de022 = user.getSjzonecode(); SystemInitLogEntity log = new SystemInitLogEntity(); String returnStr = ""; PrintWriter out = null; try { response.setHeader("Cache-Control", "no-cache"); response.setContentType("text/html; charset=utf-8"); out = response.getWriter(); systemInitService.checkKeyVal(keyval, user); } catch (Exception e) { returnStr = "<script>parent.setTSValue('口令错误,数据上传失败,请输入正确的口令!', 'red');</script>"; out.println(returnStr); out.flush(); out.close(); return ; } try { // 转型为MultipartHttpRequest MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; // 获得文件 Map map = multipartRequest.getFileMap(); CommonsMultipartFile cfile = null; for (Iterator i = map.keySet().iterator(); i.hasNext();) { cfile = (CommonsMultipartFile) map.get(i.next()); } String webroot= request.getSession().getServletContext().getRealPath("/") ; File file_ = new File(webroot+"/systemInit/"+"initXml.xml"); file_.createNewFile(); fos = new FileOutputStream(file_); bfis = new BufferedInputStream(cfile.getInputStream()); bfos = new BufferedOutputStream(fos); FileCopyUtils.copy(bfis, bfos); String filePath = webroot + "systemInit/initXml.xml"; // servletContext=request.getSession().getServletContext(); Map<String, String> paramMap = new HashMap<String, String>(); String xzqh = request.getParameter("XZQH"); paramMap.put("XZQH", xzqh);// 操作的行政区划 paramMap.put("PATH", filePath); //编辑日志 log.setLx(1); log.setDE022(xzqh); log.setFCILITYPRSONNEL(user.getId()); log.setBS("1"); log.setFunname("初始化文件导入"); log.setSM("操作成功"); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); log.setTimedata(dateFormat.format(new Date())); //执行导入操作 databaseInitService.doDatabaseInitImp(paramMap, user, log); if (log.getBS().startsWith("0")) {// 处理有异常 returnStr = "<script>parent.setTSValue('初始化失败,明细信息查看日志','red');</script>"; out.println(returnStr); out.flush(); out.close(); return ; }else{ returnStr = "<script>parent.setTSValue('初始化完成,请查看升级日志,核对初始化内容是否完全正确!', 'blue');</script>"; out.println(returnStr); out.flush(); } file_.delete(); } catch (Exception e) { e.printStackTrace(); if(e.getMessage().length()>=1000){ log.setSM(e.getMessage().substring(0, 1000)); }else{ log.setSM(e.getMessage()); } returnStr = "<script>parent.setTSValue('初始化失败,请查看日志', 'red');</script>"; out.println(returnStr); out.flush(); } finally { if (file != null) { try { fos.close(); bfos.close(); bfis.close(); } catch (Exception e) { bfis = null; bfos = null; fos = null; } } this.systemInitService.insertLog(log); returnStr += "<script>parent.refreshParent();</script>"; out.println(returnStr); out.flush(); out.close(); return ; } } }
package com.finstone.app.common.service; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.net.URLDecoder; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.dom4j.Attribute; import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.dom4j.io.OutputFormat; import org.dom4j.io.SAXReader; import org.dom4j.io.XMLWriter; import org.json.JSONObject; import org.springframework.stereotype.Service; import com.fins.common.exception.BusException; import com.fins.html.view.data.OutData; import com.fins.modules.dao.DataBaseHelper; import com.finstone.app.common.support.SystemInitLogEntity; import com.finstone.app.common.support.User; import com.finstone.framework.support.IUser; import com.finstone.zxt.common.service.GkbCommGetSqlDataService; import com.finstone.zxt.common.support.LogErrorModel; import com.finstone.zxt.common.tool.FinString; @Service public class DatabaseInitService { static Logger logger = LogManager.getLogger(DatabaseInitService.class.getName()); private LogErrorModel logdto; @Resource(name = "gkbCommGetSqlDataService") private GkbCommGetSqlDataService gkbCommGetSqlDataService; @Resource SystemInitService systemInitService; @SuppressWarnings({ "rawtypes" }) public void doDatabaseInitImp(Map p,IUser user,SystemInitLogEntity log ) { User userinfo = (User) user; List tablesList=new ArrayList();//存储tables类别列表 List tableList=new ArrayList();//存储具体某一类中的待处理表 Element tables=null; Element table=null; Attribute tablesattr=null; Attribute tableattr=null; String tablename; List list=new ArrayList();//特殊处理sql String temp_Sql=""; try { if(!userinfo.getLoginName().equalsIgnoreCase("admin")){ log.setBS("0"); log.setSM("只有超级管理员才能执行此操作"); throw new BusException("只有超级管理员才能执行此操作"); } if(p.get("XZQH")==null||p.get("XZQH").equals("")){ log.setBS("0"); log.setSM("请选择行政区划!"); throw new BusException("请选择行政区划!"); } if(p.get("XZQH").toString().replaceAll("0000", "").length()!=2){ log.setBS("0"); log.setSM("请选择省级区划!"); throw new BusException("请选择省级区划!"); } //特殊修改,admin用户 String sql="delete pt_user where username <> 'admin'"; DataBaseHelper.execute(sql); sql="update pt_user set de022='"+p.get("XZQH").toString()+"'"; DataBaseHelper.execute(sql); // String path = URLDecoder.decode(this.getClass().getClassLoader().getResource("/").getPath(), "UTF-8"); String path = p.get("PATH").toString() ; Document document = load(path); tablesList=document.selectNodes("//tables"); for (int i = 0; i < tablesList.size(); i++) { tables = (Element) tablesList.get(i); tablesattr = tables.attribute("type");// 类型 if (tablesattr.getValue().equalsIgnoreCase("1")) { tableList = tables.elements("tableName"); for (int j = 0; j < tableList.size(); j++) { table = (Element) tableList.get(j); tableattr = table.attribute("mc");// 表名称 tablename = table.getTextTrim(); try { truncateTable(tablename); } catch (Exception e) { e.printStackTrace(); log.setBS("0"); if (e.getMessage().length() >= 900) { log.setSM(e.getMessage().substring(0, 900)); } else { log.setSM(e.getMessage()); } throw new BusException("表数据清空操作执行错误:" + e.getMessage()); } } } else if (tablesattr.getValue().equalsIgnoreCase("2")) { tableList = tables.elements("tableName"); for (int j = 0; j < tableList.size(); j++) { table = (Element) tableList.get(j); tableattr = table.attribute("mc");// 表名称 Attribute guid = table.attribute("guid");// guid tablename = table.getTextTrim(); String g = ""; if (guid != null) { g = guid.getValue(); } try { copyStandInfo(tablename, p.get("XZQH").toString()); } catch (Exception e) { e.printStackTrace(); log.setBS("0"); if (e.getMessage().length() >= 900) { log.setSM(e.getMessage().substring(0, 900)); } else { log.setSM(e.getMessage()); } throw new BusException("根据标准版复制数据操作执行错误:" + e.getMessage()); } } } else if (tablesattr.getValue().equalsIgnoreCase("3")) { tableList = tables.elements("tableName"); for (int j = 0; j < tableList.size(); j++) { table = (Element) tableList.get(j); tableattr = table.attribute("mc");// 表名称 tablename = table.getTextTrim(); try { handleStandInfo(tablename, p.get("XZQH").toString()); } catch (Exception e) { e.printStackTrace(); log.setBS("0"); if (e.getMessage().length() >= 900) { log.setSM(e.getMessage().substring(0, 900)); } else { log.setSM(e.getMessage()); } throw new BusException("自动生成数据操作执行错误:" + e.getMessage()); } } } else { log.setBS("0"); log.setSM("类型配置不正确,不存在此类型"); throw new BusException("类型配置不正确,不存在此类型"); } } // 执行特殊业务sql list = document.selectNodes("//sqls/sql"); if (list != null && list.size() > 0) { int len = list.size(); for (int i = 0; i < len; i++) { Element element = (Element) list.get(i); temp_Sql = element.getText(); try { DataBaseHelper.update(temp_Sql); } catch (Exception e) { e.printStackTrace(); log.setBS("0"); if(e.getMessage().length()>=900){ log.setSM(e.getMessage().substring(0, 900)); }else{ log.setSM(e.getMessage()); } throw new BusException("配置菜单sql执行错误:"+e.getMessage()); } } } } catch (Exception e) { throw new BusException(e.getMessage()); } } /** * load * 载入一个xml文档 * @return 成功返回Document对象,失败返回null * @param uri 文件路径 */ public static Document load(String filename) { Document document = null; try { SAXReader saxReader = new SAXReader(); document = saxReader.read(new File(filename)); } catch (Exception ex){ ex.printStackTrace(); } return document; } /* * */ public void truncateTable(String tablename ){ SystemInitLogEntity log = new SystemInitLogEntity(); log.setLx(1); log.setFunname("初始化操作执行truncateTable"); log.setSM("清空表" + tablename + "成功"); log.setBS("1"); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { int istable = gkbCommGetSqlDataService.isTable(tablename); if (istable == 0) { log.setSM("清空表" + tablename + "失败:指定的表名称无效,请重新指定"); throw new BusException("指定的表名称无效,请重新指定"); } else { log.setUpdata(dateFormat.format(new Date()));// 开始时间 logger.info("清空表" + tablename + "开始"); String sql = "truncate table " + tablename; DataBaseHelper.execute(sql); log.setTimedata(dateFormat.format(new Date()));// 结束时间 logger.info("清空表" + tablename + "完成"); } } catch (Exception e) { log.setBS("0"); log.setSM("清空表" + tablename + "失败"); logger.info("清空表" + tablename + "失败"); throw new BusException(e.getMessage()); } finally { systemInitService.insertOptionLog(log); } } public void copyStandInfo(String tablename,String xzqh){ SystemInitLogEntity log = new SystemInitLogEntity(); log.setLx(1); log.setFunname("初始化操作执行copyStandInfo"); log.setSM("根据标准版复制数据操作" + tablename + "成功"); log.setBS("1"); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try{ int istable=gkbCommGetSqlDataService.isTable(tablename); if(istable==0){ log.setSM("根据标准版复制数据操作" + tablename + "失败:指定的表名称无效,请重新指定"); throw new BusException("指定的表名称无效,请重新指定"); }else{ logger.info("初始化表"+tablename+"开始"); List<Map<String, Object>> Columns= gkbCommGetSqlDataService.getTableInfo(tablename); for(int i=0;i<Columns.size();i++){ if(Columns.get(i).get("COLUMN_NAME").toString().equalsIgnoreCase("DE022"))break; if(i==Columns.size()-1&&!Columns.get(i).get("COLUMN_NAME").toString().equalsIgnoreCase("DE022")){//判断主键字段是否是表中字段,如果不是抛出异常 throw new BusException("表不存在DE022地区字段,请查验"); } } log.setUpdata(dateFormat.format(new Date()));// 开始时间 String sql="update "+tablename+" set de022='"+xzqh+"'"; DataBaseHelper.update(sql); log.setTimedata(dateFormat.format(new Date()));// 结束时间 /* List<Map<String, Object>> Columns= gkbCommGetSqlDataService.getTableInfo(tablename); String _g=""; if(guid!=""){ for(int i=0;i<Columns.size();i++){ if(Columns.get(i).get("COLUMN_NAME").toString().equalsIgnoreCase(guid))break; if(i==Columns.size()-1&&!Columns.get(i).get("COLUMN_NAME").toString().equalsIgnoreCase(guid)){//判断主键字段是否是表中字段,如果不是抛出异常 throw new BusException("主键字段设置不正确,请重新指定"); } } _g=guid+","; } else{ _g=""; } String sql="delete from "+tablename+" where de022 not like '990000'"; DataBaseHelper.update(sql); Map zdxxMap = gkbCommGetSqlDataService.getTableColumnSqlInfo( tablename, "a", _g+"de022,", ""); int codeInt = Integer.parseInt(FinString.ts(zdxxMap.get("code"))); if (codeInt < 0) { throw new BusException(FinString.ts(zdxxMap.get("text"))); } String zdxxStr = FinString.ts(zdxxMap.get("text")); List<Map<String,Object>> list=DataBaseHelper.queryForList("select "+zdxxStr+" from "+tablename+" a where de022 like '990000'"); for(int i=0;i<list.size();i++){ Map<String,Object> m=list.get(i); m.put("DE022", xzqh); if(guid!=""){ m.put(guid.toUpperCase(), GkbCommTools.getUuid()); } Map sqlMap = gkbCommGetSqlDataService.getAddSqlInfo(tablename, m); codeInt = Integer.parseInt(FinString.ts(sqlMap.get("code"))); if (codeInt < 0) { throw new BusException(FinString.ts(sqlMap.get("text"))); } DataBaseHelper.update(FinString.ts(sqlMap.get("text")), m); } */ logger.info("初始化表"+tablename+"完成"); } }catch(Exception e){ logger.info("初始化表"+tablename+"失败"); e.printStackTrace(); log.setBS("0"); log.setSM("根据标准版复制数据操作" + tablename + "失败"); // data.setCode(-1); // data.setMsg("初始化失败"); throw new BusException(e.getMessage()); } finally { systemInitService.insertOptionLog(log); } } /* * xzqh为类似于320000的代码 */ public void handleStandInfo(String tablename,String xzqh) throws Exception{ SystemInitLogEntity log = new SystemInitLogEntity(); log.setLx(1); log.setFunname("初始化操作执行handleStandInfo"); log.setSM("配置菜单sql执行" + tablename + "成功"); log.setBS("1"); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try{ int istable=gkbCommGetSqlDataService.isTable(tablename); if(istable==0){ log.setSM("配置菜单sql执行" + tablename + "失败:指定的表名称无效,请重新指定"); log.setBS("0"); throw new BusException("指定的表名称无效,请重新指定"); }else{ logger.info("初始化表"+tablename+"开始"); String sql="delete from "+tablename+" where de022 not like '99%'"; DataBaseHelper.update(sql); List<Map<String, Object>> columns= gkbCommGetSqlDataService.getTableInfo(tablename); List<Map<String, Object>> cs021Columns= gkbCommGetSqlDataService.getTableInfo("cs021"); List<Map<String,Object>> list=DataBaseHelper.queryForList("select * from "+tablename+" a where de022 like '99%'"); for(int i=0;i<list.size();i++){ Map<String,Object> m=list.get(i); String de022_bzb=m.get("DE022").toString(); int xzqhlength=0; if(de022_bzb.equalsIgnoreCase("990000")){//省级数据 xzqhlength=2; } else if(de022_bzb.equalsIgnoreCase("990900")){//市级数据 xzqhlength=4; } else if(de022_bzb.equalsIgnoreCase("990909")){//显级数据 xzqhlength=6; }else{ log.setSM("配置菜单sql执行" + tablename + "失败:需要先清空非标准版数据"); log.setBS("0"); throw new BusException("需要先清空非标准版数据"); } List<Map<String,Object>> province=DataBaseHelper.queryForList("select * from cs021 where isqy=1 and length(de0221)="+xzqhlength+" and de022 like (regexp_replace('"+xzqh+"','00$|0000$|000000$',''))||'%'"); for(int rownum=0;rownum<province.size();rownum++){ Map<String, Object> mapinfo = new HashMap<String, Object>(); Map<String,Object> provinceRow=province.get(rownum); for(int columnnum=0;columnnum<columns.size();columnnum++){//针对每列,判断是否有#内容 String columnName=columns.get(columnnum).get("COLUMN_NAME").toString(); String columnType=columns.get(columnnum).get("DATA_TYPE").toString(); if(!columnName.equals("DE022")){ if(!columnType.equals("CLOB")){ //非区域代码字段,非clob字段 if(m.get(columnName)==null){ //处理为空字段 } else if(m.get(columnName).toString().indexOf("#")<0){ //处理直接文本字段 mapinfo.put(columnName, m.get(columnName).toString()); }else{ //判断是否两个#之间的字段是否在cs021中,如果不在那张表中,跑出异常 String param=m.get(columnName).toString().substring(m.get(columnName).toString().indexOf("#")+1, m.get(columnName).toString().lastIndexOf("#")); for(int c=0;c<cs021Columns.size();c++){ if(c==cs021Columns.size()-1&&(cs021Columns.get(c).get("COLUMN_NAME").toString().equalsIgnoreCase(param))){ log.setSM("配置菜单sql执行" + tablename + "失败:参数设置不正确"); log.setBS("0"); throw new BusException("参数设置不正确,请查验"); } } mapinfo.put(columnName,m.get(columnName).toString().replace("#"+param+"#", provinceRow.get(param).toString())); } } } } //插入数据行 mapinfo.put("DE022", provinceRow.get("DE022") .toString()); Map sqlMap = gkbCommGetSqlDataService.getAddSqlInfo( tablename, mapinfo); int codeInt = Integer.parseInt(FinString.ts(sqlMap .get("code"))); if (codeInt < 0) { throw new BusException(FinString.ts(sqlMap .get("text"))); } log.setUpdata(dateFormat.format(new Date()));// 开始时间 DataBaseHelper.update(FinString.ts(sqlMap.get("text")), mapinfo); log.setTimedata(dateFormat.format(new Date()));// 结束时间 } } logger.info("配置菜单sql执行" + tablename + "完成"); } } catch (Exception e) { e.printStackTrace(); log.setBS("0"); log.setSM("配置菜单sql执行" + tablename + "失败"); throw new BusException(e.getMessage()); } finally { systemInitService.insertOptionLog(log); } } public OutData getInitXzqhList(Map<String,Object> p, IUser arg1) { User user = (User)arg1; String sql = ""; List<Map<String, Object>> list = null; try { if(!user.getLoginName().equalsIgnoreCase("admin")){ throw new BusException("初始化只有管理员才能够进行"); } sql = " select de022 id,de021 text from cs021 where length(de0221) = 2 AND DE022 NOT LIKE '99%'"; list = DataBaseHelper.queryForList(sql); OutData data = new OutData(); data.setCode(0); data.setMsg("-"); data.setData(list); return data; } catch (Exception e) { throw new BusException(e.getMessage()); } } /** * * @param * @param arg1 * @return */ public OutData getInitTables(Map<String,Object> p, IUser arg1) { User user = (User)arg1; String sql = ""; List<Map<String, Object>> list = null; sql = "select '0' pid,tb_type id,tb_typenote text from meta_tabletype where tb_type in ( select tb_type from meta_tableinfo where czlb is not null ) union all select tb_type pid, tb_name id,tb_note text from meta_tableinfo where czlb is not null"; list = DataBaseHelper.queryForList(sql); try { OutData data = new OutData(); data.setCode(0); data.setMsg("-"); data.setData(list); return data; } catch (Exception e) { throw new BusException(e.getMessage()); } } /** * * @param * @param arg1 * @return */ public OutData getInitMenuList(Map<String,Object> p, IUser arg1) { User user = (User)arg1; String sql = ""; List<Map<String, Object>> list = null; sql = "select parentid pid,id ,name text from pt_menu t where status=1"; list = DataBaseHelper.queryForList(sql); try { OutData data = new OutData(); data.setCode(0); data.setMsg("-"); data.setData(list); return data; } catch (Exception e) { throw new BusException(e.getMessage()); } } /* public String doSystemInitExp(Map<String,Object> p, IUser arg1) { StringBuffer msg = new StringBuffer(""); try { String enter = "\r\n"; Document maindoc = getDocument(this.getClass().getClassLoader().getResourceAsStream("config/systemInit.xml")); maindoc.selectSingleNode("//finersion").setText(vserion);// msgno字段暂时存放表名 maindoc.selectSingleNode("//fin/isAll").setText("1"); maindoc.selectSingleNode("//fin/de011").setText(de011); maindoc.selectSingleNode("//fin/dataBaseType").setText(dataType); maindoc.selectSingleNode("//fin/ildingUpTime").setText(new SimpleDateFormat("yyyy-MM-dd").format(new Date()).replaceAll("-", "")); maindoc.selectSingleNode("//fin//financialSector").setText(""); String mainStr = maindoc.asXML(); msg = new StringBuffer(mainStr.substring(0, mainStr.indexOf("<functionalMenus>"))); String[] menuid_arr = menuid.split(","); String m_t = ""; if (menuid_arr.length > 0) { for (int k = 0; k < menuid_arr.length; k++) { m_t += "'" + menuid_arr[k] + "',"; } } else { m_t = "'0',"; } m_t = m_t.substring(0, m_t.length() - 1); String sellectSsmenu = "select * from ssmenu where menuid in("+ m_t + ")order by menuid"; List<Map<String, Object>> list_menu = this.getSimpleJdbcTemplate().queryForList(sellectSsmenu); if (list_menu != null && list_menu.size() > 0) { for (int i = 0, len = list_menu.size(); i < len; i++) { msg.append("<menu menuid=\""+ (list_menu.get(i).get("menuid") == null ? "": list_menu.get(i).get("menuid")) + "\" "); msg.append(" menuname=\""+ (list_menu.get(i).get("menuname") == null ? "": list_menu.get(i).get("menuname")) + "\" "); msg.append(" menustatus=\""+ (list_menu.get(i).get("menustatus") == null ? "": list_menu.get(i).get("menustatus"))+ "\" "); msg.append(" menuaction=\""+ (list_menu.get(i).get("menuaction") == null ? "": list_menu.get(i).get("menuaction"))+ "\" "); msg.append(" parentid=\""+ (list_menu.get(i).get("parentid") == null ? "": list_menu.get(i).get("parentid")) + "\" "); msg.append(" displayorder=\""+ (list_menu.get(i).get("displayorder") == null ? "": list_menu.get(i).get("displayorder"))+ "\" "); msg.append(" menuicon=\""+ (list_menu.get(i).get("menuicon") == null ? "": list_menu.get(i).get("menuicon")) + "\" "); msg.append(" xtbz=\""+ (list_menu.get(i).get("xtbz") == null ? "": list_menu.get(i).get("xtbz")) + "\" "); msg.append(" ischeck=\""+ (list_menu.get(i).get("ischeck") == null ? "0": list_menu.get(i).get("ischeck"))+ "\" isFlag=\"\" ></menu> " + enter); } } msg.append(mainStr.substring(mainStr.indexOf("</functionalMenus>"), mainStr.length())); } catch (Exception e) { e.printStackTrace(); } return msg.toString(); }*/ /** * * 生成XML文件 * * @param request * @param response * @throws IOException */ public void initXmlCreate(HttpServletRequest request, HttpServletResponse response) throws IOException { // param 对象来自页面隐藏input元素,内存JSON格式对象 String param = request.getParameter("param"); StringBuffer sb = new StringBuffer(); String path=request.getSession().getServletContext().getRealPath("/"); JSONObject expObj = null; if (param != null) { try { // 获取总体param JSON JSONObject pobj = new JSONObject(param); expObj = pobj.getJSONObject("expObj"); String[] tablelist=expObj.get("TABLELIST").toString().split(",");//选取的表 String[] menulist=expObj.get("MENULIST").toString().split(",");//选取的菜单id String version= FinString.ts( expObj.get("VERSION") ); //String sjqh= FinString.ts( expObj.get("SJQH") ); //创建xml doc Document document = DocumentHelper.createDocument(); Element rootElement = document.addElement("fin"); rootElement.addElement("version").addText(version); String sql = ""; Map tabMap = null; //四大类别 Element type1 = rootElement.addElement("tables"); type1.addAttribute("type", "1"); type1.addAttribute("sm", "清空数据"); Element type2 = rootElement.addElement("tables"); type2.addAttribute("type", "2"); type2.addAttribute("sm", "根据标准版复制数据"); Element type3 = rootElement.addElement("tables"); type3.addAttribute("type", "3"); type3.addAttribute("sm", "根据标准版配置信息生成数据"); Element type4 = rootElement.addElement("sqls"); type4.addAttribute("sm", "通过Sql处理的菜单配置"); /**tablelist处理开始,拼装xml元素**/ sql = " select nvl(czlb,0)czlb ,nvl(tb_name,'-')tb_name ,nvl(tb_note,'-')tb_note,nvl(xzqh_col,'-')xzqh_col from meta_tableinfo where tb_name=? "; for(int i=0;i<tablelist.length;i++){ if("".equals( tablelist[i]) )continue; //获取表初始化配置信息 tabMap=DataBaseHelper.queryForMap(sql, new Object[]{tablelist[i]}); String czlb=FinString.ts(tabMap.get("CZLB")); if("1".equals(czlb)){ Element entity = type1.addElement("tableName"); entity.addAttribute("mc",tabMap.get("TB_NOTE").toString() ); entity.addText(tabMap.get("TB_NAME").toString() ); }else if("2".equals(czlb)){ Element entity = type2.addElement("tableName"); entity.addAttribute("mc",tabMap.get("TB_NOTE").toString() ); entity.addAttribute("xzqh_col", tabMap.get("XZQH_COL").toString() ); entity.addText(tabMap.get("TB_NAME").toString() ); }else if("3".equals(czlb)){ Element entity = type3.addElement("tableName"); entity.addAttribute("mc",tabMap.get("TB_NOTE").toString() ); entity.addAttribute("xzqh_col", tabMap.get("XZQH_COL").toString() ); entity.addText(tabMap.get("TB_NAME").toString() ); }else{ continue; } } /**tablelist处理结束**/ /**menulist处理开始,拼装xml元素**/ sql = " select * from pt_menu where id =? "; Map<?, ?> sqlMap =null; for(int i=0;i<menulist.length;i++){ String sql_col=""; String sql_val=""; if("".equals( menulist[i]) )continue; //获取菜单信息 tabMap=DataBaseHelper.queryForMap(sql, new Object[]{menulist[i]}); //获取insert语句 Iterator<Map.Entry<String, Object>> iterator = tabMap.entrySet().iterator(); while (iterator.hasNext()) { Entry<String, Object> entry = iterator.next(); sql_col =sql_col+","+entry.getKey() ; sql_val =sql_val+",'"+FinString.ts(entry.getValue())+"'" ; } sql_col=sql_col.substring(1, sql_col.length()); sql_val=sql_val.substring(1, sql_val.length()); Element entity = type4.addElement("sql"); entity.addText("insert into pt_menu ("+sql_col+") values ("+sql_val+")"); } /** menulist处理结束 **/ // 文件生成--服务器 OutputFormat format = OutputFormat.createPrettyPrint();// 缩减型格式 format.setEncoding("UTF-8");// 设置文件内部文字的编码 String filepath = path + "initXml.xml"; FileWriter fw = new FileWriter(new File(filepath)); OutputStreamWriter outstream = new OutputStreamWriter( new FileOutputStream(filepath),"UTF-8");//设置文件的编码! XMLWriter writer = new XMLWriter(outstream, format); writer.write(document); fw.close(); writer.close(); document = null; // 文件生成--客户端 response.setContentType("text/html; charset=UTF-8"); String filename = "initXml.xml" ; response.setHeader("Content-Disposition", "attachment; filename=" + new String(filename.getBytes("gb2312"),"ISO8859-1")); InputStream in = null; OutputStream out = null; try { in = new FileInputStream(filepath); out = response.getOutputStream(); int len = 0; byte[] buffer = new byte[1024]; response.setCharacterEncoding("UTF-8"); while ((len = in.read(buffer)) > 0) { out.write(buffer, 0, len); } } catch (FileNotFoundException e) { } finally { if (in != null) { try { in.close(); } catch (Exception e) { throw new RuntimeException(e); } } if (out != null) { try { out.close(); } catch (Exception e) { throw new RuntimeException(e); } } } } catch (Exception e) { e.printStackTrace(); } } else { PrintWriter Pout = null; try { response.setContentType("text/html; charset=UTF-8"); Pout = response.getWriter(); Pout.println("<script>alert('参数传入失败!');</script>"); Pout.flush(); } catch (Exception e) { e.printStackTrace(); } finally { Pout.close(); } } } }
package com.finstone.app.common.service; import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.lang.reflect.Method; import java.net.URLDecoder; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; import java.util.Map.Entry; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import java.util.zip.ZipInputStream; import java.sql.CallableStatement; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.text.SimpleDateFormat; import javax.annotation.Resource; import oracle.jdbc.OracleTypes; import org.dom4j.Document; import org.dom4j.Element; import org.dom4j.io.SAXReader; import org.springframework.dao.DataAccessException; import org.springframework.jdbc.core.CallableStatementCallback; import org.springframework.jdbc.support.lob.LobHandler; import org.springframework.stereotype.Repository; import org.springframework.stereotype.Service; import org.springframework.util.ClassUtils; import com.fins.common.exception.BusException; import com.fins.html.view.data.OutData; import com.fins.modules.dao.DataBaseHelper; import com.finstone.app.common.support.SystemInitLogEntity; import com.finstone.app.common.support.User; import com.finstone.app.core.BaseDaoSupport; import com.finstone.app.core.support.IUser; import com.finstone.app.core.support.ResultStatus; import com.finstone.zxt.common.service.GkbCommGetSqlDataService; import com.finstone.zxt.common.tool.EncryptForNet; import com.finstone.zxt.common.tool.FinString; import com.finstone.zxt.common.tool.UnzipResource; @SuppressWarnings("unchecked") @Service public class SystemInitService extends BaseDaoSupport { @Resource(name = "gkbCommGetSqlDataService") private GkbCommGetSqlDataService gkbCommGetSqlDataService; @Resource private LobHandler lobHandler; /* * author:正在改变 系统初始化 导入xml文件初始化 */ public SystemInitLogEntity doSystemInitImp(byte[] file , String yde022) { String temp_Sql = ""; String sm = ""; SAXReader saxReader = null;// xml解析器 InputStream in_xml = null; String developer = ""; String fcilityPrsonnel = ""; SystemInitLogEntity log = new SystemInitLogEntity(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try{ saxReader = new SAXReader(); in_xml = new ByteArrayInputStream(file); Document document = saxReader.read(in_xml); String path = URLDecoder.decode(this.getClass().getClassLoader().getResource("/").getPath(), "UTF-8"); Document document_init = saxReader.read(new File(path+ "com\\finstone\\fap\\logic\\systemInit\\service\\systemInitSqls.xml")); String isAll = document.selectSingleNode("//fin/isAll").getText().trim(); String xml_de011 = document.selectSingleNode("//fin/de011").getText().trim(); String dataBaseType = document.selectSingleNode("//fin/dataBaseType").getText().trim(); String admdiv_source = ""; String admdiv_target = ""; // 处理行政区划 List list = document.selectNodes("//admdivs/admdiv"); Iterator iter = list.iterator(); while (iter.hasNext()) { Element n = (Element) iter.next(); admdiv_source = n.attributeValue("source"); admdiv_target = n.attributeValue("target"); } list = document.selectNodes("//developers/developer"); iter = list.iterator(); while (iter.hasNext()) { Element n = (Element) iter.next(); developer += n.getText() + ","; } list = document.selectNodes("//fcilityPrsonnels/fcilityPrsonnel"); iter = list.iterator(); while (iter.hasNext()) { Element n = (Element) iter.next(); fcilityPrsonnel += n.getText() + ","; } log.setDE011(xml_de011); log.setDE022(admdiv_target); log.setDEVELOPERS(developer); log.setFCILITYPRSONNEL(fcilityPrsonnel); log.setSOURCEDE022(admdiv_source); log.setUpdata(dateFormat.format(new Date())); log.setBS("1"); log.setLx(1); if (!yde022.equals(admdiv_source)) { sm = "初始化文档初始化源财政地区与选择财政地区不一致,请检查后再初始化.文档中:" + admdiv_source+ ",选择的为:" + yde022; log.setBS("0"); log.setSM(sm); return log; } if (admdiv_source.trim().equals("") || admdiv_target.trim().equals("")) { sm = "<admdivs>子节点元素必需填写,请检查xml初始化文档"; log.setBS("0"); log.setSM(sm); return log; } if (admdiv_source.equals(admdiv_target)) { sm = "财政地区源和目标不可以相同"; log.setBS("0"); log.setSM(sm); return log; } // 初始化 处理菜单 list = document.selectNodes("//functionalMenus/menu"); if (list != null && list.size() > 0) { int len = list.size(); String[] sql_arr = new String[len]; for (int i = 0; i < len; i++) { String insert_ssmenu = "insert into ssmenu("; StringBuffer sb_n = new StringBuffer(); StringBuffer sb_v = new StringBuffer(); Element element = (Element) list.get(i); sb_n.append("menuid" + ","); sb_v.append("'" + element.attributeValue("menuid") + "',"); sb_n.append("menuname" + ","); sb_v.append("'" + element.attributeValue("menuname") + "',"); sb_n.append("menustatus" + ","); sb_v.append("'" + element.attributeValue("menustatus") + "',"); sb_n.append("menuaction" + ","); sb_v.append("'" + element.attributeValue("menuaction") + "',"); sb_n.append("parentid" + ","); sb_v.append("'" + element.attributeValue("parentid") + "',"); sb_n.append("displayorder" + ","); sb_v.append("'" + element.attributeValue("displayorder") + "',"); sb_n.append("menuicon" + ","); sb_v.append("'" + element.attributeValue("menuicon") + "',"); sb_n.append("xtbz" + ","); sb_v.append("'" + element.attributeValue("xtbz") + "',"); sb_n.append("ischeck" + ""); sb_v.append("'" + element.attributeValue("ischeck") + "'"); insert_ssmenu = insert_ssmenu + sb_n.toString() + ")values("+ sb_v.toString() + ")"; sql_arr[i] = insert_ssmenu; temp_Sql=insert_ssmenu; } // 批量执行 if (isAll.trim().equals("0")) {// 全量 先删除后插入 this.getJdbcTemplate().update("delete from ssmenu"); } // 执行批量执行 sql_arr this.getJdbcTemplate().batchUpdate(sql_arr); } list = document_init.selectNodes("//tables/tableName"); if (list != null && list.size() > 0) {// 主要是处理 源 sm += ".表配置初始化涉及表:"; int len = list.size(); for (int i = 0; i < len; i++) { Element element = (Element) list.get(i); // isDe011="1" isDe022="1" String isDe011 = element.attributeValue("isDe011"); if (dataBaseType.equals("1")||dataBaseType.equals("2")) {// 公司统一开发库 稳定区数据库 String table_name = element.getText().replaceAll("\n", "").replaceAll("\t", "").trim(); System.out.println("执行表拷贝"+table_name); sm += table_name + ","; if (isDe011.trim().equals("1")) {// 包含年份 this.copyTableData(table_name, admdiv_source,admdiv_target, xml_de011.trim()); } else {// 不包含年份 表 this.copyTableData(table_name, admdiv_source,admdiv_target, null); } } } } // 执行特殊业务sql list = document_init.selectNodes("//sqls/sql"); // iter = list.iterator(); if (list != null && list.size() > 0) { sm += ".执行sql节点:"; int len = list.size(); for (int i = 0; i < len; i++) { Element element = (Element) list.get(i);// isDe011="1" isDe022="1" if (dataBaseType.equals("1") ) {// 公司统一开发库 稳定区数据库 // --第一步 :业务数据库全部删除 temp_Sql = element.getText(); System.out.println("执行表删除:"+temp_Sql); try{ this.getJdbcTemplate().update(temp_Sql); }catch(Exception e){ e.printStackTrace(); } } } } // 处理 财政内部机构 01 temp_Sql = "delete Cs061 where de022 not like '"+ admdiv_target.substring(0, 4) + "%' or de022="+ admdiv_target; this.getJdbcTemplate().update(temp_Sql); temp_Sql = "insert into Cs061(de011,de062,de061,de022,Jsde017,Ptbz) values(?,'01','财政局',?,0,0)"; this.getJdbcTemplate().update(temp_Sql,new Object[] { xml_de011, admdiv_target }); // 初始化用户 //保留 fin 0 temp_Sql = "delete jscs007 where de022 not like '"+ admdiv_target.substring(0, 4) + "%' or de022="+ admdiv_target; this.getJdbcTemplate().update(temp_Sql); int jsde909 = this.getJdbcTemplate().queryForInt("select nvl(max(jsde909),-1)+1 from jscs007"); temp_Sql = "insert into jscs007(jsde909,jsde908,jsde910,jsde911,jsde901,jsde001,de001,de022,jsde039,de042)values(?,'系统管理员','FIN','2bb56fc8eb1029a1a6090fdfafc896dd','909090','0',sysdate,?,'21','000')"; this.getJdbcTemplate().update(temp_Sql,new Object[] { jsde909, admdiv_target }); // 用户属于内部机构 0- 01 this.getJdbcTemplate().update("insert into cfg018(de011,de062,jsde909,de022)values(?,'01','0',?)",new Object[] { xml_de011, admdiv_target }); temp_Sql = "delete jscs013 where (de022 not like '"+ admdiv_target.substring(0, 4) + "%' or de022="+ admdiv_target + ") and de011=" + xml_de011; this.getJdbcTemplate().update(temp_Sql); temp_Sql = "insert into jscs013(de011,jsde023,de022,ischeck,checknote) values(?,1,?,'0','合法性未检查')"; this.getJdbcTemplate().update(temp_Sql,new Object[] { xml_de011, admdiv_target }); // 处理 财政地区 temp_Sql = "delete Cs021 where de022=" + admdiv_target+ " and de011=" + xml_de011; this.getJdbcTemplate().update(temp_Sql); String de022Mc = (String) this.getJdbcTemplate().queryForObject("select de021 from cs021 where de011=1900 and de022="+ admdiv_target, String.class); temp_Sql = "insert into Cs021(de022,de021,jsde901,de011,Ptbz) values(?,?,null,?,2)"; this.getJdbcTemplate().update(temp_Sql,new Object[] { admdiv_target, de022Mc, xml_de011 }); list = document.selectNodes("//sqls/sql"); // iter = list.iterator(); if (list != null && list.size() > 0) { sm += ".执行sql节点:"; int len = list.size(); for (int i = 0; i < len; i++) { Element element = (Element) list.get(i);// isDe011="1" isDe022="1" if (dataBaseType.equals("1") ) {// 公司统一开发库 稳定区数据库 // --第一步 :业务数据库全部删除 temp_Sql = element.getText(); System.out.println("执行表删除:"+temp_Sql); try{ this.getJdbcTemplate().update(temp_Sql); }catch(Exception e){ e.printStackTrace(); } } } } }catch(Exception e){ e.printStackTrace(); // throw new Exception(e.getMessage()+"sql:"+temp_Sql); } finally { if(in_xml != null) { try { in_xml.close(); } catch (IOException e) { in_xml = null; } } } return log; } public static void main(String[] args) { // LinkedHashMap<String, String> test = new LinkedHashMap<String, String>(); // test.put("1", "w");test.put("2", "e");test.put("3", "r");test.put("4", "t"); // for(Iterator<String> it = test.keySet().iterator(); it.hasNext();) { // String key = it.next(); // System.out.println(key + "-" + test.get(key)); // } // System.out.println(test.values().toArray()); // Object [] arrays = test.entrySet().toArray(); // for(Object o : arrays){ // System.out.print(o); // } // Object [] arrays = test.values().toArray(); // for(Object o : arrays){ // System.out.print(o); // } // String str = "~1~2~3~4~5~6~7~8~9~"; // String [] s = str.split("~"); // for (String sq1 : s) { // System.out.println(sq1); // } ArrayList<String> list = new ArrayList<String>(); Method[] m = list.getClass().getMethods(); for (Method ms : m) { System.out.println(ms.getName()); } try { System.out.println(list.getClass().getMethod("get").getReturnType()); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } } /* * 自动升级处理 * author:转接于财政1.0平台 胡晶2013426进行部分优化修改 * */ public void doAutoUpgradeImport(String file,String de022, SystemInitLogEntity log) { InputStream in = null; ZipInputStream zin = null; ZipEntry ze = null; BufferedReader br = null; ZipFile zf = null; try{ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String sm = ""; log.setLx(3); log.setBS("1"); log.setFunname("系统自动升级处理"); log.setTimedata(dateFormat.format(new Date())); zf = new ZipFile(file); List<String> dml_gxh = new ArrayList<String>(); List<String> dml = new ArrayList<String>(); List<String> version = new ArrayList<String>(); List<String> ddl = new ArrayList<String>(); List<String> vw_list = new ArrayList<String>();//视图 List<String> seq_list = new ArrayList<String>();//序列 List<String> syn_list = new ArrayList<String>();//同义词 List<String> fnc_list = new ArrayList<String>();//函数 List<String> prc_list = new ArrayList<String>();//存储过程 List<String> spc_list = new ArrayList<String>();//包头 List<String> bdy_list = new ArrayList<String>();//包体 List<String> trg_list = new ArrayList<String>();// 触发器 List<Map<String,Object>> list_de022=DataBaseHelper.queryForList("select distinct de022 from cs061 where de022 like rtrim('"+de022+"','0')||'%'"); in = new BufferedInputStream(new FileInputStream(file)); zin = new ZipInputStream(in); while ((ze = zin.getNextEntry()) != null) { if (ze.isDirectory()) { continue; } if (ze.getName().toLowerCase().endsWith(".sql") || ze.getName().toLowerCase().endsWith(".~sql")) { continue; } if (ze.getSize() <= 0) { continue; } String sql = ""; br = new BufferedReader(new InputStreamReader(zf.getInputStream(ze),"gb2312")); if (ze.getName().endsWith("configVer.xml")) {// 获取版本信息 br = new BufferedReader(new InputStreamReader(zf.getInputStream(ze),"utf-8")); String line; while ((line = br.readLine()) != null) { line = line.trim(); version.add(line.replaceAll(";", "")); } } String file_name="personal/"+de022.trim()+"/"; if (ze.getName().startsWith(file_name)) {// 处理个性化 sql String line; sql = ""; while ((line = br.readLine()) != null) { if(line.contains("--")) { line = line.trim().startsWith("--") ? "" : line.substring(0, line.indexOf("--")); } if(line.trim().equals("")) continue; sql += line + "\n"; if (line.contains(";")) { sql=sql.trim(); String ss=sql.toLowerCase();//小写处理,方便语句判断 /* if (ss.startsWith("insert")|| ss.startsWith("delete")|| ss.startsWith("update")|| ss.startsWith("selete")) { if(sql.contains("999999")) for(int ii=0,len=list_de022.size();ii<len;ii++){ dml_gxh.add(sql.trim().replaceAll(";", "").replaceAll("999999", String.valueOf(list_de022.get(ii).get("de022")))); } else dml_gxh.add(sql.trim().replaceAll(";", "")); } */ if (ss.startsWith("insert") ) { //更新语句的表名 String tab_name = ss.substring( ss.indexOf("into")+4, ss.indexOf("(")).trim(); //更新表 初始化 信息(是否需要特殊处理) Map tabMap =DataBaseHelper.queryForMap (" select * from META_TABLEINFO where lower(tb_name) =? and (czlb between 2 and 3) and rownum=1 ", new Object[]{tab_name}); if( tabMap.isEmpty() ){ dml_gxh.add(sql.replaceAll(";", "")); }else{ String xzqh_col=tabMap.get("XZQH_COL").toString().trim(); String czlb= tabMap.get("CZLB").toString().toLowerCase();;//2:复制数据 3:扩展区划 //ss与sql区别于大小写,使用sql保留原语句大小写之分 String colAry[]= sql.substring(ss.indexOf("(")+1 , ss.indexOf(")") ).split(",") ; String valAry[]= sql.substring(ss.lastIndexOf("(")+1 , ss.lastIndexOf(")") ).split(",") ; /**操作判断,处理开始*/ if("2".equals(czlb) ){ //复制数据 String colStr=""; String valStr=""; //将values()中的行政区划值作标志,方便替换 for(int i=0;i<colAry.length;i++ ){ if( colAry[i].trim().equalsIgnoreCase(xzqh_col)){ valAry[i]="'#DE022#'"; } colStr=colStr+ colAry[i]+","; valStr=valStr+ valAry[i]+","; } colStr=colStr.substring(0, colStr.length()-1); valStr=valStr.substring(0, valStr.length()-1); ss= "insert into "+tab_name +"("+colStr+")"+"values ("+valStr+")"; dml_gxh.add(ss.trim().replaceAll(";", "").replaceAll("#DE022#",de022)); }else{ //扩展当前省级下的区划 for(int ii=0,len=list_de022.size(); ii<len ;ii++){ String colStr=""; String valStr=""; //将values()中的行政区划值作标志,方便替换 for(int i=0;i<colAry.length;i++ ){ if( colAry[i].trim().equalsIgnoreCase(xzqh_col)){ valAry[i]="'#DE022#'"; } colStr=colStr+ colAry[i]+","; valStr=valStr+ valAry[i]+","; } colStr=colStr.substring(0, colStr.length()-1); valStr=valStr.substring(0, valStr.length()-1); ss= "insert into "+tab_name +"("+colStr+")"+"values ("+valStr+")"; dml_gxh.add(ss.trim().replaceAll(";", "").replaceAll("#DE022#", String.valueOf(list_de022.get(ii).get("de022")))); } } } }else if( ss.startsWith("update")){ //更新语句的表名 String tab_name = ss.substring( ss.indexOf("update")+6, ss.indexOf("set")).trim(); //更新表 初始化 信息(是否需要特殊处理) Map tabMap =DataBaseHelper.queryForMap (" select * from META_TABLEINFO where lower(tb_name) =? and (czlb between 2 and 3) and rownum=1 ", new Object[]{tab_name}); if( tabMap.isEmpty() ){ dml_gxh.add(sql.trim().replaceAll(";", "")); }else{ String xzqh_col=tabMap.get("XZQH_COL").toString().trim().toLowerCase(); String czlb= tabMap.get("CZLB").toString().toLowerCase();;//2:复制数据 3:扩展区划 String whereAry[]= sql.substring(ss.indexOf("where")+5 , ss.length() ).split("and") ; /**操作判断,处理开始*/ if("2".equals(czlb) ){ //复制数据 String whereStr=" "; //分隔where后的条件语句 for(int i=0;i<whereAry.length;i++ ){ if( whereAry[i].toLowerCase().indexOf(xzqh_col) >0 ){ whereAry[i]= xzqh_col+ "='#DE022#' "; } whereStr =whereStr+ whereAry[i]+" and "; } whereStr=whereStr.substring(0, whereStr.lastIndexOf("and")); ss= ss.substring(0, ss.indexOf("where"))+" where "+whereStr; ss=ss.trim().replaceAll(";", "").replaceAll("#DE022#",de022); dml_gxh.add(ss); }else{ sql= sql.substring(0,ss.indexOf("where"));//避免ss在循环中改变 //扩展当前省级下的区划 for(int ii=0,len=list_de022.size(); ii<len ;ii++){ //复制数据 String whereStr=" "; //分隔where后的条件语句 for(int i=0;i<whereAry.length;i++ ){ if( whereAry[i].toLowerCase().indexOf(xzqh_col) >0 ){ whereAry[i]= xzqh_col+ "='#DE022#' "; } whereStr =whereStr+ whereAry[i]+" and "; } whereStr=whereStr.substring(0, whereStr.lastIndexOf("and")); ss= sql+" where "+whereStr; ss=ss.trim().replaceAll(";", "").replaceAll("#DE022#",String.valueOf(list_de022.get(ii).get("de022") )); dml_gxh.add(ss ); } } } }else if( ss.startsWith("delete")){ //删除语句的表名 String tab_name = ss.substring( ss.indexOf("from")+4, ss.indexOf("where")).trim(); //更新表 初始化 信息(是否需要特殊处理) Map tabMap =DataBaseHelper.queryForMap (" select * from META_TABLEINFO where lower(tb_name) =? and (czlb between 2 and 3) and rownum=1 ", new Object[]{tab_name}); if( tabMap.isEmpty() ){ dml_gxh.add(sql.trim().replaceAll(";", "")); }else{ String xzqh_col=tabMap.get("XZQH_COL").toString().trim().toLowerCase(); String czlb= tabMap.get("CZLB").toString().toLowerCase();;//2:复制数据 3:扩展区划 String whereAry[]= sql.substring(ss.indexOf("where")+5 , ss.length() ).split("and") ; /**操作判断,处理开始*/ if("2".equals(czlb) ){ //复制数据 String whereStr=" "; //分隔where后的条件语句 for(int i=0;i<whereAry.length;i++ ){ if( whereAry[i].toLowerCase().indexOf(xzqh_col) >0 ){ whereAry[i]= xzqh_col+ "='#DE022#' "; } whereStr =whereStr+ whereAry[i]+" and "; } whereStr=whereStr.substring(0, whereStr.lastIndexOf("and")); ss= ss.substring(0, ss.indexOf("where"))+" where "+whereStr; ss=ss.trim().replaceAll(";", "").replaceAll("#DE022#",de022); dml_gxh.add(ss); }else{ sql= sql.substring(0,ss.indexOf("where"));//避免ss在循环中改变 //扩展当前省级下的区划 for(int ii=0,len=list_de022.size(); ii<len ;ii++){ //复制数据 String whereStr=" "; //分隔where后的条件语句 for(int i=0;i<whereAry.length;i++ ){ if( whereAry[i].toLowerCase().indexOf(xzqh_col) >0 ){ whereAry[i]= xzqh_col+ "='#DE022#' "; } whereStr =whereStr+ whereAry[i]+" and "; } whereStr=whereStr.substring(0, whereStr.lastIndexOf("and")); ss= sql+" where "+whereStr; ss=ss.trim().replaceAll(";", "").replaceAll("#DE022#",String.valueOf(list_de022.get(ii).get("de022") )); dml_gxh.add(ss ); } } } } else { dml_gxh.add(sql.trim().replaceAll(";", "")); } sql = ""; } } } if (ze.getName().startsWith("Upgrade/dml/")) {// 处理 数据库操作语言 String line; sql = ""; while ((line = br.readLine()) != null) { if(line.contains("--")) { line = line.trim().startsWith("--") ? "" : line.substring(0, line.indexOf("--")); } if(line.trim().equals("")) continue; sql += line + "\n"; if (line.contains(";")) { sql=sql.trim(); String ss=sql.trim().toLowerCase();//小写处理,方便语句判断 if (ss.startsWith("insert") ) { //更新语句的表名 String tab_name = ss.substring( ss.indexOf("into")+4, ss.indexOf("(")).trim(); //更新表 初始化 信息(是否需要特殊处理) Map tabMap =DataBaseHelper.queryForMap (" select * from META_TABLEINFO where lower(tb_name) =? and (czlb between 2 and 3) and rownum=1 ", new Object[]{tab_name}); if( tabMap.isEmpty() ){ dml_gxh.add(sql.trim().replaceAll(";", "")); }else{ String xzqh_col=tabMap.get("XZQH_COL").toString().trim(); String czlb= tabMap.get("CZLB").toString().toLowerCase();;//2:复制数据 3:扩展区划 //ss与sql区别于大小写,使用sql保留原语句大小写之分 String colAry[]= sql.substring(ss.indexOf("(")+1 , ss.indexOf(")") ).split(",") ; String valAry[]= sql.substring(ss.lastIndexOf("(")+1 , ss.lastIndexOf(")") ).split(",") ; /**操作判断,处理开始*/ if("2".equals(czlb) ){ //复制数据 String colStr=""; String valStr=""; //将values()中的行政区划值作标志,方便替换 for(int i=0;i<colAry.length;i++ ){ if( colAry[i].trim().equalsIgnoreCase(xzqh_col)){ valAry[i]="'#DE022#'"; } colStr=colStr+ colAry[i]+","; valStr=valStr+ valAry[i]+","; } colStr=colStr.substring(0, colStr.length()-1); valStr=valStr.substring(0, valStr.length()-1); ss= "insert into "+tab_name +"("+colStr+")"+"values ("+valStr+")"; dml_gxh.add(ss.trim().replaceAll(";", "").replaceAll("#DE022#",de022)); }else{ //扩展当前省级下的区划 for(int ii=0,len=list_de022.size(); ii<len ;ii++){ String colStr=""; String valStr=""; //将values()中的行政区划值作标志,方便替换 for(int i=0;i<colAry.length;i++ ){ if( colAry[i].trim().equalsIgnoreCase(xzqh_col)){ valAry[i]="'#DE022#'"; } colStr=colStr+ colAry[i]+","; valStr=valStr+ valAry[i]+","; } colStr=colStr.substring(0, colStr.length()-1); valStr=valStr.substring(0, valStr.length()-1); ss= "insert into "+tab_name +"("+colStr+")"+"values ("+valStr+")"; dml_gxh.add(ss.trim().replaceAll(";", "").replaceAll("#DE022#", String.valueOf(list_de022.get(ii).get("de022")))); } } } }else if( ss.startsWith("update")){ //更新语句的表名 String tab_name = ss.substring( ss.indexOf("update")+6, ss.indexOf("set")).trim(); //更新表 初始化 信息(是否需要特殊处理) Map tabMap =DataBaseHelper.queryForMap (" select * from META_TABLEINFO where lower(tb_name) =? and (czlb between 2 and 3) and rownum=1 ", new Object[]{tab_name}); if( tabMap.isEmpty() ){ dml_gxh.add(sql.trim().replaceAll(";", "")); }else{ String xzqh_col=tabMap.get("XZQH_COL").toString().trim().toLowerCase(); String czlb= tabMap.get("CZLB").toString().toLowerCase();;//2:复制数据 3:扩展区划 //ss与sql区别于大小写,使用sql保留原语句大小写之分 String whereAry[]= sql.substring(ss.indexOf("where")+5 , ss.length() ).split("and") ; /**操作判断,处理开始*/ if("2".equals(czlb) ){ //复制数据 String whereStr=" "; //分隔where后的条件语句 for(int i=0;i<whereAry.length;i++ ){ if( whereAry[i].toLowerCase().indexOf(xzqh_col) >0 ){ whereAry[i]= xzqh_col+ "='#DE022#' "; } whereStr =whereStr+ whereAry[i]+" and "; } whereStr=whereStr.substring(0, whereStr.lastIndexOf("and")); ss= sql.substring(0, ss.indexOf("where"))+" where "+whereStr; ss=ss.trim().replaceAll(";", "").replaceAll("#DE022#",de022); dml_gxh.add(ss); }else{ sql= sql.substring(0,ss.indexOf("where"));//避免ss在循环中改变 //扩展当前省级下的区划 for(int ii=0,len=list_de022.size(); ii<len ;ii++){ //复制数据 String whereStr=" "; //分隔where后的条件语句 for(int i=0;i<whereAry.length;i++ ){ if( whereAry[i].toLowerCase().indexOf(xzqh_col) >0 ){ whereAry[i]= xzqh_col+ "='#DE022#' "; } whereStr =whereStr+ whereAry[i]+" and "; } whereStr=whereStr.substring(0, whereStr.lastIndexOf("and")); ss= sql+" where "+whereStr; ss=ss.trim().replaceAll(";", "").replaceAll("#DE022#",String.valueOf(list_de022.get(ii).get("de022") )); dml_gxh.add(ss ); } } } }else if( ss.startsWith("delete")){ //删除语句的表名 String tab_name = ss.substring( ss.indexOf("from")+4, ss.indexOf("where")).trim(); //更新表 初始化 信息(是否需要特殊处理) Map tabMap =DataBaseHelper.queryForMap (" select * from META_TABLEINFO where lower(tb_name) =? and (czlb between 2 and 3) and rownum=1 ", new Object[]{tab_name}); if( tabMap.isEmpty() ){ dml_gxh.add(sql.trim().replaceAll(";", "")); }else{ String xzqh_col=tabMap.get("XZQH_COL").toString().trim().toLowerCase(); String czlb= tabMap.get("CZLB").toString().toLowerCase();;//2:复制数据 3:扩展区划 //ss与sql区别于大小写,使用sql保留原语句大小写之分 String whereAry[]= sql.substring(ss.indexOf("where")+5 , ss.length() ).split("and") ; /**操作判断,处理开始*/ if("2".equals(czlb) ){ //复制数据 String whereStr=" "; //分隔where后的条件语句 for(int i=0;i<whereAry.length;i++ ){ if( whereAry[i].toLowerCase().indexOf(xzqh_col) >0 ){ whereAry[i]= xzqh_col+ "='#DE022#' "; } whereStr =whereStr+ whereAry[i]+" and "; } whereStr=whereStr.substring(0, whereStr.lastIndexOf("and")); ss= ss.substring(0, ss.indexOf("where"))+" where "+whereStr; ss=ss.trim().replaceAll(";", "").replaceAll("#DE022#",de022); dml_gxh.add(ss); }else{ sql= sql.substring(0,ss.indexOf("where"));//避免ss在循环中改变 //扩展当前省级下的区划 for(int ii=0,len=list_de022.size(); ii<len ;ii++){ //复制数据 String whereStr=" "; //分隔where后的条件语句 for(int i=0;i<whereAry.length;i++ ){ if( whereAry[i].toLowerCase().indexOf(xzqh_col) >0 ){ whereAry[i]= xzqh_col+ "='#DE022#' "; } whereStr =whereStr+ whereAry[i]+" and "; } whereStr=whereStr.substring(0, whereStr.lastIndexOf("and")); ss= sql+" where "+whereStr; ss=ss.trim().replaceAll(";", "").replaceAll("#DE022#",String.valueOf(list_de022.get(ii).get("de022") )); dml_gxh.add(ss ); } } } } else { dml_gxh.add(sql.trim().replaceAll(";", "")); } sql = ""; } } } if (ze.getName().startsWith("Upgrade/ddl/")) {// 处理 数据库定义语言 String line; sql = ""; while ((line = br.readLine()) != null) { if(line.contains("--")) { line = line.trim().startsWith("--") ? "" : line.substring(0, line.indexOf("--")); } if(line.trim().equals("")) continue; sql += line + "\n"; if (line.contains(";")) { String ss=sql.trim().toLowerCase(); if(ss.startsWith("drop")||ss.startsWith("create")||ss.startsWith("alter")){ ddl.add(sql.trim().replaceAll(";", "")); } sql = ""; } } } if (ze.getName().startsWith("proBody/vw/")) {// 处理视图 String line; StringBuffer sb=new StringBuffer(); while ((line = br.readLine()) != null) { sb.append(line + "\n"); } sql=sb.toString(); if (sql.trim().endsWith(";")) {// 截取最后一个/ sql = sql.substring(0, sql.lastIndexOf(";")); } vw_list.add(sql); } if (ze.getName().startsWith("proBody/seq/")) {// 处理序列 String line; StringBuffer sb=new StringBuffer(); while ((line = br.readLine()) != null) { sb.append(line + "\n"); } sql=sb.toString(); if (sql.trim().endsWith(";")) {// 截取最后一个/ sql = sql.substring(0, sql.lastIndexOf(";")); } seq_list.add(sql); } if (ze.getName().startsWith("proBody/syn/")) {// 处理视图 String line; StringBuffer sb=new StringBuffer(); while ((line = br.readLine()) != null) { sb.append(line + "\n"); } sql=sb.toString(); if (sql.trim().endsWith(";")) {// 截取最后一个/ sql = sql.substring(0, sql.lastIndexOf(";")); } syn_list.add(sql); } if (ze.getName().startsWith("proBody/fnc/")) {// 处理函数 String line; StringBuffer sb=new StringBuffer(); while ((line = br.readLine()) != null) { sb.append(line + "\n"); } sql=sb.toString(); if (sql.trim().endsWith("/")) {// 截取最后一个/ sql = sql.substring(0, sql.lastIndexOf("/")); } fnc_list.add(sql); } if (ze.getName().startsWith("proBody/prc/")) {// 处理存储过程 String line; StringBuffer sb=new StringBuffer(); while ((line = br.readLine()) != null) { sb.append(line + "\n"); } sql=sb.toString(); if (sql.trim().endsWith("/")) {// 截取最后一个/ sql = sql.substring(0, sql.lastIndexOf("/")); } prc_list.add(sql); } if (ze.getName().startsWith("proBody/spc/")) {// 处理包头 String line; StringBuffer sb=new StringBuffer(); while ((line = br.readLine()) != null) { sb.append(line + "\n"); } sql=sb.toString(); if (sql.trim().endsWith("/")) {// 截取最后一个/ sql = sql.substring(0, sql.lastIndexOf("/")); } spc_list.add(sql); } if (ze.getName().startsWith("proBody/bdy/")) {// 处理包体 String line; StringBuffer sb=new StringBuffer(); while ((line = br.readLine()) != null) { sb.append(line + "\n"); } sql=sb.toString(); if (sql.trim().endsWith("/")) {// 截取最后一个/ sql = sql.substring(0, sql.lastIndexOf("/")); } bdy_list.add(sql); } if (ze.getName().startsWith("proBody/trg/")) {// 处理触发器 String line; StringBuffer sb=new StringBuffer(); while ((line = br.readLine()) != null) { sb.append(line + "\n"); } sql=sb.toString(); if (sql.trim().endsWith("/")) {// 截取最后一个/ sql = sql.substring(0, sql.lastIndexOf("/")); } trg_list.add(sql); } zin.closeEntry(); } if (ddl.size() > 0) { sm+="共处理ddl"+ddl.size()+"条;"; String stemp=""; for(int kk=0;kk < ddl.size();kk++){ try{ DataBaseHelper.update(ddl.get(kk)); }catch(Exception e){ if(ddl.get(kk).length()>30){ stemp+=ddl.get(kk).substring(0, 20)+"...|"; }else{ stemp+=ddl.get(kk)+"|"; } e.printStackTrace(); } } if(!stemp.equals("")){ sm+="(其中出错语句:"+stemp+")";} } if (dml_gxh.size() > 0) { String stemp=""; sm+="共处理个性化dml"+dml_gxh.size()+"条;"; for(int kk=0,len=dml_gxh.size();kk<len;kk++){ try{ DataBaseHelper.update(dml_gxh.get(kk)); }catch(Exception e){ stemp+=dml_gxh.get(kk)+"|"; e.printStackTrace(); } } if(!stemp.equals("")){ sm+="(其中出错语句:"+stemp+")";} } if (dml.size() > 0) { sm+="共处理dml:"+dml.size()+"条,"; String stemp=""; for(int kk=0,len=dml.size();kk<len;kk++){ try{ DataBaseHelper.update(dml.get(kk)); }catch(Exception e){ stemp+=dml.get(kk)+"|"; e.printStackTrace(); } } if(!stemp.equals("")){ sm+="(出错:"+stemp+")";} } if (vw_list.size() > 0) { sm+="共处理(vm)"+vw_list.size()+"条;"; try{ DataBaseHelper.batchUpdate((String[])ListToArray(vw_list)); }catch(Exception e){ e.printStackTrace(); } } if (seq_list.size() > 0) { sm+="共处理(seq)"+seq_list.size()+"条;"; for(int kk=0,len=seq_list.size();kk<len;kk++){ try{ DataBaseHelper.update(seq_list.get(kk)); }catch(Exception e){ e.printStackTrace(); } } } try{ if (syn_list.size() > 0) { sm+="共处理(syn)"+syn_list.size()+"条;"; DataBaseHelper.batchUpdate((String[])ListToArray(syn_list)); } if (fnc_list.size() > 0) { sm+="共处理(fnc)"+fnc_list.size()+"条;"; DataBaseHelper.batchUpdate((String[])ListToArray(fnc_list)); } if (prc_list.size() > 0) { sm+="共处理(prc)"+prc_list.size()+"条;"; DataBaseHelper.batchUpdate(prc_list.toArray(new String[fnc_list.size()])); } if (spc_list.size() > 0) { sm+="共处理(spc)"+spc_list.size()+"条;"; DataBaseHelper.batchUpdate(spc_list.toArray(new String[spc_list.size()])); } if (bdy_list.size() > 0) { sm+="共处理(bdy)"+bdy_list.size()+"条;"; DataBaseHelper.batchUpdate(bdy_list.toArray(new String[bdy_list.size()])); } if (trg_list.size() > 0) { sm+="共处理(trg)"+trg_list.size()+"条;"; DataBaseHelper.batchUpdate(trg_list.toArray(new String[trg_list.size()])); } }catch(Exception e){ e.printStackTrace();//这里屏蔽掉异常 } log.setBS("1"); if(sm.length()>=1000){ sm=sm.substring(0,1000); } log.setSM(sm); }catch(Exception e){ e.printStackTrace(); log.setBS("0"); throw new RuntimeException("升级出错:"+e.getMessage()); } finally { //关闭流 2014-5-23 hujing if(in != null) { try { in.close(); } catch (IOException e) { in = null; } } if(zin != null) { try { zin.close(); } catch (IOException e) { zin = null; } } if(br != null) { try { br.close(); } catch (IOException e) { br = null; } } if(zf != null) { try { zf.close(); } catch (IOException e) { zf = null; } } } } // 版本号判断 public void doAutoUpgradeImport_BBH(String file,String de022 ,SystemInitLogEntity log) { InputStream in = null; ZipInputStream zin = null; BufferedReader br = null; ZipFile zf = null; try{ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); log.setLx(3); log.setDE022(de022); log.setBS("1"); log.setFunname("系统自动升级处理"); log.setTimedata(dateFormat.format(new Date())); zf = new ZipFile(file); in = new BufferedInputStream(new FileInputStream(file)); zin = new ZipInputStream(in); ZipEntry ze; List<String> version = new ArrayList<String>(); while ((ze = zin.getNextEntry()) != null) { if (ze.isDirectory()) { } else { long size = ze.getSize(); if (ze.getName().endsWith(".bak")||ze.getName().endsWith(".sql")) { continue; } if (size > 0) { br = new BufferedReader(new InputStreamReader(zf.getInputStream(ze),"gbk")); if (ze.getName().endsWith("configVer.xml")) {// 获取版本信息 br = new BufferedReader(new InputStreamReader(zf.getInputStream(ze),"utf-8")); String line; while ((line = br.readLine()) != null) { line = line.trim(); version.add(line.replaceAll(";", "")); } br.close(); } } } zin.closeEntry(); } if (version.size() > 0) { String cur_version = DataBaseHelper.queryForScalar("select nvl(max(version),0) version from systemversion ",String.class); String ver_ = ""; String ver_new = ""; String kfr = ""; String fbr = ""; String kfsj = ""; String sjsm = ""; for (int i = 0, len = version.size(); i < len; i++) { String temp =version.get(i);// new String(version.get(i).getBytes("gbk"),"utf-8"); //上次版本号 if (temp.indexOf("sysversion") > 0) { ver_ = (temp.substring(temp.indexOf(">") + 1,temp.lastIndexOf("<"))).trim(); } //当前版本号 if (temp.indexOf("newversion") > 0) { ver_new = (temp.substring(temp.indexOf(">") + 1,temp.lastIndexOf("<"))).trim(); } if (temp.indexOf("kfr") > 0) { kfr = temp.substring(temp.indexOf(">") + 1,temp.lastIndexOf("<")); } if (temp.indexOf("kfsj") > 0) { kfsj = temp.substring(temp.indexOf(">") + 1,temp.lastIndexOf("<")); } if (temp.indexOf("fbr") > 0) { fbr = temp.substring(temp.indexOf(">") + 1,temp.lastIndexOf("<")); } if (temp.indexOf("sjsm") > 0) { sjsm = temp.substring(temp.indexOf(">") + 1,temp.lastIndexOf("<")); } } // if (!cur_version.trim().endsWith("0000")) { //int cur_v1 = Integer.valueOf(cur_version.substring(cur_version.lastIndexOf(".") + 1,cur_version.length())); //int cur_v2 = Integer.valueOf(ver_.substring(ver_.lastIndexOf(".") + 1, ver_.length())); //int cur_v1 = Integer.parseInt(cur_version);//数据库最大版本号 //int cur_v2 = Integer.parseInt(ver_); //发布包里记录的上次版本号 if (!cur_version.equals(ver_)) { log.setBS("0"); log.setSM("升级版本不匹配 请联系管理员!(当前系统版本:" + cur_version+ ",升级包版本:" + ver_ + ")"); throw new Exception("升级版本不匹配 请联系管理员!(当前系统版本:" + cur_version+ ",升级包版本:" + ver_ + ")"); } // } // 插入最新版本号 String update_systemv = "insert into systemversion(version,updatedate,kfdate,fbr,sm,kfr)values(?,sysdate,?,?,?,?)"; DataBaseHelper.update(update_systemv,new Object[] { ver_new, kfsj, fbr, sjsm, kfr }); } else { log.setBS("0"); log.setSM("升级版本不匹配 请联系管理员!"); throw new Exception("升级版本不匹配 请联系管理员!"); } } catch (Exception e){ e.printStackTrace(); throw new RuntimeException("升级出错:"+e.getMessage()); } finally { //关闭流 2014-5-23 hujing if(in != null) { try { in.close(); } catch (IOException e) { in = null; } } if(zin != null) { try { zin.close(); } catch (IOException e) { zin = null; } } if(br != null) { try { br.close(); } catch (IOException e) { br = null; } } if(zf != null) { try { zf.close(); } catch (IOException e) { zf = null; } } } } //页面升级 public Map doAutoUpgradeImport_YM(String file, String de022,SystemInitLogEntity log) throws Exception { Map map = new HashMap(); InputStream in = null; ZipInputStream zin = null; try{ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); log.setLx(3); log.setDE022(de022); log.setBS("1"); log.setFunname("系统自动升级处理"); log.setTimedata(dateFormat.format(new Date())); in = new BufferedInputStream(new FileInputStream(file)); zin = new ZipInputStream(in); ZipEntry ze; while ((ze = zin.getNextEntry()) != null) { if (ze.isDirectory()) { } else { if (ze.getName().endsWith(".tt")) { String prpath = ClassUtils.getDefaultClassLoader().getResource("").getPath().replaceAll("%20", " "); map=UnzipResource.CopyFileByZip(prpath, zin);break; } } //zin.closeEntry(); } }catch(Exception e){ e.printStackTrace(); throw new Exception("升级出错:"+e.getMessage()); } finally { //关闭流 2014-5-23 hujing if(in != null) { try { in.close(); } catch (IOException e) { in = null; } } if(zin != null) { try { zin.close(); } catch (IOException e) { zin = null; } } } return map; } private ResultStatus callProcedureProcess(final String trancode, final String xml) { return (ResultStatus) DataBaseHelper.getJdbcTemplate().execute("{call P_YSZX_PROCESS(?,?,?,?)}", new CallableStatementCallback() { public ResultStatus doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException { Map<String, Object> resultsMap = new HashMap<String, Object>(); ResultStatus resultStatus = new ResultStatus(); cs.setString(1, trancode); lobHandler.getLobCreator().setClobAsString(cs, 2, xml); cs.registerOutParameter(3, OracleTypes.INTEGER); cs.registerOutParameter(4, OracleTypes.VARCHAR); cs.execute(); int retCode = cs.getInt(3); String retValue = cs.getString(4); resultsMap.put("retCode", retCode); resultsMap.put("retValue", retValue == null? "" : retValue); resultStatus.setResultsMap(resultsMap); return resultStatus; } }); } public void excuteProcedure(SystemInitLogEntity log) { ResultStatus rs = this.callProcedureProcess("ZZ0105", ""); Map resultMap = rs.getResultsMap(); SystemInitLogEntity logC = (SystemInitLogEntity) log.clone(); if(resultMap.get("retCode").toString().equals("0")){ return; } logC.setSM(resultMap.get("retValue").toString() ); log.addLog(logC); } public void inserSystemLog(int lx, String de022, String de011, String sm,String mkmc) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String insert_log = "insert into SYSTEMINITLOG (xh,FUNNAME, LX, TIMEDATA, UPDATA, SM, DE022, DE011,bs)values (SEQ_SYSTEMINIT.NEXTVAL, '" + mkmc + "', '" + lx + "', '" + dateFormat.format(new Date()) + "', (select max(t.TIMEDATA) from systeminitlog t where t.lx=2 and sm like '" + sm.substring(0, sm.indexOf("#")) + "%'),'" + sm + "', '" + de022 + "', '" + de011 + "', 1)"; this.getJdbcTemplate().update(insert_log); } /** * 已弃用(YSYY胡晶20130426) * String类型List转换成String类型数组 * (转接于财政1.0) * @param list * @return * @see common.service.SystemInitService.ListToArray */ @Deprecated public String[] changeListToStringArray(List<String> list) { if (list == null || list.size() < 1) { return null; } String[] arr = new String[list.size()]; for (int i = 0, len = list.size(); i < len; i++) { arr[i] = list.get(i); } return arr; } /** * list转数组 * @param list * @return Object[] * @author YSYY */ public Object[] ListToArray(List<?> list) { if (list == null || list.size() == 0) { return null; } return list.toArray(); } public static Document getDocument(InputStream is) { SAXReader reader = new SAXReader(); Document doc = null; try { doc = reader.read(is); return doc; } catch (Exception es) { System.err.println(es.toString()); } return null; } public void copyTableData(String tableName, String yDe022, String tDe022,String de011) throws Exception { String selectSql = ""; String deleteSql = ""; String deleteAll = ""; List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); if (de011 == null) { deleteSql = "delete from " + tableName + " where de022=" + tDe022; deleteAll = "delete from " + tableName + " where 1=1 "; selectSql = "select * from " + tableName + " where de022=" + yDe022; } else { deleteSql = "delete from " + tableName + " where de022=" + tDe022+ " and de011=" + de011; deleteAll = "delete from " + tableName + " where 1=1 "; selectSql = "select * from " + tableName + " where de022="+ yDe022 + " and de011=" + de011; } try { // 首先删除目标表数据 Map<String,Object> map_cloum=new HashMap<String,Object>(); this.getJdbcTemplate().update(deleteSql); String sql_column="SELECT DISTINCT COLUMN_NAME,DATA_TYPE FROM all_tab_columns where table_name = '"+tableName.toUpperCase()+"' "; List<Map<String,Object>> list_column=this.getJdbcTemplate().queryForList(sql_column); if(list_column!=null&&list_column.size()>0){ int len=list_column.size(); for(int ii=0;ii<len;ii++){ map_cloum.put(list_column.get(ii).get("COLUMN_NAME").toString().toLowerCase(), list_column.get(ii).get("DATA_TYPE")); } } list = this.getJdbcTemplate().queryForList(selectSql); if (list != null && list.size() > 0) { for (int i = 0, len = list.size(); i < len; i++) { String inserSql = "insert into " + tableName + " ("; String fileds = ""; String values = ""; String zwf = ""; Map map = list.get(i); Set set = map.entrySet(); Object[] obj = new Object[set.size()]; int k = 0; for (Iterator iterator = set.iterator(); iterator.hasNext();) { Map.Entry string = (Map.Entry) iterator.next(); String key = ((Map.Entry<String, String>) string).getKey().toLowerCase();// 次方法获取键值对的名称 String value = String.valueOf(((Map.Entry<String, Object>) string).getValue());// 次方法获取键值对的值 if ("de022".equals(key)) { fileds += key + ","; values += "'" + tDe022 + "',"; obj[k] = tDe022; zwf += "?" + ","; } else { fileds += key + ","; if (value.equals("null")) { obj[k] = null; values += null + ","; zwf += "?" + ","; } else { if(map_cloum.get(key).equals("DATE")){ if(value==null||"".equals(value)){ obj[k] =null; values += null + ","; zwf += "?,"; }else{ obj[k] =value.substring(0,10); values += "to_date('" + value.replaceAll("/", "-").substring(0,10) + "','yyyy-mm-dd'),"; zwf += "to_date(?,'yyyy-mm-dd')" + ","; } }else{ obj[k] = value; values += "'" + value + "',"; zwf += "?" + ","; } } } k++; } inserSql = inserSql+ fileds.substring(0, fileds.length() - 1)+ ")values(" + zwf.substring(0, zwf.length() - 1)+ ")"; values = values.substring(0, values.length() - 1); this.getJdbcTemplate().update(inserSql, obj); } } deleteAll = deleteAll + " and de022 not like '"+ tDe022.substring(0, 4) + "%'";// 删除 不属于该行政区划下面 数据 this.getJdbcTemplate().update(deleteAll); } catch (Exception e) { e.printStackTrace(); throw new Exception("系统初始化失败:"+e.getMessage()); } } public String getDe022Mc(String dm, String de011) { String sql = "select distinct de021 cs021 where de022= " + dm; return (String) (this.getSimpleJdbcTemplate().queryForObject(sql, String.class)); } //执行单步骤操作日志 public void insertOptionLog(SystemInitLogEntity log){ String insert_log = "insert into SYSTEMINITLOG ( FUNNAME,LX,UPDATA,TIMEDATA,SM)" + "values ('" + log.getFunname() + "'," + log.getLx() + ",'" + log.getUpdata() + "','" + log.getTimedata() + "','" + log.getSM() + "')"; DataBaseHelper.update(insert_log); } public void insertLog(SystemInitLogEntity log){ String insert_log = "insert into SYSTEMINITLOG (xh,p_xh,FUNNAME,LX,UPDATA,TIMEDATA,UPFCILITYPRSONNEL,FCILITYPRSONNEL,SM,DEVELOPERS,SOURCEDE022,DE022,XTUSER,DE011,bs) " + "values ((select nvl(max(xh), 0) + 1 from SYSTEMINITLOG where lx = '" + log.getLx() + "'),(select nvl(max(xh), 0) from SYSTEMINITLOG where lx = '" + log.getLx() + "'),'" + log.getFunname() + "','" + log.getLx() + "',(select nvl(max(updata), '') from SYSTEMINITLOG where xh = p_xh and lx='" + log.getLx() + "'),'" + log.getTimedata() + "','" + log.getUPFCILITYPRSONNEL() + "','" + log.getFCILITYPRSONNEL() + "','" + log.getSM() + "','" + log.getDEVELOPERS() + "','" + log.getSOURCEDE022() + "','" + log.getDE022() + "','" + log.getXTUSER() + "','" + log.getDE011() + "', '" + log.getBS() + "')"; DataBaseHelper.update(insert_log); if(log.getLogChildren().size() > 0) { int maxXH = DataBaseHelper.queryForScalar("select max(xh) as maxxh from SYSTEMINITLOG where lx=" + log.getLx(),Integer.class); for(SystemInitLogEntity logC : log.getLogChildren()) { String con = ""; if(log.getSM().contains("#")) { con = " sm like '" + logC.getSM().substring(0, logC.getSM().indexOf("#")) + "%' "; } else { con = " xh = p_xh "; } String insert_logC = "insert into SYSTEMINITLOG (xh,p_xh,FUNNAME,LX,UPDATA,TIMEDATA,UPFCILITYPRSONNEL,FCILITYPRSONNEL,SM,DEVELOPERS,SOURCEDE022,DE022,XTUSER,DE011,bs) " + "values ((select nvl(max(xh), 0) + 1 from SYSTEMINITLOG where lx = 2), '" + maxXH + "','" + logC.getFunname() + "','" + logC.getLx() + "',(select max(t.TIMEDATA) from systeminitlog t where t.lx='" + log.getLx() + "' and " + con + "),'" + logC.getTimedata() + "','" + logC.getUPFCILITYPRSONNEL() + "','" + logC.getFCILITYPRSONNEL() + "','" + logC.getSM() + "','" + logC.getDEVELOPERS() + "','" + logC.getSOURCEDE022() + "','" + logC.getDE022() + "','" + logC.getXTUSER() + "','" + logC.getDE011() + "', '" + logC.getBS() + "')"; DataBaseHelper.update(insert_logC); } } } public Connection getConn() throws SQLException { Connection con = null; try { // 加载JDBC驱动 Class.forName("oracle.jdbc.driver.OracleDriver"); // 创建数据库连接 hayszx2010 con = DriverManager.getConnection("jdbc:oracle:thin:@172.16.5.88:1521:orcl", "inte_qx", "123456"); return con; } catch (ClassNotFoundException cnf) { System.out.println("driver not find:" + cnf); return null; } catch (SQLException sqle) { System.out.println("can't connection db:" + sqle); return null; } catch (Exception e) { System.out.println("Failed to load JDBC/ODBC driver."); return null; } } @SuppressWarnings("unused") private List<String> getSqlList(int lx,String path,InputStream in,String temp ) { BufferedReader br=null; List<String> list = new ArrayList<String>(); try { if(lx==1){//读取版本控制 xml br= new BufferedReader(new InputStreamReader(in,"utf-8")); String line; while ((line = br.readLine()) != null) { line = line.trim().toLowerCase(); list.add(line.replaceAll(";", "")); } }else if(lx==2){// 读取dml 主要是处理按照行 String line; br= new BufferedReader(new InputStreamReader(in,"gbk")); while ((line = br.readLine()) != null) { line = line.trim().toLowerCase(); if (line.startsWith("insert")|| line.startsWith("delete")|| line.startsWith("update")|| line.startsWith("selete")) { list.add(line.replaceAll(";", "")); } } }else if(lx==3){//读取 处理 按照块读取 主要包含 视图 序列之类 结尾 “;” String line; br= new BufferedReader(new InputStreamReader(in,"gbk")); StringBuffer sb=new StringBuffer(); while ((line = br.readLine()) != null) { sb.append(line + "\n"); } String sql=sb.toString(); if (sql.trim().endsWith(";")) {// 截取最后一个 sql = sql.substring(0, sql.lastIndexOf(";")); } list.add(sql); }else if(lx==3){//存储过程 包体 包头 结尾是 “/” String line; br= new BufferedReader(new InputStreamReader(in,"gbk")); StringBuffer sb=new StringBuffer(); while ((line = br.readLine()) != null) { sb.append(line + "\n"); } String sql=sb.toString(); if (sql.trim().endsWith("/")) {// 截取最后一个 sql = sql.substring(0, sql.lastIndexOf("/")); } list.add(sql); } } catch (IOException e) { } finally { //关闭流2014-5-23hujing if(br != null) { try { br.close(); } catch (IOException e) { br = null; } } } return list; } public String getSysMaxVersion(){ return this.getJdbcTemplate().queryForObject("select nvl(max(version),0) version from systemversion ",String.class); } /** * 校验用户输入口令的正确性 */ public void checkKeyVal(String keyval,User user) throws Exception{ String sqlStr = ""; sqlStr = " select count(1) from jscs001 where dataelement = ? and devalue=? and de022 = ? "; int countInt=DataBaseHelper.queryForScalar(sqlStr, Integer.class, new Object[]{"PASSKEY","1",user.getSjzonecode()}); sqlStr = " select jsde902 from jscs001 where dataelement = ? and devalue=? and de022 = ? "; Map<String,Object> map = null; if(countInt==0){ map = DataBaseHelper.queryForMap(sqlStr, new Object[]{"PASSKEY","1","990000"}); }else{ map = DataBaseHelper.queryForMap(sqlStr, new Object[]{"PASSKEY","1",user.getSjzonecode()}); } if(!map.get("JSDE902").equals(EncryptForNet.encrypt(keyval, "finstone.gkb"))){ throw new Exception("口令错误,数据上传失败,请输入正确的口令"); } } public void truncateTable(String tablename,OutData data){ try{ int istable=gkbCommGetSqlDataService.isTable(tablename); if(istable==0){ throw new BusException("指定的表名称无效,请重新指定"); } else{ logger.info("清空表"+tablename+"开始"); String sql="truncate table "+tablename; DataBaseHelper.execute(sql); logger.info("清空表"+tablename+"完成"); } }catch(Exception e){ logger.info("清空表"+tablename+"失败"); data.setCode(-1); data.setMsg("初始化失败"); throw new BusException(e.getMessage()); } } public void copyStandInfo(String tablename,String xzqh){ try{ int istable=gkbCommGetSqlDataService.isTable(tablename); if(istable==0){ throw new BusException("指定的表名称无效,请重新指定"); }else{ logger.info("初始化表"+tablename+"开始"); String sql="delete from "+tablename+" where de022 not like '990000'"; DataBaseHelper.update(sql); Map zdxxMap = gkbCommGetSqlDataService.getTableColumnSqlInfo( tablename, "a", " de022,", ""); int codeInt = Integer.parseInt(FinString.ts(zdxxMap.get("code"))); if (codeInt < 0) { throw new BusException(FinString.ts(zdxxMap.get("text"))); } String zdxxStr = FinString.ts(zdxxMap.get("text")); List<Map<String,Object>> list=DataBaseHelper.queryForList("select "+zdxxStr+" from "+tablename+" where de022 like '990000'"); for(int i=0;i<list.size();i++){ Map<String,Object> m=list.get(i); m.put("DE022", xzqh); Map sqlMap = gkbCommGetSqlDataService.getAddSqlInfo(tablename, m); codeInt = Integer.parseInt(FinString.ts(sqlMap.get("code"))); if (codeInt < 0) { throw new BusException(FinString.ts(sqlMap.get("text"))); } DataBaseHelper.update(FinString.ts(sqlMap.get("text")), m); } logger.info("初始化表"+tablename+"完成"); } }catch(Exception e){ logger.info("初始化表"+tablename+"失败"); e.printStackTrace(); //data.setCode(-1); //data.setMsg("初始化失败"); throw new BusException(e.getMessage()); } } /* * xzqh为类似于320000的代码 */ public void handleStandInfo(String tablename,String xzqh){ try{ int istable=gkbCommGetSqlDataService.isTable(tablename); if(istable==0){ throw new BusException("指定的表名称无效,请重新指定"); }else{ logger.info("初始化表"+tablename+"开始"); String sql="delete from "+tablename+" where de022 not like '99%'"; DataBaseHelper.update(sql); /* Map zdxxMap = gkbCommGetSqlDataService.getTableColumnSqlInfo( tablename, "a", "", ""); int codeInt = Integer.parseInt(FinString.ts(zdxxMap.get("code"))); if (codeInt < 0) { throw new BusException(FinString.ts(zdxxMap.get("text"))); } String zdxxStr = FinString.ts(zdxxMap.get("text"));*/ List<Map<String, Object>> columns= gkbCommGetSqlDataService.getTableInfo(tablename); List<Map<String, Object>> cs021Columns= gkbCommGetSqlDataService.getTableInfo("cs021"); List<Map<String,Object>> list=DataBaseHelper.queryForList("select * from "+tablename+" where de022 like '99%'"); for(int i=0;i<list.size();i++){ Map<String,Object> m=list.get(i); String de022_bzb=m.get("DE022").toString(); int xzqhlength=0; if(de022_bzb=="990000"){//省级数据 xzqhlength=2; } else if(de022_bzb=="990900"){//市级数据 xzqhlength=4; } else if(de022_bzb=="990909"){//显级数据 xzqhlength=6; }else{ throw new BusException("需要先清空非标准版数据"); } List<Map<String,Object>> province=DataBaseHelper.queryForList("select * from cs021 where isqy=1 and length(de0221)="+xzqhlength+" and de022 like (regexp_replace('"+xzqh+"','00$|0000$|000000$',''))||'%'"); for(int rownum=0;rownum<province.size();rownum++){ Map<String, Object> mapinfo = new HashMap<String, Object>(); Map<String,Object> provinceRow=province.get(rownum); for(int columnnum=0;columnnum<columns.size();columnnum++){//针对每列,判断是否有#内容 String columnName=columns.get(columnnum).get("COLUMN_NAME").toString(); String columnType=columns.get(columnnum).get("DATA_TYPE").toString(); if((!columnName.equals("DE022"))&&(!columnType.equals("CLOB"))){//非区域代码字段,非clob字段 if(m.get(columnName).toString().indexOf("#")<0){//模板行字段为空或者是直接文本,无番薯 此时数据直接复制 mapinfo.put(columnName, m.get(columnName).toString()); }else{ //判断是否两个#之间的字段是否在cs021中,如果不在那张表中,跑出异常 String param=m.get(columnName).toString().substring(m.get(columnName).toString().indexOf("#"), m.get(columnName).toString().lastIndexOf("#")); for(int c=0;c<cs021Columns.size();c++){ if(c==cs021Columns.size()-1&&(!cs021Columns.get(c).get("COLUMN_NAME").toString().equalsIgnoreCase(param))){ throw new BusException("参数设置不正确,请查验"); } } mapinfo.put(columnName,m.get(columnName).toString().replace("#"+param+"#", provinceRow.get(param).toString())); } } } //插入数据航 mapinfo.put("DE022", provinceRow.get("DE022").toString()); Map sqlMap = gkbCommGetSqlDataService.getAddSqlInfo(tablename, mapinfo); int codeInt = Integer.parseInt(FinString.ts(sqlMap.get("code"))); if (codeInt < 0) { throw new BusException(FinString.ts(sqlMap.get("text"))); } DataBaseHelper.update(FinString.ts(sqlMap.get("text")), mapinfo); } } logger.info("初始化表"+tablename+"完成"); } }catch(Exception e){ //data.setCode(-1); //data.setMsg("初始化失败"); e.printStackTrace(); throw new BusException(e.getMessage()); } } public OutData doDatabaseInitImp(Map p,IUser user) throws Exception { User userinfo = (User) user; if(!userinfo.getLoginName().equalsIgnoreCase("admin")){ throw new BusException("只有超级管理员才能执行此操作"); } if(p.get("XZQH").toString().replaceAll("0000", "").length()!=2){ throw new BusException("请选择省级区划!"); } try{ copyStandInfo("g_fjjbcs_bzb","320000"); handleStandInfo("cs061_bzb","320000"); OutData data = new OutData(); data.setCode(0); data.setMsg("-"); return data; }catch(Exception e){ e.printStackTrace(); throw new Exception(e.getMessage()); } } }
相关推荐
xml文件导入到mysql数据库中,包括文件:ConnectionUtils.java,InsertDT.java,db_mysql.properties,test01.xml,需要的jar包dom4j-1.6.1.jar,mysql-connection-java-3.1.1.3-bin.jar,jaxen-1.1-beta-7.jar
博客中提到的工具可能使用了StAX或者类似的低内存消耗技术来读取XML,以避免一次性加载整个XML文件导致的内存压力。然后,这些数据可以被映射到Java对象,进一步处理或存储到数据库中。这个过程可能涉及到Java反射...
本文将详细介绍如何使用C#的LinqXML技术对XML文件进行读取。 首先,我们需要引入必要的命名空间。在C#代码中,确保包含了以下导入语句: ```csharp using System; using System.Linq; using System.Xml.Linq; ``` `...
导入XML文件到Java程序中,通常涉及解析XML文档。Java提供了多种解析器,如DOM(Document Object Model)、SAX(Simple API for XML)和StAX(Streaming API for XML)。DOM解析器将整个XML文档加载到内存中的树形...
在“XML导入导出DEMO”这个项目中,我们主要关注的是如何使用C#来操作XML文件,实现数据表的导入和导出。首先,数据表导出为XML的过程涉及将数据库中的表格数据转换成XML格式的文件。这通常通过读取数据库中的数据,...
该文件简单的方法读取了XML文件的字段值,本传送的是原文件,LabVIEW版本8.6
在SQL Server中,读取XML文件并对其进行处理是数据库管理员和开发者经常遇到的任务。XML作为一种通用的数据交换格式,被广泛用于存储和传输结构化数据。然而,在SQL Server 2000中,处理XML文件并不像导出数据那样...
下面,我们将详细介绍三种使用C#读取XML文件并将其写入数据库的方法。 1. **使用XmlReader类逐行读取并写入** - `XmlReader` 是一个高效的流式读取器,不占用大量内存。通过创建`XmlReader`实例,我们可以逐个节点...
本篇将详细阐述如何读取PLC寄存器以及操作XML文件。 首先,PLC是工业控制系统的核心组成部分,它负责接收来自传感器的输入信号,并根据预设的程序逻辑控制执行器的动作。读取PLC寄存器是获取设备状态或监控生产过程...
Java 解析 XML 并导入数据库是指使用 Java 语言将 XML 文件解析并将其内容导入到数据库中。下面是使用 DOM4J 库来实现此功能的相关知识点: 一、XML 文件解析 XML(Extensible Markup Language)是一种标记语言,...
在本文中,我们将深入探讨如何使用Microsoft Foundation Class (MFC) 框架与XML库,如TinyXML2,来实现保存控件数据至XML文件以及从XML文件中读取数据回控件的功能。这对于创建应用程序配置文件或者保存用户自定义...
这个函数将XML文件解析成一个XML文档对象模型(DOM),然后可以通过DOM API访问XML文件中的元素、属性和文本。例如,如果你有一个名为"data.xml"的XML文件,你可以这样读取它: ```matlab doc = xmlread('data.xml'...
在Java开发中,DOM4J被广泛用于XML数据的读取和写入,尤其在需要将XML文件与数据库交互时,它的功能尤为突出。下面我们将深入探讨DOM4J的核心概念以及如何使用它来实现XML文件导入数据库的过程。 首先,DOM4J支持...
总结来说,从Excel读取数据并生成XML文件是一种常用的数据处理方法,特别是在需要将数据导入其他系统或与Web服务交互时。熟练掌握这一技巧,能极大地提高工作效率,并促进不同应用之间的数据共享。
在本场景中,我们关注的是如何解析XML文件并将其中的数据导入到数据库,然后在前端进行分页展示。这个过程涉及到的主要技术栈包括DOM4J库、数据库操作以及前端分页技术。 首先,DOM4J是Java中一个非常流行的XML处理...
本篇文章将详细讲解如何在Delphi中创建简单的XML文件,并介绍如何读取XML子节点下的所有属性。 首先,让我们了解XML的基本结构。XML文档由元素(Element)、属性(Attribute)、文本内容(Text Content)等构成,...
标题 "PB 读取XML文件 实例" 涉及的是使用PowerBuilder(PB)这一编程工具处理XML文件的方法。PowerBuilder(PB)是Sybase公司开发的一种强大的客户端/服务器应用程序开发工具,它支持多种数据源,包括XML。在PB ...
本教程将详细介绍如何在Qt应用中实现XML文件的读取与写入,并将数据展示到QTableWidget中,以及从QTableWidget中保存回XML文件。 首先,Qt提供了QDomDocument类来处理XML文档,它可以解析XML文件并创建一个内存中的...
1. **解析XML文件**:Java提供了多种解析器来读取XML文件,如DOM(Document Object Model)、SAX(Simple API for XML)和StAX(Streaming API for XML)。DOM解析器会将整个XML文档加载到内存中,适合小型文件;SAX...
关于Delphi7读取保存XML 读取XML,修改节点,保存XML的一个完整实例。