项目可见性配置
parent
200834ea8e
commit
8ad4b00662
|
@ -4,14 +4,14 @@ package cn.palmte.work.bean;
|
|||
* { id:2, pId:0, name:"随意勾选 2", checked:true, open:true},
|
||||
* @author xiongshiyan at 2021/11/18 , contact me with email yanshixiong@126.com or phone 15208384257
|
||||
*/
|
||||
public class ZtreeNode {
|
||||
public class ZTreeNode {
|
||||
private String id;
|
||||
private String pId;
|
||||
private String name;
|
||||
private boolean checked;
|
||||
private boolean open = true;
|
||||
private boolean checked = false;
|
||||
private boolean open = false;
|
||||
|
||||
public ZtreeNode(String id, String pId, String name, boolean checked, boolean open) {
|
||||
public ZTreeNode(String id, String pId, String name, boolean checked, boolean open) {
|
||||
this.id = id;
|
||||
this.pId = pId;
|
||||
this.name = name;
|
||||
|
@ -19,6 +19,12 @@ public class ZtreeNode {
|
|||
this.open = open;
|
||||
}
|
||||
|
||||
public ZTreeNode(String id, String pId, String name) {
|
||||
this.id = id;
|
||||
this.pId = pId;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
|
@ -16,7 +16,6 @@ import com.alibaba.fastjson.JSON;
|
|||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.activiti.engine.HistoryService;
|
||||
import org.activiti.engine.RuntimeService;
|
||||
import org.activiti.engine.history.HistoricProcessInstance;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -456,8 +455,17 @@ public class ProjectController extends BaseController {
|
|||
actProcInsService.createProcInsPng(response, relationList.get(0).getProcessInsId());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 进入选择页面
|
||||
*/
|
||||
@RequestMapping("/selectRoleUser")
|
||||
public String selectRoleUser(@RequestParam int projectId, Map<String, Object> model) {
|
||||
model.put("project", projectService.getProject(projectId));
|
||||
return "admin/project_select_role_user";
|
||||
}
|
||||
/**
|
||||
* 获取当前所有的角色和角色下的用户,根据项目决定是否check
|
||||
*/
|
||||
@RequestMapping("/roleUsers")
|
||||
@ResponseBody
|
||||
public ResponseMsg roleUsers(@RequestParam int projectId) {
|
||||
|
@ -468,15 +476,32 @@ public class ProjectController extends BaseController {
|
|||
{ id:21, pId:2, name:"随意勾选 2-1"},
|
||||
{ id:22, pId:2, name:"随意勾选 2-2", open:true},
|
||||
{ id:23, pId:2, name:"随意勾选 2-3"}*/
|
||||
List<ZtreeNode> ztreeNodes = new ArrayList<>();
|
||||
ztreeNodes.add(new ZtreeNode("1","0","随意勾选 1",false,true));
|
||||
ztreeNodes.add(new ZtreeNode("11","1","随意勾选 1-1",false,true));
|
||||
ztreeNodes.add(new ZtreeNode("12","1","随意勾选 1-2",false,true));
|
||||
ztreeNodes.add(new ZtreeNode("2","0","随意勾选 2",false,true));
|
||||
ztreeNodes.add(new ZtreeNode("21","2","随意勾选 2-1",false,true));
|
||||
ztreeNodes.add(new ZtreeNode("22","2","随意勾选 2-2",false,true));
|
||||
ztreeNodes.add(new ZtreeNode("23","2","随意勾选 2-3",false,true));
|
||||
return ResponseMsg.buildSuccessData(ztreeNodes);
|
||||
List<ZTreeNode> zTreeNodes = projectService.getZTreeNodes(projectId);
|
||||
return ResponseMsg.buildSuccessData(zTreeNodes);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存项目与用户的关系
|
||||
*/
|
||||
@RequestMapping("/saveSelectRoleUser")
|
||||
@ResponseBody
|
||||
public ResponseMsg saveSelectRoleUser(@RequestBody String body) {
|
||||
/*{ id:1, pId:0, name:"随意勾选 1", open:true},
|
||||
{ id:11, pId:1, name:"随意勾选 1-1", open:true},
|
||||
{ id:12, pId:1, name:"随意勾选 1-2", open:true},
|
||||
{ id:2, pId:0, name:"随意勾选 2", checked:true, open:true},
|
||||
{ id:21, pId:2, name:"随意勾选 2-1"},
|
||||
{ id:22, pId:2, name:"随意勾选 2-2", open:true},
|
||||
{ id:23, pId:2, name:"随意勾选 2-3"}*/
|
||||
JSONObject jsonObject = JSON.parseObject(body);
|
||||
Integer projectId = jsonObject.getInteger("projectId");
|
||||
JSONArray array = jsonObject.getJSONArray("ids");
|
||||
String[] ids = new String[array.size()];
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
ids[i] = array.getString(i);
|
||||
}
|
||||
projectService.saveProjectVisible(projectId, ids);
|
||||
return ResponseMsg.buildSuccessMsg("成功");
|
||||
}
|
||||
|
||||
@InitBinder
|
||||
|
|
|
@ -11,6 +11,8 @@ import javax.persistence.*;
|
|||
@Entity
|
||||
@Table(name = "project_visible")
|
||||
public class ProjectVisible {
|
||||
public static final int TYPE_ROLE = 1;
|
||||
public static final int TYPE_USER = 2;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
|
@ -21,8 +23,9 @@ public class ProjectVisible {
|
|||
|
||||
/**
|
||||
* 1按照角色,2按照人员
|
||||
* 为了简便,目前只存人员
|
||||
*/
|
||||
private String type;
|
||||
private int type;
|
||||
|
||||
private int tid;
|
||||
|
||||
|
|
|
@ -3,5 +3,9 @@ package cn.palmte.work.model;
|
|||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ProjectVisibleRepository extends JpaRepository<ProjectVisible, Integer> {
|
||||
List<ProjectVisible> findAllByProjectIdEqualsAndTypeEquals(int projectId, int type);
|
||||
List<ProjectVisible> findAllByProjectIdEquals(int projectId);
|
||||
}
|
||||
|
|
|
@ -7,16 +7,14 @@ import com.alibaba.fastjson.JSON;
|
|||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import top.jfunc.common.db.QueryHelper;
|
||||
import top.jfunc.common.db.bean.Page;
|
||||
import top.jfunc.common.db.utils.Pagination;
|
||||
import top.jfunc.common.utils.CollectionUtil;
|
||||
import top.jfunc.common.utils.StrUtil;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author xiongshiyan at 2021/10/29 , contact me with email yanshixiong@126.com or phone 15208384257
|
||||
|
@ -33,6 +31,14 @@ public class ProjectService {
|
|||
private ActTaskDefService actTaskDefService;
|
||||
@Autowired
|
||||
private ProjectInstanceRelationRepository projectInstanceRelationRepository;
|
||||
@Autowired
|
||||
private DeptRepository deptRepository;
|
||||
@Autowired
|
||||
private ProjectVisibleRepository projectVisibleRepository;
|
||||
@Autowired
|
||||
private SysRoleRepository sysRoleRepository;
|
||||
@Autowired
|
||||
private AdminRepository adminRepository;
|
||||
|
||||
|
||||
private QueryHelper getQueryHelper(Map<String, String> searchInfo) {
|
||||
|
@ -96,7 +102,8 @@ public class ProjectService {
|
|||
Admin admin = InterfaceUtil.getAdmin();
|
||||
int roleId = admin.getRoleId();
|
||||
Integer adminId = admin.getId();
|
||||
queryHelper.addCondition("p.id in (SELECT pv1.project_id FROM project_visible pv1 WHERE pv1.type=1 AND pv1.tid=? UNION SELECT pv2.project_id FROM project_visible pv2 WHERE pv2.type=2 AND pv2.tid=?)", roleId, adminId);
|
||||
//自己创建的肯定能看见
|
||||
queryHelper.addCondition("(p.creator_id=? OR p.id in (SELECT pv1.project_id FROM project_visible pv1 WHERE pv1.type=1 AND pv1.tid=? UNION SELECT pv2.project_id FROM project_visible pv2 WHERE pv2.type=2 AND pv2.tid=?))", adminId, roleId, adminId);
|
||||
|
||||
|
||||
return queryHelper;
|
||||
|
@ -143,9 +150,9 @@ public class ProjectService {
|
|||
project.setApproveId(0);
|
||||
project.setApproveName("");
|
||||
|
||||
//TODO 获取登录人的部门信息
|
||||
project.setDeptId(admin.getId());
|
||||
project.setDeptName("工程部");
|
||||
Dept one = deptRepository.findOne(admin.getDeptId());
|
||||
project.setDeptId(one.getId());
|
||||
project.setDeptName(one.getName());
|
||||
|
||||
Date now = new Date();
|
||||
project.setCreateTime(now);
|
||||
|
@ -218,4 +225,77 @@ public class ProjectService {
|
|||
one.setLastUpdateTime(new Date());
|
||||
projectRepository.saveAndFlush(one);
|
||||
}
|
||||
|
||||
|
||||
private static final String PREFIX_ROLE = "r-";
|
||||
private static final String PREFIX_USER = "u-";
|
||||
/**
|
||||
* 把所有的角色和人员按照层级返回
|
||||
*/
|
||||
public List<ZTreeNode> getZTreeNodes(int projectId){
|
||||
List<SysRole> roleList = sysRoleRepository.findAllRole();
|
||||
List<Admin> adminList = adminRepository.getAllEnable();
|
||||
List<ZTreeNode> zTreeNodes = new ArrayList<>(roleList.size()+adminList.size());
|
||||
|
||||
List<ProjectVisible> projectVisibles = projectVisibleRepository.findAllByProjectIdEquals(projectId);
|
||||
List<ProjectVisible> visibleRoleList = filterByType(projectVisibles, ProjectVisible.TYPE_ROLE);
|
||||
List<ProjectVisible> visibleUserList = filterByType(projectVisibles, ProjectVisible.TYPE_USER);
|
||||
|
||||
|
||||
for (SysRole sysRole : roleList) {
|
||||
zTreeNodes.add(new ZTreeNode(PREFIX_ROLE + sysRole.getId(), "0", sysRole.getName(),
|
||||
isChecked(visibleRoleList, sysRole.getId()), false));
|
||||
zTreeNodes.addAll(filterAdmins(adminList, sysRole, visibleUserList));
|
||||
}
|
||||
|
||||
return zTreeNodes;
|
||||
}
|
||||
|
||||
private List<ZTreeNode> filterAdmins(List<Admin> adminList, SysRole sysRole, List<ProjectVisible> visibleUserList) {
|
||||
List<Admin> admins = adminList.stream()
|
||||
.filter(a -> sysRole.getId() == a.getRoleId())
|
||||
.collect(Collectors.toList());
|
||||
if(CollectionUtil.isNotEmpty(admins)){
|
||||
ArrayList<ZTreeNode> zTreeNodes = new ArrayList<>(admins.size());
|
||||
for (Admin admin : admins) {
|
||||
zTreeNodes.add(new ZTreeNode(PREFIX_USER+admin.getId(),PREFIX_ROLE+sysRole.getId(),admin.getRealName(),
|
||||
isChecked(visibleUserList, admin.getId()),false));
|
||||
}
|
||||
return zTreeNodes;
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private boolean isChecked(List<ProjectVisible> visibleList, int id) {
|
||||
return visibleList.stream().anyMatch(pv->pv.getTid()==id);
|
||||
}
|
||||
private List<ProjectVisible> filterByType(List<ProjectVisible> projectVisibles, int type){
|
||||
if(CollectionUtil.isEmpty(projectVisibles)){
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return projectVisibles.stream().filter(pv -> pv.getType() == type).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void saveProjectVisible(Integer projectId, String[] idss) {
|
||||
//1.先清除以前的
|
||||
List<ProjectVisible> projectVisibles = projectVisibleRepository.findAllByProjectIdEquals(projectId);
|
||||
if(CollectionUtil.isNotEmpty(projectVisibles)){
|
||||
projectVisibleRepository.deleteInBatch(projectVisibles);
|
||||
}
|
||||
//2.再保存
|
||||
List<ProjectVisible> pvs = new ArrayList<>(idss.length);
|
||||
for (String s : idss) {
|
||||
//只要用户的,角色的不要
|
||||
if(s.startsWith(PREFIX_USER)){
|
||||
ProjectVisible pv = new ProjectVisible();
|
||||
pv.setProjectId(projectId);
|
||||
pv.setType(ProjectVisible.TYPE_USER);
|
||||
//去掉前缀
|
||||
pv.setTid(Integer.parseInt(s.substring(PREFIX_USER.length())));
|
||||
pvs.add(pv);
|
||||
}
|
||||
}
|
||||
projectVisibleRepository.save(pvs);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
$(function () {
|
||||
|
||||
$("#save").click(function () {
|
||||
var checkedNodes = zTreeNodes.getCheckedNodes();
|
||||
var ids = [];
|
||||
checkedNodes.forEach(function (t) {
|
||||
ids.push(t.id);
|
||||
});
|
||||
var ps = {
|
||||
projectId:$("input[name='projectId']").val(),
|
||||
ids:ids
|
||||
};
|
||||
postAjax(base+"/project/saveSelectRoleUser", ps, function (p,d) {
|
||||
window.location.href=base+"/project/list";
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
var params = {
|
||||
projectId:$("input[name='projectId']").val()
|
||||
};
|
||||
getAjax(base+"/project/roleUsers",params,function (p,d) {
|
||||
zTreeNodes = initZTree(d);
|
||||
});
|
||||
|
||||
function initZTree(data) {
|
||||
var setting = {
|
||||
check: {
|
||||
enable: true
|
||||
},
|
||||
data: {
|
||||
simpleData: {
|
||||
enable: true
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*var zNodes =[
|
||||
{ id:1, pId:0, name:"随意勾选 1", open:true},
|
||||
{ id:11, pId:1, name:"随意勾选 1-1", open:true},
|
||||
{ id:111, pId:11, name:"随意勾选 1-1-1"},
|
||||
{ id:112, pId:11, name:"随意勾选 1-1-2"},
|
||||
{ id:12, pId:1, name:"随意勾选 1-2", open:true},
|
||||
{ id:121, pId:12, name:"随意勾选 1-2-1"},
|
||||
{ id:122, pId:12, name:"随意勾选 1-2-2"},
|
||||
{ id:2, pId:0, name:"随意勾选 2", checked:true, open:true},
|
||||
{ id:21, pId:2, name:"随意勾选 2-1"},
|
||||
{ id:22, pId:2, name:"随意勾选 2-2", open:true},
|
||||
{ id:221, pId:22, name:"随意勾选 2-2-1", checked:true},
|
||||
{ id:222, pId:22, name:"随意勾选 2-2-2"},
|
||||
{ id:23, pId:2, name:"随意勾选 2-3"}
|
||||
];*/
|
||||
var zTreeNodes = $.fn.zTree.init($("#treeSelectRoleUser"), setting, data.data);
|
||||
return zTreeNodes;
|
||||
}
|
||||
});
|
||||
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
<@defaultLayout.layout>
|
||||
<link rel="stylesheet" href="../assets/css/amazeui.switch.css"/>
|
||||
<link rel="stylesheet" href="${base}/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
|
||||
<style>
|
||||
ul.ztree {
|
||||
margin-top: 10px;
|
||||
|
@ -214,7 +213,7 @@
|
|||
<div class="am-btn-group am-btn-group-xs">
|
||||
<button type="button"
|
||||
class="am-btn am-btn-default am-btn-xs am-text-secondary"
|
||||
onclick="selectRoleUser(${list.id}, this)"><span class="am-icon-pencil-square-o"></span>设置项目可见性
|
||||
onclick="location.href='${base}/project/selectRoleUser?projectId=${list.id}'"><span class="am-icon-pencil-square-o"></span>设置项目可见性
|
||||
</button>
|
||||
<#--<@shiro.hasPermission name="PROJECT_EDIT">-->
|
||||
<#--概算状态 并且概算审批状态为草稿和不通过-->
|
||||
|
@ -324,7 +323,7 @@
|
|||
|
||||
|
||||
|
||||
<div class="am-modal am-modal-prompt" tabindex="-1" id="my-prompt-select-role-user">
|
||||
<#--<div class="am-modal am-modal-prompt" tabindex="-1" id="my-prompt-select-role-user">
|
||||
<div class="am-modal-dialog">
|
||||
<div class="am-modal-hd">请选择项目可见性</div>
|
||||
<div class="am-modal-bd">
|
||||
|
@ -336,7 +335,7 @@
|
|||
<span class="am-modal-btn" data-am-modal-confirm>提交</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>-->
|
||||
|
||||
<footer class="admin-content-footer">
|
||||
<hr>
|
||||
|
@ -411,47 +410,4 @@
|
|||
|
||||
});
|
||||
|
||||
|
||||
function selectRoleUser(projectId) {
|
||||
|
||||
|
||||
getAjax("${base}/project/roleUsers?projectId="+projectId,null,function (p,d) {
|
||||
var setting = {
|
||||
check: {
|
||||
enable: true
|
||||
},
|
||||
data: {
|
||||
simpleData: {
|
||||
enable: true
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*var zNodes =[
|
||||
{ id:1, pId:0, name:"随意勾选 1", open:true},
|
||||
{ id:11, pId:1, name:"随意勾选 1-1", open:true},
|
||||
{ id:111, pId:11, name:"随意勾选 1-1-1"},
|
||||
{ id:112, pId:11, name:"随意勾选 1-1-2"},
|
||||
{ id:12, pId:1, name:"随意勾选 1-2", open:true},
|
||||
{ id:121, pId:12, name:"随意勾选 1-2-1"},
|
||||
{ id:122, pId:12, name:"随意勾选 1-2-2"},
|
||||
{ id:2, pId:0, name:"随意勾选 2", checked:true, open:true},
|
||||
{ id:21, pId:2, name:"随意勾选 2-1"},
|
||||
{ id:22, pId:2, name:"随意勾选 2-2", open:true},
|
||||
{ id:221, pId:22, name:"随意勾选 2-2-1", checked:true},
|
||||
{ id:222, pId:22, name:"随意勾选 2-2-2"},
|
||||
{ id:23, pId:2, name:"随意勾选 2-3"}
|
||||
];*/
|
||||
$.fn.zTree.init($("#treeSelectRoleUser"), setting, d.data);
|
||||
|
||||
$("#my-prompt-select-role-user").modal({
|
||||
relatedTarget: $(this),
|
||||
onConfirm: function(e) {
|
||||
postAjax("${base}/project/selectRoleUser", data, null);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<#assign base=request.contextPath />
|
||||
<#import "../common/defaultLayout.ftl" as defaultLayout>
|
||||
<@defaultLayout.layout>
|
||||
<link rel="stylesheet" href="${base}/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
|
||||
<div class="admin-content">
|
||||
<div class="admin-content-body">
|
||||
<div class="am-cf am-padding">
|
||||
<div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">项目管理</strong> / <small>请选择${project.name}的可见性</small></div>
|
||||
</div>
|
||||
|
||||
<input type="hidden" name="projectId" value="${project.id}">
|
||||
|
||||
请勾选能够看到该项目的人员或角色
|
||||
<ul id="treeSelectRoleUser" class="ztree"></ul>
|
||||
<div class="am-margin">
|
||||
<button type="button" class="am-btn am-btn-warning am-btn-xs" onclick="javascript:history.go(-1);">返回上一级</button>
|
||||
<button type="button" class="am-btn am-btn-primary am-btn-xs" id="save">保存</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</@defaultLayout.layout>
|
||||
<script>
|
||||
var base = "${base}";
|
||||
</script>
|
||||
<script src="${base}/assets/js/project_common.js"></script>
|
||||
<script type="text/javascript" src="${base}/ztree/js/jquery.ztree.core.js"></script>
|
||||
<script type="text/javascript" src="${base}/ztree/js/jquery.ztree.excheck.js"></script>
|
||||
<script type="text/javascript" src="${base}/ztree/js/jquery.ztree.exedit.js"></script>
|
||||
<script src="${base}/assets/js/project_select_role_user.js"></script>
|
Loading…
Reference in New Issue