0a27137060db9abbf000f9862da734c4a884c5d9.svn-base
4.47 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/**
* Copyright © 2015-2018 ODM All rights reserved.
*/
package com.thinkgem.jeesite.modules.gen.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.BaseService;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.gen.entity.GenTable;
import com.thinkgem.jeesite.modules.gen.entity.GenTableColumn;
import com.thinkgem.jeesite.modules.gen.util.GenUtils;
import com.thinkgem.jeesite.modules.gen.dao.GenDataBaseDictDao;
import com.thinkgem.jeesite.modules.gen.dao.GenTableColumnDao;
import com.thinkgem.jeesite.modules.gen.dao.GenTableDao;
/**
* 业务表Service
* @author ThinkGem
* @version 2013-10-15
*/
@Service
@Transactional(readOnly = true)
public class GenTableService extends BaseService {
@Autowired
private GenTableDao genTableDao;
@Autowired
private GenTableColumnDao genTableColumnDao;
@Autowired
private GenDataBaseDictDao genDataBaseDictDao;
public GenTable get(String id) {
GenTable genTable = genTableDao.get(id);
GenTableColumn genTableColumn = new GenTableColumn();
genTableColumn.setGenTable(new GenTable(genTable.getId()));
genTable.setColumnList(genTableColumnDao.findList(genTableColumn));
return genTable;
}
public Page<GenTable> find(Page<GenTable> page, GenTable genTable) {
genTable.setPage(page);
page.setList(genTableDao.findList(genTable));
return page;
}
public List<GenTable> findAll() {
return genTableDao.findAllList(new GenTable());
}
/**
* 获取物理数据表列表
* @param genTable
* @return
*/
public List<GenTable> findTableListFormDb(GenTable genTable){
return genDataBaseDictDao.findTableList(genTable);
}
/**
* 验证表名是否可用,如果已存在,则返回false
* @param genTable
* @return
*/
public boolean checkTableName(String tableName){
if (StringUtils.isBlank(tableName)){
return true;
}
GenTable genTable = new GenTable();
genTable.setName(tableName);
List<GenTable> list = genTableDao.findList(genTable);
return list.size() == 0;
}
/**
* 获取物理数据表列表
* @param genTable
* @return
*/
public GenTable getTableFormDb(GenTable genTable){
// 如果有表名,则获取物理表
if (StringUtils.isNotBlank(genTable.getName())){
List<GenTable> list = genDataBaseDictDao.findTableList(genTable);
if (list.size() > 0){
// 如果是新增,初始化表属性
if (StringUtils.isBlank(genTable.getId())){
genTable = list.get(0);
// 设置字段说明
if (StringUtils.isBlank(genTable.getComments())){
genTable.setComments(genTable.getName());
}
genTable.setClassName(StringUtils.toCapitalizeCamelCase(genTable.getName()));
}
// 添加新列
List<GenTableColumn> columnList = genDataBaseDictDao.findTableColumnList(genTable);
for (GenTableColumn column : columnList){
boolean b = false;
for (GenTableColumn e : genTable.getColumnList()){
if (e.getName().equals(column.getName())){
b = true;
}
}
if (!b){
genTable.getColumnList().add(column);
}
}
// 删除已删除的列
for (GenTableColumn e : genTable.getColumnList()){
boolean b = false;
for (GenTableColumn column : columnList){
if (column.getName().equals(e.getName())){
b = true;
}
}
if (!b){
e.setDelFlag(GenTableColumn.DEL_FLAG_DELETE);
}
}
// 获取主键
genTable.setPkList(genDataBaseDictDao.findTablePK(genTable));
// 初始化列属性字段
GenUtils.initColumnField(genTable);
}
}
return genTable;
}
@Transactional(readOnly = false)
public void save(GenTable genTable) {
if (StringUtils.isBlank(genTable.getId())){
genTable.preInsert();
genTableDao.insert(genTable);
}else{
genTable.preUpdate();
genTableDao.update(genTable);
}
// 保存列
for (GenTableColumn column : genTable.getColumnList()){
column.setGenTable(genTable);
if (StringUtils.isBlank(column.getId())){
column.preInsert();
genTableColumnDao.insert(column);
}else{
column.preUpdate();
genTableColumnDao.update(column);
}
}
}
@Transactional(readOnly = false)
public void delete(GenTable genTable) {
genTableDao.delete(genTable);
genTableColumnDao.deleteByGenTableId(genTable.getId());
}
}