13246659623 7 kuukautta sitten
vanhempi
säilyke
b8e5ce06b1

+ 105 - 3
src/main/java/fi/cas/opplugin/PayBillToolUtil.java

@@ -33,6 +33,44 @@ public class PayBillToolUtil {
     public static final String ENTITY_NAME = "cas_paybill";
     protected static final Log log = LogFactory.getLog(PayBillToolUtil.class);
 
+    public static String queryPaymentRequest(DynamicObject payBillEntity) {
+        try {
+            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
+            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
+            Document doc = dBuilder.newDocument();
+
+            Element rootElement = doc.createElement("Message");
+            doc.appendChild(rootElement);
+
+            Element body = doc.createElement("Body");
+            rootElement.appendChild(body);
+
+
+            createElement(doc, body, "transcode", "BTSQO001");
+            createElement(doc, body, "ochannelcode", "JF");//发起渠道
+            createElement(doc, body, "ochanneldate", payBillEntity.getString("nckd_fqqdrq"));//发起渠道日期
+
+            String channelserno = payBillEntity.get("billno")+"-"+payBillEntity.getInt("nckd_bbh");
+            createElement(doc, body, "ochannelserno", channelserno);//发起渠道流水
+            TransformerFactory transformerFactory = TransformerFactory.newInstance();
+            Transformer transformer = transformerFactory.newTransformer();
+
+            // 指定编码格式为GBK
+            transformer.setOutputProperty(OutputKeys.ENCODING, "GBK");
+            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+
+
+            DOMSource source = new DOMSource(doc);
+            StringWriter writer = new StringWriter();
+            StreamResult result = new StreamResult(writer);
+            transformer.transform(source, result);
+
+            return writer.toString();
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
     public static String createSinglePaymentRequest(DynamicObject payBillEntity) {
         try {
             DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
@@ -47,8 +85,8 @@ public class PayBillToolUtil {
 
 
             createElement(doc, body, "transcode", "BTSCO001");
-            createElement(doc, body, "trxcode", "jfgx");//渠道交易代码
-            createElement(doc, body, "channelcode", "经费共享");//发起渠道
+            createElement(doc, body, "trxcode", "JF01");//渠道交易代码
+            createElement(doc, body, "channelcode", "JF");//发起渠道
             Calendar currentdate = Calendar.getInstance();
             createElement(doc, body, "channeldate", TypeUtils.date2String(currentdate.getTime(),"yyyyMMdd"));//发起渠道日期
 
@@ -188,7 +226,7 @@ public class PayBillToolUtil {
                 errMsg.append("错误号:").append("XXXXXXX");
                 errMsg.append(",错误原因:").append("接口无法连通,未获取到返回结果");
                 errMsg.append("\r\n");
-            }else if(cbsReturnJson.getJSONObject("Message")==null){
+            }else if(cbsReturnJson.get("Message")==null){
                 isSuccess = false;
                 errMsg.append("单据号:").append(billNum).append(",推送支付前置失败,");
                 errMsg.append("错误号:").append("DDDDDD1");
@@ -266,6 +304,34 @@ public class PayBillToolUtil {
         }
 
 
+    }
+
+
+    public static void saveupdatelog(DynamicObject payBillEntity,String qqbw,String fhbw){
+        try {
+            DynamicObject logInfo = new DynamicObject( EntityMetadataCache.getDataEntityType("nckd_zfcxjkrz"));
+            String channelserno = payBillEntity.get("billno")+"-"+payBillEntity.getInt("nckd_bbh");
+            logInfo.set("number",channelserno);
+            logInfo.set("name",payBillEntity.get("billno")+"查询状态日志");
+            logInfo.set("status","A");
+            logInfo.set("enable","1");
+            Calendar currentdate = Calendar.getInstance();
+            logInfo.set("nckd_redate",currentdate.getTime());
+            logInfo.set("nckd_billno",payBillEntity.get("billno"));
+            logInfo.set("nckd_payid",payBillEntity.getPkValue()+"");
+            logInfo.set("nckd_qqbw_tag",qqbw);
+            logInfo.set("nckd_fhbw_tag",fhbw);
+            logInfo.set("nckd_redate",new Date());
+
+            logInfo.set("nckd_djlx","1");
+            OperationServiceHelper.executeOperate("save","nckd_zfcxjkrz",new DynamicObject[]{logInfo});
+
+        }catch (Exception e){
+            log.info("保存日志报错"+e.getMessage());
+
+        }
+
+
     }
 
     public static JSONObject socketService(String serverName,String port,String xmlData){
@@ -302,4 +368,40 @@ public class PayBillToolUtil {
         return null;
     }
 
+
+
+    public static JSONObject socketServiceQuery(String serverName,String port,String xmlData,String transcode){
+        try {
+            Socket client = new Socket(serverName,TypeUtils.nullToInt(port));
+            int messageLength = xmlData.getBytes("GBK").length;
+            String header = String.format("%08dXML"+transcode+"%%%%%%%%%%%%%%%%%%%%%%%%%%", messageLength);
+            String fullMessage = header + xmlData;
+            OutputStream outToServer = client.getOutputStream();
+
+            PrintWriter out = new PrintWriter(new OutputStreamWriter(outToServer, "GBK"), true);
+            out.println(fullMessage);
+
+            InputStream inFromServer = client.getInputStream();
+            BufferedReader in = new BufferedReader(new InputStreamReader(inFromServer, "GBK"));
+            StringBuilder responseBuilder = new StringBuilder();
+            String line;
+            while ((line = in.readLine()) != null) {
+                responseBuilder.append(line);
+            }
+            String responseJson = responseBuilder.toString();
+            if(responseJson.indexOf("<?xml")>0){
+                int index = responseJson.indexOf("<?xml");
+                responseJson = responseJson.substring(index);
+            }
+
+            JSONObject jsonObject = XML.toJSONObject(responseJson);
+            client.close();
+            return  jsonObject;
+        } catch (IOException e) {
+            e.printStackTrace();
+            log.info(e.getMessage());
+        }
+        return null;
+    }
+
 }

+ 0 - 48
src/main/java/fi/cas/opplugin/PayQueryOP.java

@@ -1,48 +0,0 @@
-package fi.cas.opplugin;
-
-import com.alibaba.druid.util.StringUtils;
-import kd.bos.dataentity.entity.DynamicObject;
-import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
-import kd.bos.entity.plugin.AddValidatorsEventArgs;
-import kd.bos.entity.plugin.args.AfterOperationArgs;
-import kd.bos.entity.plugin.args.BeforeOperationArgs;
-
-
-public class PayQueryOP extends AbstractOperationServicePlugIn {
-    private static final String ENTITY_NAME = "cas_paybill";
-
-    @Override
-    public void onAddValidators(AddValidatorsEventArgs e) {
-        super.onAddValidators(e);
-
-
-    }
-
-    @Override
-    public void beforeExecuteOperationTransaction(BeforeOperationArgs e) {
-
-        String errMsg = "";
-
-        //获取选中行
-        DynamicObject[] billEntities = e.getDataEntities();
-
-        //获取操作按钮操作编码
-        String operationKey = e.getOperationKey();
-        if (StringUtils.equals( "paytoqianzhi",operationKey)){
-            errMsg =  PayBillToolUtil.payBillForCBSSync(billEntities);
-        }
-        if(!errMsg.isEmpty()) {
-            ////将错误信息返回到前端
-            e.setCancelMessage(errMsg);
-            e.setCancel(true);
-            System.out.println("PayToZFQZOP 错误信息:" + errMsg.toString());
-        }
-    }
-
-
-    @Override
-    public void afterExecuteOperationTransaction(AfterOperationArgs e) {
-        super.afterExecuteOperationTransaction(e);
-
-    }
-}

+ 16 - 0
src/main/java/fi/cas/opplugin/PayToZFQZOP.java

@@ -6,6 +6,8 @@ import kd.bos.entity.plugin.AddValidatorsEventArgs;
 import kd.bos.entity.plugin.args.AfterOperationArgs;
 import kd.bos.entity.plugin.args.BeforeOperationArgs;
 import com.alibaba.druid.util.StringUtils;
+import kd.bos.servicehelper.BusinessDataServiceHelper;
+import kd.bos.servicehelper.operation.SaveServiceHelper;
 
 
 public class PayToZFQZOP  extends AbstractOperationServicePlugIn {
@@ -28,6 +30,20 @@ public class PayToZFQZOP  extends AbstractOperationServicePlugIn {
         String operationKey = e.getOperationKey();
         //获取操作按钮操作编码
         if (StringUtils.equals( "paytoqianzhi",operationKey)){
+            for (DynamicObject dataEntity : billEntities) {
+                DynamicObject payBillEntity = BusinessDataServiceHelper.loadSingle(dataEntity.getPkValue(), ENTITY_NAME);
+
+                String paystatus = payBillEntity.getString("nckd_paystatus");
+                int bbh = payBillEntity.getInt("nckd_bbh");
+                int fkcs = payBillEntity.getInt("nckd_fkcs");
+                String billstatusString = payBillEntity.getString("billstatus");
+                if ("C".equals(billstatusString)&&"4".equals(paystatus)&&bbh>=1 && bbh!=fkcs-1) {
+                    //状态为已审批,支付状态为失败,版本号>1,版本号=付款次数-1。符合付款条件,修改状态和版本号先
+                    payBillEntity.set("nckd_paystatus", "1");//支付状态改回未支付
+                    payBillEntity.set("nckd_bbh",bbh+1);
+                    SaveServiceHelper.update(payBillEntity);
+                }
+            }
             errMsg =  PayBillToolUtil.payBillForCBSSync(billEntities);
         }
         if(!errMsg.isEmpty()) {

+ 0 - 78
src/main/java/fi/cas/opplugin/RePayToZFQZOP.java

@@ -1,78 +0,0 @@
-package fi.cas.opplugin;
-
-import com.alibaba.druid.util.StringUtils;
-import kd.bos.dataentity.entity.DynamicObject;
-import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
-import kd.bos.entity.plugin.args.AfterOperationArgs;
-import kd.bos.entity.plugin.args.BeforeOperationArgs;
-import kd.bos.servicehelper.BusinessDataServiceHelper;
-import kd.bos.servicehelper.operation.SaveServiceHelper;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class RePayToZFQZOP  extends AbstractOperationServicePlugIn {
-
-
-    public String repay(DynamicObject[] billEntities) {
-        StringBuffer errMsg = new StringBuffer();
-
-        List<DynamicObject> cflist = new ArrayList<>();
-
-        for (DynamicObject dataEntity : billEntities) {
-            DynamicObject payBillEntity = BusinessDataServiceHelper.loadSingle(dataEntity.getPkValue(), "cas_paybill");
-
-            boolean isZFQZ = true;
-            String billNum = payBillEntity.getString("billno");
-            String billstatusString = payBillEntity.getString("billstatus");
-            String paystatus = payBillEntity.getString("nckd_paystatus");
-            int bbh = payBillEntity.getInt("nckd_bbh");
-            int fkcs = payBillEntity.getInt("nckd_fkcs");
-
-            if (!"C".equals(billstatusString)) {
-                errMsg.append("单据号:").append(billNum).append(",付款单为审核状态,才能重付~\r\n");
-                isZFQZ = false;
-            }
-            if (!"4".equals(paystatus) && !"".equals(paystatus)) {
-                errMsg.append("单据号:").append(billNum).append(",付款单为支付失败,才能重付~\r\n");
-                isZFQZ = false;
-            }
-            if(bbh>=1 && bbh!=fkcs-1){
-                errMsg.append("单据号:").append(billNum).append(",该版本号"+bbh+"为最新版本,无需重付~\r\n");
-                isZFQZ = false;
-            }
-            //可以重复,修改付款状态及bbh
-            if(isZFQZ){
-                payBillEntity.set("nckd_paystatus", "1");//支付状态改回未支付
-                payBillEntity.set("nckd_bbh",bbh+1);
-                SaveServiceHelper.update(payBillEntity);
-                cflist.add(dataEntity);
-            }
-        }
-        if(cflist.size()>0){
-            errMsg.append(PayBillToolUtil.payBillForCBSSync(cflist.toArray(new DynamicObject[]{})));
-        }
-        return errMsg.toString();
-    }
-
-    @Override
-    public void beforeExecuteOperationTransaction(BeforeOperationArgs e) {
-
-        String errMsg = "";
-
-        //获取选中行
-        DynamicObject[] billEntities = e.getDataEntities();
-        //获取操作按钮操作编码
-        String operationKey = e.getOperationKey();
-        if(StringUtils.equals( "repaytoZFQZ",operationKey)){
-            //重付,版本号加一,支付状态改
-            errMsg = repay(billEntities);
-        }
-        if(!errMsg.isEmpty()) {
-            ////将错误信息返回到前端
-            e.setCancelMessage(errMsg);
-            e.setCancel(true);
-            System.out.println("PayToZFQZOP 错误信息:" + errMsg.toString());
-        }
-    }
-}

+ 73 - 0
src/main/java/fi/cas/task/PayQueryStatusTast.java

@@ -0,0 +1,73 @@
+package fi.cas.task;
+
+import com.alibaba.druid.support.logging.Log;
+import com.alibaba.druid.support.logging.LogFactory;
+import fi.cas.opplugin.PayBillToolUtil;
+import kd.bos.context.RequestContext;
+import kd.bos.dataentity.entity.DynamicObject;
+import kd.bos.exception.KDException;
+import kd.bos.orm.query.QCP;
+import kd.bos.orm.query.QFilter;
+import kd.bos.schedule.executor.AbstractTask;
+import kd.bos.servicehelper.BusinessDataServiceHelper;
+import kd.bos.servicehelper.operation.SaveServiceHelper;
+import org.json.JSONObject;
+
+import java.util.Map;
+
+public class PayQueryStatusTast extends AbstractTask {
+    private static final Log log = LogFactory.getLog(PayQueryStatusTast.class);
+    @Override
+    public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {
+        //获取要查询的数据。状态为已审批,支付状态为支付中。
+        QFilter filter = new QFilter("billstatus", QCP.equals, "C");
+        filter.and("nckd_paystatus", QCP.equals, "2");
+        filter.and("nckd_fkcs", QCP.large_than, 0);
+        DynamicObject[] payinfos = BusinessDataServiceHelper.load("cas_paybill","billno,billstatus,nckd_paystatus,nckd_sbyy,nckd_fqqdrq,nckd_fkcs,nckd_bbh", new QFilter[] {filter});
+        DynamicObject jkpzxx = BusinessDataServiceHelper.loadSingle("nckd_jkpzxx",new QFilter[]{new QFilter("number","=","paytozfqz")});
+        String servername =  jkpzxx.getString("nckd_servername");
+        String port =  jkpzxx.getString("nckd_port");
+
+        for (DynamicObject dataEntity : payinfos) {
+            //调用接口查询付款状态
+            String bodyxml = PayBillToolUtil.queryPaymentRequest(dataEntity);
+            String billNum = dataEntity.getString("billno");
+            log.info("单据号:"+billNum+"传入参数"+bodyxml);
+            JSONObject cbsReturnJson =PayBillToolUtil.socketServiceQuery(servername,port,bodyxml,"BTSQO001");
+            log.info("单据号:"+billNum+"返回参数"+cbsReturnJson.toString());
+            if(cbsReturnJson==null||cbsReturnJson.get("Message")==null){
+            }else{
+                JSONObject bodyinfo = cbsReturnJson.getJSONObject("Message").getJSONObject("Body");
+                if(bodyinfo!=null){
+                    String errcode =bodyinfo.getString("errorcode");
+                    boolean isupdate = false;
+                    if ("FIN0000".equals(errcode)) {//已查询到,不代表支付成功
+                        String zfstatus = bodyinfo.getString("status");
+                        String errormsg =bodyinfo.getString("errormsg");
+                        if("U".equals(zfstatus)){//在途
+                            //判断原因是否有变化
+                           String sbyy =  dataEntity.getString("nckd_sbyy");
+                           if(errormsg!=null&&errormsg.equals(sbyy)){//相等
+                           }else{
+                               dataEntity.set("nckd_sbyy",errormsg);//错误信息更新
+                               isupdate = true;
+                           }
+                        }else if("S".equals(zfstatus)){//成功
+                            dataEntity.set("nckd_paystatus",3);
+                            dataEntity.set("nckd_sbyy",errormsg);//错误信息更新
+                            isupdate = true;
+                        }else if("F".equals(zfstatus)){//失败
+                            dataEntity.set("nckd_paystatus",4);//支付失败
+                            dataEntity.set("nckd_sbyy",errormsg);//错误信息更新
+                            isupdate = true;
+                        }
+                        if(isupdate){
+                            SaveServiceHelper.update(new DynamicObject[]{dataEntity});
+                            PayBillToolUtil.saveupdatelog(dataEntity,bodyxml,cbsReturnJson.toString());
+                        }
+                    }
+                }
+            }
+        }
+    }
+}

+ 29 - 0
src/main/java/fi/cas/task/PayUpadteStatusTask.java

@@ -0,0 +1,29 @@
+package fi.cas.task;
+
+import com.alibaba.druid.support.logging.Log;
+import com.alibaba.druid.support.logging.LogFactory;
+import kd.bos.context.RequestContext;
+import kd.bos.dataentity.entity.DynamicObject;
+import kd.bos.exception.KDException;
+import kd.bos.orm.query.QCP;
+import kd.bos.orm.query.QFilter;
+import kd.bos.schedule.executor.AbstractTask;
+import kd.bos.servicehelper.BusinessDataServiceHelper;
+import kd.bos.servicehelper.operation.SaveServiceHelper;
+
+import java.util.Map;
+
+public class PayUpadteStatusTask  extends AbstractTask {
+    private static final Log log = LogFactory.getLog(PayUpadteStatusTask.class);
+    public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {
+        //获取要查询的数据。状态为已审批,支付状态为支付成功。
+        QFilter filter = new QFilter("billstatus", QCP.equals, "C");
+        filter.and("nckd_paystatus", QCP.equals, 3);
+        filter.and("nckd_fkcs", QCP.large_than, 0);
+        DynamicObject[] payinfos = BusinessDataServiceHelper.load("cas_paybill","billno,billstatus,nckd_paystatus,nckd_sbyy,nckd_fqqdrq,nckd_fkcs,nckd_bbh", new QFilter[] {filter});
+        for (DynamicObject dataEntity : payinfos) {
+            dataEntity.set("billstatus","D");
+        }
+        SaveServiceHelper.save(payinfos);
+    }
+}