| | |
| | | package com.by4cloud.platformx.business.service.impl; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.date.DatePattern; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.ArrayUtil; |
| | | import cn.hutool.core.util.ObjUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | ; |
| | | |
| | | /** |
| | | * EPR出库记录 |
| | |
| | | |
| | | @Override |
| | | public R add(OutBoundAddDTO addDTO) { |
| | | if (ArrayUtil.isEmpty(addDTO.getSubjectMatterList().toArray())) { |
| | | if (CollUtil.isEmpty(addDTO.getSubjectMatterList())) { |
| | | return R.failed("出库标的物不能为空"); |
| | | } |
| | | MPJLambdaWrapper<ContractSubjectMatter> wrapper = new MPJLambdaWrapper<ContractSubjectMatter>() |
| | |
| | | ) |
| | | .orderByAsc(ContractSubjectMatter::getCreateTime); |
| | | List<ContractSubjectMatter> subjectMatterList = contractSubjectMatterMapper.selectList(wrapper); |
| | | if (ArrayUtil.isEmpty(subjectMatterList.toArray())) { |
| | | if (CollUtil.isEmpty(subjectMatterList)) { |
| | | return R.failed("没有查询到相关合同订单"); |
| | | } |
| | | List<String> erpCodeList = subjectMatterList.stream().map(ContractSubjectMatter::getMaterialCode).collect(Collectors.toList()); |
| | |
| | | }); |
| | | |
| | | //出库应收款明细 |
| | | if (ArrayUtil.isNotEmpty(currentOutMap.keySet())) { |
| | | if (CollUtil.isNotEmpty(currentOutMap.keySet())) { |
| | | for (Long contractId : currentOutMap.keySet()) { |
| | | //当前出库合同出库标的物 |
| | | List<ContractSubjectMatter> contractSubjectMatterList = contractSubjectMatterMapper.selectList(Wrappers.<ContractSubjectMatter>lambdaQuery() |
| | |
| | | //客户付款完成合同 |
| | | List<Contract> customerCompleteContractList = contractMapper.selectList(Wrappers.<Contract>lambdaQuery().eq(Contract::getPartyAId, contract.getPartyAId()) |
| | | .eq(Contract::getPartyBId, SecurityUtils.getUser().getCompId()).apply(" amount = paid_amount")); |
| | | if (ArrayUtil.isNotEmpty(customerCompleteContractList)) { |
| | | if (CollUtil.isNotEmpty(customerCompleteContractList)) { |
| | | List<BigDecimal> outAmountList = new ArrayList<>(); |
| | | for (Contract completeContract : customerCompleteContractList |
| | | ) { |
| | |
| | | outAmountList.add(outConfirm.getTransationAmount()); |
| | | } |
| | | } |
| | | if (ArrayUtil.isNotEmpty(outAmountList.toArray())) { |
| | | if (CollUtil.isNotEmpty(outAmountList)) { |
| | | BigDecimal currentInSum = outAmountList.stream().reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | //新增当前合同 资金转入 |
| | | PaymentConfirm inConfirm = BeanUtil.copyProperties(paymentConfirm, PaymentConfirm.class, "id", "transationAmount", |
| | |
| | | //查询是否有后续阶段 |
| | | // List<ContractPaymentSchedule> afterSchedule = scheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, contractId) |
| | | // .gt(ContractPaymentSchedule::getStageOrder, schedule.getStageOrder())); |
| | | // if (ArrayUtil.isEmpty(afterSchedule.toArray())) { |
| | | // if (.isEmpty(afterSchedule)) { |
| | | // schedule.setEffectiveEndDate(contract.getExpirationDate()); |
| | | // } |
| | | scheduleMapper.updateById(schedule); |
| | |
| | | .eq(ContractPaymentSchedule::getContractId, schedule.getContractId()) |
| | | .gt(ContractPaymentSchedule::getStageOrder, schedule.getStageOrder()) |
| | | .orderByAsc(ContractPaymentSchedule::getCreateTime)); |
| | | if (ArrayUtil.isNotEmpty(afterSchedule.toArray()) && afterSchedule.size() == 1) { |
| | | if (CollUtil.isNotEmpty(afterSchedule) && afterSchedule.size() == 1) { |
| | | //最后阶段生效时间 |
| | | ContractPaymentSchedule endSchedule = afterSchedule.get(0); |
| | | if (StrUtil.equals(endSchedule.getStageName(), "质保金")) { |
| | |
| | | contract.setNextScheduleName(endSchedule.getStageName()); |
| | | contractMapper.updateById(contract); |
| | | } |
| | | if (ArrayUtil.isNotEmpty(afterSchedule.toArray()) && afterSchedule.size() > 1) { |
| | | if (CollUtil.isNotEmpty(afterSchedule) && afterSchedule.size() > 1) { |
| | | //更新合同下个阶段 |
| | | contract.setNextScheduleName(afterSchedule.get(0).getStageName()); |
| | | contractMapper.updateById(contract); |
| | | } |
| | | if (ArrayUtil.isEmpty(afterSchedule.toArray())) { |
| | | if (CollUtil.isEmpty(afterSchedule)) { |
| | | // schedule.setEffectiveEndDate(contract.getExpirationDate()); |
| | | // scheduleMapper.updateById(schedule); |
| | | //更新合同下个阶段 |
| | |
| | | |
| | | @Override |
| | | public R addContractOut(OutBoundAddDTO addDTO) { |
| | | if (ArrayUtil.isEmpty(addDTO.getSubjectMatterList().toArray())) { |
| | | if (CollUtil.isEmpty(addDTO.getSubjectMatterList())) { |
| | | return R.failed("出库标的物不能为空"); |
| | | } |
| | | // 1. 确定查询用的合同编号字段值 |
| | |
| | | if (ObjUtil.isNull(contract)) { |
| | | return R.failed("合同信息查询失败"); |
| | | } |
| | | if (addDTO.getSubjectMatterList().stream().allMatch(item->item.getOutBoundNum().compareTo(new BigDecimal("0"))==0)){ |
| | | return R.failed("出库数量不能都为为0"); |
| | | } |
| | | addDTO.setSubjectMatterList(addDTO.getSubjectMatterList().stream().filter(item->item.getOutBoundNum().compareTo(new BigDecimal("0"))>0).collect(Collectors.toList())); |
| | | //出库数量校验 |
| | | for (OutSubjectMatterAddDTO outSubjectMatterAddDTO: addDTO.getSubjectMatterList()) { |
| | | ContractSubjectMatter subjectMatter = contractSubjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery() |
| | |
| | | .last("limit 1")); |
| | | if (ObjUtil.isNull(subjectMatter)){ |
| | | continue; |
| | | } |
| | | if (outSubjectMatterAddDTO.getOutBoundNum().compareTo(new BigDecimal("0"))==0){ |
| | | return R.failed(outSubjectMatterAddDTO.getSubjectMatterCode()+"出库数量不能为0"); |
| | | } |
| | | if (subjectMatter.getDeliveryStatus()==0){ |
| | | if (outSubjectMatterAddDTO.getOutBoundNum().compareTo(subjectMatter.getQuantity())>0){ |
| | |
| | | //客户付款完成合同 |
| | | List<Contract> customerCompleteContractList = contractMapper.selectList(Wrappers.<Contract>lambdaQuery().eq(Contract::getPartyAId, contract.getPartyAId()) |
| | | .eq(Contract::getPartyBId, SecurityUtils.getUser().getCompId()).apply(" amount = paid_amount")); |
| | | if (ArrayUtil.isNotEmpty(customerCompleteContractList)) { |
| | | if (CollUtil.isNotEmpty(customerCompleteContractList)) { |
| | | List<BigDecimal> outAmountList = new ArrayList<>(); |
| | | for (Contract completeContract : customerCompleteContractList |
| | | ) { |
| | |
| | | outAmountList.add(outConfirm.getTransationAmount()); |
| | | } |
| | | } |
| | | if (ArrayUtil.isNotEmpty(outAmountList.toArray())) { |
| | | if (CollUtil.isNotEmpty(outAmountList)) { |
| | | BigDecimal currentInSum = outAmountList.stream().reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | //新增当前合同 资金转入 |
| | | PaymentConfirm inConfirm = BeanUtil.copyProperties(paymentConfirm, PaymentConfirm.class, "id", "transationAmount", |
| | |
| | | .eq(ContractPaymentSchedule::getContractId, schedule.getContractId()) |
| | | .gt(ContractPaymentSchedule::getStageOrder, schedule.getStageOrder()) |
| | | .orderByAsc(ContractPaymentSchedule::getCreateTime)); |
| | | if (ArrayUtil.isNotEmpty(afterSchedule.toArray())&&contract.getOutBoundAmout().compareTo(contract.getAmount())==0) { |
| | | if (CollUtil.isNotEmpty(afterSchedule)&&contract.getOutBoundAmout().compareTo(contract.getAmount())==0) { |
| | | contract.setNextScheduleName(afterSchedule.get(0).getStageName()); |
| | | contractMapper.updateById(contract); |
| | | } |
| | | |
| | | if (ArrayUtil.isEmpty(afterSchedule.toArray())) { |
| | | if (CollUtil.isEmpty(afterSchedule)) { |
| | | schedule.setEffectiveEndDate(contract.getExpirationDate()); |
| | | scheduleMapper.updateById(schedule); |
| | | //更新合同下个阶段 |
| | |
| | | @Override |
| | | public R delOutBound(String batchNumber) { |
| | | List<OutBound> outBoundList = baseMapper.selectList(Wrappers.<OutBound>lambdaQuery().eq(OutBound::getBatchNumber,batchNumber)); |
| | | if (ArrayUtil.isEmpty(outBoundList)){ |
| | | if (CollUtil.isEmpty(outBoundList)){ |
| | | return R.failed("出库信息异常,请联系营销系统管理人员"); |
| | | } |
| | | List<ContractOutBound> contractOutBoundList = contractOutBoundMapper.selectList(Wrappers.<ContractOutBound>lambdaQuery() |
| | | .in(ContractOutBound::getOutBoundId,outBoundList.stream().map(OutBound::getId).collect(Collectors.toList()))); |
| | | if (ArrayUtil.isEmpty(contractOutBoundList)){ |
| | | if (CollUtil.isEmpty(contractOutBoundList)){ |
| | | return R.failed("出库信息异常,请联系营销系统管理人员"); |
| | | } |
| | | boolean allZero = true; |