ServiceImpl.java.btl 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package ${packageName}.${backendModuleName}.${busName}.service.impl;
  2. import org.springframework.beans.factory.annotation.Autowired;
  3. import org.springframework.stereotype.Service;
  4. import cn.hutool.core.collection.CollectionUtil;
  5. import cn.hutool.core.util.*;
  6. import org.springframework.transaction.annotation.Transactional;
  7. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  8. import ${packageName}.${backendModuleName}.${busName}.repository.${className}Repository;
  9. import ${packageName}.${backendModuleName}.${busName}.po.${className}PO;
  10. import ${packageName}.${backendModuleName}.${busName}.dto.${className}DTO;
  11. import ${packageName}.${backendModuleName}.${busName}.dto.${className}QueryDTO;
  12. import java.util.*;
  13. import ${packageName}.${backendModuleName}.${busName}.service.I${className}Service;
  14. import ${packageName}.${backendModuleName}.mapper.${className}Mapper;
  15. /**
  16. * ${functionName}Service接口实现类
  17. *
  18. * @author ${authorName}
  19. * @date ${genTime}
  20. **/
  21. @Service
  22. public class ${className}ServiceImpl implements I${className}Service {
  23. @Autowired
  24. private ${className}Repository baseRepository;
  25. /**
  26. * 根据条件查询${functionName}
  27. * @param query 查询参数
  28. * @author ${authorName}
  29. * @date ${genTime}
  30. */
  31. @Override
  32. public List<${className}DTO> select${className}List(${className}QueryDTO query){
  33. return ${className}Mapper.INSTANCE.convertDtoList(
  34. baseRepository.selectList(new LambdaQueryWrapper<${className}PO>()
  35. <% for(var i = 0; i < configList.~size; i++) { %>
  36. <% if(configList[i].queryWhether != null && configList[i].queryWhether ) { %>
  37. <% if(configList[i].queryType == "like"){ %>
  38. .like(Objects.nonNull(query.get${configList[i].fieldNameCamelCaseFirstUpper}()),${className}PO::get${configList[i].fieldNameCamelCaseFirstUpper},
  39. query.get${configList[i].fieldNameCamelCaseFirstUpper}())
  40. <% } %>
  41. <% if(configList[i].queryType == "notLike"){ %>
  42. .notLike(Objects.nonNull(query.get${configList[i].fieldNameCamelCaseFirstUpper}()),${className}PO::get${configList[i].fieldNameCamelCaseFirstUpper},query.get${configList[i].fieldNameCamelCaseFirstUpper}())
  43. <% } %>
  44. <% if(configList[i].queryType == "eq"){ %>
  45. .eq(Objects.nonNull(query.get${configList[i].fieldNameCamelCaseFirstUpper}()),${className}PO::get${configList[i].fieldNameCamelCaseFirstUpper},query.get${configList[i].fieldNameCamelCaseFirstUpper}())
  46. <% } %>
  47. <% if(configList[i].queryType == "ne"){ %>
  48. .ne(Objects.nonNull(query.get${configList[i].fieldNameCamelCaseFirstUpper}()),${className}PO::get${configList[i].fieldNameCamelCaseFirstUpper},query.get${configList[i].fieldNameCamelCaseFirstUpper}())
  49. <% } %>
  50. <% if(configList[i].queryType == "gt"){ %>
  51. .gt(Objects.nonNull(query.get${configList[i].fieldNameCamelCaseFirstUpper}()),${className}PO::get${configList[i].fieldNameCamelCaseFirstUpper},query.get${configList[i].fieldNameCamelCaseFirstUpper}())
  52. <% } %>
  53. <% if(configList[i].queryType == "ge"){ %>
  54. .ge(Objects.nonNull(query.get${configList[i].fieldNameCamelCaseFirstUpper}()),${className}PO::get${configList[i].fieldNameCamelCaseFirstUpper},query.get${configList[i].fieldNameCamelCaseFirstUpper}())
  55. <% } %>
  56. <% if(configList[i].queryType == "lt"){ %>
  57. .lt(Objects.nonNull(query.get${configList[i].fieldNameCamelCaseFirstUpper}()),${className}PO::get${configList[i].fieldNameCamelCaseFirstUpper},query.get${configList[i].fieldNameCamelCaseFirstUpper}())
  58. <% } %>
  59. <% if(configList[i].queryType == "le"){ %>
  60. .le(Objects.nonNull(query.get${configList[i].fieldNameCamelCaseFirstUpper}()),${className}PO::get${configList[i].fieldNameCamelCaseFirstUpper},query.get${configList[i].fieldNameCamelCaseFirstUpper}())
  61. <% } %>
  62. <% if(configList[i].queryType == "BETWEEN"){ %>
  63. .le(CollectionUtil.isNotEmpty(query.get${configList[i].fieldNameCamelCaseFirstUpper}()),${className}PO::get${configList[i].fieldNameCamelCaseFirstUpper},CollectionUtil.query.get${configList[i].fieldNameCamelCaseFirstUpper}(),0))
  64. .ge(CollectionUtil.size(query.get${configList[i].fieldNameCamelCaseFirstUpper}())>1,${className}PO::get${configList[i].fieldNameCamelCaseFirstUpper},CollectionUtil.get(query.get${configList[i].fieldNameCamelCaseFirstUpper}(),1))
  65. <% } %>
  66. <% } %>
  67. <% } %>
  68. )
  69. );
  70. };
  71. /**
  72. * 根据id查询${functionName}
  73. * @param id 主键id
  74. * @author ${authorName}
  75. * @date ${genTime}
  76. */
  77. @Override
  78. public ${className}DTO select${className}ById(String id){
  79. return ${className}Mapper.INSTANCE.convertDto(baseRepository.selectById(id));
  80. };
  81. /**
  82. * 编辑${functionName}
  83. * @param source 编辑实体类
  84. * @author ${authorName}
  85. * @date ${genTime}
  86. */
  87. @Transactional(rollbackFor = Exception.class)
  88. @Override
  89. public boolean update${className}ById(${className}DTO source){
  90. return baseRepository.updateById(${className}Mapper.INSTANCE.convertPO(source))!=0;
  91. };
  92. /**
  93. * 新增${functionName}
  94. * @param source 新增实体类
  95. * @author ${authorName}
  96. * @date ${genTime}
  97. */
  98. @Override
  99. @Transactional(rollbackFor = Exception.class)
  100. public boolean insert${className}(${className}DTO source){
  101. return baseRepository.insert(${className}Mapper.INSTANCE.convertPO(source))!=0;
  102. };
  103. /**
  104. * 删除${functionName}详情
  105. * @param ids 删除主键集合
  106. * @author ${authorName}
  107. * @date ${genTime}
  108. */
  109. @Override
  110. @Transactional(rollbackFor = Exception.class)
  111. public int remove${className}ByIds(Collection<String> ids){
  112. return baseRepository.deleteBatchIds(ids);
  113. };
  114. }