diff --git a/cmp/component.xml b/cmp/component.xml new file mode 100644 index 0000000..8540fd0 --- /dev/null +++ b/cmp/component.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/cmp/src/client/nccloud/web/cmp/informer/informer/action/myBtnClickAction.java b/cmp/src/client/nccloud/web/cmp/informer/informer/action/myBtnClickAction.java new file mode 100644 index 0000000..5985642 --- /dev/null +++ b/cmp/src/client/nccloud/web/cmp/informer/informer/action/myBtnClickAction.java @@ -0,0 +1,443 @@ +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.*; + +/** + * 2005适配2312 + * + * @author mzr + * @date 2025/04/02 + */ +public class myBtnClickAction extends InformerAction implements ICommonAction { + + @Override + public Object doAction(IRequest request) { + + + // 初始化结果映射,用于存储处理结果 + HashMap resultMap = new HashMap(); + // 读取请求中的JSON数据 + + String json = request.read(); + Map maps = JSON.parseObject(json, Map.class); + if (maps.get("pks") == null) { + resultMap.put("result", "请选择行"); + return resultMap; + } + JSONArray jsonArray = (JSONArray) maps.get("pks"); + ArrayList 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 urls = (Map) getQueryService().executeQuery(urlsql, new MapProcessor()); + Map appks = (Map) getQueryService().executeQuery(appksql, new MapProcessor()); + Map appses = (Map) getQueryService().executeQuery(uappssql, new MapProcessor()); + Map tenants = (Map) 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 map = JSON.parseObject(jsonString, Map.class); + System.out.println(map); + + System.out.println(url); + + // 获取当前年份 + String sql = " select 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 " + + " where cmp.pk_informer in(" + result + ") "; + List> results = (List>) getQueryService().executeQuery(sql, new MapListProcessor()); + + ArrayList lists = new ArrayList(); + for (int i = 0; i < results.size(); i++) { + Map vmao = new HashMap(); + Map 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", "CNY"); + 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 + ArrayList successData = null; + ArrayList failData = null; + + if (jsonist != null) { + successData = (ArrayList) jsonist.toJavaList(String.class); + + } + if (faijsonist != null) { + failData = (ArrayList) 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 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; + } + +} \ No newline at end of file diff --git a/cmp/src/client/yyconfig/modules/cmp/informer/config/action/NCCInformer.xml b/cmp/src/client/yyconfig/modules/cmp/informer/config/action/NCCInformer.xml new file mode 100644 index 0000000..fe5e8dd --- /dev/null +++ b/cmp/src/client/yyconfig/modules/cmp/informer/config/action/NCCInformer.xml @@ -0,0 +1,165 @@ + + + + cmp.informer.myBtnClickAction + + nccloud.web.cmp.informer.informer.action.myBtnClickAction + + + cmp.informer.go2cardcheck + + nccloud.web.cmp.informer.informer.action.CmpInformerGo2CardCheckAction + + + cmp.informer.informerquery + + nccloud.web.cmp.informer.informer.action.ListQueryAction + + + cmp.informer.informerqueryone + + nccloud.web.cmp.informer.informer.action.InformerQueryAction + + + cmp.informer.informerpagequery + + nccloud.web.cmp.informer.informer.action.ListPageQueryAction + + + cmp.informer.informerpublish + + commitpublish,Compublish + nccloud.web.cmp.informer.informer.action.ListPublishAction + + + cmp.informer.informerunpublish + + Cancelpublish + nccloud.web.cmp.informer.informer.action.ListUnPublishAction + + + cmp.informer.informergenerate + + Generate,Confirmgenerate + nccloud.web.cmp.informer.informer.action.ListGenerateAction + + + cmp.informer.informerungenerate + + Nopublish,Unpublish + nccloud.web.cmp.informer.informer.action.ListUnGenerateAction + + + cmp.informer.informerrecgenerate + + Recgenerate + nccloud.web.cmp.informer.informer.action.ListRecGenerateAction + + + cmp.informer.informercombine + + combine + nccloud.web.cmp.informer.informer.action.ListCombineAction + + + cmp.informer.informercancelgenerate + + Cancelgenerate,ungenerate,Lungenerate + nccloud.web.cmp.informer.informer.action.ListCancelGenerateAction + + + cmp.informer.listdialogdefaultvalue + + nccloud.web.cmp.informer.informer.action.ListDialogDefaultValue + + + cmp.informer.informercardquery + + nccloud.web.cmp.informer.informer.action.CardQueryAction + + + cmp.informer.cardpublish + + nccloud.web.cmp.informer.informer.action.CardPublishAction + + + cmp.informer.cardunpublish + + Lcancelpublish,Cancelpublish + nccloud.web.cmp.informer.informer.action.CardUnPublishAction + + + cmp.informer.appoint + + nccloud.web.cmp.informer.informer.action.AppointAction + + + cmp.informer.cardunclaim + + Cancelclaim,Lunclaim + nccloud.web.cmp.informer.informer.action.CardUnClaimAction + + + cmp.informer.cardcancelgenerate + + Cancelgenerate,Lcancelgenerate + nccloud.web.cmp.informer.informer.action.CardUnMakeBillAction + + + cmp.informer.cardgenerate + + confirmgenerate,generate + nccloud.web.cmp.informer.informer.action.CardGenerateAction + + + cmp.informer.carddialogdefaultvalue + + nccloud.web.cmp.informer.informer.action.CardDialogDefaultValue + + + cmp.informer.cardcombine + + nccloud.web.cmp.informer.informer.action.CardCombineAction + + + cmp.informer.afterevent + + nccloud.web.cmp.informer.informer.handler.InformerAfterEditHandler + + + cmp.informer.linkbill + + nccloud.web.cmp.informer.informer.action.InformerLinkBill + + + cmp.informer.defaultorg + + nccloud.web.cmp.informer.informer.action.InformerDefaultOrg + + + cmp.informer.refund + + refundBill,refund + nccloud.web.cmp.informer.informer.action.RefundAction + + + cmp.informer.sscinformerquery + + nccloud.web.cmp.informer.informer.action.SSCListQueryAction + + + cmp.informer.custsupafteredit + + nccloud.web.cmp.informer.informer.action.CustSupAtferEditAction + + + cmp.informer.billdateafteredit + + nccloud.web.cmp.informer.informer.action.BillDateAfterEditAction + + + cmp.informer.checkispaymentreturn + + nccloud.web.cmp.informer.informer.action.CheckIsPaymentreturnAction + + diff --git a/cmp/src/client/yyconfig/modules/cmp/informer/config/authorize/authorize_informer.xml b/cmp/src/client/yyconfig/modules/cmp/informer/config/authorize/authorize_informer.xml new file mode 100644 index 0000000..530eeee --- /dev/null +++ b/cmp/src/client/yyconfig/modules/cmp/informer/config/authorize/authorize_informer.xml @@ -0,0 +1,39 @@ + + + + + 36070AISC,36070AISCC,36070AIPSSC + + cmp.informer.go2cardcheck + cmp.informer.informerquery + cmp.informer.informerpagequery + cmp.informer.informerpublish + cmp.informer.informerunpublish + cmp.informer.informergenerate + cmp.informer.informerungenerate + cmp.informer.informerrecgenerate + cmp.informer.informercombine + cmp.informer.informercancelgenerate + cmp.informer.informercardquery + cmp.informer.cardpublish + cmp.informer.cardunpublish + cmp.informer.cardunclaim + cmp.informer.cardcancelgenerate + cmp.informer.cardgenerate + cmp.informer.carddialogdefaultvalue + cmp.informer.cardcombine + cmp.informer.afterevent + cmp.informer.linkbill + cmp.informer.listdialogdefaultvalue + cmp.informer.defaultorg + cmp.informer.informerqueryone + cmp.informer.appoint + cmp.informer.refund + cmp.informer.sscinformerquery + cmp.informer.custsupafteredit + cmp.informer.billdateafteredit + cmp.informer.checkispaymentreturn + cmp.informer.myBtnClickAction + + + diff --git a/fbm/component.xml b/fbm/component.xml index 7ddf7ff..5643c7f 100644 --- a/fbm/component.xml +++ b/fbm/component.xml @@ -1,3 +1,5 @@ - - - \ No newline at end of file + + + + + \ No newline at end of file diff --git a/fbm/src/client/nccloud/web/fbm/fbm/gather/action/DzButton.java b/fbm/src/client/nccloud/web/fbm/fbm/gather/action/DzButton.java new file mode 100644 index 0000000..c8ea0e5 --- /dev/null +++ b/fbm/src/client/nccloud/web/fbm/fbm/gather/action/DzButton.java @@ -0,0 +1,331 @@ +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.*; + +/** + * 2005适配2312 + * + * @author mzr + * @date 2025/04/03 + */ +public class DzButton implements ICommonAction { + + @Override + public Object doAction(IRequest request) { + // 初始化结果映射,用于存储处理结果 + HashMap resultMap = new HashMap(); + // 读取请求中的JSON数据 + + String json = request.read(); + Map 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 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> results = (List>) 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 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 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; + } + + +} \ No newline at end of file diff --git a/fbm/src/client/yyconfig/modules/fbm/gather/config/action/gather_fbm.xml b/fbm/src/client/yyconfig/modules/fbm/gather/config/action/gather_fbm.xml new file mode 100644 index 0000000..57f8d90 --- /dev/null +++ b/fbm/src/client/yyconfig/modules/fbm/gather/config/action/gather_fbm.xml @@ -0,0 +1,327 @@ + + + + + fbm.gather.gatherSave + + nccloud.web.fbm.fbm.gather.action.BillGather4NCCSaveAction + + + fbm.gather.DzButton + + nccloud.web.fbm.fbm.gather.action.DzButton + + + fbm.gather.gatherDelete + + nccloud.web.fbm.fbm.gather.action.BillGather4NCCDeleteAction + + + + fbm.gather.gatherQuery + + nccloud.web.fbm.fbm.gather.action.BillGather4NCCQueryAction + + + + fbm.gather.gatherPageQuery + + nccloud.web.fbm.fbm.gather.action.BillGather4NCCPageQueryAction + + + + fbm.gather.gatherPrint + + nccloud.web.fbm.fbm.gather.action.BillGatherPrint4NCCAction + + + + fbm.gather.gatherAfterEvent + + nccloud.web.fbm.fbm.gather.action.BillGather4NCCAfterEventAction + + + + fbm.gather.gatherBeforeEvent + + nccloud.web.fbm.fbm.gather.action.BillGather4NCCBeforeEventAction + + + + fbm.gather.gatherCardQuery + + nccloud.web.fbm.fbm.gather.action.BillGatherCardQuery4NCCAction + + + + fbm.gather.gatherCommit + + nccloud.web.fbm.fbm.gather.action.BillGatherCommit4NCCAction + + + + fbm.gather.gatherUnCommit + + nccloud.web.fbm.fbm.gather.action.BillGatherUnCommit4NCCAction + + + + fbm.gather.gatherVoucher + + nccloud.web.fbm.fbm.gather.action.BillGather4NCCMkVoucherAction + + + + fbm.gather.gatherUnVoucher + + nccloud.web.fbm.fbm.gather.action.BillGather4NCCUnVoucherAction + + + + fbm.gather.linkquerysf + + nccloud.web.fbm.fbm.gather.action.FbmLQuerySFBillAction4NCC + + + + + fbm.gather.gatherReceive + + nccloud.web.fbm.fbm.gather.action.BillGatherRecieve4NCCAction + + + + fbm.gather.gatherReceiveCancel + + nccloud.web.fbm.fbm.gather.action.BillGatherRecieveCancel4NCCAction + + + + fbm.gather.gatherReceiveReject + + nccloud.web.fbm.fbm.gather.action.BillGatherRefuseSign4NCCAction + + + + fbm.gather.gatherElcBillQuery + + nccloud.web.fbm.fbm.gather.action.BillGatherReceivedElcBill4NCCAction + + + + fbm.gather.gatherCopy + + nccloud.web.fbm.fbm.gather.action.BillGather4NCCCopyAction + + + + fbm.gather.gatherCollectionSettle + + nccloud.web.fbm.fbm.gather.action.BillGatherCollectionSettle4NCCAction + + + + fbm.gather.gatherCreateGather + + nccloud.web.fbm.fbm.gather.action.BillGatherCreateGather4NCCAction + + + + + fbm.gather.queryOther + + nccloud.web.fbm.fbm.gather.action.BillGatherOtherQueryAction + + + + + fbm.gather.voucherLink + + nccloud.web.fbm.fbm.gather.action.GatherNCCVoucherLinkAction + + + + fbm.gather.palnLink + + nccloud.web.fbm.fbm.gather.action.GatherNCCNtbLinkAction + + + + + fbm.gather.bankRegister + + nccloud.web.fbm.fbm.gather.action.BillGatherBankRegisterAction + + + + fbm.gather.disabled + + nccloud.web.fbm.fbm.gather.action.GatherDisable4NCCAction + + + + fbm.gather.cancelDisabled + + nccloud.web.fbm.fbm.gather.action.GatherCancelDisable4NCCAction + + + + fbm.gather.quickservice + + nccloud.web.fbm.fbm.gather.action.GatherQuickservice4NCCAction + + + + fbm.gather.quickdiscount + + nccloud.web.fbm.fbm.gather.action.GatherQuickDiscount4NCCAction + + + + fbm.gather.quickdiscountapp + + nccloud.web.fbm.fbm.gather.action.GatherQuickDiscountApply4NCCAction + + + + fbm.gather.quickendore + + nccloud.web.fbm.fbm.gather.action.GatherQuickEndore4NCCAction + + + + fbm.gather.quickconsignbank + + nccloud.web.fbm.fbm.gather.action.GatherQuickConsign4NCCAction + + + + fbm.gather.quickimpawn + + nccloud.web.fbm.fbm.gather.action.GatherQuickImpawn4NCCAction + + + + fbm.gather.circulate + + nccloud.web.fbm.fbm.gather.action.GatherLinkCirculate4NCCAction + + + + + fbm.gather.circulateprint + + nccloud.web.fbm.fbm.gather.action.BillCirculatePrint4NCCAction + + + + fbm.gather.quickServiceAfterEvent + + nccloud.web.fbm.fbm.gather.action.BillGatherQuick4NCCAfterEventAction + + + + fbm.gather.gatheringBill + + nccloud.web.fbm.fbm.gather.action.GatherBusiAR4NCCAction + + + + fbm.gather.recbill + + nccloud.web.fbm.fbm.gather.action.GatherRecbill4NCCAction + + + + fbm.gather.commissionGathering + + nccloud.web.fbm.fbm.gather.action.GatheringConfig4NCCAction + + + + fbm.gather.pdfImport + + nccloud.web.fbm.fbm.gather.action.BillGather4NCCPDFImportAction + + + + fbm.gather.bankkeeping + + nccloud.web.fbm.fbm.gather.action.GatherBankKeeping4NCCAction + + + + fbm.gather.bankbacking + + nccloud.web.fbm.fbm.gather.action.GatherBankBacking4NCCAction + + + + fbm.gather.endoring + + nccloud.web.fbm.fbm.gather.action.GatherEndoring4NCCAction + + + + fbm.gather.discountapplying + + nccloud.web.fbm.fbm.gather.action.GatherDiscountApplying4NCCAction + + + + fbm.gather.discounting + + nccloud.web.fbm.fbm.gather.action.GatherDiscounting4NCCAction + + + + fbm.gather.consignbanking + + nccloud.web.fbm.fbm.gather.action.GatherConsignBanking4NCCAction + + + + fbm.gather.consignbanking + + nccloud.web.fbm.fbm.gather.action.GatherConsignBanking4NCCAction + + + + fbm.gather.impawning + + nccloud.web.fbm.fbm.gather.action.GatherImpawning4NCCAction + + + + fbm.gather.rreturning + + nccloud.web.fbm.fbm.gather.action.GatherRreturning4NCCAction + + + + fbm.gather.gathernontransablecancell + + nccloud.web.fbm.fbm.gather.action.GatherNonTransableCancel4NCCAction + + + + fbm.gather.gatherrecallnontranstablecancell + + nccloud.web.fbm.fbm.gather.action.GatherRecallNonTransableCancel4NCCAction + + + fbm.gather.printcirculate + + nccloud.web.fbm.fbm.gather.action.GatherBatchPrintCirculate4NCCAction + + + fbm.gather.printcirculatedesc + + nccloud.web.fbm.fbm.gather.action.GatherBatchPrintCirculateDESC4NCCAction + + + fbm.gather.batchdowncirculate + + nccloud.web.fbm.fbm.gather.action.GatherBatchDownloadCirculate4NCCAction + + \ No newline at end of file diff --git a/fbm/src/client/yyconfig/modules/fbm/gather/config/authorize/gather_fbm.xml b/fbm/src/client/yyconfig/modules/fbm/gather/config/authorize/gather_fbm.xml new file mode 100644 index 0000000..193b627 --- /dev/null +++ b/fbm/src/client/yyconfig/modules/fbm/gather/config/authorize/gather_fbm.xml @@ -0,0 +1,61 @@ + + + + 36180RBR,36180RBR_APPR,36180ET,36180ET_APPR,36180BCI,36180BBS + + fbm.gather.gatherSave + fbm.gather.gatherDelete + fbm.gather.gatherQuery + fbm.gather.gatherPageQuery + fbm.gather.gatherPrint + fbm.gather.gatherAfterEvent + fbm.gather.gatherBeforeEvent + fbm.gather.gatherCardQuery + fbm.gather.gatherCommit + fbm.gather.gatherUnCommit + fbm.gather.gatherVoucher + fbm.gather.gatherUnVoucher + fbm.gather.gatherReceive + fbm.gather.gatherReceiveCancel + fbm.gather.gatherReceiveReject + fbm.gather.gatherElcBillQuery + fbm.gather.gatherCopy + fbm.gather.gatherCollectionSettle + fbm.gather.gatherCreateGather + fbm.gather.linkquerysf + fbm.gather.queryOther + fbm.gather.voucherLink + fbm.gather.palnLink + fbm.gather.bankRegister + fbm.gather.disabled + fbm.gather.cancelDisabled + fbm.gather.quickservice + fbm.gather.quickdiscount + fbm.gather.quickdiscountapp + fbm.gather.quickendore + fbm.gather.quickconsignbank + fbm.gather.quickimpawn + fbm.gather.circulate + fbm.gather.circulateprint + fbm.gather.quickServiceAfterEvent + fbm.gather.gatheringBill + fbm.gather.recbill + fbm.gather.commissionGathering + fbm.gather.pdfImport + fbm.gather.bankkeeping + fbm.gather.bankbacking + fbm.gather.endoring + fbm.gather.discountapplying + fbm.gather.discounting + fbm.gather.consignbanking + fbm.gather.impawning + fbm.gather.rreturning + fbm.gather.gathernontransablecancell + fbm.gather.gatherrecallnontranstablecancell + fbm.gather.printcirculate + fbm.gather.printcirculatedesc + fbm.gather.batchdowncirculate + fbm.gather.DzButton + + + \ No newline at end of file diff --git a/mmpac/META-INF/productReportResources.rest b/mmpac/META-INF/productReportResources.rest new file mode 100644 index 0000000..dcad554 --- /dev/null +++ b/mmpac/META-INF/productReportResources.rest @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/mmpac/src/public/nccloud/api/mmpac/productreport/ProductReportResources.java b/mmpac/src/public/nccloud/api/mmpac/productreport/ProductReportResources.java new file mode 100644 index 0000000..039d389 --- /dev/null +++ b/mmpac/src/public/nccloud/api/mmpac/productreport/ProductReportResources.java @@ -0,0 +1,1943 @@ +package nccloud.api.mmpac.productreport; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import nc.bs.cmp.util.SqlUtils; +import nc.bs.dao.BaseDAO; +import nc.bs.framework.common.InvocationInfoProxy; +import nc.bs.framework.common.NCLocator; +import nc.bs.scmpub.query.SCMBillQuery; +import nc.itf.mmpac.pmo.pac0002.IPMOBusinessService; +import nc.itf.mmpac.pmo.pac0002.IPMOQueryService; +import nc.itf.mmpac.wr.IWrBusinessService; +import nc.itf.mmpac.wr.IWrMaintainService; +import nc.itf.mmpac.wr.IWrQueryService; +import nc.itf.uap.pf.IplatFormEntry; +import nc.jdbc.framework.processor.BeanListProcessor; +import nc.jdbc.framework.processor.ColumnProcessor; +import nc.jdbc.framework.processor.MapListProcessor; +import nc.pubitf.ic.m46.m55a4.IProductInPubServiceFor55A4; +import nc.util.mmf.busi.service.PFPubService; +import nc.util.mmf.framework.base.MMValueCheck; +import nc.util.mmpac.wr.WrTransTypeUtil; +import nc.util.mmpac.wr.vochange.WrBusiVOToChangeVO; +import nc.vo.am.common.util.StringUtils; +import nc.vo.ic.m46.entity.FinProdInBodyVO; +import nc.vo.ic.m46.entity.FinProdInHeadVO; +import nc.vo.ic.m46.entity.FinProdInVO; +import nc.vo.ic.pub.define.ICPubMetaNameConst; +import nc.vo.ml.NCLangRes4VoTransl; +import nc.vo.mmpac.pmo.pac0002.entity.PMOAggVO; +import nc.vo.mmpac.pmo.pac0002.entity.PMOItemVO; +import nc.vo.mmpac.wr.entity.*; +import nc.vo.pub.BusinessException; +import nc.vo.pub.VOStatus; +import nc.vo.pub.lang.UFDate; +import nc.vo.pub.lang.UFDateTime; +import nc.vo.pub.lang.UFDouble; +import nc.vo.pubapp.AppContext; +import nc.vo.pubapp.pattern.exception.ExceptionUtils; +import nccloud.api.ic.m46.IAPIProductInMaitain; +import nccloud.api.rest.utils.NCCRestUtils; +import nccloud.api.rest.utils.ResultMessageUtil; +import nccloud.dto.mmpub.script.entity.MMScriptResultDTO; +import nccloud.openapi.scmpub.util.BillFieldsCodeToPkUtil; +import nccloud.openapi.scmpub.util.CallReturnBuildUtil; +import nccloud.pubitf.mmpub.commit.service.IBatchRunScriptService; +import nccloud.pubitf.riart.pflow.CloudPFlowContext; +import nccloud.ws.rest.resource.AbstractNCCRestResource; +import org.apache.commons.beanutils.BeanUtils; +import org.json.JSONString; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import java.util.*; + +/** + * 生产报告和流程生产订单API接口 + * 2005适配2312 + * + * @author mzr + * @date 2025/4/7 + */ +@Path("/mmpac/productReport") +public class ProductReportResources extends AbstractNCCRestResource { + @Override + public String getModule() { + return "mmpac"; + } + + private static String BODYTABLE = "ic_finprodin_b"; + private static String HEADTABLE = "ic_finprodin_h"; + public BaseDAO dao = null; + + public BaseDAO getDao() { + if (dao == null) { + dao = new BaseDAO(); + } + return dao; + } + + IWrQueryService query = (IWrQueryService) NCLocator.getInstance().lookup(IWrQueryService.class); + IWrBusinessService service = (IWrBusinessService) NCLocator.getInstance().lookup(IWrBusinessService.class); + IplatFormEntry iIplatFormEntry = NCLocator.getInstance().lookup(IplatFormEntry.class); + + /** + * 生产报告新增 + */ + @POST + @Path("/addProductReport") + @Consumes({"application/json"}) + @Produces({"application/json"}) + public JSONString addProductReportInfo(JSONString json1) throws BusinessException { + JSONObject returnJson = new JSONObject(); + + JSONObject jObject = JSON.parseObject(json1.toJSONString()); + if (jObject == null) { + return ResultMessageUtil.exceptionToJSON(new BusinessException("参数不能为空")); + } + JSONObject headObj = (JSONObject) jObject.get("head"); + JSONArray bodyObj = (JSONArray) jObject.get("body"); + if (headObj == null || bodyObj == null || bodyObj.size() == 0) { + return ResultMessageUtil.exceptionToJSON(new BusinessException("参数head/body不能为空")); + } + // 校验数据合法性 + Map data = validateData(headObj, bodyObj); + if (!"1".equals(data.get("code"))) { + return ResultMessageUtil.exceptionToJSON(new BusinessException((String) data.get("data"))); + } + AggWrVO vo = (AggWrVO) data.get("data"); + vo.getParent().setStatus(2); + AggWrVO[] clientvos = new AggWrVO[]{vo}; + AggWrVO[] vos = (AggWrVO[]) clientvos.clone(); + InvocationInfoProxy.getInstance().setBizDateTime(vo.getParentVO().getDbilldate().getMillis()); + IWrMaintainService service = (IWrMaintainService) NCLocator.getInstance().lookup(IWrMaintainService.class); + try { + vos = service.insert(vos); + // 更新单据日期 +// for (int i = 0; i < vos.length; i++) { +// String sql=" update mm_wr set Creationtime='"+clientvos[i].getParentVO().getCreationtime()+"' , Dmakedate='"+clientvos[i].getParentVO().getDmakedate()+"' where pk_wr='"+vos[i].getParentVO().getPk_wr()+"' "; +// new BaseDAO().executeUpdate(sql); +// } + + + } catch (Exception var13) { + ExceptionUtils.wrappBusinessException(var13.getMessage()); + return ResultMessageUtil.exceptionToJSON(new BusinessException("新增失败," + var13.getMessage())); + } + + returnJson.put("message", "成功"); + returnJson.put("data", vos[0]); + return ResultMessageUtil.toJSON(returnJson); + } + + /** + * 生产报告审核 + */ + @POST + @Path("/commitProductReport") + @Consumes({"application/json"}) + @Produces({"application/json"}) + public JSONString commitProductReportInfo(JSONString json1) throws BusinessException { + JSONObject jObject = JSON.parseObject(json1.toJSONString()); + if (jObject == null) { + return ResultMessageUtil.exceptionToJSON(new BusinessException("失败!参数不能为空")); + } + String id = (String) jObject.get("id"); + String ts = (String) jObject.get("ts"); +// String taudittime = (String)jObject.get("taudittime"); + + if (StringUtils.isBlank(id) || StringUtils.isBlank(ts)) { + return ResultMessageUtil.exceptionToJSON(new BusinessException("失败!参数id/ts不能为空")); + } + + IWrQueryService query = (IWrQueryService) NCLocator.getInstance().lookup(IWrQueryService.class); + String[] ids = new String[1]; + ids[0] = id; + + AggWrVO[] aggvos = query.queryByPk(ids); + if (null == aggvos || aggvos.length == 0) { + return ResultMessageUtil.exceptionToJSON(new BusinessException("失败!未找到对应单据,请检查id值")); + } + + InvocationInfoProxy.getInstance().setBizDateTime(new UFDate(ts).getMillis()); + for (int i = 0; i < aggvos.length; i++) { + aggvos[i].getParentVO().setTaudittime(new UFDate(ts)); + } + + Integer fbillstatus = aggvos[0].getParentVO().getFbillstatus(); + if (fbillstatus != null && fbillstatus != 1) { + return ResultMessageUtil.exceptionToJSON(new BusinessException("失败!自由态的单据才可以审批")); + } + + try { + CloudPFlowContext context = new CloudPFlowContext(); + context.setBillType("55A4"); + context.setActionName("SAVE"); + + context.setBillVos(aggvos); + IBatchRunScriptService batchRunScriptService = NCLocator.getInstance().lookup(IBatchRunScriptService.class); + MMScriptResultDTO obj = batchRunScriptService.runBacth(context, AggWrVO.class); + } catch (Exception e) { + return ResultMessageUtil.exceptionToJSON(new BusinessException("失败!" + e.getMessage())); + } + + JSONObject returnJson = new JSONObject(); + returnJson.put("message", id + " 审批成功"); + return ResultMessageUtil.toJSON(returnJson); + } + + + /** + * 产成品入库 + */ + @POST + @Path("/addrefbill") + @Consumes({"application/json"}) + @Produces({"application/json"}) + public JSONString addRefbill(List> paramList) throws BusinessException { + List aggVOList = new ArrayList(); + try { + String scddid = ""; + + for (Map map : paramList) { + // 判断json格式是否合法 + if (!map.containsKey(HEADTABLE) || !map.containsKey(BODYTABLE)) { + return ResultMessageUtil.exceptionToJSON(new BusinessException("表头表体数据为空")); + } + // 将json转换为产成品入库VO + Map headInfo = (Map) map.get(HEADTABLE); + List> bodyInfo = (List>) map.get(BODYTABLE); + FinProdInVO aggvo = new FinProdInVO(); + FinProdInHeadVO hvo = new FinProdInHeadVO(); + hvo.setAttributeValue(ICPubMetaNameConst.PK_GROUP, AppContext.getInstance().getPkGroup()); + for (String headkey : headInfo.keySet()) { + hvo.setAttributeValue(headkey, headInfo.get(headkey)); + } + + InvocationInfoProxy.getInstance().setBizDateTime(hvo.getDbilldate().getMillis()); + aggvo.setParentVO(hvo); + List bvoList = new ArrayList<>(); + for (Map bodyMap : bodyInfo) { + FinProdInBodyVO bvo = new FinProdInBodyVO(); + for (String bodykey : bodyMap.keySet()) { + bvo.setAttributeValue(bodykey, bodyMap.get(bodykey)); + } + bvo.setPk_batchcode(bvo.getVbatchcode());// 将批次号注入进去走翻译 + + bvoList.add(bvo); + } + aggvo.setChildrenVO(bvoList.toArray(new FinProdInBodyVO[bvoList.size()])); + aggVOList.add(aggvo); + } + FinProdInVO[] proinVOs = aggVOList.toArray(new FinProdInVO[aggVOList.size()]); + // 将产成品入库按照编码翻译 + BillFieldsCodeToPkUtil.doTranslateVOFields(proinVOs); + + List lastList = new ArrayList(); + for (FinProdInVO proinVO : proinVOs) { + FinProdInVO lastAgg = new FinProdInVO(); + FinProdInHeadVO headVO = (FinProdInHeadVO) proinVO.getParentVO();// 表头 + FinProdInBodyVO[] proinBVOs = proinVO.getBodys();// 表体 + // 1.根据产成品入库单表体查询出上游来源单据(生产报告) + AggWrVO[] wrAggs = this.getWrByFinProdBodys(proinBVOs); + + // 2.模仿前台合格入库,构造生产报告质量信息WrQualityVO + this.fillquality(wrAggs); + + // 3.将产成品入库的部分进行过滤 + AggWrVO[] aggWrVOs = service.prodInFilter(wrAggs); + + + if (aggWrVOs == null || aggWrVOs[0].getChildrenVO() == null) { + throw new BusinessException("未查到对应的生产报告,或生产报告已生成入库单"); + } + // 4.调用转换规则 + FinProdInVO[] transVOs = this.wrChange46(aggWrVOs, headVO); + // 获取转换后的单据表头信息 + FinProdInHeadVO tranhead = transVOs[0].getHead(); + // 获取转换后的单据表体信息 + Map tranbMap = new HashMap(); + for (FinProdInVO tranAggs : transVOs) { + FinProdInBodyVO[] items = (FinProdInBodyVO[]) tranAggs.getChildrenVO(); + for (FinProdInBodyVO item : items) { + tranbMap.put(item.getVsourcerowno(), item); + } + } + // 3.处理表头 + tranhead.setPk_org(headVO.getPk_org()); + tranhead.setDbilldate(headVO.getDbilldate()); + tranhead.setCwarehouseid(headVO.getCwarehouseid()); + tranhead.setVtrantypecode(headVO.getVtrantypecode()); + String ctrantypeid = getValueByCondtion("bd_billtype", " pk_billtypeid ", " istransaction = 'Y' and nvl ( islock, 'N' ) = 'N' and parentbilltype = '46' and pk_group = '" + + InvocationInfoProxy.getInstance().getGroupId() + "' and pk_billtypecode = '" + headVO.getVtrantypecode() + "' "); + tranhead.setCtrantypeid(ctrantypeid); + tranhead.setCbizid(headVO.getCbizid()); + + String Cdptid = getValueByCondtion("org_dept_v", " pk_dept ", " pk_vid='" + tranhead.getCdptvid() + "' "); + if (Cdptid.equals("")) { + throw new BusinessException("生产部门不能为空"); + } + + tranhead.setCdptid(Cdptid); + tranhead.setVnote(headVO.getVnote()); + tranhead.setVdef12(headVO.getVdef12()); + tranhead.setStatus(VOStatus.NEW); + // 4.处理表体 + Integer count = 10; + FinProdInBodyVO[] bodys = new FinProdInBodyVO[proinBVOs.length]; + for (int i = 0; i < proinBVOs.length; i++) { + FinProdInBodyVO proinBVO = proinBVOs[i]; + String vsourcerowno = proinBVO.getVsourcerowno(); + FinProdInBodyVO transbody = tranbMap.get(vsourcerowno); + transbody.setCmaterialvid(proinBVO.getCmaterialvid()); + transbody.setNnum(proinBVO.getNnum()); + transbody.setNassistnum(proinBVO.getNnum()); + transbody.setVbatchcode(proinBVO.getVbatchcode()); + transbody.setPk_batchcode(proinBVO.getPk_batchcode()); + transbody.setDbizdate(proinBVO.getDvalidate()); + transbody.setDproducedate(proinBVO.getDproducedate()); + transbody.setVfree1(proinBVO.getVfree1()); + transbody.setVfree2(proinBVO.getVfree2()); + transbody.setVfree3(proinBVO.getVfree3()); + transbody.setVfree4(proinBVO.getVfree4()); + transbody.setVfree5(proinBVO.getVfree5()); + transbody.setVfree6(proinBVO.getVfree6()); + transbody.setVfree7(proinBVO.getVfree7()); + transbody.setCrowno(String.valueOf(count)); + transbody.setCsourcetype(proinBVO.getCsourcetype()); + transbody.setCsourcebillhid(proinBVO.getCsourcebillhid()); + transbody.setVnotebody(proinBVO.getVnotebody()); + transbody.setVproductbatch(proinBVO.getVproductbatch()); + scddid = proinBVO.getVproductbatch(); + count = count + 10; + transbody.setStatus(VOStatus.NEW); + bodys[i] = transbody; + } + lastAgg.setParentVO(tranhead); + lastAgg.setChildrenVO(bodys); + lastList.add(lastAgg); + } + IProductInPubServiceFor55A4 productService = NCLocator.getInstance().lookup(IProductInPubServiceFor55A4.class); + FinProdInVO[] results = productService.pushSave(lastList.toArray(new FinProdInVO[0])); + List hpklist = new ArrayList(); + + for (FinProdInVO result : results) { + String hpk = result.getParentVO().getPrimaryKey(); + hpklist.add(hpk); + } + // 更新产成品入库关闭时间 + + + // 自动签字代码 + SCMBillQuery queryTool = new SCMBillQuery(FinProdInVO.class); + FinProdInVO[] prodInVOs = queryTool.queryVOByIDs(hpklist.toArray(new String[0])); + if (prodInVOs.length == 0) { + return NCCRestUtils.toJSONString(CallReturnBuildUtil.buildHeadBodyResult()); + } else { + for (int i = 0; i < prodInVOs.length; i++) { + + FinProdInBodyVO[] bvos = prodInVOs[i].getBodys(); + for (int j = 0; j < bvos.length; j++) { + String scddh = bvos[j].getCfirstbillbid(); + String pk_org = prodInVOs[i].getHead().getPk_org(); + UFDate dbildate = prodInVOs[i].getHead().getDbilldate(); + String sql = " update mm_mo set tmoclosedtime='" + dbildate + "' where cmoid='" + scddh + "' and pk_org='" + pk_org + "' and dr=0 "; + getDao().executeUpdate(sql); + } + + } + prodInVOs = nc.bs.framework.common.NCLocator.getInstance().lookup(IAPIProductInMaitain.class).sign(prodInVOs); + } + return ResultMessageUtil.toJSON(proinVOs, nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("4008027_0", + "04008027-0434")/* @res "产成品入库单保存成功" */); + } catch (Exception e) { + return ResultMessageUtil.exceptionToJSON(new BusinessException("失败!" + e.getMessage())); + } + } + + + /** + * 生产报告提交 + */ + @POST + @Path("/commitPmoReport") + @Consumes({"application/json"}) + @Produces({"application/json"}) + public JSONString commitPmoReport(JSONString json1) throws BusinessException { + if (json1 == null) { + return ResultMessageUtil.toJSON("失败!参数不能为空"); + } + + JSONArray jObject = JSON.parseArray(json1.toString()); + if (jObject == null) { + return ResultMessageUtil.exceptionToJSON(new BusinessException("失败!参数不能为空")); + } + ArrayList> map = new ArrayList>(); + + + for (int i = 0; i < jObject.size(); i++) { + + Map pkmap = new HashMap(); + + + try { + JSONObject ssjson = jObject.getJSONObject(i); + String id = ssjson.getString("id"); + pkmap.put("id", id); + String usercode = ssjson.getString("usercode"); + if (StringUtils.isBlank(id) || StringUtils.isBlank(usercode)) { + throw new BusinessException("失败!参数id/usercode不能为空"); + } + String userid = getPk("sm_user", "cuserid", "user_code", usercode, ""); + if (userid.equals("")) { + throw new BusinessException("审核人不存在" + usercode); + } + InvocationInfoProxy.getInstance().setUserId(userid); + + IPMOQueryService query = (IPMOQueryService) NCLocator.getInstance().lookup(IPMOQueryService.class); + String[] ids = new String[1]; + ids[0] = id; + + PMOAggVO[] rvo = query.queryByPks(ids); + if (null == rvo || rvo.length == 0) { + throw new BusinessException("失败!未找到对应单据,请检查id值"); + } + Integer fbillstatus = rvo[0].getParentVO().getFbillstatus(); + if (fbillstatus != null && fbillstatus != 0) { + throw new BusinessException("失败!自由态的单据才可以审批"); + } + CloudPFlowContext context = new CloudPFlowContext(); + context.setBillType("55A2"); + context.setActionName("SAVE"); + context.setBillVos(rvo); + IBatchRunScriptService batchRunScriptService = NCLocator.getInstance().lookup(IBatchRunScriptService.class); + batchRunScriptService.runBacth(context, PMOAggVO.class); + pkmap.put("status", "0"); + map.add(pkmap); + } catch (BusinessException e) { + pkmap.put("errmsg", e.getMessage()); + pkmap.put("status", "1"); + map.add(pkmap); + } + + } + + + return ResultMessageUtil.toJSON(map); + } + + + /** + * 流程生产订单行投放 + */ + @POST + @Path("/putRowPmoReport") + @Consumes({"application/json"}) + @Produces({"application/json"}) + public JSONString putRowPmoReport(JSONString json1) throws BusinessException { + if (json1 == null) { + return ResultMessageUtil.toJSON("失败!参数不能为空"); + } + + JSONArray jObject = JSON.parseArray(json1.toString()); + if (jObject == null) { + return ResultMessageUtil.exceptionToJSON(new BusinessException("失败!参数不能为空")); + } + ArrayList> map = new ArrayList>(); + + + for (int i = 0; i < jObject.size(); i++) { + + Map pkmap = new HashMap(); + + + try { + JSONObject ssjson = jObject.getJSONObject(i); + String id = ssjson.getString("id"); + String rowid = ssjson.getString("rowid"); + pkmap.put("id", id); + + pkmap.put("rowid", rowid); + String usercode = ssjson.getString("usercode"); + if (StringUtils.isBlank(id) || StringUtils.isBlank(usercode) || StringUtils.isBlank(rowid)) { + throw new BusinessException("失败!参数id/usercode不能为空"); + } + String userid = getPk("sm_user", "cuserid", "user_code", usercode, ""); + if (userid.equals("")) { + throw new BusinessException("审核人不存在" + usercode); + } + InvocationInfoProxy.getInstance().setUserId(userid); + + IPMOQueryService query = (IPMOQueryService) NCLocator.getInstance().lookup(IPMOQueryService.class); + String[] ids = new String[1]; + ids[0] = id; + + PMOAggVO[] rvo = query.queryByPks(ids); + if (null == rvo || rvo.length == 0) { + throw new BusinessException("失败!未找到对应单据,请检查id值"); + } + Integer fbillstatus = rvo[0].getParentVO().getFbillstatus(); + if (fbillstatus != null && fbillstatus != 1) { + throw new BusinessException("失败!审核通过后能投放"); + } + PMOItemVO[] vbos = rvo[i].getChildrenVO(); + + ArrayList arrb = new ArrayList(); + if (vbos != null && vbos.length > 0) { + for (int j = 0; j < vbos.length; j++) { + if (vbos[j].getCmoid().equals(rowid) && vbos[j].getFitemstatus() == 4) { + arrb.add(vbos[j]); + } + } + } + if (arrb.size() < 1) { + throw new BusinessException("投放的rowid不存在或已投放"); + } + rvo[i].setChildrenVO(arrb.toArray(new PMOItemVO[arrb.size()])); + IPMOBusinessService batchRunScriptService = NCLocator.getInstance().lookup(IPMOBusinessService.class); + batchRunScriptService.rowput(rvo); + pkmap.put("status", "0"); + map.add(pkmap); + } catch (BusinessException e) { + pkmap.put("errmsg", e.getMessage()); + pkmap.put("status", "1"); + map.add(pkmap); + } + + } + + return ResultMessageUtil.toJSON(map); + } + + /** + * 生产报告审核 + */ + @POST + @Path("/putPmoReport") + @Consumes({"application/json"}) + @Produces({"application/json"}) + public JSONString putPmoReport(JSONString json1) throws BusinessException { + if (json1 == null) { + return ResultMessageUtil.toJSON("失败!参数不能为空"); + } + + JSONArray jObject = JSON.parseArray(json1.toString()); + if (jObject == null) { + return ResultMessageUtil.exceptionToJSON(new BusinessException("失败!参数不能为空")); + } + ArrayList> map = new ArrayList>(); + + + for (int i = 0; i < jObject.size(); i++) { + + Map pkmap = new HashMap(); + + + try { + JSONObject ssjson = jObject.getJSONObject(i); + String id = ssjson.getString("id"); + pkmap.put("id", id); + String usercode = ssjson.getString("usercode"); + if (StringUtils.isBlank(id) || StringUtils.isBlank(usercode)) { + throw new BusinessException("失败!参数id/usercode不能为空"); + } + String userid = getPk("sm_user", "cuserid", "user_code", usercode, ""); + if (userid.equals("")) { + throw new BusinessException("审核人不存在" + usercode); + } + InvocationInfoProxy.getInstance().setUserId(userid); + + IPMOQueryService query = (IPMOQueryService) NCLocator.getInstance().lookup(IPMOQueryService.class); + String[] ids = new String[1]; + ids[0] = id; + + PMOAggVO[] rvo = query.queryByPks(ids); + if (null == rvo || rvo.length == 0) { + throw new BusinessException("失败!未找到对应单据,请检查id值"); + } + Integer fbillstatus = rvo[0].getParentVO().getFbillstatus(); + if (fbillstatus != null && fbillstatus != 1) { + throw new BusinessException("失败!审核通过后能投放"); + } + IPMOBusinessService batchRunScriptService = NCLocator.getInstance().lookup(IPMOBusinessService.class); + batchRunScriptService.rowput(rvo); + pkmap.put("status", "0"); + map.add(pkmap); + } catch (BusinessException e) { + pkmap.put("errmsg", e.getMessage()); + pkmap.put("status", "1"); + map.add(pkmap); + } + + } + + return ResultMessageUtil.toJSON(map); + } + + private Map validateData(JSONObject headObj, JSONArray bodyObj) { + Map dataMap = new HashMap<>(); + BaseDAO baseDAO = new BaseDAO(); + + String sql = ""; + String pk_group = (String) headObj.get("pk_group"); + if (StringUtils.isBlank(pk_group)) { + dataMap.put("code", "2"); + dataMap.put("data", "head的pk_group不能为空"); + return dataMap; + } + String groupName = ""; + try { + sql = " select name from org_group where pk_group = '" + pk_group + "' "; + groupName = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + if (StringUtils.isEmpty(groupName)) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的集团"); + return dataMap; + } + } catch (Exception e) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的集团"); + return dataMap; + } + JSONObject pkGroup = new JSONObject(); + pkGroup.put("value", pk_group); + pkGroup.put("display", groupName); + + String pk_org = (String) headObj.get("pk_org"); + if (StringUtils.isBlank(pk_org)) { + dataMap.put("code", "2"); + dataMap.put("data", "head的pk_org不能为空"); + return dataMap; + } + String orgName = ""; + try { + sql = " select name from org_orgs where pk_org = '" + pk_org + "' "; + orgName = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + if (StringUtils.isEmpty(orgName)) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的组织"); + return dataMap; + } + } catch (Exception e) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的组织"); + return dataMap; + } + JSONObject pkOrg = new JSONObject(); + pkOrg.put("value", pk_org); + pkOrg.put("display", orgName); + + String pk_org_v = (String) headObj.get("pk_org_v"); + if (StringUtils.isBlank(pk_org_v)) { + dataMap.put("code", "2"); + dataMap.put("data", "head的pk_org_v不能为空"); + return dataMap; + } + String orgVName = ""; + try { + sql = " select name from org_orgs_v where pk_vid = '" + pk_org_v + "' "; + orgVName = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + if (StringUtils.isEmpty(orgVName)) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的组织版本"); + return dataMap; + } + } catch (Exception e) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的组织版本"); + return dataMap; + } + JSONObject pkOrgv = new JSONObject(); + pkOrgv.put("value", pk_org_v); + pkOrgv.put("display", orgVName); + + String vtrantypeid = (String) headObj.get("vtrantypeid"); + if (StringUtils.isBlank(vtrantypeid)) { + dataMap.put("code", "2"); + dataMap.put("data", "head的vtrantypeid不能为空"); + return dataMap; + } + String trantypeName = ""; + try { + sql = " select billtypename from bd_billtype where pk_billtypeid = '" + vtrantypeid + "' "; + trantypeName = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + if (StringUtils.isEmpty(trantypeName)) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的报告类型"); + return dataMap; + } + } catch (Exception e) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的报告类型"); + return dataMap; + } + JSONObject trantype = new JSONObject(); + trantype.put("value", vtrantypeid); + trantype.put("display", trantypeName); + + String fprodmode = (String) headObj.get("fprodmode"); + if (StringUtils.isBlank(fprodmode)) { + dataMap.put("code", "2"); + dataMap.put("data", "head的fprodmode不能为空"); + return dataMap; + } + JSONObject hfprodmode = new JSONObject(); + hfprodmode.put("value", fprodmode); + hfprodmode.put("display", "1".equals(fprodmode) ? "流程制造" : "离散制造"); + + String cdeptvid = (String) headObj.get("cdeptvid"); + if (StringUtils.isBlank(cdeptvid)) { + JSONObject deptv = new JSONObject(); + deptv.put("value", ""); + deptv.put("display", ""); + } else { + String deptvName = ""; + try { + sql = " select name from org_dept_v where pk_vid = '" + cdeptvid + "' "; + deptvName = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + if (StringUtils.isEmpty(deptvName)) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的组织_部门版本"); + return dataMap; + } + } catch (Exception e) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的组织_部门版本"); + return dataMap; + } + JSONObject deptv = new JSONObject(); + deptv.put("value", cdeptvid); + deptv.put("display", deptvName); + } + + String cdeptid = (String) headObj.get("cdeptid"); + String deptName = ""; + if (StringUtils.isBlank(cdeptid)) { + JSONObject dept = new JSONObject(); + dept.put("value", ""); + dept.put("display", ""); + } else { + try { + sql = " select name from org_dept where pk_dept = '" + cdeptid + "' "; + deptName = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + if (StringUtils.isEmpty(deptName)) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的部门"); + return dataMap; + } + } catch (Exception e) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的部门"); + return dataMap; + } + JSONObject dept = new JSONObject(); + dept.put("value", cdeptid); + dept.put("display", deptName); + } + + String cwkid = (String) headObj.get("cwkid"); + if (StringUtils.isEmpty(cwkid)) { + JSONObject cwk = new JSONObject(); + cwk.put("value", ""); + cwk.put("display", ""); + + JSONObject cwkidVwkname = new JSONObject(); + cwkidVwkname.put("value", ""); + } else { + String cwkName = ""; + try { + sql = " select vwkname from bd_wk where cwkid = '" + cwkid + "' "; + cwkName = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + if (StringUtils.isEmpty(cwkName)) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的工作中心"); + return dataMap; + } + } catch (Exception e) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的工作中心"); + return dataMap; + } + JSONObject cwk = new JSONObject(); + cwk.put("value", cwkid); + cwk.put("display", cwkName); + + JSONObject cwkidVwkname = new JSONObject(); + cwkidVwkname.put("value", cwkName); + } + + String cteamid = (String) headObj.get("cteamid"); + if (StringUtils.isBlank(cteamid)) { + JSONObject cteam = new JSONObject(); + cteam.put("value", ""); + cteam.put("display", ""); + } else { + String cteamidName = ""; + try { + sql = " select vteamname from bd_team where cteamid = '" + cteamid + "' "; + cteamidName = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + if (StringUtils.isEmpty(cteamidName)) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的班组"); + return dataMap; + } + } catch (Exception e) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的班组"); + return dataMap; + } + JSONObject cteam = new JSONObject(); + cteam.put("value", cteamid); + cteam.put("display", cteamidName); + } + + String cshiftid = (String) headObj.get("cshiftid"); + if (StringUtils.isBlank(cshiftid)) { + JSONObject cshift = new JSONObject(); + cshift.put("value", ""); + cshift.put("display", ""); + } else { + String cshiftidName = ""; + try { + sql = " select name from bd_shift where pk_shift = '" + cshiftid + "' "; + cshiftidName = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + if (StringUtils.isEmpty(cshiftidName)) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的班次"); + return dataMap; + } + } catch (Exception e) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的班次"); + return dataMap; + } + JSONObject cshift = new JSONObject(); + cshift.put("value", cshiftid); + cshift.put("display", cshiftidName); + } + + String cworkmanid = (String) headObj.get("cworkmanid"); + String cworkmanName = ""; + if (StringUtils.isBlank(cworkmanid)) { + JSONObject workman = new JSONObject(); + workman.put("value", ""); + workman.put("display", ""); + } else { + try { + sql = " select name from bd_psndoc where pk_psndoc = '" + cworkmanid + "' "; + cworkmanName = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + if (StringUtils.isEmpty(cworkmanName)) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的作业员"); + return dataMap; + } + } catch (Exception e) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的作业员"); + return dataMap; + } + JSONObject workman = new JSONObject(); + workman.put("value", cworkmanid); + workman.put("display", cworkmanName); + } + + String dbilldate = (String) headObj.get("dbilldate"); + if (StringUtils.isBlank(dbilldate)) { + dataMap.put("code", "2"); + dataMap.put("data", "head的dbilldate不能为空"); + return dataMap; + } else { + JSONObject billdate = new JSONObject(); + billdate.put("value", dbilldate); + } + + String vdef1 = (String) headObj.get("vdef1"); + String vdef2 = (String) headObj.get("vdef2"); + String vdef3 = (String) headObj.get("vdef3"); + String vdef4 = (String) headObj.get("vdef4"); + String vdef5 = (String) headObj.get("vdef5"); + String vdef6 = (String) headObj.get("vdef6"); + String vdef7 = (String) headObj.get("vdef7"); + String vdef8 = (String) headObj.get("vdef8"); + String vdef9 = (String) headObj.get("vdef9"); + String vdef10 = (String) headObj.get("vdef10"); + String vdef11 = (String) headObj.get("vdef11"); + String vdef12 = (String) headObj.get("vdef12"); + String vdef13 = (String) headObj.get("vdef13"); + String vdef14 = (String) headObj.get("vdef14"); + String vdef15 = (String) headObj.get("vdef15"); + String vdef16 = (String) headObj.get("vdef16"); + String vdef17 = (String) headObj.get("vdef17"); + String vdef18 = (String) headObj.get("vdef18"); + String vdef19 = (String) headObj.get("vdef19"); + String vdef20 = (String) headObj.get("vdef20"); + + String vnote = (String) headObj.get("vnote"); + + String billmaker = (String) headObj.get("billmaker"); + String billmakerName = ""; + if (StringUtils.isBlank(billmaker)) { + dataMap.put("code", "2"); + dataMap.put("data", "head的billmaker不能为空"); + return dataMap; + } else { + try { + sql = " select user_name from sm_user where cuserid = '" + billmaker + "' "; + billmakerName = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + if (StringUtils.isEmpty(billmakerName)) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的用户"); + return dataMap; + } + } catch (Exception e) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的用户"); + return dataMap; + } + JSONObject hbillmaker = new JSONObject(); + hbillmaker.put("value", billmaker); + hbillmaker.put("display", billmakerName); + } + + String dmakedate = (String) headObj.get("dmakedate"); + if (StringUtils.isBlank(dmakedate)) { + dataMap.put("code", "2"); + dataMap.put("data", "head的dmakedate不能为空"); + return dataMap; + } + JSONObject hdmakedate = new JSONObject(); + hdmakedate.put("value", dmakedate); + + String creator = (String) headObj.get("creator"); + String creatorName = ""; + if (StringUtils.isBlank(creator)) { + dataMap.put("code", "2"); + dataMap.put("data", "head的creator不能为空"); + return dataMap; + } else { + try { + sql = " select user_name from sm_user where cuserid = '" + creator + "' "; + creatorName = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + if (StringUtils.isEmpty(creatorName)) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的用户"); + return dataMap; + } + } catch (Exception e) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的用户"); + return dataMap; + } + JSONObject hcreator = new JSONObject(); + hcreator.put("value", creator); + hcreator.put("display", creatorName); + } + + String creationtime = (String) headObj.get("creationtime"); + if (StringUtils.isBlank(creationtime)) { + dataMap.put("code", "2"); + dataMap.put("data", "head的creationtime不能为空"); + return dataMap; + } + JSONObject hcreationtime = new JSONObject(); + hcreationtime.put("value", creationtime); + + JSONObject vtrantypecode = new JSONObject(); + vtrantypecode.put("value", "55A4-01"); + + List bvoItemList = new ArrayList<>(); + // 封装bodys + Set rownoSet = new HashSet<>(); + for (int i = 0; i < bodyObj.size(); i++) { + JSONObject item = new JSONObject(); + try { + item = (JSONObject) bodyObj.get(i); + } catch (Exception e) { + e.printStackTrace(); + } + + // 入库批次号 + String vbinbatchcode = (String) item.get("vbinbatchcode"); + + // 计划完工主数量 + String nbplanwrnum = (String) item.get("nbplanwrnum"); + + // cbmoid 生产订单 + // cbmobid 生产订单行id + String cbmoid = (String) item.get("cbmoid"); + String cbmobid = (String) item.get("cbmobid"); + String vbmobillcode = ""; + String vbmorowno = ""; + if (StringUtils.isBlank(cbmoid) || StringUtils.isBlank(cbmobid)) { + } else { + try { + sql = " select vbillcode from mm_pmo where cpmohid = '" + cbmoid + "' "; + vbmobillcode = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + if (StringUtils.isEmpty(vbmobillcode)) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的流程生产订单"); + return dataMap; + } + } catch (Exception e) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的流程生产订单"); + return dataMap; + } + JSONObject bcbmoid = new JSONObject(); + bcbmoid.put("value", cbmoid); + + JSONObject bvbmobillcode = new JSONObject(); + bvbmobillcode.put("value", vbmobillcode); + + try { + sql = " select vrowno from mm_mo where cmoid = '" + cbmobid + "' "; + vbmorowno = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + if (StringUtils.isEmpty(vbmorowno)) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的流程生产订单明细"); + return dataMap; + } + } catch (Exception e) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的流程生产订单"); + return dataMap; + } + + JSONObject bcbmobid = new JSONObject(); + bcbmobid.put("value", cbmobid); + + JSONObject bvbmorowno = new JSONObject(); + bvbmorowno.put("value", vbmorowno); + } + // vbmoparentbillcode 上级生产订单号 +// String vbmoparentbillcode = (String) item.get("vbmoparentbillcode"); + + // cbfirstmoid 源头生产订单id + String cbfirstmoid = (String) item.get("cbfirstmoid"); + // vbfirstmocode 源头生产订单号 + String vbfirstmocode = ""; + // cbfirstmobid 源头生产订单行id + String cbfirstmobid = (String) item.get("cbfirstmobid"); + String vbfirstmorowno = ""; + // vbfirstmorowno 源头生产订单行号 + if (StringUtils.isBlank(cbfirstmoid) || StringUtils.isBlank(cbfirstmobid)) { + } else { + try { + sql = " select vbillcode from mm_pmo where cpmohid = '" + cbfirstmoid + "' "; + vbfirstmocode = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + if (StringUtils.isEmpty(vbfirstmocode)) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的流程生产订单"); + return dataMap; + } + } catch (Exception e) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的流程生产订单"); + return dataMap; + } + JSONObject bcbfirstmoid = new JSONObject(); + bcbfirstmoid.put("value", cbfirstmoid); + + JSONObject bvbfirstmocode = new JSONObject(); + bvbfirstmocode.put("value", vbfirstmocode); + + try { + sql = " select vrowno from mm_mo where cmoid = '" + cbfirstmobid + "' "; + vbfirstmorowno = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + if (StringUtils.isEmpty(vbfirstmorowno)) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的流程生产订单明细"); + return dataMap; + } + } catch (Exception e) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的流程生产订单"); + return dataMap; + } + + JSONObject bcbfirstmobid = new JSONObject(); + bcbfirstmobid.put("value", cbfirstmobid); + + JSONObject bvbfirstmorowno = new JSONObject(); + bvbfirstmorowno.put("value", vbfirstmorowno); + } + + // cbsrcmoid 来源生产订单id + String cbsrcmoid = (String) item.get("cbsrcmoid"); + // vbsrcmocode 来源生产订单号 + String vbsrcmocode = ""; + // cbsrcmobid 来源生产订单行 + String cbsrcmobid = (String) item.get("cbsrcmobid"); + // vbsrcmorowno 来源生产订单行号 + String vbsrcmorowno = ""; + if (StringUtils.isBlank(cbsrcmoid) || StringUtils.isBlank(cbsrcmobid)) { + } else { + try { + sql = " select vbillcode from mm_pmo where cpmohid = '" + cbsrcmoid + "' "; + vbsrcmocode = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + if (StringUtils.isEmpty(vbsrcmocode)) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的流程生产订单"); + return dataMap; + } + } catch (Exception e) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的流程生产订单"); + return dataMap; + } + JSONObject bcbsrcmoid = new JSONObject(); + bcbsrcmoid.put("value", cbsrcmoid); + + JSONObject bvbsrcmocode = new JSONObject(); + bvbsrcmocode.put("value", vbsrcmocode); + + try { + sql = " select vrowno from mm_mo where cmoid = '" + cbsrcmobid + "' "; + vbsrcmorowno = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + if (StringUtils.isEmpty(vbsrcmorowno)) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的流程生产订单明细"); + return dataMap; + } + } catch (Exception e) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的流程生产订单"); + return dataMap; + } + + JSONObject bcbsrcmobid = new JSONObject(); + bcbsrcmobid.put("value", cbsrcmobid); + + JSONObject vvbsrcmorowno = new JSONObject(); + vvbsrcmorowno.put("value", vbsrcmorowno); + } + + + // cbfirstranstype 源头交易类型 + String cbfirstranstype = (String) item.get("cbfirstranstype"); + // vbfirstranstype 源头交易类型编码 + String vbfirstranstype = (String) item.get("vbfirstranstype"); + // 源头单据类型 + String vbfirsttype = (String) item.get("vbfirsttype"); + // vbfirstid 源头单据id + String vbfirstid = (String) item.get("vbfirstid"); + // 源头单据号 vbfirstcode + String vbfirstcode = (String) item.get("vbfirstcode"); + // vbfirstrowid 源头单据明细id + String vbfirstrowid = (String) item.get("vbfirstrowid"); + // vbfirstrowno 源头单据行号 + String vbfirstrowno = (String) item.get("vbfirstrowno"); + + // cbsrctranstype 来源交易类型 + String cbsrctranstype = (String) item.get("cbsrctranstype"); + // 来源交易类型编码 vbsrctranstype + String vbsrctranstype = (String) item.get("vbsrctranstype"); + // cbsrctype 来源单据类型 + String cbsrctype = (String) item.get("cbsrctype"); + // 来源单据 + String vbsrcid = (String) item.get("vbsrcid"); + // vbsrccode 来源单据号 + String vbsrccode = (String) item.get("vbsrccode"); + // vbsrcrowid 来源单据明细 + String vbsrcrowid = (String) item.get("vbsrcrowid"); + // vbsrcrowno 来源单据行号 + String vbsrcrowno = (String) item.get("vbsrcrowno"); + + String cbmaterialvid = (String) item.get("cbmaterialvid"); + if (StringUtils.isBlank(cbmaterialvid)) { + dataMap.put("code", "2"); + dataMap.put("data", "body的cbmaterialvid不能为空"); + return dataMap; + } + String materialvName = ""; + String materialvCode = ""; + String materialspec = ""; + String version = ""; + String graphid = ""; + String materialtype = ""; + List> materialMapList = new ArrayList<>(); + try { + sql = " select name, code, materialspec, version, graphid, materialtype from bd_material where pk_material = '" + cbmaterialvid + "' "; + materialMapList = (List>) baseDAO.executeQuery(sql, new MapListProcessor()); + if (materialMapList == null || materialMapList.size() == 0) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的物料"); + return dataMap; + } + Map materialMap = materialMapList.get(0); + materialvName = (String) materialMap.get("name"); + materialvCode = (String) materialMap.get("code"); + materialspec = (String) materialMap.get("materialspec"); + version = ((Integer) materialMap.get("version")).toString(); + graphid = (String) materialMap.get("graphid"); + materialtype = (String) materialMap.get("materialtype"); + } catch (Exception e) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的物料"); + return dataMap; + } + JSONObject bcbmaterialType = new JSONObject(); + bcbmaterialType.put("value", materialtype); + bcbmaterialType.put("display", materialtype); + + String nbwrastnum = (String) item.get("nbwrastnum"); + if (StringUtils.isBlank(nbwrastnum)) { + dataMap.put("code", "2"); + dataMap.put("data", "body的nbwrastnum不能为空"); + return dataMap; + } + + String nbplanwrastnum = (String) item.get("nbplanwrastnum"); + + String fbproducttype = (String) item.get("fbproducttype"); + if (StringUtils.isBlank(fbproducttype)) { + dataMap.put("code", "2"); + dataMap.put("data", "body的fbproducttype不能为空"); + return dataMap; + } else { + String fbproducttypeName = ""; + switch (fbproducttype) { + case "1": + fbproducttypeName = "主产品"; + break; + case "2": + fbproducttypeName = "联产品"; + break; + case "3": + fbproducttypeName = "副产品"; + break; + default: + fbproducttypeName = "主产品"; + break; + } + JSONObject bfbproducttype = new JSONObject(); + bfbproducttype.put("display", fbproducttypeName); + bfbproducttype.put("value", fbproducttype); + } + + JSONObject bmaterialvidName = new JSONObject(); + bmaterialvidName.put("display", materialvName); + bmaterialvidName.put("value", materialvName); + + String cbmainmaterialid = (String) item.get("cbmainmaterialid"); + if (StringUtils.isBlank(cbmainmaterialid)) { + dataMap.put("code", "2"); + dataMap.put("data", "body的cbmainmaterialid不能为空"); + return dataMap; + } + String mainmaterialName = ""; + try { + sql = " select name from bd_material_v where pk_source = '" + cbmainmaterialid + "' "; + mainmaterialName = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + if (StringUtils.isBlank(mainmaterialName)) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的物料"); + return dataMap; + } + } catch (Exception e) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的物料"); + return dataMap; + } + JSONObject bcbmainmaterialid = new JSONObject(); + bcbmainmaterialid.put("value", cbmainmaterialid); + bcbmainmaterialid.put("display", mainmaterialName); + + String vbrowno = (String) item.get("vbrowno"); + if (StringUtils.isBlank(vbrowno)) { + dataMap.put("code", "2"); + dataMap.put("data", "body的vbrowno不能为空"); + return dataMap; + } else { + if (rownoSet.contains(vbrowno)) { + dataMap.put("code", "2"); + dataMap.put("data", "body的vbrowno不能重复"); + return dataMap; + } else { + rownoSet.add(vbrowno); + } + } + JSONObject bvbrowno = new JSONObject(); + bvbrowno.put("value", vbrowno); + + JSONObject bcbmaterialvid = new JSONObject(); + bcbmaterialvid.put("value", cbmaterialvid); + bcbmaterialvid.put("display", materialvName); + + String cbdeptvid = (String) item.get("cbdeptvid"); + if (StringUtils.isBlank(cbdeptvid)) { + dataMap.put("code", "2"); + dataMap.put("data", "body的cbdeptvid不能为空"); + return dataMap; + } else { + String bdeptName = ""; + try { + sql = " select name from org_dept_v where pk_vid = '" + cbdeptvid + "' "; + bdeptName = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + if (StringUtils.isEmpty(bdeptName)) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的组织_部门版本"); + return dataMap; + } + } catch (Exception e) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的组织_部门版本"); + return dataMap; + } + JSONObject dept = new JSONObject(); + dept.put("value", cbdeptvid); + dept.put("display", bdeptName); + } + + String cbwkid = (String) item.get("cbwkid"); + String vwkname = ""; + if (!StringUtils.isBlank(cbwkid)) { + try { + sql = " select vwkname from bd_wk where cwkid = '" + cbwkid + "' "; + vwkname = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + if (StringUtils.isEmpty(vwkname)) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的工作中心"); + return dataMap; + } + } catch (Exception e) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的工作中心"); + return dataMap; + } + JSONObject bcbwkid = new JSONObject(); + bcbwkid.put("value", cbwkid); + bcbwkid.put("display", vwkname); + } + + String cbprojectid = (String) item.get("cbprojectid"); + if (!StringUtils.isBlank(cbprojectid)) { + String projectname = ""; + try { + sql = " select project_name from bd_project where pk_project = '" + cbprojectid + "' "; + projectname = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + if (StringUtils.isEmpty(projectname)) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的项目"); + return dataMap; + } + } catch (Exception e) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的项目"); + return dataMap; + } + JSONObject bcbprojectid = new JSONObject(); + bcbprojectid.put("value", cbprojectid); + bcbprojectid.put("display", projectname); + } + + String vbidentify = (String) item.get("vbidentify"); + JSONObject bvbidentify = new JSONObject(); + bvbidentify.put("value", vbidentify); + + if (!StringUtils.isBlank(cworkmanid)) { + JSONObject workman = new JSONObject(); + workman.put("value", cworkmanid); + workman.put("display", cworkmanName); + } + + // vbbatchid 生产批次 + String vbbatchid = (String) item.get("vbbatchid"); + String vbbatchcode = ""; + if (!StringUtils.isBlank(vbbatchid)) { + try { + sql = " select vprodbatchcode from pd_pb where pk_batchcode = '" + vbbatchid + "' "; + vbbatchcode = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + if (StringUtils.isEmpty(vbbatchcode)) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的生产批次档案"); + return dataMap; + } + } catch (Exception e) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的生产批次档案"); + return dataMap; + } + JSONObject bvbbatchid = new JSONObject(); + bvbbatchid.put("value", vbbatchid); + } + + String cbshiftid = (String) item.get("cbshiftid"); + if (!StringUtils.isBlank(cbshiftid)) { + String cbshiftidName = ""; + try { + sql = " select name from bd_shift where pk_shift = '" + cbshiftid + "' "; + cbshiftidName = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + if (StringUtils.isEmpty(cbshiftidName)) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的班次"); + return dataMap; + } + } catch (Exception e) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的班次"); + return dataMap; + } + JSONObject cbshift = new JSONObject(); + cbshift.put("value", cshiftid); + cbshift.put("display", cbshiftidName); + } + + String tbstarttime = (String) item.get("tbstarttime"); + if (StringUtils.isBlank(tbstarttime)) { + dataMap.put("code", "2"); + dataMap.put("data", "body的tbstarttime不能为空"); + return dataMap; + } else { + JSONObject btbstarttime = new JSONObject(); + btbstarttime.put("value", tbstarttime); + } + + // cbbomversionid 生产BOM版本 + String cbbomversionid = (String) item.get("cbbomversionid"); + String hversion = ""; + if (!StringUtils.isBlank(cbbomversionid)) { + try { + sql = " select hversion from bd_bom where cbomid = '" + cbbomversionid + "' "; + hversion = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + if (StringUtils.isEmpty(hversion)) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的物料清单"); + return dataMap; + } + } catch (Exception e) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的物料清单"); + return dataMap; + } + JSONObject bcbbomversionid = new JSONObject(); + bcbbomversionid.put("value", cbbomversionid); + bcbbomversionid.put("display", hversion); + } + + // nbwrnum 完工主数量 = nbwrastnum 完工数量 + JSONObject nbwrnum = new JSONObject(); + nbwrnum.put("scale", "4"); + nbwrnum.put("value", nbwrastnum); + + JSONObject pkGroupItem = new JSONObject(); + pkGroupItem.put("value", pkGroup.get("value")); + pkGroupItem.put("display", pkGroup.get("display")); + + if (!StringUtils.isBlank(cbbomversionid)) { + JSONObject vbmainbomcode = new JSONObject(); + vbmainbomcode.put("value", hversion); + + JSONObject cbmainbomid = new JSONObject(); + cbmainbomid.put("value", cbbomversionid); + cbmainbomid.put("display", hversion); + } + + if (!StringUtils.isBlank(cbwkid)) { + JSONObject bvwkname = new JSONObject(); + bvwkname.put("value", vwkname); + } + + String tbendtime = (String) item.get("tbendtime"); + if (StringUtils.isBlank(tbendtime)) { + dataMap.put("code", "2"); + dataMap.put("data", "body的tbendtime不能为空"); + return dataMap; + } else { + JSONObject btbendtime = new JSONObject(); + btbendtime.put("value", tbendtime); + } + JSONObject pkOrgItem = new JSONObject(); + pkOrgItem.put("value", pkOrg.get("value")); + pkOrgItem.put("display", pkOrg.get("display")); + + JSONObject bcbmaterialSpec = new JSONObject(); + bcbmaterialSpec.put("value", materialspec); + bcbmaterialSpec.put("display", materialspec); + + if (!StringUtils.isBlank(cdeptid)) { + JSONObject bdept = new JSONObject(); + bdept.put("value", cdeptid); + bdept.put("display", deptName); + } + + JSONObject cbmainmaterialvid = new JSONObject(); + cbmainmaterialvid.put("value", cbmaterialvid); + cbmainmaterialvid.put("display", materialvCode); + + String cbteamid = (String) item.get("cbteamid"); + String teamName = ""; + if (!StringUtils.isBlank(cbteamid)) { + try { + sql = " select vteamname from bd_team where cteamid = '" + cbteamid + "' "; + teamName = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + if (StringUtils.isEmpty(teamName)) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的班组"); + return dataMap; + } + } catch (Exception e) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的班组"); + return dataMap; + } + JSONObject bcbteamid = new JSONObject(); + bcbteamid.put("value", cbteamid); + bcbteamid.put("display", teamName); + } + + String fbsourcetype = (String) item.get("fbsourcetype"); + if (StringUtils.isBlank(fbsourcetype)) { + dataMap.put("code", "2"); + dataMap.put("data", "body的fbsourcetype不能为空"); + return dataMap; + } else { + String fbsourcetypeName = ""; + switch (fbsourcetype) { + case "1": + fbsourcetypeName = "手工自制"; + break; + case "2": + fbsourcetypeName = "订单报产"; + break; + case "3": + fbsourcetypeName = "工序完工"; + break; + case "4": + fbsourcetypeName = "投放计划"; + break; + case "5": + fbsourcetypeName = "收货单"; + break; + default: + fbsourcetypeName = "手工自制"; + break; + } + JSONObject bfbsourcetype = new JSONObject(); + bfbsourcetype.put("display", fbsourcetypeName); + bfbsourcetype.put("value", fbsourcetype); + } + + JSONObject pkOrgvItem = new JSONObject(); + try { + BeanUtils.copyProperties(pkOrgvItem, pkOrgv); + } catch (Exception e) { + e.printStackTrace(); + } + + if (!StringUtils.isBlank(vbbatchid)) { + JSONObject bvbbatchcode = new JSONObject(); + bvbbatchcode.put("value", vbbatchcode); + bvbbatchcode.put("display", vbbatchcode); + } + + JSONObject bcbmaterialVersion = new JSONObject(); + bcbmaterialVersion.put("value", version); + bcbmaterialVersion.put("display", version); + + JSONObject bmaterialvName = new JSONObject(); + bmaterialvName.put("value", materialvName); + bmaterialvName.put("display", materialvName); + + JSONObject bmaterialvgraphid = new JSONObject(); + bmaterialvgraphid.put("value", graphid); + bmaterialvgraphid.put("display", graphid); + + // vbmainmorowno 主产品行号 todo + String vbmainmorowno = (String) item.get("vbmainmorowno"); + + String cbmaterialid = (String) item.get("cbmaterialid"); + String materialName = ""; + if (StringUtils.isBlank(cbmaterialid)) { + dataMap.put("code", "2"); + dataMap.put("data", "body的cbmaterialid不能为空"); + return dataMap; + } else { + try { + sql = " select name from bd_material_v where pk_source = '" + cbmaterialid + "' "; + materialName = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + if (StringUtils.isEmpty(materialName)) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的物料"); + return dataMap; + } + } catch (Exception e) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的物料"); + return dataMap; + } + JSONObject bcbmaterialid = new JSONObject(); + bcbmaterialid.put("value", cbmaterialid); + bcbmaterialid.put("display", materialName); + } + + String cbastunitid = (String) item.get("cbastunitid"); + String unitName = ""; + if (!StringUtils.isBlank(cbastunitid)) { + try { + sql = " select name from bd_measdoc where pk_measdoc = '" + cbastunitid + "' "; + unitName = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + if (StringUtils.isEmpty(unitName)) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的计量单位"); + return dataMap; + } + } catch (Exception e) { + dataMap.put("code", "2"); + dataMap.put("data", "未查询到相应的计量单位"); + return dataMap; + } + JSONObject bcbunitid = new JSONObject(); + bcbunitid.put("value", cbastunitid); + bcbunitid.put("display", unitName); + + JSONObject bcbastunitid = new JSONObject(); + bcbastunitid.put("value", cbastunitid); + bcbastunitid.put("display", unitName); + } + + WrItemVO bvo = new WrItemVO(); + bvo.setPk_group(pk_group); + bvo.setPk_org(pk_org); + bvo.setPk_org_v(pk_org_v); + bvo.setVbrowno(vbrowno); + bvo.setCbmoid(cbmoid); + bvo.setVbmobillcode(vbmobillcode); + bvo.setCbmobid(cbmobid); + bvo.setVbmorowno(vbmorowno); + // vbmoparentbillcode + bvo.setCbfirstmoid(cbfirstmoid); + bvo.setVbfirstmocode(vbfirstmocode); + bvo.setCbfirstmobid(cbmobid); + bvo.setVbfirstmorowno(vbfirstmorowno); + bvo.setCbsrcmoid(cbsrcmoid); + bvo.setVbsrcmocode(vbsrcmocode); + bvo.setCbsrcmobid(cbsrcmobid); + bvo.setVbsrcmorowno(vbsrcmorowno); + bvo.setFbproducttype(Integer.parseInt(fbproducttype)); + bvo.setCbmaterialid(cbmaterialid); + bvo.setCbmaterialvid(cbmaterialvid); + bvo.setVbmainmorowno(vbmainmorowno); + bvo.setCbbomversionid(cbbomversionid); + bvo.setVbbomversioncode(hversion); +// bvo.setCbpackbomid(cbpackbomid); +// bvo.setCbmainbomid(cbmainbomid); + bvo.setVbmainbomcode(hversion); + bvo.setCbmainmaterialid(cbmainmaterialid); + bvo.setCbmainmaterialvid(cbmaterialvid); + +// bvo.setCbrtversionid(cbrtversionid); +// bvo.setVbrtversioncode(vbrtversioncode); + bvo.setCbdeptid(cdeptid); + bvo.setCbdeptvid(cbdeptvid); + bvo.setCbwkid(cbwkid); + bvo.setCbshiftid(cbshiftid); + bvo.setCbteamid(cbteamid); + bvo.setCbworkmanid(cworkmanid); + bvo.setTbstarttime(new UFDateTime(tbstarttime)); + bvo.setTbendtime(new UFDateTime(tbendtime)); + bvo.setVbbatchid(vbbatchid); + bvo.setVbbatchcode(vbbatchcode); +// bvo.setVbinbatchid(vbinbatchid); + bvo.setVbinbatchcode(vbinbatchcode); + bvo.setFbsourcetype(Integer.parseInt(fbsourcetype)); + bvo.setCbunitid(cbastunitid); + bvo.setCbastunitid(cbastunitid); + bvo.setVbchangerate("1/1"); + bvo.setNbplanwrnum(new UFDouble(nbplanwrnum)); + bvo.setNbplanwrastnum(new UFDouble(nbplanwrastnum)); + bvo.setNbwrnum(new UFDouble(nbwrastnum)); + bvo.setNbwrastnum(new UFDouble(nbwrastnum)); +// bvo.setNbsldinastnum(null); +// bvo.setNbsldinnum(null); +// bvo.setNbsldchecknum(nbsldchecknum); +// bvo.setNbsldcheckastnum(nbsldcheckastnum); +// bvo.setNbchecknum(nbchecknum); +// bvo.setNbcheckastnum(nbcheckastnum); +// bvo.setBbhasbckfled(bbhasbckfled); +// bvo.setBbhaspicked(bbhaspicked); +// bvo.setBbstockbycheck(bbstockbycheck); +// bvo.setBbisempass(bbisempass); +// bvo.setBbchkflag(bbchkflag); +// bvo.setBbinstock(bbinstock); +// bvo.setBbotherreject(bbotherreject); +// bvo.setBbsetmark(bbsetmark); +// bvo.setCbempassid(cbempassid); +// bvo.setCbempass_bid(cbempass_bid); +// bvo.setCbempass_brow(cbempass_brow); +// bvo.setCbempasscode(cbempasscode); +// bvo.setNbempassnum(nbempassnum); +// bvo.setNbempassastnum(nbempassastnum); +// bvo.setNbaldempinnum(nbaldempinastnum); +// bvo.setNbaldempinastnum(nbaldempinastnum); +// bvo.setVbsalebillcode(vbsalebillcode); +// bvo.setVbsalebillid(vbsalebillid); + bvo.setVbsrctranstype(vbsrctranstype); + bvo.setCbsrctranstype(cbsrctranstype); + bvo.setCbsrctype(cbsrctype); + bvo.setVbsrccode(vbsrccode); + bvo.setVbsrcid(vbsrcid); + bvo.setVbsrcrowid(vbsrcrowid); + bvo.setVbsrcrowno(vbsrcrowno); + bvo.setVbfirstranstype(vbfirstranstype); + bvo.setCbfirstranstype(cbfirstranstype); + bvo.setVbfirsttype(vbfirsttype); + bvo.setVbfirstcode(vbfirstcode); + bvo.setVbfirstid(vbfirstid); + bvo.setVbfirstrowid(vbfirstrowid); + bvo.setVbfirstrowno(vbfirstrowno); + bvo.setCbprojectid(cbprojectid); + + bvo.setVbfirstranstype(vbfirstranstype); + bvo.setCbfirstranstype(cbfirstranstype); + bvo.setVbfirsttype(vbfirsttype); + bvo.setVbfirstcode(vbfirstcode); + bvo.setVbfirstid(vbfirstid); + bvo.setVbfirstrowid(vbfirstrowid); + bvo.setVbfirstrowno(vbfirstrowno); + + bvo.setVbsrctranstype(vbsrctranstype); + bvo.setCbsrctranstype(cbsrctranstype); + bvo.setCbsrctype(cbsrctype); + bvo.setVbsrccode(vbsrccode); + bvo.setVbsrcid(vbsrcid); + bvo.setVbsrcrowid(vbsrcrowid); + bvo.setVbsrcrowno(vbsrcrowno); + + bvoItemList.add(bvo); + } + + WrVO hvo = new WrVO(); + hvo.setPk_group(pk_group); + hvo.setPk_org(pk_org); + hvo.setPk_org_v(pk_org_v); + hvo.setVtrantypeid(vtrantypeid); + hvo.setVtrantypecode("55A4-01"); + hvo.setFprodmode(Integer.parseInt(fprodmode)); + hvo.setCdeptid(cdeptid); + hvo.setCdeptvid(cdeptvid); + hvo.setCwkid(cwkid); + hvo.setDbilldate(new UFDate(dbilldate)); + hvo.setCshiftid(cshiftid); + hvo.setCteamid(cteamid); + hvo.setCworkmanid(cworkmanid); + hvo.setFbillstatus(1); + hvo.setVnote(vnote); + hvo.setBillmaker(billmaker); + hvo.setDmakedate(new UFDate(dmakedate)); + hvo.setCreator(creator); + hvo.setCreationtime(new UFDateTime(creationtime)); + hvo.setVdef1(vdef1); + hvo.setVdef2(vdef2); + hvo.setVdef3(vdef3); + hvo.setVdef4(vdef4); + hvo.setVdef5(vdef5); + hvo.setVdef6(vdef6); + hvo.setVdef7(vdef7); + hvo.setVdef8(vdef8); + hvo.setVdef9(vdef9); + hvo.setVdef10(vdef10); + hvo.setVdef11(vdef11); + hvo.setVdef12(vdef12); + hvo.setVdef13(vdef13); + hvo.setVdef14(vdef14); + hvo.setVdef15(vdef15); + hvo.setVdef16(vdef16); + hvo.setVdef17(vdef17); + hvo.setVdef18(vdef18); + hvo.setVdef19(vdef19); + hvo.setVdef20(vdef20); + + WrItemVO[] bvos = bvoItemList.toArray(new WrItemVO[bvoItemList.size()]); + AggWrVO aggWr = new AggWrVO(); + aggWr.setParent(hvo); + aggWr.setChildrenVO(bvos); + + dataMap.put("code", "1"); + dataMap.put("data", aggWr); + return dataMap; + } + + public String getPk(String tablename, String pkfile, String where, String value, String sqlwhere) throws BusinessException { + String sql = " select " + pkfile + " from " + tablename + " where nvl(dr,0)=0 and " + where + "='" + value + "' " + sqlwhere; + Object o = getDao().executeQuery(sql, new ColumnProcessor()); + if (o != null) { + return o.toString(); + } + return ""; + } + + @SuppressWarnings("unchecked") + private AggWrVO[] getWrByFinProdBodys(FinProdInBodyVO[] proinBVOs) throws BusinessException { + + if (proinBVOs == null || proinBVOs.length == 0) { + throw new BusinessException("WMS传入产成品入库表体不能为空,请检查!"); + } + + List srcbpklist = new ArrayList(); + for (FinProdInBodyVO proinBVO : proinBVOs) { + String vsourcerowno = proinBVO.getVsourcerowno();// 来源单据表体主键 + if (StringUtils.isEmpty(vsourcerowno)) { + throw new BusinessException("WMS传入产成品入库表体来源生成报告表体(完工产出)主键不能为空,请检查!"); + } + srcbpklist.add(vsourcerowno); + } + + // 根据来源单据表体主键查询上游单据 + List listaggvo = new ArrayList(); + + String condition = SqlUtils.getInStr("pk_wr_product", srcbpklist.toArray(new String[0]), false); + String bsql = "SELECT * FROM mm_wr_product where nvl(dr,0) =0 and " + condition; + List itemlist = (List) getDao().executeQuery(bsql, new BeanListProcessor(WrItemVO.class)); + + if (itemlist == null || itemlist.size() == 0) { + throw new BusinessException("根据WMS传入来源生产报告表体(完工产出)主键在NCC中找不到对应的生产报告信息,请检查!"); + } + + List hpklist = new ArrayList(); + for (WrItemVO b : itemlist) { + String pk_wr = b.getPk_wr(); + hpklist.add(pk_wr); + } + String hcondition = SqlUtils.getInStr("pk_wr", hpklist.toArray(new String[0]), false); + + String hsql = "SELECT * FROM mm_wr where nvl(dr,0) =0 and " + hcondition; + List wrHeadlist = (List) getDao().executeQuery(hsql, new BeanListProcessor(WrVO.class)); + + // 把表体按照表头主键分类 + Map> map = new HashMap>(); + + for (WrItemVO bodyVO : itemlist) { + if (map.containsKey(bodyVO.getPk_wr())) { + map.get(bodyVO.getPk_wr()).add(bodyVO); + } else { + List bodylist = new ArrayList(); + bodylist.add(bodyVO); + map.put(bodyVO.getPk_wr(), bodylist); + } + } + // 根据表头,匹配表体 + for (WrVO headVo : wrHeadlist) { + AggWrVO aggVO = new AggWrVO(); + if (map.containsKey(headVo.getPk_wr())) { + aggVO.setParent(headVo); + List listBodyVO = map.get(headVo.getPk_wr()); + aggVO.setChildrenVO(listBodyVO.toArray(new WrItemVO[listBodyVO.size()])); + listaggvo.add(aggVO); + } + } + return listaggvo.toArray(new AggWrVO[0]); + } + + public void fillquality(AggWrVO[] wrAggs) { + for (AggWrVO wrAgg : wrAggs) { + WrItemVO[] itemvos = wrAgg.getChildrenVO(); + AggWrVO[] aggvos = null; + try { + aggvos = query.queryByPk(new String[]{wrAgg.getPrimaryKey()}); + } catch (BusinessException e) { + ExceptionUtils.wrappException(e); + } + if (MMValueCheck.isEmpty(aggvos)) { + ExceptionUtils.wrappBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("5008100_0", "05008100-0000")); + } + + Map map = new HashMap(); + Map itemsMap = new HashMap(); + for (AggWrVO vo : aggvos) { + if (MMValueCheck.isNotEmpty(vo.getChildrenVO())) { + for (WrItemVO itemvo : vo.getChildrenVO()) { + itemsMap.put(itemvo.getPrimaryKey(), itemvo); + map.put(itemvo.getPrimaryKey(), itemvo.getQualityvos()); + } + } + } + + for (WrItemVO itemvo : itemvos) { + + itemvo.setQualityvos((WrQualityVO[]) map.get(itemvo.getPrimaryKey())); + itemvo.setCbmaterialid(((WrItemVO) itemsMap.get(itemvo.getPrimaryKey())).getCbmaterialid()); + itemvo.setCbmaterialvid(((WrItemVO) itemsMap.get(itemvo.getPrimaryKey())).getCbmaterialvid()); + itemvo.setCbmainbomid(((WrItemVO) itemsMap.get(itemvo.getPrimaryKey())).getCbmainbomid()); + itemvo.setCbmainmaterialvid(((WrItemVO) itemsMap.get(itemvo.getPrimaryKey())).getCbmainmaterialvid()); + itemvo.setCbmainmaterialid(((WrItemVO) itemsMap.get(itemvo.getPrimaryKey())).getCbmainmaterialid()); + itemvo.setVbbatchid(((WrItemVO) itemsMap.get(itemvo.getPrimaryKey())).getVbbatchid()); + itemvo.setVbbatchcode(((WrItemVO) itemsMap.get(itemvo.getPrimaryKey())).getVbbatchcode()); + itemvo.setVbinbatchid(((WrItemVO) itemsMap.get(itemvo.getPrimaryKey())).getVbinbatchid()); + itemvo.setVbinbatchcode(((WrItemVO) itemsMap.get(itemvo.getPrimaryKey())).getVbinbatchcode()); + itemvo.setCbunitid(((WrItemVO) itemsMap.get(itemvo.getPrimaryKey())).getCbunitid()); + itemvo.setCbastunitid(((WrItemVO) itemsMap.get(itemvo.getPrimaryKey())).getCbastunitid()); + itemvo.setVbmobillcode(((WrItemVO) itemsMap.get(itemvo.getPrimaryKey())).getVbmobillcode()); + itemvo.setVbsrctranstype(((WrItemVO) itemsMap.get(itemvo.getPrimaryKey())).getVbsrctranstype()); + itemvo.setVbsrccode(((WrItemVO) itemsMap.get(itemvo.getPrimaryKey())).getVbsrccode()); + itemvo.setVbmorowno(((WrItemVO) itemsMap.get(itemvo.getPrimaryKey())).getVbmorowno()); + itemvo.setVbfirstcode(((WrItemVO) itemsMap.get(itemvo.getPrimaryKey())).getVbfirstcode()); + itemvo.setCbfirstranstype(((WrItemVO) itemsMap.get(itemvo.getPrimaryKey())).getCbfirstranstype()); + itemvo.setVbchangerate(((WrItemVO) itemsMap.get(itemvo.getPrimaryKey())).getVbchangerate()); + itemvo.setVbfirstmorowno(((WrItemVO) itemsMap.get(itemvo.getPrimaryKey())).getVbfirstmorowno()); + itemvo.setCbsrctranstype(((WrItemVO) itemsMap.get(itemvo.getPrimaryKey())).getCbsrctranstype()); + itemvo.setVbmainmorowno(((WrItemVO) itemsMap.get(itemvo.getPrimaryKey())).getVbmainmorowno()); + itemvo.setVbfirstrowno(((WrItemVO) itemsMap.get(itemvo.getPrimaryKey())).getVbfirstrowno()); + } + } + } + + private FinProdInVO[] wrChange46(AggWrVO[] aggVOs, FinProdInHeadVO headVO) { + WrItemVO[] items = null; + + AggWrVO[] newVOs = new AggWrVO[aggVOs.length]; + for (int i = 0; i < aggVOs.length; i++) { + newVOs[i] = (AggWrVO) aggVOs[i].clone(); + WrTransTypeUtil.changeTransTypeCodeDefault(newVOs[i].getParentVO()); + items = (WrItemVO[]) newVOs[i].getChildren(WrItemVO.class); + + for (WrItemVO item : items) { + if (null == item.getBbisempass() || !item.getBbisempass().booleanValue()) { + item.setNbempassastnum(null); + item.setNbempassnum(null); + item.setCbempass_bid(null); + item.setCbempass_brow(null); + item.setCbempasscode(null); + item.setCbempassid(null); + + } + } + } + + AggWrChangeVO[] aggChangeVOs = WrBusiVOToChangeVO.changeOnlyQualityVO(newVOs); + if (aggChangeVOs == null) { + ExceptionUtils.wrappBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("5008100_0", "05008100-0031")); + } + for (AggWrChangeVO changeAgg : aggChangeVOs) { + WrChangeItemVO[] changebVOs = (WrChangeItemVO[]) changeAgg.getChildrenVO(); + for (WrChangeItemVO changeb : changebVOs) { + changeb.setCgwarehouseid(headVO.getCwarehouseid());// 补充仓库 + + } + } + + try { + return (FinProdInVO[]) PFPubService.runChangeData("55A9", "46", aggChangeVOs, null, 1); + } catch (BusinessException e) { + ExceptionUtils.wrappException(e); + return null; + } + + } + + private String getValueByCondtion(String tablename, String fieldname, String contion) throws BusinessException { + BaseDAO dao = new BaseDAO(); + + String result = ""; + StringBuffer sb = new StringBuffer(); + sb.append(" SELECT " + fieldname + " FROM " + tablename + " "); + sb.append(" WHERE nvl(" + tablename + " .dr,0)= 0 "); + sb.append(" and " + contion + " "); + result = (String) dao.executeQuery(sb.toString(), new ColumnProcessor()); + return result; + } +} diff --git a/pu/src/public/nc/pubitf/pu/m422x/ic/m4455/IQuery422XFor4455.java b/pu/src/public/nc/pubitf/pu/m422x/ic/m4455/IQuery422XFor4455.java index 807ca69..02e78c6 100644 --- a/pu/src/public/nc/pubitf/pu/m422x/ic/m4455/IQuery422XFor4455.java +++ b/pu/src/public/nc/pubitf/pu/m422x/ic/m4455/IQuery422XFor4455.java @@ -11,7 +11,7 @@ import nc.vo.pu.m422x.entity.StoreReqAppVO; import nc.vo.pub.BusinessException; public interface IQuery422XFor4455 { - StoreReqAppVO[] queryStoreReqAppsFor4455(IQueryScheme var1) throws BusinessException; + StoreReqAppVO[] queryStoreReqAppsFor4455(IQueryScheme queryScheme) throws BusinessException; AggPickmVO[] queryPickmAppsFor4455(IQueryScheme queryScheme) throws BusinessException; } diff --git a/so/META-INF/saleinvoice.rest b/so/META-INF/saleinvoice.rest new file mode 100644 index 0000000..94b8e77 --- /dev/null +++ b/so/META-INF/saleinvoice.rest @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/so/src/private/nc/bs/so/m32/maintain/rule/delete/SyncBipBillRuleForDelete.java b/so/src/private/nc/bs/so/m32/maintain/rule/delete/SyncBipBillRuleForDelete.java index 287f185..6afdea8 100644 --- a/so/src/private/nc/bs/so/m32/maintain/rule/delete/SyncBipBillRuleForDelete.java +++ b/so/src/private/nc/bs/so/m32/maintain/rule/delete/SyncBipBillRuleForDelete.java @@ -3,10 +3,13 @@ package nc.bs.so.m32.maintain.rule.delete; import com.alibaba.fastjson.JSONObject; import com.google.gson.Gson; import com.yonyou.cloud.utils.StringUtils; +import nc.bs.dao.DAOException; import nc.bs.logging.Logger; +import nc.bs.trade.business.HYSuperDMO; import nc.bs.uapbd.util.IgnoreSslUtil; import nc.impl.pubapp.pattern.rule.IRule; -import nc.vo.pubapp.pattern.exception.ExceptionUtils; +import nc.vo.bd.defdoc.DefdocVO; +import nc.vo.pub.BusinessException; import nc.vo.so.m32.entity.SaleInvoiceBVO; import nc.vo.so.m32.entity.SaleInvoiceHVO; import nc.vo.so.m32.entity.SaleInvoiceVO; @@ -31,11 +34,12 @@ import java.util.*; * @date 2025/3/20 */ public class SyncBipBillRuleForDelete implements IRule { - - private static String appKey = "a3c57e0d871240e9b9bf56b35001a324"; - private static String appSecret = "a959f7786db8dbb9a2c0493b5855a46bea68ad75"; - private static String tokenUrl = "https://www.tkkfbip.com/iuap-api-auth/open-auth/selfAppAuth/getAccessToken"; - private static String toBipUrl = "https://www.tkkfbip.com/iuap-api-gateway/oxp4h3x6/current_yonbip_default_sys/KKAPI/invoiceApplication/updateInvoice?access_token="; + private HYSuperDMO superDMO = null; + private String appKey = ""; + private String appSecret = ""; + private String baseUrl = "https://www.tkkfbip.com"; + private String tokenUrl = "/iuap-api-auth/open-auth/selfAppAuth/getAccessToken"; + private String toBipUrl = "/iuap-api-gateway/oxp4h3x6/current_yonbip_default_sys/KKAPI/invoiceApplication/updateInvoice?access_token="; @Override public void process(SaleInvoiceVO[] vos) { @@ -47,13 +51,23 @@ public class SyncBipBillRuleForDelete implements IRule { if (!hasVdef38) { return; } + // 浠庤嚜瀹氫箟妗f涓幏鍙 + Map bipParamMap = checkBipParam(); + if (bipParamMap.isEmpty()) { + return; + } + baseUrl = bipParamMap.get("baseUrl"); + appKey = bipParamMap.get("appKey"); + appSecret = bipParamMap.get("appSecret"); + NCCForUAPLogger.debug(String.format("SyncBipBillRuleForDelete-baseUrl = [%s],appKey1 = [%s],appSecret = [%s],", + baseUrl, appKey, appSecret)); String access_token = getAccessToken(); for (SaleInvoiceVO invoiceVO : vos) { SaleInvoiceHVO hvo = invoiceVO.getParentVO(); SaleInvoiceBVO[] bvos = invoiceVO.getChildrenVO(); if (access_token.isEmpty()) { Logger.error("SyncBipBillRuleForDelete-token鑾峰彇澶辫触"); - ExceptionUtils.wrappBusinessException("token鑾峰彇澶辫触"); + throw new BusinessException("token鑾峰彇澶辫触"); } // bip鏃楄埌鐗堝彂绁ㄤ富閿 String vdef38 = hvo.getVdef38(); @@ -72,15 +86,22 @@ public class SyncBipBillRuleForDelete implements IRule { updateJson.put("id", vdef38); updateJson.put("saleInvoiceId", ""); updateJson.put("contractInvoiceApplicationDetailList", childrenList); - String bipRes = doPost(toBipUrl + access_token, updateJson); + String bipRes = doPost(baseUrl + toBipUrl + access_token, updateJson); NCCForUAPLogger.debug("SyncBipBillRuleForDelete-bipRes = " + bipRes); } } - } catch (NoSuchAlgorithmException | InvalidKeyException | IOException e) { + } catch (Exception e) { Logger.error("SyncBipBillRuleForDelete-exp:" + e.getMessage(), e); } } + public HYSuperDMO getSuperDMO() { + if (superDMO == null) { + superDMO = new HYSuperDMO(); + } + return superDMO; + } + /** * 鑾峰彇鏃楄埌鐗堢殑token * @@ -89,6 +110,7 @@ public class SyncBipBillRuleForDelete implements IRule { * @date 2025/3/20 */ private String getAccessToken() throws NoSuchAlgorithmException, InvalidKeyException, IOException { + String access_token = ""; // 鑾峰彇鏃楄埌鐗堢殑token Map params = new HashMap<>(); // 闄ょ鍚嶅鐨勫叾浠栧弬鏁 @@ -107,13 +129,12 @@ public class SyncBipBillRuleForDelete implements IRule { String base64String = Base64.getEncoder().encodeToString(signData); String signature = URLEncoder.encode(base64String, "UTF-8"); params.put("signature", signature); - String responseString = doGet(tokenUrl, params); + String responseString = doGet(baseUrl + tokenUrl, params); Gson gson = new Gson(); Map result = gson.fromJson(responseString, Map.class); - String access_token = ""; - if (StringUtils.equals("00000", result.get("code").toString())) { + if (StringUtils.equals("00000", result.getOrDefault("code", "") + "")) { Map tokenInfo = (Map) result.get("data"); - access_token = (String) tokenInfo.get("access_token"); + access_token = (String) tokenInfo.getOrDefault("access_token", ""); } Logger.error("SyncBipBillRuleForDelete-getAccessToken = " + access_token); return access_token; @@ -200,4 +221,24 @@ public class SyncBipBillRuleForDelete implements IRule { return null; } + /** + * 妫鏌ip鍙傛暟鏄惁瀹屾暣 + */ + private Map checkBipParam() { + Map map = new HashMap(); + String strWhere = " pk_defdoclist in (select pk_defdoclist from bd_defdoclist where code='BIP-sq' and dr=0 ) and dr=0"; + try { + DefdocVO[] defdocVOs = (DefdocVO[]) getSuperDMO().queryByWhereClause(DefdocVO.class, strWhere); + if (defdocVOs != null && defdocVOs.length > 0) { + for (DefdocVO defdocVO : defdocVOs) { + map.put(defdocVO.getCode().trim(), defdocVO.getName()); + } + } + } catch (DAOException e) { + e.printStackTrace(); + } + return map; + + } + } diff --git a/so/src/private/nccloud/api/impl/so/m30/APISaleOrderMaitainImpl.java b/so/src/private/nccloud/api/impl/so/m30/APISaleOrderMaitainImpl.java index 63a2099..d6defd0 100644 --- a/so/src/private/nccloud/api/impl/so/m30/APISaleOrderMaitainImpl.java +++ b/so/src/private/nccloud/api/impl/so/m30/APISaleOrderMaitainImpl.java @@ -11,15 +11,18 @@ import nc.itf.scmpub.reference.uap.bd.customer.CustomerPubService; import nc.itf.scmpub.reference.uap.pf.PfServiceScmUtil; import nc.itf.so.m30.self.ISaleOrderMaintain; import nc.itf.so.m30.self.ISaleOrderScriptMaintain; +import nc.itf.uap.pf.IPFBusiAction; import nc.jdbc.framework.processor.ColumnProcessor; import nc.jdbc.framework.processor.MapProcessor; import nc.pubimpl.so.m30.pub.SaleOrderSaveUtil; import nc.pubitf.so.m30.api.ISaleOrderQueryAPI; import nc.vo.bd.defdoc.DefdocVO; +import nc.vo.ml.NCLangRes4VoTransl; import nc.vo.pub.BusinessException; import nc.vo.pub.VOStatus; import nc.vo.pub.billtype.BilltypeVO; import nc.vo.pub.lang.UFBoolean; +import nc.vo.pub.lang.UFDate; import nc.vo.pub.lang.UFDouble; import nc.vo.pubapp.AppContext; import nc.vo.pubapp.pattern.exception.ExceptionUtils; @@ -31,25 +34,20 @@ import nc.vo.scmpub.util.StringUtil; import nc.vo.so.m30.entity.SaleOrderBVO; import nc.vo.so.m30.entity.SaleOrderHVO; import nc.vo.so.m30.entity.SaleOrderVO; +import nc.vo.so.pub.SOConstant; import nc.vo.so.pub.enumeration.BillStatus; +import nc.vo.so.pub.keyvalue.IKeyValue; +import nc.vo.so.pub.keyvalue.VOKeyValue; import nc.vo.so.pub.util.AggVOUtil; import nccloud.api.impl.so.m30.check.SaleOrderValidator; import nccloud.api.impl.so.m30.fill.SaleOrderNPriceMnyCal; import nccloud.api.impl.so.m30.fill.SaleOrderSaveFillValue; -import nccloud.api.impl.so.m30.fill.SetUpdateData; import nccloud.api.so.m30.IAPISaleOrderMaitain; import nccloud.baseapp.core.log.NCCForUAPLogger; import nccloud.openapi.scmpub.pub.TransferCodeToPKTool; import nccloud.openapi.scmpub.pub.TransferMapToVOTool; import nccloud.putitf.riart.billtype.IBilltypeService; import org.apache.commons.lang3.ArrayUtils; -import nc.itf.uap.pf.IPFBusiAction; -import nc.vo.ml.NCLangRes4VoTransl; -import nc.vo.pub.lang.UFDate; -import nc.vo.so.pub.SOConstant; -import nc.vo.so.pub.util.SOCurrencyUtil; -import nc.vo.so.pub.keyvalue.IKeyValue; -import nc.vo.so.pub.keyvalue.VOKeyValue; import java.math.BigDecimal; import java.util.*; @@ -62,1001 +60,1004 @@ import java.util.*; */ public class APISaleOrderMaitainImpl implements IAPISaleOrderMaitain { - private static String BODYTABLE = "so_saleorder_b"; - private static String HEADTABLE = "so_saleorder"; + private static String BODYTABLE = "so_saleorder_b"; + private static String HEADTABLE = "so_saleorder"; - public SaleOrderVO[] save(SaleOrderVO[] vos) throws BusinessException { + public SaleOrderVO[] save(SaleOrderVO[] vos) throws BusinessException { - SaleOrderVO[] fillvos = vos; - // 检查非空项 - for (SaleOrderVO vo : vos) { - SaleOrderHVO hvo = vo.getParentVO(); - UFDate dbilldate = hvo.getDbilldate(); - SaleOrderBVO[] bvos = vo.getChildrenVO(); - String sql = " select bd_currtype.pk_currtype from bd_currtype where (code='" + hvo.getCorigcurrencyid() - + "' or pk_currtype='" + hvo.getCorigcurrencyid() + "') and dr=0 "; - Object o = new BaseDAO().executeQuery(sql, new ColumnProcessor()); - if (o != null) { - hvo.setCorigcurrencyid(BFPubTools.getString_TrimAsNull(o)); - } else { - throw new BusinessException("表头币种不能为空或币种不存在"); - } - sql = " select bd_currtype.pk_currtype from bd_currtype where (code='" + bvos[0].getCcurrencyid() - + "' or pk_currtype='" + bvos[0].getCcurrencyid() + "') and dr=0 "; - Object o1 = new BaseDAO().executeQuery(sql, new ColumnProcessor()); - if (o1 == null) { - throw new BusinessException("表体币种不能为空或币种不存在"); - } - String csettleorgid = bvos[0].getCsettleorgid(); - String ccurrencyorgid = o1.toString(); - UFDouble exchangerate = SOCurrencyUtil.getInCurrencyRateByOrg(csettleorgid, - BFPubTools.getString_TrimAsNull(o), ccurrencyorgid, dbilldate); - for (SaleOrderBVO bvo : bvos) { - bvo.setCcurrencyid(BFPubTools.getString_TrimAsNull(o1)); - if (!BFPubTools.getString_TrimAsNull(o).equals(ccurrencyorgid)) { - bvo.setNexchangerate(exchangerate); - } else { - bvo.setNexchangerate(UFDouble.ONE_DBL); - } + SaleOrderVO[] fillvos = vos; + // 检查非空项 + for (SaleOrderVO vo : vos) { + SaleOrderHVO hvo = vo.getParentVO(); + UFDate dbilldate = hvo.getDbilldate(); + SaleOrderBVO[] bvos = vo.getChildrenVO(); + String sql = " select bd_currtype.pk_currtype from bd_currtype where (code='" + hvo.getCorigcurrencyid() + + "' or pk_currtype='" + hvo.getCorigcurrencyid() + "') and dr=0 "; + Object o = new BaseDAO().executeQuery(sql, new ColumnProcessor()); + if (o != null) { + hvo.setCorigcurrencyid(BFPubTools.getString_TrimAsNull(o)); + } else { + throw new BusinessException("表头币种不能为空或币种不存在"); + } + sql = " select bd_currtype.pk_currtype from bd_currtype where (code='" + bvos[0].getCcurrencyid() + + "' or pk_currtype='" + bvos[0].getCcurrencyid() + "') and dr=0 "; + Object o1 = new BaseDAO().executeQuery(sql, new ColumnProcessor()); + if (o1 == null) { + throw new BusinessException("表体币种不能为空或币种不存在"); + } + // String csettleorgid = bvos[0].getCsettleorgid(); + String ccurrencyorgid = o1.toString(); + // UFDouble exchangerate = SOCurrencyUtil.getInCurrencyRateByOrg(csettleorgid, BFPubTools.getString_TrimAsNull(o), ccurrencyorgid, dbilldate); + for (SaleOrderBVO bvo : bvos) { + bvo.setCcurrencyid(BFPubTools.getString_TrimAsNull(o1)); + if (!BFPubTools.getString_TrimAsNull(o).equals(ccurrencyorgid)) { + // bvo.setNexchangerate(exchangerate); + } else { + // bvo.setNexchangerate(UFDouble.ONE_DBL); + } + // 折本汇率判空及保留小数位数 + UFDouble exchangerate1 = getUFDouble_NullAsOne(bvo.getNexchangerate()).setScale(2, UFDouble.ROUND_HALF_UP); + bvo.setNexchangerate(exchangerate1); + } + } - } - } - BillVOsCheckRule checker = new BillVOsCheckRule(new SaleOrderValidator()); - checker.check(vos); - // 填充默认值 - new SaleOrderSaveFillValue().setDefValue(vos); - // 有值不覆盖 - for (SaleOrderVO ordervo : vos) { - calculatorPrice(ordervo); - } + BillVOsCheckRule checker = new BillVOsCheckRule(new SaleOrderValidator()); + checker.check(vos); + // 填充默认值 + new SaleOrderSaveFillValue().setDefValue(vos); + // 有值不覆盖 + for (SaleOrderVO ordervo : vos) { + calculatorPrice(ordervo); + } - SaleOrderVO[] combinBillVOs = (SaleOrderVO[]) AggVOUtil.combinBillVO(fillvos, vos); - // 保存 - SaleOrderVO[] retvos = (SaleOrderVO[]) PfServiceScmUtil.processBatch(SOConstant.WRITE, - SOBillType.Order.getCode(), combinBillVOs, null, null); + SaleOrderVO[] combinBillVOs = (SaleOrderVO[]) AggVOUtil.combinBillVO(fillvos, vos); + // 保存 + SaleOrderVO[] retvos = (SaleOrderVO[]) PfServiceScmUtil.processBatch(SOConstant.WRITE, + SOBillType.Order.getCode(), combinBillVOs, null, null); - SaleOrderVO[] billvos = ((ISaleOrderQueryAPI) NCLocator.getInstance().lookup(ISaleOrderQueryAPI.class)) - .queryVOByIDs(new String[] { retvos[0].getParentVO().getPrimaryKey() }); - if (billvos != null) { - ((IPFBusiAction) NCLocator.getInstance().lookup(IPFBusiAction.class)).processAction("APPROVE", - billvos[0].getParentVO().getVtrantypecode(), null, billvos[0], null, null); - } - return retvos; - } + SaleOrderVO[] billvos = ((ISaleOrderQueryAPI) NCLocator.getInstance().lookup(ISaleOrderQueryAPI.class)) + .queryVOByIDs(new String[]{retvos[0].getParentVO().getPrimaryKey()}); + if (billvos != null) { + ((IPFBusiAction) NCLocator.getInstance().lookup(IPFBusiAction.class)).processAction("APPROVE", + billvos[0].getParentVO().getVtrantypecode(), null, billvos[0], null, null); + } + return retvos; + } - public void calculatorPrice(SaleOrderVO ordervo) throws BusinessException { + public void calculatorPrice(SaleOrderVO ordervo) throws BusinessException { - IKeyValue keyValue = new VOKeyValue(ordervo); + IKeyValue keyValue = new VOKeyValue(ordervo); - String ctrantypeid = keyValue.getHeadStringValue(SaleOrderHVO.CTRANTYPEID); - if (StringUtil.isEmptyTrimSpace(ctrantypeid)) { - ExceptionUtils.wrappBusinessException( - NCLangRes4VoTransl.getNCLangRes().getStrByID("4006013_0", "04006013-0024")/* @res "请先选择交易类型!" */); - } - // 1.缓存交易类型VO + String ctrantypeid = keyValue.getHeadStringValue(SaleOrderHVO.CTRANTYPEID); + if (StringUtil.isEmptyTrimSpace(ctrantypeid)) { + ExceptionUtils.wrappBusinessException( + NCLangRes4VoTransl.getNCLangRes().getStrByID("4006013_0", "04006013-0024")/* @res "请先选择交易类型!" */); + } + // 1.缓存交易类型VO - SaleOrderBVO[] vbos = ordervo.getChildrenVO(); - UFDouble sumnum = UFDouble.ZERO_DBL; - UFDouble sumnny = UFDouble.ZERO_DBL; - String ybpk = ordervo.getParentVO().getCorigcurrencyid(); + SaleOrderBVO[] vbos = ordervo.getChildrenVO(); + UFDouble sumnum = UFDouble.ZERO_DBL; + UFDouble sumnny = UFDouble.ZERO_DBL; + String ybpk = ordervo.getParentVO().getCorigcurrencyid(); - for (int i = 0; i < vbos.length; i++) { - SaleOrderBVO childrenVO = vbos[i]; - String zbbz = childrenVO.getCcurrencyid(); + for (int i = 0; i < vbos.length; i++) { + SaleOrderBVO childrenVO = vbos[i]; + String zbbz = childrenVO.getCcurrencyid(); - childrenVO.setFtaxtypeflag(1); - // 得到税率 - UFDouble ntaxrate = BFPubTools.getUFDouble_NullAsZero(childrenVO.getNtaxrate()); + childrenVO.setFtaxtypeflag(1); + // 得到税率 + UFDouble ntaxrate = BFPubTools.getUFDouble_NullAsZero(childrenVO.getNtaxrate()); - // 折本汇率 - UFDouble nexchangerate = childrenVO.getNexchangerate(); - // 含税单价 - UFDouble nqtorigtaxprice = childrenVO.getNqtorigtaxprice(); - // 无税单价 - UFDouble nqtorigprice = nqtorigtaxprice.div(UFDouble.ONE_DBL.add(ntaxrate.div(100))); - // 价税合计 - // UFDouble norigtaxmny=nqtorigtaxprice.multiply(childrenVO.getNqtunitnum()); - UFDouble norigtaxmny = nqtorigtaxprice.multiply(childrenVO.getNqtunitnum()).setScale(2, 4); - childrenVO.setNorigtaxmny(norigtaxmny); - // 无税金额 - UFDouble norigmny = nqtorigprice.multiply(childrenVO.getNqtunitnum()); + // 折本汇率 + UFDouble nexchangerate = childrenVO.getNexchangerate(); + nexchangerate = getUFDouble_NullAsOne(nexchangerate); + // 含税单价 + UFDouble nqtorigtaxprice = childrenVO.getNqtorigtaxprice(); + // 无税单价 + UFDouble nqtorigprice = nqtorigtaxprice.div(UFDouble.ONE_DBL.add(ntaxrate.div(100))); + // 价税合计 + // UFDouble norigtaxmny=nqtorigtaxprice.multiply(childrenVO.getNqtunitnum()); + UFDouble norigtaxmny = nqtorigtaxprice.multiply(childrenVO.getNqtunitnum()).setScale(2, 4); + childrenVO.setNorigtaxmny(norigtaxmny); + // 无税金额 + UFDouble norigmny = nqtorigprice.multiply(childrenVO.getNqtunitnum()); - childrenVO.setNorigmny(Currency.getFormaUfValue(ybpk, norigmny)); - // 税额 - childrenVO.setNqtorigprice(nqtorigprice.setScale(4, 4)); + childrenVO.setNorigmny(Currency.getFormaUfValue(ybpk, norigmny)); + // 税额 + childrenVO.setNqtorigprice(nqtorigprice.setScale(4, 4)); - // 无税本币金额单价 - UFDouble taxspric = nqtorigtaxprice.div(UFDouble.ONE_DBL.add(ntaxrate.div(100))); + // 无税本币金额单价 + UFDouble taxspric = nqtorigtaxprice.div(UFDouble.ONE_DBL.add(ntaxrate.div(100))); - sumnum = sumnum.add(childrenVO.getNastnum()); - sumnny = sumnny.add(childrenVO.getNorigtaxmny()); + sumnum = sumnum.add(childrenVO.getNastnum()); + sumnny = sumnny.add(childrenVO.getNorigtaxmny()); - nqtorigprice = nqtorigprice.setScale(4, 4); - // nqtorigtaxnetprc--含税净价 - childrenVO.setNqtorigtaxnetprc(nqtorigtaxprice); - // ,nqtorignetprice --无税净价 - childrenVO.setNqtorignetprice(nqtorigprice); - String Vqtunitrate = childrenVO.getVqtunitrate(); - UFDouble dVqtunitrate = UFDouble.ONE_DBL; - if (Vqtunitrate != null) { - dVqtunitrate = BFPubTools.getUFDouble_NullAsZero(Vqtunitrate.split("/")[0]); - } - // ,norigtaxprice --主含税单价 + nqtorigprice = nqtorigprice.setScale(4, 4); + // nqtorigtaxnetprc--含税净价 + childrenVO.setNqtorigtaxnetprc(nqtorigtaxprice); + // ,nqtorignetprice --无税净价 + childrenVO.setNqtorignetprice(nqtorigprice); + String Vqtunitrate = childrenVO.getVqtunitrate(); + UFDouble dVqtunitrate = UFDouble.ONE_DBL; + if (Vqtunitrate != null) { + dVqtunitrate = BFPubTools.getUFDouble_NullAsZero(Vqtunitrate.split("/")[0]); + } + // ,norigtaxprice --主含税单价 - UFDouble wsje = taxspric.multiply(nexchangerate).multiply(childrenVO.getNqtunitnum()); - if (ybpk.equals(zbbz) && BFPubTools.getString_TrimAsNull(childrenVO.getCqtunitid()) - .equals(BFPubTools.getString_TrimAsNull(childrenVO.getCastunitid()))) { - wsje = taxspric.multiply(nexchangerate).multiply(childrenVO.getNqtunitnum()); - } + UFDouble wsje = taxspric.multiply(nexchangerate).multiply(childrenVO.getNqtunitnum()); + if (ybpk.equals(zbbz) && BFPubTools.getString_TrimAsNull(childrenVO.getCqtunitid()) + .equals(BFPubTools.getString_TrimAsNull(childrenVO.getCastunitid()))) { + wsje = taxspric.multiply(nexchangerate).multiply(childrenVO.getNqtunitnum()); + } - wsje = Currency.getFormaUfValue(zbbz, wsje); - // 本币无税金额 - childrenVO.setNorigtaxprice(nqtorigtaxprice.div(dVqtunitrate).setScale(4, 4)); - // ,norigprice --主无税单价 - childrenVO.setNorigprice(nqtorigprice.div(dVqtunitrate).setScale(4, 4)); - // ,norigtaxnetprice --主含税净价 - childrenVO.setNorigtaxnetprice(childrenVO.getNorigtaxprice()); - // ,norignetprice --主无税净价 - childrenVO.setNorignetprice(childrenVO.getNorigprice()); - // ncaltaxmny --计税金额 + wsje = Currency.getFormaUfValue(zbbz, wsje); + // 本币无税金额 + childrenVO.setNorigtaxprice(nqtorigtaxprice.div(dVqtunitrate).setScale(4, 4)); + // ,norigprice --主无税单价 + childrenVO.setNorigprice(nqtorigprice.div(dVqtunitrate).setScale(4, 4)); + // ,norigtaxnetprice --主含税净价 + childrenVO.setNorigtaxnetprice(childrenVO.getNorigtaxprice()); + // ,norignetprice --主无税净价 + childrenVO.setNorignetprice(childrenVO.getNorigprice()); + // ncaltaxmny --计税金额 - // ,nqttaxprice --本币含税单价 - childrenVO.setNqttaxprice(nqtorigtaxprice.multiply(nexchangerate)); - // ,nqtprice --本币无税单价 - UFDouble bbwsd = nqtorigtaxprice.div(UFDouble.ONE_DBL.add(ntaxrate.div(100))).multiply(nexchangerate); - childrenVO.setNqtprice(bbwsd.setScale(4, 4)); - // , nqttaxnetprice --本币含税净价 - childrenVO.setNqttaxnetprice(nqtorigtaxprice.multiply(nexchangerate)); - // ,nqtnetprice --本币无税净价 - UFDouble Nqtnetprice = nqtorigtaxprice.div(UFDouble.ONE_DBL.add(ntaxrate.div(100))).multiply(nexchangerate); - childrenVO.setNqtnetprice(Nqtnetprice.setScale(4, 4)); - // ,ntaxprice --主本币含税单价 , nprice --主本币无税单价 - childrenVO.setNtaxprice(nqtorigtaxprice.div(dVqtunitrate).multiply(nexchangerate).setScale(4, 4)); - UFDouble Nprice = nqtorigtaxprice.div(dVqtunitrate).div(UFDouble.ONE_DBL.add(ntaxrate.div(100))) - .multiply(nexchangerate); - childrenVO.setNprice(Nprice.setScale(4, 4)); - // ,ntaxnetprice --主本币含税净价 - // ,nnetprice --主本币无税净价 - childrenVO.setNtaxnetprice(nqtorigtaxprice.div(dVqtunitrate).multiply(nexchangerate).setScale(4, 4)); - UFDouble Nnetprice = nqtorigtaxprice.div(UFDouble.ONE_DBL.add(ntaxrate.div(100))).div(dVqtunitrate); - childrenVO.setNnetprice(Nnetprice.multiply(nexchangerate).setScale(4, 4)); + // ,nqttaxprice --本币含税单价 + childrenVO.setNqttaxprice(nqtorigtaxprice.multiply(nexchangerate)); + // ,nqtprice --本币无税单价 + UFDouble bbwsd = nqtorigtaxprice.div(UFDouble.ONE_DBL.add(ntaxrate.div(100))).multiply(nexchangerate); + childrenVO.setNqtprice(bbwsd.setScale(4, 4)); + // , nqttaxnetprice --本币含税净价 + childrenVO.setNqttaxnetprice(nqtorigtaxprice.multiply(nexchangerate)); + // ,nqtnetprice --本币无税净价 + UFDouble Nqtnetprice = nqtorigtaxprice.div(UFDouble.ONE_DBL.add(ntaxrate.div(100))).multiply(nexchangerate); + childrenVO.setNqtnetprice(Nqtnetprice.setScale(4, 4)); + // ,ntaxprice --主本币含税单价 , nprice --主本币无税单价 + childrenVO.setNtaxprice(nqtorigtaxprice.div(dVqtunitrate).multiply(nexchangerate).setScale(4, 4)); + UFDouble Nprice = nqtorigtaxprice.div(dVqtunitrate).div(UFDouble.ONE_DBL.add(ntaxrate.div(100))) + .multiply(nexchangerate); + childrenVO.setNprice(Nprice.setScale(4, 4)); + // ,ntaxnetprice --主本币含税净价 + // ,nnetprice --主本币无税净价 + childrenVO.setNtaxnetprice(nqtorigtaxprice.div(dVqtunitrate).multiply(nexchangerate).setScale(4, 4)); + UFDouble Nnetprice = nqtorigtaxprice.div(UFDouble.ONE_DBL.add(ntaxrate.div(100))).div(dVqtunitrate); + childrenVO.setNnetprice(Nnetprice.multiply(nexchangerate).setScale(4, 4)); // ,nmny --本币无税金额 // ,ntaxmny --本币价税合计 - childrenVO.setNmny(Currency.getFormaUfValue(zbbz, norigmny.multiply(nexchangerate))); - childrenVO.setNtaxmny( - nqtorigtaxprice.multiply(nexchangerate).multiply(childrenVO.getNqtunitnum()).setScale(2, 4)); + childrenVO.setNmny(Currency.getFormaUfValue(zbbz, norigmny.multiply(nexchangerate))); + childrenVO.setNtaxmny( + nqtorigtaxprice.multiply(nexchangerate).multiply(childrenVO.getNqtunitnum()).setScale(2, 4)); // childrenVO.setNtaxmny(nqtorigtaxprice.multiply(nexchangerate).multiply(childrenVO.getNqtunitnum())); - childrenVO.setNcaltaxmny(wsje); - UFDouble ntax = norigtaxmny.multiply(nexchangerate).sub(wsje); - childrenVO.setNtax(ntax.setScale(2, 4)); - } - ordervo.getParentVO().setNtotalnum(sumnum); + childrenVO.setNcaltaxmny(wsje); + UFDouble ntax = norigtaxmny.multiply(nexchangerate).sub(wsje); + childrenVO.setNtax(ntax.setScale(2, 4)); + } + ordervo.getParentVO().setNtotalnum(sumnum); // ordervo.getParentVO().setNtotalorigmny(sumnny); - ordervo.getParentVO().setNtotalorigmny(sumnny.setScale(2, 4)); - } - - @Override - public SaleOrderVO[] save(List> paramList) throws BusinessException { - try { - List aggVOList = TransferMapToVOTool.transferMapToAggVO(paramList, SaleOrderVO.class); - - SaleOrderVO[] vos = (SaleOrderVO[]) aggVOList.toArray(new SaleOrderVO[aggVOList.size()]); - BillVOsCheckRule checker = new BillVOsCheckRule(new SaleOrderValidator()); - checker.check(vos); - - aggVOList = TransferCodeToPKTool.transferAggVO(aggVOList); - - SaleOrderSaveUtil saveUtil = new SaleOrderSaveUtil(); - return saveUtil.processBill(vos); - } catch (Exception e) { - ExceptionUtils.marsh(e); - return null; - } - } - - @Override - public SaleOrderVO[] update(List> paramList) throws BusinessException { - List aggVOList = TransferMapToVOTool.transferMapToAggVO(paramList, SaleOrderVO.class); - - aggVOList = TransferCodeToPKTool.transferAggVO(aggVOList); - - SaleOrderVO[] vos = (SaleOrderVO[]) aggVOList.toArray(new SaleOrderVO[aggVOList.size()]); - - Map> ids = getIds(vos); - if (ids.keySet() == null || ids.values() == null || ids.values().size() == 0) { - ExceptionUtils.wrappBusinessException("请传入订单主键和订单行主键"); - } - String[] hids = (String[]) ids.keySet().toArray(new String[ids.keySet().size()]); - - ISaleOrderMaintain service = (ISaleOrderMaintain) NCLocator.getInstance().lookup(ISaleOrderMaintain.class); - SaleOrderVO[] originVos = service.querySaleorder(hids); - if (null == originVos || originVos.length == 0) { - ExceptionUtils.wrappBusinessException("根据传入数据未匹配到相关数据"); - } - - for (Map objectMap : paramList) { - Map headdata = (Map) objectMap.get(HEADTABLE); - List bodyArr = (List) objectMap.get(BODYTABLE); - for (Object body : bodyArr) { - Map bodydata = (Map) body; - if (!(bodydata.getOrDefault("vbdef11", "") + "").isEmpty()) { - String vbdef11 = bodydata.get("vbdef11") + ""; - String dr = bodydata.getOrDefault("dr", "0") + ""; - String csaleorderid = bodydata.get("csaleorderid") + ""; - String countSql = "SELECT count(1) FROM so_saleorder_b" - + " WHERE nvl(dr,0) = 0 and csaleorderid = '[csaleorderid]' and vbdef11 = '[vbdef11]' "; - countSql = countSql.replace("[csaleorderid]", csaleorderid); - countSql = countSql.replace("[vbdef11]", vbdef11); - Integer num = (Integer) new BaseDAO().executeQuery(countSql, new ColumnProcessor()); - if ("0".equals(dr) && num <= 0) { - bodydata.put("status", "add"); - } - } - } - } - - // SetUpdateData setData = new SetUpdateData(); - // setData.setData(vos, originVos); - // SaleOrderVO[] combinBillVOs = (SaleOrderVO[]) AggVOUtil.combinBillVO(vos, - // originVos); - // 创建一个新的数组,并进行深拷贝 - SaleOrderVO[] combinBillVOs = new SaleOrderVO[originVos.length]; - for (int i = 0; i < originVos.length; i++) { - combinBillVOs[i] = (SaleOrderVO) originVos[i].clone(); - } - // 将 vos 中的元素按主键存储在 Map 中 - Map vosMap = new HashMap<>(); - for (SaleOrderVO vo : vos) { - vosMap.put(vo.getParentVO().getCsaleorderid(), vo); - } - - // 遍历 combinBillVOs 并更新字段 - for (SaleOrderVO vo : combinBillVOs) { - SaleOrderHVO hvo = vo.getParentVO(); - String primaryKey = hvo.getCsaleorderid(); - SaleOrderVO bipVo = vosMap.get(primaryKey); - // 设置单据状态 - hvo.setStatus(VOStatus.UPDATED); - - Map bvoMap = new HashMap<>(); - for (SaleOrderBVO saleOrderBVO : bipVo.getChildrenVO()) { - bvoMap.put(saleOrderBVO.getCsaleorderbid(), saleOrderBVO); - } - - // 比较combinBillVOs中的BVO和vos中的BVO - for (SaleOrderBVO bvo : vo.getChildrenVO()) { - bvo.setStatus(VOStatus.UPDATED); - // 设置删除的物料行的状态,在bip传的数据中找不到 - String csaleorderbid = bvo.getCsaleorderbid(); - if (bvoMap.get(csaleorderbid) == null) { - bvo.setStatus(VOStatus.DELETED); - NCCForUAPLogger.debug("findDeletedBids:" + VOStatus.DELETED + ",csaleorderbid = " + csaleorderbid); - } - } - // 更新 combinBillVO 中的字段为 vos 中的值 - updateFields(vo, bipVo); - // 设置新增的物料行 - if (paramList != null && !paramList.isEmpty()) { - addBvo(combinBillVOs, paramList); - } - } - // 联动计算 - INumPriceMnyCalculator cal = new SaleOrderNPriceMnyCal(combinBillVOs); - cal.calculate(); - for (SaleOrderVO vo : combinBillVOs) { - SaleOrderHVO hvo = vo.getParentVO(); - SaleOrderHVO originHvo = null; - for (SaleOrderVO originVo : originVos) { - if (hvo.getCsaleorderid().equals(originVo.getParentVO().getCsaleorderid())) { - originHvo = originVo.getParentVO(); - } - } - String new_ctrantypeid = hvo.getCtrantypeid(); - boolean isChangedTranType = false;// 订单类型不修改 - if (originHvo != null && new_ctrantypeid != null && !new_ctrantypeid.equals(originHvo.getCtrantypeid())) { - isChangedTranType = true; - } - SaleOrderBVO[] bvos = vo.getChildrenVO(); - // 判断是否存在新增的子表 - boolean hasNewStatus = Arrays.stream(bvos).anyMatch(bvo -> bvo.getStatus() == VOStatus.NEW); - // 新增子表或改订单类型的情况下不校验是否存在下游 - if (!hasNewStatus && !isChangedTranType) { - String countSql = "SELECT count(1) FROM so_saleinvoice_b a" - + " LEFT JOIN so_saleinvoice b ON a.csaleinvoiceid = b.csaleinvoiceid" - + " WHERE b.fopposeflag = 0 AND nvl(b.dr, 0) = 0 and csrcid = '[csrcid]' "; - countSql = countSql.replace("[csrcid]", hvo.getCsaleorderid()); - Integer num = (Integer) new BaseDAO().executeQuery(countSql, new ColumnProcessor()); - if (num > 0) { - // fopposeflag 对冲标记 0=正常 1=已被对冲 2=对冲生成 - ExceptionUtils.wrappBusinessException("下游存在未红冲完成的销售发票"); - return null; - } - } - } - - fillcustomervidbyoid(combinBillVOs); - - // 保存 - ISaleOrderScriptMaintain maintainsrv = NCLocator.getInstance().lookup(ISaleOrderScriptMaintain.class); - SaleOrderVO[] retvos = maintainsrv.saleOrderUpdate(combinBillVOs, null, originVos); - return retvos; - } - - private Map> getIds(SaleOrderVO[] vos) { - Map> ids = new HashMap>(); - for (SaleOrderVO vo : vos) { - String hid = vo.getParentVO().getCsaleorderid(); - Set bids = new HashSet(); - for (SaleOrderBVO bvo : vo.getChildrenVO()) { - bids.add(bvo.getCsaleorderbid()); - } - ids.put(hid, bids); - } - return ids; - } - - private void setOtherId(SaleOrderVO[] vos) { - for (SaleOrderVO vo : vos) { - // 部门、业务员、开票客户编码转id - SaleOrderHVO orderHVO = vo.getParentVO(); - String csaleorderid = orderHVO.getCsaleorderid(); - String cdeptvid = orderHVO.getCdeptvid(); - String cemployeeid = orderHVO.getCemployeeid(); - // 开票客户 - String cinvoicecustid = orderHVO.getCinvoicecustid(); - // 客户 - String ccustomerid = orderHVO.getCcustomerid(); - // 订单类型 - // String ctrantypeid = orderHVO.getAttributeValue("ctrantypeid") + ""; - String vtrantypecode = orderHVO.getVtrantypecode(); - NCCForUAPLogger.debug("setOtherId-ccustomerid:" + ccustomerid + ",vtrantypecode:" + vtrantypecode); - try { - String sql = ""; - // 部门 - if (cdeptvid != null && !cdeptvid.isEmpty()) { - sql = " select pk_vid,pk_dept from org_dept where code = '[code]' "; - sql = sql.replace("[code]", cdeptvid); - Map deptMap = (Map) new BaseDAO().executeQuery(sql, new MapProcessor()); - NCCForUAPLogger.debug("APISaleOrderMaitainImpl-setOtherId-deptObj:" + deptMap); - if (deptMap != null && !deptMap.isEmpty()) { - if (!"".equals(deptMap.getOrDefault("pk_dept", "") + "")) { - orderHVO.setCdeptid(deptMap.getOrDefault("pk_dept", "") + ""); - } - if (!"".equals(deptMap.getOrDefault("pk_vid", "") + "")) { - orderHVO.setCdeptvid(deptMap.getOrDefault("pk_vid", "") + ""); - } - } - } - // 业务员 - if (cemployeeid != null && !cemployeeid.isEmpty()) { - sql = " select pk_psndoc from bd_psndoc where code = '[code]' "; - sql = sql.replace("[code]", cemployeeid); - Object staffObj = new BaseDAO().executeQuery(sql, new ColumnProcessor("pk_psndoc")); - NCCForUAPLogger.debug("APISaleOrderMaitainImpl-setOtherId-staffObj:" + staffObj); - if (staffObj != null) { - String id = BFPubTools.getString_TrimAsNull(staffObj); - if (!id.isEmpty()) { - orderHVO.setCemployeeid(id); - } - } - } - // 开票客户 - if (cinvoicecustid != null && !cinvoicecustid.isEmpty()) { - sql = " select pk_customer from bd_customer where nvl(dr,0) = 0 and code = '[code]' "; - sql = sql.replace("[code]", cinvoicecustid); - Object invCustObj = new BaseDAO().executeQuery(sql, new ColumnProcessor("pk_customer")); - NCCForUAPLogger.debug("setOtherId-invCustObj:" + invCustObj); - if (invCustObj != null) { - String id = BFPubTools.getString_TrimAsNull(invCustObj); - if (!id.isEmpty()) { - orderHVO.setCinvoicecustid(id); - } - } - } - // 客户 - if (ccustomerid != null && !ccustomerid.isEmpty()) { - sql = " select pk_customer from bd_customer where nvl(dr,0) = 0 and code = '[code]' "; - sql = sql.replace("[code]", ccustomerid); - Object custObj = new BaseDAO().executeQuery(sql, new ColumnProcessor("pk_customer")); - NCCForUAPLogger.debug("setOtherId-custObj:" + custObj); - if (custObj != null) { - String id = BFPubTools.getString_TrimAsNull(custObj); - if (!id.isEmpty()) { - orderHVO.setCcustomerid(id); - } - } - } - // 交易类型 - if (vtrantypecode != null && !vtrantypecode.isEmpty()) { - IBilltypeService billtypeService = NCLocator.getInstance().lookup(IBilltypeService.class); - BilltypeVO billtype = billtypeService.getBilltype(vtrantypecode); - if (billtype != null && billtype.getPk_billtypeid() != null) { - NCCForUAPLogger.debug("setOtherId-pk_billtypeid:" + billtype.getPk_billtypeid()); - orderHVO.setCtrantypeid(billtype.getPk_billtypeid()); - } - } - } catch (Exception e) { - NCCForUAPLogger.debug("APISaleOrderMaitainImpl-setOtherId-exp:" + e.getMessage()); - throw new RuntimeException(e); - } - } - } - - private void updateFields(SaleOrderVO target, SaleOrderVO source) { - // 更新 SaleOrderHVO 字段 - SaleOrderHVO targetHVO = target.getParentVO(); - SaleOrderHVO sourceHVO = source.getParentVO(); - // 表头修改修改的字段 - String cdeptvid = sourceHVO.getCdeptvid(); - String cdeptid = sourceHVO.getCdeptid(); - if (cdeptvid != null && !cdeptvid.isEmpty()) { - targetHVO.setCdeptvid(cdeptvid); - targetHVO.setCdeptid(cdeptid); - } - - String cemployeeid = sourceHVO.getCemployeeid(); - if (cemployeeid != null && !cemployeeid.isEmpty()) { - targetHVO.setCemployeeid(cemployeeid); - } - String cinvoicecustid = sourceHVO.getCinvoicecustid(); - if (cinvoicecustid != null && !cinvoicecustid.isEmpty()) { - targetHVO.setCinvoicecustid(cinvoicecustid); - } - String ccustomerid = sourceHVO.getCcustomerid(); - if (ccustomerid != null && !ccustomerid.isEmpty()) { - targetHVO.setCcustomerid(ccustomerid); - } - // 订单类型id - String ctrantypeid = sourceHVO.getCtrantypeid(); - if (ctrantypeid != null && !ctrantypeid.isEmpty()) { - targetHVO.setCtrantypeid(ctrantypeid); - } - // 订单类型编码 - String vtrantypecode = sourceHVO.getVtrantypecode(); - if (vtrantypecode != null && !vtrantypecode.isEmpty()) { - targetHVO.setVtrantypecode(vtrantypecode); - } - - // 更新 SaleOrderBVO 字段 - SaleOrderBVO[] targetBVOs = target.getChildrenVO(); - SaleOrderBVO[] sourceBVOs = source.getChildrenVO(); - - // BVO 的主键是 csaleorderbid - Map sourceBVOsMap = new HashMap<>(); - for (SaleOrderBVO bvo : sourceBVOs) { - sourceBVOsMap.put(bvo.getCsaleorderbid(), bvo); - } - - for (SaleOrderBVO targetBVO : targetBVOs) { - String bvoId = targetBVO.getCsaleorderbid(); - SaleOrderBVO sourceBVO = sourceBVOsMap.get(bvoId); - if (sourceBVO != null) { - int status = targetBVO.getStatus(); - if (VOStatus.UPDATED == status) { - // 数量 - UFDouble nnum = sourceBVO.getNnum(); - targetBVO.setNnum(nnum); - targetBVO.setNastnum(nnum); - // targetBVO.setNqtunitnum(nnum); - // 价税合计 - targetBVO.setNorigtaxmny(sourceBVO.getNorigtaxmny()); - targetBVO.setCmaterialvid(sourceBVO.getCmaterialvid()); - // 是否赠品 - targetBVO.setBlargessflag(sourceBVO.getBlargessflag()); - // 折本汇率 - UFDouble nexchangerate = getUFDouble_NullAsOne(sourceBVO.getNexchangerate()); - targetBVO.setNexchangerate(nexchangerate); - // 物料编码 - String cmaterialvid = sourceBVO.getCmaterialvid(); - // 物料关联字段赋值 - if (cmaterialvid != null && !cmaterialvid.isEmpty()) { - setMaterl(targetBVO); - } - // 自定义项赋值 - String vbdef1 = sourceBVO.getVbdef1();// 合同编号 - Map defList = getDefList("zdy-001"); - targetBVO.setVbdef1(defList.getOrDefault(vbdef1, "")); - String vbdef5 = sourceBVO.getVbdef5();// 合同销售订单号 - defList.clear(); - defList = getDefList("BIP-ddh"); - targetBVO.setVbdef5(defList.getOrDefault(vbdef5, "")); - targetBVO.setVbdef10(sourceBVO.getVbdef10());// 项目名称 - targetBVO.setVbdef13(sourceBVO.getVbdef13());// 国网行项目号 - NCCForUAPLogger.debug(String.format( - "cmaterialvid = [%S], vbdef1 = [%S], vbdef5 = [%S], vbdef10 = [%S], vbdef13 = [%S]", - cmaterialvid, targetBVO.getVbdef1(), targetBVO.getVbdef5(), targetBVO.getVbdef10(), - targetBVO.getVbdef13())); - } - - } - } - } - - /** - * 获取自定义项信息 - */ - private Map getDefList(String code) { - Map map = new HashMap(); - String strWhere = " pk_defdoclist in (select pk_defdoclist from bd_defdoclist where code='" + code - + "' and dr=0 ) and dr = 0"; - try { - DefdocVO[] defdocVOs = (DefdocVO[]) new HYSuperDMO().queryByWhereClause(DefdocVO.class, strWhere); - if (defdocVOs != null && defdocVOs.length > 0) { - for (DefdocVO defdocVO : defdocVOs) { - map.put(defdocVO.getCode().trim(), defdocVO.getPk_defdoc()); - } - } - } catch (DAOException e) { - e.printStackTrace(); - } - return map; - - } - - @Override - public void delete(String[] hids) throws BusinessException { - BillQuery queryTool = new BillQuery(SaleOrderVO.class); - SaleOrderVO[] saleOrderVOs = (SaleOrderVO[]) queryTool.query(hids); - if (saleOrderVOs.length == 0) { - ExceptionUtils.wrappBusinessException("根据传入数据未匹配到相关数据"); - } - - PfServiceScmUtil.processBatch("DELETE", SOBillType.Order.getCode(), saleOrderVOs, null, null); - } - - private void fillcustomervidbyoid(SaleOrderVO[] combinBillVOs) { - Set customeridSet = new HashSet(); - Map customeridMap = new HashMap(); - for (SaleOrderVO vo : combinBillVOs) { - SaleOrderHVO hvo = vo.getParentVO(); - - if (!StringUtil.isSEmptyOrNull(hvo.getCcustomerid()) && StringUtil.isSEmptyOrNull(hvo.getCcustomervid())) { - customeridSet.add(hvo.getCcustomerid()); - } - - if (!StringUtil.isSEmptyOrNull(hvo.getCinvoicecustid()) - && StringUtil.isSEmptyOrNull(hvo.getCinvoicecustvid())) { - customeridSet.add(hvo.getCinvoicecustid()); - } - - if (!StringUtil.isSEmptyOrNull(hvo.getChreceivecustid()) - && StringUtil.isSEmptyOrNull(hvo.getChreceivecustvid())) { - customeridSet.add(hvo.getChreceivecustid()); - } - - SaleOrderBVO[] bvos = vo.getChildrenVO(); - for (SaleOrderBVO bvo : bvos) { - - if (!StringUtil.isSEmptyOrNull(bvo.getCreceivecustid()) - && StringUtil.isSEmptyOrNull(bvo.getCreceivecustvid())) { - customeridSet.add(bvo.getCreceivecustid()); - } - - if (!StringUtil.isSEmptyOrNull(bvo.getCvendorid()) && StringUtil.isSEmptyOrNull(bvo.getCvendorvid())) { - customeridSet.add(bvo.getCvendorid()); - } - } - } - - if (!customeridSet.isEmpty()) { - customeridMap = CustomerPubService - .queryCustomerVidsByOids((String[]) CollectionUtils.setToArray(customeridSet)); - } - - for (SaleOrderVO vo : combinBillVOs) { - SaleOrderHVO hvo = vo.getParentVO(); - - if (!StringUtil.isSEmptyOrNull(hvo.getCcustomerid()) && StringUtil.isSEmptyOrNull(hvo.getCcustomervid())) { - if (null == customeridMap || customeridMap.size() == 0) { - hvo.setCcustomervid(hvo.getCcustomerid()); - } else { - hvo.setCcustomervid((String) customeridMap.get(hvo.getCcustomerid())); - } - } - - if (!StringUtil.isSEmptyOrNull(hvo.getCinvoicecustid()) - && StringUtil.isSEmptyOrNull(hvo.getCinvoicecustvid())) { - if (null == customeridMap || customeridMap.size() == 0) { - hvo.setCinvoicecustvid(hvo.getCinvoicecustid()); - } else { - hvo.setCinvoicecustvid((String) customeridMap.get(hvo.getCinvoicecustid())); - } - } - - if (!StringUtil.isSEmptyOrNull(hvo.getChreceivecustid()) - && StringUtil.isSEmptyOrNull(hvo.getChreceivecustvid())) { - if (null == customeridMap || customeridMap.size() == 0) { - hvo.setChreceivecustvid(hvo.getChreceivecustid()); - } else { - hvo.setChreceivecustvid((String) customeridMap.get(hvo.getChreceivecustid())); - } - } - - SaleOrderBVO[] bvos = vo.getChildrenVO(); - for (SaleOrderBVO bvo : bvos) { - - if (!StringUtil.isSEmptyOrNull(bvo.getCreceivecustid()) - && StringUtil.isSEmptyOrNull(bvo.getCreceivecustvid())) { - if (null == customeridMap || customeridMap.size() == 0) { - bvo.setCreceivecustvid(bvo.getCreceivecustid()); - } else { - bvo.setCreceivecustvid((String) customeridMap.get(bvo.getCreceivecustid())); - } - } - - if (!StringUtil.isSEmptyOrNull(bvo.getCvendorid()) && StringUtil.isSEmptyOrNull(bvo.getCvendorvid())) { - if (null == customeridMap || customeridMap.size() == 0) { - bvo.setCvendorvid(bvo.getCvendorid()); - } else { - bvo.setCvendorvid((String) customeridMap.get(bvo.getCvendorid())); - } - } - } - } - } - - @Override - public SaleOrderVO[] sendApprove(String[] hids) throws BusinessException { - SaleOrderVO[] vos = querySaleOrder(hids); - try { - for (SaleOrderVO aggvo : vos) { - SaleOrderHVO parentVO = aggvo.getParentVO(); - if (!BillStatus.FREE.equalsValue(parentVO.getFstatusflag())) { - ExceptionUtils.wrappBusinessException("当前销售订单:" + parentVO.getVbillcode() + "不是自由状态,不能提交"); - } - } - return (SaleOrderVO[]) PfServiceScmUtil.processBatch("SAVE", SOBillType.Order.getCode(), vos, null, null); - } catch (Exception e) { - ExceptionUtils.marsh(e); - return null; - } - } - - @Override - public SaleOrderVO[] unSendApprove(String[] hids) throws BusinessException { - SaleOrderVO[] vos = querySaleOrder(hids); - try { - for (SaleOrderVO aggvo : vos) { - SaleOrderHVO parentVO = aggvo.getParentVO(); - if (!BillStatus.AUDITING.equalsValue(parentVO.getFstatusflag())) { - ExceptionUtils.wrappBusinessException("当前销售订单:" + parentVO.getVbillcode() + "不是提交状态,不能收回"); - } - } - return (SaleOrderVO[]) PfServiceScmUtil.processBatch("UNSAVE", SOBillType.Order.getCode(), vos, null, null); - } catch (Exception e) { - ExceptionUtils.marsh(e); - return null; - } - } - - @Override - public SaleOrderVO[] approve(String[] hids) throws BusinessException { - SaleOrderVO[] vos = querySaleOrder(hids); - try { - for (SaleOrderVO aggvo : vos) { - SaleOrderHVO parentVO = aggvo.getParentVO(); - if (!BillStatus.FREE.equalsValue(parentVO.getFstatusflag()) - && !BillStatus.AUDIT.equalsValue(parentVO.getFstatusflag()) - && !BillStatus.AUDITING.equalsValue(parentVO.getFstatusflag())) { - ExceptionUtils.wrappBusinessException("当前销售订单:" + parentVO.getVbillcode() + "状态不符合审批条件,不能审批"); - } - } - return (SaleOrderVO[]) PfServiceScmUtil.processBatch("APPROVE", SOBillType.Order.getCode(), vos, null, - null); - } catch (Exception e) { - ExceptionUtils.marsh(e); - return null; - } - } - - @Override - public SaleOrderVO[] unApprove(String[] hids) throws BusinessException { - SaleOrderVO[] vos = querySaleOrder(hids); - try { - for (SaleOrderVO aggvo : vos) { - SaleOrderHVO parentVO = aggvo.getParentVO(); - if (!BillStatus.AUDIT.equalsValue(parentVO.getFstatusflag()) - && !BillStatus.AUDITING.equalsValue(parentVO.getFstatusflag())) { - ExceptionUtils.wrappBusinessException("当前销售订单:" + parentVO.getVbillcode() + "状态不符合弃审条件,不能弃审"); - } - } - return (SaleOrderVO[]) PfServiceScmUtil.processBatch("UNAPPROVE", SOBillType.Order.getCode(), vos, null, - null); - } catch (Exception e) { - ExceptionUtils.marsh(e); - return null; - } - } - - private SaleOrderVO[] querySaleOrder(String[] hids) throws BusinessException { - ISaleOrderQueryAPI service = (ISaleOrderQueryAPI) NCLocator.getInstance().lookup(ISaleOrderQueryAPI.class); - SaleOrderVO[] vos = service.queryVOByIDs(hids); - if (ArrayUtils.isEmpty(vos)) { - ExceptionUtils.wrappBusinessException("没有符合条件的数据"); - } else { - return vos; - } - return null; - } - - /** - * 设置物料的相关字段 - */ - private void setMaterl(SaleOrderBVO bVO) { - String cmaterialvid = bVO.getCmaterialvid(); - UFDouble nnum = bVO.getNnum(); - UFDouble ntaxrate = bVO.getNtaxrate(); - try { - String sql = " select a.pk_material,a.pk_source, a.pk_measdoc cunitid,nvl(b.pk_measdoc,a.pk_measdoc) castunitid,nvl(b.measrate,'1/1') measrate " - + "from bd_material a left join bd_materialconvert b on a.pk_material=b.pk_material " - + "where a.code='" + cmaterialvid + "' "; - Map map = (Map) new BaseDAO().executeQuery(sql, new MapProcessor()); - if (map == null) { - throw new BusinessException(cmaterialvid + "物料未查到"); - } - NCCForUAPLogger.debug(String.format("setMaterl: cqtunitid = [%S], cunitid = [%S], castunitid = [%S]", - map.get("cqtunitid"), map.get("cunitid"), map.get("castunitid"))); - bVO.setAttributeValue("castunitid", map.get("castunitid")); - bVO.setAttributeValue("vchangerate", map.get("vchangerate")); - - // 重新计算金额 - bVO.setAttributeValue("cqtunitid", map.get("cunitid")); - bVO.setAttributeValue("cunitid", map.get("cunitid")); - - bVO.setAttributeValue("cmaterialid", map.get("pk_material")); - bVO.setAttributeValue("cmaterialvid", map.get("pk_material")); - - UFDouble nqtunitnum = BFPubTools.getUFDouble_NullAsZero(nnum) - .div(BFPubTools.getUFDouble_NullAsZero(map.get("measrate").toString().split("/")[0])); - bVO.setAttributeValue("nqtunitnum", nqtunitnum); - - sql = "select sl.pk_taxcode from bd_taxrate sl inner join bd_taxcode sm on sl.pk_taxcode=sm.pk_taxcode where sl.taxrate=" - + ntaxrate + " and sm.pk_group<>'~' " + ""; - - String o_pk_project = (String) new BaseDAO().executeQuery(sql, new ColumnProcessor()); - // 税码 - bVO.setAttributeValue("ctaxcodeid", o_pk_project); - } catch (BusinessException e) { - NCCForUAPLogger.debug("APISaleOrderMaitainImpl-setMaterl:" + e.getMessage()); - throw new RuntimeException(e); - } - } - - /** - * 修订销售订单的时候新增销售订单物料行的数据 - */ - private void addBvo(SaleOrderVO[] oldVOs, List> paramList) { - try { - SaleOrderVO[] copyVOs = new SaleOrderVO[oldVOs.length]; - for (int i = 0; i < oldVOs.length; i++) { - copyVOs[i] = (SaleOrderVO) oldVOs[i].clone(); - } - // 将 vos 中的元素按主键存储在 Map 中 - Map vosMap = new HashMap<>(); - for (SaleOrderVO vo : copyVOs) { - vosMap.put(vo.getParentVO().getCsaleorderid(), vo); - } - for (Map objectMap : paramList) { - Map headdata = (Map) objectMap.get("so_saleorder"); - String primaryKey = headdata.getOrDefault("csaleorderid", "") + ""; - SaleOrderVO vo = vosMap.get(primaryKey); - SaleOrderHVO hvo = vo.getParentVO(); - String csaleorderid = hvo.getCsaleorderid(); - String ybpk = hvo.getCorigcurrencyid(); - SaleOrderBVO[] bvos = vo.getChildrenVO(); - List bvoList = new ArrayList<>(Arrays.asList(bvos)); - SaleOrderBVO oneBvo = vo.getChildrenVO()[0]; - - List bodyArr = (List) objectMap.get("so_saleorder_b"); - for (Object body : bodyArr) { - Map bodydata = (Map) body; - if ("add".equals(bodydata.get("status"))) { - String pkOrgV = hvo.getPk_org_v(); - String pkOrg = hvo.getPk_org(); - String pk_group = AppContext.getInstance().getPkGroup(); - // 新数据的实体 - // SaleOrderBVO newBvo = (SaleOrderBVO) bvos[0].clone(); - SaleOrderBVO newBvo = new SaleOrderBVO(); - newBvo.setStatus(VOStatus.NEW); - newBvo.setAttributeValue("pk_group", pk_group); - String cprojectid = bodydata.get("cprojectid") + ""; - if (oneBvo != null && oneBvo.getCprojectid() != null && !"".equals(oneBvo.getCprojectid())) { - cprojectid = oneBvo.getCprojectid(); - } else { - String sql = " select pk_project from bd_project where project_code='" + cprojectid - + "' and nvl(dr,0)=0 "; - cprojectid = (String) new BaseDAO().executeQuery(sql, new ColumnProcessor()); - } - newBvo.setAttributeValue("cprojectid", cprojectid); - // newBvo.setAttributeValue("ctrafficorgvid", pkOrg); - // newBvo.setAttributeValue("csendstockorgvid", pkOrg); - // newBvo.setAttributeValue("csendstordocid", pkOrg); - // newBvo.setAttributeValue("csendstockorgid", pkOrg); - // newBvo.setAttributeValue("carorgid", pkOrg); - // newBvo.setAttributeValue("carorgvid", pkOrg); - // newBvo.setAttributeValue("csettleorgid", pkOrg); - // newBvo.setAttributeValue("csettleorgvid", pkOrg); - - newBvo.setAttributeValue("ctaxcountryid", "CN"); - newBvo.setAttributeValue("crececountryid", "CN"); - newBvo.setAttributeValue("csendcountryid", "CN"); - - newBvo.setAttributeValue("fbuysellflag", 1); - UFDouble nexchangerateBip = getUFDouble_NullAsOne(bodydata.get("nexchangerate")); - newBvo.setNexchangerate(nexchangerateBip); - // 设置物料的关联字段的值 - newBvo.setCmaterialvid(bodydata.get("cmaterialvid") + ""); - UFDouble ntaxrate = BFPubTools.getUFDouble_NullAsZero(bodydata.get("ntaxrate")); - UFDouble nnum = BFPubTools.getUFDouble_NullAsZero(bodydata.get("nnum")); - newBvo.setAttributeValue("ntaxrate", ntaxrate); - newBvo.setAttributeValue("nnum", nnum); - newBvo.setVbdef11(bodydata.getOrDefault("vbdef11", "") + ""); - - UFDouble norigtaxprice = BFPubTools.getUFDouble_NullAsZero(bodydata.get("norigtaxprice")); - newBvo.setAttributeValue("norigtaxprice", norigtaxprice); - UFDouble norigprice = BFPubTools.getUFDouble_NullAsZero(bodydata.get("norigprice")); - newBvo.setAttributeValue("norigprice", norigprice); - setMaterl(newBvo); - newBvo.setCsaleorderbid(null); - - newBvo.setCcurrencyid(ybpk); - String zbbz = newBvo.getCcurrencyid(); - - newBvo.setFtaxtypeflag(1); - - // 折本汇率 - UFDouble nexchangerate = newBvo.getNexchangerate(); - // 含税单价 - UFDouble nqtorigtaxprice = BFPubTools.getUFDouble_NullAsZero(bodydata.get("nqtorigtaxprice")); - newBvo.setAttributeValue("nqtorigtaxprice", nqtorigtaxprice); - // 无税单价 - UFDouble nqtorigprice = nqtorigtaxprice.div(UFDouble.ONE_DBL.add(ntaxrate.div(100))); - // 价税合计 - UFDouble norigtaxmny = nqtorigtaxprice.multiply(newBvo.getNqtunitnum()).setScale(2, 4); - newBvo.setNorigtaxmny(norigtaxmny); - // 无税金额 - UFDouble norigmny = nqtorigprice.multiply(newBvo.getNqtunitnum()); - - newBvo.setNorigmny(nc.itf.fi.pub.Currency.getFormaUfValue(ybpk, norigmny)); - // 税额 - newBvo.setNqtorigprice(nqtorigprice.setScale(4, 4)); - - // 无税本币金额单价 - UFDouble taxspric = nqtorigtaxprice.div(UFDouble.ONE_DBL.add(ntaxrate.div(100))); - - nqtorigprice = nqtorigprice.setScale(4, 4); - // nqtorigtaxnetprc--含税净价 - newBvo.setNqtorigtaxnetprc(nqtorigtaxprice); - // ,nqtorignetprice --无税净价 - newBvo.setNqtorignetprice(nqtorigprice); - String Vqtunitrate = newBvo.getVqtunitrate(); - UFDouble dVqtunitrate = UFDouble.ONE_DBL; - if (Vqtunitrate != null) { - dVqtunitrate = BFPubTools.getUFDouble_NullAsZero(Vqtunitrate.split("/")[0]); - } - // ,norigtaxprice --主含税单价 - - UFDouble wsje = taxspric.multiply(nexchangerate).multiply(newBvo.getNqtunitnum()); - if (ybpk.equals(zbbz) && BFPubTools.getString_TrimAsNull(newBvo.getCqtunitid()) - .equals(BFPubTools.getString_TrimAsNull(newBvo.getCastunitid()))) { - wsje = taxspric.multiply(nexchangerate).multiply(newBvo.getNqtunitnum()); - } - - wsje = nc.itf.fi.pub.Currency.getFormaUfValue(zbbz, wsje); - // 本币无税金额 - newBvo.setNorigtaxprice(nqtorigtaxprice.div(dVqtunitrate).setScale(4, 4)); - // ,norigprice --主无税单价 - newBvo.setNorigprice(nqtorigprice.div(dVqtunitrate).setScale(4, 4)); - // ,norigtaxnetprice --主含税净价 - newBvo.setNorigtaxnetprice(newBvo.getNorigtaxprice()); - // ,norignetprice --主无税净价 - newBvo.setNorignetprice(newBvo.getNorigprice()); - // ncaltaxmny --计税金额 - - // ,nqttaxprice --本币含税单价 - newBvo.setNqttaxprice(nqtorigtaxprice.multiply(nexchangerate)); - // ,nqtprice --本币无税单价 - UFDouble bbwsd = nqtorigtaxprice.div(UFDouble.ONE_DBL.add(ntaxrate.div(100))) - .multiply(nexchangerate); - newBvo.setNqtprice(bbwsd.setScale(4, 4)); - // , nqttaxnetprice --本币含税净价 - newBvo.setNqttaxnetprice(nqtorigtaxprice.multiply(nexchangerate)); - // ,nqtnetprice --本币无税净价 - UFDouble Nqtnetprice = nqtorigtaxprice.div(UFDouble.ONE_DBL.add(ntaxrate.div(100))) - .multiply(nexchangerate); - newBvo.setNqtnetprice(Nqtnetprice.setScale(4, 4)); - // ,ntaxprice --主本币含税单价 , nprice --主本币无税单价 - newBvo.setNtaxprice(nqtorigtaxprice.div(dVqtunitrate).multiply(nexchangerate).setScale(4, 4)); - UFDouble Nprice = nqtorigtaxprice.div(dVqtunitrate).div(UFDouble.ONE_DBL.add(ntaxrate.div(100))) - .multiply(nexchangerate); - newBvo.setNprice(Nprice.setScale(4, 4)); - // ,ntaxnetprice --主本币含税净价 - newBvo.setNtaxnetprice( - nqtorigtaxprice.div(dVqtunitrate).multiply(nexchangerate).setScale(4, 4)); - // ,nnetprice --主本币无税净价 - UFDouble nnetprice = nqtorigtaxprice.div(UFDouble.ONE_DBL.add(ntaxrate.div(100))) - .div(dVqtunitrate); - nnetprice = nnetprice.multiply(nexchangerate).setScale(4, 4); - newBvo.setNnetprice(nnetprice); - // nmny --本币无税金额 - // ntaxmny-- 本币价税合计 - newBvo.setNmny(Currency.getFormaUfValue(zbbz, norigmny.multiply(nexchangerate))); - newBvo.setNtaxmny(nqtorigtaxprice.multiply(nexchangerate).multiply(newBvo.getNqtunitnum()) - .setScale(2, 4)); - newBvo.setNcaltaxmny(wsje); - UFDouble ntax = norigtaxmny.multiply(nexchangerate).sub(wsje); - newBvo.setNtax(ntax.setScale(2, 4)); - newBvo.setCrowno(bodydata.get("crowno") + ""); - // 是否赠品 - String blargessflag = bodydata.getOrDefault("blargessflag", "N") + ""; - newBvo.setBlargessflag(UFBoolean.valueOf(blargessflag)); - bvoList.add(newBvo); - } - } - - SaleOrderBVO[] array = bvoList.toArray(new SaleOrderBVO[0]); - vo.setChildrenVO(array); - } - - // 填充默认值 - new SaleOrderSaveFillValue().setDefValue(copyVOs); - Map> listMap = new HashMap<>(); - for (SaleOrderVO copyVO : copyVOs) { - List newBvoList = new ArrayList<>(); - for (SaleOrderBVO saleOrderBVO : copyVO.getChildrenVO()) { - if (VOStatus.NEW == saleOrderBVO.getStatus()) { - SaleOrderBVO newBvo = (SaleOrderBVO) saleOrderBVO.clone(); - newBvoList.add(newBvo); - } - } - listMap.put(copyVO.getParentVO().getCsaleorderid(), newBvoList); - } - if (!listMap.isEmpty()) { - for (SaleOrderVO oldVO : oldVOs) { - String csaleorderid = oldVO.getParentVO().getCsaleorderid(); - SaleOrderBVO oneBvo = oldVO.getChildrenVO()[0]; - // 折本汇率 - UFDouble nexchangerate = oneBvo.getNexchangerate(); - nexchangerate = getUFDouble_NullAsOne(nexchangerate); - List newBvoList = listMap.get(csaleorderid); - if (newBvoList != null && !newBvoList.isEmpty()) { - // 上边填充默认值的时候取了系统的默认汇率,需要用BIP传的 - for (SaleOrderBVO saleOrderBVO : newBvoList) { - saleOrderBVO.setNexchangerate(nexchangerate); - } - SaleOrderBVO[] bvos = oldVO.getChildrenVO(); - List bvoList = new ArrayList<>(Arrays.asList(bvos)); - // 添加新增行 - bvoList.addAll(newBvoList); - SaleOrderBVO[] array = bvoList.toArray(new SaleOrderBVO[0]); - oldVO.setChildrenVO(array); - } - - } - } - /* - * for (SaleOrderVO combinBillVO : copyVOs) { for (SaleOrderBVO saleOrderBVO : - * combinBillVO.getChildrenVO()) { // 将实体对象转换为JSON字符串 String jsonString = - * JSON.toJSONString(saleOrderBVO); NCCForUAPLogger.debug("jsonString:" + - * jsonString); } } - */ - - } catch (Exception e) { - NCCForUAPLogger.debug("APISaleOrderMaitainImpl-addBvo:" + e.getMessage()); - throw new RuntimeException(e); - } - } - - private UFDouble getUFDouble_NullAsOne(Object value) { - if ((value == null) || (value.toString().trim().equals("")) || (value.toString().trim().equals("~"))) - return UFDouble.ONE_DBL; - if ((value instanceof UFDouble)) - return (UFDouble) value; - if ((value instanceof BigDecimal)) { - return new UFDouble((BigDecimal) value); - } - return new UFDouble(value.toString().trim()); - } + ordervo.getParentVO().setNtotalorigmny(sumnny.setScale(2, 4)); + } + + @Override + public SaleOrderVO[] save(List> paramList) throws BusinessException { + try { + List aggVOList = TransferMapToVOTool.transferMapToAggVO(paramList, SaleOrderVO.class); + + SaleOrderVO[] vos = (SaleOrderVO[]) aggVOList.toArray(new SaleOrderVO[aggVOList.size()]); + BillVOsCheckRule checker = new BillVOsCheckRule(new SaleOrderValidator()); + checker.check(vos); + + aggVOList = TransferCodeToPKTool.transferAggVO(aggVOList); + + SaleOrderSaveUtil saveUtil = new SaleOrderSaveUtil(); + return saveUtil.processBill(vos); + } catch (Exception e) { + ExceptionUtils.marsh(e); + return null; + } + } + + @Override + public SaleOrderVO[] update(List> paramList) throws BusinessException { + List aggVOList = TransferMapToVOTool.transferMapToAggVO(paramList, SaleOrderVO.class); + + aggVOList = TransferCodeToPKTool.transferAggVO(aggVOList); + + SaleOrderVO[] vos = (SaleOrderVO[]) aggVOList.toArray(new SaleOrderVO[aggVOList.size()]); + + Map> ids = getIds(vos); + if (ids.keySet() == null || ids.values() == null || ids.values().size() == 0) { + ExceptionUtils.wrappBusinessException("请传入订单主键和订单行主键"); + } + String[] hids = (String[]) ids.keySet().toArray(new String[ids.keySet().size()]); + + ISaleOrderMaintain service = (ISaleOrderMaintain) NCLocator.getInstance().lookup(ISaleOrderMaintain.class); + SaleOrderVO[] originVos = service.querySaleorder(hids); + if (null == originVos || originVos.length == 0) { + ExceptionUtils.wrappBusinessException("根据传入数据未匹配到相关数据"); + } + + for (Map objectMap : paramList) { + Map headdata = (Map) objectMap.get(HEADTABLE); + List bodyArr = (List) objectMap.get(BODYTABLE); + for (Object body : bodyArr) { + Map bodydata = (Map) body; + if (!(bodydata.getOrDefault("vbdef11", "") + "").isEmpty()) { + String vbdef11 = bodydata.get("vbdef11") + ""; + String dr = bodydata.getOrDefault("dr", "0") + ""; + String csaleorderid = bodydata.get("csaleorderid") + ""; + String countSql = "SELECT count(1) FROM so_saleorder_b" + + " WHERE nvl(dr,0) = 0 and csaleorderid = '[csaleorderid]' and vbdef11 = '[vbdef11]' "; + countSql = countSql.replace("[csaleorderid]", csaleorderid); + countSql = countSql.replace("[vbdef11]", vbdef11); + Integer num = (Integer) new BaseDAO().executeQuery(countSql, new ColumnProcessor()); + if ("0".equals(dr) && num <= 0) { + bodydata.put("status", "add"); + } + } + } + } + + // SetUpdateData setData = new SetUpdateData(); + // setData.setData(vos, originVos); + // SaleOrderVO[] combinBillVOs = (SaleOrderVO[]) AggVOUtil.combinBillVO(vos, + // originVos); + // 创建一个新的数组,并进行深拷贝 + SaleOrderVO[] combinBillVOs = new SaleOrderVO[originVos.length]; + for (int i = 0; i < originVos.length; i++) { + combinBillVOs[i] = (SaleOrderVO) originVos[i].clone(); + } + // 将 vos 中的元素按主键存储在 Map 中 + Map vosMap = new HashMap<>(); + for (SaleOrderVO vo : vos) { + vosMap.put(vo.getParentVO().getCsaleorderid(), vo); + } + + // 遍历 combinBillVOs 并更新字段 + for (SaleOrderVO vo : combinBillVOs) { + SaleOrderHVO hvo = vo.getParentVO(); + String primaryKey = hvo.getCsaleorderid(); + SaleOrderVO bipVo = vosMap.get(primaryKey); + // 设置单据状态 + hvo.setStatus(VOStatus.UPDATED); + + Map bvoMap = new HashMap<>(); + for (SaleOrderBVO saleOrderBVO : bipVo.getChildrenVO()) { + bvoMap.put(saleOrderBVO.getCsaleorderbid(), saleOrderBVO); + } + + // 比较combinBillVOs中的BVO和vos中的BVO + for (SaleOrderBVO bvo : vo.getChildrenVO()) { + bvo.setStatus(VOStatus.UPDATED); + // 设置删除的物料行的状态,在bip传的数据中找不到 + String csaleorderbid = bvo.getCsaleorderbid(); + if (bvoMap.get(csaleorderbid) == null) { + bvo.setStatus(VOStatus.DELETED); + NCCForUAPLogger.debug("findDeletedBids:" + VOStatus.DELETED + ",csaleorderbid = " + csaleorderbid); + } + } + // 更新 combinBillVO 中的字段为 vos 中的值 + updateFields(vo, bipVo); + // 设置新增的物料行 + if (paramList != null && !paramList.isEmpty()) { + addBvo(combinBillVOs, paramList); + } + } + // 联动计算 + INumPriceMnyCalculator cal = new SaleOrderNPriceMnyCal(combinBillVOs); + cal.calculate(); + for (SaleOrderVO vo : combinBillVOs) { + SaleOrderHVO hvo = vo.getParentVO(); + SaleOrderHVO originHvo = null; + for (SaleOrderVO originVo : originVos) { + if (hvo.getCsaleorderid().equals(originVo.getParentVO().getCsaleorderid())) { + originHvo = originVo.getParentVO(); + } + } + String new_ctrantypeid = hvo.getCtrantypeid(); + boolean isChangedTranType = false;// 订单类型不修改 + if (originHvo != null && new_ctrantypeid != null && !new_ctrantypeid.equals(originHvo.getCtrantypeid())) { + isChangedTranType = true; + } + SaleOrderBVO[] bvos = vo.getChildrenVO(); + // 判断是否存在新增的子表 + boolean hasNewStatus = Arrays.stream(bvos).anyMatch(bvo -> bvo.getStatus() == VOStatus.NEW); + // 新增子表或改订单类型的情况下不校验是否存在下游 + if (!hasNewStatus && !isChangedTranType) { + String countSql = "SELECT count(1) FROM so_saleinvoice_b a" + + " LEFT JOIN so_saleinvoice b ON a.csaleinvoiceid = b.csaleinvoiceid" + + " WHERE b.fopposeflag = 0 AND nvl(b.dr, 0) = 0 and csrcid = '[csrcid]' "; + countSql = countSql.replace("[csrcid]", hvo.getCsaleorderid()); + Integer num = (Integer) new BaseDAO().executeQuery(countSql, new ColumnProcessor()); + if (num > 0) { + // fopposeflag 对冲标记 0=正常 1=已被对冲 2=对冲生成 + ExceptionUtils.wrappBusinessException("下游存在未红冲完成的销售发票"); + return null; + } + } + } + + fillcustomervidbyoid(combinBillVOs); + + // 保存 + ISaleOrderScriptMaintain maintainsrv = NCLocator.getInstance().lookup(ISaleOrderScriptMaintain.class); + SaleOrderVO[] retvos = maintainsrv.saleOrderUpdate(combinBillVOs, null, originVos); + return retvos; + } + + private Map> getIds(SaleOrderVO[] vos) { + Map> ids = new HashMap>(); + for (SaleOrderVO vo : vos) { + String hid = vo.getParentVO().getCsaleorderid(); + Set bids = new HashSet(); + for (SaleOrderBVO bvo : vo.getChildrenVO()) { + bids.add(bvo.getCsaleorderbid()); + } + ids.put(hid, bids); + } + return ids; + } + + private void setOtherId(SaleOrderVO[] vos) { + for (SaleOrderVO vo : vos) { + // 部门、业务员、开票客户编码转id + SaleOrderHVO orderHVO = vo.getParentVO(); + String csaleorderid = orderHVO.getCsaleorderid(); + String cdeptvid = orderHVO.getCdeptvid(); + String cemployeeid = orderHVO.getCemployeeid(); + // 开票客户 + String cinvoicecustid = orderHVO.getCinvoicecustid(); + // 客户 + String ccustomerid = orderHVO.getCcustomerid(); + // 订单类型 + // String ctrantypeid = orderHVO.getAttributeValue("ctrantypeid") + ""; + String vtrantypecode = orderHVO.getVtrantypecode(); + NCCForUAPLogger.debug("setOtherId-ccustomerid:" + ccustomerid + ",vtrantypecode:" + vtrantypecode); + try { + String sql = ""; + // 部门 + if (cdeptvid != null && !cdeptvid.isEmpty()) { + sql = " select pk_vid,pk_dept from org_dept where code = '[code]' "; + sql = sql.replace("[code]", cdeptvid); + Map deptMap = (Map) new BaseDAO().executeQuery(sql, new MapProcessor()); + NCCForUAPLogger.debug("APISaleOrderMaitainImpl-setOtherId-deptObj:" + deptMap); + if (deptMap != null && !deptMap.isEmpty()) { + if (!"".equals(deptMap.getOrDefault("pk_dept", "") + "")) { + orderHVO.setCdeptid(deptMap.getOrDefault("pk_dept", "") + ""); + } + if (!"".equals(deptMap.getOrDefault("pk_vid", "") + "")) { + orderHVO.setCdeptvid(deptMap.getOrDefault("pk_vid", "") + ""); + } + } + } + // 业务员 + if (cemployeeid != null && !cemployeeid.isEmpty()) { + sql = " select pk_psndoc from bd_psndoc where code = '[code]' "; + sql = sql.replace("[code]", cemployeeid); + Object staffObj = new BaseDAO().executeQuery(sql, new ColumnProcessor("pk_psndoc")); + NCCForUAPLogger.debug("APISaleOrderMaitainImpl-setOtherId-staffObj:" + staffObj); + if (staffObj != null) { + String id = BFPubTools.getString_TrimAsNull(staffObj); + if (!id.isEmpty()) { + orderHVO.setCemployeeid(id); + } + } + } + // 开票客户 + if (cinvoicecustid != null && !cinvoicecustid.isEmpty()) { + sql = " select pk_customer from bd_customer where nvl(dr,0) = 0 and code = '[code]' "; + sql = sql.replace("[code]", cinvoicecustid); + Object invCustObj = new BaseDAO().executeQuery(sql, new ColumnProcessor("pk_customer")); + NCCForUAPLogger.debug("setOtherId-invCustObj:" + invCustObj); + if (invCustObj != null) { + String id = BFPubTools.getString_TrimAsNull(invCustObj); + if (!id.isEmpty()) { + orderHVO.setCinvoicecustid(id); + } + } + } + // 客户 + if (ccustomerid != null && !ccustomerid.isEmpty()) { + sql = " select pk_customer from bd_customer where nvl(dr,0) = 0 and code = '[code]' "; + sql = sql.replace("[code]", ccustomerid); + Object custObj = new BaseDAO().executeQuery(sql, new ColumnProcessor("pk_customer")); + NCCForUAPLogger.debug("setOtherId-custObj:" + custObj); + if (custObj != null) { + String id = BFPubTools.getString_TrimAsNull(custObj); + if (!id.isEmpty()) { + orderHVO.setCcustomerid(id); + } + } + } + // 交易类型 + if (vtrantypecode != null && !vtrantypecode.isEmpty()) { + IBilltypeService billtypeService = NCLocator.getInstance().lookup(IBilltypeService.class); + BilltypeVO billtype = billtypeService.getBilltype(vtrantypecode); + if (billtype != null && billtype.getPk_billtypeid() != null) { + NCCForUAPLogger.debug("setOtherId-pk_billtypeid:" + billtype.getPk_billtypeid()); + orderHVO.setCtrantypeid(billtype.getPk_billtypeid()); + } + } + } catch (Exception e) { + NCCForUAPLogger.debug("APISaleOrderMaitainImpl-setOtherId-exp:" + e.getMessage()); + throw new RuntimeException(e); + } + } + } + + private void updateFields(SaleOrderVO target, SaleOrderVO source) { + // 更新 SaleOrderHVO 字段 + SaleOrderHVO targetHVO = target.getParentVO(); + SaleOrderHVO sourceHVO = source.getParentVO(); + // 表头修改修改的字段 + String cdeptvid = sourceHVO.getCdeptvid(); + String cdeptid = sourceHVO.getCdeptid(); + if (cdeptvid != null && !cdeptvid.isEmpty()) { + targetHVO.setCdeptvid(cdeptvid); + targetHVO.setCdeptid(cdeptid); + } + + String cemployeeid = sourceHVO.getCemployeeid(); + if (cemployeeid != null && !cemployeeid.isEmpty()) { + targetHVO.setCemployeeid(cemployeeid); + } + String cinvoicecustid = sourceHVO.getCinvoicecustid(); + if (cinvoicecustid != null && !cinvoicecustid.isEmpty()) { + targetHVO.setCinvoicecustid(cinvoicecustid); + } + String ccustomerid = sourceHVO.getCcustomerid(); + if (ccustomerid != null && !ccustomerid.isEmpty()) { + targetHVO.setCcustomerid(ccustomerid); + } + // 订单类型id + String ctrantypeid = sourceHVO.getCtrantypeid(); + if (ctrantypeid != null && !ctrantypeid.isEmpty()) { + targetHVO.setCtrantypeid(ctrantypeid); + } + // 订单类型编码 + String vtrantypecode = sourceHVO.getVtrantypecode(); + if (vtrantypecode != null && !vtrantypecode.isEmpty()) { + targetHVO.setVtrantypecode(vtrantypecode); + } + + // 更新 SaleOrderBVO 字段 + SaleOrderBVO[] targetBVOs = target.getChildrenVO(); + SaleOrderBVO[] sourceBVOs = source.getChildrenVO(); + + // BVO 的主键是 csaleorderbid + Map sourceBVOsMap = new HashMap<>(); + for (SaleOrderBVO bvo : sourceBVOs) { + sourceBVOsMap.put(bvo.getCsaleorderbid(), bvo); + } + + for (SaleOrderBVO targetBVO : targetBVOs) { + String bvoId = targetBVO.getCsaleorderbid(); + SaleOrderBVO sourceBVO = sourceBVOsMap.get(bvoId); + if (sourceBVO != null) { + int status = targetBVO.getStatus(); + if (VOStatus.UPDATED == status) { + // 数量 + UFDouble nnum = sourceBVO.getNnum(); + targetBVO.setNnum(nnum); + targetBVO.setNastnum(nnum); + // targetBVO.setNqtunitnum(nnum); + // 价税合计 + targetBVO.setNorigtaxmny(sourceBVO.getNorigtaxmny()); + targetBVO.setCmaterialvid(sourceBVO.getCmaterialvid()); + // 是否赠品 + targetBVO.setBlargessflag(sourceBVO.getBlargessflag()); + // 折本汇率 + UFDouble nexchangerate = getUFDouble_NullAsOne(sourceBVO.getNexchangerate()); + targetBVO.setNexchangerate(nexchangerate); + // 物料编码 + String cmaterialvid = sourceBVO.getCmaterialvid(); + // 物料关联字段赋值 + if (cmaterialvid != null && !cmaterialvid.isEmpty()) { + setMaterl(targetBVO); + } + // 自定义项赋值 + String vbdef1 = sourceBVO.getVbdef1();// 合同编号 + Map defList = getDefList("zdy-001"); + targetBVO.setVbdef1(defList.getOrDefault(vbdef1, "")); + String vbdef5 = sourceBVO.getVbdef5();// 合同销售订单号 + defList.clear(); + defList = getDefList("BIP-ddh"); + targetBVO.setVbdef5(defList.getOrDefault(vbdef5, "")); + targetBVO.setVbdef10(sourceBVO.getVbdef10());// 项目名称 + targetBVO.setVbdef13(sourceBVO.getVbdef13());// 国网行项目号 + NCCForUAPLogger.debug(String.format( + "cmaterialvid = [%S], vbdef1 = [%S], vbdef5 = [%S], vbdef10 = [%S], vbdef13 = [%S]", + cmaterialvid, targetBVO.getVbdef1(), targetBVO.getVbdef5(), targetBVO.getVbdef10(), + targetBVO.getVbdef13())); + } + + } + } + } + + /** + * 获取自定义项信息 + */ + private Map getDefList(String code) { + Map map = new HashMap(); + String strWhere = " pk_defdoclist in (select pk_defdoclist from bd_defdoclist where code='" + code + + "' and dr=0 ) and dr = 0"; + try { + DefdocVO[] defdocVOs = (DefdocVO[]) new HYSuperDMO().queryByWhereClause(DefdocVO.class, strWhere); + if (defdocVOs != null && defdocVOs.length > 0) { + for (DefdocVO defdocVO : defdocVOs) { + map.put(defdocVO.getCode().trim(), defdocVO.getPk_defdoc()); + } + } + } catch (DAOException e) { + e.printStackTrace(); + } + return map; + + } + + @Override + public void delete(String[] hids) throws BusinessException { + BillQuery queryTool = new BillQuery(SaleOrderVO.class); + SaleOrderVO[] saleOrderVOs = (SaleOrderVO[]) queryTool.query(hids); + if (saleOrderVOs.length == 0) { + ExceptionUtils.wrappBusinessException("根据传入数据未匹配到相关数据"); + } + + PfServiceScmUtil.processBatch("DELETE", SOBillType.Order.getCode(), saleOrderVOs, null, null); + } + + private void fillcustomervidbyoid(SaleOrderVO[] combinBillVOs) { + Set customeridSet = new HashSet(); + Map customeridMap = new HashMap(); + for (SaleOrderVO vo : combinBillVOs) { + SaleOrderHVO hvo = vo.getParentVO(); + + if (!StringUtil.isSEmptyOrNull(hvo.getCcustomerid()) && StringUtil.isSEmptyOrNull(hvo.getCcustomervid())) { + customeridSet.add(hvo.getCcustomerid()); + } + + if (!StringUtil.isSEmptyOrNull(hvo.getCinvoicecustid()) + && StringUtil.isSEmptyOrNull(hvo.getCinvoicecustvid())) { + customeridSet.add(hvo.getCinvoicecustid()); + } + + if (!StringUtil.isSEmptyOrNull(hvo.getChreceivecustid()) + && StringUtil.isSEmptyOrNull(hvo.getChreceivecustvid())) { + customeridSet.add(hvo.getChreceivecustid()); + } + + SaleOrderBVO[] bvos = vo.getChildrenVO(); + for (SaleOrderBVO bvo : bvos) { + + if (!StringUtil.isSEmptyOrNull(bvo.getCreceivecustid()) + && StringUtil.isSEmptyOrNull(bvo.getCreceivecustvid())) { + customeridSet.add(bvo.getCreceivecustid()); + } + + if (!StringUtil.isSEmptyOrNull(bvo.getCvendorid()) && StringUtil.isSEmptyOrNull(bvo.getCvendorvid())) { + customeridSet.add(bvo.getCvendorid()); + } + } + } + + if (!customeridSet.isEmpty()) { + customeridMap = CustomerPubService + .queryCustomerVidsByOids((String[]) CollectionUtils.setToArray(customeridSet)); + } + + for (SaleOrderVO vo : combinBillVOs) { + SaleOrderHVO hvo = vo.getParentVO(); + + if (!StringUtil.isSEmptyOrNull(hvo.getCcustomerid()) && StringUtil.isSEmptyOrNull(hvo.getCcustomervid())) { + if (null == customeridMap || customeridMap.size() == 0) { + hvo.setCcustomervid(hvo.getCcustomerid()); + } else { + hvo.setCcustomervid((String) customeridMap.get(hvo.getCcustomerid())); + } + } + + if (!StringUtil.isSEmptyOrNull(hvo.getCinvoicecustid()) + && StringUtil.isSEmptyOrNull(hvo.getCinvoicecustvid())) { + if (null == customeridMap || customeridMap.size() == 0) { + hvo.setCinvoicecustvid(hvo.getCinvoicecustid()); + } else { + hvo.setCinvoicecustvid((String) customeridMap.get(hvo.getCinvoicecustid())); + } + } + + if (!StringUtil.isSEmptyOrNull(hvo.getChreceivecustid()) + && StringUtil.isSEmptyOrNull(hvo.getChreceivecustvid())) { + if (null == customeridMap || customeridMap.size() == 0) { + hvo.setChreceivecustvid(hvo.getChreceivecustid()); + } else { + hvo.setChreceivecustvid((String) customeridMap.get(hvo.getChreceivecustid())); + } + } + + SaleOrderBVO[] bvos = vo.getChildrenVO(); + for (SaleOrderBVO bvo : bvos) { + + if (!StringUtil.isSEmptyOrNull(bvo.getCreceivecustid()) + && StringUtil.isSEmptyOrNull(bvo.getCreceivecustvid())) { + if (null == customeridMap || customeridMap.size() == 0) { + bvo.setCreceivecustvid(bvo.getCreceivecustid()); + } else { + bvo.setCreceivecustvid((String) customeridMap.get(bvo.getCreceivecustid())); + } + } + + if (!StringUtil.isSEmptyOrNull(bvo.getCvendorid()) && StringUtil.isSEmptyOrNull(bvo.getCvendorvid())) { + if (null == customeridMap || customeridMap.size() == 0) { + bvo.setCvendorvid(bvo.getCvendorid()); + } else { + bvo.setCvendorvid((String) customeridMap.get(bvo.getCvendorid())); + } + } + } + } + } + + @Override + public SaleOrderVO[] sendApprove(String[] hids) throws BusinessException { + SaleOrderVO[] vos = querySaleOrder(hids); + try { + for (SaleOrderVO aggvo : vos) { + SaleOrderHVO parentVO = aggvo.getParentVO(); + if (!BillStatus.FREE.equalsValue(parentVO.getFstatusflag())) { + ExceptionUtils.wrappBusinessException("当前销售订单:" + parentVO.getVbillcode() + "不是自由状态,不能提交"); + } + } + return (SaleOrderVO[]) PfServiceScmUtil.processBatch("SAVE", SOBillType.Order.getCode(), vos, null, null); + } catch (Exception e) { + ExceptionUtils.marsh(e); + return null; + } + } + + @Override + public SaleOrderVO[] unSendApprove(String[] hids) throws BusinessException { + SaleOrderVO[] vos = querySaleOrder(hids); + try { + for (SaleOrderVO aggvo : vos) { + SaleOrderHVO parentVO = aggvo.getParentVO(); + if (!BillStatus.AUDITING.equalsValue(parentVO.getFstatusflag())) { + ExceptionUtils.wrappBusinessException("当前销售订单:" + parentVO.getVbillcode() + "不是提交状态,不能收回"); + } + } + return (SaleOrderVO[]) PfServiceScmUtil.processBatch("UNSAVE", SOBillType.Order.getCode(), vos, null, null); + } catch (Exception e) { + ExceptionUtils.marsh(e); + return null; + } + } + + @Override + public SaleOrderVO[] approve(String[] hids) throws BusinessException { + SaleOrderVO[] vos = querySaleOrder(hids); + try { + for (SaleOrderVO aggvo : vos) { + SaleOrderHVO parentVO = aggvo.getParentVO(); + if (!BillStatus.FREE.equalsValue(parentVO.getFstatusflag()) + && !BillStatus.AUDIT.equalsValue(parentVO.getFstatusflag()) + && !BillStatus.AUDITING.equalsValue(parentVO.getFstatusflag())) { + ExceptionUtils.wrappBusinessException("当前销售订单:" + parentVO.getVbillcode() + "状态不符合审批条件,不能审批"); + } + } + return (SaleOrderVO[]) PfServiceScmUtil.processBatch("APPROVE", SOBillType.Order.getCode(), vos, null, + null); + } catch (Exception e) { + ExceptionUtils.marsh(e); + return null; + } + } + + @Override + public SaleOrderVO[] unApprove(String[] hids) throws BusinessException { + SaleOrderVO[] vos = querySaleOrder(hids); + try { + for (SaleOrderVO aggvo : vos) { + SaleOrderHVO parentVO = aggvo.getParentVO(); + if (!BillStatus.AUDIT.equalsValue(parentVO.getFstatusflag()) + && !BillStatus.AUDITING.equalsValue(parentVO.getFstatusflag())) { + ExceptionUtils.wrappBusinessException("当前销售订单:" + parentVO.getVbillcode() + "状态不符合弃审条件,不能弃审"); + } + } + return (SaleOrderVO[]) PfServiceScmUtil.processBatch("UNAPPROVE", SOBillType.Order.getCode(), vos, null, + null); + } catch (Exception e) { + ExceptionUtils.marsh(e); + return null; + } + } + + private SaleOrderVO[] querySaleOrder(String[] hids) throws BusinessException { + ISaleOrderQueryAPI service = (ISaleOrderQueryAPI) NCLocator.getInstance().lookup(ISaleOrderQueryAPI.class); + SaleOrderVO[] vos = service.queryVOByIDs(hids); + if (ArrayUtils.isEmpty(vos)) { + ExceptionUtils.wrappBusinessException("没有符合条件的数据"); + } else { + return vos; + } + return null; + } + + /** + * 设置物料的相关字段 + */ + private void setMaterl(SaleOrderBVO bVO) { + String cmaterialvid = bVO.getCmaterialvid(); + UFDouble nnum = bVO.getNnum(); + UFDouble ntaxrate = bVO.getNtaxrate(); + try { + String sql = " select a.pk_material,a.pk_source, a.pk_measdoc cunitid,nvl(b.pk_measdoc,a.pk_measdoc) castunitid,nvl(b.measrate,'1/1') measrate " + + "from bd_material a left join bd_materialconvert b on a.pk_material=b.pk_material " + + "where a.code='" + cmaterialvid + "' "; + Map map = (Map) new BaseDAO().executeQuery(sql, new MapProcessor()); + if (map == null) { + throw new BusinessException(cmaterialvid + "物料未查到"); + } + NCCForUAPLogger.debug(String.format("setMaterl: cqtunitid = [%S], cunitid = [%S], castunitid = [%S]", + map.get("cqtunitid"), map.get("cunitid"), map.get("castunitid"))); + bVO.setAttributeValue("castunitid", map.get("castunitid")); + bVO.setAttributeValue("vchangerate", map.get("vchangerate")); + + // 重新计算金额 + bVO.setAttributeValue("cqtunitid", map.get("cunitid")); + bVO.setAttributeValue("cunitid", map.get("cunitid")); + + bVO.setAttributeValue("cmaterialid", map.get("pk_material")); + bVO.setAttributeValue("cmaterialvid", map.get("pk_material")); + + UFDouble nqtunitnum = BFPubTools.getUFDouble_NullAsZero(nnum) + .div(BFPubTools.getUFDouble_NullAsZero(map.get("measrate").toString().split("/")[0])); + bVO.setAttributeValue("nqtunitnum", nqtunitnum); + + sql = "select sl.pk_taxcode from bd_taxrate sl inner join bd_taxcode sm on sl.pk_taxcode=sm.pk_taxcode where sl.taxrate=" + + ntaxrate + " and sm.pk_group<>'~' " + ""; + + String o_pk_project = (String) new BaseDAO().executeQuery(sql, new ColumnProcessor()); + // 税码 + bVO.setAttributeValue("ctaxcodeid", o_pk_project); + } catch (BusinessException e) { + NCCForUAPLogger.debug("APISaleOrderMaitainImpl-setMaterl:" + e.getMessage()); + throw new RuntimeException(e); + } + } + + /** + * 修订销售订单的时候新增销售订单物料行的数据 + */ + private void addBvo(SaleOrderVO[] oldVOs, List> paramList) { + try { + SaleOrderVO[] copyVOs = new SaleOrderVO[oldVOs.length]; + for (int i = 0; i < oldVOs.length; i++) { + copyVOs[i] = (SaleOrderVO) oldVOs[i].clone(); + } + // 将 vos 中的元素按主键存储在 Map 中 + Map vosMap = new HashMap<>(); + for (SaleOrderVO vo : copyVOs) { + vosMap.put(vo.getParentVO().getCsaleorderid(), vo); + } + for (Map objectMap : paramList) { + Map headdata = (Map) objectMap.get("so_saleorder"); + String primaryKey = headdata.getOrDefault("csaleorderid", "") + ""; + SaleOrderVO vo = vosMap.get(primaryKey); + SaleOrderHVO hvo = vo.getParentVO(); + String csaleorderid = hvo.getCsaleorderid(); + String ybpk = hvo.getCorigcurrencyid(); + SaleOrderBVO[] bvos = vo.getChildrenVO(); + List bvoList = new ArrayList<>(Arrays.asList(bvos)); + SaleOrderBVO oneBvo = vo.getChildrenVO()[0]; + + List bodyArr = (List) objectMap.get("so_saleorder_b"); + for (Object body : bodyArr) { + Map bodydata = (Map) body; + if ("add".equals(bodydata.get("status"))) { + String pkOrgV = hvo.getPk_org_v(); + String pkOrg = hvo.getPk_org(); + String pk_group = AppContext.getInstance().getPkGroup(); + // 新数据的实体 + // SaleOrderBVO newBvo = (SaleOrderBVO) bvos[0].clone(); + SaleOrderBVO newBvo = new SaleOrderBVO(); + newBvo.setStatus(VOStatus.NEW); + newBvo.setAttributeValue("pk_group", pk_group); + String cprojectid = bodydata.get("cprojectid") + ""; + if (oneBvo != null && oneBvo.getCprojectid() != null && !"".equals(oneBvo.getCprojectid())) { + cprojectid = oneBvo.getCprojectid(); + } else { + String sql = " select pk_project from bd_project where project_code='" + cprojectid + + "' and nvl(dr,0)=0 "; + cprojectid = (String) new BaseDAO().executeQuery(sql, new ColumnProcessor()); + } + newBvo.setAttributeValue("cprojectid", cprojectid); + // newBvo.setAttributeValue("ctrafficorgvid", pkOrg); + // newBvo.setAttributeValue("csendstockorgvid", pkOrg); + // newBvo.setAttributeValue("csendstordocid", pkOrg); + // newBvo.setAttributeValue("csendstockorgid", pkOrg); + // newBvo.setAttributeValue("carorgid", pkOrg); + // newBvo.setAttributeValue("carorgvid", pkOrg); + // newBvo.setAttributeValue("csettleorgid", pkOrg); + // newBvo.setAttributeValue("csettleorgvid", pkOrg); + + newBvo.setAttributeValue("ctaxcountryid", "CN"); + newBvo.setAttributeValue("crececountryid", "CN"); + newBvo.setAttributeValue("csendcountryid", "CN"); + + newBvo.setAttributeValue("fbuysellflag", 1); + UFDouble nexchangerateBip = getUFDouble_NullAsOne(bodydata.get("nexchangerate")); + newBvo.setNexchangerate(nexchangerateBip); + // 设置物料的关联字段的值 + newBvo.setCmaterialvid(bodydata.get("cmaterialvid") + ""); + UFDouble ntaxrate = BFPubTools.getUFDouble_NullAsZero(bodydata.get("ntaxrate")); + UFDouble nnum = BFPubTools.getUFDouble_NullAsZero(bodydata.get("nnum")); + newBvo.setAttributeValue("ntaxrate", ntaxrate); + newBvo.setAttributeValue("nnum", nnum); + newBvo.setVbdef11(bodydata.getOrDefault("vbdef11", "") + ""); + + UFDouble norigtaxprice = BFPubTools.getUFDouble_NullAsZero(bodydata.get("norigtaxprice")); + newBvo.setAttributeValue("norigtaxprice", norigtaxprice); + UFDouble norigprice = BFPubTools.getUFDouble_NullAsZero(bodydata.get("norigprice")); + newBvo.setAttributeValue("norigprice", norigprice); + setMaterl(newBvo); + newBvo.setCsaleorderbid(null); + + newBvo.setCcurrencyid(ybpk); + String zbbz = newBvo.getCcurrencyid(); + + newBvo.setFtaxtypeflag(1); + + // 折本汇率 + UFDouble nexchangerate = newBvo.getNexchangerate(); + // 含税单价 + UFDouble nqtorigtaxprice = BFPubTools.getUFDouble_NullAsZero(bodydata.get("nqtorigtaxprice")); + newBvo.setAttributeValue("nqtorigtaxprice", nqtorigtaxprice); + // 无税单价 + UFDouble nqtorigprice = nqtorigtaxprice.div(UFDouble.ONE_DBL.add(ntaxrate.div(100))); + // 价税合计 + UFDouble norigtaxmny = nqtorigtaxprice.multiply(newBvo.getNqtunitnum()).setScale(2, 4); + newBvo.setNorigtaxmny(norigtaxmny); + // 无税金额 + UFDouble norigmny = nqtorigprice.multiply(newBvo.getNqtunitnum()); + + newBvo.setNorigmny(nc.itf.fi.pub.Currency.getFormaUfValue(ybpk, norigmny)); + // 税额 + newBvo.setNqtorigprice(nqtorigprice.setScale(4, 4)); + + // 无税本币金额单价 + UFDouble taxspric = nqtorigtaxprice.div(UFDouble.ONE_DBL.add(ntaxrate.div(100))); + + nqtorigprice = nqtorigprice.setScale(4, 4); + // nqtorigtaxnetprc--含税净价 + newBvo.setNqtorigtaxnetprc(nqtorigtaxprice); + // ,nqtorignetprice --无税净价 + newBvo.setNqtorignetprice(nqtorigprice); + String Vqtunitrate = newBvo.getVqtunitrate(); + UFDouble dVqtunitrate = UFDouble.ONE_DBL; + if (Vqtunitrate != null) { + dVqtunitrate = BFPubTools.getUFDouble_NullAsZero(Vqtunitrate.split("/")[0]); + } + // ,norigtaxprice --主含税单价 + + UFDouble wsje = taxspric.multiply(nexchangerate).multiply(newBvo.getNqtunitnum()); + if (ybpk.equals(zbbz) && BFPubTools.getString_TrimAsNull(newBvo.getCqtunitid()) + .equals(BFPubTools.getString_TrimAsNull(newBvo.getCastunitid()))) { + wsje = taxspric.multiply(nexchangerate).multiply(newBvo.getNqtunitnum()); + } + + wsje = nc.itf.fi.pub.Currency.getFormaUfValue(zbbz, wsje); + // 本币无税金额 + newBvo.setNorigtaxprice(nqtorigtaxprice.div(dVqtunitrate).setScale(4, 4)); + // ,norigprice --主无税单价 + newBvo.setNorigprice(nqtorigprice.div(dVqtunitrate).setScale(4, 4)); + // ,norigtaxnetprice --主含税净价 + newBvo.setNorigtaxnetprice(newBvo.getNorigtaxprice()); + // ,norignetprice --主无税净价 + newBvo.setNorignetprice(newBvo.getNorigprice()); + // ncaltaxmny --计税金额 + + // ,nqttaxprice --本币含税单价 + newBvo.setNqttaxprice(nqtorigtaxprice.multiply(nexchangerate)); + // ,nqtprice --本币无税单价 + UFDouble bbwsd = nqtorigtaxprice.div(UFDouble.ONE_DBL.add(ntaxrate.div(100))) + .multiply(nexchangerate); + newBvo.setNqtprice(bbwsd.setScale(4, 4)); + // , nqttaxnetprice --本币含税净价 + newBvo.setNqttaxnetprice(nqtorigtaxprice.multiply(nexchangerate)); + // ,nqtnetprice --本币无税净价 + UFDouble Nqtnetprice = nqtorigtaxprice.div(UFDouble.ONE_DBL.add(ntaxrate.div(100))) + .multiply(nexchangerate); + newBvo.setNqtnetprice(Nqtnetprice.setScale(4, 4)); + // ,ntaxprice --主本币含税单价 , nprice --主本币无税单价 + newBvo.setNtaxprice(nqtorigtaxprice.div(dVqtunitrate).multiply(nexchangerate).setScale(4, 4)); + UFDouble Nprice = nqtorigtaxprice.div(dVqtunitrate).div(UFDouble.ONE_DBL.add(ntaxrate.div(100))) + .multiply(nexchangerate); + newBvo.setNprice(Nprice.setScale(4, 4)); + // ,ntaxnetprice --主本币含税净价 + newBvo.setNtaxnetprice( + nqtorigtaxprice.div(dVqtunitrate).multiply(nexchangerate).setScale(4, 4)); + // ,nnetprice --主本币无税净价 + UFDouble nnetprice = nqtorigtaxprice.div(UFDouble.ONE_DBL.add(ntaxrate.div(100))) + .div(dVqtunitrate); + nnetprice = nnetprice.multiply(nexchangerate).setScale(4, 4); + newBvo.setNnetprice(nnetprice); + // nmny --本币无税金额 + // ntaxmny-- 本币价税合计 + newBvo.setNmny(Currency.getFormaUfValue(zbbz, norigmny.multiply(nexchangerate))); + newBvo.setNtaxmny(nqtorigtaxprice.multiply(nexchangerate).multiply(newBvo.getNqtunitnum()) + .setScale(2, 4)); + newBvo.setNcaltaxmny(wsje); + UFDouble ntax = norigtaxmny.multiply(nexchangerate).sub(wsje); + newBvo.setNtax(ntax.setScale(2, 4)); + newBvo.setCrowno(bodydata.get("crowno") + ""); + // 是否赠品 + String blargessflag = bodydata.getOrDefault("blargessflag", "N") + ""; + newBvo.setBlargessflag(UFBoolean.valueOf(blargessflag)); + bvoList.add(newBvo); + } + } + + SaleOrderBVO[] array = bvoList.toArray(new SaleOrderBVO[0]); + vo.setChildrenVO(array); + } + + // 填充默认值 + new SaleOrderSaveFillValue().setDefValue(copyVOs); + Map> listMap = new HashMap<>(); + for (SaleOrderVO copyVO : copyVOs) { + List newBvoList = new ArrayList<>(); + for (SaleOrderBVO saleOrderBVO : copyVO.getChildrenVO()) { + if (VOStatus.NEW == saleOrderBVO.getStatus()) { + SaleOrderBVO newBvo = (SaleOrderBVO) saleOrderBVO.clone(); + newBvoList.add(newBvo); + } + } + listMap.put(copyVO.getParentVO().getCsaleorderid(), newBvoList); + } + if (!listMap.isEmpty()) { + for (SaleOrderVO oldVO : oldVOs) { + String csaleorderid = oldVO.getParentVO().getCsaleorderid(); + SaleOrderBVO oneBvo = oldVO.getChildrenVO()[0]; + // 折本汇率 + UFDouble nexchangerate = oneBvo.getNexchangerate(); + nexchangerate = getUFDouble_NullAsOne(nexchangerate); + List newBvoList = listMap.get(csaleorderid); + if (newBvoList != null && !newBvoList.isEmpty()) { + // 上边填充默认值的时候取了系统的默认汇率,需要用BIP传的 + for (SaleOrderBVO saleOrderBVO : newBvoList) { + saleOrderBVO.setNexchangerate(nexchangerate); + } + SaleOrderBVO[] bvos = oldVO.getChildrenVO(); + List bvoList = new ArrayList<>(Arrays.asList(bvos)); + // 添加新增行 + bvoList.addAll(newBvoList); + SaleOrderBVO[] array = bvoList.toArray(new SaleOrderBVO[0]); + oldVO.setChildrenVO(array); + } + + } + } + /* + * for (SaleOrderVO combinBillVO : copyVOs) { for (SaleOrderBVO saleOrderBVO : + * combinBillVO.getChildrenVO()) { // 将实体对象转换为JSON字符串 String jsonString = + * JSON.toJSONString(saleOrderBVO); NCCForUAPLogger.debug("jsonString:" + + * jsonString); } } + */ + + } catch (Exception e) { + NCCForUAPLogger.debug("APISaleOrderMaitainImpl-addBvo:" + e.getMessage()); + throw new RuntimeException(e); + } + } + + private UFDouble getUFDouble_NullAsOne(Object value) { + if ((value == null) || (value.toString().trim().equals("")) || (value.toString().trim().equals("~"))) + return UFDouble.ONE_DBL; + if ((value instanceof UFDouble)) + return (UFDouble) value; + if ((value instanceof BigDecimal)) { + return new UFDouble((BigDecimal) value); + } + return new UFDouble(value.toString().trim()); + } } diff --git a/so/src/public/nc/vo/so/m32/saleinvoice/operator/billSaveAction.java b/so/src/public/nc/vo/so/m32/saleinvoice/operator/billSaveAction.java new file mode 100644 index 0000000..0e0b043 --- /dev/null +++ b/so/src/public/nc/vo/so/m32/saleinvoice/operator/billSaveAction.java @@ -0,0 +1,344 @@ +package nc.vo.so.m32.saleinvoice.operator; + +import com.alibaba.fastjson.JSONObject; +import nc.bs.framework.common.NCLocator; +import nc.bs.framework.core.util.ObjectCreator; +import nc.bs.ia.audit.pub.CloneUtil; +import nc.bs.logging.Logger; +import nc.bs.trade.business.HYSuperDMO; +import nc.itf.uap.IUAPQueryBS; +import nc.pubitf.so.m32.api.ISaleinvoiceQueryAPI; +import nc.vo.pub.BusinessException; +import nc.vo.pub.lang.UFBoolean; +import nc.vo.pub.lang.UFDate; +import nc.vo.pub.lang.UFDouble; +import nc.vo.scmpub.res.billtype.SOBillType; +import nc.vo.so.m32.entity.SaleInvoiceBVO; +import nc.vo.so.m32.entity.SaleInvoiceHVO; +import nc.vo.so.m32.entity.SaleInvoiceVO; +import nc.vo.sscivm.ivsale.IVApplicationAggVO; +import nc.vo.sscivm.ivsale.IVApplicationBodyVO; +import nc.vo.sscivm.ivsale.IVApplicationHeadVO; +import nccloud.api.baseapp.exchange.convert.IExchangeForService; +import nccloud.api.baseapp.exchange.convert.OpenApiConvertDataObject; +import nccloud.api.baseapp.exchange.convert.OpenApiConvertDataResult; +import nccloud.api.rest.utils.ResultMessageUtil; +import nccloud.itf.sscivm.ivsale.impl.IVApplicationServiceImpl; +import nccloud.pubitf.riart.pflow.CloudPFlowContext; +import nccloud.pubitf.riart.pflow.ICloudScriptPFlowService; +import nccloud.ws.rest.resource.AbstractNCCRestResource; +import org.json.JSONString; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import java.util.List; + + +@Path("so/saleinvoice/operator") +public class billSaveAction extends AbstractNCCRestResource { + + public static String fplxStr = "";// 开票申请发票类型 + + public billSaveAction() { + + } + + public OpenApiConvertDataResult changeToExchangeData(OpenApiConvertDataObject openApiConvertDataObject) + throws Exception { + return getPFxxEJBService().changeToExchangeData(openApiConvertDataObject); + } + + public static IExchangeForService getPFxxEJBService() { + IExchangeForService exchangeForService = (IExchangeForService) ObjectCreator.newInstance("ufesbexpress", + "nccloud.pubimpl.pfxx.convert.ExchangeForServiceImpl"); + return exchangeForService; + } + + @Override + public String getModule() { + return "so"; + } + + @POST + @Path("/billSaveRp") + @Consumes({"application/json"}) + @Produces({"application/json"}) + public JSONString billSaveRp(JSONString json) throws Exception { + /** + * 销售发票红冲: + * 1.根据bip传参中的销售发票主表id查询erp的销售发票VO + * 2.根据查询的销售发票VO生成红冲的销售发票 + */ + JSONObject jobject = JSONObject.parseObject(json.toJSONString()); + if (jobject == null) { + return ResultMessageUtil.exceptionToJSON(new NullPointerException("JSONString:null")); + } + JSONObject bject = jobject.getJSONObject("billhead"); + if (bject == null) { + return ResultMessageUtil.exceptionToJSON(new NullPointerException("billhead:null")); + } + String csaleinvoiceid = bject.getString("csaleinvoiceid"); // 销售发票id + // 根据销售发票主实体id查询销售发票 + String[] ids = {csaleinvoiceid}; + SaleInvoiceVO[] saleInvoiceVOs = NCLocator.getInstance().lookup(ISaleinvoiceQueryAPI.class) + .queryVOByIDs(ids); + if (saleInvoiceVOs.length <= 0) { + return ResultMessageUtil.exceptionToJSON(new NullPointerException("未查询到Erp对应的销售发票")); + } + try { + // 调用函数根据原销售发票组装新红冲发票 + SaleInvoiceVO saleInvoiceRedRushVO = makeNewRedRushSaleInvoice(saleInvoiceVOs[0], bject); + // 生成红冲发票 + ICloudScriptPFlowService flowService = NCLocator.getInstance().lookup(ICloudScriptPFlowService.class); + CloudPFlowContext context = new CloudPFlowContext(); + context.setBillType("32"); + context.setBillVos(new SaleInvoiceVO[]{saleInvoiceRedRushVO}); + context.setActionName("WRITE"); + SaleInvoiceVO[] returnSaveSaleInvoiceVOs = (SaleInvoiceVO[]) flowService.exeScriptPFlow(context); +// SaleInvoiceVO[] returnSaveSaleInvoiceVO = (SaleInvoiceVO[])PfServiceScmUtil.processBatch("WRITE", SOBillType.Invoice.getCode(), new SaleInvoiceVO[] { saleInvoiceRedRushVO }, null, null); + if (returnSaveSaleInvoiceVOs != null && returnSaveSaleInvoiceVOs.length > 0) { + // 生成红冲发票成功后,执行销售发票审批动作 + context.setBillType("32"); + context.setBillVos(returnSaveSaleInvoiceVOs); + context.setActionName("APPROVE"); + SaleInvoiceVO[] returnApproveSaleInvoiceVOs = (SaleInvoiceVO[]) flowService.exeScriptPFlow(context); + if (returnApproveSaleInvoiceVOs == null && returnApproveSaleInvoiceVOs.length <= 0) { + throw new BusinessException("生成销售发票审核失败"); + } + /** + * 开票申请红冲逻辑: + * 1.根据销售发票号查询下游开票申请 + * 2.根据原开票申请生成新红冲 + */ + String vBillcode = saleInvoiceVOs[0].getParentVO().getVbillcode(); + HYSuperDMO dmo = new HYSuperDMO(); + // 开票申请单主表 + IVApplicationHeadVO[] iVApplicationHeadVO = (IVApplicationHeadVO[]) dmo.queryByWhereClause(IVApplicationHeadVO.class, "src_billno='" + vBillcode + "' and dr=0 "); + String pk_ivapplication = iVApplicationHeadVO[0].getPk_ivapplication(); // 开票申请id + // 开票申请单子表 + IVApplicationBodyVO[] iVApplicationBodyVOs = (IVApplicationBodyVO[]) dmo.queryByWhereClause(IVApplicationBodyVO.class, "pk_ivapplication='" + pk_ivapplication + "' and dr=0 "); + // 调用函数封装开票申请红冲VO + IVApplicationAggVO iVApplicationAggVO = makeNewRedRushIVApplicationAggVO(iVApplicationHeadVO[0], iVApplicationBodyVOs, bject, returnApproveSaleInvoiceVOs); + // 生成红冲的开票申请 +// context.setBillType("SSCIVA"); +// context.setBillVos( new IVApplicationAggVO[] { iVApplicationAggVO }); +// context.setActionName("SAVE"); +// IVApplicationAggVO[] returnSaveIVApplicationAggVO = (IVApplicationAggVO[] )flowService.exeScriptPFlow(context); + IVApplicationServiceImpl serviceImpl = new IVApplicationServiceImpl(); + IVApplicationAggVO returnSaveIVApplicationAggVO = serviceImpl.save(iVApplicationAggVO); +// Object returnIVApplicationAggVO = PfServiceScmUtil.processBatch("SAVE", "SSCIVA", new IVApplicationAggVO[] { iVApplicationAggVO }, null, null); + if (returnSaveIVApplicationAggVO != null) { + return ResultMessageUtil.toJSON(null, "接口调用成功"); + } else { + Exception e = new Exception("接口调用失败"); + return ResultMessageUtil.exceptionToJSON(e); + } + } else { + Exception e = new Exception("接口调用失败"); + return ResultMessageUtil.exceptionToJSON(e); + } + } catch (BusinessException e) { + Logger.error("writeBack Error: ", e); + return ResultMessageUtil.exceptionToJSON(e); + } + } + + /** + * 构造红冲发票VO + * + * @param originalSaleInvoiceVO + * @param bject + * @return + * @throws Exception + */ + public static SaleInvoiceVO makeNewRedRushSaleInvoice(SaleInvoiceVO originalSaleInvoiceVO, JSONObject bject) throws Exception { + try { + SaleInvoiceVO saleInvoiceVO = new SaleInvoiceVO(); + SaleInvoiceHVO saleInvoiceHVO = originalSaleInvoiceVO.getParentVO(); // 主实体 + SaleInvoiceBVO[] saleInvoiceBVOs = originalSaleInvoiceVO.getChildrenVO(); // 子实体 + SaleInvoiceHVO newSaleInvoiceHVO = new SaleInvoiceHVO(); // 新主实体 + + // 子实体属性赋值 + UFDouble sumNum = new UFDouble(); // 合计数量 + UFDouble sumNtax = new UFDouble(); // 合计税额 + UFDouble sumNcaltaxmny = new UFDouble(); // 合计计税金额 + UFDouble sumNorigmny = new UFDouble(); // 合计无税金额 + UFDouble sumNorigtaxmny = new UFDouble(); // 合计价税合计 + int i = 0; + com.alibaba.fastjson.JSONArray paramsSaleInvoiceBVOsJSA = (com.alibaba.fastjson.JSONArray) bject.get("SaleInvoiceBVOs"); // 参数子实体数组 + List paramsSaleInvoiceBVOs = paramsSaleInvoiceBVOsJSA.toJavaList(JSONObject.class); + SaleInvoiceBVO[] newSaleInvoiceBVOs = new SaleInvoiceBVO[paramsSaleInvoiceBVOs.size()]; // 新子实体 + for (SaleInvoiceBVO saleInvoiceBVO : saleInvoiceBVOs) { + String csaleinvoicebid = saleInvoiceBVO.getCsaleinvoicebid(); // 子表id + // 筛选参数红冲的子表集合 + List newParamsSaleInvoiceBVOs = paramsSaleInvoiceBVOs.stream().filter(item -> { + String parCsaleinvoicebid = item.getString("csaleinvoicebid") + ""; + return csaleinvoicebid.equals(parCsaleinvoicebid); + }).toList(); + if (newParamsSaleInvoiceBVOs.size() <= 0) { + continue; + } + JSONObject paramSaleInvoiceBVO = newParamsSaleInvoiceBVOs.get(0); // 参数子表 + SaleInvoiceBVO newSaleInvoiceBVO = new SaleInvoiceBVO(); +// BeanUtil.copyProperties(saleInvoiceBVO,newSaleInvoiceBVO); + // 克隆取值原子表销售发票 + newSaleInvoiceBVO = (SaleInvoiceBVO) CloneUtil.depthClone(saleInvoiceBVO); + // 赋值之后修改子实体红冲时字段 + newSaleInvoiceBVO.setCsaleinvoicebid(null); // 发票子实体id + newSaleInvoiceBVO.setDbilldate(newSaleInvoiceHVO.getDbilldate()); // 开票日期 + newSaleInvoiceBVO.setNastnum(new UFDouble(paramSaleInvoiceBVO.getString("nastnum"))); // 数量 + newSaleInvoiceBVO.setNnum(new UFDouble(paramSaleInvoiceBVO.getString("nnum"))); // 主数量 + newSaleInvoiceBVO.setNtax(new UFDouble(paramSaleInvoiceBVO.getString("ntax"))); // 税额 + newSaleInvoiceBVO.setNmny(new UFDouble(paramSaleInvoiceBVO.getString("nmny"))); // 本币无税金额 + newSaleInvoiceBVO.setNtaxmny(new UFDouble(paramSaleInvoiceBVO.getString("ntaxmny"))); // 本币价税合计 + newSaleInvoiceBVO.setNcaltaxmny(new UFDouble(paramSaleInvoiceBVO.getString("ncaltaxmny"))); // 计税金额 + newSaleInvoiceBVO.setNorigmny(new UFDouble(paramSaleInvoiceBVO.getString("norigmny"))); // 无税金额 + newSaleInvoiceBVO.setNorigtaxmny(new UFDouble(paramSaleInvoiceBVO.getString("norigtaxmny"))); // 价税合计 + newSaleInvoiceBVO.setCopposesrcbid(paramSaleInvoiceBVO.getString("csaleinvoicebid")); // 对冲来源子表id + newSaleInvoiceBVO.setNqtunitnum(null); // 报价数量 + newSaleInvoiceBVO.setCsaleinvoiceid(null); // 发票关联主表id + newSaleInvoiceBVO.setNtotalcostnum(null); // 累计成本结算数量 + newSaleInvoiceBVO.setNtotalincomemny(null); // 累计确认应收金额 + newSaleInvoiceBVO.setNtotalincomenum(null); // 累计确认应收数量 + newSaleInvoiceBVO.setVchangerate("1.00/1.00"); // 换算率 + newSaleInvoiceBVOs[i++] = newSaleInvoiceBVO; + sumNum = sumNum.add(new UFDouble(paramSaleInvoiceBVO.getString("nnum"))); + sumNtax = sumNtax.add(new UFDouble(paramSaleInvoiceBVO.getString("ntax"))); + sumNcaltaxmny = sumNcaltaxmny.add(new UFDouble(paramSaleInvoiceBVO.getString("ncaltaxmny"))); + sumNorigmny = sumNorigmny.add(new UFDouble(paramSaleInvoiceBVO.getString("norigmny"))); + sumNorigtaxmny = sumNorigtaxmny.add(new UFDouble(paramSaleInvoiceBVO.getString("norigtaxmny"))); + } + + // 克隆取值原子表销售发票 + newSaleInvoiceHVO = (SaleInvoiceHVO) CloneUtil.depthClone(saleInvoiceHVO); + // 赋值之后修改主实体红冲时字段 + newSaleInvoiceHVO.setCsaleinvoiceid(null); // 发票主实体id + newSaleInvoiceHVO.setVbillcode(null); // 发票号 + newSaleInvoiceHVO.setDbilldate(new UFDate()); // 开票日期 + newSaleInvoiceHVO.setDmakedate(new UFDate()); // 制单日期 + newSaleInvoiceHVO.setBsubunitflag(UFBoolean.TRUE); // 冲抵标记 + newSaleInvoiceHVO.setFopposeflag(2); // 对冲标记 (2:对冲生成) + newSaleInvoiceHVO.setFstatusflag(1); // 单据状态 (1:自由态) + newSaleInvoiceHVO.setNtotalastnum(null); // 总数量 + newSaleInvoiceHVO.setNtotalorigsubmny(null); // 冲抵金额 + newSaleInvoiceHVO.setNtotalorigmny(null); // 价税合计 + newSaleInvoiceHVO.setVopposesrccode(saleInvoiceHVO.getVbillcode()); // 对冲来源发票号 + newSaleInvoiceHVO.setCopposesrcid(saleInvoiceHVO.getCsaleinvoiceid()); // 对冲来源发票id + newSaleInvoiceHVO.setApprover(null); // 审批人 + newSaleInvoiceHVO.setTaudittime(null); // 审批日期 + + // 组装VO + saleInvoiceVO.setParentVO(newSaleInvoiceHVO); + saleInvoiceVO.setChildrenVO(newSaleInvoiceBVOs); + return saleInvoiceVO; + } catch (Exception e) { + throw new BusinessException(e.getMessage()); + } + } + + /** + * 构造红冲开票申请VO + * + * @param ivApplicationHeadVO 原开票申请主实体 + * @param ivApplicationBodyVOS 原开票申请子实体 + * @param bject bip参数 + * @param returnApproveSaleInvoiceVOs 新生成的红冲销售发票实体 + * @return + * @throws Exception + */ + public static IVApplicationAggVO makeNewRedRushIVApplicationAggVO(IVApplicationHeadVO ivApplicationHeadVO, IVApplicationBodyVO[] ivApplicationBodyVOS, JSONObject bject, SaleInvoiceVO[] returnApproveSaleInvoiceVOs) throws Exception { + try { + IVApplicationAggVO ivApplicationAggVO = new IVApplicationAggVO(); + IVApplicationHeadVO newivApplicationHeadVO = new IVApplicationHeadVO(); // 新主实体 + + // 取新生成红冲发票的主实体数据 + String csaleinvoiceid = returnApproveSaleInvoiceVOs[0].getParentVO().getCsaleinvoiceid(); + String[] ids = {csaleinvoiceid}; + SaleInvoiceVO[] rpSaleInvoiceVOs = NCLocator.getInstance().lookup(ISaleinvoiceQueryAPI.class) + .queryVOByIDs(ids); + SaleInvoiceHVO rpSaleInvoiceHVO = rpSaleInvoiceVOs[0].getParentVO(); + + // 主实体属性赋值 +// BeanUtil.copyProperties(ivApplicationHeadVO,newivApplicationHeadVO, CopyOptions.create().setIgnoreNullValue(true)); + // 克隆取值原子表开票申请 + newivApplicationHeadVO = (IVApplicationHeadVO) CloneUtil.depthClone(ivApplicationHeadVO); + // 根据参数判断是否为部分红冲 + boolean isPartHCFlag = false; + UFDouble paramNtotalorigmny = new UFDouble(bject.getString("ntotalorigmny")); // 参数价税合计(主表红冲金额) + UFDouble ntotalorigmny = ivApplicationHeadVO.getJshj(); // 原开票申请主表价税合计 + // 红冲金额与开票申请源价税合计比较如果和值大于零,则为部分红冲 + if (ntotalorigmny.add(paramNtotalorigmny).compareTo(UFDouble.ZERO_DBL) > 0) { + isPartHCFlag = true; + } + UFDouble sumXmsl = new UFDouble(); // 合计数量 + UFDouble sumXmje = new UFDouble(); // 合计金额 + UFDouble sumXmjshj = new UFDouble(); // 合计价税合计 + UFDouble sumBchcje = new UFDouble(); // 合计本次红冲金额 + UFDouble sumSe = new UFDouble(); // 合计税额 + // 子实体属性赋值 + int i = 0; + com.alibaba.fastjson.JSONArray paramsSaleInvoiceBVOsJSA = (com.alibaba.fastjson.JSONArray) bject.get("SaleInvoiceBVOs"); // 参数子实体数组 + List paramsSaleInvoiceBVOs = paramsSaleInvoiceBVOsJSA.toJavaList(JSONObject.class); + IVApplicationBodyVO[] newivApplicationBodyVOS = new IVApplicationBodyVO[paramsSaleInvoiceBVOs.size()]; // 新子实体 + for (IVApplicationBodyVO ivApplicationBodyVO : ivApplicationBodyVOS) { + String src_pkdetail = ivApplicationBodyVO.getSrc_pkdetail(); // 来源单据行id + // 筛选参数红冲的子表集合 + List newParamsSaleInvoiceBVOs = paramsSaleInvoiceBVOs.stream().filter(item -> { + String parCsaleinvoicebid = item.getString("csaleinvoicebid") + ""; + return src_pkdetail.equals(parCsaleinvoicebid); + }).toList(); + if (newParamsSaleInvoiceBVOs.size() <= 0) { + continue; + } + JSONObject paramSaleInvoiceBVO = newParamsSaleInvoiceBVOs.get(0); // 参数子表 + IVApplicationBodyVO newivApplicationBodyVO = new IVApplicationBodyVO(); +// BeanUtil.copyProperties(ivApplicationBodyVO,newivApplicationBodyVO, CopyOptions.create().setIgnoreNullValue(true)); + // 克隆取值原子表开票申请 + newivApplicationBodyVO = (IVApplicationBodyVO) CloneUtil.depthClone(ivApplicationBodyVO); + // 赋值之后修改子实体红冲时字段 + newivApplicationBodyVO.setPk_ivappdetail(null); // 开票申请子实体id + newivApplicationBodyVO.setBillno(null); // 开票申请子实体单据号 + newivApplicationBodyVO.setSe(new UFDouble(paramSaleInvoiceBVO.getString("ntax"))); // 税额 + newivApplicationBodyVO.setXmsl(new UFDouble(paramSaleInvoiceBVO.getString("nnum"))); // 数量 + newivApplicationBodyVO.setXmje(new UFDouble(paramSaleInvoiceBVO.getString("norigmny"))); // 金额 + newivApplicationBodyVO.setXmjshj(new UFDouble(paramSaleInvoiceBVO.getString("norigtaxmny"))); // 价税合计 + newivApplicationBodyVO.setBchcje(new UFDouble(paramSaleInvoiceBVO.getString("norigtaxmny")).multiply(new UFDouble(-1))); // 本次红冲金额 = 本次参数红冲金额 + newivApplicationBodyVOS[i++] = newivApplicationBodyVO; + sumSe = sumSe.add(new UFDouble(paramSaleInvoiceBVO.getString("ntax"))); + sumXmsl = sumXmsl.add(new UFDouble(paramSaleInvoiceBVO.getString("nnum"))); + sumXmje = sumXmje.add(new UFDouble(paramSaleInvoiceBVO.getString("norigmny"))); + sumXmjshj = sumXmjshj.add(new UFDouble(paramSaleInvoiceBVO.getString("norigtaxmny"))); + sumBchcje = sumBchcje.add(new UFDouble(paramSaleInvoiceBVO.getString("norigtaxmny")).multiply(new UFDouble(-1))); + } + // 赋值之后修改主实体红冲时字段 + newivApplicationHeadVO.setPk_ivapplication(null); // 开票申请单主实体id + newivApplicationHeadVO.setBillno(null); // 单据号 + newivApplicationHeadVO.setPreparedate(new UFDate()); // 单据日期 + newivApplicationHeadVO.setJshj(sumXmjshj); // 价税合计 + newivApplicationHeadVO.setHjje(sumXmje); // 合计金额 + newivApplicationHeadVO.setHjse(sumSe); // 合计税额 + newivApplicationHeadVO.setBchcje(sumBchcje); // 本次红冲金额 + newivApplicationHeadVO.setHzfp(UFBoolean.TRUE); // 红字发票 + newivApplicationHeadVO.setSrc_billtype(SOBillType.Invoice.getCode()); // 来源单据类型 + newivApplicationHeadVO.setSrc_tradetype(rpSaleInvoiceHVO.getCtrantypeid()); // 来源交易类型 + newivApplicationHeadVO.setTranstypecode(rpSaleInvoiceHVO.getVtrantypecode()); // 来源交易类型编码 + newivApplicationHeadVO.setSrc_pkbusibill(rpSaleInvoiceHVO.getCsaleinvoiceid()); // 来源单据id + newivApplicationHeadVO.setSrc_billno(rpSaleInvoiceHVO.getVbillcode()); // 来源单据编号 + newivApplicationHeadVO.setHcyy("2"); // 红冲原因:2(开票有误) + + // 组装VO + ivApplicationAggVO.setParentVO(newivApplicationHeadVO); + ivApplicationAggVO.setChildrenVO(newivApplicationBodyVOS); + return ivApplicationAggVO; + } catch (Exception e) { + throw new BusinessException(e.getMessage()); + } + } + + public IUAPQueryBS getQueryService() { + return NCLocator.getInstance().lookup(IUAPQueryBS.class); + } + +} \ No newline at end of file