From 54270dd8d4bbcda6f7a777a369b12720cc9a0cf3 Mon Sep 17 00:00:00 2001 From: hefengkai <958118178@qq.com> Date: Tue, 4 Mar 2025 17:53:42 +0800 Subject: [PATCH] first commit --- .../BusiregForSyncSaleorderAndToBIP.java | 0 .../resource/GatheringbillRestResource.java | 0 .../nccloud/openapi/ArriveResourcesTest.java | 20 + .../nccloud/openapi/BaseOpenApiTest.java | 406 ++++++++++++++++++ .../supplierprice/rule/SupPriceQryRule.java | 0 .../nc/vo/pp/report/util/PurpRptUtils.java | 0 .../impl/so/m30/APISaleOrderMaitainImpl.java | 403 +++++++++++++++++ .../api/so/m30/IAPISaleOrderMaitain.java | 0 .../operator/saveCommitAction.java | 0 .../openapi/so/m30/SaleOrderResource.java | 0 10 files changed, 829 insertions(+) create mode 100644 arap/src/private/nc/bs/arap/busireg/BusiregForSyncSaleorderAndToBIP.java create mode 100644 arap/src/public/nc/api/arap/resource/GatheringbillRestResource.java create mode 100644 arap/src/public/nccloud/openapi/ArriveResourcesTest.java create mode 100644 arap/src/public/nccloud/openapi/BaseOpenApiTest.java create mode 100644 purp/src/private/nc/impl/pp/supplierprice/rule/SupPriceQryRule.java create mode 100644 purp/src/public/nc/vo/pp/report/util/PurpRptUtils.java create mode 100644 so/src/private/nccloud/api/impl/so/m30/APISaleOrderMaitainImpl.java create mode 100644 so/src/public/nccloud/api/so/m30/IAPISaleOrderMaitain.java create mode 100644 so/src/public/nccloud/api/so/saleinvoice/operator/saveCommitAction.java create mode 100644 so/src/public/nccloud/openapi/so/m30/SaleOrderResource.java diff --git a/arap/src/private/nc/bs/arap/busireg/BusiregForSyncSaleorderAndToBIP.java b/arap/src/private/nc/bs/arap/busireg/BusiregForSyncSaleorderAndToBIP.java new file mode 100644 index 0000000..e69de29 diff --git a/arap/src/public/nc/api/arap/resource/GatheringbillRestResource.java b/arap/src/public/nc/api/arap/resource/GatheringbillRestResource.java new file mode 100644 index 0000000..e69de29 diff --git a/arap/src/public/nccloud/openapi/ArriveResourcesTest.java b/arap/src/public/nccloud/openapi/ArriveResourcesTest.java new file mode 100644 index 0000000..ea131cf --- /dev/null +++ b/arap/src/public/nccloud/openapi/ArriveResourcesTest.java @@ -0,0 +1,20 @@ +package nccloud.openapi; + + +public class ArriveResourcesTest extends nccloud.openapi.BaseOpenApiTest { + public void save() { + String url = "/nccloud/api/pu/arrive/saveFromOrder"; + + try { + String result = requestOpenApiByJSON(url, "resources/Arrive.json"); + System.out.println(result); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static void main(String[] args) { + ArriveResourcesTest test = new ArriveResourcesTest(); + test.save(); + } +} diff --git a/arap/src/public/nccloud/openapi/BaseOpenApiTest.java b/arap/src/public/nccloud/openapi/BaseOpenApiTest.java new file mode 100644 index 0000000..28cc9ce --- /dev/null +++ b/arap/src/public/nccloud/openapi/BaseOpenApiTest.java @@ -0,0 +1,406 @@ +package nccloud.openapi; + + +import com.alibaba.fastjson.JSONObject; +import nc.ws.opm.pub.utils.security.SecurityUtil; +import nccloud.openapi.BaseOpenApiTest.HttpClientWapper.Response; +import org.apache.commons.httpclient.Header; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.NameValuePair; +import org.apache.commons.httpclient.methods.GetMethod; +import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.httpclient.methods.StringRequestEntity; +import org.apache.commons.httpclient.util.EncodingUtil; +import org.apache.commons.lang3.StringUtils; +import org.springframework.core.io.ClassPathResource; +import sun.misc.BASE64Decoder; +import sun.misc.BASE64Encoder; + +import javax.crypto.Cipher; +import java.io.*; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.security.*; +import java.security.spec.X509EncodedKeySpec; +import java.util.*; +import java.util.Map.Entry; + +/** + * @description: 审批流程接口测试 + * @author:guoxqc@yonyou.com + * @date:2020年10月23日 + */ +public class BaseOpenApiTest { + // public static final String BASE_URL_DEV="http://192.168.82.5:9999"; + public static final String BASE_URL_DEV = "http://127.0.0.1:8088"; +// public static final String BASE_URL_DEV = "http://192.168.82.104:7788"; +// public static final String BASE_URL_DEV="http://192.168.82.1:9081"; +// public static final String BASE_URL_DEV="http://172.23.17.146:8001"; + /** + * APP ID + */ + public static final String CLIENT_ID; + /** + * APP Secret + */ + public static final String CLIENT_SECRET; + /** + * 公钥 + */ + public static final String PUBLIC_KEY; + /** + * 账套编码 + */ + public static final String BIZ_CENTER; + /** + * 用户编码 + */ + public static final String USER_CODE; + + static { + ResourceBundle config = ResourceBundle.getBundle("nccloud.openapi.config"); + CLIENT_ID = config.getString("client_id"); + CLIENT_SECRET = config.getString("client_secret"); + PUBLIC_KEY = config.getString("pub_key"); + BIZ_CENTER = config.getString("biz_center"); + USER_CODE = config.getString("user_code"); + } + + public HttpClientWapper client = new HttpClientWapper(); + + /** + * @param url + * @param param + * @return + * @throws Exception + */ + public String requestOpenApi(String url, Map param) throws Exception { + return requestOpenApi(url, new JSONObject(param)); + } + + /** + * @param url + * @param param + * @return + * @throws Exception + */ + public String requestOpenApi(String url, JSONObject param) throws Exception { + return requestOpenApi(url, param.toJSONString()); + } + + /** + * @param url + * @param fileName + * @return + * @throws Exception + */ + public String requestOpenApiByJSON(String url, String fileName) throws Exception { + ClassPathResource classPathResorce = new ClassPathResource(fileName, this.getClass()); + StringBuffer data = new StringBuffer(); + try { + InputStream in = classPathResorce.getInputStream(); + BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8")); + String line = reader.readLine(); + while (StringUtils.isNotEmpty(line)) { + data.append(line); + line = reader.readLine(); + } + } catch (IOException e1) { + e1.printStackTrace(); + } + return requestOpenApi(url, data.toString()); + } + + public String requestOpenApi(String url, String param) throws Exception { + String accessToken = this.getAccessTokenByClient(); + System.out.println(param.replace(" ", "")); + String sign = digest(CLIENT_ID + PUBLIC_KEY); + List
headers = new ArrayList
(); + headers.add(new Header("Content-Type", "application/json;charset=UTF-8")); + headers.add(new Header("signature", sign)); + headers.add(new Header("ucg_flag", "y")); + headers.add(new Header("access_token", accessToken)); + headers.add(new Header("client_id", CLIENT_ID)); + Response response; + try { + response = client.post(BASE_URL_DEV + url, headers.toArray(new Header[headers.size()]), null, param); +// System.out.println(response.getData()); + return response.getData(); + } catch (Exception e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + return e.getMessage(); + } + } + + /** + * @param seed 种子,用于生成公钥 + * @param src 明文 + * @return + * @throws Exception + * @description RSA加密 + */ + public String pubEncrypt(String seed, String src) throws Exception { + String target = null; + ByteArrayOutputStream out = null; + try { + Key key = genPublicKey(PUBLIC_KEY); + Cipher cipher = Cipher.getInstance("RSA"); + cipher.init(1, key); + byte[] data = src.getBytes(); + int inputLen = data.length; + out = new ByteArrayOutputStream(); + int offSet = 0; + int i = 0; + while (inputLen - offSet > 0) { + byte[] cache; + ; + if (inputLen - offSet > 117) { + cache = cipher.doFinal(data, offSet, 117); + } else { + cache = cipher.doFinal(data, offSet, inputLen - offSet); + } + out.write(cache, 0, cache.length); + i++; + offSet = i * 117; + } + target = new BASE64Encoder().encodeBuffer(out.toByteArray()); + } catch (Exception e) { + throw new Exception("加密失败" + e.getMessage()); + } finally { + if (out != null) { + out.close(); + } + } + return target; + } + + /** + * @param str + * @return + * @description 信息摘要 + */ + public static String digest(String str) { + String encodestr = ""; + try { + MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); + messageDigest.update(str.getBytes(StandardCharsets.UTF_8)); + encodestr = byte2Hex(messageDigest.digest()); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException(e); + } + return encodestr; + } + + private static String byte2Hex(byte[] bytes) { + StringBuffer stringBuffer = new StringBuffer(); + String temp = null; + for (int i = 0; i < bytes.length; i++) { + temp = Integer.toHexString(bytes[i] & 0xFF); + if (temp.length() == 1) { + stringBuffer.append("0"); + } + stringBuffer.append(temp); + } + return stringBuffer.toString(); + } + + /** + * @param PUBLIC_KEY + * @return + * @throws Exception + * @description 根据种子生成密钥对 + */ + public static Key genPublicKey(String seed) throws Exception { + Key key = null; + try { + byte[] keyBytes = new BASE64Decoder().decodeBuffer(seed); + KeyFactory keyFactory = KeyFactory.getInstance("RSA"); + X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(keyBytes); + key = keyFactory.generatePublic(x509KeySpec); + } catch (Exception e) { + throw new Exception("无效的密钥 " + e.getMessage()); + } + return key; + } + + /** + * Http请求包装类 + * + * @author guoxiangqiao + * @date 2019年12月11日 + */ + public class HttpClientWapper { + public static final int HTTP_STATUS_SUCCESS = 200; + + /** + * post请求 + * + * @param url + * @param headers + * @param requestBody + * @return + * @throws Exception + */ + public Response post(String url, Header[] headers, NameValuePair[] requestBody, String requestEntityStr) throws Exception { + HttpClient client = new HttpClient(); + PostMethod postMethod = new PostMethod(url); + if (headers != null) { + for (Header header : headers) { + postMethod.setRequestHeader(header); + } + } + if (requestBody != null) { + postMethod.setRequestBody(requestBody); + } + if (StringUtils.isNotEmpty(requestEntityStr)) { + StringRequestEntity requestEntity = new StringRequestEntity(requestEntityStr, null, "utf-8"); + postMethod.setRequestEntity(requestEntity); + } + int httpStatus = client.executeMethod(postMethod); + String result = this.getResponseBodyAsString(postMethod); + return new Response(httpStatus, result); + } + + public String getResponseBodyAsString(PostMethod postMethod) throws IOException { + byte[] rawdata = null; + rawdata = postMethod.getResponseBody(); + return rawdata != null ? EncodingUtil.getString(rawdata, "utf-8") : null; + } + + /** + * @param params + * @return + * @description Map转URL参数 + * @author guoxqc@yonyou.com + * @date 2020年10月22日 + */ + public String getURLParam(Map params) { + StringBuffer paramStr = new StringBuffer(); + if (!params.isEmpty()) { + for (Entry kv : params.entrySet()) { + paramStr.append(kv.getKey()); + paramStr.append("="); + paramStr.append(kv.getValue()); + paramStr.append("&"); + } + paramStr.deleteCharAt(paramStr.length() - 1); + } + return paramStr.toString(); + } + + /** + * get请求 + * + * @param url + * @param headers + * @param params + * @return + * @throws Exception + */ + public Response get(String url, Header[] headers, NameValuePair[] params) throws Exception { + HttpClient client = new HttpClient(); + GetMethod getMethod = new GetMethod(url); + if (params != null) { + getMethod.setQueryString(params); + } + if (headers != null) { + for (Header header : headers) { + getMethod.setRequestHeader(header); + } + } + int httpStatus = client.executeMethod(getMethod); + String result = getMethod.getResponseBodyAsString(); + return new Response(httpStatus, result); + } + + /** + * 获取url查询参数 + * + * @param params + * @return + */ + public String getQueryString(NameValuePair[] params) { + GetMethod getMethod = new GetMethod(); + getMethod.setQueryString(params); + return getMethod.getQueryString(); + } + + class Response { + private int httpStatus; + private String data; + + public int getHttpStatus() { + return httpStatus; + } + + public void setHttpStatus(int httpStatus) { + this.httpStatus = httpStatus; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + + public Response(int httpStatus, String data) { + super(); + this.httpStatus = httpStatus; + this.data = data; + } + + public Response() { + super(); + } + } + } + + public static String getSHA256(String str, String key) throws Exception { + byte[] salt = new byte[16]; + SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); + random.setSeed(key.getBytes()); + random.nextBytes(salt); + String salt_value = new BASE64Encoder().encodeBuffer(salt); + return digest(str + salt_value.replaceAll("\r|\n", "")); + } + + /** + * @return + * @throws Exception + * @description 获取AccessToken + */ + @SuppressWarnings("static-access") + public String getAccessTokenByClient() throws Exception { + String url = BASE_URL_DEV + "/nccloud/opm/accesstoken"; + List
headers = new ArrayList
(); + headers.add(new Header("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8")); + // 获取信息摘要 + String signature = getSHA256(CLIENT_ID + CLIENT_SECRET + PUBLIC_KEY, PUBLIC_KEY); + // 使用PUBLIC_KEY生成公钥,对CLIENT_SECRET加密 + SecurityUtil securityUtil = new SecurityUtil(); + String CLIENT_SECRETEn = URLEncoder.encode(securityUtil.pubEncrypt(PUBLIC_KEY, CLIENT_SECRET), "utf-8"); + Map params = new HashMap(); + params.put("client_id", CLIENT_ID); + params.put("userCode", USER_CODE); + params.put("grant_type", "client_credentials"); + params.put("biz_center", BIZ_CENTER); + params.put("signature", signature); + params.put("client_secret", CLIENT_SECRETEn); + try { + Response response = client.post(url, headers.toArray(new Header[headers.size()]), null, client.getURLParam(params)); + System.out.println(response.getData()); + JSONObject result = JSONObject.parseObject(response.getData()); + boolean success = result.getBoolean("success"); + if (success) { + return result.getJSONObject("data").getString("access_token"); + } + } catch (Exception e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + } + return null; + } +} \ No newline at end of file diff --git a/purp/src/private/nc/impl/pp/supplierprice/rule/SupPriceQryRule.java b/purp/src/private/nc/impl/pp/supplierprice/rule/SupPriceQryRule.java new file mode 100644 index 0000000..e69de29 diff --git a/purp/src/public/nc/vo/pp/report/util/PurpRptUtils.java b/purp/src/public/nc/vo/pp/report/util/PurpRptUtils.java new file mode 100644 index 0000000..e69de29 diff --git a/so/src/private/nccloud/api/impl/so/m30/APISaleOrderMaitainImpl.java b/so/src/private/nccloud/api/impl/so/m30/APISaleOrderMaitainImpl.java new file mode 100644 index 0000000..09c1b65 --- /dev/null +++ b/so/src/private/nccloud/api/impl/so/m30/APISaleOrderMaitainImpl.java @@ -0,0 +1,403 @@ +package nccloud.api.impl.so.m30; + +import nc.bd.itf.tools.BFPubTools; +import nc.bs.dao.BaseDAO; +import nc.bs.framework.common.NCLocator; +import nc.itf.fi.pub.Currency; +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.pubitf.so.m30.api.ISaleOrderQueryAPI; +import nc.vo.ml.NCLangRes4VoTransl; +import nc.vo.pub.BusinessException; +import nc.vo.pub.VOStatus; +import nc.vo.pub.lang.UFBoolean; +import nc.vo.pub.lang.UFDate; +import nc.vo.pub.lang.UFDouble; +import nc.vo.pubapp.pattern.exception.ExceptionUtils; +import nc.vo.pubapp.pflow.PfUserObject; +import nc.vo.scmpub.check.billvalidate.BillVOsCheckRule; +import nc.vo.scmpub.res.billtype.SOBillType; +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.m30.revise.entity.SaleOrderHistoryBVO; +import nc.vo.so.m30.revise.entity.SaleOrderHistoryHVO; +import nc.vo.so.m30.revise.entity.SaleOrderHistoryVO; +import nc.vo.so.pub.SOConstant; +import nc.vo.so.pub.keyvalue.IKeyValue; +import nc.vo.so.pub.keyvalue.VOKeyValue; +import nc.vo.so.pub.util.AggVOUtil; +import nc.vo.so.pub.util.SOCurrencyUtil; +import nccloud.api.impl.so.m30.check.SaleOrderValidator; +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.dto.scmpub.pflow.SCMCloudPFlowContext; +import nccloud.pubitf.scmpub.commit.service.IBatchRunScriptService; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * @Description: 销售订单维护实现类 + * @author: yanghff + * @date: 2019-10-23 下午4:57:49 + * @Copyright: + */ +public class APISaleOrderMaitainImpl2 implements IAPISaleOrderMaitain { + + @Override + public SaleOrderVO[] save(SaleOrderVO[] vos) throws BusinessException { + + SaleOrderVO[] fillvos = vos; + // 检查非空项 + for (SaleOrderVO vo : vos) { + SaleOrderHVO hvo = vo.getParentVO(); + String corigcurrencyid = hvo.getCorigcurrencyid(); + 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); + } + + } + +// bvo.setNexchangerate(rateReturnObject.getRate()); +// bvo.setCratetype(rateReturnObject.getPk_ratetype()); +// bvo.setFratecategory( rateReturnObject.getRate_category()); +// bvo.setDratedate( rateReturnObject.getDate()); + + } + + + 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[] 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 { + + + 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 + + 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(); + + 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()); + + childrenVO.setNorigmny(Currency.getFormaUfValue(ybpk, norigmny)); + //税额 + childrenVO.setNqtorigprice(nqtorigprice.setScale(4, 4)); + + + //无税本币金额单价 + UFDouble taxspric = nqtorigtaxprice.div(UFDouble.ONE_DBL.add(ntaxrate.div(100))); + + + 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 --主含税单价 + + 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 --计税金额 + + // ,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.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); +// ordervo.getParentVO().setNtotalorigmny(sumnny); + ordervo.getParentVO().setNtotalorigmny(sumnny.setScale(2, 4)); + } + + + @Override + public SaleOrderVO[] update(SaleOrderVO[] vos) throws BusinessException { + + // 获取参数vo的id + Map> ids = this.getIds(vos); + if (ids.keySet() == null || ids.values() == null + || ids.values().size() == 0) { + ExceptionUtils.wrappBusinessException("请传入订单主键和订单行主键"); + } + String[] hids = ids.keySet().toArray(new String[ids.keySet().size()]); + // 查询销售订单 + ISaleOrderMaintain service = + NCLocator.getInstance().lookup(ISaleOrderMaintain.class); + SaleOrderVO[] originVos = service.querySaleorder(hids); + SetUpdateData setData = new SetUpdateData(); + setData.setData(vos, originVos); + setOtherId(vos); + // 有值不覆盖 + SaleOrderVO[] combinBillVOs = + (SaleOrderVO[]) AggVOUtil.combinBillVO(vos, originVos); + // 设置单据状态 + for (SaleOrderVO vo : vos) { + vo.getParentVO().setStatus(VOStatus.UPDATED); + for (SaleOrderBVO bvo : vo.getChildrenVO()) { + bvo.setStatus(VOStatus.UPDATED); + } + } + // 保存 + ISaleOrderScriptMaintain maintainsrv = + NCLocator.getInstance().lookup(ISaleOrderScriptMaintain.class); + SaleOrderVO[] retvos = + maintainsrv.saleOrderUpdate(combinBillVOs, null, originVos); + return retvos; + } + + /** + * @Description: 获取参数vo的id + * @date: 2019-11-1 上午10:31:42 + * @version NCC1909 + */ + 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 + String cdeptvid = vo.getParentVO().getCdeptvid(); + String cemployeeid = vo.getParentVO().getCdeptvid(); + String cinvoicecustid = vo.getParentVO().getCdeptvid(); + try { + String sql = ""; + // 部门 + if (cdeptvid != null && !cdeptvid.isEmpty()) { + sql = " select pk_dept from org_dept where code = '[code]' "; + sql = sql.replace("[code]", cdeptvid); + Object deptObj = new BaseDAO().executeQuery(sql, new ColumnProcessor()); + NCCForUAPLogger.debug("APISaleOrderMaitainImpl-setOtherId-deptObj:" + deptObj); + if (deptObj != null) { + String id = BFPubTools.getString_TrimAsNull(deptObj); + if (!id.isEmpty()) { + vo.getParentVO().setCdeptvid(id); + } + } + } + // 业务员 + 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()); + NCCForUAPLogger.debug("APISaleOrderMaitainImpl-setOtherId-staffObj:" + staffObj); + if (staffObj != null) { + String id = BFPubTools.getString_TrimAsNull(staffObj); + if (!id.isEmpty()) { + vo.getParentVO().setCdeptvid(id); + } + } + } + // 开票客户 + if (cinvoicecustid != null && !cinvoicecustid.isEmpty()) { + sql = " select pk_customer from bd_customer where code = '[code]' "; + sql = sql.replace("[code]", cinvoicecustid); + Object invCustObj = new BaseDAO().executeQuery(sql, new ColumnProcessor()); + NCCForUAPLogger.debug("APISaleOrderMaitainImpl-setOtherId-invCustObj:" + invCustObj); + if (invCustObj != null) { + String id = BFPubTools.getString_TrimAsNull(invCustObj); + if (!id.isEmpty()) { + vo.getParentVO().setCdeptvid(id); + } + } + } + } catch (Exception e) { + NCCForUAPLogger.debug("APISaleOrderMaitainImpl-setOtherId-exp:" + e.getMessage()); + throw new RuntimeException(e); + } + } + } + + + @Override + public SaleOrderVO[] modify(SaleOrderHistoryVO[] vos) throws BusinessException { + for (SaleOrderHistoryVO vo : vos) { + SaleOrderHistoryHVO hvo = vo.getParentVO(); + UFDate dbilldate = hvo.getDbilldate(); + SaleOrderHistoryBVO[] 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 (SaleOrderHistoryBVO bvo : bvos) { + bvo.setCcurrencyid(BFPubTools.getString_TrimAsNull(o1)); + if (!BFPubTools.getString_TrimAsNull(o).equals(ccurrencyorgid)) { + bvo.setNexchangerate(exchangerate); + } else { + bvo.setNexchangerate(UFDouble.ONE_DBL); + } + + } + } + for (SaleOrderVO ordervo : vos) { + calculatorPrice(ordervo); + } + Map eParam = new HashMap(); + eParam.put("nolockandconsist", UFBoolean.TRUE); + + SCMCloudPFlowContext context = new SCMCloudPFlowContext(); + context.setBillType(SOBillType.Order30R.getCode()); + PfUserObject userObject = new PfUserObject(); + userObject.setUserObject(null); + context.seteParam(eParam); + context.setUserObj(new PfUserObject[]{userObject}); + context.setBillVos(vos); + context.setActionName("REVISEWRITE"); + IBatchRunScriptService service2 = (IBatchRunScriptService) NCLocator.getInstance().lookup(IBatchRunScriptService.class); + SaleOrderHistoryVO[] objects = (SaleOrderHistoryVO[]) service2.run(context, SaleOrderHistoryVO.class); + + + return (SaleOrderVO[]) NCLocator.getInstance().lookup(IPFBusiAction.class).processAction("APPROVE", "30R", null, objects[0], null, null); + } + + private void cheageHVo(SaleOrderHistoryVO billvo, SaleOrderVO saleOrderVO) { + SaleOrderHistoryHVO hvo = billvo.getParentVO(); + SaleOrderHVO oldvo = saleOrderVO.getParentVO(); + hvo.setCinvoicecustid(oldvo.getCinvoicecustid()); + hvo.setCemployeeid(oldvo.getCemployeeid()); + } + +} diff --git a/so/src/public/nccloud/api/so/m30/IAPISaleOrderMaitain.java b/so/src/public/nccloud/api/so/m30/IAPISaleOrderMaitain.java new file mode 100644 index 0000000..e69de29 diff --git a/so/src/public/nccloud/api/so/saleinvoice/operator/saveCommitAction.java b/so/src/public/nccloud/api/so/saleinvoice/operator/saveCommitAction.java new file mode 100644 index 0000000..e69de29 diff --git a/so/src/public/nccloud/openapi/so/m30/SaleOrderResource.java b/so/src/public/nccloud/openapi/so/m30/SaleOrderResource.java new file mode 100644 index 0000000..e69de29