# FutureHoldDAOImpl.java

    package com.mycim.server.ctx.exec.dao.impl;

    import com.mycim.framework.jdbc.JdbcTemplate;
    import com.mycim.framework.jdbc.mapper.RowMapper;
    import com.mycim.framework.utils.lang.collections.MapUtils;
    import com.mycim.server.ctx.exec.dao.FutureHoldDAO;
    import com.mycim.valueobject.consts.DataBaseNames;
    import com.mycim.valueobject.prp.FutureHold;
    import com.mycim.valueobject.prp.FutureHoldHistory;
    import com.mycim.valueobject.prp.FutureHoldLot;
    import com.mycim.valueobject.prp.FutureHoldLotHistory;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Repository;

    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Timestamp;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;

    /**
     * @author Sola
     * @date 2021/7/19
     **/
    @Repository
    public class FutureHoldDAOImpl implements FutureHoldDAO{
        @Autowired
        private JdbcTemplate jdbcTemplate;

        @Override
        public void insertFutureHold(FutureHold futureHoldInfo) {
            Long sysRrn =futureHoldInfo.getSysRrn();
            Long facilityRrn = futureHoldInfo.getFacilityRrn();
            String status = futureHoldInfo.getStatus();
            Long lotRrn = futureHoldInfo.getLotRrn();
            Long productRrn = futureHoldInfo.getProductRrn();
            Long productVersion = futureHoldInfo.getProductVersion();
            Long processRrn = futureHoldInfo.getProcessRrn();
            Long processVersion = futureHoldInfo.getProcessVersion();
            Long routeRrn = futureHoldInfo.getRouteRrn();
            String routeSeq = futureHoldInfo.getRouteSeq();
            Long operationRrn = futureHoldInfo.getOperationRrn();
            String operationSeq = futureHoldInfo.getOperationSeq();
            String flowSeq = futureHoldInfo.getFlowSeq();
            Long effictiveCount = futureHoldInfo.getEffictiveCount();
            String holdType = futureHoldInfo.getHoldType();
            String holdCategory = futureHoldInfo.getHoldCategory();
            String holdGroup = futureHoldInfo.getHoldGroup();
            String holdCode = futureHoldInfo.getHoldCode();
            String holdReason = futureHoldInfo.getHoldReason();
            String holdComment = futureHoldInfo.getHoldComment();
            Long createUserRrn = futureHoldInfo.getCreateUserRrn();
            Timestamp createTime = (Timestamp) futureHoldInfo.getCreateTime();
            Long updateUserRrn = futureHoldInfo.getUpdateUserRrn();
            Timestamp updateTime = (Timestamp) futureHoldInfo.getUpdateTime();
            String seqNum = futureHoldInfo.getAttributeData1();

            String sql = "INSERT INTO " + DataBaseNames.FUTURE_HOLD + "(SYS_RRN, FACILITY_RRN, STATUS, LOT_RRN, PRODUCT_RRN, PRODUCT_VERSION, " +
                    " PROCESS_RRN,PROCESS_VERSION,ROUTE_RRN,ROUTE_SEQ,OPERATION_RRN,OPERATION_SEQ,FLOW_SEQ, " +
                    " EFFICTIVE_COUNT,HOLD_TYPE,HOLD_CATEGORY,HOLD_GROUP,HOLD_CODE,HOLD_REASON," +
                    " HOLD_COMMENT,CREATE_USER_RRN,CREATE_TIME,UPDATE_USER_RRN,UPDATE_TIME,ATTRIBUTE_DATA1) " +
                    " VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ";

            Object[] obj ={sysRrn,facilityRrn,status,lotRrn,productRrn,productVersion,processRrn
                        ,processVersion,routeRrn,routeSeq,operationRrn,operationSeq,flowSeq,
                           effictiveCount,holdType,holdCategory,holdGroup,holdCode,holdReason,
                           holdComment,createUserRrn,createTime,updateUserRrn,updateTime,seqNum};
            jdbcTemplate.update(sql,obj);
        }

        @Override
        public void insertFutureHoldH(FutureHoldHistory futureHoldHInfo) {
            Long sysRrn = futureHoldHInfo.getSysRrn();
            Long transRrn = futureHoldHInfo.getTransRrn();
            String transId = futureHoldHInfo.getTransId();
            Long facilityRrn = futureHoldHInfo.getFacilityRrn();
            String status = futureHoldHInfo.getStatus();
            Long lotRrn = futureHoldHInfo.getLotRrn();
            Long productRrn = futureHoldHInfo.getProductRrn();
            Long productVersion = futureHoldHInfo.getProductVersion();
            Long processRrn = futureHoldHInfo.getProcessRrn();
            Long processVersion = futureHoldHInfo.getProcessVersion();
            Long routeRrn = futureHoldHInfo.getRouteRrn();
            String routeSeq = futureHoldHInfo.getRouteSeq();
            Long operationRrn = futureHoldHInfo.getOperationRrn();
            String operationSeq = futureHoldHInfo.getOperationSeq();
            String flowSeq = futureHoldHInfo.getFlowSeq();
            String holdType = futureHoldHInfo.getHoldType();
            String holdCategory = futureHoldHInfo.getHoldCategory();
            String holdGroup = futureHoldHInfo.getHoldGroup();
            String holdCode = futureHoldHInfo.getHoldCode();
            String holdReason = futureHoldHInfo.getHoldReason();
            String holdComment = futureHoldHInfo.getHoldComment();
            String transUserId = futureHoldHInfo.getTransUserId();
            Timestamp transTime = (Timestamp) futureHoldHInfo.getTransTime();

            String sql = "INSERT INTO " + DataBaseNames.FUTURE_HOLD_H + "(SYS_RRN,TRANS_RRN,TRANS_ID,FACILITY_RRN, " +
                    " STATUS, LOT_RRN, PRODUCT_RRN, PRODUCT_VERSION, " +
                    " PROCESS_RRN,PROCESS_VERSION,ROUTE_RRN,ROUTE_SEQ,OPERATION_RRN,OPERATION_SEQ,FLOW_SEQ, " +
                    " HOLD_TYPE,HOLD_CATEGORY,HOLD_GROUP,HOLD_CODE,HOLD_REASON,HOLD_COMMENT,TRANS_USER_ID,TRANS_TIME) " +
                    " VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ";

            Object[] obj ={sysRrn,transRrn,transId,facilityRrn,status,lotRrn,productRrn,productVersion,processRrn
                    ,processVersion,routeRrn,routeSeq,operationRrn,operationSeq,flowSeq,
                           holdType,holdCategory,holdGroup,holdCode,holdReason,holdComment,transUserId,transTime};
            jdbcTemplate.update(sql,obj);
        }

        @Override
        public List<FutureHold> getFHListByProduct(Long facilityRrn, Long productRrn, String holdType, String holdCategory) {
            String sql = " SELECT SYS_RRN,FACILITY_RRN,STATUS,LOT_RRN,PRODUCT_RRN,PRODUCT_VERSION,PROCESS_RRN,PROCESS_VERSION,ROUTE_RRN, " +
                    " ROUTE_SEQ,OPERATION_RRN,OPERATION_SEQ,FLOW_SEQ,EFFICTIVE_COUNT,HOLD_TYPE,HOLD_GROUP,HOLD_CODE, " +
                    " HOLD_REASON,HOLD_COMMENT,CREATE_USER_RRN,CREATE_TIME,UPDATE_USER_RRN,UPDATE_TIME,HOLD_CATEGORY,ATTRIBUTE_DATA1,ATTRIBUTE_DATA2 FROM  " + DataBaseNames.FUTURE_HOLD +
                    " WHERE FACILITY_RRN=? AND PRODUCT_RRN=? AND HOLD_TYPE=? AND HOLD_CATEGORY=? ";

            return jdbcTemplate.query(sql, new Object[]{facilityRrn, productRrn, holdType, holdCategory}, new RowMapper<FutureHold>() {
                @Override
                public FutureHold mapRow(ResultSet rs, int rowNum) throws SQLException {
                    FutureHold futureHold = new FutureHold();
                    futureHold.setSysRrn(rs.getLong("SYS_RRN"));
                    futureHold.setFacilityRrn(rs.getLong("FACILITY_RRN"));
                    futureHold.setStatus(rs.getString("STATUS"));
                    futureHold.setLotRrn(rs.getLong("LOT_RRN"));
                    futureHold.setProductRrn(rs.getLong("PRODUCT_RRN"));
                    futureHold.setProductVersion(rs.getLong("PRODUCT_VERSION"));
                    futureHold.setProcessRrn(rs.getLong("PROCESS_RRN"));
                    futureHold.setProcessVersion(rs.getLong("PROCESS_VERSION"));
                    futureHold.setRouteRrn(rs.getLong("ROUTE_RRN"));
                    futureHold.setRouteSeq(rs.getString("ROUTE_SEQ"));
                    futureHold.setOperationRrn(rs.getLong("OPERATION_RRN"));
                    futureHold.setOperationSeq(rs.getString("OPERATION_SEQ"));
                    futureHold.setFlowSeq(rs.getString("FLOW_SEQ"));
                    futureHold.setEffictiveCount(rs.getLong("EFFICTIVE_COUNT"));
                    futureHold.setHoldType(rs.getString("HOLD_TYPE"));
                    futureHold.setHoldGroup(rs.getString("HOLD_GROUP"));
                    futureHold.setHoldCode(rs.getString("HOLD_CODE"));
                    futureHold.setHoldReason(rs.getString("HOLD_REASON"));
                    futureHold.setHoldComment(rs.getString("HOLD_COMMENT"));
                    futureHold.setHoldCategory(rs.getString("HOLD_CATEGORY"));
                    futureHold.setCreateUserRrn(rs.getLong("CREATE_USER_RRN"));
                    futureHold.setCreateTime(rs.getTimestamp("CREATE_TIME"));
                    futureHold.setUpdateUserRrn(rs.getLong("UPDATE_USER_RRN"));
                    futureHold.setUpdateTime(rs.getTimestamp("UPDATE_TIME"));
                    futureHold.setAttributeData1(rs.getString("ATTRIBUTE_DATA1"));
                    futureHold.setAttributeData2(rs.getString("ATTRIBUTE_DATA2"));
                    return futureHold;
                }
            });
        }

        @Override
        public List<FutureHoldLotHistory> getFutureHoldLotHList(Long sysRrn, Long lotRrn) {
            String sql = " SELECT TRANS_RRN,TRANS_ID,FUTURE_HOLD_SYS_RRN,LOT_RRN,JOB_RRN,PRODUCT_RRN,PRODUCT_VERSION,PROCESS_RRN,PROCESS_VERSION, " +
                    " ROUTE_RRN,ROUTE_SEQ,OPERATION_RRN,OPERATION_SEQ,FLOW_SEQ,OPERATION_DESC,STAGE_ID,PROCESS_LOCATION, " +
                    " HOLD_TYPE,HOLD_GROUP,HOLD_CODE,HOLD_REASON,HOLD_COMMENT,HOLD_CATEGORY,HOLD_QTY,RESPONSIBILITY,TRANS_USER_ID,TRANS_TIME "+
                    " FROM "+DataBaseNames.FUTURE_HOLD_LOT_H+" WHERE FUTURE_HOLD_SYS_RRN=?  AND LOT_RRN = ? ";

            return jdbcTemplate.query(sql,new Object[]{sysRrn,lotRrn},new RowMapper<FutureHoldLotHistory>() {
                @Override
                public FutureHoldLotHistory mapRow(ResultSet rs, int rowNum) throws SQLException {
                    FutureHoldLotHistory futureHoldLotHistory = new FutureHoldLotHistory();
                    futureHoldLotHistory.setTransRrn(rs.getLong("TRANS_RRN"));
                    futureHoldLotHistory.setTransId(rs.getString("TRANS_ID"));
                    futureHoldLotHistory.setFutureHoldSysRrn(rs.getLong("FUTURE_HOLD_SYS_RRN"));
                    futureHoldLotHistory.setLotRrn(rs.getLong("LOT_RRN"));
                    futureHoldLotHistory.setJobRrn(rs.getLong("JOB_RRN"));
                    futureHoldLotHistory.setProductRrn(rs.getLong("PRODUCT_RRN"));
                    futureHoldLotHistory.setProductVersion(rs.getLong("PRODUCT_VERSION"));
                    futureHoldLotHistory.setProcessRrn(rs.getLong("PROCESS_RRN"));
                    futureHoldLotHistory.setProcessVersion(rs.getLong("PROCESS_VERSION"));
                    futureHoldLotHistory.setRouteRrn(rs.getLong("ROUTE_RRN"));
                    futureHoldLotHistory.setRouteSeq(rs.getString("ROUTE_SEQ"));
                    futureHoldLotHistory.setOperationRrn(rs.getLong("OPERATION_RRN"));
                    futureHoldLotHistory.setOperationSeq(rs.getString("OPERATION_SEQ"));
                    futureHoldLotHistory.setFlowSeq(rs.getString("FLOW_SEQ"));
                    futureHoldLotHistory.setOperationDesc(rs.getString("OPERATION_DESC"));
                    futureHoldLotHistory.setStageId(rs.getString("STAGE_ID"));
                    futureHoldLotHistory.setProcessLocation(rs.getString("PROCESS_LOCATION"));
                    futureHoldLotHistory.setHoldType(rs.getString("HOLD_TYPE"));
                    futureHoldLotHistory.setHoldGroup(rs.getString("HOLD_GROUP"));
                    futureHoldLotHistory.setHoldCode(rs.getString("HOLD_CODE"));
                    futureHoldLotHistory.setHoldReason(rs.getString("HOLD_REASON"));
                    futureHoldLotHistory.setHoldComment(rs.getString("HOLD_COMMENT"));
                    futureHoldLotHistory.setHoldCategory(rs.getString("HOLD_CATEGORY"));
                    futureHoldLotHistory.setHoldQty(rs.getLong("HOLD_QTY"));
                    futureHoldLotHistory.setResponsibility(rs.getString("RESPONSIBILITY"));
                    futureHoldLotHistory.setTransUserId(rs.getString("TRANS_USER_ID"));
                    futureHoldLotHistory.setTransTime(rs.getTimestamp("TRANS_TIME"));
                    return futureHoldLotHistory;
                }
            });
        }

        @Override
        public void deleteFutureHold(Long sysRrn) {
            String sql = "DELETE FROM " + DataBaseNames.FUTURE_HOLD + " WHERE SYS_RRN=? ";

            jdbcTemplate.update(sql, sysRrn);
        }

        @Override
        public List<FutureHold> getFutureHoldBySysRrn(Long futureHoldSysRrn) {
            String sql = " SELECT SYS_RRN,FACILITY_RRN,STATUS,LOT_RRN,PRODUCT_RRN,PRODUCT_VERSION,PROCESS_RRN,PROCESS_VERSION,ROUTE_RRN, " +
                    " ROUTE_SEQ,OPERATION_RRN,OPERATION_SEQ,FLOW_SEQ,EFFICTIVE_COUNT,HOLD_TYPE,HOLD_GROUP,HOLD_CODE, " +
                    " HOLD_REASON,HOLD_COMMENT,CREATE_USER_RRN,CREATE_TIME,UPDATE_USER_RRN,UPDATE_TIME,HOLD_CATEGORY,ATTRIBUTE_DATA1 FROM "+DataBaseNames.FUTURE_HOLD+" WHERE " +
                    " SYS_RRN = ? ";
            return jdbcTemplate.query(sql,new Object[]{futureHoldSysRrn}, new RowMapper<FutureHold>() {
                @Override
                public FutureHold mapRow(ResultSet rs, int rowNum) throws SQLException {
                    FutureHold futureHold = new FutureHold();
                    futureHold.setSysRrn(rs.getLong("SYS_RRN"));
                    futureHold.setFacilityRrn(rs.getLong("FACILITY_RRN"));
                    futureHold.setStatus(rs.getString("STATUS"));
                    futureHold.setLotRrn(rs.getLong("LOT_RRN"));
                    futureHold.setProductRrn(rs.getLong("PRODUCT_RRN"));
                    futureHold.setProductVersion(rs.getLong("PRODUCT_VERSION"));
                    futureHold.setProcessRrn(rs.getLong("PROCESS_RRN"));
                    futureHold.setProcessVersion(rs.getLong("PROCESS_VERSION"));
                    futureHold.setRouteRrn(rs.getLong("ROUTE_RRN"));
                    futureHold.setRouteSeq(rs.getString("ROUTE_SEQ"));
                    futureHold.setOperationRrn(rs.getLong("OPERATION_RRN"));
                    futureHold.setOperationSeq(rs.getString("OPERATION_SEQ"));
                    futureHold.setFlowSeq(rs.getString("FLOW_SEQ"));
                    futureHold.setEffictiveCount(rs.getLong("EFFICTIVE_COUNT"));
                    futureHold.setHoldType(rs.getString("HOLD_TYPE"));
                    futureHold.setHoldGroup(rs.getString("HOLD_GROUP"));
                    futureHold.setHoldCode(rs.getString("HOLD_CODE"));
                    futureHold.setHoldReason(rs.getString("HOLD_REASON"));
                    futureHold.setHoldComment(rs.getString("HOLD_COMMENT"));
                    futureHold.setHoldCategory(rs.getString("HOLD_CATEGORY"));
                    futureHold.setCreateUserRrn(rs.getLong("CREATE_USER_RRN"));
                    futureHold.setCreateTime(rs.getTimestamp("CREATE_TIME"));
                    futureHold.setUpdateUserRrn(rs.getLong("UPDATE_USER_RRN"));
                    futureHold.setUpdateTime(rs.getTimestamp("UPDATE_TIME"));
                    futureHold.setAttributeData1(rs.getString("ATTRIBUTE_DATA1"));
                    return futureHold;
                }
            });
        }

        @Override
        public List<FutureHold> getFutureHold(FutureHold futureHold) {
            List<Object> obj = new ArrayList();
            obj.add(futureHold.getFacilityRrn());
            obj.add(futureHold.getProductRrn());
            obj.add(futureHold.getProcessRrn());
            obj.add(futureHold.getRouteRrn());
            obj.add(futureHold.getOperationRrn());
            obj.add(futureHold.getHoldType());
            obj.add(futureHold.getHoldCategory());

            Long lotRrn = futureHold.getLotRrn();
            String lotCondition = "";
            if(lotRrn != null && lotRrn != 0){
                obj.add(lotRrn);
                lotCondition = " AND LOT_RRN = ? ";
            }

            String sql = " SELECT SYS_RRN,FACILITY_RRN,STATUS,LOT_RRN,PRODUCT_RRN,PRODUCT_VERSION,PROCESS_RRN,PROCESS_VERSION,ROUTE_RRN, " +
                    " ROUTE_SEQ,OPERATION_RRN,OPERATION_SEQ,FLOW_SEQ,EFFICTIVE_COUNT,HOLD_TYPE,HOLD_GROUP,HOLD_CODE, " +
                    " HOLD_REASON,HOLD_COMMENT,CREATE_USER_RRN,CREATE_TIME,UPDATE_USER_RRN,UPDATE_TIME,HOLD_CATEGORY,ATTRIBUTE_DATA1 FROM "+DataBaseNames.FUTURE_HOLD+" WHERE " +
                    " FACILITY_RRN=? AND PRODUCT_RRN=? AND PROCESS_RRN=? AND ROUTE_RRN=? "+
                    " AND OPERATION_RRN=? AND HOLD_TYPE=? AND HOLD_CATEGORY=? "+ lotCondition;

            return jdbcTemplate.query(sql, obj.toArray(), new RowMapper<FutureHold>() {
                @Override
                public FutureHold mapRow(ResultSet rs, int rowNum) throws SQLException {
                    FutureHold futureHold = new FutureHold();
                    futureHold.setSysRrn(rs.getLong("SYS_RRN"));
                    futureHold.setFacilityRrn(rs.getLong("FACILITY_RRN"));
                    futureHold.setStatus(rs.getString("STATUS"));
                    futureHold.setLotRrn(rs.getLong("LOT_RRN"));
                    futureHold.setProductRrn(rs.getLong("PRODUCT_RRN"));
                    futureHold.setProductVersion(rs.getLong("PRODUCT_VERSION"));
                    futureHold.setProcessRrn(rs.getLong("PROCESS_RRN"));
                    futureHold.setProcessVersion(rs.getLong("PROCESS_VERSION"));
                    futureHold.setRouteRrn(rs.getLong("ROUTE_RRN"));
                    futureHold.setRouteSeq(rs.getString("ROUTE_SEQ"));
                    futureHold.setOperationRrn(rs.getLong("OPERATION_RRN"));
                    futureHold.setOperationSeq(rs.getString("OPERATION_SEQ"));
                    futureHold.setFlowSeq(rs.getString("FLOW_SEQ"));
                    futureHold.setEffictiveCount(rs.getLong("EFFICTIVE_COUNT"));
                    futureHold.setHoldType(rs.getString("HOLD_TYPE"));
                    futureHold.setHoldGroup(rs.getString("HOLD_GROUP"));
                    futureHold.setHoldCode(rs.getString("HOLD_CODE"));
                    futureHold.setHoldReason(rs.getString("HOLD_REASON"));
                    futureHold.setHoldComment(rs.getString("HOLD_COMMENT"));
                    futureHold.setHoldCategory(rs.getString("HOLD_CATEGORY"));
                    futureHold.setCreateUserRrn(rs.getLong("CREATE_USER_RRN"));
                    futureHold.setCreateTime(rs.getTimestamp("CREATE_TIME"));
                    futureHold.setUpdateUserRrn(rs.getLong("UPDATE_USER_RRN"));
                    futureHold.setUpdateTime(rs.getTimestamp("UPDATE_TIME"));
                    futureHold.setAttributeData1(rs.getString("ATTRIBUTE_DATA1"));
                    return futureHold;
                }
            });
        }

        @Override
        public List<FutureHold> getFHListByLot(Long facilityRrn, Long lotRrn, String holdType,
                                                        String holdCategory) {
            String sql = " SELECT SYS_RRN,FACILITY_RRN,STATUS,LOT_RRN,PRODUCT_RRN,PRODUCT_VERSION,PROCESS_RRN,PROCESS_VERSION,ROUTE_RRN, " +
                    " ROUTE_SEQ,OPERATION_RRN,OPERATION_SEQ,FLOW_SEQ,EFFICTIVE_COUNT,HOLD_TYPE,HOLD_GROUP,HOLD_CODE, " +
                    " HOLD_REASON,HOLD_COMMENT,CREATE_USER_RRN,CREATE_TIME,UPDATE_USER_RRN,UPDATE_TIME,HOLD_CATEGORY,ATTRIBUTE_DATA1 FROM  " + DataBaseNames.FUTURE_HOLD +
                    " WHERE FACILITY_RRN=? AND LOT_RRN=? AND HOLD_TYPE=? AND HOLD_CATEGORY=? ";

            return jdbcTemplate.query(sql, new Object[]{facilityRrn, lotRrn, holdType, holdCategory}, new RowMapper<FutureHold>() {
                @Override
                public FutureHold mapRow(ResultSet rs, int rowNum) throws SQLException {
                    FutureHold futureHold = new FutureHold();
                    futureHold.setSysRrn(rs.getLong("SYS_RRN"));
                    futureHold.setFacilityRrn(rs.getLong("FACILITY_RRN"));
                    futureHold.setStatus(rs.getString("STATUS"));
                    futureHold.setLotRrn(rs.getLong("LOT_RRN"));
                    futureHold.setProductRrn(rs.getLong("PRODUCT_RRN"));
                    futureHold.setProductVersion(rs.getLong("PRODUCT_VERSION"));
                    futureHold.setProcessRrn(rs.getLong("PROCESS_RRN"));
                    futureHold.setProcessVersion(rs.getLong("PROCESS_VERSION"));
                    futureHold.setRouteRrn(rs.getLong("ROUTE_RRN"));
                    futureHold.setRouteSeq(rs.getString("ROUTE_SEQ"));
                    futureHold.setOperationRrn(rs.getLong("OPERATION_RRN"));
                    futureHold.setOperationSeq(rs.getString("OPERATION_SEQ"));
                    futureHold.setFlowSeq(rs.getString("FLOW_SEQ"));
                    futureHold.setEffictiveCount(rs.getLong("EFFICTIVE_COUNT"));
                    futureHold.setHoldType(rs.getString("HOLD_TYPE"));
                    futureHold.setHoldGroup(rs.getString("HOLD_GROUP"));
                    futureHold.setHoldCode(rs.getString("HOLD_CODE"));
                    futureHold.setHoldReason(rs.getString("HOLD_REASON"));
                    futureHold.setHoldComment(rs.getString("HOLD_COMMENT"));
                    futureHold.setHoldCategory(rs.getString("HOLD_CATEGORY"));
                    futureHold.setCreateUserRrn(rs.getLong("CREATE_USER_RRN"));
                    futureHold.setCreateTime(rs.getTimestamp("CREATE_TIME"));
                    futureHold.setUpdateUserRrn(rs.getLong("UPDATE_USER_RRN"));
                    futureHold.setUpdateTime(rs.getTimestamp("UPDATE_TIME"));
                    futureHold.setAttributeData1(rs.getString("ATTRIBUTE_DATA1"));
                    return futureHold;
                }
            });

        }

        @Override
        public List<FutureHoldLot> getFHLotListByLot(Long lotRrn, String holdType) {
            String sql = " SELECT FUTURE_HOLD_SYS_RRN,LOT_RRN,JOB_RRN,PRODUCT_RRN,PRODUCT_VERSION,PROCESS_RRN,PROCESS_VERSION, " +
                    " ROUTE_RRN,ROUTE_SEQ,OPERATION_RRN,OPERATION_SEQ,FLOW_SEQ,OPERATION_DESC,STAGE_ID,PROCESS_LOCATION, " +
                    " HOLD_TYPE,HOLD_GROUP,HOLD_CODE,HOLD_REASON,HOLD_COMMENT,HOLD_CATEGORY,HOLD_QTY,RESPONSIBILITY, " +
                    " CREATE_USER_RRN,CREATE_TIME,UPDATE_USER_RRN,UPDATE_TIME,ATTRIBUTE_DATA1,ATTRIBUTE_DATA2 FROM "+DataBaseNames.FUTURE_HOLD_LOT+" WHERE LOT_RRN = ? AND HOLD_TYPE = ? ";

            return jdbcTemplate.query(sql, new Object[]{lotRrn,holdType}, new RowMapper<FutureHoldLot>() {
                @Override
                public FutureHoldLot mapRow(ResultSet rs, int rowNum) throws SQLException {
                    FutureHoldLot futureHoldLot = new FutureHoldLot();
                    futureHoldLot.setFutureHoldSysRrn(rs.getLong("FUTURE_HOLD_SYS_RRN"));
                    futureHoldLot.setLotRrn(rs.getLong("LOT_RRN"));
                    futureHoldLot.setJobRrn(rs.getLong("JOB_RRN"));
                    futureHoldLot.setProductRrn(rs.getLong("PRODUCT_RRN"));
                    futureHoldLot.setProductVersion(rs.getLong("PRODUCT_VERSION"));
                    futureHoldLot.setProcessRrn(rs.getLong("PROCESS_RRN"));
                    futureHoldLot.setProcessVersion(rs.getLong("PROCESS_VERSION"));
                    futureHoldLot.setRouteRrn(rs.getLong("ROUTE_RRN"));
                    futureHoldLot.setRouteSeq(rs.getString("ROUTE_SEQ"));
                    futureHoldLot.setOperationRrn(rs.getLong("OPERATION_RRN"));
                    futureHoldLot.setOperationSeq(rs.getString("OPERATION_SEQ"));
                    futureHoldLot.setFlowSeq(rs.getString("FLOW_SEQ"));
                    futureHoldLot.setOperationDesc(rs.getString("OPERATION_DESC"));
                    futureHoldLot.setStageId(rs.getString("STAGE_ID"));
                    futureHoldLot.setProcessLocation(rs.getString("PROCESS_LOCATION"));
                    futureHoldLot.setHoldType(rs.getString("HOLD_TYPE"));
                    futureHoldLot.setHoldGroup(rs.getString("HOLD_GROUP"));
                    futureHoldLot.setHoldCode(rs.getString("HOLD_CODE"));
                    futureHoldLot.setHoldReason(rs.getString("HOLD_REASON"));
                    futureHoldLot.setHoldComment(rs.getString("HOLD_COMMENT"));
                    futureHoldLot.setHoldCategory(rs.getString("HOLD_CATEGORY"));
                    futureHoldLot.setHoldQty(rs.getLong("HOLD_QTY"));
                    futureHoldLot.setResponsibility(rs.getString("RESPONSIBILITY"));
                    futureHoldLot.setCreateUserRrn(rs.getLong("CREATE_USER_RRN"));
                    futureHoldLot.setCreateTime(rs.getTimestamp("CREATE_TIME"));
                    futureHoldLot.setUpdateUserRrn(rs.getLong("UPDATE_USER_RRN"));
                    futureHoldLot.setUpdateTime(rs.getTimestamp("UPDATE_TIME"));
                    futureHoldLot.setAttributeData1(rs.getString("ATTRIBUTE_DATA1"));
                    futureHoldLot.setAttributeData2(rs.getString("ATTRIBUTE_DATA2"));
                    return futureHoldLot;
                }
            });
        }

        @Override
        public void insertFutureHoldLot(FutureHoldLot futureHoldLot) {
            Long futureHoldSysRrn = futureHoldLot.getFutureHoldSysRrn();
            Long lotRrn = futureHoldLot.getLotRrn();
            Long stepSequence = futureHoldLot.getStepSequence();
            Long jobRrn = futureHoldLot.getJobRrn();
            Long productRrn = futureHoldLot.getProductRrn();
            Long productVersion = futureHoldLot.getProductVersion();
            Long processRrn = futureHoldLot.getProcessRrn();
            Long processVersion = futureHoldLot.getProcessVersion();
            Long routeRrn = futureHoldLot.getRouteRrn();
            String routeSeq = futureHoldLot.getRouteSeq();
            Long operationRrn = futureHoldLot.getOperationRrn();
            String operationSeq = futureHoldLot.getOperationSeq();
            String flowSeq = futureHoldLot.getFlowSeq();
            String operationDesc = futureHoldLot.getOperationDesc();
            String stageId = futureHoldLot.getStageId();
            String processLocation = futureHoldLot.getProcessLocation();
            String holdType = futureHoldLot.getHoldType();
            String holdCategory = futureHoldLot.getHoldCategory();
            String holdGroup = futureHoldLot.getHoldGroup();
            String holdCode = futureHoldLot.getHoldCode();
            String holdReason = futureHoldLot.getHoldReason();
            String holdComment = futureHoldLot.getHoldComment();
            Long holdQty = futureHoldLot.getHoldQty();
            String responsibility = futureHoldLot.getResponsibility();
            Long createUserRrn = futureHoldLot.getCreateUserRrn();
            Timestamp createTime = (Timestamp) futureHoldLot.getCreateTime();
            Long updateUserRrn = futureHoldLot.getUpdateUserRrn();
            Timestamp updateTime = (Timestamp) futureHoldLot.getUpdateTime();
            //release时的标识
            String sequenceNumber = futureHoldLot.getAttributeData1();
            //MoveOut的类型：AUTO/MANUAL
            String type = futureHoldLot.getAttributeData2();

            String sql = "INSERT INTO " + DataBaseNames.FUTURE_HOLD_LOT + "(FUTURE_HOLD_SYS_RRN, LOT_RRN,STEP_SEQUENCE,JOB_RRN, PRODUCT_RRN, PRODUCT_VERSION, " +
                    " PROCESS_RRN,PROCESS_VERSION,ROUTE_RRN,ROUTE_SEQ,OPERATION_RRN,OPERATION_SEQ,FLOW_SEQ, " +
                    " OPERATION_DESC,STAGE_ID,PROCESS_LOCATION,HOLD_TYPE,HOLD_CATEGORY,HOLD_GROUP,HOLD_CODE," +
                    " HOLD_REASON,HOLD_COMMENT,HOLD_QTY,RESPONSIBILITY,CREATE_USER_RRN,CREATE_TIME,UPDATE_USER_RRN,UPDATE_TIME,ATTRIBUTE_DATA1,ATTRIBUTE_DATA2) " +
                    " VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ";

            Object[] obj ={futureHoldSysRrn,lotRrn,stepSequence,jobRrn,productRrn,productVersion,processRrn,processVersion,routeRrn,routeSeq,operationRrn,operationSeq,flowSeq,
                           operationDesc,stageId,processLocation,holdType,holdCategory,holdGroup,holdCode,holdReason,holdComment,holdQty,responsibility,createUserRrn,createTime,
                           updateUserRrn,updateTime,sequenceNumber,type};
            jdbcTemplate.update(sql,obj);
        }

        @Override
        public void deleteFutureHoldLot(Long futureHoldSysRrn, Long lotRrn) {
            String sql = "DELETE FROM "+DataBaseNames.FUTURE_HOLD_LOT+" WHERE FUTURE_HOLD_SYS_RRN = ? AND LOT_RRN = ? ";
            jdbcTemplate.update(sql,new Object[]{futureHoldSysRrn,lotRrn});
        }

        @Override
        public void insertFutureHoldLotH(FutureHoldLotHistory futureHoldLotHistory) {
            Long transRrn = futureHoldLotHistory.getTransRrn();
            String transId = futureHoldLotHistory.getTransId();
            Long futureHoldSysRrn = futureHoldLotHistory.getFutureHoldSysRrn();
            Long lotRrn = futureHoldLotHistory.getLotRrn();
            Long jobRrn = futureHoldLotHistory.getJobRrn();
            Long productRrn = futureHoldLotHistory.getProductRrn();
            Long productVersion = futureHoldLotHistory.getProcessVersion();
            Long processRrn = futureHoldLotHistory.getProcessRrn();
            Long processVersion = futureHoldLotHistory.getProcessVersion();
            Long routeRrn = futureHoldLotHistory.getRouteRrn();
            String routeSeq = futureHoldLotHistory.getRouteSeq();
            Long operationRrn = futureHoldLotHistory.getOperationRrn();
            String operationSeq = futureHoldLotHistory.getOperationSeq();
            String flowSeq = futureHoldLotHistory.getFlowSeq();
            String operationDesc = futureHoldLotHistory.getOperationDesc();
            String stageId = futureHoldLotHistory.getStageId();
            String processLocation = futureHoldLotHistory.getProcessLocation();
            String holdType = futureHoldLotHistory.getHoldType();
            String holdCategory = futureHoldLotHistory.getHoldCategory();
            String holdGroup = futureHoldLotHistory.getHoldGroup();
            String holdCode = futureHoldLotHistory.getHoldCode();
            String holdReason = futureHoldLotHistory.getHoldReason();
            String holdComment = futureHoldLotHistory.getHoldComment();
            Long holdQty = futureHoldLotHistory.getHoldQty();
            String responsibility = futureHoldLotHistory.getResponsibility();
            String transUserId = futureHoldLotHistory.getTransUserId();
            Timestamp transTime = (Timestamp) futureHoldLotHistory.getTransTime();
            //MoveOut的类型：AUTO/MANUAL
            String type = futureHoldLotHistory.getAttributeData2();

            String sql = "INSERT INTO  "+ DataBaseNames.FUTURE_HOLD_LOT_H + "(TRANS_RRN,TRANS_ID,FUTURE_HOLD_SYS_RRN,LOT_RRN,JOB_RRN,PRODUCT_RRN,PRODUCT_VERSION, " +
                    " PROCESS_RRN,PROCESS_VERSION,ROUTE_RRN,ROUTE_SEQ,OPERATION_RRN,OPERATION_SEQ,FLOW_SEQ, " +
                    " OPERATION_DESC,STAGE_ID,PROCESS_LOCATION,HOLD_TYPE,HOLD_CATEGORY,HOLD_GROUP,HOLD_CODE, " +
                    " HOLD_REASON,HOLD_COMMENT,HOLD_QTY,RESPONSIBILITY,TRANS_USER_ID,TRANS_TIME,ATTRIBUTE_DATA2) " +
                    " VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ";
            Object[] obj ={transRrn,transId,futureHoldSysRrn,lotRrn,jobRrn,productRrn,productVersion,processRrn,processVersion,routeRrn,routeSeq,operationRrn,operationSeq,flowSeq,
                           operationDesc,stageId,processLocation,holdType,holdCategory,holdGroup,holdCode,holdReason,holdComment,holdQty,responsibility,transUserId,transTime,type};
            jdbcTemplate.update(sql,obj);
        }

        @Override
        public List<String> getMaxSeqNumByProduct(Long facilityRrn, Long productRrn, String holdType, String holdCategory) {
            String sql = "select max(attribute_data1) from future_hold where facility_rrn=? and product_rrn=? and hold_type=? and hold_category=?";
            return jdbcTemplate.query(sql,new Object[]{facilityRrn,productRrn,holdType,holdCategory},String.class);
        }

        @Override
        public List<String> getMaxSeqNumByLot(Long facilityRrn, Long lotRrn, String holdType, String holdCategory) {
            String sql = "select max(attribute_data1) from future_hold where facility_rrn=? and lot_rrn=? and hold_type=? and hold_category=?";
            return jdbcTemplate.query(sql,new Object[]{facilityRrn,lotRrn,holdType,holdCategory},String.class);
        }
    }