审查视图

src/java/com/airport/dao/impl/DaoImpl.java 5.9 KB
朱兆平 authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.airport.dao.impl;

import com.airport.bean.MessageBak;
import com.airport.dao.Dao;
import com.airport.util.ConfigUtils;
import java.io.IOException;
import java.io.Writer;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import oracle.sql.CLOB;
import org.apache.log4j.Logger;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementCreator;
import org.springframework.jdbc.core.support.AbstractLobStreamingResultSetExtractor;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.jdbc.support.lob.DefaultLobHandler;
import org.springframework.jdbc.support.lob.LobHandler;

public class DaoImpl implements Dao {
    private static final Logger logger = Logger.getLogger(DaoImpl.class);
    private JdbcTemplate jdbcTemplate;

    public DaoImpl() {
    }

    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }
朱兆平 authored
43
    public int insertRecord(final String oper, final String sndr,String sntm,String type,String styp,String seqn) {
朱兆平 authored
44 45 46
        KeyHolder keyHolder = new GeneratedKeyHolder();
        this.jdbcTemplate.update(new PreparedStatementCreator() {
            public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
朱兆平 authored
47
                DaoImpl.logger.info("oper=" + oper + " sndr=" + sndr+"type="+type+"styp="+styp);
朱兆平 authored
48
                String sql = "insert into  T_ETL_MESSAGE(OPER,SNDR,SNTM,content,TYPE,STYP,SEQN) values(?,?,to_date(?,'yyyyMMddhh24miss'),empty_clob(),?,?,?)";
朱兆平 authored
49 50 51
                PreparedStatement ps = connection.prepareStatement(sql, new String[]{"FID"});
                ps.setString(1, oper);
                ps.setString(2, sndr);
朱兆平 authored
52 53 54 55
                ps.setString(3, sntm);
                ps.setString(4, type);
                ps.setString(5, styp);
                ps.setString(6,seqn);
朱兆平 authored
56 57 58 59 60 61 62
                return ps;
            }
        }, keyHolder);
        int generatedId = keyHolder.getKey().intValue();
        return generatedId;
    }
朱兆平 authored
63
    public void saveRecord(String messaegType, String sndr,String sntm, String xmlContent,String type,String styp,String seqn) throws Exception {
朱兆平 authored
64 65 66 67 68 69
        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;
        int fid = -100;

        try {
朱兆平 authored
70
            fid = this.insertRecord(messaegType, sndr,sntm,type,styp,seqn);
朱兆平 authored
71 72 73
            conn = this.jdbcTemplate.getDataSource().getConnection();
            conn.setAutoCommit(false);
            stmt = conn.createStatement();
朱兆平 authored
74
            String SQL = "select CONTENT from T_ETL_MESSAGE where FID=" + fid + " for update";
朱兆平 authored
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
            rs = stmt.executeQuery(SQL);

            while(rs.next()) {
                CLOB clob = (CLOB)rs.getClob(1);
                Writer os = clob.getCharacterOutputStream();
                os.write(xmlContent);
                os.flush();
                os.close();
            }

            conn.commit();
        } catch (SQLException var14) {
            if (fid > 0) {
                this.delete(fid);
            }

            var14.printStackTrace();
            conn.rollback();
        } finally {
            if (conn != null) {
                conn.setAutoCommit(true);
            }

            if (rs != null) {
                rs.close();
            }

            if (stmt != null) {
                stmt.close();
            }

            if (conn != null) {
                conn.close();
            }

        }

    }

    public void delete(int fid) {
115
        this.jdbcTemplate.update("delete from T_ETL_MESSAGE where fid=" + fid);
朱兆平 authored
116 117
    }
118 119
    public int getMaxFID(String sqlmax) {
//        String sqlmax = "select max(fid) from MESSAGE_BAK WHERE (FID>%s and FID<%s+%s) AND (TYPE='CLR' OR TYPE='ES1' OR TYPE='IS1' OR  STYP = 'BSTA' OR STYP = 'FZE_RCF' OR STYP = 'FSU_FOH' OR STYP = 'FSU_DEP' OR STYP = 'COST' OR STYP = 'ABME' OR STYP = 'FZE_DEP' OR STYP = 'FSU_RCF') ORDER BY FID\n";
120
//        sqlmax = ConfigUtils.SQlMax;
121
        return this.jdbcTemplate.queryForInt(sqlmax);
朱兆平 authored
122 123
    }
124 125
    public List<MessageBak> getRecordByFID(int fid,String sql) {
朱兆平 authored
126 127 128 129 130 131 132 133 134 135
        final LobHandler lobHandler = new DefaultLobHandler();
        final ArrayList xmlList = new ArrayList();

        try {
            this.jdbcTemplate.query(sql, new AbstractLobStreamingResultSetExtractor() {
                protected void streamData(ResultSet rs) throws SQLException, IOException, DataAccessException {
                    String content = "";
                    while(rs.next()) {
                        int fid = rs.getInt(1);
                        content = lobHandler.getClobAsString(rs, "CONTENT");
136
                        int rownum = rs.getInt("rownum_");
朱兆平 authored
137
                        if (content != null) {
138
                            MessageBak obj = new MessageBak(fid, content,rownum);
朱兆平 authored
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
                            xmlList.add(obj);
                        } else {
                            DaoImpl.logger.error("FID=" + fid + "  content is NULL");
                        }
                    }

                }
            });
        } catch (EmptyResultDataAccessException var7) {
            var7.printStackTrace();
        }

        return xmlList;
    }

    public int getRecordCount() {
155
        return this.jdbcTemplate.queryForInt("select count(*) from T_ETL_MESSAGE where SNDR='FIMS' ");
朱兆平 authored
156 157 158
    }

    public void update(int fid, int times) {
159
        String sql = String.format("update T_ETL_MESSAGE set OUTFLAG=%s ,OUTTM=sysdate  where  FID=%s", times, fid);
朱兆平 authored
160 161 162 163
        logger.info("sql=" + sql);
        this.jdbcTemplate.update(sql);
    }
}