| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- package com.ydtech.modules.esm.service.impl;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.ydtech.modules.esm.dao.EsmInsCompanyMapper;
- import com.ydtech.modules.esm.model.EsmInsCompany;
- import com.ydtech.modules.esm.model.vo.req.EsmInsCompanyReq;
- import com.ydtech.modules.esm.service.EsmInsCompanyService;
- import com.ydtech.modules.protocol.utils.AssertionUtils;
- import com.ydtech.utils.StringUtils;
- import org.springframework.beans.BeanUtils;
- import org.springframework.stereotype.Service;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.concurrent.atomic.AtomicBoolean;
- @Service
- public class EsmInsCompanyServiceImpl extends ServiceImpl<EsmInsCompanyMapper, EsmInsCompany>
- implements EsmInsCompanyService {
- // @Override
- // public EsmInsCompany isOpen(String company) {
- // LambdaQueryWrapper<EsmInsCompany> wrapper = new LambdaQueryWrapper<>();
- // wrapper.eq(EsmInsCompany::getId, company)
- // .eq(EsmInsCompany::getDelFlag, "0")
- // .eq(EsmInsCompany::getOpenQuote, "1");
- // EsmInsCompany esmInsCompanies = baseMapper.selectOne(wrapper);
- // if (ObjectUtils.isEmpty(esmInsCompanies)) {
- // throw new SystemException("报价公司未开启, 请联系团队长配置。");
- // }
- // return esmInsCompanies;
- // }
- @Override
- public List<EsmInsCompany> findTree(EsmInsCompanyReq req) {
- LambdaQueryWrapper<EsmInsCompany> lqw = new LambdaQueryWrapper<>();
- if (null != req) {
- lqw.like(StringUtils.isNotEmpty(req.getName()), EsmInsCompany::getName, req.getName());
- lqw.eq(StringUtils.isNotEmpty(req.getType()), EsmInsCompany::getType, req.getType());
- // lqw.like(StringUtils.isNotEmpty(req.getParentId()), EsmInsCompany::getParentId, req.getParentId());
- }
- List<EsmInsCompany> list = new ArrayList<>();
- List<EsmInsCompany> allList = list(lqw);
- allList.forEach(r -> {
- if (StringUtils.isNullOrEmpty(r.getParentId()) || r.getParentId().equalsIgnoreCase("0") && (!exists(list, r))) {
- r.setLogo("");
- list.add(r);
- }
- });
- findChildren(list, allList);
- return list;
- }
- @Override
- public EsmInsCompany isExists(String companyId) {
- EsmInsCompany esmInsCompany = baseMapper.selectById(companyId);
- AssertionUtils.isEmpty(esmInsCompany, "保险公司不存在");
- return esmInsCompany;
- }
- @Override
- public EsmInsCompany findInsCompanyByName(String companyName) {
- LambdaQueryWrapper<EsmInsCompany> lqw = new LambdaQueryWrapper<>();
- lqw.eq(EsmInsCompany::getName, companyName);
- List<EsmInsCompany> list = list(lqw);
- if (null != list && !list.isEmpty()) {
- return list.get(0);
- }
- return null;
- }
- private void findChildren(List<EsmInsCompany> list, List<EsmInsCompany> allList) {
- for (EsmInsCompany l : list) {
- List<EsmInsCompany> children = new ArrayList<>();
- for (EsmInsCompany esmInsCompany : allList) {
- if (l.getId() != null && l.getId().equals(esmInsCompany.getParentId())) {
- if (!exists(children, esmInsCompany)) {
- esmInsCompany.setLogo("");
- children.add(esmInsCompany);
- }
- }
- }
- l.setChildren(children);
- // children.sort((o1, o2) -> o1.getOrderNum().compareTo(o2.getOrderNum()));
- findChildren(children, allList);
- }
- }
- private boolean exists(List<EsmInsCompany> insCompanyList, EsmInsCompany insCompany) {
- AtomicBoolean exist = new AtomicBoolean(false);
- insCompanyList.stream().forEach(a -> {
- if (a.getId().equals(insCompany.getId())) {
- exist.set(true);
- }
- });
- return exist.get();
- }
- @Override
- public EsmInsCompany getBySubsidiary(String subsidiaryId) {
- String code = "000000";
- String substring = subsidiaryId.substring(0, 5);
- String companyId = substring + code;
- EsmInsCompany esmInsCompany = getById(companyId);
- AssertionUtils.isEmpty(esmInsCompany, "保险公司不存在");
- return esmInsCompany;
- }
- @Override
- public List<String> getByLowerId(String companyId) {
- return baseMapper.getByLowerId(companyId);
- }
- @Override
- public List<String> getAllRelationCompanyId(String companyId){
- // //获取本级和下级
- // List result=getByLowerId(companyId);
- //调整为查本级和上级
- List<String> result=new ArrayList<>();
- //放入本级
- result.add(companyId);
- //取出本级机构信息
- EsmInsCompany insCompany=getById(companyId);
- //放入上级
- while (!"0".equals(insCompany.getParentId())){
- LambdaQueryWrapper<EsmInsCompany> lqw1 = new LambdaQueryWrapper<>();
- lqw1.eq(EsmInsCompany::getId, insCompany.getParentId());
- List<EsmInsCompany> list = list(lqw1);
- if (null != list && !list.isEmpty()) {
- insCompany=list.get(0);
- result.add(insCompany.getId());
- }
- }
- return result;
- }
- @Override
- public List<String> getInsCompanyNextLevel(String companyId){
- List<String> result=new ArrayList<>();
- LambdaQueryWrapper<EsmInsCompany> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(EsmInsCompany::getType,"1");
- if(StringUtils.isNotEmpty(companyId)){
- //不为空时,需要找选定机构的下一层
- wrapper.eq(EsmInsCompany::getParentId,companyId);
- }else{
- //为空时,直接查询顶层保险公司机构 parentid=0
- wrapper.eq(EsmInsCompany::getParentId,"0");
- }
- List<EsmInsCompany> allList = list(wrapper);
- allList.forEach(item -> {
- result.add(item.getId());
- });
- return result;
- }
- @Override
- public List<EsmInsCompany> queryListByParentId(String parentId) {
- List<EsmInsCompany> resultList=baseMapper.queryListByParentId(parentId);
- return resultList;
- }
- }
|