提交 | 用户 | 时间
|
71e81e
|
1 |
package ${package.ServiceImpl}; |
懒 |
2 |
|
|
3 |
import cn.stylefeng.roses.core.page.PageFactory; |
|
4 |
import cn.stylefeng.roses.kernel.model.page.PageResult; |
|
5 |
import ${package.Entity}.${entity}; |
|
6 |
import ${package.Mapper}.${table.mapperName}; |
|
7 |
import ${package.EntitySpecParams}.${entity}Param; |
|
8 |
import ${package.EntitySpecResult}.${entity}Result; |
|
9 |
import ${package.Service}.${table.serviceName}; |
|
10 |
import cn.stylefeng.roses.core.util.ToolUtil; |
|
11 |
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
12 |
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
13 |
import ${superServiceImplClassPackage}; |
|
14 |
import org.springframework.stereotype.Service; |
|
15 |
|
|
16 |
import java.io.Serializable; |
|
17 |
import java.util.List; |
|
18 |
|
|
19 |
/** |
|
20 |
* <p> |
|
21 |
* $!{table.comment} 服务实现类 |
|
22 |
* </p> |
|
23 |
* |
|
24 |
* @author ${author} |
|
25 |
* @since ${date} |
|
26 |
*/ |
|
27 |
@Service |
|
28 |
#if(${kotlin}) |
|
29 |
open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} { |
|
30 |
|
|
31 |
} |
|
32 |
#else |
|
33 |
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} { |
|
34 |
|
|
35 |
@Override |
|
36 |
public void add(${entity}Param param){ |
|
37 |
${entity} entity = getEntity(param); |
|
38 |
this.save(entity); |
|
39 |
} |
|
40 |
|
|
41 |
@Override |
|
42 |
public void delete(${entity}Param param){ |
|
43 |
this.removeById(getKey(param)); |
|
44 |
} |
|
45 |
|
|
46 |
@Override |
|
47 |
public void update(${entity}Param param){ |
|
48 |
${entity} oldEntity = getOldEntity(param); |
|
49 |
${entity} newEntity = getEntity(param); |
|
50 |
ToolUtil.copyProperties(newEntity, oldEntity); |
|
51 |
this.updateById(newEntity); |
|
52 |
} |
|
53 |
|
|
54 |
@Override |
|
55 |
public ${entity}Result findBySpec(${entity}Param param){ |
|
56 |
return null; |
|
57 |
} |
|
58 |
|
|
59 |
@Override |
|
60 |
public List<${entity}Result> findListBySpec(${entity}Param param){ |
|
61 |
return null; |
|
62 |
} |
|
63 |
|
|
64 |
@Override |
|
65 |
public PageResult<${entity}Result> findPageBySpec(${entity}Param param){ |
|
66 |
Page pageContext = getPageContext(); |
|
67 |
IPage<${entity}Result> page = this.baseMapper.customPageList(pageContext, param); |
|
68 |
return new PageResult<>(page); |
|
69 |
} |
|
70 |
|
|
71 |
private Serializable getKey(${entity}Param param){ |
|
72 |
#set( $haveNoKey = true ) |
|
73 |
#foreach($field in ${table.fields}) |
|
74 |
#if(${field.keyFlag}) |
|
75 |
#set( $haveNoKey = false ) |
|
76 |
return param.get${field.capitalName}(); |
|
77 |
#end |
|
78 |
#end |
|
79 |
#if(${haveNoKey}) |
|
80 |
return null; |
|
81 |
#end |
|
82 |
} |
|
83 |
|
|
84 |
private Page getPageContext() { |
|
85 |
return PageFactory.defaultPage(); |
|
86 |
} |
|
87 |
|
|
88 |
private ${entity} getOldEntity(${entity}Param param) { |
|
89 |
return this.getById(getKey(param)); |
|
90 |
} |
|
91 |
|
|
92 |
private ${entity} getEntity(${entity}Param param) { |
|
93 |
${entity} entity = new ${entity}(); |
|
94 |
ToolUtil.copyProperties(param, entity); |
|
95 |
return entity; |
|
96 |
} |
|
97 |
|
|
98 |
} |
|
99 |
#end |