一。星云部门树
业务层
//1.先正常查出部门集合(部门实体有属性parentId和childList)
//2.所有部门dto装进map
orgDeptTreeDTOList.forEach(dto -> {
String id = dto.getId();
deptMap.put(id, dto);
dto.setChildren(new ArrayList<>());
});
//3.组成树结构
orgDeptTreeDTOList.forEach(dto -> {
OrgDeptTreeDTO parentDto = deptMap.get(dto.getParentId());
if (parentDto != null) { //如果有父节点,将当前节点添加到父节点下
parentDto.getChildren().add(dto);
} else { //如果找不到父节点,说明是顶级节点 则放到集合中返回
resultList.add(dto);
}
});
public List<StationParamDTO> stationParamList() {
//用来装载所有集合
HashMap<String, StationParamDTO> stationMap = new HashMap<>();
//用来装载最后的信息
ArrayList<StationParamDTO> resultList = new ArrayList<>();
//1.查询所有有系统配置集合
List<StationParamDTO> stationParamList = orgStationParamMapper.stationParamList();
//2.所有系统配置dto装进map
stationParamList.forEach(dto -> {
String id = dto.getId();
stationMap.put(id, dto);
dto.setChildren(new ArrayList<>());
});
//3.组成树结构
stationParamList.forEach(dto -> {
StationParamDTO parentDto = stationMap.get(dto.getParentId());
if (parentDto != null) { //如果有父节点,将当前节点添加到父节点下
parentDto.getChildren().add(dto);
} else { //如果找不到父节点,说明是顶级节点 则放到集合中返回
resultList.add(dto);
}
});
return resultList;
}
实体类
public class OrgDeptTreeDTO {
/**
* 机构ID
*/
private String id;
/**
* 机构类型:1. 运营商 2.站点 3.组织机构
*/
private int type;
/**
* 机构名称
*/
private String name;
/**
* 上级机构id
*/
private String parentId;
/**
* 子集
*/
private List<OrgDeptTreeDTO> children = new ArrayList<>();
}
二。绩效系统 前端Boostrap
关键点在service
1.Body
提供一个id,class= “ztree”
//指标页面
<div class="ui-layout-west" style="width: 210px;height:100%;float:left">
<div class="main-content">
<div class="box box-main">
<div class="box-header">
<div class="box-title">
<i class="fa icon-grid"></i> 指标列表
</div>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" id="btnExpand" title="展开"
style="display:none;"><i class="fa fa-chevron-up"></i></button>
<button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i
class="fa fa-chevron-down"></i></button>
<button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新"><i
class="fa fa-refresh"></i></button>
</div>
</div>
<div class="ui-layout-content">
<div id="indicator_tree" class="ztree"></div>
</div>
</div>
</div>
</div>
<div class="ui-layout-content">
<div id="tree" class="ztree"></div>
</div>
2.JS
var options里面有访问路径显示所有树形数据,点击事件提供id
//指标页面
function queryIndicatorTree() {
var url = ctx + "beforehand/levelIndicators/treeData";
var options = {
id: "indicator_tree",
url: url + '?indicatorName=' + indicatorName,
expandLevel: 2,
onClick: zOnClick
};
$.tree.init(options);
function zOnClick(event, treeId, treeNode) {
$("#indicatorClass").val("");
$("#firstIndicator").val("");
$("#secondIndicator").val("");
var level = treeNode.level;
if (level == 0) {
$("#indicatorClass").val(treeNode.name);
} else if (level == 1) {
$("#indicatorClass").val(treeNode.getParentNode().name);
$("#firstIndicator").val(treeNode.name);
} else if (level == 2) {
$("#indicatorClass").val(treeNode.getParentNode().getParentNode().name);
$("#firstIndicator").val(treeNode.getParentNode().name);
$("#secondIndicator").val(treeNode.name);
}
$.table.search('formId');
}
//点击展开折叠及刷新
$('#btnExpand').click(function () {
$._tree.expandAll(true);
$(this).hide();
$('#btnCollapse').show();
});
$('#btnCollapse').click(function () {
$._tree.expandAll(false);
$(this).hide();
$('#btnExpand').show();
});
$('#btnRefresh').click(function () {
queryIndicatorTree();
});
}
//项目页面
function queryProjectTree() {
var url = ctx + "beforehand/achiProjectInformation/treeData";
var options = {
url: url,
expandLevel: 2,
onClick: zOnClick
};
$.tree.init(options);
function zOnClick(event, treeId, treeNode) {
$("#projectId").val(treeNode.id);
$.ajax({
url: ctx + "beforehand/achiProjectInformation/projectInfo/" + treeNode.id,
type: "get",
dataType: "json",
beforeSend: function () {
$.modal.loading("加载数据中,请稍后...");
},
success: function (result) {
if (result.code == web_status.SUCCESS) {
console.log(result.data);
initTableData(result.data);
} else if (result.code == web_status.WARNING) {
$.modal.alertWarning(result.msg)
} else {
$.modal.alertError(result.msg);
}
}
}) ;
$.modal.closeLoading();
return false;
}
}
3.control
@RequiresPermissions("beforehand:monitor:addPage")
@GetMapping("/treeData")
@ResponseBody
public List<Ztree> treeData() {
if (ShiroUtils.getSysUser().isAdmin()) {
return achiProjectInformationService.selectProjectTree(null);
} else {
return achiProjectInformationService.selectProjectTree(ShiroUtils.getDeptId().toString());
}
}
4.service
List<Ztree> selectProjectTree(String unitCode);
//fillTree(id=1) taskReceiveTree(id=2) projectTree(id=3)
public List<Ztree> findProjectAndTaskTreeData(EvaluationReviewPo evaluationreviewpo){
List<Ztree> ztrees = new ArrayList<>();
/*最大节点 填报列表*/
Ztree fillTree = new Ztree();
fillTree.setId(new Long(1));
fillTree.setTitle("事前填报列表");
fillTree.setName("事前填报列表");
ztrees.add(fillTree);
/*中节点1 任务接收列表*/
Ztree taskReceiveTree = new Ztree();
taskReceiveTree.setId(new Long(2));
taskReceiveTree.setTitle("任务接收列表");
taskReceiveTree.setName("任务接收列表");
taskReceiveTree.setpId(new Long(1));
ztrees.add(taskReceiveTree);
/*查询任务集合*/
TaskDeliveryShiqian taskDeliveryShiqian = new TaskDeliveryShiqian();
String year1 = ShiroUtils.getSession().getAttribute("year").toString();
if (year1 == null) {
year1 = String.valueOf(new Date().getYear());
}
taskDeliveryShiqian.setYear(new Integer(year1));
taskDeliveryShiqian.setState(0);
taskDeliveryShiqian.setDeliveryState(1);
if (!ShiroUtils.getSysUser().isAdmin()){
taskDeliveryShiqian.setUnitCode(ShiroUtils.getDeptId());
taskDeliveryShiqian.setUserId(ShiroUtils.getUserId());
}
List<TaskDeliveryShiqian> deliveryList = taskDeliveryShiqianService.selectTaskDeliveryShiqianList(taskDeliveryShiqian);
/*添加到任务接收列表*/
if (deliveryList.size() > 0 ){
for (TaskDeliveryShiqian task: deliveryList){
Ztree taskZtree = new Ztree();
taskZtree.setId(task.getProjectId().longValue());
taskZtree.setName(task.getProjectName());
taskZtree.setTitle(task.getProjectName());
taskZtree.setpId(new Long(2));
ztrees.add(taskZtree);
}
}
/*中节点2 事前项目列表*/
if (!resultList.isEmpty()){
Ztree projectTree = new Ztree();
projectTree.setId(new Long(3));
projectTree.setTitle("项目列表");
projectTree.setName("项目列表");
projectTree.setpId(new Long(1));
ztrees.add(projectTree);
/*添加到任务接收列表*/
for (EvaluationReviewPo monitorDeclare1 : resultList) {
Ztree ztree = new Ztree();
ztree.setId(monitorDeclare1.getProjectId().longValue());
ztree.setName(monitorDeclare1.getProjectName());
ztree.setTitle(monitorDeclare1.getProjectName());
ztree.setpId(new Long(3));
ztrees.add(ztree);
}
}
return ztrees;
}
树形实体
public class Ztree implements Serializable{
private static final long serialVersionUID = 1L;
/** 节点ID */
private Long id;
/** 节点父ID */
private Long pId;
/** 节点名称 */
private String name;
/** 节点标题 */
private String title;
/** 是否勾选 */
private boolean checked = false;
/** 是否展开 */
private boolean open = false;
/** 是否能勾选 */
private boolean nocheck = false
}
DAO
public List<AchiProjectInformation> selectAchiProjectInformationList(AchiProjectInformation achiProjectInformation);
<select id="selectAchiProjectInformationList" parameterType="com.ruoyi.beforehand.domain.AchiProjectInformation" resultMap="AchiProjectInformationResult">
select unit_name,project_code, project_name, project_person, project_post, project_hone, evaluation_level, evaluation_type, project_nature,
project_undertaker, project_authorities, project_attributes, project_type, project_category, functional_code, functional_name, project_start_time,
project_end_time, distribution, actual_start_time, actual_end_time, approval_number, target_completion, unaccomplished, project_overview,
project_basis, project_feasibility, project_target, project_necessity, impl_system, impl_measures, specific_measure,subsidy_type,
is_subsidy, subsidy_region, year_total_amoun, year_public, year_fund, year_finance, year_balance, year_other, impl_total_amoun,
impl_public, impl_fund, impl_finance, impl_balance, impl_other, project_evaluation, other_evaluations, project_id,
implement_bidding,government_procurement,contract_manage,must_purchase_money,actual_purchase_money
from achi_project_information
</SELECT>