serviceImpl.java.vm 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. package ${packageName}.service.impl;
  2. import java.util.List;
  3. #if($table.tree)
  4. import java.util.ArrayList;
  5. import com.ruoyi.common.core.domain.Ztree;
  6. #end
  7. #foreach ($column in $columns)
  8. #if($column.javaField == 'createTime' || $column.javaField == 'updateTime')
  9. import com.ruoyi.common.utils.DateUtils;
  10. #break
  11. #end
  12. #end
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.stereotype.Service;
  15. #if($table.sub)
  16. import java.util.ArrayList;
  17. import com.ruoyi.common.utils.StringUtils;
  18. import org.springframework.transaction.annotation.Transactional;
  19. import ${packageName}.domain.${subClassName};
  20. #end
  21. import ${packageName}.mapper.${ClassName}Mapper;
  22. import ${packageName}.domain.${ClassName};
  23. import ${packageName}.service.I${ClassName}Service;
  24. import com.ruoyi.common.core.text.Convert;
  25. /**
  26. * ${functionName}Service业务层处理
  27. *
  28. * @author ${author}
  29. * @date ${datetime}
  30. */
  31. @Service
  32. public class ${ClassName}ServiceImpl implements I${ClassName}Service
  33. {
  34. @Autowired
  35. private ${ClassName}Mapper ${className}Mapper;
  36. /**
  37. * 查询${functionName}
  38. *
  39. * @param ${pkColumn.javaField} ${functionName}ID
  40. * @return ${functionName}
  41. */
  42. @Override
  43. public ${ClassName} select${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField})
  44. {
  45. return ${className}Mapper.select${ClassName}ById(${pkColumn.javaField});
  46. }
  47. /**
  48. * 查询${functionName}列表
  49. *
  50. * @param ${className} ${functionName}
  51. * @return ${functionName}
  52. */
  53. @Override
  54. public List<${ClassName}> select${ClassName}List(${ClassName} ${className})
  55. {
  56. return ${className}Mapper.select${ClassName}List(${className});
  57. }
  58. /**
  59. * 新增${functionName}
  60. *
  61. * @param ${className} ${functionName}
  62. * @return 结果
  63. */
  64. #if($table.sub)
  65. @Transactional
  66. #end
  67. @Override
  68. public int insert${ClassName}(${ClassName} ${className})
  69. {
  70. #foreach ($column in $columns)
  71. #if($column.javaField == 'createTime')
  72. ${className}.setCreateTime(DateUtils.getNowDate());
  73. #end
  74. #end
  75. #if($table.sub)
  76. int rows = ${className}Mapper.insert${ClassName}(${className});
  77. insert${subClassName}(${className});
  78. return rows;
  79. #else
  80. return ${className}Mapper.insert${ClassName}(${className});
  81. #end
  82. }
  83. /**
  84. * 修改${functionName}
  85. *
  86. * @param ${className} ${functionName}
  87. * @return 结果
  88. */
  89. #if($table.sub)
  90. @Transactional
  91. #end
  92. @Override
  93. public int update${ClassName}(${ClassName} ${className})
  94. {
  95. #foreach ($column in $columns)
  96. #if($column.javaField == 'updateTime')
  97. ${className}.setUpdateTime(DateUtils.getNowDate());
  98. #end
  99. #end
  100. #if($table.sub)
  101. ${className}Mapper.delete${subClassName}By${subTableFkClassName}(${className}.get${pkColumn.capJavaField}());
  102. insert${subClassName}(${className});
  103. #end
  104. return ${className}Mapper.update${ClassName}(${className});
  105. }
  106. /**
  107. * 删除${functionName}对象
  108. *
  109. * @param ids 需要删除的数据ID
  110. * @return 结果
  111. */
  112. #if($table.sub)
  113. @Transactional
  114. #end
  115. @Override
  116. public int delete${ClassName}ByIds(String ids)
  117. {
  118. #if($table.sub)
  119. ${className}Mapper.delete${subClassName}By${subTableFkClassName}s(Convert.toStrArray(ids));
  120. #end
  121. return ${className}Mapper.delete${ClassName}ByIds(Convert.toStrArray(ids));
  122. }
  123. /**
  124. * 删除${functionName}信息
  125. *
  126. * @param ${pkColumn.javaField} ${functionName}ID
  127. * @return 结果
  128. */
  129. @Override
  130. public int delete${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField})
  131. {
  132. #if($table.sub)
  133. ${className}Mapper.delete${subClassName}By${subTableFkClassName}(${pkColumn.javaField});
  134. #end
  135. return ${className}Mapper.delete${ClassName}ById(${pkColumn.javaField});
  136. }
  137. #if($table.tree)
  138. /**
  139. * 查询${functionName}树列表
  140. *
  141. * @return 所有${functionName}信息
  142. */
  143. @Override
  144. public List<Ztree> select${ClassName}Tree()
  145. {
  146. List<${ClassName}> ${className}List = ${className}Mapper.select${ClassName}List(new ${ClassName}());
  147. List<Ztree> ztrees = new ArrayList<Ztree>();
  148. for (${ClassName} ${className} : ${className}List)
  149. {
  150. Ztree ztree = new Ztree();
  151. #set($TreeCode=$treeCode.substring(0,1).toUpperCase() + ${treeCode.substring(1)})
  152. #set($TreeParentCode=$treeParentCode.substring(0,1).toUpperCase() + ${treeParentCode.substring(1)})
  153. #set($TreeName=$treeName.substring(0,1).toUpperCase() + ${treeName.substring(1)})
  154. ztree.setId(${className}.get${TreeCode}());
  155. ztree.setpId(${className}.get${TreeParentCode}());
  156. ztree.setName(${className}.get${TreeName}());
  157. ztree.setTitle(${className}.get${TreeName}());
  158. ztrees.add(ztree);
  159. }
  160. return ztrees;
  161. }
  162. #end
  163. #if($table.sub)
  164. /**
  165. * 新增${subTable.functionName}信息
  166. *
  167. * @param ${className} ${functionName}对象
  168. */
  169. public void insert${subClassName}(${ClassName} ${className})
  170. {
  171. List<${subClassName}> ${subclassName}List = ${className}.get${subClassName}List();
  172. Long ${pkColumn.javaField} = ${className}.get${pkColumn.capJavaField}();
  173. if (StringUtils.isNotNull(${subclassName}List))
  174. {
  175. List<${subClassName}> list = new ArrayList<${subClassName}>();
  176. for (${subClassName} ${subclassName} : ${subclassName}List)
  177. {
  178. ${subclassName}.set${subTableFkClassName}(${pkColumn.javaField});
  179. list.add(${subclassName});
  180. }
  181. if (list.size() > 0)
  182. {
  183. ${className}Mapper.batch${subClassName}(list);
  184. }
  185. }
  186. }
  187. #end
  188. }