304e06fad09ef67d75cfa4befde1691ec261ee40.svn-base 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. package cn.com.goldenwater.dcproj.service.impl.system;
  2. import cn.com.goldenwater.dcproj.dao.*;
  3. import cn.com.goldenwater.dcproj.model.*;
  4. import cn.com.goldenwater.dcproj.param.*;
  5. import cn.com.goldenwater.dcproj.service.OlBisInspOrgService;
  6. import cn.com.goldenwater.dcproj.utils.InspUtils;
  7. import org.apache.commons.lang3.StringUtils;
  8. import org.apache.commons.lang3.math.NumberUtils;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.beans.factory.annotation.Value;
  11. import org.springframework.stereotype.Service;
  12. import org.springframework.transaction.annotation.Transactional;
  13. import java.text.SimpleDateFormat;
  14. import java.util.*;
  15. import java.util.function.Function;
  16. import java.util.stream.Collectors;
  17. @Service
  18. @Transactional
  19. public class OrganizationTreeImpl {
  20. //机构id
  21. @Value("${org.code}")
  22. public String orgId;
  23. //七个委的父id
  24. @Value("${org.pGuid}")
  25. public String pGuid;
  26. @Autowired
  27. private AttOrgBaseDao attOrgBaseDao;
  28. //新版的机构表
  29. @Autowired
  30. private BisInspAllDao bisInspAllDao;
  31. //批次相关dao
  32. @Autowired
  33. private BisInspPlanDao bisInspPlanDao;
  34. @Autowired
  35. private UserRoleDao userRoleDao;
  36. @Autowired
  37. private BisInspGroupDao bisInspGroupDao;
  38. @Autowired
  39. private AttMampuInfoDao attMampuInfoDao;
  40. @Autowired
  41. private BisInspKeyRegisterSectionDao bisInspKeyRegisterSectionDao;
  42. @Autowired
  43. private BisInspKeyRegSecUnitDao bisInspKeyRegSecUnitDao;
  44. /**
  45. * 获取树形结构相关信息
  46. *
  47. * @param guid
  48. * @param userId
  49. * @param type
  50. * @param code
  51. * @return
  52. */
  53. public List<OrganizationAndBatchAndGroup> getOrganizationTreeByGuidAndOthers(String guid, String userId, String type, String code) {
  54. //当type和code为null是,是查询默认能看的树形根节点,其他是点击查询下一级树
  55. if (StringUtils.isEmpty(type) || StringUtils.isEmpty(code)) {
  56. //根据机构id查询跟节点
  57. AttOrgBase attOrgBase = attOrgBaseDao.get(guid);
  58. if (null != attOrgBase) {
  59. OrganizationAndBatchAndGroup organizationAndBatchAndGroup = new OrganizationAndBatchAndGroup();
  60. organizationAndBatchAndGroup.setCode(attOrgBase.getGuid());
  61. organizationAndBatchAndGroup.setName(attOrgBase.getOrgName());
  62. if (orgId.equalsIgnoreCase(guid)) {
  63. organizationAndBatchAndGroup.setType("1");
  64. } else {
  65. organizationAndBatchAndGroup.setType("2");
  66. }
  67. ArrayList<OrganizationAndBatchAndGroup> organizationAndBatchAndGroups = new ArrayList<>();
  68. organizationAndBatchAndGroups.add(organizationAndBatchAndGroup);
  69. return organizationAndBatchAndGroups;
  70. } else {
  71. return null;
  72. }
  73. } else {
  74. //根据点击查询下一级,先判断是否是管理员,如果是,一查到底所有,如果不是查自己能看到的
  75. UserRoleParam userRoleParam = new UserRoleParam();
  76. userRoleParam.setUserId(userId);
  77. List<UserRole> list = userRoleDao.findList(userRoleParam);
  78. //暂时认为1是管理员2是普通用户
  79. if (null != list && 0 < list.size()) {
  80. UserRole userRole = list.get(0);
  81. String roleId = userRole.getRoleId();
  82. //根据角色分流
  83. if ("1098064352187461632".equalsIgnoreCase(roleId)) {
  84. //管理员,一查到底,没限制
  85. List<OrganizationAndBatchAndGroup> result = new ArrayList<OrganizationAndBatchAndGroup>();
  86. switch (NumberUtils.toInt(type)) {
  87. case 1:
  88. //根据监督司查机构
  89. AttOrgBaseParam attOrgBaseParam = new AttOrgBaseParam();
  90. attOrgBaseParam.setPguid(pGuid);
  91. attOrgBaseParam.setAreaType("4");
  92. List<AttOrgBase> list1 = attOrgBaseDao.findList(attOrgBaseParam);
  93. if (null != list1 && 0 < list1.size()) {
  94. for (AttOrgBase att : list1) {
  95. OrganizationAndBatchAndGroup bean = new OrganizationAndBatchAndGroup();
  96. bean.setType("2");
  97. bean.setName(att.getOrgName());
  98. bean.setCode(att.getGuid());
  99. result.add(bean);
  100. }
  101. }
  102. break;
  103. case 2:
  104. //根据机构查询批次
  105. BisInspPlanParam bisInspPlanParam = new BisInspPlanParam();
  106. bisInspPlanParam.setGuid(code);
  107. List<BisInspPlan> list2 = bisInspPlanDao.findList(bisInspPlanParam);
  108. if (null != list2 && 0 < list2.size()) {
  109. for (BisInspPlan bis : list2) {
  110. OrganizationAndBatchAndGroup bean = new OrganizationAndBatchAndGroup();
  111. bean.setType("3");
  112. bean.setName(bis.getPrsnTitle());
  113. bean.setCode(bis.getPlnaId());
  114. result.add(bean);
  115. }
  116. }
  117. break;
  118. case 3:
  119. //根据批次查组
  120. BisInspGroupParam bisInspGroupParam = new BisInspGroupParam();
  121. bisInspGroupParam.setGuid(guid);
  122. bisInspGroupParam.setPlnaId(code);
  123. bisInspGroupParam.setDataStat("1");
  124. List<BisInspGroup> list3 = bisInspGroupDao.findList(bisInspGroupParam);
  125. if (null != list3 && 0 < list3.size()) {
  126. for (BisInspGroup group : list3) {
  127. OrganizationAndBatchAndGroup bean = new OrganizationAndBatchAndGroup();
  128. bean.setType("4");
  129. bean.setName(group.getInspGroupName());
  130. bean.setCode(group.getInspGroupId());
  131. result.add(bean);
  132. }
  133. }
  134. }
  135. return result;
  136. } else {
  137. //为2,普通用户,只查自己参与的组
  138. List<OrganizationAndBatchAndGroup> result = new ArrayList<OrganizationAndBatchAndGroup>();
  139. switch (NumberUtils.toInt(type)) {
  140. case 1:
  141. //根据监督司查机构,组员应该进不到这个情况
  142. AttOrgBaseParam attOrgBaseParam = new AttOrgBaseParam();
  143. attOrgBaseParam.setPguid(pGuid);
  144. attOrgBaseParam.setAreaType("4");
  145. List<AttOrgBase> list1 = attOrgBaseDao.findList(attOrgBaseParam);
  146. if (null != list1 && 0 < list1.size()) {
  147. for (AttOrgBase att : list1) {
  148. OrganizationAndBatchAndGroup bean = new OrganizationAndBatchAndGroup();
  149. bean.setType("2");
  150. bean.setName(att.getOrgName());
  151. bean.setCode(att.getGuid());
  152. result.add(bean);
  153. }
  154. }
  155. break;
  156. case 2:
  157. //根据人员id查批次
  158. List<BisInspPlan> list2 = bisInspPlanDao.findListByUserId(userId);
  159. if (null != list2 && 0 < list2.size()) {
  160. for (BisInspPlan bis : list2) {
  161. OrganizationAndBatchAndGroup bean = new OrganizationAndBatchAndGroup();
  162. bean.setType("3");
  163. bean.setName(bis.getPrsnTitle());
  164. bean.setCode(bis.getPlnaId());
  165. result.add(bean);
  166. }
  167. }
  168. break;
  169. case 3:
  170. //根据批次查组,注意普通用户只查跟自己相关的组
  171. List<BisInspGroup> list3 = bisInspGroupDao.findListByBatchIdAndUserId(code, userId);
  172. if (null != list3 && 0 < list3.size()) {
  173. for (BisInspGroup group : list3) {
  174. OrganizationAndBatchAndGroup bean = new OrganizationAndBatchAndGroup();
  175. bean.setType("4");
  176. bean.setName(group.getInspGroupName());
  177. bean.setCode(group.getInspGroupId());
  178. result.add(bean);
  179. }
  180. }
  181. }
  182. return result;
  183. }
  184. }
  185. }
  186. return null;
  187. }
  188. @Autowired
  189. private OlBisInspOrgService olBisInspOrgService;
  190. public List<BisInspAll> getAllNode(String userid, String orgType, String orgId, String tabType, String year, String yearTaskId, String curYear, String leadDep) {
  191. if (orgType.length() == 2) {
  192. orgType = "0" + orgType;
  193. }
  194. if (orgType.length() == 1) {
  195. orgType = "00" + orgType;
  196. }
  197. if (orgType.length() == 4) {
  198. if (Integer.parseInt(orgType) > 100) {
  199. orgType = orgType.substring(1, orgType.length());
  200. }
  201. }
  202. String province = olBisInspOrgService.getProvince(orgId);
  203. String nowTime = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
  204. if (null != year && year.equals("全部")) {
  205. year = null;
  206. }
  207. return bisInspAllDao.getAllNode(userid, orgType, province, orgId, tabType, nowTime, year, yearTaskId, curYear, leadDep);
  208. }
  209. public List<BisInspAll> getAllNodeById(String id) {
  210. // 前台传过来的字符串格式化成 in 能接受的
  211. return bisInspAllDao.getAllNodeById(InspUtils.setOrgIds(id));
  212. }
  213. public List<OrganizationAndBatchAndGroup> getOrganizationTreeByParams(String guid, String userId, String type, String code, String objType) {
  214. //第一次查询code,type为空
  215. List<OrganizationAndBatchAndGroup> result = new ArrayList<OrganizationAndBatchAndGroup>();
  216. //非第一次查询,根据父id,查询子id集合
  217. //非水利部,直接根据id查询根节点
  218. BisInspAllParam bisInspAllParam = new BisInspAllParam();
  219. //查水利部下面所有的职能部门 ______
  220. bisInspAllParam.setPid(code);
  221. List<BisInspAll> list = bisInspAllDao.findList(bisInspAllParam);
  222. if (null != list && 0 < list.size()) {
  223. for (BisInspAll o : list) {
  224. OrganizationAndBatchAndGroup bean = new OrganizationAndBatchAndGroup();
  225. //根据id长度判断type
  226. String typeStr = o.getId();
  227. if (null != typeStr) {
  228. if (3 == typeStr.length()) {
  229. //待定是谁
  230. bean.setType("1");
  231. } else if (6 == typeStr.length()) {
  232. //各委员会
  233. bean.setType("2");
  234. } else if (9 == typeStr.length()) {
  235. //批次
  236. bean.setType("3");
  237. } else if (12 == typeStr.length()) {
  238. //组
  239. bean.setType("4");
  240. }
  241. }
  242. bean.setName(o.getPnm());
  243. bean.setCode(o.getId());
  244. result.add(bean);
  245. }
  246. }
  247. return result;
  248. }
  249. public List<BisInspAllNode> getAllNodeAndObj(String persId, String objType, int level, String province) {
  250. List<BisInspAllNode> list = new ArrayList<>();
  251. level = level * 3;
  252. List<BisInspAll> bisList = bisInspAllDao.getAllNodeByLevel(persId, objType, level, province);
  253. boolean notHas = true;
  254. String maxNode = "";
  255. String maxPid = "";
  256. for (BisInspAll bis : bisList) {
  257. String id = bis.getId();
  258. String pid = bis.getPid();
  259. if (id.length() == level) {
  260. notHas = false;
  261. list = getNodeList(bisList, pid, province);
  262. }
  263. if (StringUtils.isBlank(maxNode)) {
  264. maxNode = id;
  265. maxPid = pid;
  266. } else {
  267. if (maxNode.length() >= id.length()) {
  268. maxNode = id;
  269. maxPid = pid;
  270. }
  271. }
  272. }
  273. if (notHas) {
  274. list = getNodeList(bisList, maxPid, province);
  275. }
  276. if (list != null) {
  277. if (list.size() > 1) {
  278. BisInspAllNode bisInspAllNode = new BisInspAllNode();
  279. bisInspAllNode.setId(objType);
  280. bisInspAllNode.setPid("0");
  281. bisInspAllNode.setChildren(list);
  282. list = new ArrayList<>();
  283. list.add(bisInspAllNode);
  284. }
  285. }
  286. return list;
  287. }
  288. public List<BisInspAllNode> getNodeList(List<BisInspAll> bisList, String pid, String province) {
  289. List<BisInspAllNode> list = new ArrayList<>();
  290. if (StringUtils.isNotBlank(pid)) {
  291. for (BisInspAll bis : bisList) {
  292. String id = bis.getId();
  293. String pnm = bis.getPnm();
  294. String pId = bis.getPid();
  295. if (pid.equals(pId)) {
  296. List<BisInspAllNode> children = new ArrayList<>();
  297. if (id.length() == 12) {
  298. String prov = province.replace("00", "");
  299. children = bisInspAllDao.BisInspAllObjById(id, prov);
  300. for (BisInspAllNode child : children) {
  301. getChildrenList(child);
  302. }
  303. } else {
  304. children = getNodeList(bisList, id, province);
  305. }
  306. BisInspAllNode node = new BisInspAllNode();
  307. node.setId(id);
  308. node.setPnm(pnm);
  309. node.setPid(pId);
  310. node.setChildren(children);
  311. list.add(node);
  312. }
  313. }
  314. }
  315. return list;
  316. }
  317. private void getChildrenList(BisInspAllNode node) {
  318. if ("004".equals(node.getPid().substring(0, 3))) {
  319. List<BisInspKeyRegisterSection> secs = bisInspKeyRegisterSectionDao.getByRegId(node.getId());
  320. for (BisInspKeyRegisterSection sec : secs) {
  321. BisInspAllNode secNode = new BisInspAllNode();
  322. secNode.setId(sec.getId());
  323. secNode.setObjId(sec.getObjId());
  324. secNode.setPnm(sec.getNm());
  325. secNode.setPid(node.getId());
  326. secNode.setFlag("sec");
  327. secNode.setChildren(new ArrayList<>());
  328. List<BisInspKeyRegSecUnit> units = bisInspKeyRegSecUnitDao.getBySecId(sec.getId());
  329. for (BisInspKeyRegSecUnit unit : units) {
  330. BisInspAllNode unitNode = new BisInspAllNode();
  331. unitNode.setId(unit.getId());
  332. unitNode.setPnm(unit.getNm());
  333. unitNode.setObjId(unit.getObjId());
  334. unitNode.setPid(sec.getId());
  335. unitNode.setFlag("unit");
  336. secNode.getChildren().add(unitNode);
  337. }
  338. if (node.getChildren() == null) {
  339. node.setChildren(new ArrayList<>());
  340. }
  341. node.getChildren().add(secNode);
  342. }
  343. } else if ("007".equals(node.getPid().substring(0, 3))) {
  344. //得到所有单位信息
  345. List<AttMampuInfo> mampus = new ArrayList<>();
  346. List<AttMampuInfo> mampusSec = new ArrayList<>();
  347. List<AttMampuInfo> mampusThi = new ArrayList<>();
  348. AttMampuInfoParam param = new AttMampuInfoParam();
  349. param.setLev("1");
  350. param.setRegId("'" + node.getId() + "'");
  351. mampus = attMampuInfoDao.getAttMampus(param);
  352. param.setLev("2");
  353. mampusSec = attMampuInfoDao.getAttMampus(param);
  354. param.setLev("3");
  355. mampusThi = attMampuInfoDao.getAttMampus(param);
  356. List<BisInspAllNode> nodes = new ArrayList<>();
  357. Map<String, BisInspAllNode> map = nodes.stream().collect(Collectors.toMap(BisInspAllNode::getId, Function.identity()));
  358. map.put(node.getId(), node);
  359. for (AttMampuInfo info : mampus) {
  360. info.setPid(info.getRegId());
  361. getNodeList(map, info, "mamp1");
  362. }
  363. //缓存所有三级节点
  364. Map<String, BisInspAllNode> nodeThr = new HashMap<>();
  365. for (AttMampuInfo info : mampusSec) {
  366. Map<String, BisInspAllNode> parents = map.get(info.getRegId()).getChildren().stream().collect(Collectors.toMap(BisInspAllNode::getId, Function.identity()));
  367. BisInspAllNode inspAllNode = getNodeList(parents, info, "mamp2");
  368. if (inspAllNode == null) {
  369. continue;
  370. }
  371. nodeThr.put(inspAllNode.getId(), inspAllNode);
  372. }
  373. for (AttMampuInfo info : mampusThi) {
  374. getNodeList(nodeThr, info, "mamp3");
  375. }
  376. }
  377. }
  378. private BisInspAllNode getNodeList(Map<String, BisInspAllNode> map, AttMampuInfo info, String flag) {
  379. BisInspAllNode node = map.get(info.getPid());
  380. if (node == null) {
  381. return null;
  382. }
  383. BisInspAllNode child = new BisInspAllNode();
  384. child.setId(info.getId());
  385. child.setPnm(info.getNm());
  386. child.setObjId(node.getObjId());
  387. child.setPid(node.getId());
  388. child.setFlag(flag);
  389. if (node.getChildren() == null) {
  390. node.setChildren(new ArrayList<>());
  391. }
  392. node.getChildren().add(child);
  393. return child;
  394. }
  395. }