|
@@ -0,0 +1,386 @@
|
|
|
+package nckd.jimin.jyyy.fi.webapi;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import kd.bos.dataentity.entity.DynamicObject;
|
|
|
+import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
|
+import kd.bos.db.DB;
|
|
|
+import kd.bos.ext.fi.plugin.ArApConvert.util.EmptyUtils;
|
|
|
+import kd.bos.logging.Log;
|
|
|
+import kd.bos.logging.LogFactory;
|
|
|
+import kd.bos.login.utils.DateUtils;
|
|
|
+import kd.bos.openapi.common.custom.annotation.ApiController;
|
|
|
+import kd.bos.openapi.common.custom.annotation.ApiMapping;
|
|
|
+import kd.bos.openapi.common.custom.annotation.ApiParam;
|
|
|
+import kd.bos.openapi.common.custom.annotation.ApiPostMapping;
|
|
|
+import kd.bos.openapi.common.result.CustomApiResult;
|
|
|
+import kd.bos.orm.query.QCP;
|
|
|
+import kd.bos.orm.query.QFilter;
|
|
|
+import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
+import kd.bos.servicehelper.operation.DeleteServiceHelper;
|
|
|
+import kd.bos.servicehelper.operation.SaveServiceHelper;
|
|
|
+
|
|
|
+import java.io.Serializable;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * 交易明细API插件类
|
|
|
+ * 用于处理交易明细相关的操作,如保存交易明细信息。
|
|
|
+ */
|
|
|
+@ApiController(value = "nstc", desc = "对接九恒星交易明细")
|
|
|
+@ApiMapping("/nstc")
|
|
|
+public class TransDetailApiPlugin implements Serializable {
|
|
|
+
|
|
|
+ private static final Log log = LogFactory.getLog(TransDetailApiPlugin.class);
|
|
|
+
|
|
|
+
|
|
|
+ * 保存交易明细
|
|
|
+ *
|
|
|
+ * @param operation 操作类型
|
|
|
+ * @param jsondata 交易明细数据
|
|
|
+ * @return 处理结果
|
|
|
+ */
|
|
|
+ @ApiPostMapping(value = "/transdetail", desc = "操作九恒星交易明细")
|
|
|
+ public CustomApiResult<Object> oprationTransDetail(
|
|
|
+ @ApiParam(value = "操作类型", required = true) String operation,
|
|
|
+ @ApiParam(value = "交易明细数据", required = true) String jsondata
|
|
|
+ ) {
|
|
|
+ log.info("收到保存交易明细请求:\r\n操作类型:{}\r\n交易明细数据:{}",
|
|
|
+ operation,
|
|
|
+ jsondata
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+ if(jsondata.startsWith("[")){
|
|
|
+ log.error("保存交易明细失败。操作类型:{},交易明细数据:{},错误信息:{}", operation, jsondata, "只允许接收1条数据,请重新传输!");
|
|
|
+ return CustomApiResult.fail("803","操作交易明细失败: 只允许接收1条数据,请重新传输!");
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ switch (operation) {
|
|
|
+ case "save":
|
|
|
+
|
|
|
+ String errMsg = saveTransDetail(jsondata);
|
|
|
+ if (!EmptyUtils.isEmpty(errMsg)) {
|
|
|
+ log.error("交易明细添加失败。操作类型:{},交易明细数据:{},错误信息:{}", operation, jsondata, "交易明细添加失败" + errMsg);
|
|
|
+ return CustomApiResult.fail("802","交易明细添加失败" + errMsg);
|
|
|
+ } else {
|
|
|
+ log.info("交易明细添加成功。操作类型:{},交易明细数据:{}", operation, jsondata);
|
|
|
+ return CustomApiResult.success("交易明细添加成功");
|
|
|
+ }
|
|
|
+ case "delete":
|
|
|
+
|
|
|
+ String errMsg1 = deleteTransDetail(jsondata);
|
|
|
+ if (!EmptyUtils.isEmpty(errMsg1)) {
|
|
|
+ log.error("交易明细更新失败。操作类型:{},交易明细数据:{},错误信息:{}", operation, jsondata, errMsg1);
|
|
|
+ return CustomApiResult.fail("801","交易明细更新失败" + errMsg1);
|
|
|
+ } else {
|
|
|
+ log.info("交易明细更新成功。操作类型:{},交易明细数据:{}", operation, jsondata);
|
|
|
+ return CustomApiResult.success("交易明细更新成功");
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ log.error("不支持的操作类型。操作类型:{},交易明细数据:{}", operation, jsondata);
|
|
|
+ return CustomApiResult.fail("700","不支持的操作类型");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("保存交易明细失败。操作类型:{},交易明细数据:{},错误信息:{}", operation, jsondata, e.getMessage());
|
|
|
+ return CustomApiResult.fail("801","操作交易明细失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String deleteTransDetail(String jsonData) {
|
|
|
+
|
|
|
+ JSONObject jsonObject = JSON.parseObject(jsonData);
|
|
|
+
|
|
|
+ StringBuilder errMsg = new StringBuilder();
|
|
|
+
|
|
|
+ String number = jsonObject.getString("number");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ DynamicObject billByn = BusinessDataServiceHelper.loadSingle(
|
|
|
+ BeiTransdetailConstantInfo.ENTITYID,
|
|
|
+ new QFilter[]{new QFilter(BeiTransdetailConstantInfo.BILLNO, QCP.equals, number)}
|
|
|
+ );
|
|
|
+ if(!EmptyUtils.isEmpty(billByn)) {
|
|
|
+ DeleteServiceHelper.delete(BeiTransdetailConstantInfo.ENTITYID,new QFilter[]{new QFilter("id", QCP.equals, billByn.getPkValue())});
|
|
|
+ }else {
|
|
|
+ errMsg = new StringBuilder("交易流水号: " + number + "不存在;");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ DynamicObject billeleByn = BusinessDataServiceHelper.loadSingle(
|
|
|
+ BeiElecreceiptConstantInfo.ENTITYID,
|
|
|
+ new QFilter[]{new QFilter(BeiElecreceiptConstantInfo.BILLNO, QCP.equals, number)}
|
|
|
+ );
|
|
|
+ if(!EmptyUtils.isEmpty(billeleByn)) {
|
|
|
+ DeleteServiceHelper.delete(BeiElecreceiptConstantInfo.ENTITYID,new QFilter[]{new QFilter("id", QCP.equals, billeleByn.getPkValue())});
|
|
|
+ }else {
|
|
|
+ errMsg = new StringBuilder("电子回单号: " + number + "不存在;");
|
|
|
+ }
|
|
|
+
|
|
|
+ return errMsg.toString();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 保存交易明细信息
|
|
|
+ *
|
|
|
+ * @param jsonData JSON数据
|
|
|
+ */
|
|
|
+ public String saveTransDetail( String jsonData) {
|
|
|
+
|
|
|
+ JSONObject jsonObject = JSON.parseObject(jsonData);
|
|
|
+
|
|
|
+ StringBuilder errMsg = new StringBuilder();
|
|
|
+
|
|
|
+ String number = jsonObject.getString("number");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ DynamicObject billByn = BusinessDataServiceHelper.loadSingle(
|
|
|
+ BeiTransdetailConstantInfo.ENTITYID,
|
|
|
+ new QFilter[]{new QFilter(BeiTransdetailConstantInfo.BILLNO, QCP.equals, number)}
|
|
|
+ );
|
|
|
+ boolean isNew = EmptyUtils.isEmpty(billByn);
|
|
|
+ DynamicObject transDetail = null;
|
|
|
+ if(!isNew){
|
|
|
+ transDetail = billByn;
|
|
|
+ }else {
|
|
|
+
|
|
|
+ transDetail = BusinessDataServiceHelper.newDynamicObject(BeiTransdetailConstantInfo.ENTITYID);
|
|
|
+
|
|
|
+ long Id = DB.genLongId("t_bei_transdetail");
|
|
|
+ transDetail.set("id", Id);
|
|
|
+ transDetail.set(BeiTransdetailConstantInfo.BILLNO, number);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * 资金组织判断
|
|
|
+ */
|
|
|
+ String company = jsonObject.getString("company");
|
|
|
+ DynamicObject companyByn = BusinessDataServiceHelper.loadSingle("bos_org",new QFilter[]{new QFilter("number", QCP.equals, company)});
|
|
|
+ if(EmptyUtils.isEmpty(companyByn)) {
|
|
|
+ errMsg.append("资金组织不存在;");
|
|
|
+ }else {
|
|
|
+ transDetail.set(BeiTransdetailConstantInfo.COMPANY, companyByn);
|
|
|
+ }
|
|
|
+
|
|
|
+ * 银行账号Number
|
|
|
+ */
|
|
|
+ String bankAccount = jsonObject.getString("bankAccount");
|
|
|
+ DynamicObject bankAccountByn = BusinessDataServiceHelper.loadSingle("bd_accountbanks",new QFilter[]{new QFilter("number", QCP.equals, bankAccount)});
|
|
|
+ if (EmptyUtils.isEmpty(bankAccountByn)){
|
|
|
+ errMsg.append("银行账号不存在;");
|
|
|
+ }else {
|
|
|
+ transDetail.set(BeiTransdetailConstantInfo.ACCOUNTBANK, bankAccountByn);
|
|
|
+ transDetail.set(BeiTransdetailConstantInfo.BANK, bankAccountByn.getDynamicObject("bank"));
|
|
|
+ }
|
|
|
+
|
|
|
+ * 币种ID
|
|
|
+ */
|
|
|
+ String currency = jsonObject.getString("currency");
|
|
|
+ DynamicObject currencyByn = BusinessDataServiceHelper.loadSingle("bd_currency",new QFilter[]{new QFilter("number", QCP.equals, currency)});
|
|
|
+ if (EmptyUtils.isEmpty(currencyByn)){
|
|
|
+ errMsg.append("币种不存在;");
|
|
|
+ }else {
|
|
|
+ transDetail.set(BeiTransdetailConstantInfo.CURRENCY, currencyByn);
|
|
|
+ }
|
|
|
+ String bizTimeStr = jsonObject.getString("bizTime");
|
|
|
+ Date bizTime = DateUtils.parseDateTime(bizTimeStr, "yyyy-MM-dd HH:mm:ss");
|
|
|
+ transDetail.set(BeiTransdetailConstantInfo.BIZTIME, bizTime);
|
|
|
+
|
|
|
+ String bizdateString = jsonObject.getString("bizDate");
|
|
|
+ Date bizdate = DateUtils.parseDateTime(bizdateString, "yyyy-MM-dd");
|
|
|
+ transDetail.set(BeiTransdetailConstantInfo.BIZDATE, bizdate);
|
|
|
+
|
|
|
+ transDetail.set(BeiTransdetailConstantInfo.DESCRIPTION, jsonObject.getString("description"));
|
|
|
+ transDetail.set(BeiTransdetailConstantInfo.BUSINESSBILLNUM, jsonObject.getString("name"));
|
|
|
+
|
|
|
+ transDetail.set(BeiTransdetailConstantInfo.CREDITAMOUNT, jsonObject.getBigDecimal("creditAmount"));
|
|
|
+ transDetail.set(BeiTransdetailConstantInfo.DEBITAMOUNT, jsonObject.getBigDecimal("debitAmount"));
|
|
|
+ transDetail.set(BeiTransdetailConstantInfo.TRANSBALANCE, jsonObject.getBigDecimal("transBalance"));
|
|
|
+
|
|
|
+ transDetail.set(BeiTransdetailConstantInfo.OPPUNIT, jsonObject.getString("oppUnit"));
|
|
|
+ transDetail.set(BeiTransdetailConstantInfo.OPPBANK, jsonObject.getString("oppBank"));
|
|
|
+ transDetail.set(BeiTransdetailConstantInfo.OPPBANKNUMBER, jsonObject.getString("oppBankNumber"));
|
|
|
+
|
|
|
+
|
|
|
+ * 交易流水号ID
|
|
|
+ */
|
|
|
+ transDetail.set(BeiTransdetailConstantInfo.DETAILID, jsonObject.getString("tranPackageID"));
|
|
|
+ transDetail.set(BeiTransdetailConstantInfo.BANKDETAILNO, jsonObject.getString("tranPackageID"));
|
|
|
+
|
|
|
+ transDetail.set(BeiTransdetailConstantInfo.BILLSTATUS, "C");
|
|
|
+ String receiptNo = jsonObject.getString("receiptNo");
|
|
|
+ transDetail.set(BeiTransdetailConstantInfo.RECEIPTNO, receiptNo);
|
|
|
+
|
|
|
+
|
|
|
+ * 入账状态
|
|
|
+ * 待入账=0,已入账=1,无需入账=2
|
|
|
+ */
|
|
|
+ String isReced = jsonObject.getString("isReced");
|
|
|
+ switch (isReced) {
|
|
|
+ case "0":
|
|
|
+ transDetail.set(BeiTransdetailConstantInfo.RECEREDTYPE, "0");
|
|
|
+ break;
|
|
|
+ case "1":
|
|
|
+ transDetail.set(BeiTransdetailConstantInfo.RECEREDTYPE, "3");
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ errMsg.append("入账状态不存在;");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 业务类型
|
|
|
+ * 普通 1
|
|
|
+ * 上划 2
|
|
|
+ * 下拨 3
|
|
|
+ * 内部代付 4
|
|
|
+ * 内部转账 5
|
|
|
+ * 内部扣款 6
|
|
|
+ * 贷款收回 7
|
|
|
+ * 贷款结息 8
|
|
|
+ * 活转定 9
|
|
|
+ * 定转活 10
|
|
|
+ * 供应链融资还款 11
|
|
|
+ * 联动支付 12
|
|
|
+ * 内部收款 13
|
|
|
+ * 贷款发放 14
|
|
|
+ * 存款结息 15
|
|
|
+ * 定期收益 16
|
|
|
+ */
|
|
|
+ String bizType = jsonObject.getString("bizType");
|
|
|
+ switch (bizType) {
|
|
|
+ case "1":
|
|
|
+ transDetail.set(BeiTransdetailConstantInfo.BIZTYPE, "1");
|
|
|
+ break;
|
|
|
+ case "2":
|
|
|
+ transDetail.set(BeiTransdetailConstantInfo.BIZTYPE, "2");
|
|
|
+ transDetail.set(BeiTransdetailConstantInfo.ISTRANSUP, true);
|
|
|
+ break;
|
|
|
+ case "3":
|
|
|
+ transDetail.set(BeiTransdetailConstantInfo.BIZTYPE, "3");
|
|
|
+ transDetail.set(BeiTransdetailConstantInfo.ISTRANSDOWN, true);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ errMsg.append("业务类型不存在;");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ String electricAddress = jsonObject.getString("electricAddress");
|
|
|
+
|
|
|
+ if (EmptyUtils.isNotEmpty(electricAddress)) {
|
|
|
+ DynamicObject elecreceipt = BusinessDataServiceHelper.loadSingle(BeiElecreceiptConstantInfo.ENTITYID, new QFilter[]{new QFilter("billno", QCP.equals, receiptNo)});
|
|
|
+
|
|
|
+ * 保存电子回单
|
|
|
+ */
|
|
|
+ String errStr = saveElecreceipt(transDetail, elecreceipt,electricAddress);
|
|
|
+ if (EmptyUtils.isNotEmpty(errStr)) {
|
|
|
+ errMsg.append(errStr);
|
|
|
+ }else{
|
|
|
+ transDetail.set(BeiTransdetailConstantInfo.ISMATCHERECEIPT, true);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ transDetail.set(BeiTransdetailConstantInfo.UNIQUESEQ, receiptNo);
|
|
|
+
|
|
|
+ SaveServiceHelper.save(new DynamicObject[]{transDetail});
|
|
|
+
|
|
|
+ return errMsg.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ private String saveElecreceipt( DynamicObject transDetail,DynamicObject elecreceipt,String electricAddress) {
|
|
|
+ StringBuilder errMsg = new StringBuilder();
|
|
|
+
|
|
|
+ DynamicObject elecreceiptDyn = null;
|
|
|
+ if(!EmptyUtils.isEmpty(elecreceipt)){
|
|
|
+ elecreceiptDyn = elecreceipt;
|
|
|
+ }else {
|
|
|
+
|
|
|
+ elecreceiptDyn = BusinessDataServiceHelper.newDynamicObject(BeiElecreceiptConstantInfo.ENTITYID);
|
|
|
+ long Id = DB.genLongId("t_bei_elecreceipt");
|
|
|
+ elecreceiptDyn.set("id", Id);
|
|
|
+
|
|
|
+ elecreceiptDyn.set(BeiElecreceiptConstantInfo.DETAILID, transDetail.get(BeiTransdetailConstantInfo.DETAILID));
|
|
|
+ elecreceiptDyn.set(BeiElecreceiptConstantInfo.BILLNO, transDetail.get(BeiTransdetailConstantInfo.BILLNO));
|
|
|
+ elecreceiptDyn.set(BeiElecreceiptConstantInfo.COMPANY, transDetail.get(BeiTransdetailConstantInfo.COMPANY));
|
|
|
+ elecreceiptDyn.set(BeiElecreceiptConstantInfo.ACCOUNTBANK, transDetail.get(BeiTransdetailConstantInfo.ACCOUNTBANK));
|
|
|
+ elecreceiptDyn.set(BeiElecreceiptConstantInfo.CURRENCY, transDetail.get(BeiTransdetailConstantInfo.CURRENCY));
|
|
|
+ elecreceiptDyn.set(BeiElecreceiptConstantInfo.BIZDATE, transDetail.get(BeiTransdetailConstantInfo.BIZDATE));
|
|
|
+ elecreceiptDyn.set(BeiElecreceiptConstantInfo.BIZTYPE, transDetail.get(BeiTransdetailConstantInfo.BIZTYPE));
|
|
|
+ elecreceiptDyn.set(BeiElecreceiptConstantInfo.DETAILDATETIME, transDetail.get(BeiTransdetailConstantInfo.BIZTIME));
|
|
|
+ elecreceiptDyn.set(BeiElecreceiptConstantInfo.DESCRIPTION, transDetail.get(BeiTransdetailConstantInfo.DESCRIPTION));
|
|
|
+ elecreceiptDyn.set(BeiElecreceiptConstantInfo.DEBITAMOUNT, transDetail.get(BeiTransdetailConstantInfo.DEBITAMOUNT));
|
|
|
+ elecreceiptDyn.set(BeiElecreceiptConstantInfo.CREDITAMOUNT, transDetail.get(BeiTransdetailConstantInfo.CREDITAMOUNT));
|
|
|
+ elecreceiptDyn.set(BeiElecreceiptConstantInfo.RECEIPTNO, transDetail.get(BeiTransdetailConstantInfo.RECEIPTNO));
|
|
|
+ if(transDetail.getBigDecimal(BeiTransdetailConstantInfo.DEBITAMOUNT).compareTo(BigDecimal.ZERO)>0){
|
|
|
+ elecreceiptDyn.set(BeiElecreceiptConstantInfo.AMOUNT, transDetail.get(BeiTransdetailConstantInfo.DEBITAMOUNT));
|
|
|
+ elecreceiptDyn.set(BeiElecreceiptConstantInfo.CREDITDEBITFLAG, "1");
|
|
|
+ }else{
|
|
|
+ elecreceiptDyn.set(BeiElecreceiptConstantInfo.AMOUNT, transDetail.get(BeiTransdetailConstantInfo.CREDITAMOUNT));
|
|
|
+ elecreceiptDyn.set(BeiElecreceiptConstantInfo.CREDITDEBITFLAG, "2");
|
|
|
+ }
|
|
|
+ elecreceiptDyn.set(BeiElecreceiptConstantInfo.OPPUNIT, transDetail.get(BeiTransdetailConstantInfo.OPPUNIT));
|
|
|
+ elecreceiptDyn.set(BeiElecreceiptConstantInfo.OPPBANK, transDetail.get(BeiTransdetailConstantInfo.OPPBANK));
|
|
|
+ elecreceiptDyn.set(BeiElecreceiptConstantInfo.OPPBANKNUMBER, transDetail.get(BeiTransdetailConstantInfo.OPPBANKNUMBER));
|
|
|
+ elecreceiptDyn.set(BeiElecreceiptConstantInfo.BILLSTATUS, transDetail.get(BeiTransdetailConstantInfo.BILLSTATUS));
|
|
|
+
|
|
|
+ DynamicObjectCollection entrys = elecreceiptDyn.getDynamicObjectCollection(BeiElecreceiptConstantInfo.MATCHDETAILENTRY);
|
|
|
+ DynamicObject entry = entrys.addNew();
|
|
|
+ entry.set("e_transdetailid",transDetail.getPkValue());
|
|
|
+
|
|
|
+
|
|
|
+ DynamicObjectCollection entrys1 = transDetail.getDynamicObjectCollection(BeiTransdetailConstantInfo.MATCHRECEIPTENTRY);
|
|
|
+ if(entrys1.size()<=0) {
|
|
|
+ DynamicObject entry1 = entrys1.addNew();
|
|
|
+ entry1.set("e_receiptid", Id);
|
|
|
+ entry1.set("e_receiptno", transDetail.get(BeiTransdetailConstantInfo.RECEIPTNO));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 地址格式:address="ftp:\\\\172.16.3.232\\Files\\12Qwee.pdf";
|
|
|
+ * 格式 :ftp:
|
|
|
+ */
|
|
|
+ String address = electricAddress;
|
|
|
+ String filename = extractFilename(address);
|
|
|
+ elecreceiptDyn.set(BeiElecreceiptConstantInfo.UPLOADFILENAME,filename);
|
|
|
+
|
|
|
+ address=address.split("Files")[1];
|
|
|
+ address=address.replace("\\", "/");
|
|
|
+ address="/Files"+address;
|
|
|
+ address=address.replace("//", "/");
|
|
|
+ elecreceiptDyn.set(BeiElecreceiptConstantInfo.FILEPATH,address);
|
|
|
+
|
|
|
+
|
|
|
+ * 处理文件上传
|
|
|
+ */
|
|
|
+
|
|
|
+ elecreceiptDyn.set(BeiElecreceiptConstantInfo.FILEFLAG, "1");
|
|
|
+
|
|
|
+ SaveServiceHelper.save(new DynamicObject[]{elecreceiptDyn});
|
|
|
+
|
|
|
+ return errMsg.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String extractFilename(String address) {
|
|
|
+
|
|
|
+ int lastSlashIndex = address.lastIndexOf('/');
|
|
|
+ if (lastSlashIndex == -1) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ return address.substring(lastSlashIndex + 1);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|