ServiceImpl.java.vm 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. package ${basePackage}.service;
  2. import com.kym.common.enumeration.MsgEnum;
  3. import com.kym.common.exception.BizException;
  4. import com.kym.common.page.Res;
  5. import com.kym.jdbc.Bean;
  6. import ${basePackage}.entity.po.${pojoName};
  7. import ${basePackage}.entity.po.${pojoName}.${pojoName}Info;
  8. import ${basePackage}.entity.po.${pojoName}.${pojoName}BasicQuery;
  9. import org.springframework.transaction.annotation.Transactional;
  10. /**
  11. * ${pojoComment}业务类
  12. * @date ${datetime}
  13. */
  14. @Service("${firstLowPojoName}Service")
  15. public class ${pojoName}Service extends IService implements ${pojoName}Service{
  16. @Resource
  17. private ${pojoName}DAO ${firstLowPojoName}DAO;
  18. /**
  19. * ${pojoComment}分页查询
  20. */
  21. public Bean<${pojoName}Info>list(${pojoName}BasicQuery query) {
  22. setupQuery(query);
  23. return ${firstLowPojoName}DAO.selectPageBean(query);
  24. }
  25. /**
  26. * 查询${pojoComment}详情
  27. */
  28. public ${pojoName}Info detail(long id) {
  29. return ${firstLowPojoName}DAO.selectOneExist(${pojoName}Info.class,id);
  30. }
  31. /**
  32. * ${pojoComment}状态变更
  33. */
  34. @Transactional(rollbackFor = Exception.class)
  35. public void status(long id,int status) {
  36. ${pojoName} old = ${firstLowPojoName}DAO.selectOneExist(${pojoName}.class,id);
  37. ${pojoName} bean = new ${pojoName}();
  38. bean.setId(id);
  39. bean.setStatus(status);
  40. ${firstLowPojoName}DAO.updateSelective(bean,"status");
  41. super.afterModify(old,bean);
  42. }
  43. /**
  44. * 新增${pojoComment}
  45. */
  46. @Transactional(rollbackFor = Exception.class)
  47. public long add(${pojoName}Info ${firstLowPojoName}) {
  48. ${firstLowPojoName}DAO.checkUniqueValue(${pojoName}.class,oBuilder().eq(${pojoName}::getName, ${firstLowPojoName}.getName()),${pojoName}::getName,${firstLowPojoName}.getId());
  49. long ret = ${firstLowPojoName}DAO.insert(${firstLowPojoName});
  50. CommUtil.asserts(ret>0, MsgEnum.DB_ERROR);
  51. super.afterAdd(ret);
  52. return ret;
  53. }
  54. /**
  55. * 物理删除${pojoComment}
  56. */
  57. @Transactional(rollbackFor = Exception.class)
  58. public Res remove(long id) {
  59. ${firstLowPojoName}DAO.delete(${pojoName}.class,id);
  60. super.afterRemove(id);
  61. return Res.success();
  62. }
  63. /**
  64. * 编辑${pojoComment}
  65. */
  66. @Transactional(rollbackFor = Exception.class)
  67. public void modify(${pojoName}Info ${firstLowPojoName}) {
  68. ${pojoName}Info oldBean = ${firstLowPojoName}DAO.selectOneExist(${pojoName}Info.class, ${firstLowPojoName}.getId());
  69. int ret = ${firstLowPojoName}DAO.update(${firstLowPojoName});
  70. CommUtil.asserts(ret>0, MsgEnum.DB_ERROR);
  71. super.afterModify(oldBean,${firstLowPojoName});
  72. }
  73. #if(${hasCategory})
  74. /**
  75. * 新增${pojoComment}分类
  76. */
  77. @Transactional(rollbackFor = Exception.class)
  78. public int addCategory(${pojoName}Category category) {
  79. ${firstLowPojoName}DAO.checkUniqueValue(${pojoName}Category.class,oBuilder().eq(${pojoName}Category::getName, category.getName()),${pojoName}Category::getName,category.getId());
  80. int ret = ${firstLowPojoName}DAO.insert(category);
  81. CommUtil.asserts(ret>0, MsgEnum.DB_ERROR);
  82. super.afterAdd(ret);
  83. return ret;
  84. }
  85. /**
  86. * ${pojoComment}分类分页查询
  87. */
  88. public Res listCategory(${pojoName}Category.${pojoName}CategoryBasicQuery query) {
  89. return Res.succ(${firstLowPojoName}DAO.selectPageList(query));
  90. }
  91. /**
  92. * ${pojoComment}分类详情
  93. */
  94. public ${pojoName}Category detailCategory(long id) {
  95. return ${firstLowPojoName}DAO.selectOneExist(${pojoName}Category.class,id)
  96. }
  97. /**
  98. * ${pojoComment}分类编辑
  99. */
  100. @Transactional(rollbackFor = Exception.class)
  101. public void modifyCategory(${pojoName}Category category) {
  102. ${pojoName} old = ${firstLowPojoName}DAO.selectOneExist(${pojoName}.class,id);
  103. int ret =${firstLowPojoName}DAO.update(category);
  104. CommUtil.asserts(ret>0, MsgEnum.DB_ERROR);
  105. super.afterModify(old,category);
  106. }
  107. /**
  108. * ${pojoComment}分类发布/撤回
  109. */
  110. @Transactional(rollbackFor = Exception.class)
  111. public void releaseCategory(long id,int releaseStatus) {
  112. ${pojoName} old = ${firstLowPojoName}DAO.selectOneExist(${pojoName}.class,id);
  113. ${pojoName} bean = new ${pojoName}();
  114. bean.setId(id);
  115. //bean.releaseStatus = releaseStatus;
  116. ${firstLowPojoName}DAO.updateSelective(bean,"releaseStatus");
  117. super.afterModify(old,bean);
  118. }
  119. /**
  120. * ${pojoComment}分类物理删除
  121. */
  122. @Transactional(rollbackFor = Exception.class)
  123. public void removeCategory(long categoryId) {
  124. //子分类
  125. int subCategoryCount = ${firstLowPojoName}DAO.selectCount(${pojoName}Category.class, oBuilder().eq(${pojoName}Category::getPid, categoryId));
  126. if (subCategoryCount > 0) {
  127. throw new BizException(MsgEnum.SYSTEM_ERROR.code, "有子分类存在,请先删除子分类再操作");
  128. }
  129. int typeCount = ${firstLowPojoName}DAO.selectCount(${pojoName}.class,oBuilder().eq(${pojoName}.class::getCategoryId,categoryId));
  130. if(typeCount>0){
  131. throw new BizException(MsgEnum.SYSTEM_ERROR.code,"此分类下有${pojoComment},请解除分类关系或删除后再删除");
  132. }
  133. ${firstLowPojoName}DAO.delete(${pojoName}Category.class,categoryId);
  134. super.afterRemove(categoryId);
  135. }
  136. #end
  137. }