到账通知发布-推送按钮和收票登记-到账通知推送按钮
This commit is contained in:
		
							parent
							
								
									f1ddc2ea01
								
							
						
					
					
						commit
						3db0b46ead
					
				|  | @ -0,0 +1,431 @@ | |||
| package nccloud.web.cmp.informer.informer.action; | ||||
| 
 | ||||
| import com.alibaba.fastjson.JSON; | ||||
| import com.alibaba.fastjson.JSONArray; | ||||
| import nc.bs.logging.Logger; | ||||
| import nc.itf.uap.IUAPQueryBS; | ||||
| import nc.jdbc.framework.JdbcSession; | ||||
| import nc.jdbc.framework.PersistenceManager; | ||||
| import nc.jdbc.framework.exception.DbException; | ||||
| import nc.jdbc.framework.processor.MapListProcessor; | ||||
| import nc.jdbc.framework.processor.MapProcessor; | ||||
| import nccloud.framework.service.ServiceLocator; | ||||
| import nccloud.framework.web.action.itf.ICommonAction; | ||||
| import nccloud.framework.web.container.IRequest; | ||||
| import nccloud.web.cmp.informer.action.InformerAction; | ||||
| import org.apache.commons.codec.binary.Base64; | ||||
| 
 | ||||
| import javax.crypto.Mac; | ||||
| import javax.crypto.spec.SecretKeySpec; | ||||
| import javax.net.ssl.HttpsURLConnection; | ||||
| import javax.net.ssl.SSLContext; | ||||
| import javax.net.ssl.TrustManager; | ||||
| import javax.net.ssl.X509TrustManager; | ||||
| import java.io.*; | ||||
| import java.net.HttpURLConnection; | ||||
| import java.net.URL; | ||||
| import java.net.URLEncoder; | ||||
| import java.nio.charset.StandardCharsets; | ||||
| import java.security.InvalidKeyException; | ||||
| import java.security.NoSuchAlgorithmException; | ||||
| import java.security.SecureRandom; | ||||
| import java.security.cert.X509Certificate; | ||||
| import java.sql.Connection; | ||||
| import java.sql.SQLException; | ||||
| import java.util.*; | ||||
| 
 | ||||
