| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423 |
- package cn.com.goldenwater.dcproj.service.impl.system;
- import cn.com.goldenwater.dcproj.dao.*;
- import cn.com.goldenwater.dcproj.model.*;
- import cn.com.goldenwater.dcproj.param.*;
- import cn.com.goldenwater.dcproj.service.OlBisInspOrgService;
- import cn.com.goldenwater.dcproj.utils.InspUtils;
- import org.apache.commons.lang3.StringUtils;
- import org.apache.commons.lang3.math.NumberUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.text.SimpleDateFormat;
- import java.util.*;
- import java.util.function.Function;
- import java.util.stream.Collectors;
- @Service
- @Transactional
- public class OrganizationTreeImpl {
- //机构id
- @Value("${org.code}")
- public String orgId;
- //七个委的父id
- @Value("${org.pGuid}")
- public String pGuid;
- @Autowired
- private AttOrgBaseDao attOrgBaseDao;
- //新版的机构表
- @Autowired
- private BisInspAllDao bisInspAllDao;
- //批次相关dao
- @Autowired
- private BisInspPlanDao bisInspPlanDao;
- @Autowired
- private UserRoleDao userRoleDao;
- @Autowired
- private BisInspGroupDao bisInspGroupDao;
- @Autowired
- private AttMampuInfoDao attMampuInfoDao;
- @Autowired
- private BisInspKeyRegisterSectionDao bisInspKeyRegisterSectionDao;
- @Autowired
- private BisInspKeyRegSecUnitDao bisInspKeyRegSecUnitDao;
- /**
- * 获取树形结构相关信息
- *
- * @param guid
- * @param userId
- * @param type
- * @param code
- * @return
- */
- public List<OrganizationAndBatchAndGroup> getOrganizationTreeByGuidAndOthers(String guid, String userId, String type, String code) {
- //当type和code为null是,是查询默认能看的树形根节点,其他是点击查询下一级树
- if (StringUtils.isEmpty(type) || StringUtils.isEmpty(code)) {
- //根据机构id查询跟节点
- AttOrgBase attOrgBase = attOrgBaseDao.get(guid);
- if (null != attOrgBase) {
- OrganizationAndBatchAndGroup organizationAndBatchAndGroup = new OrganizationAndBatchAndGroup();
- organizationAndBatchAndGroup.setCode(attOrgBase.getGuid());
- organizationAndBatchAndGroup.setName(attOrgBase.getOrgName());
- if (orgId.equalsIgnoreCase(guid)) {
- organizationAndBatchAndGroup.setType("1");
- } else {
- organizationAndBatchAndGroup.setType("2");
- }
- ArrayList<OrganizationAndBatchAndGroup> organizationAndBatchAndGroups = new ArrayList<>();
- organizationAndBatchAndGroups.add(organizationAndBatchAndGroup);
- return organizationAndBatchAndGroups;
- } else {
- return null;
- }
- } else {
- //根据点击查询下一级,先判断是否是管理员,如果是,一查到底所有,如果不是查自己能看到的
- UserRoleParam userRoleParam = new UserRoleParam();
- userRoleParam.setUserId(userId);
- List<UserRole> list = userRoleDao.findList(userRoleParam);
- //暂时认为1是管理员2是普通用户
- if (null != list && 0 < list.size()) {
- UserRole userRole = list.get(0);
- String roleId = userRole.getRoleId();
- //根据角色分流
- if ("1098064352187461632".equalsIgnoreCase(roleId)) {
- //管理员,一查到底,没限制
- List<OrganizationAndBatchAndGroup> result = new ArrayList<OrganizationAndBatchAndGroup>();
- switch (NumberUtils.toInt(type)) {
- case 1:
- //根据监督司查机构
- AttOrgBaseParam attOrgBaseParam = new AttOrgBaseParam();
- attOrgBaseParam.setPguid(pGuid);
- attOrgBaseParam.setAreaType("4");
- List<AttOrgBase> list1 = attOrgBaseDao.findList(attOrgBaseParam);
- if (null != list1 && 0 < list1.size()) {
- for (AttOrgBase att : list1) {
- OrganizationAndBatchAndGroup bean = new OrganizationAndBatchAndGroup();
- bean.setType("2");
- bean.setName(att.getOrgName());
- bean.setCode(att.getGuid());
- result.add(bean);
- }
- }
- break;
- case 2:
- //根据机构查询批次
- BisInspPlanParam bisInspPlanParam = new BisInspPlanParam();
- bisInspPlanParam.setGuid(code);
- List<BisInspPlan> list2 = bisInspPlanDao.findList(bisInspPlanParam);
- if (null != list2 && 0 < list2.size()) {
- for (BisInspPlan bis : list2) {
- OrganizationAndBatchAndGroup bean = new OrganizationAndBatchAndGroup();
- bean.setType("3");
- bean.setName(bis.getPrsnTitle());
- bean.setCode(bis.getPlnaId());
- result.add(bean);
- }
- }
- break;
- case 3:
- //根据批次查组
- BisInspGroupParam bisInspGroupParam = new BisInspGroupParam();
- bisInspGroupParam.setGuid(guid);
- bisInspGroupParam.setPlnaId(code);
- bisInspGroupParam.setDataStat("1");
- List<BisInspGroup> list3 = bisInspGroupDao.findList(bisInspGroupParam);
- if (null != list3 && 0 < list3.size()) {
- for (BisInspGroup group : list3) {
- OrganizationAndBatchAndGroup bean = new OrganizationAndBatchAndGroup();
- bean.setType("4");
- bean.setName(group.getInspGroupName());
- bean.setCode(group.getInspGroupId());
- result.add(bean);
- }
- }
- }
- return result;
- } else {
- //为2,普通用户,只查自己参与的组
- List<OrganizationAndBatchAndGroup> result = new ArrayList<OrganizationAndBatchAndGroup>();
- switch (NumberUtils.toInt(type)) {
- case 1:
- //根据监督司查机构,组员应该进不到这个情况
- AttOrgBaseParam attOrgBaseParam = new AttOrgBaseParam();
- attOrgBaseParam.setPguid(pGuid);
- attOrgBaseParam.setAreaType("4");
- List<AttOrgBase> list1 = attOrgBaseDao.findList(attOrgBaseParam);
- if (null != list1 && 0 < list1.size()) {
- for (AttOrgBase att : list1) {
- OrganizationAndBatchAndGroup bean = new OrganizationAndBatchAndGroup();
- bean.setType("2");
- bean.setName(att.getOrgName());
- bean.setCode(att.getGuid());
- result.add(bean);
- }
- }
- break;
- case 2:
- //根据人员id查批次
- List<BisInspPlan> list2 = bisInspPlanDao.findListByUserId(userId);
- if (null != list2 && 0 < list2.size()) {
- for (BisInspPlan bis : list2) {
- OrganizationAndBatchAndGroup bean = new OrganizationAndBatchAndGroup();
- bean.setType("3");
- bean.setName(bis.getPrsnTitle());
- bean.setCode(bis.getPlnaId());
- result.add(bean);
- }
- }
- break;
- case 3:
- //根据批次查组,注意普通用户只查跟自己相关的组
- List<BisInspGroup> list3 = bisInspGroupDao.findListByBatchIdAndUserId(code, userId);
- if (null != list3 && 0 < list3.size()) {
- for (BisInspGroup group : list3) {
- OrganizationAndBatchAndGroup bean = new OrganizationAndBatchAndGroup();
- bean.setType("4");
- bean.setName(group.getInspGroupName());
- bean.setCode(group.getInspGroupId());
- result.add(bean);
- }
- }
- }
- return result;
- }
- }
- }
- return null;
- }
- @Autowired
- private OlBisInspOrgService olBisInspOrgService;
- public List<BisInspAll> getAllNode(String userid, String orgType, String orgId, String tabType, String year, String yearTaskId, String curYear, String leadDep) {
- if (orgType.length() == 2) {
- orgType = "0" + orgType;
- }
- if (orgType.length() == 1) {
- orgType = "00" + orgType;
- }
- if (orgType.length() == 4) {
- if (Integer.parseInt(orgType) > 100) {
- orgType = orgType.substring(1, orgType.length());
- }
- }
- String province = olBisInspOrgService.getProvince(orgId);
- String nowTime = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
- if (null != year && year.equals("全部")) {
- year = null;
- }
- return bisInspAllDao.getAllNode(userid, orgType, province, orgId, tabType, nowTime, year, yearTaskId, curYear, leadDep);
- }
- public List<BisInspAll> getAllNodeById(String id) {
- // 前台传过来的字符串格式化成 in 能接受的
- return bisInspAllDao.getAllNodeById(InspUtils.setOrgIds(id));
- }
- public List<OrganizationAndBatchAndGroup> getOrganizationTreeByParams(String guid, String userId, String type, String code, String objType) {
- //第一次查询code,type为空
- List<OrganizationAndBatchAndGroup> result = new ArrayList<OrganizationAndBatchAndGroup>();
- //非第一次查询,根据父id,查询子id集合
- //非水利部,直接根据id查询根节点
- BisInspAllParam bisInspAllParam = new BisInspAllParam();
- //查水利部下面所有的职能部门 ______
- bisInspAllParam.setPid(code);
- List<BisInspAll> list = bisInspAllDao.findList(bisInspAllParam);
- if (null != list && 0 < list.size()) {
- for (BisInspAll o : list) {
- OrganizationAndBatchAndGroup bean = new OrganizationAndBatchAndGroup();
- //根据id长度判断type
- String typeStr = o.getId();
- if (null != typeStr) {
- if (3 == typeStr.length()) {
- //待定是谁
- bean.setType("1");
- } else if (6 == typeStr.length()) {
- //各委员会
- bean.setType("2");
- } else if (9 == typeStr.length()) {
- //批次
- bean.setType("3");
- } else if (12 == typeStr.length()) {
- //组
- bean.setType("4");
- }
- }
- bean.setName(o.getPnm());
- bean.setCode(o.getId());
- result.add(bean);
- }
- }
- return result;
- }
- public List<BisInspAllNode> getAllNodeAndObj(String persId, String objType, int level, String province) {
- List<BisInspAllNode> list = new ArrayList<>();
- level = level * 3;
- List<BisInspAll> bisList = bisInspAllDao.getAllNodeByLevel(persId, objType, level, province);
- boolean notHas = true;
- String maxNode = "";
- String maxPid = "";
- for (BisInspAll bis : bisList) {
- String id = bis.getId();
- String pid = bis.getPid();
- if (id.length() == level) {
- notHas = false;
- list = getNodeList(bisList, pid, province);
- }
- if (StringUtils.isBlank(maxNode)) {
- maxNode = id;
- maxPid = pid;
- } else {
- if (maxNode.length() >= id.length()) {
- maxNode = id;
- maxPid = pid;
- }
- }
- }
- if (notHas) {
- list = getNodeList(bisList, maxPid, province);
- }
- if (list != null) {
- if (list.size() > 1) {
- BisInspAllNode bisInspAllNode = new BisInspAllNode();
- bisInspAllNode.setId(objType);
- bisInspAllNode.setPid("0");
- bisInspAllNode.setChildren(list);
- list = new ArrayList<>();
- list.add(bisInspAllNode);
- }
- }
- return list;
- }
- public List<BisInspAllNode> getNodeList(List<BisInspAll> bisList, String pid, String province) {
- List<BisInspAllNode> list = new ArrayList<>();
- if (StringUtils.isNotBlank(pid)) {
- for (BisInspAll bis : bisList) {
- String id = bis.getId();
- String pnm = bis.getPnm();
- String pId = bis.getPid();
- if (pid.equals(pId)) {
- List<BisInspAllNode> children = new ArrayList<>();
- if (id.length() == 12) {
- String prov = province.replace("00", "");
- children = bisInspAllDao.BisInspAllObjById(id, prov);
- for (BisInspAllNode child : children) {
- getChildrenList(child);
- }
- } else {
- children = getNodeList(bisList, id, province);
- }
- BisInspAllNode node = new BisInspAllNode();
- node.setId(id);
- node.setPnm(pnm);
- node.setPid(pId);
- node.setChildren(children);
- list.add(node);
- }
- }
- }
- return list;
- }
- private void getChildrenList(BisInspAllNode node) {
- if ("004".equals(node.getPid().substring(0, 3))) {
- List<BisInspKeyRegisterSection> secs = bisInspKeyRegisterSectionDao.getByRegId(node.getId());
- for (BisInspKeyRegisterSection sec : secs) {
- BisInspAllNode secNode = new BisInspAllNode();
- secNode.setId(sec.getId());
- secNode.setObjId(sec.getObjId());
- secNode.setPnm(sec.getNm());
- secNode.setPid(node.getId());
- secNode.setFlag("sec");
- secNode.setChildren(new ArrayList<>());
- List<BisInspKeyRegSecUnit> units = bisInspKeyRegSecUnitDao.getBySecId(sec.getId());
- for (BisInspKeyRegSecUnit unit : units) {
- BisInspAllNode unitNode = new BisInspAllNode();
- unitNode.setId(unit.getId());
- unitNode.setPnm(unit.getNm());
- unitNode.setObjId(unit.getObjId());
- unitNode.setPid(sec.getId());
- unitNode.setFlag("unit");
- secNode.getChildren().add(unitNode);
- }
- if (node.getChildren() == null) {
- node.setChildren(new ArrayList<>());
- }
- node.getChildren().add(secNode);
- }
- } else if ("007".equals(node.getPid().substring(0, 3))) {
- //得到所有单位信息
- List<AttMampuInfo> mampus = new ArrayList<>();
- List<AttMampuInfo> mampusSec = new ArrayList<>();
- List<AttMampuInfo> mampusThi = new ArrayList<>();
- AttMampuInfoParam param = new AttMampuInfoParam();
- param.setLev("1");
- param.setRegId("'" + node.getId() + "'");
- mampus = attMampuInfoDao.getAttMampus(param);
- param.setLev("2");
- mampusSec = attMampuInfoDao.getAttMampus(param);
- param.setLev("3");
- mampusThi = attMampuInfoDao.getAttMampus(param);
- List<BisInspAllNode> nodes = new ArrayList<>();
- Map<String, BisInspAllNode> map = nodes.stream().collect(Collectors.toMap(BisInspAllNode::getId, Function.identity()));
- map.put(node.getId(), node);
- for (AttMampuInfo info : mampus) {
- info.setPid(info.getRegId());
- getNodeList(map, info, "mamp1");
- }
- //缓存所有三级节点
- Map<String, BisInspAllNode> nodeThr = new HashMap<>();
- for (AttMampuInfo info : mampusSec) {
- Map<String, BisInspAllNode> parents = map.get(info.getRegId()).getChildren().stream().collect(Collectors.toMap(BisInspAllNode::getId, Function.identity()));
- BisInspAllNode inspAllNode = getNodeList(parents, info, "mamp2");
- if (inspAllNode == null) {
- continue;
- }
- nodeThr.put(inspAllNode.getId(), inspAllNode);
- }
- for (AttMampuInfo info : mampusThi) {
- getNodeList(nodeThr, info, "mamp3");
- }
- }
- }
- private BisInspAllNode getNodeList(Map<String, BisInspAllNode> map, AttMampuInfo info, String flag) {
- BisInspAllNode node = map.get(info.getPid());
- if (node == null) {
- return null;
- }
- BisInspAllNode child = new BisInspAllNode();
- child.setId(info.getId());
- child.setPnm(info.getNm());
- child.setObjId(node.getObjId());
- child.setPid(node.getId());
- child.setFlag(flag);
- if (node.getChildren() == null) {
- node.setChildren(new ArrayList<>());
- }
- node.getChildren().add(child);
- return child;
- }
- }
|