123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- 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<SysLayout> implements SysLayoutDao {
- public SysLayoutDaoImpl() {
- this.cmt=new CMTemplate();
- this.map=new HashMap<String,String>();
- //旧代码
- 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<conId.length;count++){
- log.info("===saveLayou()===sql==="+saveOpenMatic);
- ps=conn.prepareStatement(saveOpenMatic);
- ps.setString(1, conId[count]);
- ps.setString(2, objectId);
- ps.setString(3,maticId[count]);
- ps.setString(4, viewName);
- ps.executeUpdate();
- }
- conn.commit();
- result=ResultState.SUCCESS;
- } catch (Exception e) {
- conn.rollback();
- log.error(e.getMessage());
- result=ResultState.FAILURE;
-
- }finally{
- DBUtils.close(rs, ps, conn);
- return result;
- }
- }
-
- public List<Map<String,String>> findAll(String sqlName,Object...args) throws SQLStringException{
- List<String> 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<conId.length;i++){
- ps=conn.prepareStatement(insertMatics);
- ps.setString(1, conId[i]);
- ps.setString(2, id);
- ps.setString(3, maticId[i]);
- ps.setString(4, name);
- ps.executeUpdate();
- }
- conn.commit();
- result=ResultState.SUCCESS;
- } catch (SQLException e) {
- conn.rollback();
- e.printStackTrace();
- result=ResultState.FAILURE;
- }finally{
- DBUtils.close(null, ps, conn);
- return result;
- }
- }
- //删除视图
- public int deleteSysLayou(String FD_OBJECTID){
- Connection conn=null;
- PreparedStatement ps=null;
- try {
- conn=DBUtils.getConnection();
- conn.setAutoCommit(false);
- ps=conn.prepareStatement("delete from ECM_CM_SYSLAYOUT where FD_OBJECTID=?");
- ps.setString(1, FD_OBJECTID);
- ps.executeUpdate();
- ps=conn.prepareStatement("delete from NWYJ.ECM_CM_OPENLAYERMATIC where OL_AREAID=?");
- ps.setString(1, FD_OBJECTID);
- ps.executeUpdate();
- conn.commit();
- return 1;
- } catch (SQLException e) {
- try {
- conn.rollback();
- } catch (SQLException e1) {
- e1.printStackTrace();
- }
- e.printStackTrace();
- return 0;
- }finally{
- DBUtils.close(null, ps, conn);
- }
- }
-
- //设置默认视图
- public int setDefaultSysLayou(String userId,String FD_OBJECTID){
- Connection conn=null;
- PreparedStatement ps=null;
- try {
- conn=DBUtils.getConnection();
- conn.setAutoCommit(false);
- ps=conn.prepareStatement("UPDATE ECM_CM_SYSLAYOUT SET TM_BEX='0' WHERE SL_USERID=? AND SCREEN_STATE='1'");
- ps.setString(1, userId);
- ps.executeUpdate();
- ps=conn.prepareStatement("UPDATE ECM_CM_SYSLAYOUT SET TM_BEX='1' WHERE SL_USERID=? AND FD_OBJECTID=?");
- ps.setString(1, userId);
- ps.setString(2, FD_OBJECTID);
- ps.executeUpdate();
- conn.commit();
- return 1;
- } catch (SQLException e) {
- try {
- conn.rollback();
- } catch (SQLException e1) {
- e1.printStackTrace();
- }
- e.printStackTrace();
- return 0;
- }finally{
- DBUtils.close(null, ps, conn);
- }
- }
-
- @Override
- public SysLayout findById(String id) throws SQLException {
- log.info(map.get("queryById"));
- if(map.get("queryById").toLowerCase()==null&&"".equals(map.get("queryById").trim())) {
- throw new SQLStringException("查询语句异常");};
- log.info(id);
- if(id.toLowerCase()==null&&"".equals(id)&&"".equals(id.trim())){
- throw new SQLStringException("查询参数异常");};
- return (SysLayout)cmt.query(map.get("queryById"), new CMHandlerResultSet() {
-
- @Override
- public Object doHandler(ResultSet rs) throws SQLException {
- SysLayout sy=new SysLayout();
- while(rs.next()){
- 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"));
- }
-
- return sy;
- }
- }, id);
- }
- @Override
- public List<SysLayout> findAll() throws SQLException {
- log.info(map.get("queryAll"));
- if(map.get("queryAll").toLowerCase()==null&&"".equals(map.get("update").trim())) {
- throw new SQLStringException("查询语句异常");};
- return (List<SysLayout>) cmt.query(map.get("queryAll"),new CMHandlerResultSet() {
-
- @Override
- public Object doHandler(final ResultSet rs) throws SQLException {
- final List<SysLayout> 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<SysLayout> list=sld.findAll();
- System.out.println(JsonPluginsUtil.beanListToJson(list));
- //sld.updateName();
-
- }*/
- }
|