Former-commit-id: 2be4735809235ca6657b82c2a0f1aa481acadc97
master
wangbing 5 years ago
parent 7f838050ca
commit 35a070acdd

@ -1,25 +1,15 @@
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.ErrorType;
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.RoleResource;
import ${basePackage}.module.system.mgr.RoleResourceManager;
import ${basePackage}.module.system.req.RoleResourceCheckRequest;
import ${basePackage}.module.system.req.RoleResourceCreateRequest;
import ${basePackage}.module.system.req.RoleResourceDeleteRequest;
import ${basePackage}.module.system.req.RoleResourceFindRequest;
import ${basePackage}.module.system.req.RoleResourceGetRequest;
import ${basePackage}.module.system.req.RoleResourceUpdateRequest;
import ${basePackage}.module.system.rsp.RoleResourceCheckResponse;
import ${basePackage}.module.system.rsp.RoleResourceCreateResponse;
import ${basePackage}.module.system.rsp.RoleResourceDeleteResponse;
import ${basePackage}.module.system.rsp.RoleResourceFindResponse;
@ -53,4 +43,8 @@ public class RoleResourceAjax{
public RoleResourceGetResponse get(RoleResourceGetRequest request) {
return roleResourceManager.get(request, LocalData.getToken());
}
public RoleResourceCheckResponse check(RoleResourceCheckRequest request) {
return roleResourceManager.check(request, LocalData.getToken());
}
}

@ -1,19 +1,7 @@
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.ErrorType;
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.UserRole;
import ${basePackage}.module.system.mgr.UserRoleManager;
import ${basePackage}.module.system.req.UserRoleCreateRequest;
import ${basePackage}.module.system.req.UserRoleDeleteRequest;

@ -1,11 +1,13 @@
package ${basePackage}.module.system.mgr;
import ${basePackage}.frame.base.Token;
import ${basePackage}.module.system.req.RoleResourceCheckRequest;
import ${basePackage}.module.system.req.RoleResourceCreateRequest;
import ${basePackage}.module.system.req.RoleResourceDeleteRequest;
import ${basePackage}.module.system.req.RoleResourceFindRequest;
import ${basePackage}.module.system.req.RoleResourceGetRequest;
import ${basePackage}.module.system.req.RoleResourceUpdateRequest;
import ${basePackage}.module.system.rsp.RoleResourceCheckResponse;
import ${basePackage}.module.system.rsp.RoleResourceCreateResponse;
import ${basePackage}.module.system.rsp.RoleResourceDeleteResponse;
import ${basePackage}.module.system.rsp.RoleResourceFindResponse;
@ -65,4 +67,13 @@ public interface RoleResourceManager {
* @return
*/
RoleResourceGetResponse get(RoleResourceGetRequest request, Token token);
/**
*
*
* @param request
* @param token
* @return
*/
RoleResourceCheckResponse check(RoleResourceCheckRequest request, Token token);
}

@ -6,6 +6,7 @@ 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 org.springframework.transaction.interceptor.TransactionAspectSupport;
import ${basePackage}.frame.base.ErrorType;
import ${basePackage}.frame.base.Token;
import ${basePackage}.frame.utils.IDgenerator;
@ -14,11 +15,13 @@ import ${basePackage}.frame.utils.Message;
import ${basePackage}.frame.utils.ValidationUtil;
import ${basePackage}.module.system.ent.RoleResource;
import ${basePackage}.module.system.mpr.RoleResourceMapper;
import ${basePackage}.module.system.req.RoleResourceCheckRequest;
import ${basePackage}.module.system.req.RoleResourceCreateRequest;
import ${basePackage}.module.system.req.RoleResourceDeleteRequest;
import ${basePackage}.module.system.req.RoleResourceFindRequest;
import ${basePackage}.module.system.req.RoleResourceGetRequest;
import ${basePackage}.module.system.req.RoleResourceUpdateRequest;
import ${basePackage}.module.system.rsp.RoleResourceCheckResponse;
import ${basePackage}.module.system.rsp.RoleResourceCreateResponse;
import ${basePackage}.module.system.rsp.RoleResourceDeleteResponse;
import ${basePackage}.module.system.rsp.RoleResourceFindResponse;
@ -172,4 +175,53 @@ public class RoleResourceManagerImpl implements RoleResourceManager {
return response;
}
/**
*
*
* @param request
* @param token
* @return
*/
public RoleResourceCheckResponse check(RoleResourceCheckRequest request, Token token) {
RoleResourceCheckResponse response = new RoleResourceCheckResponse();
ValidationUtil.validate(request, response);
if (response.hasError()) {
return response;
}
RoleResourceFindRequest roleResourceFindRequest = new RoleResourceFindRequest();
roleResourceFindRequest.setRoleId(request.getRoleId());
roleResourceFindRequest.setResourceId(request.getResourceId());
RoleResourceFindResponse roleResourceFindResponse = this.find(roleResourceFindRequest, token);
if (roleResourceFindResponse.hasError()) {
response.addErrors(roleResourceFindResponse.getErrors());
return response;
}
if (request.getChecked() && roleResourceFindResponse.getResult().size() == 0) {
RoleResourceCreateRequest roleResourceCreateRequest = new RoleResourceCreateRequest();
roleResourceCreateRequest.setRoleId(request.getRoleId());
roleResourceCreateRequest.setResourceId(request.getResourceId());
RoleResourceCreateResponse roleResourceCreateResponse = this.create(roleResourceCreateRequest, token);
if (roleResourceCreateResponse.hasError()) {
response.addErrors(roleResourceCreateResponse.getErrors());
return response;
}
} else if (!request.getChecked() && roleResourceFindResponse.getResult().size() > 0) {
for (RoleResource roleResource : roleResourceFindResponse.getResult()) {
RoleResourceDeleteRequest roleResourceDeleteRequest = new RoleResourceDeleteRequest();
roleResourceDeleteRequest.setId(roleResource.getId());
RoleResourceDeleteResponse roleResourceDeleteResponse = this.delete(roleResourceDeleteRequest, token);
if (roleResourceDeleteResponse.hasError()) {
response.addErrors(roleResourceDeleteResponse.getErrors());
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return response;
}
}
}
return response;
}
}

