XtGydmDAOImpl.java 11 KB

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