CrudService.java 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /**
  2. * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
  3. */
  4. package com.thinkgem.jeesite.common.service;
  5. import java.util.List;
  6. import java.util.Map;
  7. import com.caimei.modules.basesetting.entity.Province;
  8. import com.caimei.modules.bulkpurchase.entity.PurchaseProduct;
  9. import com.caimei.modules.hehe.entity.HeheOrder;
  10. import com.caimei.modules.hehe.entity.HeheProduct;
  11. import com.caimei.modules.hehe.entity.HeheTransaction;
  12. import com.caimei.modules.order.entity.CmRefundShop;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.transaction.annotation.Transactional;
  15. import com.thinkgem.jeesite.common.persistence.CrudDao;
  16. import com.thinkgem.jeesite.common.persistence.DataEntity;
  17. import com.thinkgem.jeesite.common.persistence.Page;
  18. /**
  19. * Service基类
  20. * @author ThinkGem
  21. * @version 2014-05-16
  22. */
  23. @Transactional(readOnly = true)
  24. public abstract class CrudService<D extends CrudDao<T>, T extends DataEntity<T>> extends BaseService {
  25. /**
  26. * 持久层对象
  27. */
  28. @Autowired
  29. protected D dao;
  30. /**
  31. * 获取单条数据
  32. * @param id
  33. * @return
  34. */
  35. public T get(String id) {
  36. return dao.get(id);
  37. }
  38. /**
  39. * 获取单条数据
  40. * @param entity
  41. * @return
  42. */
  43. public T get(T entity) {
  44. return dao.get(entity);
  45. }
  46. /**
  47. * 查询列表数据
  48. * @param entity
  49. * @return
  50. */
  51. public List<T> findList(T entity) {
  52. return dao.findList(entity);
  53. }
  54. /**
  55. * 查询分页数据
  56. * @param page 分页对象
  57. * @param entity
  58. * @return
  59. */
  60. public Page<T> findPage(Page<T> page, T entity) {
  61. entity.setPage(page);
  62. page.setList(dao.findList(entity));
  63. return page;
  64. }
  65. /**
  66. * 保存数据(插入或更新)
  67. * @param entity
  68. */
  69. @Transactional(readOnly = false)
  70. public void save(T entity) {
  71. if (entity.getIsNewRecord()){
  72. entity.preInsert();
  73. dao.insert(entity);
  74. }else{
  75. entity.preUpdate();
  76. dao.update(entity);
  77. }
  78. }
  79. /**
  80. * 删除数据
  81. * @param entity
  82. */
  83. @Transactional(readOnly = false)
  84. public void delete(T entity) {
  85. dao.delete(entity);
  86. }
  87. /**
  88. * PC端---批量修改启用、禁用状态
  89. * @param enabledStatus
  90. * @param ids
  91. */
  92. @Transactional(readOnly = false)
  93. public void updateEnabledStatusByIds(String enabledStatus, String[] ids) {
  94. dao.updateEnabledStatusByIds(enabledStatus,ids);
  95. }
  96. /**
  97. * crm端---批量修改启用、禁用状态
  98. * @param enabledStatus
  99. * @param ids
  100. */
  101. @Transactional(readOnly = false)
  102. public void updateCrmEnabledStatusByIds(String enabledStatus, String[] ids) {
  103. dao.updateCrmEnabledStatusByIds(enabledStatus,ids);
  104. }
  105. }