OrganizationManagerImpl.java
8.06 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
* @(#)OrganizationManagerImpl.java
*
* Copyright (c) 2014-2017 xiniunet 版权所有
* xiniunet. All rights reserved.
*
* This software is the confidential and proprietary
* information of xiniunet.
* ("Confidential Information"). You shall not disclose
* such Confidential Information and shall use it only
* in accordance with the terms of the contract agreement
* you entered into with xiniunet.
*/
package com.xiniunet.service.railway.biz;
import com.xiniunet.foundation.service.FoundationService;
import com.xiniunet.framework.base.BaseManagerImpl;
import com.xiniunet.framework.base.BaseResponse;
import com.xiniunet.framework.exception.ErrorType;
import com.xiniunet.framework.security.Passport;
import com.xiniunet.railway.domain.Organization;
import com.xiniunet.railway.request.*;
import com.xiniunet.railway.response.*;
import com.xiniunet.service.railway.Message;
import com.xiniunet.service.railway.dal.OrganizationMapper;
import com.xiniunet.service.railway.po.OrganizationPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
/**
* 组织部门的管理方法实现.
*
* @author xiniunet
*/
@Transactional
@Service("RailwayOrganizationManager")
public class OrganizationManagerImpl extends BaseManagerImpl implements OrganizationManager {
@Autowired
private FoundationService foundationService;
@Autowired
private OrganizationMapper organizationMapper;
/**
* 根据Id获取组织部门
*
* @param request 获取组织部门请求
* @param passport 用户护照
* @return 获取组织部门应答
*/
@Override
@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
public OrganizationGetResponse get(OrganizationGetRequest request, Passport passport) {
OrganizationGetResponse response = new OrganizationGetResponse();
OrganizationPO entity = organizationMapper.getById(request.getId(), passport);
if (entity != null) {
Organization organization = this.getMapper().map(entity, Organization.class);
response.setOrganization(organization);
} else {
response.addError(ErrorType.EXPECTATION_NULL, Message.COMMON_GET_FAILURE);
}
return response;
}
/**
* 模糊查询组织部门
*
* @param request 模糊查询组织部门请求
* @param passport 用户护照
* @return 模糊查询组织部门应答
*/
@Override
@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
public OrganizationSearchResponse search(OrganizationSearchRequest request, Passport passport) {
OrganizationSearchResponse response = new OrganizationSearchResponse();
List<Organization> modelList = new ArrayList<>();
Long count = organizationMapper.searchCount(request, passport);
if (count > 0) {
// 处理分页参数
if (request.getPageSize() > 0) {
//如果输入的页码大于实际的分页数,将页码设置为最后一页的页码
int lastPageNumber = (int) ((count - 1) / request.getPageSize() + 1);
if (request.getPageNumber() > lastPageNumber) {
request.setPageNumber(lastPageNumber);
}
}
//通过关键字查询出用户集合
List<OrganizationPO> entityList = organizationMapper.search(request, passport);
for (OrganizationPO entity : entityList) {
Organization organization = this.getMapper().map(entity, Organization.class);
modelList.add(organization);
}
}
response.setTotalCount(count);
response.setResult(modelList);
return response;
}
/**
* 高级查询组织部门
*
* @param request 高级查询组织部门请求
* @param passport 用户护照
* @return 高级查询组织部门应答
*/
@Override
@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
public OrganizationFindResponse find(OrganizationFindRequest request, Passport passport) {
OrganizationFindResponse response = new OrganizationFindResponse();
List<Organization> modelList = new ArrayList<>();
Long count = organizationMapper.findCount(request, passport);
if (count > 0) {
// 处理分页参数
if (request.getPageSize() > 0) {
//如果输入的页码大于实际的分页数,将页码设置为最后一页的页码
int lastPageNumber = (int) ((count - 1) / request.getPageSize() + 1);
if (request.getPageNumber() > lastPageNumber) {
request.setPageNumber(lastPageNumber);
}
}
List<OrganizationPO> entityList = organizationMapper.find(request, passport);
for (OrganizationPO entity : entityList) {
Organization organization = this.getMapper().map(entity, Organization.class);
modelList.add(organization);
}
}
response.setTotalCount(count);
response.setResult(modelList);
return response;
}
/**
* 创建组织部门
*
* @param request 创建组织部门请求
* @param passport 用户护照
* @return 创建组织部门应答
*/
@Override
public OrganizationCreateResponse create(OrganizationCreateRequest request, Passport passport) {
OrganizationCreateResponse response = new OrganizationCreateResponse();
OrganizationPO entity = this.getMapper().map(request, OrganizationPO.class);
if (entity.getId() == null) {
long id = foundationService.getNewId();
entity.setId(id);
}
// 先检查关键数据是否有重复,在检查通过后才能做插入操作
checkValidate(entity, passport, response);
if (response.hasError()) {
return response;
}
if (organizationMapper.insert(entity, passport) == 0) {
response.addError(ErrorType.EXPECTATION_NULL, Message.COMMON_CREATE_FAILURE);
return response;
}
response.setId(entity.getId());
return response;
}
/**
* 更新组织部门
*
* @param request 更新组织部门请求
* @param passport 用户护照
* @return 更新组织部门应答
*/
@Override
public OrganizationUpdateResponse update(OrganizationUpdateRequest request, Passport passport) {
OrganizationUpdateResponse response = new OrganizationUpdateResponse();
OrganizationPO entity = this.getMapper().map(request, OrganizationPO.class);
// 先检查关键数据是否有重复,在检查通过后才能做插入操作
checkValidate(entity, passport, response);
if (response.hasError()) {
return response;
}
Long result = organizationMapper.update(entity, passport);
if (result != 1) {
response.addError(ErrorType.BUSINESS_ERROR, Message.COMMON_UPDATE_FAILURE);
return response;
}
response.setResult(result);
return response;
}
/**
* 删除组织部门
*
* @param request 删除组织部门请求
* @param passport 用户护照
* @return 删除组织部门应答
*/
@Override
public OrganizationDeleteResponse delete(OrganizationDeleteRequest request, Passport passport) {
OrganizationDeleteResponse response = new OrganizationDeleteResponse();
Long result = organizationMapper.delete(request.getId(), passport);
response.setResult(result);
return response;
}
/**
* 验证对象
*
* @param organization 组织部门
* @param passport 用户护照
*/
private void checkValidate(OrganizationPO organization, Passport passport, BaseResponse response) {
// TODO
}
}