78 lines
2.7 KiB
Java
78 lines
2.7 KiB
Java
|
|
package com.rzyc.service;
|
|||
|
|
|
|||
|
|
import com.alibaba.fastjson.JSON;
|
|||
|
|
import com.alibaba.fastjson.JSONArray;
|
|||
|
|
import com.common.utils.StringUtils;
|
|||
|
|
import com.common.utils.TypeConversion;
|
|||
|
|
import com.common.utils.model.SingleResult;
|
|||
|
|
import com.rzyc.bean.emergency.PlanList;
|
|||
|
|
import com.rzyc.controller.BaseController;
|
|||
|
|
import com.rzyc.model.ent.EntPost;
|
|||
|
|
import com.rzyc.model.ent.EntUser;
|
|||
|
|
import com.rzyc.model.ent.SysEnterprise;
|
|||
|
|
|
|||
|
|
import org.springframework.stereotype.Service;
|
|||
|
|
|
|||
|
|
import java.util.ArrayList;
|
|||
|
|
import java.util.HashMap;
|
|||
|
|
import java.util.List;
|
|||
|
|
import java.util.Map;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 企业端pc业务 Service
|
|||
|
|
* @author Xuwanxin
|
|||
|
|
* @date 2022/9/29
|
|||
|
|
* */
|
|||
|
|
|
|||
|
|
|
|||
|
|
@Service
|
|||
|
|
public class PcBusinessService extends BaseController {
|
|||
|
|
|
|||
|
|
public SingleResult<List<EntUser>>entUserTree(String enterpriseId,String postId){
|
|||
|
|
SingleResult singleResult = new SingleResult();
|
|||
|
|
SysEnterprise sysEnterprise = sysEnterpriseMapper.selectByPrimaryKey(enterpriseId);
|
|||
|
|
List<EntPost> list = entPostMapper.selectEntUserTree(enterpriseId,postId);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* sql里进行了order by,如果传入postId就是查询非全部的数结构,需要加入一个公司,所以把第一个最大权限设置为company,这样公司才会在树的最上面
|
|||
|
|
* 相反不穿postId就是查询全部,默认会有company打头就不用再修改list的0对象
|
|||
|
|
*/
|
|||
|
|
if (null != postId){
|
|||
|
|
list.get(0).setParentId("company");
|
|||
|
|
}
|
|||
|
|
//加入公司为第一个树结构
|
|||
|
|
EntPost entPost = new EntPost();
|
|||
|
|
entPost.setName(sysEnterprise.getEntname());
|
|||
|
|
entPost.setPostId("company");
|
|||
|
|
list.add(entPost);
|
|||
|
|
|
|||
|
|
JSONArray jsonArray = handleEntUserTree(list);
|
|||
|
|
List<EntPost>posts = JSONArray.parseArray(JSONArray.toJSONString(jsonArray),EntPost.class);
|
|||
|
|
singleResult.setData(posts);
|
|||
|
|
return singleResult;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 处理企业用户数结构list
|
|||
|
|
*/
|
|||
|
|
private JSONArray handleEntUserTree(List<EntPost> list){
|
|||
|
|
List<Map<String,Object>> data = new ArrayList<>();
|
|||
|
|
for(EntPost entPost : list){
|
|||
|
|
if(StringUtils.isBlank(entPost.getParentId())){
|
|||
|
|
entPost.setParentId("");
|
|||
|
|
}
|
|||
|
|
Map<String,Object> entPostMap = new HashMap<String,Object>();
|
|||
|
|
entPostMap.put("postId",entPost.getPostId());
|
|||
|
|
entPostMap.put("name",entPost.getName());
|
|||
|
|
entPostMap.put("parentId",entPost.getParentId());
|
|||
|
|
entPostMap.put("subordinates",entPost.getSubordinates());
|
|||
|
|
data.add(entPostMap);
|
|||
|
|
}
|
|||
|
|
com.alibaba.fastjson.JSONArray result = TypeConversion.listToTree(com.alibaba.fastjson.JSONArray.parseArray(JSON.toJSONString(data)),"postId","parentId","children");
|
|||
|
|
return result;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|