package com.huimv.sj.dao; import java.sql.SQLException; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; import org.springframework.orm.ibatis.SqlMapClientCallback; import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport; import org.springframework.util.StringUtils; import com.huimv.busi.base.dto.ResponseBean; import com.huimv.busi.da.dto.DaSlxxDTO; import com.huimv.busi.xt.constant.XtSqlMapConstant; import com.huimv.busi.xt.utils.DynamicDataSourceHolder; import com.huimv.sj.dataobject.SjSscssj; import com.huimv.sj.dataobject.SjSscssjExample; import com.huimv.web.base.PageBean; import com.ibatis.sqlmap.client.SqlMapExecutor; public class SjSscssjDAOImpl extends SqlMapClientDaoSupport implements SjSscssjDAO { /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table sj_sscssj * * @ibatorgenerated Thu Jun 19 15:59:45 CST 2014 */ public SjSscssjDAOImpl() { super(); } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table sj_sscssj * * @ibatorgenerated Thu Jun 19 15:59:45 CST 2014 */ public int countByExample(SjSscssjExample example) { Integer count = (Integer) getSqlMapClientTemplate().queryForObject("sj_sscssj.ibatorgenerated_countByExample", example); return count; } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table sj_sscssj * * @ibatorgenerated Thu Jun 19 15:59:45 CST 2014 */ public int deleteByExample(SjSscssjExample example) { int rows = getSqlMapClientTemplate().delete("sj_sscssj.ibatorgenerated_deleteByExample", example); return rows; } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table sj_sscssj * * @ibatorgenerated Thu Jun 19 15:59:45 CST 2014 */ public int deleteByPrimaryKey(Integer id) { SjSscssj key = new SjSscssj(); key.setId(id); int rows = getSqlMapClientTemplate().delete("sj_sscssj.ibatorgenerated_deleteByPrimaryKey", key); return rows; } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table sj_sscssj * * @ibatorgenerated Thu Jun 19 15:59:45 CST 2014 */ public void insert(SjSscssj record) { getSqlMapClientTemplate().insert("sj_sscssj.ibatorgenerated_insert", record); } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table sj_sscssj * * @ibatorgenerated Thu Jun 19 15:59:45 CST 2014 */ public void insertSelective(SjSscssj record) { getSqlMapClientTemplate().insert("sj_sscssj.ibatorgenerated_insertSelective", record); } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table sj_sscssj * * @ibatorgenerated Thu Jun 19 15:59:45 CST 2014 */ @SuppressWarnings("unchecked") public List selectByExample(SjSscssjExample example) { List list = getSqlMapClientTemplate().queryForList("sj_sscssj.ibatorgenerated_selectByExample", example); return list; } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table sj_sscssj * * @ibatorgenerated Thu Jun 19 15:59:45 CST 2014 */ public SjSscssj selectByPrimaryKey(Integer id) { SjSscssj key = new SjSscssj(); key.setId(id); SjSscssj record = (SjSscssj) getSqlMapClientTemplate().queryForObject("sj_sscssj.ibatorgenerated_selectByPrimaryKey", key); return record; } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table sj_sscssj * * @ibatorgenerated Thu Jun 19 15:59:45 CST 2014 */ public int updateByExampleSelective(SjSscssj record, SjSscssjExample example) { UpdateByExampleParms parms = new UpdateByExampleParms(record, example); int rows = getSqlMapClientTemplate().update("sj_sscssj.ibatorgenerated_updateByExampleSelective", parms); return rows; } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table sj_sscssj * * @ibatorgenerated Thu Jun 19 15:59:45 CST 2014 */ public int updateByExample(SjSscssj record, SjSscssjExample example) { UpdateByExampleParms parms = new UpdateByExampleParms(record, example); int rows = getSqlMapClientTemplate().update("sj_sscssj.ibatorgenerated_updateByExample", parms); return rows; } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table sj_sscssj * * @ibatorgenerated Thu Jun 19 15:59:45 CST 2014 */ public int updateByPrimaryKeySelective(SjSscssj record) { int rows = getSqlMapClientTemplate().update("sj_sscssj.ibatorgenerated_updateByPrimaryKeySelective", record); return rows; } /** * This method was generated by Apache iBATIS ibator. * This method corresponds to the database table sj_sscssj * * @ibatorgenerated Thu Jun 19 15:59:45 CST 2014 */ public int updateByPrimaryKey(SjSscssj record) { int rows = getSqlMapClientTemplate().update("sj_sscssj.ibatorgenerated_updateByPrimaryKey", record); return rows; } /** * This class was generated by Apache iBATIS ibator. * This class corresponds to the database table sj_sscssj * * @ibatorgenerated Thu Jun 19 15:59:45 CST 2014 */ private static class UpdateByExampleParms extends SjSscssjExample { private Object record; public UpdateByExampleParms(Object record, SjSscssjExample example) { super(example); this.record = record; } @SuppressWarnings("unused") public Object getRecord() { return record; } } /** * 得到指定条件采食记录的最大时间 */ public Date selectMaxSscssjTimeByParam(Map searchParam) { Date date = (Date) getSqlMapClientTemplate().queryForObject(XtSqlMapConstant.SQLMAP_SELECT_MAX_SSCSSJ_TIME_BY_PARAM, searchParam); return date; } /** * 插入动物访问记录 */ public void insertSscssjByParam(List> paramMapList) { SscssjSqlMapClientCallback sscssjSqlMapClientCallback = new SscssjSqlMapClientCallback(); sscssjSqlMapClientCallback.setParamMapList(paramMapList); getSqlMapClientTemplate().execute(sscssjSqlMapClientCallback); } /** * 插入数据的回调类 */ private class SscssjSqlMapClientCallback implements SqlMapClientCallback { private List> paramMapList; public void setParamMapList(List> paramMapList) { this.paramMapList = paramMapList; } @Override public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException { executor.startBatch(); String dqlq = ""; String jqid = ""; for (Map paramMap : paramMapList) { jqid = (String) paramMap.get("jqid"); dqlq = (String) executor.queryForObject(XtSqlMapConstant.SQLMAP_SELECT_DQLQ_FROM_ZSDA_AND_JQDA_BY_JQID, jqid); if (StringUtils.hasText(dqlq)) { paramMap.put("dqlq", dqlq); executor.insert(XtSqlMapConstant.SQLMAP_INSERT_SSCSSJ_BY_PARAM, paramMap); } } executor.executeBatch(); return null; } } /** * 上料维护 * @param example * @return */ public int countSlwhByExample(SjSscssjExample example) { Integer count = (Integer) getSqlMapClientTemplate().queryForObject("sj_sscssj.ibatorgenerated_countSlwhByExample", example); return count; } /** * 上料维护信息查询 * @param example * @return */ @SuppressWarnings("unchecked") public List selectSlwhByExample(SjSscssjExample example) { List list = getSqlMapClientTemplate().queryForList("sj_sscssj.ibatorgenerated_selectSlwhByExample", example); return list; } /** * 上料信息参数查询 */ @SuppressWarnings("unchecked") public ResponseBean selectDaSlxxByParam(Map paramMap, PageBean pageBean) throws Exception { ResponseBean rb = new ResponseBean(); List daSlxxDTOs = new ArrayList(); int count = (Integer) getSqlMapClientTemplate().queryForObject(XtSqlMapConstant.SQLMAP_COUNT_SLXX_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); } daSlxxDTOs = (List) getSqlMapClientTemplate().queryForList(XtSqlMapConstant.SQLMAP_SELECT_SLXX_BY_PARAM, paramMap); rb.setResult(daSlxxDTOs); rb.setReturnCode(count); return rb; } @Override public void callPrcSlxx(Map searchParam) { // TODO Auto-generated method stub getSqlMapClientTemplate().update(XtSqlMapConstant.SQLMAP_PRC_SLXX, searchParam); } @SuppressWarnings("unchecked") public List selectHkcsCgqidByParam(Map searchParam) { DynamicDataSourceHolder.setRouteKey(""); List list = getSqlMapClientTemplate().queryForList(XtSqlMapConstant.SQLMAP_SELECT_HKCS_CGQID_BY_PARAM, searchParam); return list; } @SuppressWarnings("unchecked") public List selectQccsByParam(Map searchParam) { DynamicDataSourceHolder.setRouteKey(""); List list = getSqlMapClientTemplate().queryForList(XtSqlMapConstant.SQLMAP_SELECT_QCHKCS_BY_PARAM, searchParam); DynamicDataSourceHolder.removeRouteKey(); return list; } @SuppressWarnings("unchecked") public List selectDqcsByParam(Map searchParam) { DynamicDataSourceHolder.setRouteKey(""); List list = getSqlMapClientTemplate().queryForList(XtSqlMapConstant.SQLMAP_SELECT_DQHKCS_BY_PARAM, searchParam); DynamicDataSourceHolder.removeRouteKey(); return list; } }