Former-commit-id: c3f6dc18df853928631a6bb29497c8bb50e7eae9
master
wangbing 5 years ago
parent 80335ef7db
commit f947b14c4c

@ -3,27 +3,29 @@ package ${basePackage}.action.ajax.system;
import com.fasterxml.jackson.core.TreeNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.multipart.MultipartFile;
import ${basePackage}.frame.excel.WSheet;
import ${basePackage}.frame.utils.LogUtil;
import ${basePackage}.frame.auth.LocalData;
import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.base.ErrorType;
import ${basePackage}.frame.excel.WSheet;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.frame.utils.LogUtil;
import ${basePackage}.frame.utils.MapperUtil;
import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.utils.ResponseUtil;
import ${basePackage}.frame.utils.ValidationUtil;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.module.system.ent.Dept;
import ${basePackage}.module.system.mgr.DeptManager;
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.DeptTreeRequest;
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.DeptTreeResponse;
import ${basePackage}.module.system.rsp.DeptUpdateResponse;
import java.io.IOException;
@ -54,6 +56,10 @@ public class DeptAjax{
return deptManager.get(request, LocalData.getToken());
}
public DeptTreeResponse tree(DeptTreeRequest request) {
return deptManager.tree(request, LocalData.getToken());
}
public Object template() {
return ResponseUtil.apply(new WSheet<>(Dept.class));
}

@ -0,0 +1,34 @@
package xyz.wbsite.module.system.ent;
import java.util.ArrayList;
import java.util.List;
/**
* DEPT -
*
* @author wangbing
* @version 0.0.1
* @since 2019-12-24
*/
public class DeptTree extends Dept {
private Long pId;
private List<DeptTree> children = new ArrayList<>();
public Long getpId() {
return pId;
}
public void setpId(Long pId) {
this.pId = pId;
}
public List<DeptTree> getChildren() {
return children;
}
public void setChildren(List<DeptTree> children) {
this.children = children;
}
}

@ -1,16 +1,18 @@
package ${basePackage}.module.system.mgr;
package xyz.wbsite.module.system.mgr;
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;
import ${basePackage}.frame.base.Token;
import xyz.wbsite.frame.base.Token;
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;
/**
*
@ -65,4 +67,13 @@ public interface DeptManager {
* @return
*/
DeptGetResponse get(DeptGetRequest request, Token token);
/**
*
*
* @param request
* @param token
* @return
*/
DeptTreeResponse tree(DeptTreeRequest request, Token token);
}

@ -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;
}
}

