1.前台jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.4.1/themes/default/easyui.css">
<span style="white-space:pre"> </span><link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.4.1/themes/icon.css">
<span style="white-space:pre"> </span><link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.4.1/demo/demo.css">
<link type="text/css" rel="stylesheet" href="css/circle/circle-add.css" />
<link type="text/css" rel="stylesheet" href="css/zTreeStyle.css" />
<!-------工作圈创建 start------>
<div style="font-family:Microsoft YaHei;" id="creat">
<div class="main">
<div class="main_top">
<strong>创建工作圈:</strong>
<input type='text' id='circleName_input' placeholder='请输入工作圈名称' />
</div>
<br />
<div class="main_left">
<strong>选择用户成员</strong>
<input type="text" name="serchUser_input" id="serchUser_input" placeholder='请输入姓名/标段'>
<button style="font-family:Microsoft Yahei;" οnclick="serchUser_Creat()">搜索</button>
<div class="list">
<div class="zTreeDemoBackground left">
<!-- <div style="margin:20px 0;">
<a href="#" class="easyui-linkbutton" οnclick="getChecked()">GetChecked</a>
</div> -->
<div style="display: none"><input type="checkbox" checked οnchange="$('#tt').tree({cascadeCheck:$(this).is(':checked')})">CascadeCheck </div>
<div class="easyui-panel" style="padding:5px;width: 461px;">
<ul id="tt" class="easyui-tree" data-options="animate:true,checkbox:true"></ul>
</div>
</div>
</div>
</div>
<div class="main_right">
<strong>已选用户成员</strong>
<div id="select_user" style="margin: 38px 60px;">
<!-- <input type="checkbox" name="name" class="check" value=" " />
<img src="images/renyuan.png" />
<span>张尚清.ZZ标段.监理.A公司.经理</span> -->
</div>
</div>
<span style="white-space:pre"> </span><div class="main_bottom" style="margin-right: 20%;margin-top: 27%;position:fixed;float:left;right:232px;" >
<span style="white-space:pre"> </span><!-- <button type="button" class="btn btn-default" οnclick="creatCircleBtn()" style="font-size: 20px; background-color:#4682B4;">完成创建</button>
<button type="button" class="btn btn-default" οnclick="creatCircleCancle()" style="font-size: 20px; background-color:#4682B4;">取消</button> -->
<span style="white-space:pre"> </span><a href="javascript:void(0)" class="easyui-linkbutton" οnclick="creatCircleBtn()">完成创建</a>
<span style="white-space:pre"> </span><a href="javascript:void(0)" class="easyui-linkbutton" οnclick="creatCircleCancle()">取消</a>
</div>
</div>
</div>
<!---------工作圈创建 end--------->
<script type="text/javascript" src="js/circle/circle-add.js"></script>
2.前台js
$(document).ready(function() {
findTreeWorkCircle();
});
/**
* 工作圈初始化
*/
function findTreeWorkCircle() {
$.ajax({
async : false,
dataType : 'json',
type : 'get',
url : "circle/tree",
success : sucFindTreeWorkCirlce,
error : function() {
alert("error");
}
});
}
/**
* 创建工作圈时查询标段和成员列表查询成功,加载数据
*
* @param json
*/
function sucFindTreeWorkCirlce(json) {
if (json.status == 200) {
// 创建工作圈树形结构
var object_data = {
data : json.data
};
$('#tt').tree(object_data);
}
}
function getChecked() {
var nodes = $('#tt').tree('getChecked');
var s = '';
var id = '';
for (var i = 0; i < nodes.length; i++) {
if (s != '')
s += ',';
{
if (nodes[i].levelNo == 1) {
// s += nodes[i].name;
id += nodes[i].tendersOruserId + '#';
}
}
}
// alert(s);
alert(id);
}
function getChildren(id/* 节点ID */) {
var $tree = $('#tt');
var node = $tree.tree('find', id);
var childrenNodes = $tree.tree('getChildren', node.target);
return childrenNodes;
}
$('#tt')
.tree(
{
onCheck : function(node) {
if (!node.checked) {
// if(node.levelNo==0){
// alert(node.text);
// }
if (node.levelNo == 0) {
// console.log(getChildren(node.id));
// console.log(getChildren(node.id)[0].text);
var listNodes = getChildren(node.id);
for (var i = 0; i < listNodes.length; i++) {
var id_div = listNodes[i].id;
// var tendersOruserId =
// treeNode.tendersOruserId;
var str = "<div id="
+ id_div
+ "><input type='hidden' class='select_input' name='select_input' value='"
+ id_div
+ "'><img src='images/renyuan.png' /><span>"
+ listNodes[i].text
+ "</span></div>";
$("#select_user").append(str);
}
} else if (node.levelNo == 1) {
var id_div = node.id;
// var tendersOruserId =
// treeNode.tendersOruserId;
var str = "<div id="
+ id_div
+ "><input type='hidden' class='select_input' name='select_input' value='"
+ id_div
+ "'><img src='images/renyuan.png' /><span>"
+ node.text + "</span></div>";
$("#select_user").append(str);
}
} else {
if (node.levelNo == 0) {
// $("#log").html("");
var first_id = node.id + "100";
// console.log("first_id: "+first_id);
var first_id_int = parseInt(first_id);
for (var i = first_id_int, l = first_id_int + 211; i < l; i++) {
var id_div = "#" + i;
$(id_div).remove();
}
first_id = node.id + "1000";
first_id_int = parseInt(first_id);
for (var i = first_id_int, l = first_id_int + 211; i < l; i++) {
var id_div = "#" + i;
$(id_div).remove();
}
first_id = node.id + "10000";
first_id_int = parseInt(first_id);
for (var i = first_id_int, l = first_id_int + 211; i < l; i++) {
var id_div = "#" + i;
$(id_div).remove();
}
} else if (node.levelNo == 1) {
var id_div = "#" + node.id;
$(id_div).remove();
}
}
}
});
/**
* 点击搜索
*/
function serchUser_Creat() {
var serchValue=document.getElementById("serchUser_input").value;
if(serchValue!=null && serchValue!="null" && serchValue!=undefined && serchValue!="undefined"){
$.ajax({
async : false,
dataType:'json',
data:"serchValue=" + serchValue,
type : 'post',
url : "circle/treefy",
success : sucSerchUser_CreatTwo,
error : function() {
alert("error");
}
});
}
}
/**
* 点击搜索成功加载数据
*/
function sucSerchUser_CreatTwo(json) {
if (json.status == 200) {
// 创建工作圈树形结构
var object_data = {
data : json.data
};
$('#tt').tree(object_data);
}
}
package org.bigdatacn.zczw.controller.pc;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.bigdatacn.zczw.common.pojo.Datagrid;
import org.bigdatacn.zczw.common.pojo.ZzResult;
import org.bigdatacn.zczw.common.utils.ExceptionUtil;
import org.bigdatacn.zczw.controller.BaseController;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/circle")
public class CircleController extends BaseController {
@Value("${IMAGE_SERVER_BASE_URL}")
private String IMAGE_SERVER_BASE_URL;
/**
*
* @description
* @author renzong
* @creatime 2016年5月11日下午4:37:24
* @user renzong
* @update
* @updatetime 2016年5月11日下午4:37:24
* @param type
* @param request
* @return
*/
@RequestMapping("/list")
@ResponseBody
public Datagrid findAllCircle(
@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "30") Integer rows, String text,
Long circleId, HttpServletRequest request) {
try {
return groupInfoService.fy_Circle(page, rows, text, circleId);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
*
* @description 修改圈子名称
* @author renzong
* @creatime 2016年6月7日上午10:26:52
* @user renzong
* @update
* @updatetime 2016年6月7日上午10:26:52
* @param circleId
* @param circleName
* @return
*/
@RequestMapping(value = "/modify", method = RequestMethod.POST)
@ResponseBody
public ZzResult modifyCircle(Long circleId, String circleName,HttpServletRequest request, HttpServletResponse response) {
try {
return groupInfoService.updateCircle(getCurrentUser(request)
.getUserid(),circleId, circleName);
} catch (Exception e) {
return ZzResult.build(500, ExceptionUtil.getStackTrace(e));
}
}
/**
*
* @description 禁用和启用圈子的状态
* @author renzong
* @creatime 2016年5月13日上午11:25:39
* @user renzong
* @update
* @updatetime 2016年5月13日上午11:25:39
* @param ids
* @param deleteflag
* @return
*/
@RequestMapping(value = "/updateStatus", method = RequestMethod.POST)
@ResponseBody
public ZzResult updateStatus(Long[] ids, int deleteflag) {
try {
return groupInfoService.disableCircles(ids, deleteflag);
} catch (Exception e) {
return ZzResult.build(500, ExceptionUtil.getStackTrace(e));
}
}
/**
*
* 根据群组id在融云上创建群组
*
* 方法名: createRongCircle
*
* 描述:
*
* 变量:
*
* 返回值: @param id
* 返回值: @return
*
*/
@RequestMapping(value = "/createRong")
@ResponseBody
public ZzResult createRongCircle(Long id) {
try {
return groupInfoService.createRong(id);
} catch (Exception e) {
return ZzResult.build(500, ExceptionUtil.getStackTrace(e));
}
}
/**
*
* @description 删除圈子里的一个或多个人
* @author renzong
* @creatime 2016年5月26日上午10:53:43
* @user renzong
* @update
* @updatetime 2016年5月26日上午10:53:43
* @param ids
* @return
*/
@RequestMapping(value = "user/delete", method = RequestMethod.POST)
@ResponseBody
public ZzResult deleteCU(Long circleId,Long[] ids) {
try {
return groupInfoService.deleteCU(circleId,ids);
} catch (Exception e) {
return ZzResult.build(500, ExceptionUtil.getStackTrace(e));
}
}
/**
*
* @description 树形结构
* @author renzong
* @creatime 2016年6月4日上午11:56:51
* @user renzong
* @update
* @updatetime 2016年6月4日上午11:56:51
* @return
*/
@RequestMapping(value = "tree", method = RequestMethod.GET)
@ResponseBody
public ZzResult tree() {
try {
return groupInfoService.findListTree();
} catch (Exception e) {
return ZzResult.build(500, ExceptionUtil.getStackTrace(e));
}
}
/**
*
* @description 树形结构模糊查询
* @author renzong
* @creatime 2016年6月4日上午11:56:51
* @user renzong
* @update
* @updatetime 2016年6月4日上午11:56:51
* @return
*/
@RequestMapping(value = "treefy", method = RequestMethod.POST)
@ResponseBody
public ZzResult treefy(String serchValue) {
try {
if(serchValue.isEmpty()){
return groupInfoService.findListTree();
}else{
return groupInfoService.findListTree_fy(serchValue);
}
} catch (Exception e) {
return ZzResult.build(500, ExceptionUtil.getStackTrace(e));
}
}
}
/**
*
* @description easyui树形结构
* @author renzong
* @creatime 2016年6月12日上午10:10:56
* @user renzong
* @update
* @updatetime 2016年6月12日上午10:10:56
* @return
* @throws Exception
*/
@Override
public ZzResult findListTree() throws Exception {
List<TreeInfo> listTree=new ArrayList<>();
Map<Object, Object> map = new HashMap<>();
map.put("name", CommonUtil.UNITS);
map.put("icon_units", CommonUtil.TENDERS_ICON_UNITS);
map.put("icon_user", CommonUtil.TENDERS_USER_UNITS);
return ZzResult.ok(treeInfoMapper.listTree(map));
}
package org.bigdatacn.zczw.common.pojo;
import java.util.List;
/**
*
* @description easyui tree 新建圈子需要
* @author renzong
* @creatime 2016年6月8日下午3:43:02
*/
public class TreeInfo {
private int id;// ---------
private int pId;//图片id
private int levelNo;
private String text;// 显示名称-----
//private String userAllName;// 用户全称,单位,公司,职级,姓名
private String tendersOruserId;// 标段id或者用户id
private String iconCls;// 图标位置-----
private Boolean checked = false;// 选中默认未选中
private String state = "closed"; // 默认打开open(针对根节点) //-----
private List<TreeInfoChildren> children;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getLevelNo() {
return levelNo;
}
public void setLevelNo(int levelNo) {
this.levelNo = levelNo;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
// public String getUserAllName() {
// return userAllName;
// }
// public void setUserAllName(String userAllName) {
// this.userAllName = userAllName;
// }
public String getTendersOruserId() {
return tendersOruserId;
}
public void setTendersOruserId(String tendersOruserId) {
this.tendersOruserId = tendersOruserId;
}
public String getIconCls() {
return iconCls;
}
public void setIconCls(String iconCls) {
this.iconCls = iconCls;
}
public Boolean getChecked() {
return checked;
}
public void setChecked(Boolean checked) {
this.checked = checked;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public List<TreeInfoChildren> getChildren() {
return children;
}
public void setChildren(List<TreeInfoChildren> children) {
this.children = children;
}
public int getpId() {
return pId;
}
public void setpId(int pId) {
this.pId = pId;
}
}
package org.bigdatacn.zczw.common.pojo;
import java.util.List;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* 自定义响应结构
*/
public class ZzResult {
// 定义jackson对象
private static final ObjectMapper MAPPER = new ObjectMapper();
// 响应业务状态
private Integer status;
// 响应消息
private String msg;
// 响应中的数据
private Object data;
public static ZzResult build(Integer status, String msg, Object data) {
return new ZzResult(status, msg, data);
}
public static ZzResult ok(Object data) {
return new ZzResult(data);
}
public static ZzResult ok() {
return new ZzResult(null);
}
public ZzResult() {
}
public static ZzResult build(Integer status, String msg) {
return new ZzResult(status, msg, null);
}
public ZzResult(Integer status, String msg, Object data) {
this.status = status;
this.msg = msg;
this.data = data;
}
public ZzResult(Object data) {
this.status = 200;
this.msg = "OK";
this.data = data;
}
// public Boolean isOK() {
// return this.status == 200;
// }
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
/**
* 将json结果集转化为ZzResult对象
*
* @param jsonData json数据
* @param clazz ZzResult中的object类型
* @return
*/
public static ZzResult formatToPojo(String jsonData, Class<?> clazz) {
try {
if (clazz == null) {
return MAPPER.readValue(jsonData, ZzResult.class);
}
JsonNode jsonNode = MAPPER.readTree(jsonData);
JsonNode data = jsonNode.get("data");
Object obj = null;
if (clazz != null) {
if (data.isObject()) {
obj = MAPPER.readValue(data.traverse(), clazz);
} else if (data.isTextual()) {
obj = MAPPER.readValue(data.asText(), clazz);
}
}
return build(jsonNode.get("status").intValue(), jsonNode.get("msg")
.asText(), obj);
} catch (Exception e) {
return null;
}
}
/**
* 没有object对象的转化
*
* @param json
* @return
*/
public static ZzResult format(String json) {
try {
return MAPPER.readValue(json, ZzResult.class);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* Object是集合转化
*
* @param jsonData json数据
* @param clazz 集合中的类型
* @return
*/
public static ZzResult formatToList(String jsonData, Class<?> clazz) {
try {
JsonNode jsonNode = MAPPER.readTree(jsonData);
JsonNode data = jsonNode.get("data");
Object obj = null;
if (data.isArray() && data.size() > 0) {
obj = MAPPER.readValue(data.traverse(), MAPPER.getTypeFactory()
.constructCollectionType(List.class, clazz));
}
return build(jsonNode.get("status").intValue(), jsonNode.get("msg")
.asText(), obj);
} catch (Exception e) {
return null;
}
}
}
6.后台mapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.bigdatacn.zczw.mapper.result.TreeInfoMapper">
<resultMap id="treeInfo" type="org.bigdatacn.zczw.common.pojo.TreeInfo">
<id column="id" property="id" jdbcType="INTEGER" />
<result column="pId" property="pId" jdbcType="INTEGER" />
<result column="levelNo" property="levelNo" jdbcType="INTEGER" />
<result column="text" property="text" jdbcType="VARCHAR" />
<result column="tendersOruserId" property="tendersOruserId" jdbcType="VARCHAR" />
<result column="state" property="state" jdbcType="VARCHAR" />
<result column="iconCls" property="iconCls" jdbcType="VARCHAR" />
</resultMap>
<!-- 增加节点children信息 -->
<resultMap type="org.bigdatacn.zczw.common.pojo.TreeInfo"
id="treeInfoChildren" extends="treeInfo">
<collection property="children"
ofType="org.bigdatacn.zczw.common.pojo.TreeInfoChildren">
<id column="id1" property="id" jdbcType="INTEGER" />
<result column="pId1" property="pId" jdbcType="INTEGER" />
<result column="levelNo1" property="levelNo" jdbcType="INTEGER" />
<result column="text1" property="text" jdbcType="VARCHAR" />
<result column="userAllName1" property="userAllName" jdbcType="VARCHAR" />
<result column="tendersOruserId1" property="tendersOruserId" jdbcType="VARCHAR" />
<result column="iconCls1" property="iconCls" jdbcType="VARCHAR" />
</collection>
</resultMap>
<!-- 树形结构 rz -->
<select id="listTree" statementType="CALLABLE" parameterType="map" resultMap="treeInfoChildren">
{call units_syscode_tree(#{name},#{icon_units},#{icon_user})}
</select>
<!-- 树形结构模糊查询 rz -->
<select id="listTree_fy" statementType="CALLABLE" parameterType="map" resultMap="treeInfoChildren">
{call units_syscode_tree_fy(#{name},#{icon_units},#{icon_user},#{serchValue})}
</select>
</mapper>
6.存储过程
units_syscode_tree(IN commonUtilUnits VARCHAR(30),IN icon_units VARCHAR(30),IN icon_user VARCHAR(30))
BEGIN
SET @m = 0;
SET @n = 0;
SET @levelNo = 0;
SET @icon_units = icon_units;
SET @commonUtilUnits = commonUtilUnits;
SET @i = 0;
SET @j = 0;
SET @icon_user = icon_user;
SET @levelNoTwo = 1;
SET @ROW = 0;
SET @mid = '';
SELECT
s_2.*,
s5.*
FROM
(
SELECT
@m :=@m + 1 AS id ,
@n :=@n + 1 AS pId ,
@levelNo AS levelNo,
s_1.sysSubclassCode AS tendersOruserId,
s_1.sysSubclasName AS text,
s_1.iconCls
FROM
(
SELECT
s.sysSubclassCode,
s.sysSubclasName ,@icon_units AS iconCls
FROM
zz_syscode AS s
WHERE
s.sysCategoryCode =@commonUtilUnits
) AS s_1
) AS s_2
LEFT JOIN
(
SELECT
CONCAT(s4.id,100+s4.rownum) AS id1,
s4.pId AS pId1,
@levelNoTwo AS levelNo1,
s4.userId AS tendersOruserId1,
s4.userName AS text1,
s4.icon AS iconCls1,
CONCAT(
s4.userName,
'.',
s4.sysSubclasName
) AS userAllName1
FROM
(
SELECT
s3.*, CASE
WHEN @mid = s3.unitsId THEN
@ROW :=@ROW + 1
ELSE
@ROW := 1
END rownum,
@mid := s3.unitsId
FROM
(
SELECT
tu.unitsId,
s2.*, u.userId,
u.userName
FROM
zz_units_user AS tu,
(
SELECT
@i :=@i + 1 AS id,
@j :=@j + 1 AS pId,
s1.sysSubclassCode,
s1.sysSubclasName,
s1.icon
FROM
(
SELECT
s.sysSubclassCode,
s.sysSubclasName ,@icon_user AS icon
FROM
zz_syscode AS s
WHERE
s.sysCategoryCode =@commonUtilUnits
) AS s1
) AS s2,
zz_user AS u
WHERE
tu.deleteflag = '1'
AND u.deleteflag = '1'
AND tu.unitsId = s2.sysSubclassCode
AND tu.userId = u.userId
ORDER BY
s2.id
) AS s3
ORDER BY
s3.unitsId
) AS s4
) AS s5
ON s_2.pId=s5.pId1;
END
units_syscode_tree_fy(IN commonUtilUnits VARCHAR(30),IN icon_units VARCHAR(30),IN icon_user VARCHAR(30),IN serchValue VARCHAR(30))
BEGIN
SET @m = 0;
SET @n = 0;
SET @levelNo = 0;
SET @icon_units = icon_units;
SET @commonUtilUnits = commonUtilUnits;
SET @i = 0;
SET @j = 0;
SET @icon_user = icon_user;
SET @levelNoTwo = 1;
SET @ROW = 0;
SET @mid = '';
SET @serchValue = serchValue;
SELECT
r1.*
FROM
(
SELECT
s_2.*,
s5.*
FROM
(
SELECT
@m :=@m + 1 AS id ,
@n :=@n + 1 AS pId ,
@levelNo AS levelNo,
s_1.sysSubclassCode AS tendersOruserId,
s_1.sysSubclasName AS text,
'open' AS state,
s_1.iconCls
FROM
(
SELECT
s.sysSubclassCode,
s.sysSubclasName ,@icon_units AS iconCls
FROM
zz_syscode AS s
WHERE
s.sysCategoryCode =@commonUtilUnits
) AS s_1
) AS s_2
LEFT JOIN
(
SELECT
CONCAT(s4.id,100+s4.rownum) AS id1,
s4.pId AS pId1,
@levelNoTwo AS levelNo1,
s4.userId AS tendersOruserId1,
s4.userName AS text1,
s4.icon AS iconCls1,
CONCAT(
s4.userName,
'.',
s4.sysSubclasName
) AS userAllName1
FROM
(
SELECT
s3.*, CASE
WHEN @mid = s3.unitsId THEN
@ROW :=@ROW + 1
ELSE
@ROW := 1
END rownum,
@mid := s3.unitsId
FROM
(
SELECT
tu.unitsId,
s2.*, u.userId,
u.userName
FROM
zz_units_user AS tu,
(
SELECT
@i :=@i + 1 AS id,
@j :=@j + 1 AS pId,
s1.sysSubclassCode,
s1.sysSubclasName,
s1.icon
FROM
(
SELECT
s.sysSubclassCode,
s.sysSubclasName ,@icon_user AS icon
FROM
zz_syscode AS s
WHERE
s.sysCategoryCode =@commonUtilUnits
) AS s1
) AS s2,
zz_user AS u
WHERE
tu.deleteflag = '1'
AND u.deleteflag = '1'
AND tu.unitsId = s2.sysSubclassCode
AND tu.userId = u.userId
ORDER BY
s2.id
) AS s3
ORDER BY
s3.unitsId
) AS s4
) AS s5
ON s_2.pId=s5.pId1
) AS r1
WHERE
r1.userAllName1 LIKE CONCAT('%',@serchValue,'%')
;
END