XtDmlbDAOImpl.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. package com.huimv.xt.dao;
  2. import com.huimv.busi.base.dto.ResponseBean;
  3. import com.huimv.busi.xt.constant.XtAppConstant;
  4. import com.huimv.busi.xt.constant.XtSqlMapConstant;
  5. import com.huimv.web.base.PageBean;
  6. import com.huimv.xt.dataobject.XtDmlb;
  7. import com.huimv.xt.dataobject.XtDmlbExample;
  8. import com.ibatis.sqlmap.client.SqlMapExecutor;
  9. import java.sql.SQLException;
  10. import java.util.ArrayList;
  11. import java.util.List;
  12. import java.util.Map;
  13. import org.springframework.orm.ibatis.SqlMapClientCallback;
  14. import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
  15. public class XtDmlbDAOImpl extends SqlMapClientDaoSupport implements XtDmlbDAO {
  16. /**
  17. * This method was generated by Apache iBATIS ibator.
  18. * This method corresponds to the database table xt_dmlb
  19. *
  20. * @ibatorgenerated Fri May 30 10:23:18 CST 2014
  21. */
  22. public XtDmlbDAOImpl() {
  23. super();
  24. }
  25. /**
  26. * This method was generated by Apache iBATIS ibator.
  27. * This method corresponds to the database table xt_dmlb
  28. *
  29. * @ibatorgenerated Fri May 30 10:23:18 CST 2014
  30. */
  31. public int countByExample(XtDmlbExample example) {
  32. Integer count = (Integer) getSqlMapClientTemplate().queryForObject("xt_dmlb.ibatorgenerated_countByExample", example);
  33. return count;
  34. }
  35. /**
  36. * This method was generated by Apache iBATIS ibator.
  37. * This method corresponds to the database table xt_dmlb
  38. *
  39. * @ibatorgenerated Fri May 30 10:23:18 CST 2014
  40. */
  41. public int deleteByExample(XtDmlbExample example) {
  42. int rows = getSqlMapClientTemplate().delete("xt_dmlb.ibatorgenerated_deleteByExample", example);
  43. return rows;
  44. }
  45. /**
  46. * This method was generated by Apache iBATIS ibator.
  47. * This method corresponds to the database table xt_dmlb
  48. *
  49. * @ibatorgenerated Fri May 30 10:23:18 CST 2014
  50. */
  51. public int deleteByPrimaryKey(Integer lbid) {
  52. XtDmlb key = new XtDmlb();
  53. key.setLbid(lbid);
  54. int rows = getSqlMapClientTemplate().delete("xt_dmlb.ibatorgenerated_deleteByPrimaryKey", key);
  55. return rows;
  56. }
  57. /**
  58. * This method was generated by Apache iBATIS ibator.
  59. * This method corresponds to the database table xt_dmlb
  60. *
  61. * @ibatorgenerated Fri May 30 10:23:18 CST 2014
  62. */
  63. public void insert(XtDmlb record) {
  64. getSqlMapClientTemplate().insert("xt_dmlb.ibatorgenerated_insert", record);
  65. }
  66. /**
  67. * This method was generated by Apache iBATIS ibator.
  68. * This method corresponds to the database table xt_dmlb
  69. *
  70. * @ibatorgenerated Fri May 30 10:23:18 CST 2014
  71. */
  72. public void insertSelective(XtDmlb record) {
  73. getSqlMapClientTemplate().insert("xt_dmlb.ibatorgenerated_insertSelective", record);
  74. }
  75. /**
  76. * This method was generated by Apache iBATIS ibator.
  77. * This method corresponds to the database table xt_dmlb
  78. *
  79. * @ibatorgenerated Fri May 30 10:23:18 CST 2014
  80. */
  81. @SuppressWarnings("unchecked")
  82. public List<XtDmlb> selectByExample(XtDmlbExample example) {
  83. List<XtDmlb> list = getSqlMapClientTemplate().queryForList("xt_dmlb.ibatorgenerated_selectByExample", example);
  84. return list;
  85. }
  86. /**
  87. * This method was generated by Apache iBATIS ibator.
  88. * This method corresponds to the database table xt_dmlb
  89. *
  90. * @ibatorgenerated Fri May 30 10:23:18 CST 2014
  91. */
  92. public XtDmlb selectByPrimaryKey(Integer lbid) {
  93. XtDmlb key = new XtDmlb();
  94. key.setLbid(lbid);
  95. XtDmlb record = (XtDmlb) getSqlMapClientTemplate().queryForObject("xt_dmlb.ibatorgenerated_selectByPrimaryKey", key);
  96. return record;
  97. }
  98. /**
  99. * This method was generated by Apache iBATIS ibator.
  100. * This method corresponds to the database table xt_dmlb
  101. *
  102. * @ibatorgenerated Fri May 30 10:23:18 CST 2014
  103. */
  104. public int updateByExampleSelective(XtDmlb record, XtDmlbExample example) {
  105. UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
  106. int rows = getSqlMapClientTemplate().update("xt_dmlb.ibatorgenerated_updateByExampleSelective", parms);
  107. return rows;
  108. }
  109. /**
  110. * This method was generated by Apache iBATIS ibator.
  111. * This method corresponds to the database table xt_dmlb
  112. *
  113. * @ibatorgenerated Fri May 30 10:23:18 CST 2014
  114. */
  115. public int updateByExample(XtDmlb record, XtDmlbExample example) {
  116. UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
  117. int rows = getSqlMapClientTemplate().update("xt_dmlb.ibatorgenerated_updateByExample", parms);
  118. return rows;
  119. }
  120. /**
  121. * This method was generated by Apache iBATIS ibator.
  122. * This method corresponds to the database table xt_dmlb
  123. *
  124. * @ibatorgenerated Fri May 30 10:23:18 CST 2014
  125. */
  126. public int updateByPrimaryKeySelective(XtDmlb record) {
  127. int rows = getSqlMapClientTemplate().update("xt_dmlb.ibatorgenerated_updateByPrimaryKeySelective", record);
  128. return rows;
  129. }
  130. /**
  131. * This method was generated by Apache iBATIS ibator.
  132. * This method corresponds to the database table xt_dmlb
  133. *
  134. * @ibatorgenerated Fri May 30 10:23:18 CST 2014
  135. */
  136. public int updateByPrimaryKey(XtDmlb record) {
  137. int rows = getSqlMapClientTemplate().update("xt_dmlb.ibatorgenerated_updateByPrimaryKey", record);
  138. return rows;
  139. }
  140. /**
  141. * This class was generated by Apache iBATIS ibator.
  142. * This class corresponds to the database table xt_dmlb
  143. *
  144. * @ibatorgenerated Fri May 30 10:23:18 CST 2014
  145. */
  146. private static class UpdateByExampleParms extends XtDmlbExample {
  147. private Object record;
  148. public UpdateByExampleParms(Object record, XtDmlbExample example) {
  149. super(example);
  150. this.record = record;
  151. }
  152. public Object getRecord() {
  153. return record;
  154. }
  155. }
  156. /**
  157. * 根据参数搜索XtDmlb
  158. *
  159. * @return
  160. * @throws Exception
  161. */
  162. @SuppressWarnings("unchecked")
  163. public ResponseBean selectXtDmlbByParam(Map<String, Object> paramMap, PageBean pageBean) throws Exception {
  164. ResponseBean rb = new ResponseBean();
  165. List<XtDmlb> xtDmlbs = new ArrayList<XtDmlb>();
  166. int count = (Integer) getSqlMapClientTemplate().queryForObject(XtSqlMapConstant.SQLMAP_COUNT_DMLB_BY_PARAM, paramMap);
  167. if(null != pageBean) {
  168. int startRecord = pageBean.getCurrentPageFirstRecord();
  169. int endRecord = pageBean.getPageSize();
  170. paramMap.put("startRecord", startRecord);
  171. paramMap.put("endRecord", endRecord);
  172. pageBean.setRecordCount(count);
  173. } else {
  174. paramMap.put("startRecord", 0);
  175. paramMap.put("endRecord", count);
  176. }
  177. xtDmlbs = (List<XtDmlb>) getSqlMapClientTemplate().queryForList(XtSqlMapConstant.SQLMAP_SELECT_DMLB_BY_PARAM, paramMap);
  178. rb.setResult(xtDmlbs);
  179. rb.setReturnCode(count);
  180. return rb;
  181. }
  182. /**
  183. * 找到最大的sxh
  184. */
  185. public Integer selectMaxSxh() {
  186. return (Integer) getSqlMapClientTemplate().queryForObject(XtSqlMapConstant.SQLMAP_COUNT_DMLB_BY_PARAM, null);
  187. }
  188. /**
  189. * 插入XtDmlb,同时更新对应XtDmlb的sxh字段
  190. * @param XtDmlb
  191. * 需要插入的XtDmlb
  192. */
  193. public void insertXtDmlb(final XtDmlb xtDmlb) {
  194. XtDmlbExample dmlbEx = new XtDmlbExample();
  195. dmlbEx.createCriteria().andZfbzEqualTo(XtAppConstant.ZFBZ_VALID);
  196. final List<XtDmlb> xtDmlbs = selectByExample(dmlbEx);
  197. getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
  198. @Override
  199. public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
  200. executor.startBatch();
  201. for (XtDmlb yXtDmlb : xtDmlbs) {
  202. if(yXtDmlb.getSxh() >= xtDmlb.getSxh()) {
  203. yXtDmlb.setSxh(yXtDmlb.getSxh() + 1);
  204. executor.update("xt_dmlb.ibatorgenerated_updateByPrimaryKeySelective", yXtDmlb);
  205. }
  206. }
  207. executor.insert("xt_dmlb.ibatorgenerated_insertSelective", xtDmlb);
  208. executor.executeBatch();
  209. return null;
  210. }
  211. });
  212. }
  213. /**
  214. * 更新XtDmlb,同时更新对应XtDmlb的sxh字段
  215. * @param yXtDmlb
  216. * 原XtDmlb
  217. * @param xXtDmlb
  218. * 新XtDmlb
  219. */
  220. public void updateXtDmlb(final XtDmlb yXtDmlb, final XtDmlb xXtDmlb) {
  221. XtDmlbExample dmlbEx = new XtDmlbExample();
  222. dmlbEx.createCriteria().andZfbzEqualTo(XtAppConstant.ZFBZ_VALID);
  223. final List<XtDmlb> xtDmlbs = selectByExample(dmlbEx);
  224. getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
  225. @Override
  226. public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
  227. executor.startBatch();
  228. if(xXtDmlb.getSxh() > yXtDmlb.getSxh()) { //顺序号增加
  229. for (XtDmlb xtDmlb : xtDmlbs) {
  230. if(xtDmlb.getSxh() > yXtDmlb.getSxh() && xtDmlb.getSxh() <= xXtDmlb.getSxh()) {
  231. xtDmlb.setSxh(xtDmlb.getSxh() - 1);
  232. executor.update("xt_dmlb.ibatorgenerated_updateByPrimaryKeySelective", xtDmlb);
  233. }
  234. }
  235. updateByPrimaryKeySelective(xXtDmlb);
  236. } else if (xXtDmlb.getSxh() < yXtDmlb.getSxh()) { //顺序号减小
  237. for (XtDmlb xtDmlb : xtDmlbs) {
  238. if(xtDmlb.getSxh() < yXtDmlb.getSxh() && xtDmlb.getSxh() >= xXtDmlb.getSxh()) {
  239. xtDmlb.setSxh(xtDmlb.getSxh() + 1);
  240. executor.update("xt_dmlb.ibatorgenerated_updateByPrimaryKeySelective", xtDmlb);
  241. }
  242. }
  243. executor.update("xt_dmlb.ibatorgenerated_updateByPrimaryKeySelective", xXtDmlb);
  244. }
  245. executor.executeBatch();
  246. return null;
  247. }
  248. });
  249. }
  250. /**
  251. * 置废XtDmlb,同时更新对应XtDmlb的sxh字段
  252. * @param xtDmlb
  253. * 需要置废的XtDmlb
  254. */
  255. public void disableXtDmlb(final XtDmlb xtDmlb) {
  256. XtDmlbExample dmlbEx = new XtDmlbExample();
  257. dmlbEx.createCriteria().andZfbzEqualTo(XtAppConstant.ZFBZ_VALID);
  258. final List<XtDmlb> xtDmlbs = selectByExample(dmlbEx);
  259. getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
  260. @Override
  261. public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
  262. executor.startBatch();
  263. for (XtDmlb dmlb : xtDmlbs) {
  264. if(dmlb.getSxh() > xtDmlb.getSxh()) {
  265. dmlb.setSxh(dmlb.getSxh() - 1);
  266. executor.update("xt_dmlb.ibatorgenerated_updateByPrimaryKeySelective", dmlb);
  267. }
  268. }
  269. executor.update("xt_dmlb.ibatorgenerated_updateByPrimaryKeySelective", xtDmlb);
  270. executor.executeBatch();
  271. return null;
  272. }
  273. });
  274. }
  275. }