| | |
| | | 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 lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.data.redis.core.StringRedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.UnsupportedEncodingException; |
| | |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.IntStream; |
| | | |
| | | ; |
| | | |
| | | /** |
| | | * 收款确认 |
| | |
| | | private final MeterReadRecordMapper meterReadRecordMapper; |
| | | private final BankStatementMapper bankStatementMapper; |
| | | private final RemoteDeptService remoteDeptService; |
| | | private final RedisTemplate redisTemplate; |
| | | private final StringRedisTemplate redisTemplate; |
| | | |
| | | @Value("${bip.url}") |
| | | private String url; |
| | |
| | | slip.setPaymentTime(addDTO.getConfirmTime()); |
| | | slip.setPaymentAmount(addDTO.getTransationAmount()); |
| | | slip.setPayType(addDTO.getPayType()); |
| | | slip.setContractId(contract.getId()); |
| | | paymentSlipMapper.insert(slip); |
| | | |
| | | BigDecimal newtotal = addDTO.getTransationAmount().add(lastTotal); |
| | |
| | | List<ContractPaymentSchedule> scheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery() |
| | | .eq(ContractPaymentSchedule::getContractId, contract.getId()).ne(ContractPaymentSchedule::getPaymentStatus, 2).ne(ContractPaymentSchedule::getPaymentStatus, 3) |
| | | .orderByAsc(ContractPaymentSchedule::getCreateTime)); |
| | | if (ArrayUtil.isNotEmpty(scheduleList.toArray())) { |
| | | if (CollUtil.isNotEmpty(scheduleList)) { |
| | | BigDecimal remain = addDTO.getTransationAmount(); |
| | | for (ContractPaymentSchedule schedule : scheduleList) { |
| | | BigDecimal lastRemain = remain; |
| | |
| | | List<MeterReadRecord> recordList = meterReadRecordMapper.selectList(Wrappers.<MeterReadRecord>lambdaQuery() |
| | | .eq(MeterReadRecord::getContractId,contract.getId()) |
| | | .isNull(MeterReadRecord::getMeterReadNum)); |
| | | if (ArrayUtil.isEmpty(execDateList.toArray())&&ArrayUtil.isEmpty(recordList.toArray())){ |
| | | if (CollUtil.isEmpty(execDateList)&&CollUtil.isEmpty(recordList)){ |
| | | //更新合同已付款 |
| | | BigDecimal paid = new BigDecimal("0"); |
| | | if (ObjUtil.isNotNull(contract.getPaidAmount())) { |
| | |
| | | // List<Contract> customerContractList = contractService.list(Wrappers.<Contract>lambdaQuery().eq(Contract::getPartyAId, addDTO.getBusGuestId()) |
| | | // .eq(Contract::getPartyBId, SecurityUtils.getUser().getCompId()).orderByAsc(Contract::getCreateTime) |
| | | // .apply(" ((contract_category != 'water_house' and amount != paid_amount) or contract_category = 'water_house')")); |
| | | // if (ArrayUtil.isEmpty(customerContractList.toArray())) { |
| | | // if (ArrayUtil.isEmpty(customerContractList)) { |
| | | // return R.failed("为查询到未付款合同"); |
| | | // } |
| | | // BusinessCustomer customer = businessCustomerService.getOne(Wrappers.<BusinessCustomer>lambdaQuery() |
| | |
| | | // .eq(ContractPaymentSchedule::getContractId, contract.getId()).ne(ContractPaymentSchedule::getPaymentStatus, 2) |
| | | // .ne(ContractPaymentSchedule::getPaymentStatus, 3) |
| | | // .orderByAsc(ContractPaymentSchedule::getCreateTime)); |
| | | // if (ArrayUtil.isNotEmpty(scheduleList.toArray())) { |
| | | // if (ArrayUtil.isNotEmpty(scheduleList)) { |
| | | // BigDecimal remain = transtionAmount; |
| | | // for (ContractPaymentSchedule schedule : scheduleList) { |
| | | // BigDecimal lastRemain = remain; |
| | |
| | | // List<ContractPaymentSchedule> payComScheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery() |
| | | // .eq(ContractPaymentSchedule::getContractId, contract.getId()).ne(ContractPaymentSchedule::getPaymentStatus, 0) |
| | | // .ne(ContractPaymentSchedule::getPaymentStatus, 3)); |
| | | // if (ArrayUtil.isNotEmpty(payComScheduleList.toArray())) { |
| | | // if (ArrayUtil.isNotEmpty(payComScheduleList)) { |
| | | // BigDecimal payTotal = payComScheduleList.stream().map(item -> StrUtil.equals(item.getPaymentStatus() + "", "2") ? item.getPlannedAmount() : |
| | | // item.getActualAmount()).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | // contract.setPaidAmount(payTotal); |
| | |
| | | // if (StrUtil.isNotEmpty(contract.getContractCategory()) && StrUtil.equals(contract.getContractCategory(), "water_house")) { |
| | | // List<ContractExecDate> execDateList = contractExecDateMapper.selectList(Wrappers.<ContractExecDate>lambdaQuery() |
| | | // .eq(ContractExecDate::getContractId, contract.getId()).eq(ContractExecDate::getGenFlag, "0")); |
| | | // if (ArrayUtil.isEmpty(execDateList.toArray())) { |
| | | // if (ArrayUtil.isEmpty(execDateList)) { |
| | | // List<ContractPaymentSchedule> contractPaymentScheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery() |
| | | // .eq(ContractPaymentSchedule::getContractId, contract.getId())); |
| | | // if (ArrayUtil.isNotEmpty(contractPaymentScheduleList.toArray()) && contractPaymentScheduleList.stream().allMatch(item -> Objects.equals(item.getPaymentStatus(), 2))) { |
| | | // if (ArrayUtil.isNotEmpty(contractPaymentScheduleList) && contractPaymentScheduleList.stream().allMatch(item -> Objects.equals(item.getPaymentStatus(), 2))) { |
| | | // contract.setContractStatus(3); |
| | | // contractService.updateById(contract); |
| | | // } |
| | |
| | | |
| | | //客户预付有剩余 且 有预付款的合同 |
| | | // if (transtionRemainAmount.compareTo(new BigDecimal("0")) > 0) { |
| | | // if (ArrayUtil.isNotEmpty(payNoCompleteContractList.toArray())){ |
| | | // if (ArrayUtil.isNotEmpty(payNoCompleteContractList)){ |
| | | // //余额 放到付款未完成合同 预收 |
| | | // Contract lastContract = payNoCompleteContractList.get(0); |
| | | // //保存明细 |
| | | // saveNewPaymentConfirm(customer,null,lastContract,transtionRemainAmount,payDate); |
| | | // } |
| | | // if (ArrayUtil.isEmpty(payNoCompleteContractList.toArray())&&ArrayUtil.isNotEmpty(advanceContractList.toArray())){ |
| | | // if (ArrayUtil.isEmpty(payNoCompleteContractList)&&ArrayUtil.isNotEmpty(advanceContractList)){ |
| | | // //客户预付有剩余 没有预付款的合同 |
| | | // Contract lastContract = advanceContractList.get(0); |
| | | // //保存明细 |
| | | // saveNewPaymentConfirm(customer,null,lastContract,transtionRemainAmount,payDate); |
| | | // } |
| | | // if (ArrayUtil.isEmpty(payNoCompleteContractList.toArray())&&ArrayUtil.isEmpty(advanceContractList.toArray()) |
| | | // &&ArrayUtil.isNotEmpty(payCompleteContractList.toArray())) { |
| | | // if (ArrayUtil.isEmpty(payNoCompleteContractList)&&ArrayUtil.isEmpty(advanceContractList) |
| | | // &&ArrayUtil.isNotEmpty(payCompleteContractList)) { |
| | | // //客户预付有剩余 没有预付款的合同 |
| | | // Contract lastContract = payCompleteContractList.get(payCompleteContractList.size() - 1); |
| | | // //保存明细 |
| | |
| | | if (redisTemplate.hasKey("BIP_TOKEN")) { |
| | | accessToken = (String) redisTemplate.opsForValue().get("BIP_TOKEN"); |
| | | } else { |
| | | getAccessToken(accessToken); |
| | | accessToken = getAccessToken(accessToken); |
| | | } |
| | | if (StrUtil.isEmpty(accessToken)) { |
| | | return R.failed("获取token失败"); |
| | |
| | | for (String bipCode : bipCodeArr) { |
| | | //入参 |
| | | JSONObject params = new JSONObject(); |
| | | if (ObjUtil.isNotEmpty(dto.getPageSize())){ |
| | | params.put("pageSize",dto.getPageSize()); |
| | | }else { |
| | | params.put("pageSize",999); |
| | | } |
| | | if (ObjUtil.isNotEmpty(dto.getPageNum())){ |
| | | params.put("pageNum",dto.getPageNum()); |
| | | }else { |
| | | params.put("pageNum",1); |
| | | } |
| | | if (StrUtil.isNotBlank(dto.getStartDate())){ |
| | | params.put("begindate",dto.getStartDate()); |
| | | }else { |
| | |
| | | return; |
| | | } |
| | | SysDept dept = r.getData(); |
| | | JSONObject dataJson = JSONObject.parseObject(resultJson.getString("data")); |
| | | JSONObject dataJson = resultJson.getJSONObject("data"); |
| | | if (ObjUtil.isNull(dataJson)) { |
| | | log.error("返回结果中data解析失败"); |
| | | return; |
| | | } |
| | | JSONArray recordList = JSONArray.parseArray(resultJson.getString("recordList")); |
| | | if (ArrayUtil.isEmpty(recordList.toArray())) { |
| | | JSONArray recordList = dataJson.getJSONArray("recordList"); |
| | | if (CollUtil.isEmpty(recordList)) { |
| | | log.error("返回结果中recordList为空"); |
| | | return; |
| | | } |
| | |
| | | |
| | | private void savePaymentConfirm(JSONObject record, SysDept dept) { |
| | | |
| | | if (record.containsKey("to_acct_name")){ |
| | | log.error("付款单id:{},付款公司为空", record.getString("id")); |
| | | return; |
| | | } |
| | | |
| | | BusinessCustomer customer = businessCustomerService.getOne(Wrappers.<BusinessCustomer>lambdaQuery() |
| | | .eq(BusinessCustomer::getCompanyName, record.getString("to_acct_name")) |
| | | .eq(BusinessCustomer::getCompId,dept.getDeptId()) |
| | | ); |
| | | if (ObjUtil.isNull(customer)) { |
| | | log.error("付款单id:{},客商查询失败,请检查客商", record.getString("id")); |
| | | return; |
| | | } |
| | | if (ObjUtil.isNull(record.getBigDecimal("tran_amt"))) { |
| | | log.error("付款单id:{},交易金额异常", record.getString("id")); |
| | | return; |
| | | } |
| | | //保存付款单 |
| | | Boolean codeFlag = saveBankStatement(customer, record); |
| | | Boolean codeFlag = saveBankStatement(customer, record,dept); |
| | | if (codeFlag) { |
| | | log.error("付款单id:{},付款单已存在"); |
| | | return; |
| | |
| | | |
| | | } |
| | | |
| | | private Boolean saveBankStatement(BusinessCustomer customer, JSONObject record) { |
| | | private Boolean saveBankStatement(BusinessCustomer customer, JSONObject record,SysDept dept) { |
| | | BankStatement bankStatement = new BankStatement(); |
| | | bankStatement.setBankSeqNo(record.getString("bank_seq_no")); |
| | | bankStatement.setReceiveBankAcc(record.getString("bank_seq_no")); |
| | |
| | | bankStatement.setTranAmount(record.getBigDecimal("tran_amt")); |
| | | bankStatement.setDataId(record.getLong("id")); |
| | | bankStatement.setDataJson(record.toJSONString()); |
| | | if (ObjUtil.isNotNull(customer)) { |
| | | bankStatement.setBusGuestId(customer.getId()); |
| | | } |
| | | BankStatement statement = bankStatementMapper.selectOne(Wrappers.<BankStatement>lambdaQuery().eq(BankStatement::getDataId,record.getLong("id"))); |
| | | if (ObjUtil.isNotNull(statement)){ |
| | | return false; |
| | | } |
| | | statement.setCompId(customer.getCompId()); |
| | | bankStatement.setRemark(record.getString("remark")); |
| | | bankStatement.setCompId(dept.getDeptId()); |
| | | bankStatementMapper.insert(bankStatement); |
| | | return true; |
| | | } |
| | |
| | | @Override |
| | | public R queryAging() { |
| | | List<AgingCompanyVo> companys = contractPaymentScheduleMapper.selectAgingCompany(null, DataScope.of("comp_id")); |
| | | if (ArrayUtil.isEmpty(companys.toArray())) { |
| | | if (CollUtil.isEmpty(companys)) { |
| | | return R.failed("暂无账龄"); |
| | | } |
| | | List<AgingAnalysisVo> result = new ArrayList<>(); |
| | |
| | | queryDTO.setCompanyId(company.getCompanyId()); |
| | | List<AgingVo> companyAgingVo = contractPaymentScheduleMapper.selectAgingTotal(queryDTO); |
| | | //补全数据 |
| | | if (ArrayUtil.isEmpty(companyAgingVo.toArray())) { |
| | | if (CollUtil.isEmpty(companyAgingVo)) { |
| | | companyAgingVo = new ArrayList<>(); |
| | | AgingVo agingVo1 = new AgingVo(1L,"0-30天", new BigDecimal("0"), null); |
| | | AgingVo agingVo2 = new AgingVo(2L,"31-60天", new BigDecimal("0"), null); |
| | |
| | | companyAgingVo.add(agingVo6); |
| | | } else { |
| | | List<String> overdueRanges = companyAgingVo.stream().map(AgingVo::getOverdueRange).collect(Collectors.toList()); |
| | | if (!ArrayUtil.contains(overdueRanges.toArray(), "0-30天")) { |
| | | if (!CollUtil.contains(overdueRanges, "0-30天")) { |
| | | AgingVo agingVo1 = new AgingVo(1L,"0-30天", new BigDecimal("0"), null); |
| | | companyAgingVo.add(agingVo1); |
| | | } |
| | | if (!ArrayUtil.contains(overdueRanges.toArray(), "31-60天")) { |
| | | if (!CollUtil.contains(overdueRanges, "31-60天")) { |
| | | AgingVo agingVo2 = new AgingVo(2L,"31-60天", new BigDecimal("0"), null); |
| | | companyAgingVo.add(agingVo2); |
| | | } |
| | | if (!ArrayUtil.contains(overdueRanges.toArray(), "61-90天")) { |
| | | if (!CollUtil.contains(overdueRanges, "61-90天")) { |
| | | AgingVo agingVo3 = new AgingVo(3L,"61-90天", new BigDecimal("0"), null); |
| | | companyAgingVo.add(agingVo3); |
| | | } |
| | | if (!ArrayUtil.contains(overdueRanges.toArray(), "91-180天")) { |
| | | if (!CollUtil.contains(overdueRanges, "91-180天")) { |
| | | AgingVo agingVo4 = new AgingVo(4L,"91-180天", new BigDecimal("0"), null); |
| | | companyAgingVo.add(agingVo4); |
| | | } |
| | | if (!ArrayUtil.contains(overdueRanges.toArray(), "181-365天")) { |
| | | if (!CollUtil.contains(overdueRanges, "181-365天")) { |
| | | AgingVo agingVo5 = new AgingVo(5L,"181-365天", new BigDecimal("0"), null); |
| | | companyAgingVo.add(agingVo5); |
| | | } |
| | | if (!ArrayUtil.contains(overdueRanges.toArray(), "1年以上")) { |
| | | if (!CollUtil.contains(overdueRanges, "1年以上")) { |
| | | AgingVo agingVo6 = new AgingVo(6L,"1年以上", new BigDecimal("0"), null); |
| | | companyAgingVo.add(agingVo6); |
| | | } |