package com.huimv.xt.dao; 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; 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.XtGydm; import com.huimv.xt.dataobject.XtGydmExample; import com.huimv.xt.dataobject.XtGydmKey; import com.ibatis.sqlmap.client.SqlMapExecutor; public class XtGydmDAOImpl extends SqlMapClientDaoSupport implements XtGydmDAO { /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table xt_gydm * * @ibatorgenerated Fri May 30 10:23:18 CST 2014 */ public XtGydmDAOImpl() { super(); } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table xt_gydm * * @ibatorgenerated Fri May 30 10:23:18 CST 2014 */ public int countByExample(XtGydmExample example) { Integer count = (Integer) getSqlMapClientTemplate().queryForObject("xt_gydm.ibatorgenerated_countByExample", example); return count; } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table xt_gydm * * @ibatorgenerated Fri May 30 10:23:18 CST 2014 */ public int deleteByExample(XtGydmExample example) { int rows = getSqlMapClientTemplate().delete("xt_gydm.ibatorgenerated_deleteByExample", example); return rows; } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table xt_gydm * * @ibatorgenerated Fri May 30 10:23:18 CST 2014 */ public int deleteByPrimaryKey(XtGydmKey key) { int rows = getSqlMapClientTemplate().delete("xt_gydm.ibatorgenerated_deleteByPrimaryKey", key); return rows; } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table xt_gydm * * @ibatorgenerated Fri May 30 10:23:18 CST 2014 */ public void insert(XtGydm record) { getSqlMapClientTemplate().insert("xt_gydm.ibatorgenerated_insert", record); } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table xt_gydm * * @ibatorgenerated Fri May 30 10:23:18 CST 2014 */ public void insertSelective(XtGydm record) { getSqlMapClientTemplate().insert("xt_gydm.ibatorgenerated_insertSelective", record); } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table xt_gydm * * @ibatorgenerated Fri May 30 10:23:18 CST 2014 */ @SuppressWarnings("unchecked") public List selectByExample(XtGydmExample example) { List list = getSqlMapClientTemplate().queryForList("xt_gydm.ibatorgenerated_selectByExample", example); return list; } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table xt_gydm * * @ibatorgenerated Fri May 30 10:23:18 CST 2014 */ public XtGydm selectByPrimaryKey(XtGydmKey key) { XtGydm record = (XtGydm) getSqlMapClientTemplate().queryForObject("xt_gydm.ibatorgenerated_selectByPrimaryKey", key); return record; } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table xt_gydm * * @ibatorgenerated Fri May 30 10:23:18 CST 2014 */ public int updateByExampleSelective(XtGydm record, XtGydmExample example) { UpdateByExampleParms parms = new UpdateByExampleParms(record, example); int rows = getSqlMapClientTemplate().update("xt_gydm.ibatorgenerated_updateByExampleSelective", parms); return rows; } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table xt_gydm * * @ibatorgenerated Fri May 30 10:23:18 CST 2014 */ public int updateByExample(XtGydm record, XtGydmExample example) { UpdateByExampleParms parms = new UpdateByExampleParms(record, example); int rows = getSqlMapClientTemplate().update("xt_gydm.ibatorgenerated_updateByExample", parms); return rows; } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table xt_gydm * * @ibatorgenerated Fri May 30 10:23:18 CST 2014 */ public int updateByPrimaryKeySelective(XtGydm record) { int rows = getSqlMapClientTemplate().update("xt_gydm.ibatorgenerated_updateByPrimaryKeySelective", record); return rows; } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table xt_gydm * * @ibatorgenerated Fri May 30 10:23:18 CST 2014 */ public int updateByPrimaryKey(XtGydm record) { int rows = getSqlMapClientTemplate().update("xt_gydm.ibatorgenerated_updateByPrimaryKey", record); return rows; } /** * This class was generated by Apache iBATIS ibator. * This class corresponds to the database table xt_gydm * * @ibatorgenerated Fri May 30 10:23:18 CST 2014 */ private static class UpdateByExampleParms extends XtGydmExample { private Object record; public UpdateByExampleParms(Object record, XtGydmExample example) { super(example); this.record = record; } public Object getRecord() { return record; } } @SuppressWarnings("unchecked") public List selectBydmmc(XtGydm gydm) { List list = (List) getSqlMapClientTemplate() .queryForList("xt_gydm.abatorgenerated_selectBydmmc", gydm); return list; } /** * 根据参数搜索XtGydm * * @return * @throws Exception */ @SuppressWarnings("unchecked") public ResponseBean selectXtGydmByParam(Map paramMap, PageBean pageBean) throws Exception { ResponseBean rb = new ResponseBean(); List xtGydms = new ArrayList(); int count = (Integer) getSqlMapClientTemplate().queryForObject(XtSqlMapConstant.SQLMAP_COUNT_GYDM_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); } xtGydms = (List) getSqlMapClientTemplate().queryForList(XtSqlMapConstant.SQLMAP_SELECT_GYDM_BY_PARAM, paramMap); rb.setResult(xtGydms); rb.setReturnCode(count); return rb; } /** * 搜索指定条件的XtGydm条数 */ public int countGydmByParam(Map paramMap) { return (Integer) getSqlMapClientTemplate().queryForObject(XtSqlMapConstant.SQLMAP_COUNT_GYDM_BY_PARAM, paramMap); } /** * 插入XtGydm并更新同类别下XtGydm.SXH * @param xtGydm * 需要插入的XtGydm */ public void insertXtGydm(final XtGydm xtGydm) { XtGydmExample xtGydmEx = new XtGydmExample(); xtGydmEx.createCriteria().andZfbzEqualTo(XtAppConstant.ZFBZ_VALID).andLbidEqualTo(xtGydm.getLbid()); final List xtGydms = selectByExample(xtGydmEx); getSqlMapClientTemplate().execute(new SqlMapClientCallback() { @Override public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException { executor.startBatch(); for (XtGydm gydm : xtGydms) { if(gydm.getSxh() >= xtGydm.getSxh()) { gydm.setSxh(gydm.getSxh() + 1); executor.update("xt_gydm.ibatorgenerated_updateByPrimaryKeySelective", gydm); } } executor.insert("xt_gydm.ibatorgenerated_insertSelective", xtGydm); executor.executeBatch(); return null; } }); } /** * 修改XtGydm,同时更新同lbid下的XtGydm.SXH * @param yXtGydm * 原XtGydm * @param xXtGydm * 新XtGydm */ public void updateXtGydm(final XtGydm yXtGydm, final XtGydm xXtGydm) { XtGydmExample xtGydmEx = new XtGydmExample(); xtGydmEx.createCriteria().andZfbzEqualTo(XtAppConstant.ZFBZ_VALID).andLbidEqualTo(xXtGydm.getLbid()); final List xtGydms = selectByExample(xtGydmEx); getSqlMapClientTemplate().execute(new SqlMapClientCallback() { @Override public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException { executor.startBatch(); if( xXtGydm.getSxh() > yXtGydm.getSxh() ) { for (XtGydm gydm : xtGydms) { if(gydm.getSxh() > yXtGydm.getSxh() && gydm.getSxh() <= xXtGydm.getSxh()) { gydm.setSxh(gydm.getSxh() - 1); executor.update("xt_gydm.ibatorgenerated_updateByPrimaryKeySelective", gydm); } } updateByPrimaryKeySelective(xXtGydm); } else if( xXtGydm.getSxh() < yXtGydm.getSxh() ) { for (XtGydm gydm : xtGydms) { if(gydm.getSxh() < yXtGydm.getSxh() && gydm.getSxh() >= xXtGydm.getSxh()) { gydm.setSxh(gydm.getSxh() + 1); executor.update("xt_gydm.ibatorgenerated_updateByPrimaryKeySelective", gydm); } } executor.update("xt_gydm.ibatorgenerated_updateByPrimaryKeySelective", xXtGydm); } else { executor.update("xt_gydm.ibatorgenerated_updateByPrimaryKeySelective", xXtGydm); } executor.executeBatch(); return null; } }); } /** * 置废XtGydm,同时更新同lbid的XtGydm.SXH * @param xtGydm * 需要置废的XtGydm */ public void disableXtGydm(final XtGydm xtGydm) { XtGydmExample xtGydmEx = new XtGydmExample(); xtGydmEx.createCriteria().andZfbzEqualTo(XtAppConstant.ZFBZ_VALID).andLbidEqualTo(xtGydm.getLbid()); final List xtGydms = selectByExample(xtGydmEx); getSqlMapClientTemplate().execute(new SqlMapClientCallback() { @Override public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException { executor.startBatch(); for (XtGydm gydm : xtGydms) { if(gydm.getSxh() >= xtGydm.getSxh()) { gydm.setSxh(gydm.getSxh() - 1); executor.update("xt_gydm.ibatorgenerated_updateByPrimaryKeySelective", gydm); } } executor.update("xt_gydm.ibatorgenerated_updateByPrimaryKeySelective", xtGydm); executor.executeBatch(); return null; } }); } /** * 返回指定LBID中最大的DMID */ public int selectMaxDmidByLbid(Integer lbid) { Integer count = (Integer) getSqlMapClientTemplate().queryForObject(XtSqlMapConstant.SQLMAP_SELECT_MAX_GYDM_DMID_BY_LBID, lbid); return count == null ? 0 : count; } /** * 根据lbmc获取gydm */ @SuppressWarnings("unchecked") public List selectGydmByLbmc(String lbmc) { //TODO ZJ 修改 SQLMAP_SELECT_GYDM_BY_LBMC_NOLIKE 名称 List list = getSqlMapClientTemplate().queryForList(XtSqlMapConstant.SQLMAP_SELECT_GYDM_BY_LBMC_NOLIKE, lbmc); return list; } }