| | |
| | | package com.by4cloud.platformx.business.service.impl; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.date.DatePattern; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.IdUtil; |
| | | import cn.hutool.core.util.ObjUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.http.HttpUtil; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.by4cloud.platformx.admin.api.entity.SysDept; |
| | | import com.by4cloud.platformx.admin.api.feign.RemoteDeptService; |
| | | import com.by4cloud.platformx.business.dto.BankStatementUpdateDTO; |
| | | import com.by4cloud.platformx.business.dto.BipQueryDTO; |
| | | import com.by4cloud.platformx.business.dto.PaymentConfirmAddDTO; |
| | | import com.by4cloud.platformx.business.entity.*; |
| | | import com.by4cloud.platformx.business.mapper.*; |
| | | import com.by4cloud.platformx.business.service.BankStatementService; |
| | | import com.by4cloud.platformx.business.service.PaymentConfirmService; |
| | | import com.by4cloud.platformx.business.vo.CustInfoVo; |
| | | import com.by4cloud.platformx.business.vo.ReceiveBipVo; |
| | | import com.by4cloud.platformx.business.vo.ReceiveItemVo; |
| | | import com.by4cloud.platformx.business.vo.StatementContractVo; |
| | | import com.by4cloud.platformx.common.core.util.R; |
| | | import com.by4cloud.platformx.common.data.datascope.DataScope; |
| | | import com.by4cloud.platformx.common.security.util.SecurityUtils; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import okhttp3.*; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.data.redis.core.StringRedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public R edit(BankStatementUpdateDTO updateDTO) { |
| | | BankStatement statement = baseMapper.selectById(updateDTO.getId()); |
| | | if (CollUtil.isEmpty(updateDTO.getContractCollectionList())){ |
| | | if (CollUtil.isEmpty(updateDTO.getContractCollectionList())) { |
| | | return R.failed("请选择收款合同后在提交"); |
| | | } |
| | | BigDecimal toPaidTotal = updateDTO.getContractCollectionList().stream() .map(StatementContractDTO::getToPaidAmount) |
| | | BigDecimal toPaidTotal = updateDTO.getContractCollectionList().stream().map(StatementContractDTO::getToPaidAmount) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | if (toPaidTotal.compareTo(statement.getTranAmount().subtract(statement.getConfirmAmount()))!=0){ |
| | | if (toPaidTotal.compareTo(statement.getTranAmount().subtract(statement.getConfirmAmount())) != 0) { |
| | | return R.failed("确认收款总额必须与交易流水金额一致"); |
| | | } |
| | | |
| | |
| | | baseMapper.updateById(statement); |
| | | |
| | | updateDTO.getContractCollectionList().stream().forEach(statementContractDTO -> { |
| | | Contract contract = contractMapper.selectById(statementContractDTO.getId()); |
| | | R<SysDept> r = remoteDeptService.getById(SecurityUtils.getUser().getCompId()); |
| | | SysDept b = r.getData(); |
| | | BusinessCustomer customer = businessCustomerMapper.selectById(contract.getPartyAId()); |
| | | BankStatementItem item = new BankStatementItem(); |
| | | item.setStatetId(statement.getId()); |
| | | item.setBankSeqNo(statement.getBankSeqNo()); |
| | | item.setConfirmAmount(statementContractDTO.getToPaidAmount()); |
| | | item.setContractId(statementContractDTO.getId()); |
| | | ReceiveBipVo bipVo = tranBipVo(statement, item, b, customer); |
| | | item.setBipParam(JSONObject.toJSONString(bipVo)); |
| | | bankStatementItemMapper.insert(item); |
| | | |
| | | Contract contract = contractMapper.selectById(statementContractDTO.getId()); |
| | | PaymentConfirmAddDTO addDTO = new PaymentConfirmAddDTO(); |
| | | addDTO.setBusGuestId(statement.getBusGuestId()+""); |
| | | addDTO.setBusGuestId(statement.getBusGuestId() + ""); |
| | | addDTO.setConfirmTime(statement.getTranDate()); |
| | | addDTO.setContractNo(contract.getContractNo()); |
| | | addDTO.setInOrOut(statement.getDcFlag()); |
| | |
| | | addDTO.setBankSeqNo(statement.getBankSeqNo()); |
| | | paymentConfirmService.add(addDTO); |
| | | |
| | | |
| | | //石工泵主动推送系统 |
| | | if ((StrUtil.equals(SecurityUtils.getUser().getCompId() + "", sgb)) && StrUtil.isNotEmpty(sgbErp)) { |
| | | BusinessCustomer customer = businessCustomerMapper.selectById(contract.getPartyAId()); |
| | | if (ObjUtil.isNotNull(customer)) { |
| | | pushCollection(statement, contract,customer,item); |
| | | } |
| | | } |
| | | |
| | | }); |
| | | |
| | | //判断是否内部单位 |
| | | CustInfoVo custInfoVo = bipViewMapper.selectBaseInfoByCustName(statement.getPayBankAccName()); |
| | | if (ObjUtil.isNull(custInfoVo)){ |
| | | return R.ok(); |
| | | //石工泵主动推送系统 |
| | | if ((StrUtil.equals(SecurityUtils.getUser().getCompId() + "", sgb)) && StrUtil.isNotEmpty(sgbErp)) { |
| | | pushCollectionSgb(statement, updateDTO.getContractCollectionList()); |
| | | } |
| | | //bip推送 |
| | | if (bipFlag&&custInfoVo.getCustCode().equals("01")) { |
| | | return pushSaveCollection(statement, updateDTO.getContractCollectionList()); |
| | | } |
| | | log.info("内部往来收款单,客户名称:{},客户类型:{},不用保存收款单",custInfoVo.getCustName(),custInfoVo.getCustclass()); |
| | | |
| | | // //判断是否内部单位 |
| | | // CustInfoVo custInfoVo = bipViewMapper.selectBaseInfoByCustName(statement.getPayBankAccName()); |
| | | // if (ObjUtil.isNull(custInfoVo)){ |
| | | // return R.ok(); |
| | | // } |
| | | // //bip推送 |
| | | // if (bipFlag&&custInfoVo.getCustCode().equals("01")) { |
| | | // return pushSaveCollection(statement, updateDTO.getContractCollectionList()); |
| | | // } |
| | | // log.info("内部往来收款单,客户名称:{},客户类型:{},不用保存收款单",custInfoVo.getCustName(),custInfoVo.getCustclass()); |
| | | return R.ok(); |
| | | } |
| | | |
| | | private void pushCollection(BankStatement statement,Contract contract,BusinessCustomer customer,BankStatementItem item) { |
| | | new Thread(() -> { |
| | | JSONObject request = genErpParam(statement,contract,customer,item); |
| | | String resp = ""; |
| | | String reqPath = ""; |
| | | log.info("工业泵收款/退款:{},入参:{}",statement.getDcFlag(),request.toJSONString()); |
| | | if (statement.getDcFlag().equals("1")){ |
| | | reqPath = sgbErp + "/arpclose/create"; |
| | | } |
| | | if (statement.getDcFlag().equals("2")){ |
| | | reqPath = sgbErp+"/arpclose/create"; |
| | | } |
| | | resp = HttpUtil.post(reqPath,request.toJSONString()); |
| | | saveErpRequestRecord("sgb",reqPath,request.toJSONString(),resp); |
| | | log.info("工业泵收款/退款回参:{}",resp); |
| | | private void pushCollectionSgb(BankStatement statement, List<StatementContractDTO> contractCollectionList) { |
| | | JSONObject request = genErpParam(statement, contractCollectionList); |
| | | statement.setPushParam(request.toJSONString()); |
| | | log.info("工业泵收款地址:{}", sgbErp + "/apilink/arclose/create?corpsecret=12345678&appserver=appserver1&accountid=888&tradeid=" + IdUtil.fastUUID()); |
| | | |
| | | try { |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | // HttpResponse resp = HttpUtil.createPost(sgbErp + "/apilink/arclose/create?corpsecret=12345678&appserver=appserver1&accountid=888&tradeid=" |
| | | // + IdUtil.fastUUID()) |
| | | // .header("Content-Type","application/x-www-form-urlencoded") |
| | | // .body(URLEncodeUtil.encode(request.toJSONString(), StandardCharsets.UTF_8)) |
| | | // .timeout(30000) |
| | | // // 指定编码格式 |
| | | // .charset(StandardCharsets.UTF_8) |
| | | // .execute(); |
| | | |
| | | log.info("工业泵收款入参:{}", "=" +request.toJSONString()); |
| | | OkHttpClient client = new OkHttpClient().newBuilder() |
| | | .build(); |
| | | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); |
| | | RequestBody body = RequestBody.create(mediaType, "=" + request.toJSONString()); |
| | | Request req = new Request.Builder() |
| | | .url(sgbErp + "/apilink/arclose/create?corpsecret=12345678&appserver=appserver1&accountid=888&tradeid=" + IdUtil.fastUUID()) |
| | | .method("POST", body) |
| | | .addHeader("Content-Type", "application/x-www-form-urlencoded") |
| | | .build(); |
| | | String result = ""; |
| | | try (Response response = client.newCall(req).execute()){ |
| | | if (response.isSuccessful()) { |
| | | // 仅调用一次string(),结果存入变量复用,后续所有逻辑直接读取该变量 |
| | | result = response.body().string(); |
| | | // 业务逻辑直接使用result,禁止再次调用response.body().string() |
| | | } |
| | | log.info("工业泵收款回参:{}", result); |
| | | saveErpRequestRecord("sgb", "/apilink/arclose/create", request.toJSONString(), result); |
| | | JSONObject respJson = JSONObject.parseObject(result); |
| | | if (respJson.containsKey("errcode") && respJson.getString("errcode").equals("0")) { |
| | | statement.setPushFlag(1); |
| | | statement.setPushVouchNo(respJson.getString("code")); |
| | | baseMapper.updateById(statement); |
| | | return; |
| | | } |
| | | }).start(); |
| | | log.error("工业泵收款推送失败:{}", response.body().string()); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | private void saveErpRequestRecord(String ymj,String medthodName, String toJSONString, String result) { |
| | | private void saveErpRequestRecord(String ymj, String medthodName, String toJSONString, String result) { |
| | | ErpRequestRecord record = new ErpRequestRecord(); |
| | | record.setErpName(ymj); |
| | | record.setMothedName(medthodName); |
| | |
| | | erpRequestRecordMapper.insert(record); |
| | | } |
| | | |
| | | private JSONObject genErpParam(BankStatement statement, Contract contract,BusinessCustomer customer,BankStatementItem item) { |
| | | private JSONObject genErpParam(BankStatement statement, List<StatementContractDTO> contractCollectionList) { |
| | | JSONObject req = new JSONObject(); |
| | | JSONObject djt = new JSONObject(); |
| | | djt.put("iAmt",item.getConfirmAmount()); |
| | | djt.put("iAmt_f",item.getConfirmAmount()); |
| | | djt.put("cCusVen",customer.getErpCompanyCode()); |
| | | djt.put("cexch_name","人民币"); |
| | | djt.put("iAmount",item.getConfirmAmount()); |
| | | req.put("单据头",djt); |
| | | Map<String, Object> djt = new LinkedHashMap<>(); |
| | | Contract contract = contractMapper.selectById(contractCollectionList.get(0).getId()); |
| | | BusinessCustomer customer = businessCustomerMapper.selectById(contract.getPartyAId()); |
| | | djt.put("dVouchDate", DateUtil.formatDate(statement.getTranDate()));//单据日期 |
| | | if (ObjUtil.isNotNull(customer)) { |
| | | djt.put("cDwCode", customer.getErpCompanyCode());//单位编码 |
| | | } |
| | | djt.put("cexch_name", "人民币");//单位编码 |
| | | djt.put("cOperator", "10123");//录入人编码 |
| | | djt.put("cSSCode", "01");//录入人编码 |
| | | djt.put("iAmount", statement.getConfirmAmount());//人民币金额 |
| | | djt.put("cBankAccount", statement.getReceiveBankAccAcc());//本方银行账号 |
| | | djt.put("cBank", statement.getPayBankAccName());//本方银行账号 |
| | | djt.put("cContractType", "161"); |
| | | if (CollUtil.size(contractCollectionList)==1) { |
| | | Contract contractHeader = contractMapper.selectById(contractCollectionList.get(0).getId()); |
| | | djt.put("cContractID", contractHeader.getErpContractNo()); |
| | | } |
| | | req.put("单据头", djt); |
| | | JSONObject line = new JSONObject(); |
| | | JSONArray array = new JSONArray(); |
| | | JSONObject djti = new JSONObject(); |
| | | djti.put("cVouchID",statement.getBankSeqNo()); |
| | | djti.put("dVouchDate",DateUtil.formatDate(statement.getTranDate())); |
| | | djti.put("cDwCode",customer.getErpCompanyCode()); |
| | | djti.put("cexch_name","人民币"); |
| | | djti.put("iAmount",item.getConfirmAmount()); |
| | | array.add(djti); |
| | | req.put("单据头",array); |
| | | |
| | | contractCollectionList.stream().forEach(statementContractDTO -> { |
| | | JSONObject djti = new JSONObject(); |
| | | djti.put("cCusVen", customer.getErpCompanyCode());//往来单位编码 |
| | | djti.put("iAmt_f", statementContractDTO.getToPaidAmount());//本行本币金额 |
| | | djti.put("iAmt", statementContractDTO.getToPaidAmount());//本行本币金额 |
| | | djti.put("cPersonCode", "00164");//业务员编码 |
| | | djti.put("cConID", contract.getErpContractNo());//合同编码 |
| | | djti.put("款项类型", "应收款"); |
| | | djti.put("cConType","镇江市"); |
| | | array.add(djti); |
| | | }); |
| | | |
| | | line.put("行", array); |
| | | req.put("单据体", line); |
| | | JSONObject apicontext = new JSONObject(); |
| | | apicontext.put("username", ""); |
| | | req.put("apicontext", apicontext); |
| | | return req; |
| | | } |
| | | |
| | | private R pushSaveCollection(BankStatement statement, List<StatementContractDTO> contractDTOList) { |
| | | private R pushSaveCollection(BankStatement statement, BankStatementItem bankStatementItem) { |
| | | String accessToken = ""; |
| | | if (redisTemplate.hasKey("BIP_TOKEN")) { |
| | | accessToken = (String) redisTemplate.opsForValue().get("BIP_TOKEN"); |
| | |
| | | String finalAccessToken = accessToken; |
| | | |
| | | R<SysDept> r = remoteDeptService.getById(SecurityUtils.getUser().getCompId()); |
| | | log.info("查询单位信息:{}",JSONObject.toJSONString(r.getData())); |
| | | if (!r.isOk()){ |
| | | log.info("查询单位信息:{}", JSONObject.toJSONString(r.getData())); |
| | | if (!r.isOk()) { |
| | | log.error("查询单位信息异常"); |
| | | return R.failed("查询单位信息异常"); |
| | | } |
| | | SysDept dept = r.getData(); |
| | | JSONObject params = genRequestParam(statement,dept,contractDTOList); |
| | | JSONObject params = genRequestParam(statement, dept, bankStatementItem); |
| | | |
| | | log.info("收款单集成 Request:{}", params.toJSONString()); |
| | | String result = HttpUtil.post(url + "/yonbip/EFI/collection/saveandsubmit?access_token=" + finalAccessToken, params.toJSONString()); |
| | |
| | | if (!resultJson.getString("code").equals("200")) { |
| | | return R.failed(resultJson.getString("message")); |
| | | } |
| | | bankStatementItem.setBipPush("1"); |
| | | bankStatementItem.setBipId(resultJson.getJSONObject("data").getLong("id")); |
| | | bankStatementItemMapper.updateById(bankStatementItem); |
| | | return R.ok(); |
| | | } |
| | | |
| | | private JSONObject genRequestParam(BankStatement statement,SysDept dept,List<StatementContractDTO> contractDTOList) { |
| | | Contract contract1 = contractMapper.selectById(contractDTOList.get(0).getId()); |
| | | BusinessCustomer customer = businessCustomerMapper.selectById(contract1.getPartyAId()); |
| | | private JSONObject genRequestParam(BankStatement statement, SysDept dept, BankStatementItem statementItem) { |
| | | Contract contract = contractMapper.selectById(statementItem.getContractId()); |
| | | BusinessCustomer customer = businessCustomerMapper.selectById(contract.getPartyAId()); |
| | | ReceiveBipVo bipVo = BeanUtil.copyProperties(JSONObject.parseObject(statementItem.getBipParam()), ReceiveBipVo.class); |
| | | JSONObject jsonObject = new JSONObject(); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("billDate",DateUtil.format(statement.getTranDate(), DatePattern.NORM_DATETIME_FORMAT)); |
| | | data.put("exchangeRate","1");//汇率 |
| | | data.put("exchangeRateDate",DateUtil.now());//汇率时间 |
| | | data.put("objectType","1"); |
| | | data.put("customerCode",customer.getBipCode());//客户编码 |
| | | data.put("financeOrgCode",dept.getBipCode());//开票组织编码 |
| | | data.put("orgCode",dept.getBipCode());//业务组织编码 |
| | | data.put("bustypeCode","ar_colsale");// TODO 交易类型编码 暂估默认ZGYSFP,装备默认ZBYXGLXT暂时不能用 |
| | | data.put("oriCurrencyCode","CNY");//币种 |
| | | data.put("srcBillType","38"); |
| | | data.put("srcBillNo",statement.getBankSeqNo()); |
| | | data.put("_status","Insert"); |
| | | data.put("billDate", DateUtil.format(statement.getTranDate(), DatePattern.NORM_DATETIME_FORMAT)); |
| | | data.put("exchangeRate", "1");//汇率 |
| | | data.put("exchangeRateDate", DateUtil.now());//汇率时间 |
| | | data.put("objectType", "1"); |
| | | data.put("customerCode", customer.getBipCode());//客户编码 |
| | | data.put("financeOrgCode", dept.getBipCode());//开票组织编码 |
| | | data.put("orgCode", dept.getBipCode());//业务组织编码 |
| | | data.put("bustypeCode", "ar_colsale");// TODO 交易类型编码 暂估默认ZGYSFP,装备默认ZBYXGLXT暂时不能用 |
| | | data.put("oriCurrencyCode", "CNY");//币种 |
| | | data.put("srcBillType", "38"); |
| | | data.put("srcBillNo", statement.getBankSeqNo()); |
| | | data.put("_status", "Insert"); |
| | | JSONArray bodyItem = new JSONArray(); |
| | | for (StatementContractDTO statementContractDTO:contractDTOList) { |
| | | Contract contract = contractMapper.selectById(statementContractDTO.getId()); |
| | | JSONObject item = new JSONObject(); |
| | | item.put("oriTaxIncludedAmount", statementContractDTO.getToPaidAmount()); |
| | | item.put("contractNo", contract.getContractNo()); |
| | | item.put("quickTypeCode", "1"); |
| | | item.put("_status", "Insert"); |
| | | bodyItem.add(item); |
| | | } |
| | | data.put("bodyItem",bodyItem); |
| | | jsonObject.put("data",data); |
| | | return jsonObject; |
| | | |
| | | JSONObject item = new JSONObject(); |
| | | item.put("oriTaxIncludedAmount", statementItem.getConfirmAmount()); |
| | | item.put("contractNo", contract.getContractNo()); |
| | | item.put("quickTypeCode", "1"); |
| | | item.put("_status", "Insert"); |
| | | |
| | | item.put("expenseItemCode", bipVo.getItemList().get(0).getJjsx());//经济事项 |
| | | item.put("remarks", bipVo.getItemList().get(0).getZy());//摘要 |
| | | JSONObject freeChId = new JSONObject(); |
| | | freeChId.put("GX08", bipVo.getItemList().get(0).getHsdy());//核算单元 |
| | | freeChId.put("YSYF14", "1");//款项类型 1 预收款 2 应收款 |
| | | freeChId.put("JT04", bipVo.getItemList().get(0).getHsjylx());//核算交易类型 0101 集团外部 01020301 三级分子公司间 01020302 三级分公司与子子公司之间 |
| | | freeChId.put("JT06", bipVo.getItemList().get(0).getKxmx());//款项明细 |
| | | freeChId.put("JT12", bipVo.getItemList().get(0).getCpwlfl());//产品物料分类 |
| | | |
| | | item.put("freeChId", freeChId); |
| | | |
| | | |
| | | bodyItem.add(item); |
| | | data.put("bodyItem", bodyItem); |
| | | JSONObject datafreeChId = new JSONObject(); |
| | | datafreeChId.put("YSYF_SFZY", bipVo.getSfzy());//是否主营 |
| | | datafreeChId.put("fk_038", bipVo.getPzzdr());//凭证制单人 |
| | | datafreeChId.put("YSYF_08", bipVo.getSfnbwl());//是否内部往来 |
| | | datafreeChId.put("YSYF24", bipVo.getSfjyjs());//是否简易计税 |
| | | datafreeChId.put("fk_002", bipVo.getFjzs());//附件1 |
| | | datafreeChId.put("GX08", bipVo.getHsdy());//核算单元 |
| | | datafreeChId.put("TzMY042", contract.getExpirationDate());//预计回款日期 |
| | | data.put("freeChId", datafreeChId); |
| | | data.put("remarks", bipVo.getZy());//摘要 |
| | | jsonObject.put("data", data); |
| | | return jsonObject; |
| | | } |
| | | |
| | | @Override |
| | |
| | | .select(Contract::getContractNo) |
| | | .select(Contract::getPartyA) |
| | | .select(Contract::getAmount) |
| | | .leftJoin(Contract.class,Contract::getId,BankStatementItem::getContractId) |
| | | .eq(BankStatementItem::getCompId,SecurityUtils.getUser().getCompId()) |
| | | .eq(BankStatementItem::getStatetId,id) |
| | | .leftJoin(Contract.class, Contract::getId, BankStatementItem::getContractId) |
| | | .eq(BankStatementItem::getCompId, SecurityUtils.getUser().getCompId()) |
| | | .eq(BankStatementItem::getStatetId, id) |
| | | .orderByDesc(BankStatementItem::getCreateTime); |
| | | return R.ok(bankStatementItemMapper.selectJoinList(StatementContractVo.class, wrapper)); |
| | | } |
| | |
| | | BankStatementItem statement = bankStatementItemMapper.selectById(id); |
| | | BankStatement bankStatement = baseMapper.selectById(statement.getStatetId()); |
| | | Contract contract = contractMapper.selectById(statement.getContractId()); |
| | | if (ObjUtil.isNull(contract)){ |
| | | if (ObjUtil.isNull(contract)) { |
| | | return R.failed("合同信息异常"); |
| | | } |
| | | BusinessCustomer customer = businessCustomerMapper.selectById(contract.getPartyAId()); |
| | | if (ObjUtil.isNull(customer)){ |
| | | if (ObjUtil.isNull(customer)) { |
| | | return R.failed("客户信息信息异常"); |
| | | } |
| | | R<SysDept> r = remoteDeptService.getById(contract.getPartyBId()); |
| | | if (!r.isOk()){ |
| | | if (!r.isOk()) { |
| | | return r; |
| | | } |
| | | //bip推送 |
| | |
| | | return R.failed("bip accessToken 获取异常"); |
| | | } |
| | | String finalAccessToken = accessToken; |
| | | JSONObject request = genRefundParam(bankStatement,statement, contract, customer, r.getData()); |
| | | JSONObject request = genRefundParam(bankStatement, statement, contract, customer, r.getData()); |
| | | log.info("收款退款单-退款单一历史确认请求入参:{}", request.toJSONString()); |
| | | String result = HttpUtil.post(url + "/yonbip/EFI/arRefund/saveandsubmit?access_token=" + finalAccessToken, request.toJSONString()); |
| | | log.info("收款退款单-退款单一历史确认请求回参:{}", result); |
| | |
| | | return R.ok(); |
| | | } |
| | | |
| | | private JSONObject genRefundParam(BankStatement bankStatement,BankStatementItem statement, Contract contract,BusinessCustomer customer, SysDept dept) { |
| | | private JSONObject genRefundParam(BankStatement bankStatement, BankStatementItem statement, Contract contract, BusinessCustomer customer, SysDept dept) { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("billDate",DateUtil.now()); |
| | | data.put("exchangeRate","1");//汇率 |
| | | data.put("exchangeRateDate",DateUtil.now());//汇率时间 |
| | | data.put("objectType","1"); |
| | | data.put("customerCode",customer.getBipCode());//客户编码 |
| | | data.put("financeOrgCode",dept.getBipCode());//开票组织编码 |
| | | data.put("orgCode",dept.getBipCode());//业务组织编码 |
| | | data.put("bustypeCode","ar_refsale");//交易类型编码 暂估默认ZGYSFP,销售默认MJHYXGLXT |
| | | data.put("oriCurrencyCode","CNY");//币种 |
| | | data.put("srcBillType","38"); |
| | | data.put("srcBillNo",bankStatement.getBankSeqNo()); |
| | | data.put("_status","Insert"); |
| | | data.put("billDate", DateUtil.now()); |
| | | data.put("exchangeRate", "1");//汇率 |
| | | data.put("exchangeRateDate", DateUtil.now());//汇率时间 |
| | | data.put("objectType", "1"); |
| | | data.put("customerCode", customer.getBipCode());//客户编码 |
| | | data.put("financeOrgCode", dept.getBipCode());//开票组织编码 |
| | | data.put("orgCode", dept.getBipCode());//业务组织编码 |
| | | data.put("bustypeCode", "ar_refsale");//交易类型编码 暂估默认ZGYSFP,销售默认MJHYXGLXT |
| | | data.put("oriCurrencyCode", "CNY");//币种 |
| | | data.put("srcBillType", "38"); |
| | | data.put("srcBillNo", bankStatement.getBankSeqNo()); |
| | | data.put("_status", "Insert"); |
| | | JSONArray bodyItem = new JSONArray(); |
| | | JSONObject item = new JSONObject(); |
| | | item.put("oriTaxIncludedAmount", statement.getConfirmAmount()); |
| | |
| | | item.put("quickTypeCode", "1"); |
| | | item.put("_status", "Insert"); |
| | | bodyItem.add(item); |
| | | data.put("bodyItem",bodyItem); |
| | | jsonObject.put("data",data); |
| | | return jsonObject; |
| | | data.put("bodyItem", bodyItem); |
| | | jsonObject.put("data", data); |
| | | return jsonObject; |
| | | } |
| | | |
| | | @Override |
| | | public R backBal(Long id) { |
| | | BankStatement bankStatement = baseMapper.selectById(id); |
| | | BusinessCustomer customer = businessCustomerMapper.selectById(bankStatement.getBusGuestId()); |
| | | if (ObjUtil.isNull(customer)||StrUtil.isEmpty(customer.getBipCode())){ |
| | | if (ObjUtil.isNull(customer) || StrUtil.isEmpty(customer.getBipCode())) { |
| | | log.error("查询客户信息异常"); |
| | | return R.failed("查询客户信息异常"); |
| | | } |
| | | R<SysDept> r = remoteDeptService.getById(SecurityUtils.getUser().getCompId()); |
| | | if (!r.isOk()){ |
| | | if (!r.isOk()) { |
| | | log.error("查询单位信息异常"); |
| | | return R.failed("查询单位信息异常"); |
| | | } |
| | | SysDept dept = r.getData(); |
| | | List<BankStatementItem> items = bankStatementItemMapper.selectList(Wrappers.<BankStatementItem>lambdaQuery() |
| | | .eq(BankStatementItem::getStatetId,id)); |
| | | if (bipFlag){ |
| | | .eq(BankStatementItem::getStatetId, id)); |
| | | if (bipFlag) { |
| | | String accessToken = ""; |
| | | if (redisTemplate.hasKey("BIP_TOKEN")) { |
| | | accessToken = (String) redisTemplate.opsForValue().get("BIP_TOKEN"); |
| | |
| | | return R.failed("bip accessToken 获取异常"); |
| | | } |
| | | String finalAccessToken = accessToken; |
| | | JSONObject request = genBackBalParam(bankStatement,customer,dept,items); |
| | | JSONObject request = genBackBalParam(bankStatement, customer, dept, items); |
| | | log.info("收款退款单-退款余额请求入参:{}", request.toJSONString()); |
| | | String result = HttpUtil.post(url + "/yonbip/EFI/arRefund/saveandsubmit?access_token=" + finalAccessToken, request.toJSONString()); |
| | | log.info("收款退款单-退款余额请求回参:{}", result); |
| | |
| | | private JSONObject genBackBalParam(BankStatement bankStatement, BusinessCustomer customer, SysDept dept, List<BankStatementItem> items) { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("billDate",DateUtil.now()); |
| | | data.put("exchangeRate","1");//汇率 |
| | | data.put("exchangeRateDate",DateUtil.now());//汇率时间 |
| | | data.put("objectType","1"); |
| | | data.put("customerCode",customer.getBipCode());//客户编码 |
| | | data.put("financeOrgCode",dept.getBipCode());//开票组织编码 |
| | | data.put("orgCode",dept.getBipCode());//业务组织编码 |
| | | data.put("bustypeCode","ar_refsale");//交易类型编码 暂估默认ZGYSFP,销售默认MJHYXGLXT |
| | | data.put("oriCurrencyCode","CNY");//币种 |
| | | data.put("srcBillType","38"); |
| | | data.put("srcBillNo",bankStatement.getBankSeqNo()); |
| | | data.put("_status","Insert"); |
| | | data.put("billDate", DateUtil.now()); |
| | | data.put("exchangeRate", "1");//汇率 |
| | | data.put("exchangeRateDate", DateUtil.now());//汇率时间 |
| | | data.put("objectType", "1"); |
| | | data.put("customerCode", customer.getBipCode());//客户编码 |
| | | data.put("financeOrgCode", dept.getBipCode());//开票组织编码 |
| | | data.put("orgCode", dept.getBipCode());//业务组织编码 |
| | | data.put("bustypeCode", "ar_refsale");//交易类型编码 暂估默认ZGYSFP,销售默认MJHYXGLXT |
| | | data.put("oriCurrencyCode", "CNY");//币种 |
| | | data.put("srcBillType", "38"); |
| | | data.put("srcBillNo", bankStatement.getBankSeqNo()); |
| | | data.put("_status", "Insert"); |
| | | JSONArray bodyItem = new JSONArray(); |
| | | JSONObject item = new JSONObject(); |
| | | item.put("oriTaxIncludedAmount", bankStatement.getTranAmount().subtract(bankStatement.getConfirmAmount())); |
| | | item.put("quickTypeCode", "1"); |
| | | item.put("_status", "Insert"); |
| | | bodyItem.add(item); |
| | | data.put("bodyItem",bodyItem); |
| | | jsonObject.put("data",data); |
| | | return jsonObject; |
| | | data.put("bodyItem", bodyItem); |
| | | jsonObject.put("data", data); |
| | | return jsonObject; |
| | | } |
| | | |
| | | @Override |
| | | public R backAll(Long id) { |
| | | BankStatement bankStatement = baseMapper.selectById(id); |
| | | BusinessCustomer customer = businessCustomerMapper.selectById(bankStatement.getBusGuestId()); |
| | | if (ObjUtil.isNull(customer)||StrUtil.isEmpty(customer.getBipCode())){ |
| | | if (ObjUtil.isNull(customer) || StrUtil.isEmpty(customer.getBipCode())) { |
| | | log.error("查询客户信息异常"); |
| | | return R.failed("查询客户信息异常"); |
| | | } |
| | | R<SysDept> r = remoteDeptService.getById(SecurityUtils.getUser().getCompId()); |
| | | if (!r.isOk()){ |
| | | if (!r.isOk()) { |
| | | log.error("查询单位信息异常"); |
| | | return R.failed("查询单位信息异常"); |
| | | } |
| | | SysDept dept = r.getData(); |
| | | List<BankStatementItem> items = bankStatementItemMapper.selectList(Wrappers.<BankStatementItem>lambdaQuery() |
| | | .eq(BankStatementItem::getStatetId,id)); |
| | | if (bipFlag){ |
| | | .eq(BankStatementItem::getStatetId, id)); |
| | | if (bipFlag) { |
| | | String accessToken = ""; |
| | | if (redisTemplate.hasKey("BIP_TOKEN")) { |
| | | accessToken = (String) redisTemplate.opsForValue().get("BIP_TOKEN"); |
| | |
| | | return R.failed("bip accessToken 获取异常"); |
| | | } |
| | | String finalAccessToken = accessToken; |
| | | JSONObject request = genBackAllParam(bankStatement,customer,dept,items); |
| | | JSONObject request = genBackAllParam(bankStatement, customer, dept, items); |
| | | log.info("收款退款单-退款所有请求入参:{}", request.toJSONString()); |
| | | String result = HttpUtil.post(url + "/yonbip/EFI/arRefund/saveandsubmit?access_token=" + finalAccessToken, request.toJSONString()); |
| | | log.info("收款退款单-退款所有请求回参:{}", result); |
| | |
| | | private JSONObject genBackAllParam(BankStatement bankStatement, BusinessCustomer customer, SysDept dept, List<BankStatementItem> items) { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("billDate",DateUtil.now()); |
| | | data.put("exchangeRate","1");//汇率 |
| | | data.put("exchangeRateDate",DateUtil.now());//汇率时间 |
| | | data.put("objectType","1"); |
| | | data.put("customerCode",customer.getBipCode());//客户编码 |
| | | data.put("financeOrgCode",dept.getBipCode());//开票组织编码 |
| | | data.put("orgCode",dept.getBipCode());//业务组织编码 |
| | | data.put("bustypeCode","ar_refsale");//交易类型编码 暂估默认ZGYSFP,销售默认MJHYXGLXT |
| | | data.put("oriCurrencyCode","CNY");//币种 |
| | | data.put("srcBillType","38"); |
| | | data.put("srcBillNo",bankStatement.getBankSeqNo()); |
| | | data.put("_status","Insert"); |
| | | data.put("billDate", DateUtil.now()); |
| | | data.put("exchangeRate", "1");//汇率 |
| | | data.put("exchangeRateDate", DateUtil.now());//汇率时间 |
| | | data.put("objectType", "1"); |
| | | data.put("customerCode", customer.getBipCode());//客户编码 |
| | | data.put("financeOrgCode", dept.getBipCode());//开票组织编码 |
| | | data.put("orgCode", dept.getBipCode());//业务组织编码 |
| | | data.put("bustypeCode", "ar_refsale");//交易类型编码 暂估默认ZGYSFP,销售默认MJHYXGLXT |
| | | data.put("oriCurrencyCode", "CNY");//币种 |
| | | data.put("srcBillType", "38"); |
| | | data.put("srcBillNo", bankStatement.getBankSeqNo()); |
| | | data.put("_status", "Insert"); |
| | | JSONArray bodyItem = new JSONArray(); |
| | | JSONObject item = new JSONObject(); |
| | | item.put("oriTaxIncludedAmount", bankStatement.getTranAmount()); |
| | | item.put("quickTypeCode", "1"); |
| | | item.put("_status", "Insert"); |
| | | bodyItem.add(item); |
| | | data.put("bodyItem",bodyItem); |
| | | jsonObject.put("data",data); |
| | | return jsonObject; |
| | | data.put("bodyItem", bodyItem); |
| | | jsonObject.put("data", data); |
| | | return jsonObject; |
| | | } |
| | | |
| | | @Override |
| | | public R backHis(Long id) { |
| | | BankStatement bankStatement = baseMapper.selectById(id); |
| | | BusinessCustomer customer = businessCustomerMapper.selectById(bankStatement.getBusGuestId()); |
| | | if (ObjUtil.isNull(customer)||StrUtil.isEmpty(customer.getBipCode())){ |
| | | if (ObjUtil.isNull(customer) || StrUtil.isEmpty(customer.getBipCode())) { |
| | | log.error("查询客户信息异常"); |
| | | return R.failed("查询客户信息异常"); |
| | | } |
| | | R<SysDept> r = remoteDeptService.getById(SecurityUtils.getUser().getCompId()); |
| | | if (!r.isOk()){ |
| | | if (!r.isOk()) { |
| | | log.error("查询单位信息异常"); |
| | | return R.failed("查询单位信息异常"); |
| | | } |
| | | SysDept dept = r.getData(); |
| | | List<BankStatementItem> items = bankStatementItemMapper.selectList(Wrappers.<BankStatementItem>lambdaQuery() |
| | | .eq(BankStatementItem::getStatetId,id)); |
| | | if (bipFlag){ |
| | | .eq(BankStatementItem::getStatetId, id)); |
| | | if (bipFlag) { |
| | | String accessToken = ""; |
| | | if (redisTemplate.hasKey("BIP_TOKEN")) { |
| | | accessToken = (String) redisTemplate.opsForValue().get("BIP_TOKEN"); |
| | |
| | | return R.failed("bip accessToken 获取异常"); |
| | | } |
| | | String finalAccessToken = accessToken; |
| | | JSONObject request = genBackHisParam(bankStatement,customer,dept,items); |
| | | JSONObject request = genBackHisParam(bankStatement, customer, dept, items); |
| | | log.info("收款退款单-退款历史确认请求入参:{}", request.toJSONString()); |
| | | String result = HttpUtil.post(url + "/yonbip/EFI/arRefund/saveandsubmit?access_token=" + finalAccessToken, request.toJSONString()); |
| | | log.info("收款退款单-退款历史确认请求回参:{}", result); |
| | |
| | | |
| | | bankStatement.setConfirmAmount(new BigDecimal("0")); |
| | | baseMapper.updateById(bankStatement); |
| | | bankStatementItemMapper.deleteByIds(items.stream().map(item->item.getId()).collect(Collectors.toList())); |
| | | bankStatementItemMapper.deleteByIds(items.stream().map(item -> item.getId()).collect(Collectors.toList())); |
| | | return R.ok(); |
| | | } |
| | | |
| | | private JSONObject genBackHisParam(BankStatement bankStatement, BusinessCustomer customer, SysDept dept,List<BankStatementItem> items) { |
| | | private JSONObject genBackHisParam(BankStatement bankStatement, BusinessCustomer customer, SysDept dept, List<BankStatementItem> items) { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("billDate",DateUtil.now()); |
| | | data.put("exchangeRate","1");//汇率 |
| | | data.put("exchangeRateDate",DateUtil.now());//汇率时间 |
| | | data.put("objectType","1"); |
| | | data.put("customerCode",customer.getBipCode());//客户编码 |
| | | data.put("financeOrgCode",dept.getBipCode());//开票组织编码 |
| | | data.put("orgCode",dept.getBipCode());//业务组织编码 |
| | | data.put("bustypeCode","ar_refsale");//交易类型编码 暂估默认ZGYSFP,销售默认MJHYXGLXT |
| | | data.put("oriCurrencyCode","CNY");//币种 |
| | | data.put("srcBillType","38"); |
| | | data.put("srcBillNo",bankStatement.getBankSeqNo()); |
| | | data.put("_status","Insert"); |
| | | data.put("billDate", DateUtil.now()); |
| | | data.put("exchangeRate", "1");//汇率 |
| | | data.put("exchangeRateDate", DateUtil.now());//汇率时间 |
| | | data.put("objectType", "1"); |
| | | data.put("customerCode", customer.getBipCode());//客户编码 |
| | | data.put("financeOrgCode", dept.getBipCode());//开票组织编码 |
| | | data.put("orgCode", dept.getBipCode());//业务组织编码 |
| | | data.put("bustypeCode", "ar_refsale");//交易类型编码 暂估默认ZGYSFP,销售默认MJHYXGLXT |
| | | data.put("oriCurrencyCode", "CNY");//币种 |
| | | data.put("srcBillType", "38"); |
| | | data.put("srcBillNo", bankStatement.getBankSeqNo()); |
| | | data.put("_status", "Insert"); |
| | | JSONArray bodyItem = new JSONArray(); |
| | | for (BankStatementItem statementItem:items) { |
| | | for (BankStatementItem statementItem : items) { |
| | | Contract contract = contractMapper.selectById(statementItem.getContractId()); |
| | | JSONObject item = new JSONObject(); |
| | | item.put("oriTaxIncludedAmount", statementItem.getConfirmAmount()); |
| | |
| | | item.put("_status", "Insert"); |
| | | bodyItem.add(item); |
| | | } |
| | | data.put("bodyItem",bodyItem); |
| | | jsonObject.put("data",data); |
| | | return jsonObject; |
| | | data.put("bodyItem", bodyItem); |
| | | jsonObject.put("data", data); |
| | | return jsonObject; |
| | | } |
| | | |
| | | private ReceiveBipVo tranBipVo(BankStatement statement, BankStatementItem bankStatementItem, SysDept b, BusinessCustomer customer) { |
| | | ReceiveBipVo bipVo = new ReceiveBipVo(); |
| | | bipVo.setDjrq(DateUtil.formatDate(statement.getTranDate())); |
| | | bipVo.setKpzz(b.getBipCode()); |
| | | bipVo.setYwzz(b.getBipCode()); |
| | | R<SysDept> rDept = remoteDeptService.getById(SecurityUtils.getUser().getDeptId()); |
| | | if (rDept.isOk()) { |
| | | bipVo.setBm(rDept.getData().getOrgCode()); |
| | | bipVo.setHsdy(rDept.getData().getOrgCode()); |
| | | } |
| | | bipVo.setYwy(SecurityUtils.getUser().getNickname()); |
| | | bipVo.setPzzdr(SecurityUtils.getUser().getNickname()); |
| | | bipVo.setJylx("ZBYXGLXT"); |
| | | bipVo.setWldxlx("1"); |
| | | bipVo.setKh(customer.getCreditCode()); |
| | | bipVo.setBz("CNY"); |
| | | bipVo.setFjzs("0"); |
| | | bipVo.setSfzy("1"); |
| | | bipVo.setSfnbwl("1"); |
| | | bipVo.setSfjyjs("0"); |
| | | bipVo.setDjfx("1"); |
| | | List<ReceiveItemVo> list = new ArrayList<>(); |
| | | ReceiveItemVo itemVo = new ReceiveItemVo(); |
| | | itemVo.setConfirmAmount(bankStatementItem.getConfirmAmount()); |
| | | list.add(itemVo); |
| | | bipVo.setItemList(list); |
| | | return bipVo; |
| | | } |
| | | |
| | | @Override |
| | | public R pushBip(Long itemId) { |
| | | BankStatementItem item = bankStatementItemMapper.selectById(itemId); |
| | | public Page pageBip(Page page, BipQueryDTO queryDTO) { |
| | | return baseMapper.pageBip(page, queryDTO, DataScope.of("comp_id")); |
| | | } |
| | | |
| | | @Override |
| | | public R saveAndPush(BankStatementUpdateDTO updateDTO) { |
| | | BankStatementItem item = bankStatementItemMapper.selectById(updateDTO.getId()); |
| | | item.setBipParam(updateDTO.getBipParam()); |
| | | bankStatementItemMapper.updateById(item); |
| | | BankStatement statement = baseMapper.selectById(item.getStatetId()); |
| | | List<StatementContractDTO> statementContractDTOList = new ArrayList<>(); |
| | | StatementContractDTO contractDTO = new StatementContractDTO(); |
| | | contractDTO.setId(item.getContractId()); |
| | | contractDTO.setToPaidAmount(item.getConfirmAmount()); |
| | | statementContractDTOList.add(contractDTO); |
| | | R r = pushSaveCollection(statement,statementContractDTOList); |
| | | if (r.isOk()){ |
| | | item.setPushFlag("1"); |
| | | bankStatementItemMapper.updateById(item); |
| | | return r; |
| | | } |
| | | return r; |
| | | return pushSaveCollection(statement, item); |
| | | } |
| | | } |