package com.yc.service.build.type; import java.io.File; import java.io.IOException; import java.util.List; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; import com.yc.api.bean.T9685Entity; import com.yc.api.service.ApiServiceIfc; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.jdbc.support.rowset.SqlRowSet; import org.springframework.stereotype.Service; import com.yc.action.grid.TreeGridIfc; import com.yc.entity.AttachmentConfig; import com.yc.service.BaseService; import com.yc.service.build.BuildFuncIfc; import com.yc.service.commons.GformIfc; import com.yc.service.impl.DBHelper; import com.yc.utils.HtmlUtil; import com.yc.utils.SessionKey; import com.yc.utils.fileAndFolder.FileAndFolderOper; /* * 窗体类型生成基类 * danaus * 2011-02-18 */ @Service @Scope("prototype") public class BaseImpl extends BaseService implements BaseIfc { @Autowired protected BuildFuncIfc BFI; @Autowired protected TreeGridIfc treeGrid; @Autowired protected GformIfc gformIfc; @Autowired private ApiServiceIfc apiServiceIfc; FileAndFolderOper FAFO = new FileAndFolderOper(); protected String formID = ""; protected String URI = ""; protected String path = ""; protected String[] formName; protected String versionId;// 版本号 protected String dataBaseId;// 数据库id号 protected String language; protected String gPath = ""; protected String title = ""; public String path2 = "";// 第二路径 public String getPath2() { return path2; } public void setPath2(String path2) { this.path2 = path2; } protected int type = 0; protected String hostUrl = ""; private String injector=""; protected String mainformid=null;//主功能号,针对多表的子功能号生成,需要附带上主功能号,如:150348子功能号,需要生成:150101_15348 public String getInjector() { return injector; } public String getHostUrl() { return hostUrl; } public void setHostUrl(String hostUrl) { this.hostUrl = hostUrl; } public String getgPath() { return gPath; } public void setgPath(String gPath) { this.gPath = gPath; } public String getTitle() { return "【<%=session.getAttribute(\""+SessionKey.USERNAME+"\")%>】" + this.formName[0] + "-" + this.formID; } public String getTitle2() {// 针对5,8,16类型 return "【<%=session.getAttribute(\""+SessionKey.USERNAME+"\")%>】" + this.formName[1] + "-" + this.formID; } public String[] getFormName() { return formName; } public void setFormName(String[] formName) { this.formName = formName; } // 查找哪些功能号把当前功能号作为主表使用 // 格式:引用的功能号|外表的关联字段;当前表的关联字段,...... protected String[] getPrIndex(String formid, List> list, String type) { String ind = ""; int index = 0; for (Map map : list) { if (type.equalsIgnoreCase((Integer) map.get("formtype") + "") && !formid.equalsIgnoreCase((Integer) map.get("formid") + "")) { index++; if (formid.equalsIgnoreCase((Integer) map.get("FT") + "")) { ind += "T_" + map.get("formid") + "|" +((((String) map.get("SeekGroupID")).split(";").length>1)?((String) map.get("SeekGroupID")).split(";")[1]:"") + ";" + ((((String) map.get("FK")).split(";").length>1)?((String) map.get("FK")).split(";")[1]:"") + ","; } } } return new String[] { (ind != "" || !ind.isEmpty()) ? ind.substring(0, ind.length() - 1) : "", index + "" }; } // 去除字符串中的换行符等 public String replaceBlank(String str) { if (str == null) { return ""; } Pattern p = Pattern.compile("\t|\r|\n"); Matcher m = p.matcher(str); return m.replaceAll(""); } public String getPath() { return path; } public void setPath(String path) { this.path = path; } public String getFormID() { return formID; } public String getURI() { return URI; } @Override public void setFormID(String formID) { this.formID = formID; } @Override public void setURI(String URI) { this.URI = URI; } @Override public void setHostURI(String URI) { this.hostUrl = URI; } @Override public void setPath(String formID, int type) throws Exception { this.type = type; this.path = BFI.getPath(formID, type, getVersionId(), getDataBaseId(), getLanguage()); gPath = getDataBaseId() + File.separator + getVersionId() + File.separator + getLanguage(); } @Override public synchronized int build() throws Exception { return 0; } public String getUpath(String formID, int type) { String p = ""; try { p = BFI.getPath(formID, type, getVersionId(), getDataBaseId(), getLanguage()); } catch (Exception e) { e.printStackTrace(); } return p; } protected String getValue(Map map, String col) { return (map.get(col) == null) ? "" : map.get(col).toString(); } protected String getValueInt(Map map, String col) { return (map.get(col) == null) ? "0" : map.get(col).toString(); } protected String getToPath() { String path1 = ""; try { path1 = this.URI + File.separator + "app" + File.separator + BFI.getPath(formID, type, getVersionId(), getDataBaseId(), getLanguage()) + File.separator; } catch (Exception e) { e.printStackTrace(); } return path1; } protected String getIonicCreatePath(int ptype) { String path1 = ""; try { //this.URI + File.separator + "app" + File.separator +"ionic"+ File.separator+getDataBaseId()+File.separator+formID+File.separator+type+ File.separator; path1 =AttachmentConfig.getInstanse().get("Ionic.webUrl")+ File.separator+getDomainUrl()+ File.separator+"ionic_chcp"+File.separator+"www"+File.separator+"app"+File.separator+getDataBaseId()+File.separator+getFormidCreate()+ File.separator+ptype+ File.separator; //D:/ionicPage/178/ionic_chcp/www/app/178/+File.separator+formID+File.separator+type+ File.separator } catch (Exception e) { e.printStackTrace(); } return path1; } /** * 根据是否存在主功能号做相应的处理 * @return */ private String getFormidCreate(){ if(mainformid!=null) return mainformid+"_"+formID; else return formID; } protected String getDomainUrl(){ if(this.hostUrl=="") return ""; String str=HtmlUtil.getDomain(this.hostUrl); int inx=str.indexOf("."); if(inx==-1){ int y=str.indexOf(":"); return y==-1?str:str.substring(0, y); } return str.substring(0, inx); } protected String getIonicBaseUrl() { String path1 = ""; try { //this.URI + File.separator + "app" + File.separator +"ionic"+ File.separator+getDataBaseId()+File.separator+formID+File.separator+type+ File.separator; path1 =AttachmentConfig.getInstanse().get("Ionic.webUrl")+ File.separator+getDomainUrl();//getDataBaseId(); } catch (Exception e) { e.printStackTrace(); } return path1; } @Override public void buildPageCode(String data, String targetFileName) throws Exception { File file = new File(this.URI + File.separator + "app" + File.separator + BFI.getPath(formID, type, getVersionId(), getDataBaseId(), getLanguage()) + File.separator); //处理上传控件需要增加js,css的导出,根据功能号是否设置有9,19,40控件决定加不加上这些页面,从而优化页面加载 by danaus 17-11-23 //根据formid查找9802中是不是有包括上面所说的控件,有则加载。 SqlRowSet row = this.getRowSet(" set nocount on ; select count(1) as a from gfield where formid=" + formID + " and (gridcontroltype in(9,19,40) or controltype in(9,19,40))"); row.next(); int num = row.getInt(1); String js_css = "\n"; js_css += "\">\n" + "\">\n" + "\n" + "\n"; if (num != 0) {//表示存在有上传控件 js_css += // "\">\n"+ // "\">\n"+ // "\">\n"+ // "\n"+ // "\n"+ // "\n"; "\">\n" + "\">\n" + "\n" + "\n" + ""; // data = data.replace("@_add_js_css_@", js_css); } // else { data = data.replace("@_add_js_css_@", js_css); // } //-------------文字颜色说明---------xin 2022-5-18 16:09:54-----------// StringBuilder colorText =new StringBuilder();//文字颜色说明 if(StringUtils.isNotBlank(formID)) { List colorList = apiServiceIfc.get9685List(Integer.parseInt(formID)); if (colorList != null && colorList.size() > 0) { colorText.append("
"); colorText.append("
文字颜色说明
"); colorText.append("
"); for (T9685Entity t : colorList) { colorText.append("
" + "" + t.getColorName() + "
"); } colorText.append("
"); } } //文字颜色说明 xin 2022-5-18 15:53:13 data = data.replace("[?ColorDescription]",colorText); if (!file.exists() || !file.isDirectory()) file.mkdirs(); file = new File(file.getPath() + File.separator + targetFileName); FileUtils.writeStringToFile(file, data, "utf-8"); } @Override public String getPageCode(String templateFileName) throws IOException { return FileUtils.readFileToString(new File(this.URI + File.separator + "public" + File.separator + "template" + File.separator + getVersionId() + File.separator + type + File.separator + templateFileName), "utf-8"); } @Override public String toString(Object str) { return str == null ? "" : str.toString(); } @Override public String getBuildPath() { return getTemPath() + type + File.separator; } @Override public String getIonicPath() { return this.URI + File.separator + "public" + File.separator + "ionic" + File.separator + getVersionId() + File.separator + type + File.separator; } @Override public String getIonicBasePath() { return this.URI + File.separator + "public" + File.separator + "ionic" + File.separator + getVersionId() + File.separator; } public String getTemPath() { return this.URI + File.separator + "public" + File.separator + "template" + File.separator + getVersionId() + File.separator; } public String getVersionId() { return versionId; } public void setVersionId(String versionId) { this.versionId = versionId; } public String getDataBaseId() { return dataBaseId; } public void setDataBaseId(String dataBaseId) { this.dataBaseId = dataBaseId; } public String getLanguage() { return language; } public void setLanguage(String language) { this.language = language; } public String replaceGform(String tmpJsp) { Map formInfo = gformIfc.getGformInfo("dataformid,formdatafilters", Integer.parseInt(formID)); String dataformid = DBHelper.getValue(formInfo, "dataformid"); tmpJsp = tmpJsp.replaceAll("#dataformid#", (dataformid.equals("")) ? "" :(","+ dataformid));//" or formid in(" + dataformid + ")" String formdatafilters = DBHelper.getValue(formInfo, "formdatafilters"); tmpJsp = tmpJsp.replaceAll("#formdatafilters#", (formdatafilters.equals("")) ? "" : " and " + formdatafilters); return tmpJsp; } public String trim(Object str){ if(str==null)return ""; return str.toString().trim().replaceAll("\\r\\n|\\n|\\r", ""); } @Override public void setInjector(String s) { this.injector=s; } }