RepositoryTemplate.ftl
2.68 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
package ${basePackage}.repository;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.Map;
import org.msgpack.MessagePack;
import org.springframework.stereotype.Repository;
import ${basePackage}.bean.entity.${entityClassSimpleName};
import ${basePackage}.bean.vo.${voClassSimpleName};
import com.taover.repository.CustomJdbcTemplate;
import com.taover.util.UtilHttpRequestMap;
import com.taover.util.UtilObject;
@Repository
public class ${repositoryClassSimpleName} extends CustomJdbcTemplate<${entityClassSimpleName}, Integer>{
public ${repositoryClassSimpleName}() throws Exception {
super();
}
public String getSsidById(Integer id) throws Exception{
MessagePack pack = new MessagePack();
return Base64.getEncoder().encodeToString(pack.write(new Integer[]{id, id, id}));
}
public Integer getIdBySsid(String ssid) throws Exception{
MessagePack pack = new MessagePack();
return pack.read(Base64.getDecoder().decode(ssid), Integer[].class)[0];
}
public Map<String, Object> getVoPage(List<Object[]> condition, Integer page, Integer size) throws Exception{
Map<String, Object> entityData = this.findPageByCondition(condition, page, size);
List<${entityClassSimpleName}> entityList = (List<${entityClassSimpleName}>) entityData.get("rows");
List<${voClassSimpleName}> voList = new ArrayList<${voClassSimpleName}>();
for(int i=0; i<entityList.size(); ++i){
voList.add(this.getVoByEntity(entityList.get(i)));
}
entityData.put("rows", voList);
return entityData;
}
public ${voClassSimpleName} getVoBySsid(String ssid) throws Exception{
return this.getVoByEntity(this.findEntityByID(this.getIdBySsid(ssid)));
}
public ${voClassSimpleName} getVoByEntity(${entityClassSimpleName} entity) throws Exception{
${voClassSimpleName} voObj = null;
try {
voObj = UtilObject.fieldCopy(entity, ${voClassSimpleName}.class, true, new String[]{"id"});
} catch (Exception e) {
throw new Exception("对象转换失败");
}
voObj.setSsid(this.getSsidById(entity.getId()));
return voObj;
}
public void updateEntityBySsid(String ssid, List<Object[]> updateList) throws Exception{
this.updateEntityById(updateList, this.getIdBySsid(ssid));
}
public void deleteEntityBySsid(String ssid) throws Exception{
this.deleteEntityByID(this.getIdBySsid(ssid));
}
public ${voClassSimpleName} addEntityByMap(Map<String, Object> data) throws Exception{
${entityClassSimpleName} entityObj = UtilHttpRequestMap.getBeanByMap(data, ${entityClassSimpleName}.class, false, "id");
BigInteger resultId = this.addEntityForAutoincrementId(entityObj);
return this.getVoByEntity(this.findEntityByID(resultId.intValue()));
}
}