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.EntPostList; 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>entUserTree(String enterpriseId,String postId){ SingleResult singleResult = new SingleResult(); SysEnterprise sysEnterprise = sysEnterpriseMapper.selectByPrimaryKey(enterpriseId); List 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); Listposts = JSONArray.parseArray(JSONArray.toJSONString(jsonArray),EntPost.class); singleResult.setData(posts); return singleResult; } /** * 处理企业用户数结构list */ private JSONArray handleEntUserTree(List list){ List> data = new ArrayList<>(); for(EntPost entPost : list){ if(StringUtils.isBlank(entPost.getParentId())){ entPost.setParentId(""); } Map entPostMap = new HashMap(); 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; } public SingleResult entUserPostList(String enterpriseId,String entUserId,String postId){ SingleResult singleResult = new SingleResult(); Listlist = entPostListMapper.selectEntPostList(enterpriseId,entUserId,postId); singleResult.setData(list); return singleResult; } public SingleResult entUserPostTask(String enterpriseId, String entUserId,String postId,String listId){ SingleResult singleResult = new SingleResult(); //EntPostTask return singleResult; } }