| public class myBtnClickAction extends InformerAction implements ICommonAction { | ||||
| 
 | ||||
|     @Override | ||||
|     public Object doAction(IRequest request) { | ||||
| 
 | ||||
| 
 | ||||
|         // 初始化结果映射,用于存储处理结果 | ||||
|         HashMap<String, String> resultMap  =  new HashMap<String, String>(); | ||||
|         // 读取请求中的JSON数据 | ||||
| 
 | ||||
|         String json = request.read(); | ||||
|         Map<String, Object> maps = JSON.parseObject(json, Map.class); | ||||
|         if (maps.get("pks") == null  ){ | ||||
|             resultMap.put("result", "请选择行"); | ||||
|             return resultMap; | ||||
|         } | ||||
|         JSONArray jsonArray = (JSONArray) maps.get("pks"); | ||||
|         ArrayList<Object> pks = new ArrayList<>(Arrays.asList(jsonArray.toArray())); | ||||
| 
 | ||||
| // 使用 String.join 进行字符串拼接 | ||||
|         String result = ""; | ||||
|         StringBuilder sb = new StringBuilder(); | ||||
|         if (pks.size() > 1) { | ||||
|             for (int i = 0; i < pks.size(); i++) { | ||||
|                 sb.append("'").append(pks.get(i)).append("'"); | ||||
|                 if (i < pks.size() - 1) { | ||||
|                     sb.append(","); | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             result = sb.toString(); | ||||
|         }else { | ||||
|             result= "'"+(String) pks.get(0)+"'"; | ||||
| 
 | ||||
|         } | ||||
|         System.out.println(result); | ||||
|         // 解析JSON数据为JSONObject对象 | ||||
|         // 从JSON对象中提取账单编号 | ||||
|         System.out.println(json); | ||||
|         String urlpath; | ||||
|         String appKey ; | ||||
|         String appSecret ; | ||||
|         String tenant ; | ||||
| 
 | ||||
|         // 如果账单编号为空,则返回失败结果 | ||||
| 
 | ||||
|         try { | ||||
|             String urlsql="select code,name from bd_defdoc  where  code='baseUrl'"; | ||||
|             String appksql="select code,name from bd_defdoc  where  code='appKey'"; | ||||
|             String uappssql="select code,name from bd_defdoc  where  code='appSecret'"; | ||||
|             String tenantsql="select code,name from bd_defdoc  where  code='tenant'"; | ||||
| 
 | ||||
|             Map<String, Object> urls = (Map<String, Object>) getQueryService().executeQuery(urlsql, new MapProcessor()); | ||||
|             Map<String, Object>appks = (Map<String, Object>) getQueryService().executeQuery(appksql, new MapProcessor()); | ||||
|             Map<String, Object> appses = (Map<String, Object>) getQueryService().executeQuery(uappssql, new MapProcessor()); | ||||
|             Map<String, Object> tenants = (Map<String, Object>) getQueryService().executeQuery(tenantsql, new MapProcessor()); | ||||
| 
 | ||||
|             if (urls.get("code") != null) { | ||||
|                 urlpath = (String) urls.get("name"); | ||||
|             } else { | ||||
|                 resultMap.put("result", "未配置url"); | ||||
|                 return resultMap; | ||||
|             } | ||||
|             if (appks.get("code") != null) { | ||||
|                 appKey = (String) appks.get("name"); | ||||
|             } else { | ||||
|                 resultMap.put("result", "未配置appKey"); | ||||
|                 return resultMap; | ||||
|             } | ||||
|             if (appses.get("code") != null) { | ||||
|                 appSecret = (String) appses.get("name"); | ||||
|             } else { | ||||
|                 resultMap.put("result", "未配置appSecret"); | ||||
|                 return resultMap; | ||||
|             } | ||||
|             if (tenants.get("code") != null) { | ||||
|                 tenant = (String) tenants.get("name"); | ||||
|             } else { | ||||
|                 resultMap.put("result", "未配置tenant"); | ||||
|                 return resultMap;            } | ||||
|             long timestampMillis = System.currentTimeMillis(); | ||||
|             System.out.println("当前时间戳(毫秒):" + timestampMillis); | ||||
|             String dai = "appKey" + appKey + "timestamp" + timestampMillis; | ||||
|             String signature = calculateHmacSHA256(dai, appSecret); | ||||
|             SSLUtilities sas= new SSLUtilities() ; | ||||
|             sas.disableCertificateValidation(); | ||||
| 
 | ||||
|             String urlstr = "appKey=" + appKey + "×tamp=" + timestampMillis + "&signature="+signature; | ||||
|             URL url = new URL(urlpath+"/iuap-api-auth/open-auth/selfAppAuth/getAccessToken?" + urlstr); | ||||
|             // 打开连接 | ||||
|             HttpURLConnection con = (HttpURLConnection) url.openConnection(); | ||||
| 
 | ||||
|             // 设置请求方法为 GET | ||||
|             con.setRequestMethod("GET"); | ||||
| 
 | ||||
| 
 | ||||
|             // 获取响应代码 | ||||
|             BufferedReader ins = new BufferedReader(new InputStreamReader(con.getInputStream())); | ||||
|             String inputLine; | ||||
|             StringBuilder response = new StringBuilder(); | ||||
| 
 | ||||
|             while ((inputLine = ins.readLine()) != null) { | ||||
|                 response.append(inputLine); | ||||
|             } | ||||
| 
 | ||||
|             System.out.println(response); | ||||
|             System.out.println(response); | ||||
| 
 | ||||
|             String jsonString = response.toString(); | ||||
|             Map<String, Object> map = JSON.parseObject(jsonString, Map.class); | ||||
|             System.out.println(map); | ||||
| 
 | ||||
|             System.out.println(url); | ||||
| 
 | ||||
|             // 获取当前年份 | ||||
|             String sql = " select bz.code as nzcode,jstype.code as pk_balatype,ban.code bancode,ban.name as banname,bankname,bank.accnum as  accnum,infodate,CASE direction " + | ||||
|                     "WHEN 'paymoney'  THEN '付款' " + | ||||
|                     "WHEN 'receivemoney'  THEN '收款' " + | ||||
|                     "ELSE '不存在' " + | ||||
|                     "END as direction, 'CNY' as currencyCode,moneyy , bant.code as  dfcode,bant.name as dfname,oppbankaccount,bankt.accnum dfaccnum " + | ||||
|                     ",pk_oppunit,org.code as orgcode,org.name as orgname,cmp.pk_informer " + | ||||
|                     ",cmp.memo,cmp.transerial,df.name as  ksmc,df.code as  ksbm,cmp.note_no,def01,cmp.oppunitname " + | ||||
|                     "from cmp_informer cmp " + | ||||
|                     "left join bd_bankaccbas bank on cmp.pk_bankacc=bank.pk_bankaccbas " + | ||||
|                     "left join bd_bankdoc ban on cmp.pk_bank=ban.pk_bankdoc " + | ||||
|                     "left join bd_bankdoc bant on cmp.pk_oppbank=bant.pk_bankdoc " + | ||||
|                     "left join bd_bankaccbas bankt on cmp.pk_oppacc=bankt.pk_bankaccbas " + | ||||
|                     "left join bd_cust_supplier df  on cmp.pk_oppunit=df.pk_cust_sup " + | ||||
|                     "left join org_financeorg org on cmp.pk_org = org.pk_financeorg " + | ||||
|                     "left join bd_balatype jstype on jstype.pk_balatype =cmp.pk_balatype "+ | ||||
|                     "left join bd_currtype bz on cmp.pk_currtype=bz.pk_currtype"+ | ||||
|                     " where  cmp.pk_informer in("+result+") "; | ||||
|             List<Map<String, String>> results = (List<Map<String, String>>) getQueryService().executeQuery(sql, new MapListProcessor()); | ||||
| 
 | ||||
|             ArrayList lists= new ArrayList(); | ||||
|             for (int i = 0; i < results.size(); i++) { | ||||
|                 Map vmao = new HashMap(); | ||||
|                 Map<String, String> row = results.get(i); | ||||
|                 String def01 = (String) row.get("def01"); | ||||
|                 if ("已推送".equals(def01)) { | ||||
|                     resultMap.put("flag", "false"); | ||||
|                     resultMap.put("message", "已推送无法再次推送"); | ||||
|                     return resultMap; | ||||
|                 } | ||||
|                 if ("撤回".equals(def01)){ | ||||
|                     vmao.put("publishStatus", "再次发布"); | ||||
|                 }else { | ||||
|                     vmao.put("publishStatus", ""); | ||||
| 
 | ||||
|                 } | ||||
|                 String pjlsh; | ||||
|                 if (row.get("transerial") != null){ | ||||
|                     pjlsh=row.get("transerial").toString(); | ||||
|                 }else if (row.get("note_no") != null){ | ||||
|                     pjlsh=row.get("note_no").toString(); | ||||
|                 }else { | ||||
|                     resultMap.put("flag", "false"); | ||||
|                     resultMap.put("message", "票据与流水号不可同时为空"); | ||||
|                     return resultMap; | ||||
|                 } | ||||
| 
 | ||||
| 
 | ||||
|                 vmao.put("accountName", row.get("bancode")); | ||||
|                 vmao.put("bankNum",row.get("accnum")); | ||||
|                 vmao.put("transactionDate", row.get("infodate")); | ||||
|                 vmao.put("paymentReceiptStatus", row.get("direction")); | ||||
|                 vmao.put("currencyCode", row.get("nzcode") ); | ||||
|                 vmao.put("transactionAmount", row.get("moneyy") ); | ||||
|                 vmao.put("pendingClaimAmount",0); | ||||
|                 vmao.put("oppAccount", row.get("oppbankaccount")); | ||||
|                 vmao.put("oppAccountName", row.get("oppunitname")); | ||||
|                 vmao.put("oppBank",row.get("dfcode")); | ||||
|                 vmao.put("oppBankName",row.get("dfname")); | ||||
|                 vmao.put("description", row.get("memo")); | ||||
|                 vmao.put("bankTransactionNumber", pjlsh); | ||||
|                 vmao.put("accountType","默认类型"); | ||||
|                 vmao.put("orgCode",row.get("orgcode")); | ||||
|                 vmao.put("billNumber",row.get("note_no")); | ||||
| 
 | ||||
|                 if (row.get("pk_balatype") != null && row.get("pk_balatype") != "" && row.get("pk_balatype") != "~"){ | ||||
|                     vmao.put("paymentMethod",row.get("pk_balatype")); | ||||
|                 }else { | ||||
|                     vmao.put("paymentMethod","10"); | ||||
|                 } | ||||
|                 vmao.put("sourceId",row.get("pk_informer")); | ||||
|                 lists.add(vmao); | ||||
|             } | ||||
| 
 | ||||
|             //lists转json | ||||
|             String jsonString1 = JSON.toJSONString(lists); | ||||
|             Map access_token=(Map)map.get("data"); | ||||
|             String urls2=urlpath+"/iuap-api-gateway/"+tenant+"/current_yonbip_default_sys/KKAPI/paymentNotice/addBatch?access_token="+access_token.get("access_token"); | ||||
|             Map mapjson = httpFW(urls2,jsonString1); | ||||
|             Map datas= (Map) mapjson.get("data"); | ||||
|             JSONArray faijsonist = (JSONArray) datas.get("failData"); | ||||
| 
 | ||||
|             String message1= (String) mapjson.get("message"); | ||||
|             JSONArray jsonist = (JSONArray) datas.get("successData"); | ||||
|             // 将JSONArray转换为List<String> | ||||
|             ArrayList<String> successData = null; | ||||
|             ArrayList<String> failData = null; | ||||
| 
 | ||||
|             if (jsonist != null) { | ||||
|                 successData = (ArrayList<String>) jsonist.toJavaList(String.class); | ||||
| 
 | ||||
|             } | ||||
|             if (faijsonist != null){ | ||||
|                 failData = (ArrayList<String>) faijsonist.toJavaList(String.class); | ||||
|             } | ||||
|             ArrayList sqlStr = new ArrayList<>(); | ||||
|             for (int i = 0; i < pks.size(); i++) { | ||||
|                 String pk_s= (String) pks.get(i); | ||||
|                 String sql1; | ||||
|                 if (successData!=null&&successData.contains(pk_s)) { | ||||
|                     sql1="update cmp_informer set def01='已推送' where pk_informer='"+pk_s+"'"; | ||||
|                     sqlStr.add(sql1); | ||||
|                 } else { | ||||
|                     sql1="update cmp_informer set def01='推送失败' where pk_informer='"+pk_s+"'"; | ||||
|                 } | ||||
|                 sqlStr.add(sql1); | ||||
| 
 | ||||
|             } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|             int succState = executeUpdate(sqlStr); | ||||
|             String message= datas.get("successData")+"成功" + message1+",失败:"+failData; | ||||
|             resultMap.put("flag", "true"); | ||||
|             resultMap.put("message", message); | ||||
|             // 调用服务工具类的deletePrcplInterest方法,尝试删除利息计划 | ||||
|             System.out.println("year"+mapjson); | ||||
|             ins.close(); | ||||
|         } catch (Exception ex) { | ||||
|             // 捕获异常,并记录错误日志 | ||||
|             Logger.error("123"+ex.getMessage(), ex); | ||||
|             resultMap.put("flag", "0"); | ||||
|             resultMap.put("message", ex.getMessage()); | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         // 返回结果映射 | ||||
|         return resultMap; | ||||
|     } | ||||
|     public IUAPQueryBS getQueryService() { | ||||
| 
 | ||||
|         return ServiceLocator.find(IUAPQueryBS.class); | ||||
|     } | ||||
| 
 | ||||
|     public static String calculateHmacSHA256(String data, String key) throws NoSuchAlgorithmException, InvalidKeyException, UnsupportedEncodingException { | ||||
|         String algorithm = "HmacSHA256"; | ||||
|         Mac hmacSHA256 = Mac.getInstance(algorithm); | ||||
|         SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(), algorithm); | ||||
|         hmacSHA256.init(secretKey); | ||||
|         byte[] hashBytes = hmacSHA256.doFinal(data.getBytes()); | ||||
|         String base64Hash = Base64.encodeBase64String(hashBytes); | ||||
|         return URLEncoder.encode(base64Hash, StandardCharsets.UTF_8.toString()); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     public static Map httpFW(String urlString, String jsonInputString)  { | ||||
| //        String jsonInputString = "{\"key\": \"中文\"}"; // 你的 JSON 数据 | ||||
| //        String urlString = "http://example.com/api"; // 替换为你的 URL | ||||
|         System.out.println("请求值"); | ||||
|         System.out.println(jsonInputString); | ||||
|         try { | ||||
|             URL url = new URL(urlString); | ||||
|             HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | ||||
| 
 | ||||
|             connection.setRequestMethod("POST"); | ||||
|             connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); | ||||
|             connection.setDoOutput(true); | ||||
| 
 | ||||
|             // 发送请求 | ||||
|             try (OutputStream os = connection.getOutputStream()) { | ||||
|                 byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8); | ||||
|                 os.write(input, 0, input.length); | ||||
|             } | ||||
| 
 | ||||
|             // 获取响应码 | ||||
|             int responseCode = connection.getResponseCode(); | ||||
|             System.out.println("响应码: " + responseCode); | ||||
|             // 根据响应码读取响应 | ||||
|             InputStream is = (responseCode >= 200 && responseCode < 300) ? connection.getInputStream() : connection.getErrorStream(); | ||||
|             StringBuilder response = new StringBuilder(); | ||||
| 
 | ||||
|             try (BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) { | ||||
|                 String responseLine; | ||||
|                 while ((responseLine = br.readLine()) != null) { | ||||
|                     response.append(responseLine.trim()); | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             // 输出响应 | ||||
|             System.out.println("返回值:"); | ||||
|             System.out.println(response.toString()); | ||||
|             //返回map | ||||
|             Map result= JSON.parseObject(response.toString(), HashMap.class); | ||||
|             return result; | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
|             e.printStackTrace(); | ||||
|         } | ||||
|         return null; | ||||
|     } | ||||
|     public class SSLUtilities { | ||||
|         public  void disableCertificateValidation() throws Exception { | ||||
|             TrustManager[] trustAllCertificates = new TrustManager[]{ | ||||
|                     new X509TrustManager() { | ||||
|                         public X509Certificate[] getAcceptedIssuers() { | ||||
|                             return null; | ||||
|                         } | ||||
|                         public void checkClientTrusted(X509Certificate[] certs, String authType) { | ||||
|                         } | ||||
|                         public void checkServerTrusted(X509Certificate[] certs, String authType) { | ||||
|                         } | ||||
|                     } | ||||
|             }; | ||||
| 
 | ||||
|             SSLContext sc = SSLContext.getInstance("TLS"); | ||||
|             sc.init(null, trustAllCertificates, new SecureRandom()); | ||||
|             HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); | ||||
|         } | ||||
|     } | ||||
|     public int executeUpdate(List<String> updateSqls) throws DbException { | ||||
|         if (updateSqls == null) { | ||||
|             return 0; | ||||
|         } | ||||
| 
 | ||||
|         int ret = 0; | ||||
|         PersistenceManager manager = null; | ||||
|         JdbcSession session = null; | ||||
|         Connection connection = null; | ||||
| 
 | ||||
|         try { | ||||
|             manager = PersistenceManager.getInstance(); | ||||
|             session = manager.getJdbcSession(); | ||||
|             connection = session.getConnection();  // 获取实际的数据库连接 | ||||
| //			connection = ConnectionFactory.getConnection(); | ||||
|             // 开始事务 | ||||
|             connection.setAutoCommit(false);  // 禁用自动提交,手动管理事务 | ||||
| 
 | ||||
|             // 执行批量操作 | ||||
|             for (String sql : updateSqls) { | ||||
|                 session.addBatch(sql); | ||||
|             } | ||||
| 
 | ||||
| 
 | ||||
|             // 执行批处理 | ||||
|             ret = session.executeBatch(); | ||||
| 
 | ||||
|             // 提交事务 | ||||
|             connection.commit();  // 批处理成功后提交事务 | ||||
| 
 | ||||
|         } catch (DbException e) { | ||||
|             if (connection != null) { | ||||
|                 try { | ||||
|                     // 如果发生异常,回滚事务 | ||||
|                     connection.rollback(); | ||||
|                 } catch (SQLException rollbackEx) { | ||||
|                     // 记录回滚异常的详细信息 | ||||
|                     throw new DbException("Error during transaction rollback", rollbackEx) { | ||||
|                         @Override | ||||
|                         public boolean isDataIntegrityViolation() { | ||||
|                             return false; | ||||
|                         } | ||||
| 
 | ||||
|                         @Override | ||||
|                         public boolean isBadSQLGrammar() { | ||||
|                             return false; | ||||
|                         } | ||||
|                     }; | ||||
|                 } | ||||
|             } | ||||
|             throw e;  // 将原始异常抛出 | ||||
|         } catch (SQLException e) { | ||||
|             throw new RuntimeException(e); | ||||
|         } finally { | ||||
|             if (connection != null) { | ||||
|                 try { | ||||
|                     // 恢复自动提交模式,确保不会影响其他操作 | ||||
|                     connection.setAutoCommit(true); | ||||
|                 } catch (SQLException e) { | ||||
|                     // 忽略恢复自动提交时的异常 | ||||
|                 } | ||||
|             } | ||||
|             if (manager != null) { | ||||
|                 manager.release(); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         return ret; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
|  | @ -0,0 +1,328 @@ | |||
| package nccloud.web.fbm.fbm.gather.action; | ||||
| 
 | ||||
| import com.alibaba.fastjson.JSON; | ||||
| import com.alibaba.fastjson.JSONArray; | ||||
| import nc.itf.uap.IUAPQueryBS; | ||||
| import nc.jdbc.framework.JdbcSession; | ||||
| import nc.jdbc.framework.PersistenceManager; | ||||
| import nc.jdbc.framework.exception.DbException; | ||||
| import nc.jdbc.framework.processor.MapListProcessor; | ||||
| import nccloud.framework.service.ServiceLocator; | ||||
| import nccloud.framework.web.action.itf.ICommonAction; | ||||
| import nccloud.framework.web.container.IRequest; | ||||
| 
 | ||||
| import java.sql.Connection; | ||||
| import java.sql.SQLException; | ||||
| import java.time.LocalDateTime; | ||||
| import java.time.format.DateTimeFormatter; | ||||
| import java.util.*; | ||||
| 
 | ||||
| public class DzButton  implements ICommonAction { | ||||
| 
 | ||||
|     @Override | ||||
|     public Object doAction(IRequest request) { | ||||
|         // 初始化结果映射,用于存储处理结果 | ||||
|         HashMap<String, String> resultMap  =  new HashMap<String, String>(); | ||||
|         // 读取请求中的JSON数据 | ||||
| 
 | ||||
|         String json = request.read(); | ||||
|         Map<String, Object> maps = JSON.parseObject(json, Map.class); | ||||
|         if (maps.get("pks") == null  ){ | ||||
|             resultMap.put("result", "请选择行"); | ||||
|             return resultMap; | ||||
|         } | ||||
|         int yg=0; | ||||
|         int cg=0; | ||||
|         int sbl=0; | ||||
| 
 | ||||
|         JSONArray jsonArray = (JSONArray) maps.get("pks"); | ||||
|         ArrayList<Object> pks = new ArrayList<>(Arrays.asList(jsonArray.toArray())); | ||||
| 
 | ||||
| // 使用 String.join 进行字符串拼接 | ||||
|         String result = ""; | ||||
|         StringBuilder sb = new StringBuilder(); | ||||
|         if (pks.size() > 1) { | ||||
|             for (int i = 0; i < pks.size(); i++) { | ||||
|                 sb.append("'").append(pks.get(i)).append("'"); | ||||
|                 if (i < pks.size() - 1) { | ||||
|                     sb.append(","); | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             result = sb.toString(); | ||||
|         }else { | ||||
|             result= "'"+(String) pks.get(0)+"'"; | ||||
|         } | ||||
|         // 如果账单编号为空,则返回失败结果 | ||||
|         try { | ||||
|             // 获取当前年份 | ||||
|             String sql = "select fbm.gatherdate,bank1.pk_bankdoc as fkyh,bank2.pk_bankdoc as  skyh,fbm.acceptorbank,fbm.hidereceivebankacc ,holdunit,org.name as orgname , reg.name as pjname,xxb_bon.bdcode,btype.pk_balatype,reg.code,xxe.exsystemcode,\n" + | ||||
|                     "xxb_bon.exsysval\n" + | ||||
|                     ",invoiceunit,fbmbilltype,fbm.fbmbillno,fbm.pk_register, paybankacc as bankaccount,fbm.payunit,cust.name as bankname,fbm.billmaker,fbm.creator,fbm.note,fbm.money,cust.custsupprop ,cust.custsuptype,fbm.pk_banktype ,fbm.pk_org ,fbm.pk_org_v,fbm.hidereceiveunit, fbm.hidepayunit,fbm.hidepaybankacc ,fbm.hidepaybank ,fbm.paybankacc ,fbm.paybank ,fbm.receiveunit,fbm.receivebankacc ,fbm.receivebank ,hidereceivebank, bankdoc.pk_bankaccbas ,fbm.pk_group \n" + | ||||
|                     "from fbm_register fbm \n" + | ||||
|                     "left join bd_cust_supplier cust on fbm.hidepayunit=cust.pk_cust_sup  \n" + | ||||
|                     "left join bd_bankaccbas   bankdoc on fbm.receivebankacc = bankdoc.code\n" + | ||||
|                     "left join bd_notetype  reg on fbm.fbmbilltype=reg.pk_notetype\n" + | ||||
|                     "join xx_bdcontra_b xxb_bon  on xxb_bon.exsysval=reg.code\n" + | ||||
|                     "join xx_bdcontra xxb on xxb.pk_contra=xxb_bon.pk_contra\n" + | ||||
|                     "join xx_exsystem xxe on xxe.pk_exsystem =xxb.exsystem and xxe.exsystemcode='pkinformer'\n" + | ||||
|                     "left join org_financeorg  org on org.pk_financeorg=fbm.holdunit\n" + | ||||
|                     "left   join bd_bankdoc bank1 on fbm.paybank =bank1.name\n" + | ||||
|                     "left   join bd_bankdoc bank2 on fbm.receivebank =bank2.name\n" + | ||||
|                     "left join bd_balatype btype on btype.code=xxb_bon.bdcode " + | ||||
| 
 | ||||
|                     " where  fbm.pk_register in("+result+") "; | ||||
|             List<Map<String, Object>> results = (List<Map<String, Object>>) getQueryService().executeQuery(sql, new MapListProcessor()); | ||||
| 
 | ||||
|             List sqlStr = new ArrayList(); | ||||
|             LocalDateTime creationTime = LocalDateTime.now(); | ||||
| 
 | ||||
| // 格式化年月日 | ||||
| 
 | ||||
|             DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); | ||||
|             String formattedDate = creationTime.format(dateFormatter); | ||||
|             // 格式化时分秒 | ||||
|             DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); | ||||
|             String formattedTime = creationTime.format(timeFormatter); | ||||
| 
 | ||||
| // 格式化时间 | ||||
|             DateTimeFormatter datatimes = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); | ||||
|             String formatteddatatime = creationTime.format(datatimes); | ||||
|             yg=results.size(); | ||||
|             for (int i = 0; i < results.size(); i++) { | ||||
| 
 | ||||
|                 Map <String, Object> row = results.get(i); | ||||
|                 String bankAccount = (String) row.get("receivebankacc"); | ||||
|                 String gatherdate=(String) row.get("gatherdate"); | ||||
|                 // 本方开户银行名称 | ||||
|                 String bankName= (String) row.get("receiveunit"); | ||||
|                 // 制单人 | ||||
|                 String billMaker= (String) row.get("billmaker"); | ||||
|                 // 托收协议号 | ||||
|                 String consignAgreement="~"; | ||||
|                 // 记录创建时间 | ||||
|                 String sj = formatteddatatime; | ||||
|                 // 创建人 | ||||
|                 String creator= (String) row.get("creator"); | ||||
|                 // 收付性质 | ||||
|                 String direction="receivemoney"; | ||||
|                 // (未明确用途,可根据实际情况使用) | ||||
|                 String domain="~"; | ||||
|                 // 制单日期 | ||||
|                 String doOperateDate=formatteddatatime; | ||||
|                 // 制单时间 | ||||
|                 String doOperateTime=formattedTime; | ||||
|                 // 标记,通常用于逻辑删除,0 表示未删除 | ||||
|                 int dr=0; | ||||
|                 // (未明确用途,可根据实际情况使用) | ||||
|                 String family="~"; | ||||
|                 // 未生成标志 | ||||
|                 String generateFlag="hasnogenerate"; | ||||
|                 // 到账日期 | ||||
|                 String infoDate=gatherdate; | ||||
|                 // 到账时间 | ||||
|                 String infoDateTime=formattedTime; | ||||
|                 // 备注 | ||||
|                 String memo=(String) row.get("note"); | ||||
|                 // 修改时间 | ||||
|                 String modifiedTime=formatteddatatime; | ||||
|                 // 修改人 | ||||
|                 String modifier=(String) row.get("creator"); | ||||
|                 // 金额 | ||||
|                 double money=Double.parseDouble(row.get("money").toString()); | ||||
|                 // 对方账户 | ||||
|                 String oppBankAccount=(String) row.get("paybankacc"); | ||||
|                 // 对方单位内外部标识 custsupprop 0=外部单位; | ||||
|                 //1=内部单位; | ||||
| 
 | ||||
|                 String oppInOut; | ||||
|                 if (row.get("custsupprop")!=null&&row.get("custsupprop").toString().equals("0")){ | ||||
|                     oppInOut="outer"; | ||||
|                 }else{ | ||||
|                     oppInOut="inner"; | ||||
|                 } | ||||
|                 // 对方名称 | ||||
|                 String oppUnitName=(String) row.get("payunit"); | ||||
|                 // 对方单位类别 | ||||
|                 Object custsuptype = row.get("custsuptype"); | ||||
|                 String oppUnitType = "cust"; // 默认值 | ||||
| 
 | ||||
|                 if (custsuptype != null && custsuptype.toString().equals("2")) { | ||||
|                     oppUnitType = "supp"; | ||||
|                 } | ||||
| 
 | ||||
|                 // 本方账户对应子户 | ||||
|                 String pkAccSub=(String) row.get("hidereceivebankacc"); | ||||
|                 // (未明确用途,可根据实际情况使用) | ||||
|                 String pk_balatype= (String) row.get("pk_balatype"); | ||||
|                 // 本方开户银行主键 | ||||
|                 String pkBank=(String) row.get("skyh"); | ||||
|                 // 本方银行账号主键 | ||||
|                 String pkBankAcc=(String) row.get("pk_bankaccbas");//1 | ||||
|                 // 记账人 | ||||
|                 String pkBankAccer="~"; | ||||
|                 // 本方银行类别主键 | ||||
|                 String pkBankType=(String) row.get("pk_banktype"); | ||||
| 
 | ||||
|                 // 对方单位 | ||||
|                 String pk_oppunit=(String) row.get("hidepayunit"); | ||||
|                 // 对方开户银行账号主键 | ||||
|                 String pk_oppbank=(String)row.get("fkyh"); | ||||
|                 //对方账户PK | ||||
|                 String pk_oppacc= (String) row.get("hidepaybankacc"); | ||||
| 
 | ||||
| 
 | ||||
|                 // 单据类型 | ||||
|                 String pkBillTypeCode="36S3"; | ||||
|                 // 单据类型主键 | ||||
|                 String pkBillTypeId="1001Z61000000001SOPF"; | ||||
|                 // (未明确用途,可根据实际情况使用) | ||||
|                 String pkClaimer="~"; | ||||
|                 // 币种 | ||||
|                 String pkCurrType="1002Z0100000000001K1"; | ||||
|                 // (未明确用途,可根据实际情况使用) | ||||
|                 String pkFundType="~"; | ||||
|                 // 所属集团 | ||||
|                 String pkGroup=(String) row.get("pk_group"); | ||||
|                 // (未明确用途,可根据实际情况使用主键) | ||||
|                 String pkInformer=(String) row.get("pk_register"); | ||||
|                 // (未明确用途,可根据实际情况使用) | ||||
|                 String pkOrg=(String) row.get("pk_org"); | ||||
|                 // 财务组织版本 | ||||
|                 String pkOrgV=(String) row.get("pk_org_v"); | ||||
|                 // 来源单据主键 | ||||
|                 String pkSrc=null; | ||||
|                 // 制证人 | ||||
|                 String pkVouch=(String) row.get("billmaker"); | ||||
|                 // 收/付款资金组织 | ||||
|                 String recPayFundOrg="~"; | ||||
|                 // 收/付款资金组织计划项目 | ||||
|                 String recPayFundPlansubj="~"; | ||||
|                 // (未明确用途,可根据实际情况使用) | ||||
|                 String recPayInnerAcc="~"; | ||||
|                 // (未明确用途,可根据实际情况使用) | ||||
|                 String recPayOrg="~"; | ||||
|                 // (未明确用途,可根据实际情况使用) | ||||
|                 String recPayOrgPlansubj="~"; | ||||
|                 // (未明确用途,可根据实际情况使用) | ||||
|                 String releaseOrg="~"; | ||||
|                 // 风格标志,A 可能表示某种风格类型 | ||||
|                 char styleFlag='A'; | ||||
|                 // (未明确用途,可根据实际情况使用) | ||||
|                 String subFamily="~"; | ||||
|                 // 系统代码 | ||||
|                 String sysCode="sysnet"; | ||||
|                 // 时间戳 | ||||
|                 String ts= formatteddatatime; | ||||
|                 // 单据号 | ||||
|                 long timestamp = System.currentTimeMillis(); | ||||
|                 Random random = new Random(); | ||||
|                 int randomNumber = random.nextInt(10000); // 生成0到9999之间的随机数 | ||||
|                 String vBillNo = "36S"+String.format("%d%04d", timestamp, randomNumber); | ||||
|                 String note_no=(String) row.get("fbmbillno"); | ||||
|                 //String sqlp="insert into cmp_informer(bankaccount,bankname,billmaker,consignagreement,creationtime,creator,direction,domain,doperatedate,doperatetime,dr,family,generateflag,infodate,infodatetime,memo,modifiedtime,modifier,moneyy,oppbankaccount,oppinout,oppunitname,oppunittype,pk_acc_sub,pk_balatype,pk_bank,pk_bankacc,pk_bankaccer,pk_banktype,pk_billtypecode,pk_billtypeid,pk_claimer,pk_currtype,pk_fundtype,pk_group,pk_informer,pk_org,pk_org_v,pk_src,pk_vouch,recpay_fundorg,recpay_fundplansubj,recpay_inneracc,recpay_org,recpay_orgplansubj,release_org,styleflag,subfamily,syscode,ts,vbillno) values('"+num+"','济南热电有限公司','1001A110000000003Q0I','~','"+dam+"','1001A110000000003Q0I','"+pr+"','~','"+transactionDate+"','"+dam+"','0','~','hasnogenerate','"+transactionDate+"','"+timesub+"','"+zhaiYao+"','"+dam+"','1001A110000000003Q0I',"+money+",'"+oppositeAccountNumber+"','"+opp+"','"+oppositeUserName+"','"+opptype+"','"+select[2]+"','~','"+select[0]+"','"+select[1]+"','~','"+select3[0]+"','36S3','1001Z61000000001SOPF','~','1002Z0100000000001K1','~','0001N2100000000002ZE','"+vId+"','0001N710000000001FWC','0001N710000000001FWB','1001A110000000007IWJ','~','~','~','~','~','~','~','A','~','sysnet','"+dam+"','"+fId2+"')" | ||||
|                 // 形成sql | ||||
|                 String sqlp="insert into cmp_informer(bankaccount,bankname,billmaker,consignagreement,creationtime,creator,direction,domain,doperatedate,doperatetime,dr,family,generateflag,infodate,infodatetime,memo,modifiedtime,modifier,moneyy,oppbankaccount,oppinout,oppunitname,oppunittype,pk_acc_sub,pk_balatype,pk_bank,pk_bankacc,pk_bankaccer,pk_banktype,pk_billtypecode,pk_billtypeid,pk_claimer,pk_currtype,pk_fundtype,pk_group,pk_informer,pk_org,pk_org_v,pk_src,pk_vouch,recpay_fundorg,recpay_fundplansubj,recpay_inneracc,recpay_org,recpay_orgplansubj,release_org,styleflag,subfamily,syscode,ts,vbillno,note_no,pk_oppunit,pk_oppbank,pk_oppacc) values('" | ||||
|                         +bankAccount+"','"+bankName+"','"+billMaker+"','"+consignAgreement+"','"+formatteddatatime+"','"+creator+"','"+direction+"','"+domain+"','"+doOperateDate+"','"+sj+"','"+dr+"','"+family+"','"+generateFlag+"','"+infoDate+"','"+infoDateTime+"','"+memo+"','"+modifiedTime+"','"+modifier+"','"+money+"','"+oppBankAccount+"','"+oppInOut+"','"+oppUnitName+"','"+oppUnitType+"','"+pkAccSub+"','"+pk_balatype+"','"+pkBank+"','"+pkBankAcc+"','"+pkBankAccer+"','"+pkBankType+"','"+pkBillTypeCode+"','"+pkBillTypeId+"','"+pkClaimer+"','"+pkCurrType+"','"+pkFundType+"','"+pkGroup+"','"+pkInformer+"','"+pkOrg+"','"+pkOrgV+"','"+pkSrc+"','"+pkVouch+"','"+recPayFundOrg+"','"+recPayFundPlansubj+"','"+recPayInnerAcc+"','"+recPayOrg+"','"+recPayOrgPlansubj+"','"+releaseOrg+"','"+styleFlag+"','"+subFamily+"','"+sysCode+"','"+ts+"','"+vBillNo+"','"+note_no+"','"+pk_oppunit+"','"+pk_oppbank+"','"+pk_oppacc+"')"; | ||||
|                 sqlStr.add(sqlp); | ||||
|             } | ||||
|             int succState = executeUpdate(sqlStr); | ||||
|             cg=succState; | ||||
|             sbl=yg-succState; | ||||
|             resultMap.put("flag", "1"); | ||||
|             resultMap.put("message", "插入数据成功,已插入"+succState+"条数据"); | ||||
|             resultMap.put("cg", String.valueOf(cg)); | ||||
|             resultMap.put("sbl", String.valueOf(sbl)); | ||||
|             resultMap.put("yg", String.valueOf(yg)); | ||||
|             //lists转json | ||||
|         } catch (Exception ex) { | ||||
|             // 捕获异常,并记录错误日志 | ||||
|             resultMap.put("cg", String.valueOf(0)); | ||||
|             resultMap.put("sbl", String.valueOf(yg)); | ||||
|             resultMap.put("yg", String.valueOf(yg)); | ||||
|             resultMap.put("flag", "0"); | ||||
|             resultMap.put("message", ex.getMessage()); | ||||
|         } | ||||
|         // 返回结果映射 | ||||
|         return resultMap; | ||||
|     } | ||||
|     public IUAPQueryBS getQueryService() { | ||||
|         return ServiceLocator.find(IUAPQueryBS.class); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     public int executeUpdate(List<String> updateSqls) throws DbException { | ||||
|         if (updateSqls == null) { | ||||
|             return 0; | ||||
|         } | ||||
| 
 | ||||
|         int ret = 0; | ||||
|         PersistenceManager manager = null; | ||||
|         JdbcSession session = null; | ||||
|         Connection connection = null; | ||||
| 
 | ||||
|         try { | ||||
|             manager = PersistenceManager.getInstance(); | ||||
|             session = manager.getJdbcSession(); | ||||
|             connection = session.getConnection();  // 获取实际的数据库连接 | ||||
| 
 | ||||
|             // 开始事务 | ||||
|             connection.setAutoCommit(false);  // 禁用自动提交,手动管理事务 | ||||
| 
 | ||||
|             // 执行批量操作 | ||||
|             for (String sql : updateSqls) { | ||||
|                 session.addBatch(sql); | ||||
|             } | ||||
| 
 | ||||
|             // 执行批处理 | ||||
|             ret = session.executeBatch(); | ||||
| 
 | ||||
|             // 提交事务 | ||||
|             connection.commit();  // 批处理成功后提交事务 | ||||
| 
 | ||||
|         } catch (DbException e) { | ||||
|             if (connection != null) { | ||||
|                 try { | ||||
|                     // 如果发生异常,回滚事务 | ||||
|                     connection.rollback(); | ||||
|                 } catch (SQLException rollbackEx) { | ||||
|                     // 记录回滚异常的详细信息 | ||||
|                     throw new DbException("Error during transaction rollback", rollbackEx) { | ||||
|                         @Override | ||||
|                         public boolean isDataIntegrityViolation() { | ||||
|                             return false; | ||||
|                         } | ||||
| 
 | ||||
|                         @Override | ||||
|                         public boolean isBadSQLGrammar() { | ||||
|                             return false; | ||||
|                         } | ||||
|                     }; | ||||
|                 } | ||||
|             } | ||||
|             throw e;  // 将原始异常抛出 | ||||
|         } catch (SQLException e) { | ||||
|             throw new RuntimeException(e); | ||||
|         } finally { | ||||
|             if (connection != null) { | ||||
|                 try { | ||||
|                     // 恢复自动提交模式,确保不会影响其他操作 | ||||
|                     connection.setAutoCommit(true); | ||||
|                 } catch (SQLException e) { | ||||
|                     // 忽略恢复自动提交时的异常 | ||||
|                 } | ||||
|             } | ||||
|             if (manager != null) { | ||||
|                 manager.release(); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         return ret; | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
		Loading…
	
		Reference in New Issue