# CheckListDaoImpl.java

    package com.mycim.server.pms.dao.impl;

    import com.fa.sesa.threadlocal.LocalContext;
    import com.mycim.framework.jdbc.JdbcTemplate;
    import com.mycim.server.pms.dao.CheckListDao;
    import com.mycim.valueobject.bas.TransactionLog;
    import com.mycim.valueobject.consts.DataBaseNames;
    import com.mycim.valueobject.ems.Checklist;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.jdbc.core.RowMapper;
    import org.springframework.stereotype.Repository;

    import java.sql.ResultSet;
    import java.sql.SQLException;

    /**
     * CheckList DaoImpl
     *
     * @author pinyan.song
     * @version 6.0.0
     * @date 2019-11-5
     **/
    @Repository
    public class CheckListDaoImpl implements CheckListDao {
        @Autowired
        private JdbcTemplate jdbcTemplate;

        @Override
        public Checklist getChecklist(Checklist checklist) {
            String sql = "SELECT CHECKLIST_RRN, START_EVENT_RRN, END_EVENT_RRN " + " FROM " + DataBaseNames.CHECKLIST +
                    " WHERE  CHECKLIST_RRN = " + checklist.getInstanceRrn();

            Checklist data = jdbcTemplate.queryForObjectWithNull(sql, new RowMapper<Checklist>() {
                @Override
                public Checklist mapRow(ResultSet rs, int rowNum) throws SQLException {
                    Checklist c = new Checklist();
                    c.setStartEventRrn(rs.getLong("START_EVENT_RRN"));
                    c.setEndEventRrn(rs.getLong("END_EVENT_RRN"));
                    return c;
                }
            });

            checklist.setStartEventRrn(data.getStartEventRrn());
            checklist.setEndEventRrn(data.getEndEventRrn());
            return checklist;
        }

        @Override
        public void insertCheckList(Checklist checkList) {
            String sql = " INSERT INTO " + DataBaseNames.CHECKLIST + "(CHECKLIST_RRN, START_EVENT_RRN, END_EVENT_RRN," +
                    "SYS_RRN,CHECKLIST_ID,DESCRIPTION,FACILITY_RRN,OBJ_SPACE," + "OBJ_TYPE,OBJ_SUBTYPE,OBJ_STATUS," +
                    "CREATE_TIME,UPDATE_TIME," + "CREATE_USER_RRN,UPDATE_USER_RRN,LOCK_VERSION ) VALUES (" + "?,?,?,?,?," +
                    "?,?,?,?,?," + "?,?,?,?,?,?)";
            Object[] args = new Object[]{checkList.getInstanceRrn(), checkList.getStartEventRrn(),
                    checkList.getEndEventRrn(), checkList.getInstanceRrn(), checkList.getInstanceId(),
                    checkList.getInstanceDesc(), LocalContext.getFacilityRrn(), checkList.getNamedSpace(),
                    checkList.getObjectType(), checkList.getObjectSubtype(), checkList.getInstanceStatus(),
                    checkList.getCreatedTimestamp(), checkList.getCreatedTimestamp(), LocalContext.getUserRrn(),
                    LocalContext.getUserRrn(), checkList.getLockVersion()};
            jdbcTemplate.update(sql, args);
        }

        @Override
        public void deleteCheckList(Checklist checkList) {

            String sql = "DELETE FROM " + DataBaseNames.CHECKLIST + " WHERE CHECKLIST_RRN=" + checkList.getInstanceRrn();
            jdbcTemplate.execute(sql);
        }

        @Override
        public void updateCheckList(Checklist checkList) {
            String sql = "UPDATE  " + DataBaseNames.CHECKLIST + " SET START_EVENT_RRN = ?,END_EVENT_RRN = ?,OBJ_SUBTYPE =" +
                    " ?," + " DESCRIPTION = ?,UPDATE_TIME = ?,UPDATE_USER_RRN = ? " + " WHERE CHECKLIST_RRN = ?";

            Object[] args = new Object[]{checkList.getStartEventRrn(), checkList.getEndEventRrn(),
                    checkList.getObjectSubtype(), checkList.getInstanceDesc(), checkList.getLastUpdateTimestamp(),
                    LocalContext.getUserRrn(), checkList.getInstanceRrn()};
            jdbcTemplate.update(sql, args);
        }

        @Override
        public void insertCheckListHis(Long checkListRrn, TransactionLog transactionLog) {
            String sql = "INSERT INTO " + DataBaseNames.CHECKLIST_H + " (TRANS_RRN,TRANS_ID,SYS_RRN,CHECKLIST_ID," +
                    "FACILITY_RRN," + " DESCRIPTION,OBJ_SPACE,OBJ_TYPE,OBJ_SUBTYPE,OBJ_STATUS," + " START_EVENT_RRN," +
                    "END_EVENT_RRN,ATTRIBUTE_DATA1," + " ATTRIBUTE_DATA2,ATTRIBUTE_DATA3,TRANS_USER_RRN,TRANS_TIME)" + " " +
                    "SELECT " + " ?,?,SYS_RRN,CHECKLIST_ID,FACILITY_RRN," + " DESCRIPTION,OBJ_SPACE,OBJ_TYPE,OBJ_SUBTYPE," +
                    "OBJ_STATUS," + " START_EVENT_RRN,END_EVENT_RRN,ATTRIBUTE_DATA1," + " ATTRIBUTE_DATA2," +
                    "ATTRIBUTE_DATA3,?,? " + " FROM " + DataBaseNames.CHECKLIST + " WHERE CHECKLIST_RRN = ?";
            Object[] args = new Object[]{transactionLog.getTransRrn(), transactionLog.getTransId(),
                    LocalContext.getUserRrn(), transactionLog.getTransStartTimestamp(), checkListRrn};
            jdbcTemplate.update(sql, args);
        }

    }