Blame view

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