|  |  |  | 
|---|
|  |  |  | 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.*; | 
|---|
|  |  |  | import com.doumee.dao.business.dto.DirectInvoicingDTO; | 
|---|
|  |  |  | import com.doumee.dao.business.dto.DirectInvoicingDetailDTO; | 
|---|
|  |  |  | import com.doumee.dao.business.dto.EntrustInvoicingDTO; | 
|---|
|  |  |  | 
|---|
|  |  |  | private ApplyChangeJoinMapper applyChangeJoinMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SolutionsMapper solutionsMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private NoticesMapper noticesMapper; | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Integer create(Taxes taxes) { | 
|---|
|  |  |  | taxesMapper.insert(taxes); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //存储待办信息 | 
|---|
|  |  |  | Constants.NoticeObjectType noticeObjectType = Constants.NoticeObjectType.TAXES; | 
|---|
|  |  |  | //删除其他待办 | 
|---|
|  |  |  | noticesMapper.delete(new QueryWrapper<Notices>().lambda().eq(Notices::getObjType,noticeObjectType.getKey()).eq(Notices::getObjId,model.getId())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private List<TaxDetial> getDetailListById(Integer id) { | 
|---|
|  |  |  | 
|---|
|  |  |  | private List<TaxDetial> getJoinDetailListById(Integer id) { | 
|---|
|  |  |  | MPJLambdaWrapper<TaxDetial> queryWrapper = new MPJLambdaWrapper<>(); | 
|---|
|  |  |  | queryWrapper.selectAll(TaxDetial.class); | 
|---|
|  |  |  | queryWrapper.selectAs(Solutions::getName,TaxDetial::getSolutionName); | 
|---|
|  |  |  | queryWrapper.selectAs(Taxes::getDoneCode,TaxDetial::getTaxDoneCode); | 
|---|
|  |  |  | queryWrapper.selectAs(Taxes::getCreateDate,TaxDetial::getTaxCreateDate); | 
|---|
|  |  |  | queryWrapper.selectAs(InsuranceApply::getCode,TaxDetial::getApplyCode); | 
|---|
|  |  |  | queryWrapper.selectAs(ApplyChange::getCode,TaxDetial::getChangApplyCode); | 
|---|
|  |  |  | queryWrapper.select("(CASE t.type\n" + | 
|---|
|  |  |  | queryWrapper.selectAs(ApplyChange::getValidCode,TaxDetial::getChangApplyCode); | 
|---|
|  |  |  | /*        queryWrapper.select("(CASE t.type\n" + | 
|---|
|  |  |  | "WHEN 0 THEN (select count(1) from apply_detail c where c.APPLY_ID=t.INSURANCE_APPLY_ID) \n" + | 
|---|
|  |  |  | "ELSE 0  \n" + | 
|---|
|  |  |  | "END) as applyNum,\n" + | 
|---|
|  |  |  | 
|---|
|  |  |  | "(CASE t.type \n" + | 
|---|
|  |  |  | "WHEN 1 THEN  (select count(1) from apply_chagne_detail c where c.APPLY_CHANGE_ID=t.APPLY_CHANGE_ID)  \n" + | 
|---|
|  |  |  | "ELSE 0  \n" + | 
|---|
|  |  |  | "END) as applyChangeAddNum"); | 
|---|
|  |  |  | "END) as applyChangeAddNum");*/ | 
|---|
|  |  |  | queryWrapper.leftJoin(InsuranceApply.class,InsuranceApply::getId,TaxDetial::getInsuranceApplyId); | 
|---|
|  |  |  | queryWrapper.leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId); | 
|---|
|  |  |  | queryWrapper.leftJoin(ApplyChange.class,ApplyChange::getId,TaxDetial::getApplyChangeId); | 
|---|
|  |  |  | queryWrapper.leftJoin(Taxes.class,Taxes::getId,TaxDetial::getDelTaxId); | 
|---|
|  |  |  | queryWrapper.eq(  TaxDetial::getTaxId,id); | 
|---|
|  |  |  | List<TaxDetial> detialList =  taxDetailJoinMapper.selectJoinList(TaxDetial.class,queryWrapper.orderByAsc(TaxDetial::getType)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return detialList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | update.setDoneDate(update.getEditDate()); | 
|---|
|  |  |  | update.setImgurl(taxes.getImgurl()); | 
|---|
|  |  |  | taxesMapper.updateById(update); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //查询开票明细记录 | 
|---|
|  |  |  | List<TaxDetial> taxDetialList = taxDetialMapper.selectList(new QueryWrapper<TaxDetial>().lambda() | 
|---|
|  |  |  | .eq(TaxDetial::getTaxId,taxes.getId()) | 
|---|
|  |  |  | .eq(TaxDetial::getType,Constants.TWO)); | 
|---|
|  |  |  | if(CollectionUtils.isNotEmpty(taxDetialList)){ | 
|---|
|  |  |  | for (TaxDetial taxDetial:taxDetialList) { | 
|---|
|  |  |  | taxesMapper.update(null,new UpdateWrapper<Taxes>().lambda() | 
|---|
|  |  |  | .set(Taxes::getEditDate,new Date()) | 
|---|
|  |  |  | .set(Taxes::getEditor,user.getId()) | 
|---|
|  |  |  | .set(Taxes::getStatus,3).eq(Taxes::getId,taxDetial.getDelTaxId())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //存储待办信息 | 
|---|
|  |  |  | Constants.NoticeObjectType noticeObjectType = Constants.NoticeObjectType.TAXES; | 
|---|
|  |  |  | //删除其他待办 | 
|---|
|  |  |  | noticesMapper.delete(new QueryWrapper<Notices>().lambda().eq(Notices::getObjType,noticeObjectType.getKey()).eq(Notices::getObjId,taxes.getId())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | MPJLambdaWrapper<Taxes> queryWrapper = new MPJLambdaWrapper<>(); | 
|---|
|  |  |  | queryWrapper.selectAll(Taxes.class); | 
|---|
|  |  |  | queryWrapper.selectAs(Solutions::getName,Taxes::getSolutionName); | 
|---|
|  |  |  | queryWrapper.selectAs(SystemUser::getRealname,Taxes::getCancelUserName); | 
|---|
|  |  |  | queryWrapper.leftJoin(Solutions.class,Solutions::getId,Taxes::getSolutionId); | 
|---|
|  |  |  | queryWrapper.leftJoin(SystemUser.class,SystemUser::getId,Taxes::getCancelUserId); | 
|---|
|  |  |  | Taxes model =taxesJoinMapper.selectById(id); | 
|---|
|  |  |  | if(model==null || !Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)){ | 
|---|
|  |  |  | throw  new BusinessException(ResponseStatus.DATA_EMPTY); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(Constants.equalsInteger(model.getType(),Constants.ZERO)){ | 
|---|
|  |  |  | if(Constants.equalsInteger(model.getApplyType(),Constants.ZERO)){ | 
|---|
|  |  |  | List<TaxDetial> detialList = getDetailsApplysListById(id); | 
|---|
|  |  |  | model.setApplyList(detialList); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | 
|---|
|  |  |  | List<TaxDetial> applyList = new ArrayList<>();//投保和加减保 | 
|---|
|  |  |  | List<TaxDetial> delList = new ArrayList<>();//冲红单 | 
|---|
|  |  |  | if(detialList!=null){ | 
|---|
|  |  |  | for(TaxDetial d :delList){ | 
|---|
|  |  |  | d.setSolutionName(model.getSolutionName()); | 
|---|
|  |  |  | for(TaxDetial d :detialList){ | 
|---|
|  |  |  | //                    d.setSolutionName(model.getSolutionName()); | 
|---|
|  |  |  | d.setFee(Constants.formatBigdecimal(d.getFee())); | 
|---|
|  |  |  | d.setTotalFee(Constants.formatBigdecimal(d.getTotalFee())); | 
|---|
|  |  |  | if(Constants.equalsInteger(d.getType(),Constants.ZERO) || Constants.equalsInteger(d.getType(),Constants.ONE)){ | 
|---|
|  |  |  | if(Constants.equalsInteger(d.getType(),Constants.ZERO) | 
|---|
|  |  |  | || Constants.equalsInteger(d.getType(),Constants.ONE)){ | 
|---|
|  |  |  | applyList.add(d); | 
|---|
|  |  |  | }else  if(Constants.equalsInteger(d.getType(),Constants.TWO)){ | 
|---|
|  |  |  | delList.add(d); | 
|---|
|  |  |  | 
|---|
|  |  |  | queryWrapper.selectAll(TaxDetial.class); | 
|---|
|  |  |  | queryWrapper.selectAs(InsuranceApply::getCode,TaxDetial::getApplyCode); | 
|---|
|  |  |  | queryWrapper.selectAs(Solutions::getName,TaxDetial::getSolutionName); | 
|---|
|  |  |  | queryWrapper.selectAs(ApplyChange::getValidCode,TaxDetial::getChangApplyCode); | 
|---|
|  |  |  | queryWrapper.leftJoin(InsuranceApply.class,InsuranceApply::getId,TaxDetial::getInsuranceApplyId); | 
|---|
|  |  |  | queryWrapper.leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId); | 
|---|
|  |  |  | queryWrapper.leftJoin(ApplyChange.class,ApplyChange::getId,TaxDetial::getApplyChangeId); | 
|---|
|  |  |  | queryWrapper.in(TaxDetial::getType,Constants.ZERO,Constants.ONE); | 
|---|
|  |  |  | queryWrapper.eq(TaxDetial::getTaxId,id); | 
|---|
|  |  |  | List<TaxDetial> detialList =  taxDetailJoinMapper.selectJoinList(TaxDetial.class,queryWrapper.orderByAsc(TaxDetial::getType)); | 
|---|
|  |  |  | return detialList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | 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.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(),"非企业用户无法进行该业务查询"); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | queryWrapper.eq(Taxes::getCompanyId,user.getCompanyId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!Objects.isNull(queryModel)){ | 
|---|
|  |  |  | 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(!Objects.isNull(queryModel.getInsuranceApplyId()),Taxes::getInsuranceApplyId,queryModel.getInsuranceApplyId()); | 
|---|
|  |  |  | queryWrapper.eq(!Objects.isNull(queryModel.getStatus()),Taxes::getStatus,queryModel.getStatus()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<Taxes> findListForCompany(Taxes queryModel) { | 
|---|
|  |  |  | LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|---|
|  |  |  | MPJLambdaWrapper<Taxes> queryWrapper = new MPJLambdaWrapper<>(); | 
|---|
|  |  |  | queryWrapper.selectAll(Taxes.class); | 
|---|
|  |  |  | queryWrapper.selectAs(SystemUser::getRealname,Taxes::getCreatorName); | 
|---|
|  |  |  | queryWrapper.leftJoin(SystemUser.class,SystemUser::getId,Taxes::getCreator); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | queryWrapper.eq(Taxes::getIsdeleted, Constants.ZERO); | 
|---|
|  |  |  | if(!user.getType().equals(Constants.ONE)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"非企业用户无法进行该业务查询"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!Objects.isNull(queryModel)){ | 
|---|
|  |  |  | queryWrapper.ge(queryModel.getStartDate() != null,Taxes::getCreateDate, (queryModel.getStartDate())); | 
|---|
|  |  |  | queryWrapper.le(queryModel.getEndDate() != null,Taxes::getCreateDate,  (queryModel.getEndDate())); | 
|---|
|  |  |  | queryWrapper.eq(!Objects.isNull(queryModel.getInsuranceApplyId()),Taxes::getInsuranceApplyId,queryModel.getInsuranceApplyId()); | 
|---|
|  |  |  | queryWrapper.eq(!Objects.isNull(queryModel.getStatus()),Taxes::getStatus,queryModel.getStatus()); | 
|---|
|  |  |  | queryWrapper.exists(!Objects.isNull(queryModel.getApplyId())," select 1 from tax_detial td where td.insurance_apply_id = "+queryModel.getApplyId()+" and t.id = td.tax_id "); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | queryWrapper.orderByAsc(Taxes::getCreateDate); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Taxes> result = taxesJoinMapper.selectJoinList(Taxes.class, queryWrapper); | 
|---|
|  |  |  | String path =systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()+systemDictDataBiz.queryByCode(Constants.OSS,Constants.TAXES_FILE).getCode(); | 
|---|
|  |  |  | for(Taxes t : result){ | 
|---|
|  |  |  | if(StringUtils.isNotBlank(t.getImgurl())){ | 
|---|
|  |  |  | t.setImgurlFull(path + t.getImgurl()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | || Objects.isNull(entrustInvoicingDTO.getInvoicingMoney()) | 
|---|
|  |  |  | || Objects.isNull(entrustInvoicingDTO.getType()) | 
|---|
|  |  |  | || Objects.isNull(entrustInvoicingDTO.getTaxDetialList()) | 
|---|
|  |  |  | || StringUtils.isNotBlank(entrustInvoicingDTO.getAddress()) | 
|---|
|  |  |  | || StringUtils.isBlank(entrustInvoicingDTO.getAddress()) | 
|---|
|  |  |  | ){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | taxes.setAddr(entrustInvoicingDTO.getAddress()); | 
|---|
|  |  |  | taxes.setCompanyName(company.getName()); | 
|---|
|  |  |  | taxes.setApplyType(Constants.ZERO); | 
|---|
|  |  |  | taxes.setTaxBank(company.getTaxBank()); | 
|---|
|  |  |  | taxesMapper.insert(taxes); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<TaxDetial> taxDetialList = entrustInvoicingDTO.getTaxDetialList(); | 
|---|
|  |  |  | 
|---|
|  |  |  | ){ | 
|---|
|  |  |  | 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 ") | 
|---|
|  |  |  | //                    .select(" ifnull(( select sum(td.fee) from taxes ts inner join tax_detial td on td.TAX_ID = ts.id  where ts.status  = 1 and td.INSURANCE_APPLY_ID = t.id ),0) as taxesMoney") | 
|---|
|  |  |  | .select(" ifnull(( select sum(td.fee) from taxes ts inner join tax_detial td on td.TAX_ID = ts.id  where ts.status != 2 and td.INSURANCE_APPLY_ID = t.id ),0) 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())+"】"); | 
|---|
|  |  |  | //throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"保单号【"+taxDetial.getApplyCode()+"】可报销金额错误【"+insuranceApply.getCurrentFee().subtract(insuranceApply.getTaxesMoney())+"】"); | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"保单号【"+taxDetial.getApplyCode()+"】不满足开票条件"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | taxDetial.setCreator(user.getId()); | 
|---|
|  |  |  | taxDetial.setCreateDate(new Date()); | 
|---|
|  |  |  | 
|---|
|  |  |  | taxDetial.setTotalFee(insuranceApply.getCurrentFee()); | 
|---|
|  |  |  | taxDetial.setType(Constants.ZERO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | taxDetailJoinMapper.insertBatchSomeColumn(taxDetialList); | 
|---|
|  |  |  | taxDetailJoinMapper.insert(taxDetialList); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //存储待办信息 | 
|---|
|  |  |  | Constants.NoticeObjectType noticeObjectType = Constants.NoticeObjectType.TAXES; | 
|---|
|  |  |  | //删除其他待办 | 
|---|
|  |  |  | noticesMapper.delete(new QueryWrapper<Notices>().lambda().eq(Notices::getObjType,noticeObjectType.getKey()).eq(Notices::getObjId,taxes.getId())); | 
|---|
|  |  |  | Notices notices = new Notices(noticeObjectType,Constants.ZERO,taxes.getId(),taxes.getPrice().toString(), | 
|---|
|  |  |  | taxes.getCompanyId(), Constants.NoticeType.ZERO); | 
|---|
|  |  |  | noticesMapper.insert(notices); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | .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) | 
|---|
|  |  |  | .selectAs(Solutions::getName,ApplyChange::getSolutionsName) | 
|---|
|  |  |  | .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" ) | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(CollectionUtils.isNotEmpty(applyChangeList)){ | 
|---|
|  |  |  | for (ApplyChange applyChange:applyChangeList) { | 
|---|
|  |  |  | insuranceApply.setFee(insuranceApply.getFee().subtract(applyChange.getFee())); | 
|---|
|  |  |  | TaxesInvoicingVO taxesInvoicingVO = applyChange.getTaxesInvoicingVO(); | 
|---|
|  |  |  | if(!Objects.isNull(insuranceApply)){ | 
|---|
|  |  |  | taxesInvoicingVO.setAmount(BigDecimal.ZERO); | 
|---|
|  |  |  | 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.getTaxesInvoicingVO(); | 
|---|
|  |  |  | TaxesInvoicingVO taxesInvoicingVO = insuranceApply.toTaxesInvoicingVO(); | 
|---|
|  |  |  | taxesInvoicingVOList.add(taxesInvoicingVO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | || Objects.isNull(directInvoicingDTO.getInvoicingMoney()) | 
|---|
|  |  |  | || Objects.isNull(directInvoicingDTO.getType()) | 
|---|
|  |  |  | || Objects.isNull(directInvoicingDTO.getInvoicingDetailDTOList()) | 
|---|
|  |  |  | || StringUtils.isNotBlank(directInvoicingDTO.getAddress()) | 
|---|
|  |  |  | || StringUtils.isBlank(directInvoicingDTO.getAddress()) | 
|---|
|  |  |  | ){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | taxes.setType(directInvoicingDTO.getType()); | 
|---|
|  |  |  | taxes.setTaxCode(company.getTaxCode()); | 
|---|
|  |  |  | taxes.setTaxAccount(company.getTaxAccount()); | 
|---|
|  |  |  | taxes.setTaxBank(company.getTaxBank()); | 
|---|
|  |  |  | taxes.setTaxAddr(company.getTaxAddr()); | 
|---|
|  |  |  | taxes.setAddr(directInvoicingDTO.getAddress()); | 
|---|
|  |  |  | taxes.setCompanyName(company.getName()); | 
|---|
|  |  |  | 
|---|
|  |  |  | taxDetial.setTaxId(taxes.getId()); | 
|---|
|  |  |  | taxDetial.setTotalFee(taxesInvoicingVO.getAmount()); | 
|---|
|  |  |  | taxDetial.setFee(taxesInvoicingVO.getAmount()); | 
|---|
|  |  |  | taxDetial.setInsuranceApplyId(taxes.getInsuranceApplyId()); | 
|---|
|  |  |  | 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.setTotalFee(chTaxes.getPrice()); | 
|---|
|  |  |  | taxDetial.setFee(chTaxes.getPrice()); | 
|---|
|  |  |  | taxDetial.setDelTaxId(chTaxes.getId()); | 
|---|
|  |  |  | taxDetial.setInsuranceApplyId(taxes.getInsuranceApplyId()); | 
|---|
|  |  |  | taxDetial.setType(Constants.TWO); | 
|---|
|  |  |  | taxDetailList.add(taxDetial); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(CollectionUtils.isNotEmpty(taxDetailList)){ | 
|---|
|  |  |  | taxDetailJoinMapper.insertBatchSomeColumn(taxDetailList); | 
|---|
|  |  |  | taxDetailJoinMapper.insert(taxDetailList); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"无可开票数据,操作失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //存储待办信息 | 
|---|
|  |  |  | Constants.NoticeObjectType noticeObjectType = Constants.NoticeObjectType.TAXES; | 
|---|
|  |  |  | //删除其他待办 | 
|---|
|  |  |  | noticesMapper.delete(new QueryWrapper<Notices>().lambda().eq(Notices::getObjType,noticeObjectType.getKey()).eq(Notices::getObjId,taxes.getId())); | 
|---|
|  |  |  | Notices notices = new Notices(noticeObjectType,Constants.ZERO,taxes.getId(),taxes.getPrice().toString(), | 
|---|
|  |  |  | taxes.getCompanyId(), Constants.NoticeType.ZERO); | 
|---|
|  |  |  | noticesMapper.insert(notices); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //        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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|