package com.sinosoft.am.count.dao; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.ws.rs.core.Context; import org.apache.log4j.Logger; import com.persistence.service.PersistenceFactory; import com.persistence.service.SysPersistence; import com.sysmodel.datamodel.xmlmodel.ModelFactory; import com.sysmodel.datamodel.xmlmodel.able.SysModel; public class AmyjyanCountDao1 { SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); StringBuffer json = new StringBuffer(); private Logger log = Logger.getLogger(this.getClass()); /** * 获取可编辑动态表头 * * @param REPORT_NAME * @return */ public String getEditColumnsName(String REPORT_TABLE_NAME,String column1) { String result = ""; String lenth =""; String[]arr1=null; StringBuffer cols=new StringBuffer(); String [] columnTemp = column1.split(","); int length = columnTemp.length; String sql = ""; if(length!=0){ lenth =100/(column1.split(",").length)+"%"; arr1=column1.split(","); for(int k=0;k -1) { cols.deleteCharAt(cols.lastIndexOf(",")); } sql = "select REPORT_TABLE_NAME,TABLE_HEAD,TABLE_COLUMN,COLUMN_NAME,REPORT_NAME,is_count from EMC_AM_TONGJITABLE where is_del='0' and REPORT_TABLE_NAME='" + REPORT_TABLE_NAME + "' and table_column in("+cols.toString()+") order by fd_objectid"; }else{ sql = "select REPORT_TABLE_NAME,TABLE_HEAD,TABLE_COLUMN,COLUMN_NAME,REPORT_NAME,is_count from EMC_AM_TONGJITABLE where is_del='0' and REPORT_TABLE_NAME='" + REPORT_TABLE_NAME + "' order by fd_objectid"; } try { List tempList = persistence.getSearchResult(99, sql.toString()); String title = ""; StringBuffer json = new StringBuffer(); List list = new ArrayList(); Map jsonMap = new HashMap(); //if("10".equals(REPORT_TABLE_NAME)){ json.append("["); json.append("{"); if("ECM_AM_EMERGENCY_TEAM".equals(REPORT_TABLE_NAME)|| "EMC_AM_GENERATOR_CAR".equals(REPORT_TABLE_NAME) || "EMC_AM_GENERATOR".equals(REPORT_TABLE_NAME) ||"EMC_AM_EXTEMAL_RESOURCES".equals(REPORT_TABLE_NAME)){ json.append("\"display\":\"" + "供电局" + "\","); }else{ json.append("\"display\":\"" + "所属单位" + "\","); } json.append("\"name\":\"" + "name" + "\","); json.append("\"width\":\"" + "150px" + "\","); json.append("\"frozen\":" + "true" + ","); json.append("\"render\":addStatus" + ","); json.append("\"maxWidth\":\"" + "150px" + "\","); json.append("\"id\":\"name\""); json.append("},"); json.append("{"); json.append("\"hide\":" + "true" + ","); json.append("\"name\":\"" + "FD_OBJECTID" + "\""); json.append("},"); for (int i = 0; i < tempList.size(); i++) { String[] arr = tempList.get(i); String table_head = arr[1]; String column = arr[2]; title = arr[4]; String isCount = arr[5]; String column_name = arr[3]; if ("".equals(table_head)||table_head==null) { jsonMap.put(column, column + "|" + column_name+"|"+isCount); list.add("|"+column); } else { if (list.contains(table_head)) { String value = jsonMap.get(table_head); jsonMap.put(table_head, value + ";" + column + "|" + column_name+"|"+isCount); } else { jsonMap.put(table_head, column + "|" + column_name+"|"+isCount); list.add(table_head); } } } for (int i = 0; i < list.size(); i++) { String table_head = list.get(i); if(table_head.startsWith("|")){ String cotent=jsonMap.get(table_head.split("[|]")[1]); String isCount=cotent.split("[|]")[2]; json.append("{"); json.append("\"display\":\"" + cotent.split("[|]")[1] + "\","); json.append("\"name\":\"" + cotent.split("[|]")[0] + "\","); json.append("\"isCount\":\"" +isCount + "\","); // json.append("\"showTitle\":true,"); json.append("\"render\":showMsger,"); json.append("\"width\":\""+"10%"+"\","); json.append("\"editor\":" + "{ \"type\": \"text\"}"); json.append("},"); }else{ String content = jsonMap.get(table_head); String[] arr = content.split(";"); json.append("{"); json.append("\"display\":\"" + table_head + "\","); json.append("\"columns\":" + "[" + ""); for (int j = 0; j < arr.length; j++) { String column = arr[j].split("[|]")[0]; String column_name = arr[j].split("[|]")[1]; String isCount=arr[j].split("[|]")[2]; int len=column_name.length()*17; json.append("{"); json.append("\"display\":\"" + column_name + "\","); json.append("\"name\":\"" + column + "\","); // json.append("\"showTitle\":true,"); json.append("\"isCount\":\"" + isCount + "\","); json.append("\"render\":showMsger,"); json.append("\"width\":\""+lenth+"\","); if ("0".equals(isCount)||"1".equals(isCount)) { json.append("\"editor\":" + "{ \"type\": \"text\",\"inputMode\":\"positiveDecimal\"}"); json.append("},"); } else { json.append("\"editor\":" + "{ \"type\": \"text\"}"); json.append("},"); } } if (json.lastIndexOf(",") > -1) { json.deleteCharAt(json.lastIndexOf(",")); } json.append("]"); json.append("},"); } } if (json.lastIndexOf(",") > -1) { json.deleteCharAt(json.lastIndexOf(",")); } json.append("]"); StringBuffer sb = new StringBuffer(); log.info(sb.toString()); result = sb.toString(); result=json.toString(); } catch (Exception e) { e.printStackTrace(); } log.info("=========================="+result); return result; } }