@ -34,18 +34,6 @@ public class DeptCreateRequest extends BaseRequest {
@Length(min = 0, max = 50, message = "[deptAlias]部门别名长度不合法(0-50)")
private String deptAlias;
/**
*
*/
@Length(min = 0, max = 50, message = "[supCode]上级代码长度不合法(0-50)")
private String supCode;
/**
*
*/
@Length(min = 0, max = 100, message = "[supName]上级名称长度不合法(0-100)")
private String supName;
/**
*
*/
@ -76,22 +64,6 @@ public class DeptCreateRequest extends BaseRequest {
this.deptAlias = deptAlias;
}
public String getSupCode() {
return this.supCode;
}
public void setSupCode(String supCode) {
this.supCode = supCode;
}
public String getSupName() {
return this.supName;
}
public void setSupName(String supName) {
this.supName = supName;
}
public Boolean getValid() {
return this.valid;
}

@ -0,0 +1,14 @@
package xyz.wbsite.module.system.req;
import xyz.wbsite.frame.base.BaseRequest;
/**
* ResourceTreeRequest -
*
* @author wangbing
* @version 0.0.1
* @since 2019-12-26
*/
public class DeptTreeRequest extends BaseRequest {
}

@ -0,0 +1,15 @@
package xyz.wbsite.module.system.rsp;
import xyz.wbsite.frame.base.BaseFindResponse;
import xyz.wbsite.module.system.ent.DeptTree;
/**
* ResourceTreeResponse -
*
* @author author
* @version 0.0.1
* @since 2017-01-01
*/
public class DeptTreeResponse extends BaseFindResponse<DeptTree> {
}

@ -151,7 +151,8 @@
<el-row>
<el-col :span="12">
<el-input v-model="treeKeyword" clearable size="mini" placeholder="请输入资源内容" @change="onChange" style="width: 200px;" ></el-input>
<el-input v-model="treeKeyword" clearable size="mini" placeholder="请输入资源内容" @change="onChange"
style="width: 200px;"></el-input>
</el-col>
<el-col :span="12">
<el-button-group style="float: right;">
@ -176,7 +177,7 @@
:filter-node-method="filterTree"
:expand-on-click-node="false">
<div class="tree" slot-scope="{ node, data }">
<span>{{ data.comment }}<span style="color: #409EFF">[{{data.code}}]</span></span>
<span>{{ data.deptName }}<span style="color: #409EFF">[{{data.deptCode}}]</span></span>
<span>
<el-button
icon="el-icon-plus"
@ -209,12 +210,6 @@
<el-form-item label="部门别名" prop="deptAlias">
<el-input v-model="form.deptAlias" clearable size="small" placeholder="请输入部门别名"></el-input>
</el-form-item>
<el-form-item label="上级代码" prop="supCode">
<el-input v-model="form.supCode" clearable size="small" placeholder="请输入上级代码"></el-input>
</el-form-item>
<el-form-item label="上级名称" prop="supName">
<el-input v-model="form.supName" clearable size="small" placeholder="请输入上级名称"></el-input>
</el-form-item>
<el-form-item label="是否有效" prop="valid">
<el-radio-group v-model="form.valid" clearable size="small">
<el-radio :label="true">是</el-radio>
@ -228,6 +223,16 @@
</span>
</el-dialog>
</div>
<style>
.tree {
flex: auto;
display: flex;
align-items: center;
justify-content: space-between;
font-size: 14px;
padding-right: 8px;
}
</style>
<script>
var app = new Vue({
mixins: [mixin],
@ -272,16 +277,12 @@
deptAlias: [
{min: 1, max: 50, message: '部门别名长度在 1 到 50 个字符', trigger: 'blur'}
],
supCode: [
{min: 1, max: 50, message: '上级代码长度在 1 到 50 个字符', trigger: 'blur'}
],
supName: [
{min: 1, max: 100, message: '上级名称长度在 1 到 100 个字符', trigger: 'blur'}
],
valid: [
{required: true, message: '是否有效不能为空', trigger: 'blur'},
],
}
},
treeKeyword: '',
treeData: []
},
methods: {
onCreate: function () {
@ -291,9 +292,33 @@
this.form.deptCode = "";
this.form.deptName = "";
this.form.deptAlias = "";
this.form.supCode = "";
this.form.supName = "";
this.form.valid = "";
this.form.valid = true;
},
onTreeCreate: function (pItem) {
this.form.title = "部门新增";
this.form.dialog = true;
this.form.id = "";
this.form.deptCode = pItem.deptCode + "_";
this.form.deptName = "";
this.form.deptAlias = "";
this.form.valid = true;
},
onTreeEdit: function (item) {
this.form.title = "部门编辑";
this.form.dialog = true;
this.form.id = item.id;
this.form.deptCode = item.deptCode;
this.form.deptName = item.deptName;
this.form.deptAlias = item.deptAlias;
this.form.valid = item.valid;
this.form.rowVersion = item.rowVersion;
},
onChange: function (value) {
this.$refs.tree.filter(value);
},
filterTree: function (value, data) {
if (!value) return true;
return data.deptName.indexOf(value) !== -1;
},
onCommand: function (arg) {
const cmd = arg[0];
@ -306,8 +331,6 @@
this.form.deptCode = item.deptCode;
this.form.deptName = item.deptName;
this.form.deptAlias = item.deptAlias;
this.form.supCode = item.supCode;
this.form.supName = item.supName;
this.form.valid = item.valid;
this.form.rowVersion = item.rowVersion;
break;
@ -319,9 +342,60 @@
break;
}
},
onLoadTree: function () {
this.$ajax.post({
module: this.module,
target: this.target,
method: "tree",
data: {}
}).then(function (response) {
if (response.errors.length > 0) {
this.e(response.errors[0].message);
} else {
this.treeData = response.result;
}
}.bind(this))
},
onSave: function () {
this.$refs['form'].validate(function (valid) {
if (valid) {
if (this.form.id) {
this.$ajax.update(this.module, this.target, this.form).then(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
this.onFind();
this.onLoadTree();
this.$refs['form'].resetFields();
this.form.dialog = false;
}
}.bind(this))
} else {
this.$ajax.create(this.module, this.target, this.form).then(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
this.onFind();
this.onLoadTree();
this.$refs['form'].resetFields();
this.form.dialog = false;
}
}.bind(this))
}
} else {
return false;
}
}.bind(this));
},
},
watch: {
treeKeyword: function (val) {
this.$refs.tree.filter(val);
}
},
mounted: function () {
this.onFind();
this.onLoadTree();
},
})
</script>

