serviceImpl.java.ftl
4.07 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package ${package.ServiceImpl};
import ${package.Entity}.${entity};
import ${package.Mapper}.${table.mapperName};
import ${package.Service}.${table.serviceName};
import ${superServiceImplClassPackage};
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.List;
import javax.annotation.Resource;
import com.hotent.base.util.BeanUtils;
<#------------ 子表Manager包引入 ---------->
<#if cfg.boEntList?exists>
<#list cfg.cgUtil.getSubModelInfo(cfg.boEntList,table.name) as subModel>
import ${package.Entity}.${subModel.className};
import ${package.Service}.${subModel.className}Manager;
</#list>
</#if>
<#------------ END 子表Manager包引入 ---------->
/**
* ${table.comment!} 服务实现类
*
<#if cfg.companyName??>
* @company ${cfg.companyName}
</#if>
* @author ${author}
<#if cfg.authorEmail??>
* @email ${cfg.authorEmail}
</#if>
* @since ${date}
*/
@Service
<#if kotlin>
open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} {
}
<#else>
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} {
<#if cfg.type != "querySqldef">
<#------------ 子表Manager注入 ---------->
<#if cfg.boEntList?exists>
<#list cfg.cgUtil.getSubModelInfo(cfg.boEntList,table.name) as subModel>
@Resource
${subModel.className}Manager ${subModel.className?uncap_first}Manager;
</#list>
</#if>
<#------------END 子表Manager注入 ---------->
@Override
public ${entity} getDetail(String id) {
${entity} ${entity?uncap_first} = this.get(id);
<#------------ 子表数据获取 ---------->
<#if cfg.boEntList?exists>
<#list cfg.cgUtil.getSubModelInfo(cfg.boEntList,table.name) as subModel>
// 获取子表 ${subModel.comment}数据
QueryWrapper<${subModel.className}> ${subModel.className?uncap_first}QueryWrapper = new QueryWrapper<>();
${subModel.className?uncap_first}QueryWrapper.eq("REF_ID_", id);
List<${subModel.className}> ${subModel.className?uncap_first}List = ${subModel.className?uncap_first}Manager.list(${subModel.className?uncap_first}QueryWrapper);
${entity?uncap_first}.set${subModel.propertyName?cap_first}(${subModel.className?uncap_first}List);
<#if (cfg.cgUtil.getSubModelInfo(cfg.boEntList,subModel.tableName)?size>0) >
${subModel.className?uncap_first}List.forEach(e->{
try {
BeanUtils.copyNotNullProperties(e, ${subModel.className?uncap_first}Manager.getDetail(e.getId()));
} catch (Exception e1) {
e1.printStackTrace();
}
});
</#if>
</#list>
</#if>
<#------------ END 子表数据获取 ---------->
return ${entity?uncap_first};
}
@Override
@Transactional
public void createOrUpdate(${entity} ${entity?uncap_first}) {
//新建或更新
this.saveOrUpdate(${entity?uncap_first});
<#------------ 子表数据增删改查 ---------->
<#if cfg.boEntList?exists>
<#if cfg.cgUtil.getSubModelInfo(cfg.boEntList,table.name)?? && (cfg.cgUtil.getSubModelInfo(cfg.boEntList,table.name)?size>0) >
//主表主键
String refId = ${entity?uncap_first}.getId();
</#if>
<#list cfg.cgUtil.getSubModelInfo(cfg.boEntList,table.name) as subModel>
//删除${subModel.comment}数据
QueryWrapper<${subModel.className}> ${subModel.className?uncap_first}QueryWrapper = new QueryWrapper<>();
${subModel.className?uncap_first}QueryWrapper.eq("REF_ID_", refId);
${subModel.className?uncap_first}Manager.remove(${subModel.className?uncap_first}QueryWrapper);
List<${subModel.className}> ${subModel.className?uncap_first}List = ${entity?uncap_first}.get${subModel.propertyName?cap_first}();
if(BeanUtils.isNotEmpty(${subModel.className?uncap_first}List)){
${subModel.className?uncap_first}List.forEach(item->{
//设置主表主键
item.setRefId(refId);
//保存${subModel.comment}数据
${subModel.className?uncap_first}Manager.createOrUpdate(item);
});
}
</#list>
</#if>
<#------------ END 子表数据增删改查 ---------->
}
</#if>
}
</#if>