| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381 |
- package com.ydtech.modules.protocol.service.impl;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.ydtech.constants.sys.SystemConstant;
- import com.ydtech.modules.admin.constants.RoleConstants;
- import com.ydtech.modules.admin.model.SysUserRole;
- import com.ydtech.modules.admin.service.SysUserRoleService;
- import com.ydtech.modules.esm.model.EsmInsCompany;
- import com.ydtech.modules.esm.service.EsmInsCompanyService;
- import com.ydtech.modules.order.service.InsOrdersService;
- import com.ydtech.modules.protocol.constants.TaxSourceStatusConstants;
- import com.ydtech.modules.protocol.dao.TaxSourceMapper;
- import com.ydtech.modules.protocol.entity.dto.PtlAgreementDto;
- import com.ydtech.modules.protocol.entity.dto.PtlAgreementInsCompanyDto;
- import com.ydtech.modules.protocol.entity.dto.TaxSourceDto;
- import com.ydtech.modules.protocol.entity.dto.TaxSourceExcludeDto;
- import com.ydtech.modules.protocol.entity.po.PtlAgreement;
- import com.ydtech.modules.protocol.entity.vo.TaxSourceVo;
- import com.ydtech.modules.protocol.service.ITaxSourceExcludeService;
- import com.ydtech.modules.protocol.service.ITaxSourceService;
- import com.ydtech.modules.protocol.service.PtlAgreementService;
- import com.ydtech.utils.idgen.IdGenerate;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Objects;
- import java.util.stream.Collectors;
- @Service
- public class TaxSourceServiceImpl extends ServiceImpl<TaxSourceMapper, TaxSourceDto> implements ITaxSourceService {
- @Autowired
- PtlAgreementService ptlAgreementService;
- @Autowired
- ITaxSourceExcludeService taxSourceExcludeService;
- @Autowired
- InsOrdersService insOrdersService;
- @Autowired
- SysUserRoleService sysUserRoleService;
- @Autowired
- EsmInsCompanyService esmInsCompanyService;
- @Override
- public IPage<EsmInsCompany> getInsureCompany(Page page) {
- return baseMapper.getInsureCompany(page);
- }
- @Override
- public List<PtlAgreement> getAgreementByCompanyId(String companyId, String deptId, String userId) {
- List<PtlAgreementInsCompanyDto> agreementInsCompany = this.getAgreementInsCompany(deptId, userId);
- List<String> agreementIds = new ArrayList<>();
- for (PtlAgreementInsCompanyDto item : agreementInsCompany) {
- if (item.getId().equals(companyId)) {
- for (PtlAgreementDto agreementDto : item.getAgreement()) {
- agreementIds.add(agreementDto.getId());
- }
- }
- }
- QueryWrapper<PtlAgreement> queryWrapper = new QueryWrapper<>();
- queryWrapper.in("id", agreementIds);
- List<PtlAgreement> list = ptlAgreementService.list(queryWrapper);
- return list;
- }
- @Override
- @Transactional
- public boolean saveTaxSource(TaxSourceVo taxSourceVo) {
- //删除排除的信息
- taxSourceExcludeService.remove(new LambdaQueryWrapper<TaxSourceExcludeDto>().eq(TaxSourceExcludeDto::getInsCompanyId, taxSourceVo.getInsCompanyId()));
- //删除税源配置信息
- baseMapper.delete(new LambdaQueryWrapper<TaxSourceDto>().eq(TaxSourceDto::getInsCompanyId,
- taxSourceVo.getInsCompanyId()));
- //组装税源数据
- List<TaxSourceDto> dtos = new ArrayList<>();
- List<TaxSourceExcludeDto> excludeDtos = new ArrayList<>();
- taxSourceVo.getAgreementTaxList().forEach(agreementTax -> {
- TaxSourceDto dto = new TaxSourceDto();
- dto.setId(IdGenerate.nextId());
- dto.setInsCompanyId(taxSourceVo.getInsCompanyId());
- dto.setInsCompanyName(taxSourceVo.getInsCompanyName());
- dto.setAgreementId(agreementTax.getAgreementId());
- dto.setIsTaxSource(agreementTax.getIsTaxSource());
- dto.setLicense(agreementTax.getLicense());
- dto.setInsuranceRepertoire(agreementTax.getInsuranceRepertoire());
- dtos.add(dto);
- });
- //组装排除的部门信息
- for (String agreementTaxExclude : taxSourceVo.getAgreementTaxExcludeDeptList()) {
- TaxSourceExcludeDto dto = new TaxSourceExcludeDto();
- dto.setId(IdGenerate.nextId());
- dto.setType(Integer.parseInt(TaxSourceStatusConstants.EXCLUDE_TYPE_DEPT));
- dto.setInsCompanyId(taxSourceVo.getInsCompanyId());
- dto.setExcludeInfo(agreementTaxExclude);
- excludeDtos.add(dto);
- }
- // taxSourceVo.getAgreementTaxExcludeDeptList().forEach(agreementTaxExclude -> {
- // TaxSourceExcludeDto dto = new TaxSourceExcludeDto();
- // dto.setId(IdGenerate.nextId());
- // dto.setType(Integer.parseInt(TaxSourceStatusConstants.EXCLUDE_TYPE_DEPT));
- // dto.setInsCompanyId(taxSourceVo.getInsCompanyId());
- // dto.setExcludeInfo(agreementTaxExclude.getExcludeInfo());
- // excludeDtos.add(dto);
- // });
- //组装排除的车牌号信息
- for (String agreementTaxExclude : taxSourceVo.getAgreementTaxExcludeLicenseList()) {
- TaxSourceExcludeDto dto = new TaxSourceExcludeDto();
- dto.setId(IdGenerate.nextId());
- dto.setType(Integer.parseInt(TaxSourceStatusConstants.EXCLUDE_TYPE_LICENSE));
- dto.setInsCompanyId(taxSourceVo.getInsCompanyId());
- dto.setExcludeInfo(agreementTaxExclude);
- excludeDtos.add(dto);
- }
- // taxSourceVo.getAgreementTaxExcludeLicenseList().forEach(agreementTaxExclude -> {
- // TaxSourceExcludeDto dto = new TaxSourceExcludeDto();
- // dto.setId(IdGenerate.nextId());
- // dto.setType(Integer.parseInt(TaxSourceStatusConstants.EXCLUDE_TYPE_LICENSE));
- // dto.setInsCompanyId(taxSourceVo.getInsCompanyId());
- // dto.setExcludeInfo(agreementTaxExclude.getExcludeInfo());
- // excludeDtos.add(dto);
- // });
- this.saveBatch(dtos);
- taxSourceExcludeService.saveBatch(excludeDtos);
- return true;
- }
- @Override
- public TaxSourceVo getTaxSource(String companyId) {
- TaxSourceVo taxSourceVo = new TaxSourceVo();
- //税源信息
- List<TaxSourceDto> taxSourceDto =
- baseMapper.selectList(new LambdaQueryWrapper<TaxSourceDto>().eq(TaxSourceDto::getInsCompanyId,
- companyId));
- //排除的部门信息
- List<TaxSourceExcludeDto> taxSourceExcludeDepts =
- taxSourceExcludeService.list(new LambdaQueryWrapper<TaxSourceExcludeDto>().eq(TaxSourceExcludeDto::getInsCompanyId, companyId).eq(TaxSourceExcludeDto::getType, TaxSourceStatusConstants.EXCLUDE_TYPE_DEPT));
- //排除的车牌号信息
- List<TaxSourceExcludeDto> taxSourceExcludeLicense =
- taxSourceExcludeService.list(new LambdaQueryWrapper<TaxSourceExcludeDto>().eq(TaxSourceExcludeDto::getInsCompanyId, companyId).eq(TaxSourceExcludeDto::getType, TaxSourceStatusConstants.EXCLUDE_TYPE_LICENSE));
- taxSourceVo.setInsCompanyId(companyId);
- //税源信息转换
- List<TaxSourceVo.AgreementTax> agreementTaxList = new ArrayList<>();
- taxSourceDto.forEach(item -> {
- TaxSourceVo.AgreementTax agreementTax = new TaxSourceVo.AgreementTax();
- agreementTax.setAgreementId(item.getAgreementId());
- agreementTax.setIsTaxSource(item.getIsTaxSource());
- agreementTax.setLicense(item.getLicense());
- agreementTax.setInsuranceRepertoire(item.getInsuranceRepertoire());
- agreementTaxList.add(agreementTax);
- });
- taxSourceVo.setAgreementTaxList(agreementTaxList);
- //部门信息转换
- List<String> agreementTaxExcludeDepts = new ArrayList<>();
- taxSourceExcludeDepts.forEach(item -> {
- agreementTaxExcludeDepts.add(item.getExcludeInfo());
- });
- taxSourceVo.setAgreementTaxExcludeDeptList(agreementTaxExcludeDepts.toArray(new String[agreementTaxExcludeDepts.size()]));
- //车牌信息转换
- List<String> agreementTaxExcludeLicense = new ArrayList<>();
- taxSourceExcludeLicense.forEach(item -> {
- agreementTaxExcludeLicense.add(item.getExcludeInfo());
- });
- taxSourceVo.setAgreementTaxExcludeLicenseList(agreementTaxExcludeLicense.toArray(new String[agreementTaxExcludeLicense.size()]));
- return taxSourceVo;
- }
- public List<PtlAgreementInsCompanyDto> getAgreementInsCompany(String deptId, String userId) {
- // 领导标志
- SysUserRole userRole = sysUserRoleService.selectByUserId(userId);
- if (Arrays.asList(SystemConstant.getSysRoleTeamLeader()).contains(userRole.getRoleId().toString()) && !RoleConstants.R21.getCode().equals(userRole.getRoleId().toString())) { //团队长可查询下面所有人员订单
- deptId = null;
- }
- List<PtlAgreementInsCompanyDto> agreementCompany = ptlAgreementService.getAgreementCompany(deptId);
- return agreementCompany;
- }
- public PtlAgreementInsCompanyDto getAgreementInsCompany(String deptId, String userId, String companyId) {
- // 领导标志
- SysUserRole userRole = sysUserRoleService.selectByUserId(userId);
- if (Arrays.asList(SystemConstant.getSysRoleTeamLeader()).contains(userRole.getRoleId().toString()) && !RoleConstants.R21.getCode().equals(userRole.getRoleId().toString())) { //团队长可查询下面所有人员订单
- deptId = null;
- }
- PtlAgreementInsCompanyDto agreementCompany = ptlAgreementService.getAgreementCompany(deptId, companyId);
- return agreementCompany;
- }
- // @Override
- // public List<PtlAgreementInsCompanyDto> getAgreementInsCompany(String deptId, String userId, String license,
- // String volume) {
- // //查出所有协议
- // List<PtlAgreementInsCompanyDto> agreementInsCompany = this.getAgreementInsCompany(deptId, userId);
- // if(license != null && volume != null) {
- // //排除的部门信息
- // List<TaxSourceExcludeDto> excludeDepts = taxSourceExcludeService.list(new
- // LambdaQueryWrapper<TaxSourceExcludeDto>().eq
- // (TaxSourceExcludeDto::getExcludeInfo, deptId)
- // .eq(TaxSourceExcludeDto::getType, TaxSourceStatusConstants.EXCLUDE_TYPE_DEPT));
- //
- // agreementInsCompany.forEach(item ->
- // excludeDepts.stream()
- // .filter(taxSourceDto -> item.getId().equals(taxSourceDto.getInsCompanyId()) &&
- // taxSourceDto.getExcludeInfo
- // ().equals(deptId))
- // .findFirst()
- // .ifPresent(taxSourceDto -> item.setIsExclude(TaxSourceStatusConstants.TAX_SOURCE_START))
- // );
- // //查找排除的车牌号
- // List<TaxSourceExcludeDto> licenseExclude = taxSourceExcludeService.list(new
- // LambdaQueryWrapper<TaxSourceExcludeDto>().eq
- // (TaxSourceExcludeDto::getExcludeInfo, license)
- // .eq(TaxSourceExcludeDto::getType, TaxSourceStatusConstants.EXCLUDE_TYPE_LICENSE));
- // agreementInsCompany.forEach(item -> {
- // licenseExclude.forEach(taxSourceDto -> {
- // if (item.getId().equals(taxSourceDto.getInsCompanyId())) {
- // if (license.equals(taxSourceDto.getExcludeInfo())) {
- // //排除
- // item.setIsExclude(TaxSourceStatusConstants.TAX_SOURCE_START);
- // }
- // }
- // });
- // });
- //
- // //查找配置的默认项
- // List<TaxSourceDto> taxSourceDefaultDtos = baseMapper.selectList(new LambdaQueryWrapper<TaxSourceDto>()
- // .eq(TaxSourceDto::getLicense, license));
- // //设置协议的默认项
- // agreementInsCompany.forEach(item -> {
- // taxSourceDefaultDtos.forEach(taxSourceDto -> {
- // if (item.getId().equals(taxSourceDto.getInsCompanyId())) {
- // item.getAgreement().forEach(agreement -> {
- // if (agreement.getId().equals(taxSourceDto.getAgreementId())) {
- // agreement.setIsAllocation(TaxSourceStatusConstants.TAX_SOURCE_START);
- // }
- // });
- // }
- // });
- // });
- // //判断汽车排量是否大于1升
- // if (Float.parseFloat(volume) >= 1) {
- // //查找是否配置税源
- // List<TaxSourceDto> taxSourceDtos = baseMapper.selectList(new LambdaQueryWrapper<TaxSourceDto>().eq
- // (TaxSourceDto::getIsTaxSource, "1"));
- // //设置税源参数
- // agreementInsCompany.forEach(item -> {
- // if (!TaxSourceStatusConstants.TAX_SOURCE_START.equals(item.getIsExclude())) {
- // taxSourceDtos.forEach(taxSourceDto -> {
- // if (item.getId().equals(taxSourceDto.getInsCompanyId())) {
- // item.getAgreement().forEach(agreement -> {
- // if (agreement.getId().equals(taxSourceDto.getAgreementId())) {
- // agreement.setIsTaxSource(TaxSourceStatusConstants.TAX_SOURCE_START);
- // item.setIsTaxSource(TaxSourceStatusConstants.TAX_SOURCE_START);
- // item.setTaxSourceAgreementId(taxSourceDto.getAgreementId());
- // }
- // });
- // }
- // });
- // }
- // });
- // }
- // }
- // return agreementInsCompany;
- // }
- /**
- * 返回是否是税源
- *
- * @param deptId
- * @param userId
- * @return
- */
- @Override
- public List<PtlAgreementInsCompanyDto> getAllAgreement(String deptId, String userId) {
- //查出所有协议
- List<PtlAgreementInsCompanyDto> agreementInsCompany = this.getAgreementInsCompany(deptId, userId);
- //查找是否配置税源
- List<TaxSourceDto> taxSourceDtos =
- baseMapper.selectList(new LambdaQueryWrapper<TaxSourceDto>().eq(TaxSourceDto::getIsTaxSource, "1"));
- //设置税源参数
- agreementInsCompany.forEach(item -> {
- if (!TaxSourceStatusConstants.TAX_SOURCE_START.equals(item.getIsExclude())) {
- taxSourceDtos.forEach(taxSourceDto -> {
- if (item.getId().equals(taxSourceDto.getInsCompanyId())) {
- item.getAgreement().forEach(agreement -> {
- if (agreement.getId().equals(taxSourceDto.getAgreementId())) {
- agreement.setIsTaxSource(TaxSourceStatusConstants.TAX_SOURCE_START);
- item.setIsTaxSource(TaxSourceStatusConstants.TAX_SOURCE_START);
- item.setTaxSourceAgreementId(taxSourceDto.getAgreementId());
- }
- });
- }
- });
- }
- });
- return agreementInsCompany;
- }
- /**
- * 根据税源获取协议id
- *
- * @param deptId
- * @param userId
- * @param companyId
- * @param license
- * @param volume
- * @return
- */
- @Override
- public String getAgreementId(String deptId, String userId, String companyId, String license, String volume,
- String productid) {
- // 车牌前两位
- String firstTwoPlates = license.substring(0, 2);
- String resultId = "";
- //查找配置的默认项
- List<TaxSourceDto> taxSourceDtoList =
- baseMapper.selectList(new LambdaQueryWrapper<TaxSourceDto>().eq(TaxSourceDto::getInsCompanyId,
- companyId));
- List<TaxSourceDto> taxSource =
- taxSourceDtoList.stream().filter(x -> x.getLicense().equals(firstTwoPlates)).collect(Collectors.toList());
- if (!taxSource.isEmpty()) {
- resultId = taxSourceDtoList.get(0).getAgreementId();
- }
- boolean isExclude = false;
- //排除的部门信息
- List<TaxSourceExcludeDto> excludeDepts =
- taxSourceExcludeService.list(new LambdaQueryWrapper<TaxSourceExcludeDto>().eq(TaxSourceExcludeDto::getExcludeInfo, deptId).eq(TaxSourceExcludeDto::getInsCompanyId, companyId).eq(TaxSourceExcludeDto::getType, TaxSourceStatusConstants.EXCLUDE_TYPE_DEPT));
- //部门排除
- if (excludeDepts.stream().anyMatch(taxSourceDto -> taxSourceDto.getExcludeInfo().equals(deptId))) {
- isExclude = true;
- }
- //查找排除的车牌号
- List<TaxSourceExcludeDto> licenseExclude =
- taxSourceExcludeService.list(new LambdaQueryWrapper<TaxSourceExcludeDto>().eq(TaxSourceExcludeDto::getExcludeInfo, firstTwoPlates).eq(TaxSourceExcludeDto::getType, TaxSourceStatusConstants.EXCLUDE_TYPE_LICENSE));
- //车牌排除
- if (licenseExclude.stream().anyMatch(taxSourceDto -> taxSourceDto.getExcludeInfo().equals(firstTwoPlates))) {
- isExclude = true;
- }
- // 税源
- TaxSourceDto taxSourceDtos =
- taxSourceDtoList.stream().filter(x -> x.getIsTaxSource().equals("1")).collect(Collectors.toList()).get(0);
- if (!isExclude && (Float.parseFloat(volume) >= 1) && (taxSourceDtos != null)) {
- resultId = taxSourceDtos.getAgreementId();
- }
- // 不包含险种 随机其他保险公司
- if (taxSourceDtos != null && taxSourceDtos.getAgreementId().equals(resultId) && taxSourceDtos.getInsuranceRepertoire().contains(productid)) {
- resultId = taxSourceDtos.getBanishAgreementId();
- }
- return resultId;
- }
- }
|