@ -367,6 +367,37 @@
}
}.bind(this))
},
onSave: function () {
this.$refs['form'].validate(function (valid) {
if (valid) {
if (this.form.id) {
this.$ajax.update(this.module, this.target, this.form).then(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
this.onFind();
this.onLoadTree();
this.$refs['form'].resetFields();
this.form.dialog = false;
}
}.bind(this))
} else {
this.$ajax.create(this.module, this.target, this.form).then(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
this.onFind();
this.onLoadTree();
this.$refs['form'].resetFields();
this.form.dialog = false;
}
}.bind(this))
}
} else {
return false;
}
}.bind(this));
},
},
watch: {
treeKeyword:function(val) {

@ -1,15 +1,16 @@
package ${basePackage}.system;
package xyz.wbsite.system;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import ${basePackage}.frame.base.Token;
import ${basePackage}.module.system.mgr.DeptManager;
import ${basePackage}.module.system.req.*;
import ${basePackage}.module.system.rsp.*;
import xyz.wbsite.frame.base.Token;
import xyz.wbsite.module.system.mgr.DeptManager;
import xyz.wbsite.module.system.req.*;
import xyz.wbsite.module.system.rsp.*;
import static org.junit.Assert.assertTrue;
@ -33,30 +34,36 @@ public class DeptTest {
private DeptManager deptManager;
@Test
@Rollback(false)
public void testCreate() {
{
DeptCreateRequest request = new DeptCreateRequest();
request.setDeptCode("部门代码");
request.setDeptName("部门名称");
request.setDeptAlias("部门别名");
request.setSupCode("上级代码");
request.setSupName("上级名称");
request.setDeptCode("A00");
request.setDeptName("开发部");
request.setDeptAlias("开发部");
request.setValid(true);
DeptCreateResponse response = deptManager.create(request,token);
assertTrue(!response.hasError());
}
{
DeptCreateRequest request = new DeptCreateRequest();
request.setDeptCode("A00_B00");
request.setDeptName("开发部开发一组");
request.setDeptAlias("开发一组");
request.setValid(true);
DeptCreateResponse response = deptManager.create(request,token);
assertTrue(!response.hasError());
}
}
@Test
public void testDelete() {
//创建数据
DeptCreateRequest createRequest = new DeptCreateRequest();
createRequest.setDeptCode("部门代码");
createRequest.setDeptName("部门名称");
createRequest.setDeptAlias("部门别名");
createRequest.setSupCode("上级代码");
createRequest.setSupName("上级名称");
createRequest.setDeptCode("A00");
createRequest.setDeptName("开发部");
createRequest.setDeptAlias("开发部");
createRequest.setValid(true);
DeptCreateResponse createResponse = deptManager.create(createRequest,token);
@ -75,11 +82,9 @@ public class DeptTest {
public void testUpdate() {
//创建数据
DeptCreateRequest createRequest = new DeptCreateRequest();
createRequest.setDeptCode("部门代码");
createRequest.setDeptName("部门名称");
createRequest.setDeptAlias("部门别名");
createRequest.setSupCode("上级代码");
createRequest.setSupName("上级名称");
createRequest.setDeptCode("A00");
createRequest.setDeptName("开发部");
createRequest.setDeptAlias("开发部");
createRequest.setValid(true);
DeptCreateResponse createResponse = deptManager.create(createRequest, token);
@ -89,11 +94,9 @@ public class DeptTest {
//更新数据
DeptUpdateRequest request = new DeptUpdateRequest();
request.setId(createResponse.getId());
request.setDeptCode("部门代码");
request.setDeptName("部门名称");
request.setDeptAlias("部门别名");
request.setSupCode("上级代码");
request.setSupName("上级名称");
request.setDeptCode("A00");
request.setDeptName("开发部");
request.setDeptAlias("开发部");
request.setValid(true);
DeptUpdateResponse response = deptManager.update(request,token);
@ -104,11 +107,9 @@ public class DeptTest {
@Test
public void testFind() {
DeptFindRequest request = new DeptFindRequest();
request.setDeptCode("部门代码");
request.setDeptName("部门名称");
request.setDeptAlias("部门别名");
request.setSupCode("上级代码");
request.setSupName("上级名称");
request.setDeptCode("A00");
request.setDeptName("开发部");
request.setDeptAlias("开发部");
request.setValid(true);
DeptFindResponse response = deptManager.find(request,token);
@ -120,11 +121,9 @@ public class DeptTest {
public void testGet() {
//创建数据
DeptCreateRequest createRequest = new DeptCreateRequest();
createRequest.setDeptCode("部门代码");
createRequest.setDeptName("部门名称");
createRequest.setDeptAlias("部门别名");
createRequest.setSupCode("上级代码");
createRequest.setSupName("上级名称");
createRequest.setDeptCode("A00");
createRequest.setDeptName("开发部");
createRequest.setDeptAlias("开发部");
createRequest.setValid(true);
DeptCreateResponse createResponse = deptManager.create(createRequest, token);

Loading…
Cancel
Save

Powered by TurnKey Linux.