|
|
|
@ -1,29 +1,41 @@
|
|
|
|
|
package ${basePackage}.module.system.mgr;
|
|
|
|
|
|
|
|
|
|
import ${basePackage}.frame.utils.IDgenerator;
|
|
|
|
|
import ${basePackage}.frame.utils.Message;
|
|
|
|
|
import ${basePackage}.frame.base.ErrorType;
|
|
|
|
|
import ${basePackage}.frame.base.Token;
|
|
|
|
|
import ${basePackage}.frame.utils.MapperUtil;
|
|
|
|
|
import ${basePackage}.frame.utils.ValidationUtil;
|
|
|
|
|
import ${basePackage}.module.system.ent.Dept;
|
|
|
|
|
import ${basePackage}.module.system.mpr.DeptMapper;
|
|
|
|
|
import ${basePackage}.module.system.req.DeptCreateRequest;
|
|
|
|
|
import ${basePackage}.module.system.req.DeptDeleteRequest;
|
|
|
|
|
import ${basePackage}.module.system.req.DeptFindRequest;
|
|
|
|
|
import ${basePackage}.module.system.req.DeptGetRequest;
|
|
|
|
|
import ${basePackage}.module.system.req.DeptUpdateRequest;
|
|
|
|
|
import ${basePackage}.module.system.rsp.DeptCreateResponse;
|
|
|
|
|
import ${basePackage}.module.system.rsp.DeptDeleteResponse;
|
|
|
|
|
import ${basePackage}.module.system.rsp.DeptFindResponse;
|
|
|
|
|
import ${basePackage}.module.system.rsp.DeptGetResponse;
|
|
|
|
|
import ${basePackage}.module.system.rsp.DeptUpdateResponse;
|
|
|
|
|
package xyz.wbsite.module.system.mgr;
|
|
|
|
|
|
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
|
|
import com.github.pagehelper.util.StringUtil;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import xyz.wbsite.frame.base.ErrorType;
|
|
|
|
|
import xyz.wbsite.frame.base.SortType;
|
|
|
|
|
import xyz.wbsite.frame.base.Token;
|
|
|
|
|
import xyz.wbsite.frame.utils.IDgenerator;
|
|
|
|
|
import xyz.wbsite.frame.utils.MapperUtil;
|
|
|
|
|
import xyz.wbsite.frame.utils.Message;
|
|
|
|
|
import xyz.wbsite.frame.utils.StringUtil;
|
|
|
|
|
import xyz.wbsite.frame.utils.ValidationUtil;
|
|
|
|
|
import xyz.wbsite.module.system.ent.Dept;
|
|
|
|
|
import xyz.wbsite.module.system.ent.DeptTree;
|
|
|
|
|
import xyz.wbsite.module.system.ent.Resource;
|
|
|
|
|
import xyz.wbsite.module.system.ent.ResourceTree;
|
|
|
|
|
import xyz.wbsite.module.system.mpr.DeptMapper;
|
|
|
|
|
import xyz.wbsite.module.system.req.DeptCreateRequest;
|
|
|
|
|
import xyz.wbsite.module.system.req.DeptDeleteRequest;
|
|
|
|
|
import xyz.wbsite.module.system.req.DeptFindRequest;
|
|
|
|
|
import xyz.wbsite.module.system.req.DeptGetRequest;
|
|
|
|
|
import xyz.wbsite.module.system.req.DeptTreeRequest;
|
|
|
|
|
import xyz.wbsite.module.system.req.DeptUpdateRequest;
|
|
|
|
|
import xyz.wbsite.module.system.rsp.DeptCreateResponse;
|
|
|
|
|
import xyz.wbsite.module.system.rsp.DeptDeleteResponse;
|
|
|
|
|
import xyz.wbsite.module.system.rsp.DeptFindResponse;
|
|
|
|
|
import xyz.wbsite.module.system.rsp.DeptGetResponse;
|
|
|
|
|
import xyz.wbsite.module.system.rsp.DeptTreeResponse;
|
|
|
|
|
import xyz.wbsite.module.system.rsp.DeptUpdateResponse;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* DEPT - 部门
|
|
|
|
@ -54,9 +66,34 @@ public class DeptManagerImpl implements DeptManager {
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//检查是否重复
|
|
|
|
|
{
|
|
|
|
|
DeptFindRequest deptFindRequest = new DeptFindRequest();
|
|
|
|
|
deptFindRequest.setDeptCode(request.getDeptCode());
|
|
|
|
|
DeptFindResponse deptFindResponse = this.find(deptFindRequest, token);
|
|
|
|
|
if (deptFindResponse.getResult().size() > 0) {
|
|
|
|
|
response.addError(ErrorType.BUSINESS_ERROR, "[" + request.getDeptCode() + "]机构代码重复");
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long id = IDgenerator.nextId();
|
|
|
|
|
Dept entity = MapperUtil.map(request, Dept.class);
|
|
|
|
|
entity.setId(id);
|
|
|
|
|
if (StringUtil.isEmpty(entity.getSupCode()) || StringUtil.isEmpty(entity.getSupName())) {
|
|
|
|
|
String deptCode = entity.getDeptCode();
|
|
|
|
|
while (deptCode.contains("_")) {
|
|
|
|
|
deptCode = deptCode.substring(0, deptCode.lastIndexOf("_"));
|
|
|
|
|
DeptFindRequest deptFindRequest = new DeptFindRequest();
|
|
|
|
|
deptFindRequest.setDeptCode(deptCode);
|
|
|
|
|
DeptFindResponse deptFindResponse = this.find(deptFindRequest, token);
|
|
|
|
|
if (deptFindResponse.getResult().size() > 0) {
|
|
|
|
|
Dept supDept = deptFindResponse.getResult().get(0);
|
|
|
|
|
entity.setSupCode(supDept.getDeptCode());
|
|
|
|
|
entity.setSupName(supDept.getDeptName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long result = deptMapper.insert(entity, token);
|
|
|
|
|
if (1L != result) {
|
|
|
|
@ -172,4 +209,70 @@ public class DeptManagerImpl implements DeptManager {
|
|
|
|
|
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public DeptTreeResponse tree(DeptTreeRequest request, Token token) {
|
|
|
|
|
DeptTreeResponse response = new DeptTreeResponse();
|
|
|
|
|
|
|
|
|
|
ValidationUtil.validate(request, response);
|
|
|
|
|
if (response.hasError()) {
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DeptFindRequest deptFindRequest = new DeptFindRequest();
|
|
|
|
|
deptFindRequest.setPageSize(0);
|
|
|
|
|
deptFindRequest.setValid(true);
|
|
|
|
|
deptFindRequest.setSortType(SortType.ASC);
|
|
|
|
|
deptFindRequest.setSortKey("DEPT_CODE");
|
|
|
|
|
DeptFindResponse deptFindResponse = this.find(deptFindRequest, token);
|
|
|
|
|
|
|
|
|
|
if (deptFindResponse.hasError()) {
|
|
|
|
|
response.addErrors(deptFindResponse.getErrors());
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<DeptTree> data = new ArrayList<>();
|
|
|
|
|
Map<String, DeptTree> allMap = new HashMap<>();
|
|
|
|
|
List<Dept> result = deptFindResponse.getResult();
|
|
|
|
|
// 获取最顶级资源
|
|
|
|
|
int level = 1;
|
|
|
|
|
while (result.size() > 0) {
|
|
|
|
|
Iterator<Dept> iterator = result.iterator();
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
|
Dept next = iterator.next();
|
|
|
|
|
DeptTree tree = new DeptTree();
|
|
|
|
|
tree.setId(next.getId());
|
|
|
|
|
tree.setDeptCode(next.getDeptCode());
|
|
|
|
|
tree.setDeptName(next.getDeptName());
|
|
|
|
|
tree.setSupCode(next.getSupCode());
|
|
|
|
|
tree.setSupName(next.getSupName());
|
|
|
|
|
tree.setValid(next.getValid());
|
|
|
|
|
tree.setRowVersion(next.getRowVersion());
|
|
|
|
|
|
|
|
|
|
if (next.getDeptCode() != null && next.getDeptCode().split("_").length == level) {
|
|
|
|
|
allMap.put(tree.getDeptCode(), tree);
|
|
|
|
|
iterator.remove();
|
|
|
|
|
//尝试获取上级资源
|
|
|
|
|
String code = next.getDeptCode();
|
|
|
|
|
DeptTree Ptree = null;
|
|
|
|
|
while (code.contains("_")) {
|
|
|
|
|
code = code.substring(0, code.lastIndexOf("_"));
|
|
|
|
|
Ptree = allMap.get(code);
|
|
|
|
|
if (Ptree != null) break;
|
|
|
|
|
}
|
|
|
|
|
if (Ptree != null) {
|
|
|
|
|
tree.setpId(Ptree.getId());
|
|
|
|
|
Ptree.getChildren().add(tree);
|
|
|
|
|
} else {
|
|
|
|
|
data.add(tree);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
level++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response.setResult(data);
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|