package weaver.mobile.plugin.ecology.service; import org.apache.commons.lang.StringUtils; import org.jsoup.Jsoup; import weaver.conn.RecordSet; import weaver.crm.Maint.CustomerInfoComInfo; import weaver.docs.news.DocNewsManager; import weaver.general.BaseBean; import weaver.general.Util; import weaver.hrm.User; import weaver.hrm.resource.ResourceComInfo; import weaver.mobile.HtmlToPlainText; import weaver.share.ShareManager; import weaver.splitepage.transform.SptmForDoc; import weaver.systeminfo.setting.HrmUserSettingComInfo; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class WdsxyService extends BaseBean { public static final int COLUMN_CUSTOM = 0;//自定义 public static final int COLUMN_NEWEST = -1;//最新 public static final int COLUMN_HOT = -2;//最热 public static final int COLUMN_UNREAD = -3;//未读 public static final int COLUMN_MINE = -4;//我的 public static final int COLUMN_ALL = -5;//全部(修改时间倒序) public Map getDocumentList(List conditions, int pageIndex, int pageSize, User user) throws Exception { Map result = new HashMap(); List list = new ArrayList(); int count = 0; int pageCount = 0; int isHavePre = 0; int isHaveNext = 0; if (user != null) { RecordSet rs = new RecordSet(); RecordSet rs1 = new RecordSet(); ShareManager shareManager = new ShareManager(); CustomerInfoComInfo cici = new CustomerInfoComInfo(); ResourceComInfo rci = new ResourceComInfo(); String sql = ""; sql = " from uf_wdsxy where 1=1 "; for(int i=0;conditions!=null&&conditions.size()>0&&i 0)?1:0); if(pageIndex <= pageCount) { isHaveNext = (pageIndex + 1 <= pageCount)?1:0; isHavePre = (pageIndex - 1 >= 1)?1:0; sql = " * from uf_wdsxy where 1=1 "; for(int i=0;conditions!=null&&conditions.size()>0&&i0&&pageSize>0) { if (rs.getDBType().equals("oracle")) { sql = " select " + sql; sql = "select * from ( select row_.*, rownum rownum_ from ( " + sql + " ) row_ where rownum <= " + (pageIndex * pageSize) + ") where rownum_ > " + ((pageIndex - 1) * pageSize); }else if(rs.getDBType().equals("mysql")){ sql = " select " + sql + " limit "+(pageIndex - 1) * pageSize+","+pageSize+" "; } else { if(pageIndex>1) { int topSize = pageSize; if(pageSize * pageIndex > count) { topSize = count - (pageSize * (pageIndex - 1)); } sql = " select top " + topSize + " * from ( select top " + topSize + " * from ( select top " + (pageIndex * pageSize) + sql + " ) tbltemp1 order by doclastmoddate asc,doclastmodtime asc,id asc ) tbltemp2 order by doclastmoddate desc,doclastmodtime desc,id desc "; } else { sql = " select top " + pageSize + sql; } } } else { sql = " select " + sql; } rs.execute(sql); while (rs.next()) { //{"createtime":"2011-11-15 17:22:07","docimg":"750","docid":"670","owner":"赵静","isnew":"0","docsubject":"维森集团2011年5月份维森之星"} Map gzzd = new HashMap(); gzzd.put("wdbt", Util.null2String(rs.getString("wdbt"))); gzzd.put("bzrq", Util.null2String(rs.getString("bzrq"))); gzzd.put("bm", Util.null2String(rs.getString("bm"))); gzzd.put("bzbm", Util.null2String(rs.getString("bzbm"))); gzzd.put("sxyid", Util.null2String(rs.getString("id"))); list.add(gzzd); } } result.put("result", "list"); result.put("pagesize",pageSize+""); result.put("pageindex",pageIndex+""); result.put("count",count+""); result.put("pagecount",pageCount+""); result.put("ishavepre",isHavePre+""); result.put("ishavenext",isHaveNext+""); result.put("list",list); } return result; } public Map getDocumentCount(List conditions, User user) throws Exception { Map result = new HashMap(); int count1 = 0; int count2 = 0; if (user != null) { RecordSet rs = new RecordSet(); ShareManager shareManager = new ShareManager(); String sql = ""; if (rs.getDBType().equals("oracle") || rs.getDBType().equals("mysql")) sql = " from DocDetail t1,"+shareManager.getShareDetailTableByUser("doc", user)+" t2,DocDetailContent t3 where t1.id = t2.sourceid and t1.id = t3.docid "; else sql = " from DocDetail t1,"+shareManager.getShareDetailTableByUser("doc", user)+" t2 where t1.id = t2.sourceid "; sql += " and ((docstatus = 7 and (sharelevel>1 or (t1.doccreaterid="+user.getUID()+")) ) or t1.docstatus in ('1','2','5')) "; sql += " and seccategory!=0 and (ishistory is null or ishistory = 0) "; for(int i=0;conditions!=null&&conditions.size()>0&&i getDocumentList2(int module, User user, int pageIndex, int pageSize, int columnid, List conditions) { Map result = new HashMap(); try { List> list = new ArrayList>(); List> imglist = new ArrayList>(); int isHavePre = 0; int isHaveNext = 0; if (user != null) { RecordSet rs = new RecordSet(); RecordSet rs1 = new RecordSet(); ShareManager shareManager = new ShareManager(); CustomerInfoComInfo cici = new CustomerInfoComInfo(); ResourceComInfo rci = new ResourceComInfo(); SptmForDoc sptmForDoc = new SptmForDoc(); HtmlToPlainText formatter = new HtmlToPlainText(); isHavePre = (pageIndex - 1 >= 1)?1:0; String baseSql = ""; String fields = ""; if (rs.getDBType().equals("oracle") || rs.getDBType().equals("mysql")) { fields = " t1.*,t2.sharelevel,t3.doccontent "; baseSql = " from DocDetail t1,"+shareManager.getShareDetailTableByUser("doc", user)+" t2,DocDetailContent t3 where t1.id = t2.sourceid and t1.id = t3.docid "; } else { fields = " t1.*,t2.sharelevel "; baseSql = " from DocDetail t1,"+shareManager.getShareDetailTableByUser("doc", user)+" t2 where t1.id = t2.sourceid "; } baseSql += " and t1.seccategory <> 0 and (t1.ishistory is null or t1.ishistory = 0) "; if(module == 3 && columnid == COLUMN_MINE) { HrmUserSettingComInfo husc = new HrmUserSettingComInfo(); String belongtoshow = husc.getBelongtoshowByUserId(user.getUID()+""); String belongtoids = User.getBelongtoidsByUserId(user.getUID()+""); if(belongtoshow.equals("1")) { if(belongtoids.isEmpty()) { belongtoids = user.getUID()+""; } else { belongtoids += ","+user.getUID(); } baseSql += " and (t1.doccreaterid in ("+belongtoids+") or t1.ownerid in ("+belongtoids+")) "; } else { baseSql += " and (t1.doccreaterid = "+user.getUID()+" or t1.ownerid = "+user.getUID()+") "; } } else { baseSql += " and ((t1.docstatus = 7 and (t2.sharelevel>1 or (t1.doccreaterid="+user.getUID()+")) ) or t1.docstatus in ('1','2','5')) "; } String settingWhere = this.getSettingSql(columnid); if(columnid == COLUMN_CUSTOM || columnid == COLUMN_NEWEST || columnid == COLUMN_HOT || columnid == COLUMN_UNREAD || columnid == COLUMN_MINE || columnid == COLUMN_ALL || (columnid > 0 && settingWhere != null)) { baseSql += StringUtils.trimToEmpty(settingWhere); if(conditions != null && conditions.size() > 0) { for(String condition : conditions) { if(StringUtils.isBlank(condition)) continue; baseSql += " and " + condition + " "; } } if(module == 3 && columnid == COLUMN_UNREAD) { baseSql += " and t1.doccreaterid <> "+user.getUID()+" and not exists (select 1 from docReadTag where userid="+user.getUID()+" and docid = t1.id) "; } if(columnid == COLUMN_NEWEST || columnid == COLUMN_HOT || columnid == COLUMN_UNREAD || columnid == COLUMN_MINE || columnid == COLUMN_ALL) { baseSql += " and (t1.isreply is null or t1.isreply <> 1) "; } String orderby = " order by t1.doclastmoddate desc, t1.doclastmodtime desc"; if(module == 3 && columnid == COLUMN_HOT) orderby = " order by t1.sumReadCount desc, t1.id desc"; if(module == 3 && columnid == COLUMN_NEWEST) orderby = " order by t1.doccreatedate desc, t1.doccreatetime desc, t1.id desc"; String doctype=null; String docextendname=null; String listSql = ""; if(pageIndex>0&&pageSize>0) { if (rs.getDBType().equals("oracle")) { listSql = " select " + fields + baseSql + orderby; listSql = "select * from ( select row_.*, rownum rownum_ from ( " + listSql + " ) row_ where rownum <= " + (pageIndex * pageSize) + ") where rownum_ > " + ((pageIndex - 1) * pageSize); } else if(rs.getDBType().equals("mysql")){ listSql = " select " + fields + baseSql + orderby + " limit "+(pageIndex - 1) * pageSize+","+pageSize+" "; }else { if(pageIndex>1) { listSql = "select top "+pageSize+fields+baseSql+" AND id not in (select top "+(pageIndex-1)*pageSize+" id "+baseSql+orderby+") "+orderby; } else { listSql = " select top " + pageSize + fields + baseSql + orderby; } } } else { listSql = " select " + fields + baseSql + orderby; } rs.executeSql(listSql); while (rs.next()) { Map doc = new HashMap(); String docid = rs.getString("id"); doc.put("docid", docid); String docsubject_tmp = rs.getString("docsubject"); docsubject_tmp = docsubject_tmp.replaceAll("\n", "");// TD11607 docsubject_tmp = docsubject_tmp.replaceAll("<", "<"); docsubject_tmp = docsubject_tmp.replaceAll(">", ">"); doc.put("docsubject",docsubject_tmp); String ownerid = rs.getString("ownerid"); String owner = rs.getInt("ownerType") == 2 ? cici.getCustomerInfoname(ownerid) : rci.getResourcename(ownerid); doc.put("ownerid", ownerid); doc.put("owner", owner); //doc.put("ownermobile", rci.getMobile(ownerid)); doc.put("ownermobile", rci.getMobileShow(ownerid,ownerid)); doc.put("ownerloginid", rci.getLoginID(ownerid)); doc.put("doccreatedate", rs.getString("doccreatedate")+" "+rs.getString("doccreatetime")); doc.put("docupdatedate", rs.getString("doclastmoddate")+" "+rs.getString("doclastmodtime")); String sql = "select count(0) as c from DocDetail t where t.id="+docid+" and t.doccreaterid<>"+user.getUID()+" and not exists (select 1 from docReadTag where userid="+user.getUID()+" and docid=t.id)"; rs1.execute(sql); if(rs1.next()&&rs1.getInt("c")>0) { doc.put("isnew", "1"); } else { doc.put("isnew", "0"); } String doccontent = Util.null2String(rs.getString("doccontent")); //doc.put("doctype", rs.getString("docextendname")); docextendname=Util.null2String(rs.getString("docextendname")); doctype=getDocTypeByDocId(docid,docextendname,doccontent); doc.put("doctype", doctype); if(module == 2) { String docimg = ""; // sql = "select i.imagefileid from docimagefile di,imagefile i where di.imagefileid=i.imagefileid and di.docid="+docid+" and di.docfiletype='1' order by i.imagefileid"; // rs1.execute(sql); // if(rs1.next()) { // docimg = rs1.getString("imagefileid"); // } docimg=getFirstImageFileIdByDoccontent(doccontent); doc.put("docimg", docimg); String summary = ""; if(StringUtils.isNotBlank(doccontent)) { int tmppos = doccontent.indexOf("!@#$%^&*"); if(tmppos!=-1){ summary = doccontent.substring(0,tmppos); } else { summary = formatter.getPlainText(Jsoup.parse(doccontent)); summary = StringUtils.replace(summary, "\n", ""); } summary = (summary.length()) > 100 ? summary.substring(0, 100) : summary; } doc.put("summary", summary); if(pageIndex == 1 && Util.getIntValue(docimg) > 0 && imglist.size() < 5) { Map img = new HashMap(); img.put("docimg", docimg); img.put("docid", docid); img.put("docsubject", docsubject_tmp); imglist.add(img); } } else { // if(columnid == COLUMN_MINE) { int docstatus = rs.getInt("docstatus"); doc.put("docstatusid", ""+docstatus); int seccategory = rs.getInt("seccategory"); String docstatusname = sptmForDoc.getDocStatus3(docid, ""+user.getLanguage()+"+"+docstatus+"+"+seccategory); doc.put("docstatus", docstatusname); // } } list.add(doc); } isHaveNext = list.size() == pageSize ? 1 : 0; result.put("result", "list"); result.put("pagesize",pageSize+""); result.put("pageindex",pageIndex+""); result.put("count","0"); result.put("pagecount","0"); result.put("ishavepre",isHavePre+""); result.put("ishavenext",isHaveNext+""); result.put("list",list); if(module == 2 && pageIndex == 1 && imglist.size() > 0) { result.put("imglist",imglist); } } else { result.put("result", "error"); result.put("errorno", "-1"); result.put("errormsg", "columnid not exists!"); } } } catch (Exception e) { writeLog(e); } return result; } private String getSettingSql(int columnid) throws Exception { if(columnid <= 0) return null; String where = null; RecordSet rs = new RecordSet(); RecordSet rs1 = new RecordSet(); rs.executeSql("SELECT * FROM MobileDocSetting WHERE columnid="+columnid); if(rs.next()) { where = ""; int source = rs.getInt("source"); int isreplay = rs.getInt("isreplay"); if (source == 1) { //来源新闻中心 rs1.executeSql("SELECT docid FROM MobileDocColSetting WHERE columnid="+columnid); if(rs1.next()) { DocNewsManager dnm = new DocNewsManager(); dnm.setId(rs1.getInt("docid")); dnm.getDocNewsInfoById(); where = dnm.getNewsclause(); where = StringUtils.isNotBlank(where) ? " and "+where : ""; where += " and t1.docpublishtype in ('2','3') "; } } else if (source == 2) { //来源文档目录 rs1.executeSql("SELECT docid FROM MobileDocColSetting WHERE columnid="+columnid); String ids = ""; while(rs1.next()) { ids += "," + rs1.getInt("docid"); // where = " and exists (select id from docseccategory where id = t1.seccategory and id in (select docid from MobileDocColSetting where columnid="+columnid+"))"; } if(!ids.isEmpty()){ ids = ids.substring(1); where = " and t1.seccategory in(" + ids + ") "; } } else if (source == 3) { //来源虚拟目录 rs1.executeSql("SELECT docid FROM MobileDocColSetting WHERE columnid="+columnid); String ids = ""; while(rs1.next()) { ids += "," + rs1.getInt("docid"); //where = " and exists (select 1 from DocDummyDetail where docid = t1.id and catelogid in (select docid from MobileDocColSetting where columnid="+columnid+")) "; } if(!ids.isEmpty()){ ids = ids.substring(1); where = " and t1.id in(select docid from DocDummyDetail where catelogid in(" + ids + ")) "; } } else if (source == 4) { //来源指定文档 List docids = new ArrayList(); rs1.executeSql("SELECT docid FROM MobileDocColSetting WHERE columnid="+columnid); while(rs1.next()) { String docid = rs1.getString("docid"); String newdocid = docid; RecordSet rs3 = new RecordSet(); rs3.executeSql("select doceditionid from docdetail where id=" + docid); if(rs3.next()) { int editionid = rs3.getInt("doceditionid"); if (editionid > 0) { rs3.executeSql("select id from docdetail where docedition=(select max(docedition) from docdetail where doceditionid=" + editionid + ") and doceditionid=" + editionid); if(rs3.next()) { newdocid = rs3.getString("id"); } } } docids.add(newdocid); } if(docids != null && docids.size() > 0) where = " and t1.id in (" + StringUtils.join(docids, ',') + ") "; } if(isreplay != 1){ where += " and (t1.isreply is null or t1.isreply <> 1) "; } } return where; } /** * 获取指定模块的版块列表 * @param scope 模块id * @return 版块列表/错误 */ public Map getColumnList(int scope) { Map result = new HashMap(); try { if(scope > 0) { List> columns = new ArrayList>(); RecordSet rs = new RecordSet(); rs.executeSql("SELECT * FROM MobileDocSetting where scope="+scope+" ORDER BY showOrder"); while(rs.next()) { Map colItem = new HashMap(); colItem.put("columnid", rs.getString("columnid")); colItem.put("columnname", rs.getString("name")); columns.add(colItem); } result.put("result", "list"); result.put("list", columns); } else { result.put("result", "error"); result.put("error", "scope value must be greater than zero![scope:"+scope+"]"); } } catch (Exception e) { writeLog(e); result.put("result", "error"); result.put("error", e.getMessage()); } return result; } private String getDocTypeByDocId(String docid,String docextendname,String doccontent){ String doctype=docextendname; try { if((!"".equals(docextendname))&&(!"html".equals(docextendname))){ return doctype; } //html编辑框有内容则返回html int tmppos = doccontent.indexOf("!@#$%^&*"); if(tmppos!=-1){ doccontent = doccontent.substring(tmppos+8,doccontent.length()); } //替换HTML标签 String strDoccontent=Util.replace(doccontent,"<[^>]*>","",0); //替换空字符串 strDoccontent=Util.replace(strDoccontent," ","",0); //替换换行 strDoccontent=Util.replace(strDoccontent,"\r\n","",0); //替换空格 strDoccontent=Util.replace(strDoccontent," ","",0); if("initFlashVideo();".equals(strDoccontent)||"".equals(strDoccontent)){ int fileNum=0; RecordSet rs = new RecordSet(); rs.executeSql("select count(distinct id) as fileNum from DocImageFile where docid="+docid); if(rs.next()){ fileNum=Util.getIntValue(rs.getString("fileNum")); } if(fileNum==1){ rs.executeSql("select imageFileName from DocImageFile where docid="+docid+" order by imageFileId desc"); if(rs.next()){ String imageFileName=Util.null2String(rs.getString("imageFileName")); if(imageFileName.lastIndexOf(".")>=0){ if(!(imageFileName.endsWith("."))){ doctype=imageFileName.substring(imageFileName.lastIndexOf(".")+1); } } } } }else{ return doctype; } }catch (Exception e) { writeLog(e); } return doctype; } private String getFirstImageFileIdByDoccontent(String doccontent){ String docimg=""; if(doccontent==null||doccontent.trim().equals("")){ return docimg; } try { ArrayList list=Util.matchAll(doccontent,"/weaver/weaver.file.FileDownload\\?fileid=([0-9]+)",1,1); if(list.size()<=0){ return docimg; } docimg= Util.null2String((String)list.get(0)); }catch (Exception e) { writeLog(e); } return docimg; } public static String getWheresBySettings(String settings) { String wheres=""; try{ if(settings==null||settings.trim().equals("")){ return wheres; } settings=settings.trim(); boolean newdoc = settings.startsWith("@"); if(newdoc) settings = settings.substring(1); String[] settingList = StringUtils.split(settings, '#'); if(settingList == null || settingList.length == 0){ return wheres; } for(int i=0; i 2 ? Util.null2String(colsetting[2]) : "1"; docids = colsetting.length > 3 ? Util.null2String(colsetting[3]) : ""; isreplay = colsetting.length > 4 ? Util.null2String(colsetting[4]) : "0"; } else { source = colsetting.length>0 ? Util.null2String(colsetting[0]) : "1"; docids = colsetting.length>1 ? Util.null2String(colsetting[1]) : ""; isreplay = colsetting.length>2 ? Util.null2String(colsetting[2]): "0"; } String where = ""; if (source.equals("1")) { //来源新闻中心 String[] targets = StringUtils.split(docids, ","); DocNewsManager dnm = new DocNewsManager(); dnm.setId(Util.getIntValue(targets[0])); dnm.getDocNewsInfoById(); where = dnm.getNewsclause(); where += (StringUtils.isEmpty(where)?"":" and ") + " docpublishtype in ('2','3') "; } else if (source.equals("2")) { //来源文档目录 String targets = docids.startsWith(",") ? docids.substring(1) : docids; //String where = " seccategory in (" + targets + ") "; where = " exists (select id from docseccategory where id = seccategory and id in (" + targets + "))"; } else if (source.equals("3")) { //来源虚拟目录 String targets = docids.startsWith(",") ? docids.substring(1) : docids; where = " exists (select 1 from DocDummyDetail where docid = t1.id and catelogid in (" + targets + ")) "; } else if (source.equals("4")) { //来源指定文档 String targets = docids.startsWith(",") ? docids.substring(1) : docids; String[] tmpdocids = StringUtils.split(targets, ","); String docids_where = ""; for (String docid : tmpdocids) { int editionid = 0; int newdocid = Util.getIntValue(docid); RecordSet rs = new RecordSet(); rs.executeSql("select doceditionid from docdetail where id=" + docid); if(rs.next()) { editionid = Util.getIntValue(rs.getString("doceditionid")); } if (editionid > 0) { rs.executeSql("select id from docdetail where docedition=(select max(docedition) from docdetail where doceditionid=" + editionid + ") and doceditionid=" + editionid); if(rs.next()) { newdocid = Util.getIntValue(rs.getString("id")); } } docids_where += "," + newdocid; } docids_where = docids_where.startsWith(",") ? docids_where.substring(1) : docids_where; where = " id in (" + docids_where + ") "; } if(StringUtils.isEmpty(isreplay)||"0".equals(isreplay)){ if(where.equals("")){ where = " (isreply is null or isreply <> 1) "; }else{ where = "("+where+")"+ " and (isreply is null or isreply <> 1) "; } } if(!where.equals("")){ wheres=wheres+" or ("+where+")"; } } if(!wheres.equals("")){ wheres=wheres.substring(3); wheres="("+wheres+")"; } }catch(Exception ex){ } return wheres; } public static String getWheresByScope(int scope) { String wheres=""; try{ if(scope<=0){ return wheres; } List columnidList=new ArrayList(); RecordSet rs = new RecordSet(); rs.execute("SELECT * FROM MobileDocSetting where scope="+scope+" ORDER BY showOrder"); while(rs.next()) { columnidList.add(rs.getString("columnid")); } if(columnidList == null || columnidList.size()== 0){ return wheres; } int columnid=0; WdsxyService documentService=new WdsxyService(); for(int i=0; i