| | |
| | | package com.by4cloud.platformx.business.service.impl; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | 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 cn.hutool.http.HttpUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.by4cloud.platformx.business.dto.PaymentConfirmAddDTO; |
| | |
| | | import com.by4cloud.platformx.business.mapper.HistoryOverdueMapper; |
| | | import com.by4cloud.platformx.business.mapper.PaymentConfirmMapper; |
| | | import com.by4cloud.platformx.business.service.BusinessCustomerService; |
| | | import com.by4cloud.platformx.business.service.ContractPaymentScheduleService; |
| | | import com.by4cloud.platformx.business.service.ContractService; |
| | | import com.by4cloud.platformx.business.service.PaymentConfirmService; |
| | | import com.by4cloud.platformx.common.core.util.R; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * 收款确认 |
| | |
| | | private final ContractPaymentScheduleMapper contractPaymentScheduleMapper; |
| | | private final CurrentOverdueMapper currentOverdueMapper; |
| | | private final HistoryOverdueMapper historyOverdueMapper; |
| | | |
| | | @Value("${bip.url}") |
| | | private String url; |
| | | |
| | | |
| | | @Override |
| | | public R add(PaymentConfirmAddDTO addDTO) { |
| | |
| | | entity.setConfirmTime(new Date()); |
| | | baseMapper.insert(entity); |
| | | } |
| | | //更新付款阶段付款 |
| | | List<ContractPaymentSchedule> scheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery() |
| | | .eq(ContractPaymentSchedule::getContractId,contract.getId()).ne(ContractPaymentSchedule::getPaymentStatus,2) |
| | | .orderByAsc(ContractPaymentSchedule::getCreateTime)); |
| | | if (ArrayUtil.isNotEmpty(scheduleList.toArray())){ |
| | | BigDecimal remain = addDTO.getTransationAmount(); |
| | | for (ContractPaymentSchedule schedule:scheduleList) { |
| | | BigDecimal lastRemain = remain; |
| | | remain = remain.subtract(StrUtil.equals(schedule.getPaymentStatus()+"","0")?schedule.getPlannedAmount(): |
| | | schedule.getPlannedAmount().subtract(schedule.getActualAmount())); |
| | | if (remain.compareTo(new BigDecimal("0"))>=0){ |
| | |
| | | //新增逾期历史 |
| | | HistoryOverdue historyOverdue = BeanUtil.copyProperties(currentOverdue,HistoryOverdue.class,"id"); |
| | | historyOverdue.setPaymentTime(addDTO.getConfirmTime()); |
| | | historyOverdue.setCompId(schedule.getCompId()); |
| | | historyOverdueMapper.insert(historyOverdue); |
| | | //删除当前逾期 |
| | | currentOverdueMapper.deleteById(currentOverdue); |
| | | } |
| | | }else { |
| | | schedule.setActualAmount(StrUtil.equals(schedule.getPaymentStatus()+"","0")?schedule.getPlannedAmount().add(remain): |
| | | schedule.getPlannedAmount().subtract(schedule.getActualAmount()).add(remain)); |
| | | schedule.getActualAmount().add(lastRemain)); |
| | | schedule.setPaymentDate(addDTO.getConfirmTime()); |
| | | schedule.setPaymentStatus(1); |
| | | contractPaymentScheduleMapper.updateById(schedule); |
| | | //查询是否有当前逾期 |
| | | CurrentOverdue currentOverdue = currentOverdueMapper.selectOne(Wrappers.<CurrentOverdue>lambdaQuery().eq(CurrentOverdue::getScheduleId,schedule.getId()) |
| | | .eq(CurrentOverdue::getContractId,schedule.getContractId()).last("limit 1")); |
| | | if (ObjUtil.isNotNull(currentOverdue)){ |
| | | //新增逾期历史 |
| | | HistoryOverdue historyOverdue = BeanUtil.copyProperties(currentOverdue,HistoryOverdue.class,"id"); |
| | | historyOverdue.setReceivableAmount(lastRemain); |
| | | historyOverdue.setPaymentTime(addDTO.getConfirmTime()); |
| | | historyOverdue.setCompId(schedule.getCompId()); |
| | | historyOverdueMapper.insert(historyOverdue); |
| | | //查询历史已付逾期金额 |
| | | List<HistoryOverdue> historyOverdueList = historyOverdueMapper.selectList(Wrappers.<HistoryOverdue>lambdaQuery().eq(HistoryOverdue::getScheduleId,currentOverdue.getScheduleId())); |
| | | BigDecimal hisTotal = historyOverdueList.stream().map(item->item.getReceivableAmount()).reduce(BigDecimal.ZERO,BigDecimal::add); |
| | | //更新当前逾期 |
| | | currentOverdue.setReceivableAmount(schedule.getPlannedAmount().subtract(hisTotal)); |
| | | currentOverdueMapper.updateById(currentOverdue); |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | //更新合同已付款 |
| | | BigDecimal paid = new BigDecimal("0"); |
| | | if (ObjUtil.isNotNull(contract.getPaidAmount())){ |
| | | paid = contract.getPaidAmount(); |
| | | } |
| | | paid = paid.add(addDTO.getTransationAmount()); |
| | | contract.setPaidAmount(paid); |
| | | if (paid.compareTo(contract.getAmount())>0){ |
| | | contract.setPaidAmount(contract.getAmount()); |
| | | } |
| | | contractService.updateById(contract); |
| | | } |
| | | //转出 |
| | | if (StrUtil.equals(addDTO.getInOrOut(),"2")){ |
| | |
| | | entity.setConfirmTime(new Date()); |
| | | baseMapper.insert(entity); |
| | | } |
| | | // 查询所有付款阶段是否都付款完成 |
| | | List<ContractPaymentSchedule> scheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId,contract.getId())); |
| | | if (ArrayUtil.isNotEmpty(scheduleList.toArray())){ |
| | | if (scheduleList.stream().allMatch(item -> Objects.equals(item.getPaymentStatus(), 2))){ |
| | | contract.setContractStatus(3); |
| | | contractService.updateById(contract); |
| | | }; |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | @Override |
| | | public R syncPaymentRecepit() { |
| | | |
| | | JSONObject params = new JSONObject(); |
| | | params.put("pageIndex", 1); |
| | | params.put("pageSize", 999); |
| | | params.put("open_billDate_begin", DateUtil.offsetDay(new Date(),-1) + " 00:00:00"); |
| | | params.put("open_billDate_begin", DateUtil.today() + " 00:00:00"); |
| | | //单据状态已审批 |
| | | params.put("verifyState", new String[]{"2"}); |
| | | //往来对象客户 |
| | | params.put("objectType", new String[]{"1"}); |
| | | //单位 |
| | | // JSONObject simpleMap = new JSONObject(); |
| | | // simpleMap.put("financeOrg.code", bipCode); |
| | | // params.put("simple", simpleMap); |
| | | HttpUtil.post(url+"/yonbip/EFI/collection/list",params.toJSONString()); |
| | | |
| | | return null; |
| | | } |
| | | } |