|  |  |  | 
|---|
|  |  |  | import com.doumee.core.model.PageWrap; | 
|---|
|  |  |  | import com.doumee.core.utils.Constants; | 
|---|
|  |  |  | import com.doumee.core.utils.Utils; | 
|---|
|  |  |  | import com.doumee.dao.business.CompanyMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.SolutionsMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.TaxDetialMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.TaxesMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.dto.DirectInvoicingDTO; | 
|---|
|  |  |  | import com.doumee.dao.business.dto.DirectInvoicingDetailDTO; | 
|---|
|  |  |  | import com.doumee.dao.business.dto.EntrustInvoicingDTO; | 
|---|
|  |  |  | import com.doumee.dao.business.join.ApplyChangeJoinMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.join.InsuranceApplyJoinMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.join.TaxDetailJoinMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.join.TaxesJoinMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.model.*; | 
|---|
|  |  |  | import com.doumee.dao.business.vo.TaxesInvoicingVO; | 
|---|
|  |  |  | import com.doumee.dao.system.model.SystemUser; | 
|---|
|  |  |  | import com.doumee.service.business.TaxesService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.metadata.IPage; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.github.xiaoymin.knife4j.core.util.CollectionUtils; | 
|---|
|  |  |  | import com.github.yulichang.wrapper.MPJLambdaWrapper; | 
|---|
|  |  |  | import org.apache.commons.lang3.StringUtils; | 
|---|
|  |  |  | import org.apache.shiro.SecurityUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.util.CollectionUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.math.BigDecimal; | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 发票信息表Service实现 | 
|---|
|  |  |  | 
|---|
|  |  |  | private TaxDetailJoinMapper taxDetailJoinMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SystemDictDataBiz systemDictDataBiz; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private CompanyMapper companyMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private InsuranceApplyJoinMapper insuranceApplyJoinMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ApplyChangeJoinMapper applyChangeJoinMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SolutionsMapper solutionsMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Integer create(Taxes taxes) { | 
|---|
|  |  |  | 
|---|
|  |  |  | queryWrapper.eq(Taxes::getCompanyId,-1);//设置无效访问 | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | queryWrapper.in(Taxes::getCompanyId,user.getCompanyIdList()); | 
|---|
|  |  |  | queryWrapper.ge(pageWrap.getModel().getStartDate() != null,Taxes::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getStartDate())); | 
|---|
|  |  |  | queryWrapper.le(SignRecord::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getEndDate())); | 
|---|
|  |  |  | queryWrapper.ge(pageWrap.getModel().getStartDate() != null,Taxes::getCreateDate, pageWrap.getModel().getStartDate()); | 
|---|
|  |  |  | queryWrapper.le(pageWrap.getModel().getEndDate() != null,Taxes::getCreateDate, pageWrap.getModel().getEndDate()); | 
|---|
|  |  |  | queryWrapper.eq(pageWrap.getModel().getTaxBank() != null,Taxes::getTaxBank, pageWrap.getModel().getTaxBank()); | 
|---|
|  |  |  | queryWrapper.eq(pageWrap.getModel().getTaxBank() != null,Taxes::getTaxBank, pageWrap.getModel().getTaxBank()); | 
|---|
|  |  |  | queryWrapper.eq(pageWrap.getModel().getRemark() != null,Taxes::getRemark, pageWrap.getModel().getRemark()); | 
|---|
|  |  |  | 
|---|
|  |  |  | QueryWrapper<Taxes> wrapper = new QueryWrapper<>(taxes); | 
|---|
|  |  |  | return taxesMapper.selectCount(wrapper); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public PageData<Taxes> findPageForCompany(PageWrap<Taxes> pageWrap) { | 
|---|
|  |  |  | LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|---|
|  |  |  | IPage<Taxes> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); | 
|---|
|  |  |  | MPJLambdaWrapper<Taxes> queryWrapper = new MPJLambdaWrapper<>(); | 
|---|
|  |  |  | queryWrapper.selectAll(Taxes.class); | 
|---|
|  |  |  | queryWrapper.selectAs(SystemUser::getRealname,Taxes::getCreatorName); | 
|---|
|  |  |  | queryWrapper.leftJoin(SystemUser.class,SystemUser::getId,Taxes::getCreator); | 
|---|
|  |  |  | Utils.MP.blankToNull(pageWrap.getModel()); | 
|---|
|  |  |  | queryWrapper.eq(Taxes::getIsdeleted, Constants.ZERO); | 
|---|
|  |  |  | Taxes queryModel = pageWrap.getModel(); | 
|---|
|  |  |  | if(!user.getType().equals(Constants.ONE)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"非企业用户无法进行该业务查询"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!Objects.isNull(queryModel)){ | 
|---|
|  |  |  | queryWrapper.ge(pageWrap.getModel().getStartDate() != null,Taxes::getCreateDate, (pageWrap.getModel().getStartDate())); | 
|---|
|  |  |  | queryWrapper.le(pageWrap.getModel().getEndDate() != null,Taxes::getCreateDate,  (pageWrap.getModel().getEndDate())); | 
|---|
|  |  |  | queryWrapper.eq(!Objects.isNull(queryModel.getInsuranceApplyId()),Taxes::getInsuranceApplyId,queryModel.getInsuranceApplyId()); | 
|---|
|  |  |  | queryWrapper.eq(!Objects.isNull(queryModel.getStatus()),Taxes::getStatus,queryModel.getStatus()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | queryWrapper.orderByAsc(Taxes::getCreateDate); | 
|---|
|  |  |  | PageData<Taxes>  result =PageData.from(taxesJoinMapper.selectJoinPage(page,Taxes.class, queryWrapper)); | 
|---|
|  |  |  | if(result!=null && result.getRecords()!=null){ | 
|---|
|  |  |  | String path =systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()+systemDictDataBiz.queryByCode(Constants.OSS,Constants.TAXES_FILE).getCode(); | 
|---|
|  |  |  | for(Taxes t : result.getRecords()){ | 
|---|
|  |  |  | if(StringUtils.isNotBlank(t.getImgurl())){ | 
|---|
|  |  |  | t.setImgurlFull(path + t.getImgurl()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = {BusinessException.class,Exception.class}) | 
|---|
|  |  |  | public void entrustInvoicing(EntrustInvoicingDTO entrustInvoicingDTO){ | 
|---|
|  |  |  | LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|---|
|  |  |  | if(Objects.isNull(entrustInvoicingDTO) | 
|---|
|  |  |  | || Objects.isNull(entrustInvoicingDTO.getInvoicingMoney()) | 
|---|
|  |  |  | || Objects.isNull(entrustInvoicingDTO.getType()) | 
|---|
|  |  |  | || Objects.isNull(entrustInvoicingDTO.getTaxDetialList()) | 
|---|
|  |  |  | || StringUtils.isNotBlank(entrustInvoicingDTO.getAddress()) | 
|---|
|  |  |  | ){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!user.getType().equals(Constants.ONE)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"非企业用户无法进行该业务查询"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Company company = companyMapper.selectById(user.getCompanyId()); | 
|---|
|  |  |  | if(Objects.isNull(company)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到企业信息"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Taxes taxes = new Taxes(); | 
|---|
|  |  |  | taxes.setCreator(user.getId()); | 
|---|
|  |  |  | taxes.setCreateDate(new Date()); | 
|---|
|  |  |  | taxes.setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | taxes.setStatus(Constants.ZERO); | 
|---|
|  |  |  | taxes.setCompanyId(company.getId()); | 
|---|
|  |  |  | taxes.setPrice(entrustInvoicingDTO.getInvoicingMoney()); | 
|---|
|  |  |  | taxes.setType(entrustInvoicingDTO.getType()); | 
|---|
|  |  |  | taxes.setTaxCode(company.getTaxCode()); | 
|---|
|  |  |  | taxes.setTaxAccount(company.getTaxAccount()); | 
|---|
|  |  |  | taxes.setTaxAddr(company.getTaxAddr()); | 
|---|
|  |  |  | taxes.setAddr(entrustInvoicingDTO.getAddress()); | 
|---|
|  |  |  | taxes.setCompanyName(company.getName()); | 
|---|
|  |  |  | taxes.setApplyType(Constants.ZERO); | 
|---|
|  |  |  | taxesMapper.insert(taxes); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<TaxDetial> taxDetialList = entrustInvoicingDTO.getTaxDetialList(); | 
|---|
|  |  |  | for (TaxDetial taxDetial:taxDetialList) { | 
|---|
|  |  |  | if(Objects.isNull(taxDetial) | 
|---|
|  |  |  | || Objects.isNull(taxDetial.getInsuranceApplyId()) | 
|---|
|  |  |  | || Objects.isNull(taxDetial.getFee()) | 
|---|
|  |  |  | ){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //查询每个保单下可以投保的金额 | 
|---|
|  |  |  | InsuranceApply insuranceApply = insuranceApplyJoinMapper.selectJoinOne(InsuranceApply.class,new MPJLambdaWrapper<InsuranceApply>() | 
|---|
|  |  |  | .selectAll(InsuranceApply.class) | 
|---|
|  |  |  | .select(" ( select sum(td.fee) from taxes ts inner join tax_detial td on ts.TAX_ID = ts.id  where ts.status != 2 and td.INSURANCE_APPLY_ID = t.id ) as taxesMoney ") | 
|---|
|  |  |  | .eq(InsuranceApply::getId,taxDetial.getInsuranceApplyId()) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(Objects.isNull(insuranceApply)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"保单号【"+taxDetial.getApplyCode()+"】未查询到保单信息"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(insuranceApply.getCurrentFee().subtract(insuranceApply.getTaxesMoney()).compareTo(taxDetial.getFee())!=Constants.ZERO){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"保单号【"+taxDetial.getApplyCode()+"】可报销金额错误【"+insuranceApply.getCurrentFee().subtract(insuranceApply.getTaxesMoney())+"】"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | taxDetial.setCreator(user.getId()); | 
|---|
|  |  |  | taxDetial.setCreateDate(new Date()); | 
|---|
|  |  |  | taxDetial.setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | taxDetial.setTaxId(taxes.getId()); | 
|---|
|  |  |  | taxDetial.setTotalFee(insuranceApply.getCurrentFee()); | 
|---|
|  |  |  | taxDetial.setType(Constants.ZERO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | taxDetailJoinMapper.insertBatchSomeColumn(taxDetialList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<TaxesInvoicingVO> getDirectTaxes(Integer id){ | 
|---|
|  |  |  | InsuranceApply queryInsuranceApply = insuranceApplyJoinMapper.selectById(id); | 
|---|
|  |  |  | if(Objects.isNull(queryInsuranceApply)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EMPTY); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Solutions solutions = solutionsMapper.selectById(queryInsuranceApply.getSolutionId()); | 
|---|
|  |  |  | if(Objects.isNull(solutions)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到方案信息"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!solutions.getType().equals(Constants.ZERO)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"非直保方案保单,无法进行该操作"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<TaxesInvoicingVO>  taxesInvoicingVOList = new ArrayList<>(); | 
|---|
|  |  |  | this.dealTaxesData(id,taxesInvoicingVOList); | 
|---|
|  |  |  | List<Taxes> taxesList = taxesJoinMapper.selectJoinList(Taxes.class,new MPJLambdaWrapper<Taxes>() | 
|---|
|  |  |  | .selectAll(Taxes.class) | 
|---|
|  |  |  | .selectAs(Solutions::getName,Taxes::getSolutionName) | 
|---|
|  |  |  | .selectAs(InsuranceApply::getCode,Taxes::getInsuranceCode) | 
|---|
|  |  |  | .leftJoin(Solutions.class,Solutions::getId,Taxes::getSolutionId) | 
|---|
|  |  |  | .leftJoin(InsuranceApply.class,InsuranceApply::getId,Taxes::getInsuranceApplyId) | 
|---|
|  |  |  | .eq(Taxes::getStatus,Constants.ONE) | 
|---|
|  |  |  | .eq(Taxes::getInsuranceApplyId,id) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(CollectionUtils.isNotEmpty(taxesList)){ | 
|---|
|  |  |  | for (Taxes taxes:taxesList) { | 
|---|
|  |  |  | TaxesInvoicingVO taxesInvoicingVO = taxes.getTaxesInvoicingVO(); | 
|---|
|  |  |  | taxesInvoicingVOList.add(taxesInvoicingVO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return taxesInvoicingVOList; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void dealTaxesData(Integer id,List<TaxesInvoicingVO>  taxesInvoicingVOList){ | 
|---|
|  |  |  | InsuranceApply insuranceApply =  insuranceApplyJoinMapper.selectJoinOne(InsuranceApply.class, | 
|---|
|  |  |  | new MPJLambdaWrapper<InsuranceApply>() | 
|---|
|  |  |  | .selectAll(InsuranceApply.class) | 
|---|
|  |  |  | .selectAs(Solutions::getName,InsuranceApply::getSolutionsName) | 
|---|
|  |  |  | .select(" ( select count(1) from apply_detail ad  where ad.apply_id = t.id ) as insureNum") | 
|---|
|  |  |  | .leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId) | 
|---|
|  |  |  | .notExists(" select 1 from taxes t1 inner join tax_detial t2 on t1.id  = t2.tax_id where t2.type = 0 and t1.status != 2 and t.id = t2.INSURANCE_APPLY_ID  ") | 
|---|
|  |  |  | .eq(InsuranceApply::getStatus,Constants.InsuranceApplyStatus.UPLOAD_INSURANCE.getKey()) | 
|---|
|  |  |  | .eq(InsuranceApply::getId,id) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<ApplyChange> applyChangeList = applyChangeJoinMapper.selectJoinList(ApplyChange.class,new MPJLambdaWrapper<ApplyChange>() | 
|---|
|  |  |  | .selectAll(ApplyChange.class) | 
|---|
|  |  |  | .selectAs(InsuranceApply::getCode,ApplyChange::getApplyCode) | 
|---|
|  |  |  | .select("( select count(1) from apply_chagne_detail ad where t.id = ad.APPLY_CHANGE_ID and ad.TYPE = 0  ) as addNum ") | 
|---|
|  |  |  | .select("( select count(1) from apply_chagne_detail ad where t.id = ad.APPLY_CHANGE_ID and ad.TYPE = 1  ) as delNum ") | 
|---|
|  |  |  | .select("( select ifnull(sum(ad.FEE),0) from apply_chagne_detail ad where t.id = ad.APPLY_CHANGE_ID  ) as changeMoney" ) | 
|---|
|  |  |  | .notExists(" select 1 from taxes t1 inner join tax_detial t2 on t1.id  = t2.tax_id where t2.type = 1 and t1.status != 2 and t.id = t2.APPLY_CHANGE_ID  ") | 
|---|
|  |  |  | .leftJoin(InsuranceApply.class,InsuranceApply::getId,ApplyChange::getApplyId) | 
|---|
|  |  |  | .leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId) | 
|---|
|  |  |  | .eq(ApplyChange::getStatus,Constants.ApplyChangeStatus.APPROVE.getKey()) | 
|---|
|  |  |  | .eq(ApplyChange::getType,Constants.ZERO) | 
|---|
|  |  |  | .eq(InsuranceApply::getId,id) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(CollectionUtils.isNotEmpty(applyChangeList)){ | 
|---|
|  |  |  | for (ApplyChange applyChange:applyChangeList) { | 
|---|
|  |  |  | insuranceApply.setFee(insuranceApply.getFee().subtract(applyChange.getFee())); | 
|---|
|  |  |  | TaxesInvoicingVO taxesInvoicingVO = applyChange.toTaxesInvoicingVO(); | 
|---|
|  |  |  | if(!Objects.isNull(insuranceApply)){ | 
|---|
|  |  |  | taxesInvoicingVO.setAmount(BigDecimal.ZERO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | taxesInvoicingVOList.add(taxesInvoicingVO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!Objects.isNull(insuranceApply)){ | 
|---|
|  |  |  | TaxesInvoicingVO taxesInvoicingVO = insuranceApply.toTaxesInvoicingVO(); | 
|---|
|  |  |  | taxesInvoicingVOList.add(taxesInvoicingVO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 直保数据提交 | 
|---|
|  |  |  | * @param directInvoicingDTO | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = {BusinessException.class,Exception.class}) | 
|---|
|  |  |  | public void directInvoicing(DirectInvoicingDTO directInvoicingDTO){ | 
|---|
|  |  |  | LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|---|
|  |  |  | if(Objects.isNull(directInvoicingDTO) | 
|---|
|  |  |  | || Objects.isNull(directInvoicingDTO.getInvoicingMoney()) | 
|---|
|  |  |  | || Objects.isNull(directInvoicingDTO.getType()) | 
|---|
|  |  |  | || Objects.isNull(directInvoicingDTO.getInvoicingDetailDTOList()) | 
|---|
|  |  |  | || StringUtils.isBlank(directInvoicingDTO.getAddress()) | 
|---|
|  |  |  | ){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!user.getType().equals(Constants.ONE)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"非企业用户无法进行该业务查询"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Company company = companyMapper.selectById(user.getCompanyId()); | 
|---|
|  |  |  | if(Objects.isNull(company)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到企业信息"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | InsuranceApply queryInsuranceApply = insuranceApplyJoinMapper.selectById(directInvoicingDTO.getId()); | 
|---|
|  |  |  | if(Objects.isNull(queryInsuranceApply)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EMPTY); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Solutions solutions = solutionsMapper.selectById(queryInsuranceApply.getSolutionId()); | 
|---|
|  |  |  | if(Objects.isNull(solutions)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到方案信息"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!solutions.getType().equals(Constants.ZERO)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"非直保方案保单,无法进行该操作"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Taxes taxes = new Taxes(); | 
|---|
|  |  |  | taxes.setCreator(user.getId()); | 
|---|
|  |  |  | taxes.setCreateDate(new Date()); | 
|---|
|  |  |  | taxes.setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | taxes.setStatus(Constants.ZERO); | 
|---|
|  |  |  | taxes.setCompanyId(company.getId()); | 
|---|
|  |  |  | taxes.setPrice(directInvoicingDTO.getInvoicingMoney()); | 
|---|
|  |  |  | taxes.setType(directInvoicingDTO.getType()); | 
|---|
|  |  |  | taxes.setTaxCode(company.getTaxCode()); | 
|---|
|  |  |  | taxes.setTaxAccount(company.getTaxAccount()); | 
|---|
|  |  |  | taxes.setTaxAddr(company.getTaxAddr()); | 
|---|
|  |  |  | taxes.setAddr(directInvoicingDTO.getAddress()); | 
|---|
|  |  |  | taxes.setCompanyName(company.getName()); | 
|---|
|  |  |  | taxes.setApplyType(Constants.ONE); | 
|---|
|  |  |  | taxes.setSolutionId(solutions.getId()); | 
|---|
|  |  |  | taxes.setInsuranceApplyId(queryInsuranceApply.getId()); | 
|---|
|  |  |  | taxesMapper.insert(taxes); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<TaxesInvoicingVO>  taxesInvoicingVOList = new ArrayList<>(); | 
|---|
|  |  |  | this.dealTaxesData(queryInsuranceApply.getId(),taxesInvoicingVOList); | 
|---|
|  |  |  | List<TaxDetial> taxDetailList = new ArrayList<>(); | 
|---|
|  |  |  | for (TaxesInvoicingVO taxesInvoicingVO:taxesInvoicingVOList) { | 
|---|
|  |  |  | if(Objects.isNull(taxesInvoicingVO) | 
|---|
|  |  |  | || Objects.isNull(taxesInvoicingVO.getAmount()) | 
|---|
|  |  |  | || Objects.isNull(taxesInvoicingVO.getId()) | 
|---|
|  |  |  | || Objects.isNull(taxesInvoicingVO.getType()) | 
|---|
|  |  |  | ){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | TaxDetial taxDetial = new TaxDetial(); | 
|---|
|  |  |  | taxDetial.setCreator(user.getId()); | 
|---|
|  |  |  | taxDetial.setCreateDate(new Date()); | 
|---|
|  |  |  | taxDetial.setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | taxDetial.setTaxId(taxes.getId()); | 
|---|
|  |  |  | taxDetial.setTotalFee(taxesInvoicingVO.getAmount()); | 
|---|
|  |  |  | taxDetial.setFee(taxesInvoicingVO.getAmount()); | 
|---|
|  |  |  | if(taxesInvoicingVO.getType().equals(Constants.ZERO)){ | 
|---|
|  |  |  | taxDetial.setInsuranceApplyId(taxesInvoicingVO.getId()); | 
|---|
|  |  |  | taxDetial.setType(taxesInvoicingVO.getType()); | 
|---|
|  |  |  | }else if(taxesInvoicingVO.getType().equals(Constants.ONE)){ | 
|---|
|  |  |  | taxDetial.setApplyChangeId(taxesInvoicingVO.getId()); | 
|---|
|  |  |  | taxDetial.setType(taxesInvoicingVO.getType()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | taxDetailList.add(taxDetial); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Integer> chIdList = directInvoicingDTO.getInvoicingDetailDTOList(); | 
|---|
|  |  |  | if(CollectionUtils.isNotEmpty(chIdList)){ | 
|---|
|  |  |  | for (Integer id:chIdList) { | 
|---|
|  |  |  | Taxes chTaxes = taxesMapper.selectById(id); | 
|---|
|  |  |  | if(Objects.isNull(chTaxes)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到选择冲红数据"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!(chTaxes.getStatus().equals(Constants.ZERO)||chTaxes.getStatus().equals(Constants.ONE))){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"冲红数据状态错误"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | TaxDetial taxDetial = new TaxDetial(); | 
|---|
|  |  |  | taxDetial.setCreator(user.getId()); | 
|---|
|  |  |  | taxDetial.setCreateDate(new Date()); | 
|---|
|  |  |  | taxDetial.setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | taxDetial.setTaxId(taxes.getId()); | 
|---|
|  |  |  | taxDetial.setTotalFee(chTaxes.getPrice()); | 
|---|
|  |  |  | taxDetial.setFee(chTaxes.getPrice()); | 
|---|
|  |  |  | taxDetial.setDelTaxId(chTaxes.getId()); | 
|---|
|  |  |  | taxDetial.setType(Constants.TWO); | 
|---|
|  |  |  | taxDetailList.add(taxDetial); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(CollectionUtils.isNotEmpty(taxDetailList)){ | 
|---|
|  |  |  | taxDetailJoinMapper.insertBatchSomeColumn(taxDetailList); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"无可开票数据,操作失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //        List<DirectInvoicingDetailDTO> directInvoicingDetailDTOList = directInvoicingDTO.getDirectInvoicingDetailDTOList(); | 
|---|
|  |  |  | //        for (DirectInvoicingDetailDTO directInvoicingDetailDTO:directInvoicingDetailDTOList) { | 
|---|
|  |  |  | //            if(Objects.isNull(directInvoicingDetailDTO) | 
|---|
|  |  |  | //                    || Objects.isNull(directInvoicingDetailDTO.getId()) | 
|---|
|  |  |  | //                    || Objects.isNull(directInvoicingDetailDTO.getType()) | 
|---|
|  |  |  | //                    || Objects.isNull(directInvoicingDetailDTO.getFee()) | 
|---|
|  |  |  | //            ){ | 
|---|
|  |  |  | //                throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //            if(directInvoicingDetailDTO.getType().equals(Constants.ZERO)){ | 
|---|
|  |  |  | //                //保单 | 
|---|
|  |  |  | //                InsuranceApply insuranceApply =  insuranceApplyJoinMapper.selectJoinOne(InsuranceApply.class, | 
|---|
|  |  |  | //                        new MPJLambdaWrapper<InsuranceApply>() | 
|---|
|  |  |  | //                                .selectAll(InsuranceApply.class) | 
|---|
|  |  |  | //                                .selectAs(Solutions::getName,InsuranceApply::getSolutionsName) | 
|---|
|  |  |  | //                                .select(" ( select count(1) from apply_detail ad  where ad.apply_id = t.id ) as insureNum") | 
|---|
|  |  |  | //                                .notExists(" select 1 from taxes t1 inner join tax_detial t2 on t1.id  = t2.tax_id where t2.type = 0 and t1.status != 2 and t.id = t2.INSURANCE_APPLY_ID  ") | 
|---|
|  |  |  | //                                .eq(InsuranceApply::getStatus,Constants.InsuranceApplyStatus.UPLOAD_INSURANCE.getKey()) | 
|---|
|  |  |  | //                                .eq(InsuranceApply::getId,directInvoicingDetailDTO.getId()) | 
|---|
|  |  |  | //                ); | 
|---|
|  |  |  | //                if(Objects.isNull(insuranceApply)){ | 
|---|
|  |  |  | //                    throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"保单号【"+insuranceApply.getCode()+"】未查询到保单信息"); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | // | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //            }else if(directInvoicingDetailDTO.getType().equals(Constants.ZERO)){ | 
|---|
|  |  |  | //                //加减保 | 
|---|
|  |  |  | //            }else{ | 
|---|
|  |  |  | //                //冲红单 | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        taxDetailJoinMapper.insertBatchSomeColumn(taxDetialList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|