package com.sinosoft.cm.impl; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.HashMap; import java.util.List; import java.util.Map; import nl.justobjects.pushlet.util.Sys; import org.apache.log4j.Logger; import com.sinosoft.cm.CMHandlerResultSet; import com.sinosoft.cm.CMTemplate; import com.sinosoft.cm.DBUtils; import com.sinosoft.cm.common.StringUtils; import com.sinosoft.cm.common.vo.ResultState; import com.sinosoft.cm.dao.SysLayoutDao; import com.sinosoft.cm.ex.SQLStringException; import com.sinosoft.cm.vo.SysLayout; import flex.messaging.io.ArrayList; public class SysLayoutDaoImpl extends CMDaoImpl implements SysLayoutDao { public SysLayoutDaoImpl() { this.cmt=new CMTemplate(); this.map=new HashMap(); //旧代码 this.map.put("update", "update ECM_CM_SYSLAYOUT set IS_DEL=? where FD_OBJECTID=?"); this.map.put("delete", "delete from ECM_CM_SYSLAYOUT where FD_OBJECTID=?"); this.map.put("insert", "insert into ECM_CM_SYSLAYOUT (FD_OBJECTID,IS_DEL,SL_LAYOUTID,SL_NAME,SL_PARAMENT,TM_BEX,SL_USERID) " + "values(?,?,?,?,?,?,?)"); this.map.put("queryById", "select FD_OBJECTID,IS_DEL,SL_LAYOUTID,SL_NAME,SL_PARAMENT,TM_BEX,SL_USERID,SCREEN_STATE from ECM_CM_SYSLAYOUT where FD_OBJECTID=?"); this.map.put("queryAll", "select FD_OBJECTID,IS_DEL,SL_LAYOUTID,SL_NAME,SL_PARAMENT,TM_BEX,SL_USERID,UPDATEDATE from ECM_CM_SYSLAYOUT"); //新代码 this.map.put("getView","SELECT FD_OBJECTID,IS_DEL,SL_LAYOUTID,SL_NAME,SL_PARAMENT,TM_BEX,SL_USERID "+ "FROM ECM_CM_SYSLAYOUT "+ " WHERE SL_USERID='R002105430214' OR SL_USERID=? ORDER BY SL_USERID,UPDATEDATE"); this.map.put("getSingleView", "SELECT OL_CONID,OL_MATICID FROM ECM_CM_OPENLAYERMATIC WHERE OL_AREAID=?"); this.map.put("getOften", "SELECT IS_COMMONUSE FROM ECM_CM_SYSLAYOUT WHERE IS_COMMONUSE <> '' AND SL_USERID=? AND SCREEN_STATE='1';"); } public String saveLayou(String name,String params,String userId,String[] conId,String[] maticId,String setOften ){ String saveLayoutStr="insert into NWYJ.ECM_CM_SYSLAYOUT( FD_OBJECTID, SL_NAME, SL_PARAMENT, SL_USERID, IS_DEL, UPDATEDATE, TM_BEX,IS_COMMONUSE) " + " VALUES(sq_num.NEXTVAL, ?, ?, ?, 0, SYSDATE(), 0,?)"; String LayoutStr="SELECT FD_OBJECTID,UPDATEDATE,SL_NAME FROM NWYJ.ECM_CM_SYSLAYOUT " + " WHERE UPDATEDATE=(SELECT MAX(UPDATEDATE) " + " FROM NWYJ.ECM_CM_SYSLAYOUT WHERE SL_USERID= ? )"; String saveOpenMatic="insert into NWYJ.ECM_CM_OPENLAYERMATIC(FD_OBJECTID, OL_CONID, OL_AREAID, OL_MATICID, IS_DEL, UPDATEDATE, OL_BEX) " + " VALUES(sq_num.NEXTVAL, ?, ?, ?, 0,SYSDATE(), ?)"; String result=null; Connection conn=null; PreparedStatement ps=null; ResultSet rs=null; int flag=0; try { conn=DBUtils.getConnection(); conn.setAutoCommit(false); //保存视图 log.info("===saveLayou()===sql==="+saveLayoutStr); ps=conn.prepareStatement(saveLayoutStr); ps.setString(1, name); ps.setString(2, params); ps.setString(3, userId); ps.setString(4, setOften); ps.executeUpdate(); //获取保存视图后的主键id log.info("===saveLayou()===sql==="+LayoutStr); ps=conn.prepareStatement(LayoutStr); ps.setString(1, userId); rs=ps.executeQuery(); //System.out.println(flag); //保存各个容器的专题图 System.out.println("conId.length"+conId.length); String objectId=null; String viewName=null; while(rs.next()){ objectId= rs.getString("FD_OBJECTID"); viewName=rs.getString("SL_NAME"); } for(int count=0;count> findAll(String sqlName,Object...args) throws SQLStringException{ List list=StringUtils.sqlStringToListLabel(map.get(sqlName).trim().toUpperCase(), ","); log.info("======findAll(String sqlName,Object...args)==sqlLabel="+list); if(map.get(sqlName).toLowerCase()==null&&"".equals(map.get(sqlName).trim())) throw new SQLStringException("查询语句为空"); log.info("======findAll(String sqlName,Object...args)==sql="+map.get(sqlName).trim().toUpperCase()); return cmt.queryMoreTypeToMap(map.get(sqlName), list, args); } //更改视图名称 @SuppressWarnings("finally") public String updateName(String name,String id,String[] conId,String[] maticId){ Connection conn=null; PreparedStatement ps=null; String setViewName="update ECM_CM_SYSLAYOUT set SL_NAME=? where FD_OBJECTID=?"; String deleteMatics="DELETE FROM ECM_CM_OPENLAYERMATIC WHERE OL_AREAID=?"; String insertMatics="insert into NWYJ.ECM_CM_OPENLAYERMATIC(FD_OBJECTID, OL_CONID, OL_AREAID, OL_MATICID, IS_DEL, UPDATEDATE, OL_BEX) " + " VALUES(sq_num.NEXTVAL, ?, ?, ?, 0,SYSDATE(), ?)"; String result=null; try { conn=DBUtils.getConnection(); conn.setAutoCommit(false); //修改视图名称 ps=conn.prepareStatement(setViewName); ps.setString(1, name); ps.setString(2, id); ps.executeUpdate(); ps.close(); //删除视图 ps=conn.prepareStatement(deleteMatics); ps.setString(1,id); ps.executeUpdate(); // for(int i=0;i findAll() throws SQLException { log.info(map.get("queryAll")); if(map.get("queryAll").toLowerCase()==null&&"".equals(map.get("update").trim())) { throw new SQLStringException("查询语句异常");}; return (List) cmt.query(map.get("queryAll"),new CMHandlerResultSet() { @Override public Object doHandler(final ResultSet rs) throws SQLException { final List list=new ArrayList(); while(rs.next()){ SysLayout sy=new SysLayout(); sy.setFD_OBJECTID(rs.getString("FD_OBJECTID")); sy.setIS_DEL(rs.getString("IS_DEL")); sy.setSL_LAYOUTID(rs.getString("SL_LAYOUTID")); sy.setSL_NAME(rs.getString("SL_NAME")); sy.setSL_PARAMENT(rs.getString("SL_PARAMENT")); sy.setTM_BEX(rs.getString("TM_BEX")); sy.setSL_USERID(rs.getString("SL_USERID")); //sy.setUPDATEDATE(rs.getDate("UPDATEDATE")); list.add(sy); } return list; } }); } //Result res=new Result(JsonPluginsUtil.beanListToJson(list), Result.STATE_SUCCESS, 0, listString.size()); /* public static void main(String[] args) { Logger log1 = Logger.getLogger(SysLayoutDaoImpl.class); SysLayoutDaoImpl sld=new SysLayoutDaoImpl(); int add=sld.add("1","1","1","1","1","1","1"); Assert.equals(1, add); int update=sld.update(1,2); int delete=sld.delete(1); Assert.equals(1, delete); SysLayout sl=sld.findById("2"); System.out.println(sl.toJSONString()); List list=sld.findAll(); System.out.println(JsonPluginsUtil.beanListToJson(list)); //sld.updateName(); }*/ }