SysOrgServiceImpl.java
9.19 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
package com.zteits.sys.biz;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.clouds.common.log.LogSelf;
import com.clouds.common.utils.BeanValidatorsUtils;
import com.clouds.common.utils.ListCopyUtil;
import com.clouds.common.utils.LogSelfFactory;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import com.zteits.clouds.api.apibase.bean.BizResult;
import com.zteits.clouds.api.apibase.bean.PageBean;
import com.zteits.clouds.api.apibase.constants.DataStatusEnum;
import com.zteits.clouds.api.apibase.constants.ErrorType;
import com.zteits.clouds.api.apibase.exception.BizException;
import com.zteits.clouds.api.dto.sys.SysOpDTO;
import com.zteits.clouds.api.dto.sys.SysOrgDTO;
import com.zteits.clouds.api.dto.sys.param.OrgByOrgLevelRequest;
import com.zteits.clouds.api.dto.sys.param.SysOrgByIdQueryRequest;
import com.zteits.clouds.api.dto.sys.param.SysOrgByIdsDeleteRequest;
import com.zteits.clouds.api.dto.sys.param.SysOrgPageQueryRequest;
import com.zteits.clouds.api.dto.sys.param.SysOrgQueryByOpIdRequest;
import com.zteits.clouds.api.dto.sys.param.SysOrgQueryBySysOpIDRequest;
import com.zteits.clouds.api.dto.sys.param.SysOrgSaveRequest;
import com.zteits.clouds.api.dto.sys.param.SysOrgUpdateRequest;
import com.zteits.clouds.api.service.sys.SysOrgService;
import com.zteits.sys.dao.SysOpOrgDao;
import com.zteits.sys.dao.SysOrgDao;
import com.zteits.sys.domain.SysOp;
import com.zteits.sys.domain.SysOrg;
import com.zteits.sys.pagepaper.PageBeanUtil;
/**
*
*
* Copyright: Copyright (c) 2017 zteits
*
* @ClassName: SysOrgServiceImpl.java
* @Description:
* @version: v1.0.0
* @author: langlw
* @date: 2017年5月11日 上午9:56:03
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2017年5月11日 langlw v1.0.0 创建
*/
@Service("com.zteits.sys.biz.SysOrgServiceImpl")
public class SysOrgServiceImpl implements SysOrgService {
private static final LogSelf logger = LogSelfFactory.getLogSelf(SysOrgServiceImpl.class);
@Autowired
private SysOrgDao sysOrgDao;
@Autowired
private SysOpOrgDao sysOpOrgDao;
@Override
public BizResult<List<SysOrgDTO>> queryAllSysOrgByParentId(SysOrgPageQueryRequest request) {
List<SysOrgDTO> dtoList = new ArrayList<>();
List<SysOrg> allSysOrgs = getChildSys(request.getParentOrgId());
for (SysOrg sysOrg :allSysOrgs){
SysOrgDTO dto = new SysOrgDTO();
BeanUtils.copyProperties(sysOrg,dto);
dtoList.add(dto);
}
return new BizResult<>(dtoList);
}
private List<SysOrg> getChildSys(Long parentId){
List<SysOrg> result = Lists.newArrayList();
List<SysOrg> dubboResult = sysOrgDao.querySysOrgByParentId(parentId);
if(null == dubboResult){
dubboResult = new ArrayList<>();
}
result.addAll(dubboResult);
for(SysOrg sysOrg:dubboResult){
List<SysOrg> childResult = getChildSys(sysOrg.getId());
if(CollectionUtils.isEmpty(childResult)){
continue;
}else{
result.addAll(childResult);
}
}
return result;
}
@Override
public BizResult<PageBean<SysOrgDTO>> pageQuerySysOrg(SysOrgPageQueryRequest request) {
if(request ==null){
throw new BizException(ErrorType.PARAMM_NULL,"请求对象");
}
PageInfo<SysOrg> pageInfo = sysOrgDao.queryPageSysOrgForList(request);
PageBean<SysOrgDTO> pageBean = new PageBean<SysOrgDTO>();
if(null !=pageInfo){
PageBeanUtil.copyProperties(pageInfo, pageBean, SysOrgDTO.class);
}
return new BizResult<PageBean<SysOrgDTO>>(pageBean);
}
@Override
public BizResult<List<SysOrgDTO>> querySysOrgByUserId(SysOrgQueryByOpIdRequest request) {
if (CollectionUtils.isEmpty(request.getOpIds())) {
throw new BizException(ErrorType.PARAMM_NULL, "操作员Id集合");
}
List<Long> result = sysOpOrgDao.queryOrgIdsByOpIds(request.getOpIds(), request.getDataStatus(),
request.getSysCode());
if (CollectionUtils.isEmpty(result)) {
logger.info("根据操作员ID查询组织ID,未查找到对应状态的组织ID,直接返回空集合!");
return new BizResult<>(new ArrayList<SysOrgDTO>());
}
List<SysOrg> sysOrgs = sysOrgDao.queryBatchSysOrgById(result , request.getDataStatus(),
request.getSysCode());
List<SysOrgDTO> dtos = new ArrayList<>();
SysOrgDTO dto;
for (SysOrg org : sysOrgs) {
dto = new SysOrgDTO();
BeanUtils.copyProperties(org, dto);
dtos.add(dto);
}
return new BizResult<>(dtos);
}
@Override
public BizResult<SysOrgDTO> getSysOrgById(SysOrgByIdQueryRequest request) throws Exception {
if(request ==null){
throw new BizException(ErrorType.PARAMM_NULL,"请求对象");
}
SysOrg sys0rg = sysOrgDao.getSysOrgById(request.getId());
SysOrgDTO orgDTO = new SysOrgDTO();
if(sys0rg != null){
BeanUtils.copyProperties(sys0rg, orgDTO);
}
return new BizResult<SysOrgDTO>(orgDTO);
}
@Transactional
@Override
public BizResult<Boolean> deleteOrgByIds(SysOrgByIdsDeleteRequest request) throws Exception {
BeanValidatorsUtils.validateWithException(request);
if(CollectionUtils.isEmpty(request.getIds())){
throw new BizException(ErrorType.PARAMM_NULL,"请求对象");
}
Boolean b = sysOrgDao.deleteSysOrgByIds(request.getIds());
for (Long id : request.getIds()) {
sysOrgDao.updateSysOrgSortNumOfDelete(id);
}
return new BizResult<Boolean>(b);
}
@Transactional
@Override
public BizResult<Long> saveSysOrg(SysOrgSaveRequest request) throws Exception{
BeanValidatorsUtils.validateWithException(request);
request.setSysCode(request.getSysCode());
Long id = sysOrgDao.saveSysOrg(request);
int oldSortNum = request.getOldSortNum().intValue();
int sortNum = request.getSortNum().intValue();
sysOrgDao.updateSysOrgSortNumOfSaveOrUpdate(id,request.getParentOrgId(),sortNum,oldSortNum);
return new BizResult<Long>(id);
}
@Transactional
@Override
public BizResult<Boolean> updateSysOrg(SysOrgUpdateRequest request) throws Exception{
BeanValidatorsUtils.validateWithException(request);
SysOrg sysOrg = new SysOrg();
BeanUtils.copyProperties(request, sysOrg);
sysOrg.setModfiyEmpid(request.getEmpid());
sysOrg.setModfiyDate(new Date());
Boolean b=sysOrgDao.updateSysOrgById(sysOrg);
int oldSortNum = request.getOldSortNum().intValue();
int sortNum = request.getSortNum().intValue();
sysOrgDao.updateSysOrgSortNumOfSaveOrUpdate(request.getId(),request.getParentOrgId(),sortNum,oldSortNum);
return new BizResult<Boolean>(b);
}
@Override
public BizResult<Boolean> isUsedForOrgByOrgId(SysOrgByIdQueryRequest request) {
//验证参数
BeanValidatorsUtils.validateWithException(request);
List<Long> orgIds = Lists.newArrayList();
orgIds.add(request.getId());
List<Long> ops =sysOrgDao.queryOpIdsByOrgId(orgIds,DataStatusEnum.DATA_STATUS_VALID.value(), request.getSysCode());
return new BizResult<Boolean>(!CollectionUtils.isEmpty(ops));
}
@Override
public BizResult<List<Long>> querySysOrgBySysOpId(SysOrgQueryBySysOpIDRequest sysOrgQueryBySysOpIDRequest) throws Exception {
logger.info("---begin---通过操作员工ID查询对应组织,入参={}",JSONObject.toJSONString(sysOrgQueryBySysOpIDRequest));
List<Long> orgList = new ArrayList<Long>();
if(sysOrgQueryBySysOpIDRequest != null){
orgList = sysOpOrgDao.querySysOrgBySysOpId(sysOrgQueryBySysOpIDRequest.getSysOpId(), sysOrgQueryBySysOpIDRequest.getSysCode());
}else{
throw new BizException(ErrorType.PARAMM_NULL,"请求对象");
}
logger.info("---end---通过操作员工ID查询对应组织,结果={}",JSONArray.toJSONString(orgList));
return new BizResult<List<Long>>(orgList);
}
@Override
public BizResult<PageBean<SysOpDTO>> queryOpByorgIdForPage(SysOrgByIdQueryRequest request) {
if(null == request.getId() || StringUtils.isEmpty(request.getSysCode())){
throw new BizException(ErrorType.PARAMM_NULL,"组织ID不能为空");
}
PageInfo<SysOp> pageInfo = sysOrgDao.queryOpByorgIdForPage(request.getId(),request.getBaseRequest().getPageSize(),request.getBaseRequest().getPageNum(),request.getSysCode());
PageBean<SysOpDTO> pageBean = new PageBean<SysOpDTO>();
if(null !=pageInfo){
PageBeanUtil.copyProperties(pageInfo, pageBean, SysOpDTO.class);
}
return new BizResult<PageBean<SysOpDTO>>(pageBean);
}
@Override
public BizResult<List<SysOrgDTO>> queryOrgByOrgLevel(OrgByOrgLevelRequest orgByOrgLevelRequest) {
List<SysOrgDTO> list = Lists.newArrayList();
if(null == orgByOrgLevelRequest || StringUtils.isEmpty(orgByOrgLevelRequest.getOrgLevel()+"")){
throw new BizException(ErrorType.PARAMM_NULL,"组织ID不能为空");
}
List<SysOrg> sysorgList = sysOrgDao.queryOrgByOrgLevel(orgByOrgLevelRequest);
ListCopyUtil.listCopyProperties(sysorgList, list, SysOrgDTO.class);
return new BizResult<List<SysOrgDTO>>(list);
}
}