package com.huimv.xt.dao; import com.huimv.busi.base.dto.ResponseBean; import com.huimv.busi.xt.constant.XtAppConstant; import com.huimv.busi.xt.constant.XtSqlMapConstant; import com.huimv.web.base.PageBean; import com.huimv.xt.dataobject.XtDmlb; import com.huimv.xt.dataobject.XtDmlbExample; import com.ibatis.sqlmap.client.SqlMapExecutor; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.springframework.orm.ibatis.SqlMapClientCallback; import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport; public class XtDmlbDAOImpl extends SqlMapClientDaoSupport implements XtDmlbDAO { /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table xt_dmlb * * @ibatorgenerated Fri May 30 10:23:18 CST 2014 */ public XtDmlbDAOImpl() { super(); } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table xt_dmlb * * @ibatorgenerated Fri May 30 10:23:18 CST 2014 */ public int countByExample(XtDmlbExample example) { Integer count = (Integer) getSqlMapClientTemplate().queryForObject("xt_dmlb.ibatorgenerated_countByExample", example); return count; } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table xt_dmlb * * @ibatorgenerated Fri May 30 10:23:18 CST 2014 */ public int deleteByExample(XtDmlbExample example) { int rows = getSqlMapClientTemplate().delete("xt_dmlb.ibatorgenerated_deleteByExample", example); return rows; } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table xt_dmlb * * @ibatorgenerated Fri May 30 10:23:18 CST 2014 */ public int deleteByPrimaryKey(Integer lbid) { XtDmlb key = new XtDmlb(); key.setLbid(lbid); int rows = getSqlMapClientTemplate().delete("xt_dmlb.ibatorgenerated_deleteByPrimaryKey", key); return rows; } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table xt_dmlb * * @ibatorgenerated Fri May 30 10:23:18 CST 2014 */ public void insert(XtDmlb record) { getSqlMapClientTemplate().insert("xt_dmlb.ibatorgenerated_insert", record); } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table xt_dmlb * * @ibatorgenerated Fri May 30 10:23:18 CST 2014 */ public void insertSelective(XtDmlb record) { getSqlMapClientTemplate().insert("xt_dmlb.ibatorgenerated_insertSelective", record); } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table xt_dmlb * * @ibatorgenerated Fri May 30 10:23:18 CST 2014 */ @SuppressWarnings("unchecked") public List selectByExample(XtDmlbExample example) { List list = getSqlMapClientTemplate().queryForList("xt_dmlb.ibatorgenerated_selectByExample", example); return list; } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table xt_dmlb * * @ibatorgenerated Fri May 30 10:23:18 CST 2014 */ public XtDmlb selectByPrimaryKey(Integer lbid) { XtDmlb key = new XtDmlb(); key.setLbid(lbid); XtDmlb record = (XtDmlb) getSqlMapClientTemplate().queryForObject("xt_dmlb.ibatorgenerated_selectByPrimaryKey", key); return record; } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table xt_dmlb * * @ibatorgenerated Fri May 30 10:23:18 CST 2014 */ public int updateByExampleSelective(XtDmlb record, XtDmlbExample example) { UpdateByExampleParms parms = new UpdateByExampleParms(record, example); int rows = getSqlMapClientTemplate().update("xt_dmlb.ibatorgenerated_updateByExampleSelective", parms); return rows; } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table xt_dmlb * * @ibatorgenerated Fri May 30 10:23:18 CST 2014 */ public int updateByExample(XtDmlb record, XtDmlbExample example) { UpdateByExampleParms parms = new UpdateByExampleParms(record, example); int rows = getSqlMapClientTemplate().update("xt_dmlb.ibatorgenerated_updateByExample", parms); return rows; } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table xt_dmlb * * @ibatorgenerated Fri May 30 10:23:18 CST 2014 */ public int updateByPrimaryKeySelective(XtDmlb record) { int rows = getSqlMapClientTemplate().update("xt_dmlb.ibatorgenerated_updateByPrimaryKeySelective", record); return rows; } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table xt_dmlb * * @ibatorgenerated Fri May 30 10:23:18 CST 2014 */ public int updateByPrimaryKey(XtDmlb record) { int rows = getSqlMapClientTemplate().update("xt_dmlb.ibatorgenerated_updateByPrimaryKey", record); return rows; } /** * This class was generated by Apache iBATIS ibator. * This class corresponds to the database table xt_dmlb * * @ibatorgenerated Fri May 30 10:23:18 CST 2014 */ private static class UpdateByExampleParms extends XtDmlbExample { private Object record; public UpdateByExampleParms(Object record, XtDmlbExample example) { super(example); this.record = record; } public Object getRecord() { return record; } } /** * 根据参数搜索XtDmlb * * @return * @throws Exception */ @SuppressWarnings("unchecked") public ResponseBean selectXtDmlbByParam(Map paramMap, PageBean pageBean) throws Exception { ResponseBean rb = new ResponseBean(); List xtDmlbs = new ArrayList(); int count = (Integer) getSqlMapClientTemplate().queryForObject(XtSqlMapConstant.SQLMAP_COUNT_DMLB_BY_PARAM, paramMap); if(null != pageBean) { int startRecord = pageBean.getCurrentPageFirstRecord(); int endRecord = pageBean.getPageSize(); paramMap.put("startRecord", startRecord); paramMap.put("endRecord", endRecord); pageBean.setRecordCount(count); } else { paramMap.put("startRecord", 0); paramMap.put("endRecord", count); } xtDmlbs = (List) getSqlMapClientTemplate().queryForList(XtSqlMapConstant.SQLMAP_SELECT_DMLB_BY_PARAM, paramMap); rb.setResult(xtDmlbs); rb.setReturnCode(count); return rb; } /** * 找到最大的sxh */ public Integer selectMaxSxh() { return (Integer) getSqlMapClientTemplate().queryForObject(XtSqlMapConstant.SQLMAP_COUNT_DMLB_BY_PARAM, null); } /** * 插入XtDmlb,同时更新对应XtDmlb的sxh字段 * @param XtDmlb * 需要插入的XtDmlb */ public void insertXtDmlb(final XtDmlb xtDmlb) { XtDmlbExample dmlbEx = new XtDmlbExample(); dmlbEx.createCriteria().andZfbzEqualTo(XtAppConstant.ZFBZ_VALID); final List xtDmlbs = selectByExample(dmlbEx); getSqlMapClientTemplate().execute(new SqlMapClientCallback() { @Override public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException { executor.startBatch(); for (XtDmlb yXtDmlb : xtDmlbs) { if(yXtDmlb.getSxh() >= xtDmlb.getSxh()) { yXtDmlb.setSxh(yXtDmlb.getSxh() + 1); executor.update("xt_dmlb.ibatorgenerated_updateByPrimaryKeySelective", yXtDmlb); } } executor.insert("xt_dmlb.ibatorgenerated_insertSelective", xtDmlb); executor.executeBatch(); return null; } }); } /** * 更新XtDmlb,同时更新对应XtDmlb的sxh字段 * @param yXtDmlb * 原XtDmlb * @param xXtDmlb * 新XtDmlb */ public void updateXtDmlb(final XtDmlb yXtDmlb, final XtDmlb xXtDmlb) { XtDmlbExample dmlbEx = new XtDmlbExample(); dmlbEx.createCriteria().andZfbzEqualTo(XtAppConstant.ZFBZ_VALID); final List xtDmlbs = selectByExample(dmlbEx); getSqlMapClientTemplate().execute(new SqlMapClientCallback() { @Override public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException { executor.startBatch(); if(xXtDmlb.getSxh() > yXtDmlb.getSxh()) { //顺序号增加 for (XtDmlb xtDmlb : xtDmlbs) { if(xtDmlb.getSxh() > yXtDmlb.getSxh() && xtDmlb.getSxh() <= xXtDmlb.getSxh()) { xtDmlb.setSxh(xtDmlb.getSxh() - 1); executor.update("xt_dmlb.ibatorgenerated_updateByPrimaryKeySelective", xtDmlb); } } updateByPrimaryKeySelective(xXtDmlb); } else if (xXtDmlb.getSxh() < yXtDmlb.getSxh()) { //顺序号减小 for (XtDmlb xtDmlb : xtDmlbs) { if(xtDmlb.getSxh() < yXtDmlb.getSxh() && xtDmlb.getSxh() >= xXtDmlb.getSxh()) { xtDmlb.setSxh(xtDmlb.getSxh() + 1); executor.update("xt_dmlb.ibatorgenerated_updateByPrimaryKeySelective", xtDmlb); } } executor.update("xt_dmlb.ibatorgenerated_updateByPrimaryKeySelective", xXtDmlb); } executor.executeBatch(); return null; } }); } /** * 置废XtDmlb,同时更新对应XtDmlb的sxh字段 * @param xtDmlb * 需要置废的XtDmlb */ public void disableXtDmlb(final XtDmlb xtDmlb) { XtDmlbExample dmlbEx = new XtDmlbExample(); dmlbEx.createCriteria().andZfbzEqualTo(XtAppConstant.ZFBZ_VALID); final List xtDmlbs = selectByExample(dmlbEx); getSqlMapClientTemplate().execute(new SqlMapClientCallback() { @Override public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException { executor.startBatch(); for (XtDmlb dmlb : xtDmlbs) { if(dmlb.getSxh() > xtDmlb.getSxh()) { dmlb.setSxh(dmlb.getSxh() - 1); executor.update("xt_dmlb.ibatorgenerated_updateByPrimaryKeySelective", dmlb); } } executor.update("xt_dmlb.ibatorgenerated_updateByPrimaryKeySelective", xtDmlb); executor.executeBatch(); return null; } }); } }