|
|
@@ -0,0 +1,265 @@
|
|
|
+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.github.pagehelper.PageHelper;
|
|
|
+import com.ydtech.constants.sys.SystemConstant;
|
|
|
+import com.ydtech.core.page.HttpResult;
|
|
|
+import com.ydtech.core.page.PageRequest;
|
|
|
+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.entity.InsOrders;
|
|
|
+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;
|
|
|
+
|
|
|
+@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 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());
|
|
|
+ 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());
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<PtlAgreementInsCompanyDto> getAgreementInsCompany(String deptId, String userId, String license,String volume) {
|
|
|
+ //查出所有协议
|
|
|
+ List<PtlAgreementInsCompanyDto> agreementInsCompany = this.getAgreementInsCompany(deptId, userId);
|
|
|
+ //排除的部门信息
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|