EsmInsCompanyServiceImpl.java 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. package com.ydtech.modules.esm.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  4. import com.ydtech.modules.esm.dao.EsmInsCompanyMapper;
  5. import com.ydtech.modules.esm.model.EsmInsCompany;
  6. import com.ydtech.modules.esm.model.vo.req.EsmInsCompanyReq;
  7. import com.ydtech.modules.esm.service.EsmInsCompanyService;
  8. import com.ydtech.modules.protocol.utils.AssertionUtils;
  9. import com.ydtech.utils.StringUtils;
  10. import org.springframework.beans.BeanUtils;
  11. import org.springframework.stereotype.Service;
  12. import java.util.ArrayList;
  13. import java.util.List;
  14. import java.util.concurrent.atomic.AtomicBoolean;
  15. @Service
  16. public class EsmInsCompanyServiceImpl extends ServiceImpl<EsmInsCompanyMapper, EsmInsCompany>
  17. implements EsmInsCompanyService {
  18. // @Override
  19. // public EsmInsCompany isOpen(String company) {
  20. // LambdaQueryWrapper<EsmInsCompany> wrapper = new LambdaQueryWrapper<>();
  21. // wrapper.eq(EsmInsCompany::getId, company)
  22. // .eq(EsmInsCompany::getDelFlag, "0")
  23. // .eq(EsmInsCompany::getOpenQuote, "1");
  24. // EsmInsCompany esmInsCompanies = baseMapper.selectOne(wrapper);
  25. // if (ObjectUtils.isEmpty(esmInsCompanies)) {
  26. // throw new SystemException("报价公司未开启, 请联系团队长配置。");
  27. // }
  28. // return esmInsCompanies;
  29. // }
  30. @Override
  31. public List<EsmInsCompany> findTree(EsmInsCompanyReq req) {
  32. LambdaQueryWrapper<EsmInsCompany> lqw = new LambdaQueryWrapper<>();
  33. if (null != req) {
  34. lqw.like(StringUtils.isNotEmpty(req.getName()), EsmInsCompany::getName, req.getName());
  35. lqw.eq(StringUtils.isNotEmpty(req.getType()), EsmInsCompany::getType, req.getType());
  36. // lqw.like(StringUtils.isNotEmpty(req.getParentId()), EsmInsCompany::getParentId, req.getParentId());
  37. }
  38. List<EsmInsCompany> list = new ArrayList<>();
  39. List<EsmInsCompany> allList = list(lqw);
  40. allList.forEach(r -> {
  41. if (StringUtils.isNullOrEmpty(r.getParentId()) || r.getParentId().equalsIgnoreCase("0") && (!exists(list, r))) {
  42. r.setLogo("");
  43. list.add(r);
  44. }
  45. });
  46. findChildren(list, allList);
  47. return list;
  48. }
  49. @Override
  50. public EsmInsCompany isExists(String companyId) {
  51. EsmInsCompany esmInsCompany = baseMapper.selectById(companyId);
  52. AssertionUtils.isEmpty(esmInsCompany, "保险公司不存在");
  53. return esmInsCompany;
  54. }
  55. @Override
  56. public EsmInsCompany findInsCompanyByName(String companyName) {
  57. LambdaQueryWrapper<EsmInsCompany> lqw = new LambdaQueryWrapper<>();
  58. lqw.eq(EsmInsCompany::getName, companyName);
  59. List<EsmInsCompany> list = list(lqw);
  60. if (null != list && !list.isEmpty()) {
  61. return list.get(0);
  62. }
  63. return null;
  64. }
  65. private void findChildren(List<EsmInsCompany> list, List<EsmInsCompany> allList) {
  66. for (EsmInsCompany l : list) {
  67. List<EsmInsCompany> children = new ArrayList<>();
  68. for (EsmInsCompany esmInsCompany : allList) {
  69. if (l.getId() != null && l.getId().equals(esmInsCompany.getParentId())) {
  70. if (!exists(children, esmInsCompany)) {
  71. esmInsCompany.setLogo("");
  72. children.add(esmInsCompany);
  73. }
  74. }
  75. }
  76. l.setChildren(children);
  77. // children.sort((o1, o2) -> o1.getOrderNum().compareTo(o2.getOrderNum()));
  78. findChildren(children, allList);
  79. }
  80. }
  81. private boolean exists(List<EsmInsCompany> insCompanyList, EsmInsCompany insCompany) {
  82. AtomicBoolean exist = new AtomicBoolean(false);
  83. insCompanyList.stream().forEach(a -> {
  84. if (a.getId().equals(insCompany.getId())) {
  85. exist.set(true);
  86. }
  87. });
  88. return exist.get();
  89. }
  90. @Override
  91. public EsmInsCompany getBySubsidiary(String subsidiaryId) {
  92. String code = "000000";
  93. String substring = subsidiaryId.substring(0, 5);
  94. String companyId = substring + code;
  95. EsmInsCompany esmInsCompany = getById(companyId);
  96. AssertionUtils.isEmpty(esmInsCompany, "保险公司不存在");
  97. return esmInsCompany;
  98. }
  99. @Override
  100. public List<String> getByLowerId(String companyId) {
  101. return baseMapper.getByLowerId(companyId);
  102. }
  103. @Override
  104. public List<String> getAllRelationCompanyId(String companyId){
  105. // //获取本级和下级
  106. // List result=getByLowerId(companyId);
  107. //调整为查本级和上级
  108. List<String> result=new ArrayList<>();
  109. //放入本级
  110. result.add(companyId);
  111. //取出本级机构信息
  112. EsmInsCompany insCompany=getById(companyId);
  113. //放入上级
  114. while (!"0".equals(insCompany.getParentId())){
  115. LambdaQueryWrapper<EsmInsCompany> lqw1 = new LambdaQueryWrapper<>();
  116. lqw1.eq(EsmInsCompany::getId, insCompany.getParentId());
  117. List<EsmInsCompany> list = list(lqw1);
  118. if (null != list && !list.isEmpty()) {
  119. insCompany=list.get(0);
  120. result.add(insCompany.getId());
  121. }
  122. }
  123. return result;
  124. }
  125. @Override
  126. public List<String> getInsCompanyNextLevel(String companyId){
  127. List<String> result=new ArrayList<>();
  128. LambdaQueryWrapper<EsmInsCompany> wrapper = new LambdaQueryWrapper<>();
  129. wrapper.eq(EsmInsCompany::getType,"1");
  130. if(StringUtils.isNotEmpty(companyId)){
  131. //不为空时,需要找选定机构的下一层
  132. wrapper.eq(EsmInsCompany::getParentId,companyId);
  133. }else{
  134. //为空时,直接查询顶层保险公司机构 parentid=0
  135. wrapper.eq(EsmInsCompany::getParentId,"0");
  136. }
  137. List<EsmInsCompany> allList = list(wrapper);
  138. allList.forEach(item -> {
  139. result.add(item.getId());
  140. });
  141. return result;
  142. }
  143. @Override
  144. public List<EsmInsCompany> queryListByParentId(String parentId) {
  145. List<EsmInsCompany> resultList=baseMapper.queryListByParentId(parentId);
  146. return resultList;
  147. }
  148. }