@ -0,0 +1,58 @@
package ${basePackage}.module.system.req;
import ${basePackage}.frame.base.BaseUpdateRequest;
import javax.validation.constraints.NotNull;
/**
* RoleResourceUpdateRequest -
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class RoleResourceCheckRequest extends BaseUpdateRequest {
/**
*
*/
@NotNull(message = "[roleId]角色主键不能为NULL")
private Long roleId;
/**
*
*/
@NotNull(message = "[resourceId]资源主键不能为NULL")
private Long resourceId;
/**
*
*/
@NotNull(message = "[checked]是否选中不能为NULL")
private Boolean checked;
public Long getRoleId() {
return this.roleId;
}
public void setRoleId(Long roleId) {
this.roleId = roleId;
}
public Long getResourceId() {
return this.resourceId;
}
public void setResourceId(Long resourceId) {
this.resourceId = resourceId;
}
public Boolean getChecked() {
return checked;
}
public void setChecked(Boolean checked) {
this.checked = checked;
}
}

@ -0,0 +1,26 @@
package ${basePackage}.module.system.rsp;
import ${basePackage}.frame.base.BaseResponse;
/**
* RoleResourceCreateResponse -
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class RoleResourceCheckResponse extends BaseResponse {
/**
* ID
*/
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}

@ -90,12 +90,11 @@
width="120"
label="操作">
<template slot-scope="scope">
<el-dropdown size="mini" split-button type="primary" @click="onCommand(['edit',scope.row])"
@command="onCommand">
<i class="el-icon-edit"></i>编辑
<el-dropdown size="mini" split-button type="primary" @click="onCommand(['edit',scope.row])" @command="onCommand">
<i class="el-icon-edit">编辑</i>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item :command="['delete',scope.row]" icon="el-icon-delete">删除
</el-dropdown-item>
<el-dropdown-item :command="['resourceEdit',scope.row]" icon="el-icon-edit">分配资源</el-dropdown-item>
<el-dropdown-item :command="['delete',scope.row]" icon="el-icon-delete">删除</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</template>
@ -127,11 +126,32 @@
<el-input v-model="form.comment" clearable size="small" placeholder="请输入角色描述"></el-input>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button size="small" @click="form.dialog = false">取 消</el-button>
<el-button size="small" type="primary" @click="onSave">保存</el-button>
</span>
</el-dialog>
<el-dialog class="form-dialog" :title="formResource.title" :visible.sync="formResource.dialog">
<el-tree
:data="treeData"
show-checkbox
node-key="id"
ref="tree"
@check="onCheck"
:check-strictly="true"
:default-expand-all="true"
:expand-on-click-node="false">
<div class="tree" slot-scope="{ node, data }">
<span>{{ data.comment }}<span style="color: #409EFF">[{{data.code}}]</span></span>
</div>
</el-tree>
<span slot="footer" class="dialog-footer">
<el-button size="small" @click="formResource.dialog = false">关 闭</el-button>
</span>
</el-dialog>
</div>
<script>
var app = new Vue({
@ -159,6 +179,11 @@
comment: "",
rowVersion: ""
},
formResource: {
title: "",
dialog: false,
roleId: '',
},
formRules: {
code: [
{required: true, message: '角色代码不能为空', trigger: 'blur'},
@ -171,7 +196,8 @@
comment: [
{min: 1, max: 50, message: '角色描述长度在 1 到 50 个字符', trigger: 'blur'}
],
}
},
treeData: []
},
methods: {
onCreate: function () {
@ -195,6 +221,23 @@
this.form.comment = item.comment;
this.form.rowVersion = item.rowVersion;
break;
case "resourceEdit":
this.formResource.title = "分配资源";
this.formResource.dialog = true;
this.formResource.roleId = item.id
this.$ajax.find("system", "roleResource", {roleId: item.id, pageSize: 0}).then(function (response) {
if (response.errors.length > 0) {
this.e(response.errors[0].message);
} else {
this.$refs.tree.setCheckedKeys([]);
var ids = [];
for (var i = 0; i < response.result.length; i++) {
ids.push(response.result[i].resourceId);
}
this.$refs.tree.setCheckedKeys(ids);
}
}.bind(this));
break;
case "delete":
this.onDelete(item);
break;
@ -203,9 +246,42 @@
break;
}
},
onCheck: function (item, status) {
this.$ajax.post({
module: "system",
target: "roleResource",
method: "check",
data: {
roleId: this.formResource.roleId,
resourceId: item.id,
checked: status.checkedKeys.indexOf(item.id) !== -1,
}
}).then(function (response) {
if (response.errors.length > 0) {
this.e(response.errors[0].message);
} else {
}
}.bind(this))
},
onLoadTree: function () {
this.$ajax.post({
module: "system",
target: "resource",
method: "tree",
data: {}
}).then(function (response) {
if (response.errors.length > 0) {
this.e(response.errors[0].message);
} else {
this.treeData = response.result;
}
}.bind(this))
},
},
mounted: function () {
this.onFind();
},
this.onLoadTree();
}
})
</script>

Loading…
Cancel
Save

Powered by TurnKey Linux.