serviceImpl.vm 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package ${basePackage}.modules.${table.moduleName}.service.${table.businessName}.impl;
  2. import org.springframework.beans.factory.annotation.Autowired;
  3. import org.springframework.stereotype.Service;
  4. import javax.annotation.Resource;
  5. import org.springframework.validation.annotation.Validated;
  6. import java.util.*;
  7. import ${basePackage}.modules.${table.moduleName}.controller.${table.businessName}.vo.*;
  8. import ${basePackage}.modules.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO;
  9. import ${PageResultClassName};
  10. import ${basePackage}.modules.${table.moduleName}.convert.${table.businessName}.${table.className}Convert;
  11. import ${basePackage}.modules.${table.moduleName}.dal.mysql.${table.businessName}.${table.className}Mapper;
  12. import ${basePackage}.modules.${table.moduleName}.service.${table.businessName}.${table.className}Service;
  13. import ${ServiceExceptionUtilClassName};
  14. import static cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil.exception;
  15. import static ${basePackage}.modules.${table.moduleName}.enums.${simpleModuleName_upperFirst}ErrorCodeConstants.*;
  16. /**
  17. * ${table.classComment} Service 实现类
  18. *
  19. * @author ${table.author}
  20. */
  21. @Service
  22. @Validated
  23. public class ${table.className}ServiceImpl implements ${table.className}Service {
  24. @Resource
  25. private ${table.className}Mapper ${classNameVar}Mapper;
  26. @Override
  27. public ${primaryColumn.javaType} create${simpleClassName}(${table.className}CreateReqVO createReqVO) {
  28. // 插入
  29. ${table.className}DO ${classNameVar} = ${table.className}Convert.INSTANCE.convert(createReqVO);
  30. ${classNameVar}Mapper.insert(${classNameVar});
  31. // 返回
  32. return ${classNameVar}.getId();
  33. }
  34. @Override
  35. public void update${simpleClassName}(${table.className}UpdateReqVO updateReqVO) {
  36. // 校验存在
  37. this.validate${simpleClassName}Exists(updateReqVO.getId());
  38. // 更新
  39. ${table.className}DO updateObj = ${table.className}Convert.INSTANCE.convert(updateReqVO);
  40. ${classNameVar}Mapper.updateById(updateObj);
  41. }
  42. @Override
  43. public void delete${simpleClassName}(${primaryColumn.javaType} id) {
  44. // 校验存在
  45. this.validate${simpleClassName}Exists(id);
  46. // 删除
  47. ${classNameVar}Mapper.deleteById(id);
  48. }
  49. private void validate${simpleClassName}Exists(${primaryColumn.javaType} id) {
  50. if (${classNameVar}Mapper.selectById(id) == null) {
  51. throw exception(${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS);
  52. }
  53. }
  54. @Override
  55. public ${table.className}DO get${simpleClassName}(${primaryColumn.javaType} id) {
  56. return ${classNameVar}Mapper.selectById(id);
  57. }
  58. @Override
  59. public List<${table.className}DO> get${simpleClassName}List(Collection<${primaryColumn.javaType}> ids) {
  60. return ${classNameVar}Mapper.selectBatchIds(ids);
  61. }
  62. @Override
  63. public PageResult<${table.className}DO> get${simpleClassName}Page(${table.className}PageReqVO pageReqVO) {
  64. return ${classNameVar}Mapper.selectPage(pageReqVO);
  65. }
  66. @Override
  67. public List<${table.className}DO> get${simpleClassName}List(${table.className}ExportReqVO exportReqVO) {
  68. return ${classNameVar}Mapper.selectList(exportReqVO);
  69. }
  70. }