From 5a11c774179d6bb0ddf4a643460fb4a2ae73fbfe Mon Sep 17 00:00:00 2001 From: mzr <1562242162@qq.com> Date: Tue, 4 Mar 2025 18:06:59 +0800 Subject: [PATCH] =?UTF-8?q?=E9=94=80=E5=94=AE=E8=AE=A2=E5=8D=95=E7=94=9F?= =?UTF-8?q?=E5=8D=95=E5=8F=8A=E9=94=80=E5=94=AE=E8=AE=A2=E5=8D=95=E4=BF=AE?= =?UTF-8?q?=E8=AE=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/so/m30/APISaleOrderMaitainImpl.java | 412 ++++++++++-- .../api/so/m30/IAPISaleOrderMaitain.java | 35 + .../openapi/so/m30/SaleOrderResource.java | 629 ++++++++++++++++++ 3 files changed, 1035 insertions(+), 41 deletions(-) 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 09c1b65..0fbe25c 100644 --- a/so/src/private/nccloud/api/impl/so/m30/APISaleOrderMaitainImpl.java +++ b/so/src/private/nccloud/api/impl/so/m30/APISaleOrderMaitainImpl.java @@ -1,5 +1,6 @@ package nccloud.api.impl.so.m30; +import com.alibaba.fastjson.JSON; import nc.bd.itf.tools.BFPubTools; import nc.bs.dao.BaseDAO; import nc.bs.framework.common.NCLocator; @@ -9,6 +10,7 @@ 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.pubitf.so.m30.api.ISaleOrderQueryAPI; import nc.vo.ml.NCLangRes4VoTransl; import nc.vo.pub.BusinessException; @@ -16,9 +18,11 @@ 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.AppContext; import nc.vo.pubapp.pattern.exception.ExceptionUtils; import nc.vo.pubapp.pflow.PfUserObject; import nc.vo.scmpub.check.billvalidate.BillVOsCheckRule; +import nc.vo.scmpub.fill.pricemny.INumPriceMnyCalculator; import nc.vo.scmpub.res.billtype.SOBillType; import nc.vo.scmpub.util.StringUtil; import nc.vo.so.m30.entity.SaleOrderBVO; @@ -33,17 +37,14 @@ 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.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.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; +import java.util.*; /** * @Description: 销售订单维护实现类 @@ -51,7 +52,7 @@ import java.util.Set; * @date: 2019-10-23 下午4:57:49 * @Copyright: */ -public class APISaleOrderMaitainImpl2 implements IAPISaleOrderMaitain { +public class APISaleOrderMaitainImpl implements IAPISaleOrderMaitain { @Override public SaleOrderVO[] save(SaleOrderVO[] vos) throws BusinessException { @@ -81,9 +82,9 @@ public class APISaleOrderMaitainImpl2 implements IAPISaleOrderMaitain { for (SaleOrderBVO bvo : bvos) { bvo.setCcurrencyid(BFPubTools.getString_TrimAsNull(o1)); if (!BFPubTools.getString_TrimAsNull(o).equals(ccurrencyorgid)) { - bvo.setNexchangerate(exchangerate); + // bvo.setNexchangerate(exchangerate); } else { - bvo.setNexchangerate(UFDouble.ONE_DBL); + // bvo.setNexchangerate(UFDouble.ONE_DBL); } } @@ -141,28 +142,28 @@ public class APISaleOrderMaitainImpl2 implements IAPISaleOrderMaitain { 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))); @@ -171,7 +172,7 @@ public class APISaleOrderMaitainImpl2 implements IAPISaleOrderMaitain { nqtorigprice = nqtorigprice.setScale(4, 4); - //nqtorigtaxnetprc--含税净价 + // nqtorigtaxnetprc--含税净价 childrenVO.setNqtorigtaxnetprc(nqtorigtaxprice); //,nqtorignetprice --无税净价 childrenVO.setNqtorignetprice(nqtorigprice); @@ -189,7 +190,7 @@ public class APISaleOrderMaitainImpl2 implements IAPISaleOrderMaitain { wsje = Currency.getFormaUfValue(zbbz, wsje); - //本币无税金额 + // 本币无税金额 childrenVO.setNorigtaxprice(nqtorigtaxprice.div(dVqtunitrate).setScale(4, 4)); //,norigprice --主无税单价 childrenVO.setNorigprice(nqtorigprice.div(dVqtunitrate).setScale(4, 4)); @@ -234,8 +235,21 @@ public class APISaleOrderMaitainImpl2 implements IAPISaleOrderMaitain { @Override - public SaleOrderVO[] update(SaleOrderVO[] vos) throws BusinessException { - + public SaleOrderVO[] update(SaleOrderVO[] vos, List> paramList) throws BusinessException { + for (SaleOrderVO vo : vos) { + 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]", vo.getParentVO().getCsaleorderid()); + Integer num = (Integer) new BaseDAO().executeQuery(countSql, new ColumnProcessor()); + if (num > 0) { + // fopposeflag 对冲标记 0=正常 1=已被对冲 2=对冲生成 + ExceptionUtils.wrappBusinessException("下游存在未红冲完成的销售发票"); + return null; + } + } + // 编码转id + setOtherId(vos); // 获取参数vo的id Map> ids = this.getIds(vos); if (ids.keySet() == null || ids.values() == null @@ -247,24 +261,57 @@ public class APISaleOrderMaitainImpl2 implements IAPISaleOrderMaitain { ISaleOrderMaintain service = NCLocator.getInstance().lookup(ISaleOrderMaintain.class); SaleOrderVO[] originVos = service.querySaleorder(hids); - SetUpdateData setData = new SetUpdateData(); - setData.setData(vos, originVos); - setOtherId(vos); + // SetUpdateData setData = new SetUpdateData(); + // setData.setData(vos, originVos); // 有值不覆盖 - SaleOrderVO[] combinBillVOs = - (SaleOrderVO[]) AggVOUtil.combinBillVO(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) { - vo.getParentVO().setStatus(VOStatus.UPDATED); + vosMap.put(vo.getParentVO().getCsaleorderid(), vo); + } + + // 遍历 combinBillVOs 并更新字段 + for (SaleOrderVO vo : combinBillVOs) { + SaleOrderHVO hvo = vo.getParentVO(); + String primaryKey = hvo.getCsaleorderid(); + SaleOrderVO bipVo = vosMap.get(primaryKey); + // 创建一个Set来存储vos中多的csaleorderbid + Set delBids = findOtherBids(bipVo.getChildrenVO(), vo.getChildrenVO()); + // 设置单据状态 + hvo.setStatus(VOStatus.UPDATED); + // 比较combinBillVOs中的BVO和vos中的BVO for (SaleOrderBVO bvo : vo.getChildrenVO()) { bvo.setStatus(VOStatus.UPDATED); + // 设置删除的物料行的状态 + if (!delBids.isEmpty() && delBids.contains(bvo.getCsaleorderbid())) { + bvo.setStatus(VOStatus.DELETED); + NCCForUAPLogger.debug("findDeletedBids:" + VOStatus.DELETED + ",csaleorderbid = " + bvo.getCsaleorderbid()); + } + } + // 更新 combinBillVO 中的字段为 vos 中的值 + updateFields(vo, bipVo); + // 设置新增的物料行 + if (paramList != null && !paramList.isEmpty()) { + // addBvo(combinBillVOs, paramList); } } + // 联动计算 + INumPriceMnyCalculator cal = new SaleOrderNPriceMnyCal(combinBillVOs); + cal.calculate(); // 保存 ISaleOrderScriptMaintain maintainsrv = NCLocator.getInstance().lookup(ISaleOrderScriptMaintain.class); SaleOrderVO[] retvos = maintainsrv.saleOrderUpdate(combinBillVOs, null, originVos); + ; return retvos; } @@ -289,21 +336,25 @@ public class APISaleOrderMaitainImpl2 implements IAPISaleOrderMaitain { 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(); + SaleOrderHVO orderHVO = vo.getParentVO(); + String csaleorderid = orderHVO.getCsaleorderid(); + String cdeptvid = orderHVO.getCdeptvid(); + String cemployeeid = orderHVO.getCemployeeid(); + String cinvoicecustid = orderHVO.getCinvoicecustid(); try { String sql = ""; // 部门 if (cdeptvid != null && !cdeptvid.isEmpty()) { - sql = " select pk_dept from org_dept where code = '[code]' "; + sql = " select pk_vid,pk_dept from org_dept_v 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); + 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", "") + ""); } } } @@ -311,12 +362,12 @@ public class APISaleOrderMaitainImpl2 implements IAPISaleOrderMaitain { 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()); + 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()) { - vo.getParentVO().setCdeptvid(id); + orderHVO.setCemployeeid(id); } } } @@ -324,12 +375,12 @@ public class APISaleOrderMaitainImpl2 implements IAPISaleOrderMaitain { 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()); + Object invCustObj = new BaseDAO().executeQuery(sql, new ColumnProcessor("pk_customer")); NCCForUAPLogger.debug("APISaleOrderMaitainImpl-setOtherId-invCustObj:" + invCustObj); if (invCustObj != null) { String id = BFPubTools.getString_TrimAsNull(invCustObj); if (!id.isEmpty()) { - vo.getParentVO().setCdeptvid(id); + orderHVO.setCinvoicecustid(id); } } } @@ -340,6 +391,65 @@ public class APISaleOrderMaitainImpl2 implements IAPISaleOrderMaitain { } } + 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); + } + + // 更新 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.setNexchangerate(sourceBVO.getNexchangerate()); + // 物料编码 + String cmaterialvid = sourceBVO.getCmaterialvid(); + // 物料关联字段赋值 + if (cmaterialvid != null && !cmaterialvid.isEmpty()) { + setMaterl(targetBVO); + } + } + + } + } + } + @Override public SaleOrderVO[] modify(SaleOrderHistoryVO[] vos) throws BusinessException { @@ -365,9 +475,9 @@ public class APISaleOrderMaitainImpl2 implements IAPISaleOrderMaitain { for (SaleOrderHistoryBVO bvo : bvos) { bvo.setCcurrencyid(BFPubTools.getString_TrimAsNull(o1)); if (!BFPubTools.getString_TrimAsNull(o).equals(ccurrencyorgid)) { - bvo.setNexchangerate(exchangerate); + // bvo.setNexchangerate(exchangerate); } else { - bvo.setNexchangerate(UFDouble.ONE_DBL); + // bvo.setNexchangerate(UFDouble.ONE_DBL); } } @@ -400,4 +510,224 @@ public class APISaleOrderMaitainImpl2 implements IAPISaleOrderMaitain { hvo.setCemployeeid(oldvo.getCemployeeid()); } + 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); + } + } + + // 新增函数:比较两个vos,返回新增的bids和删除的bids + private Set findOtherBids(SaleOrderBVO[] bipBVOs, SaleOrderBVO[] nccBVOs) { + Set bipBids = new HashSet<>(); + for (SaleOrderBVO bvo : bipBVOs) { + bipBids.add(bvo.getCsaleorderbid()); + } + + Set deletedBids = new HashSet<>(); + for (SaleOrderBVO bvo : nccBVOs) { + if (!bipBids.contains(bvo.getCsaleorderbid())) { + deletedBids.add(bvo.getCsaleorderbid()); + } + } + return deletedBids; + } + + /** + * 修订销售订单的时候新增销售订单物料行的数据 + */ + private void addBvo(SaleOrderVO[] combinBillVOs, List> paramList) { + try { + for (SaleOrderVO vo : combinBillVOs) { + SaleOrderHVO hvo = vo.getParentVO(); + SaleOrderBVO[] bvos = vo.getChildrenVO(); + List bvoList = new ArrayList<>(Arrays.asList(bvos)); + String csaleorderid = hvo.getCsaleorderid(); + String ybpk = hvo.getCorigcurrencyid(); + Map objectMap = Collections.emptyMap(); + for (Map map : paramList) { + objectMap = (Map) map.get(csaleorderid); + } + if (objectMap != null && !objectMap.isEmpty()) { + 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); + newBvo.setAttributeValue("cprojectid", bodydata.get("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 = BFPubTools.getUFDouble_NullAsZero(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(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 = 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 --主本币含税净价 + //,nnetprice --主本币无税净价 + newBvo.setNtaxnetprice(nqtorigtaxprice.div(dVqtunitrate).multiply(nexchangerate).setScale(4, 4)); + UFDouble Nnetprice = nqtorigtaxprice.div(UFDouble.ONE_DBL.add(ntaxrate.div(100))).div(dVqtunitrate); + newBvo.setNnetprice(Nnetprice.multiply(nexchangerate).setScale(4, 4)); + // 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") + ""); + bvoList.add(newBvo); + } + } + } + SaleOrderBVO[] array = bvoList.toArray(new SaleOrderBVO[0]); + vo.setChildrenVO(array); + } + // 填充默认值 + new SaleOrderSaveFillValue().setDefValue(combinBillVOs); + for (SaleOrderVO combinBillVO : combinBillVOs) { + 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); + } + } + } diff --git a/so/src/public/nccloud/api/so/m30/IAPISaleOrderMaitain.java b/so/src/public/nccloud/api/so/m30/IAPISaleOrderMaitain.java index e69de29..9aacd84 100644 --- a/so/src/public/nccloud/api/so/m30/IAPISaleOrderMaitain.java +++ b/so/src/public/nccloud/api/so/m30/IAPISaleOrderMaitain.java @@ -0,0 +1,35 @@ +package nccloud.api.so.m30; + +import nc.vo.pub.BusinessException; +import nc.vo.so.m30.entity.SaleOrderVO; +import nc.vo.so.m30.revise.entity.SaleOrderHistoryVO; + +import java.util.List; +import java.util.Map; + +/** + * @version NCC1909 + * @Description: 销售订单维护接口 + * @author: yanghff + * @date: 2019-11-1 上午9:59:48 + */ +public interface IAPISaleOrderMaitain { + + /** + * @Description: 销售订单新增保存 + * @date: 2019-11-1 上午10:00:22 + * @version NCC1909 + */ + SaleOrderVO[] save(SaleOrderVO[] vos) throws BusinessException; + + /** + * @Description: 销售订单修改保存 + * @date: 2019-11-1 上午10:17:46 + * @version NCC1909 + */ + SaleOrderVO[] update(SaleOrderVO[] vos, List> paramList) throws BusinessException; + + // 变更销售销售订单 + SaleOrderVO[] modify(SaleOrderHistoryVO[] vos) throws BusinessException; + +} diff --git a/so/src/public/nccloud/openapi/so/m30/SaleOrderResource.java b/so/src/public/nccloud/openapi/so/m30/SaleOrderResource.java index e69de29..d1adc92 100644 --- a/so/src/public/nccloud/openapi/so/m30/SaleOrderResource.java +++ b/so/src/public/nccloud/openapi/so/m30/SaleOrderResource.java @@ -0,0 +1,629 @@ +/** + * + */ +package nccloud.openapi.so.m30; + +import nc.bd.itf.tools.BFPubTools; +import nc.bs.dao.BaseDAO; +import nc.bs.framework.common.InvocationInfoProxy; +import nc.bs.framework.common.NCLocator; +import nc.itf.bd.defdoc.IDefdocService; +import nc.itf.pim.project.prv.IProject; +import nc.itf.so.m30.revise.ISaleOrderReviseMaintainApp; +import nc.jdbc.framework.processor.ColumnListProcessor; +import nc.jdbc.framework.processor.ColumnProcessor; +import nc.jdbc.framework.processor.MapProcessor; +import nc.ui.querytemplate.querytree.IQueryScheme; +import nc.vo.bd.defdoc.DefdocVO; +import nc.vo.ml.NCLangRes4VoTransl; +import nc.vo.pim.project.ProjectHeadVO; +import nc.vo.pub.BusinessException; +import nc.vo.pub.VOStatus; +import nc.vo.pub.lang.UFDateTime; +import nc.vo.pubapp.AppContext; +import nc.vo.scmpub.util.CollectionUtils; +import nc.vo.scmpub.util.VOEntityUtil; +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 nccloud.api.rest.utils.NCCRestUtils; +import nccloud.api.so.m30.IAPISaleOrderMaitain; +import nccloud.api.so.m30.IAPISaleOrderQuery; +import nccloud.framework.core.exception.ExceptionUtils; +import nccloud.openapi.scmpub.pub.NCCPubRestResource; +import nccloud.openapi.scmpub.pub.TransferMapToVOTool; +import nccloud.openapi.scmpub.util.BillFieldsCodeToPkUtil; +import nccloud.openapi.scmpub.util.CallReturnBuildUtil; +import nccloud.openapi.so.m30.mapping.SaleOrderFieldMapping; +import nccloud.openapi.so.utils.QuerySchemeUtils; +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.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @version NCC1909 + * @Description: 销售订单资源访问类 + * @author: yanghff + * @date: 2019-11-1 上午10:02:32 + */ +@Path("so/saleorder") +public class SaleOrderResource extends NCCPubRestResource { + private Integer pageNo = defaultPageIndex; + private Integer pageSize = defaultPageNum; + private static String BODYTABLE = "so_saleorder_b"; + private static String HEADTABLE = "so_saleorder"; + public BaseDAO dao; + + public BaseDAO getDao() { + if (dao == null) { + dao = new BaseDAO(); + } + return dao; + } + + /** + * @Description: 销售订单新增保存 + * @date: 2019-11-1 上午10:03:21 + * @version NCC1909 + */ + @SuppressWarnings("unchecked") + @POST + @Path("save") + @Consumes("application/json") + @Produces("application/json") + public JSONString save(List> paramList) { + InvocationInfoProxy.getInstance().setGroupId("0001A110000000000677"); + try { + for (Map map : paramList) { + if (!map.containsKey(HEADTABLE) || !map.containsKey(BODYTABLE)) { + return NCCRestUtils.toJSONString(CallReturnBuildUtil + .buildHeadBodyResult()); + } + // 设置集团 + Map headdata = (Map) map.get(HEADTABLE); + headdata.put("pk_org", headdata.get("pk_org_v")); + headdata.put("cdeptid", headdata.get("cdeptvid")); + headdata.put("fstatusflag", 1); + headdata.put("dmakedate", headdata.get("dbilldate")); + headdata.put("dmakedate", headdata.get("dbilldate")); + headdata.put("cinvoicecustid", headdata.get("ccustomerid")); + + String pk_group = AppContext.getInstance().getPkGroup(); + headdata.put("pk_group", pk_group); + List bodyArr = (List) map.get(BODYTABLE); + for (Object body : bodyArr) { + Map bodydata = (Map) body; + bodydata.put("pk_group", pk_group); + bodydata.put("cprojectid", headdata.get("vdef6")); + bodydata.put("ctrafficorgvid", headdata.get("pk_org_v")); + bodydata.put("csendstockorgvid", headdata.get("pk_org_v")); + bodydata.put("csendstordocid", headdata.get("pk_org_v")); + bodydata.put("csendstockorgid", headdata.get("pk_org_v")); + bodydata.put("carorgid", headdata.get("pk_org_v")); + bodydata.put("carorgvid", headdata.get("pk_org_v")); + bodydata.put("csettleorgid", headdata.get("pk_org_v")); + bodydata.put("csettleorgvid", headdata.get("pk_org_v")); + +// bodydata.put("nqtunitnum", bodydata.get("nnum")); + + bodydata.put("ctaxcountryid", "CN"); + bodydata.put("crececountryid", "CN"); + bodydata.put("csendcountryid", "CN"); + + bodydata.put("fbuysellflag", 1); + +// bodydata.put("blargessflag", "N"); + + + // 根据物料编码查询物料信息 + setMaterl(bodydata); + } + } + // 新增自定义档案 + SaleOrderVO[] salevos = OpenAPIParaUtil.changeVO(paramList, HEADTABLE, BODYTABLE); + + genDef(salevos); + + for (Map map : paramList) { + BaseDAO baseDAO = new BaseDAO(); + Map headdata = (Map) map.get(HEADTABLE); + List bodyArr = (List) map.get(BODYTABLE); + for (Object body : bodyArr) { + Map bodydata = (Map) body; + String sql = " select pk_project from bd_project where project_code='" + headdata.get("vdef6") + "' and nvl(dr,0)=0 "; + String o_pk_project = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + bodydata.put("cprojectid", o_pk_project); + } + } +// BillFieldsCodeToPkUtil.doTranslateVOFields(salevos); + + // 参数形式转换为vo并翻译 + List vosList = + TransferMapToVOTool.transferMapToAggVO(paramList, SaleOrderVO.class, + true); + SaleOrderVO[] vos = vosList.toArray(new SaleOrderVO[vosList.size()]); + // 调用接口保存 + IAPISaleOrderMaitain service = + NCLocator.getInstance().lookup(IAPISaleOrderMaitain.class); + SaleOrderVO[] results = service.save(vos); + // 包装返回信息 + return NCCRestUtils.toJSONString(CallReturnBuildUtil.buildSuccessResult( + results, "销售订单保存成功")); + } catch (Exception e) { + return NCCRestUtils.toJSONString(CallReturnBuildUtil.buildFailResult( + null, "销售单保存异常:" + e.getMessage())); + } + } + + private void setMaterl(Map bodydata) throws BusinessException { + 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='" + bodydata.get("cmaterialvid") + "' "; + Map map = (Map) getDao().executeQuery(sql, new MapProcessor()); + if (map == null) { + throw new BusinessException(bodydata.get("cmaterialvid") + "物料未查到"); + } + bodydata.put("castunitid", map.get("castunitid")); + bodydata.put("vchangerate", map.get("measrate")); + // 重新计算金额 + bodydata.put("cqtunitid", map.get("castunitid")); + bodydata.put("cunitid", map.get("cunitid")); + + bodydata.put("cmaterialid", map.get("pk_material")); + bodydata.put("cmaterialvid", map.get("pk_source")); + + bodydata.put("nqtunitnum", BFPubTools.getUFDouble_NullAsZero(bodydata.get("nnum")).div(BFPubTools.getUFDouble_NullAsZero(map.get("measrate").toString().split("/")[0]))); + + sql = "select sl.pk_taxcode from bd_taxrate sl inner join bd_taxcode sm on sl.pk_taxcode=sm.pk_taxcode where sl.taxrate=" + bodydata.get("ntaxrate") + " and sm.pk_group<>'~' " + + ""; + + String o_pk_project = (String) getDao().executeQuery(sql, new ColumnProcessor()); + bodydata.put("ctaxcodeid", o_pk_project); + + + } + + + private void genDef(SaleOrderVO[] salevos) throws BusinessException { + BaseDAO baseDAO = new BaseDAO(); + ArrayList arrhth = new ArrayList(); + ArrayList arrxmh = new ArrayList(); + ArrayList arrxsddh = new ArrayList(); + String pk_org = salevos[0].getParentVO().getPk_org(); + + String sql = " select pk_org,pk_vid from org_orgs where org_orgs.code='" + salevos[0].getParentVO().getPk_org() + "' and nvl(dr,0)=0 and isbusinessunit='Y' "; + + Map map = (Map) baseDAO.executeQuery(sql, new MapProcessor()); + if (map == null) { + throw new BusinessException("采购组织档案未查到"); + } + String o = (String) map.get("pk_org"); + + + String cprocode = salevos[0].getChildrenVO()[0].getCprojectid(); +// String cprocode=salevos[0].getParentVO().getVdef6(); + String cproname = salevos[0].getChildrenVO()[0].getVbdef10(); + if (!BFPubTools.getString_TrimAsNull(cprocode).equals("")) { + sql = " select pk_project from bd_project where project_code='" + cprocode + "' and pk_duty_org='" + o + "' and nvl(dr,0)=0 "; + String o_pk_project = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); + if (o_pk_project == null) { + // 新增项目档案 + createPro(cprocode, cproname, map); + } + } + + + for (int i = 0; i < salevos.length; i++) { + + String vdef6 = BFPubTools.getString_TrimAsNull(salevos[i].getParentVO().getVdef6()); + if (vdef6 != "" && !arrhth.contains(vdef6)) { + + arrhth.add(vdef6); + } + +// if(!arrhth.contains(BFPubTools.getString_TrimAsNull(salevos[i].getParentVO().getVdef6()))) { +// arrhth.add(salevos[i].getParentVO().getVdef6()); +// } + + String vdef2 = BFPubTools.getString_TrimAsNull(salevos[i].getParentVO().getVdef2()); + if (vdef2 != "" && !arrxmh.contains(vdef2)) { + arrxmh.add(vdef2); + } +// if(!arrxmh.contains(BFPubTools.getString_TrimAsNull(salevos[i].getParentVO().getVdef2()))) { +// arrxmh.add(salevos[i].getParentVO().getVdef2()); +// } + + String vdef13 = BFPubTools.getString_TrimAsNull(salevos[i].getParentVO().getVdef13()); + if (vdef13 != "" && !arrxsddh.contains(vdef13)) { + arrxsddh.add(vdef13); + } + +// if(!arrxsddh.contains(BFPubTools.getString_TrimAsNull(salevos[i].getParentVO().getVdef13()))) { +// arrxsddh.add(salevos[i].getParentVO().getVdef13()); +// } + + } +// List newhth=new ArrayList(); + if (arrhth.size() > 0) { + sql = " select code from bd_defdoc where pk_defdoclist in(select pk_defdoclist from bd_defdoclist where code='zdy-001') and pk_org='" + o + "' and "; + sql += BFPubTools.getInSqlWithOutAnd("code", arrhth, 0, arrhth.size()); + ArrayList obj_arrhth = (ArrayList) baseDAO.executeQuery(sql, new ColumnListProcessor()); + if (obj_arrhth != null && obj_arrhth.size() > 0) { + arrhth.removeAll(obj_arrhth); + } + } + + // 组装销售订单数据 + if (arrhth.size() > 0) { + NCLocator.getInstance().lookup(IDefdocService.class).insertDefdocs(o, createDefVO(arrhth, "zdy-001", o.toString())); + } + + +// List newxmh=new ArrayList(); + if (arrxmh.size() > 0) { + sql = " select code from bd_defdoc where pk_defdoclist in(select pk_defdoclist from bd_defdoclist where code='BQxmh') and pk_org='" + o + "' and "; + sql += BFPubTools.getInSqlWithOutAnd("code", arrxmh, 0, arrxmh.size()); + ArrayList obj_arrhth = (ArrayList) baseDAO.executeQuery(sql, new ColumnListProcessor()); + + if (obj_arrhth != null && obj_arrhth.size() > 0) { + + arrxmh.removeAll(obj_arrhth); + } + + } + if (arrxmh.size() > 0) { +// newarrvo.addAll(createDefVO(newxmh,"BQxmh",o.toString())); + NCLocator.getInstance().lookup(IDefdocService.class).insertDefdocs(o, createDefVO(arrxmh, "BQxmh", o.toString())); + } + +// List newxsddh=new ArrayList(); + if (arrxsddh.size() > 0) { + sql = " select code from bd_defdoc where pk_defdoclist in( select pk_defdoclist from bd_defdoclist where code='BIP-ddh') and pk_org='" + o + "' and "; + sql += BFPubTools.getInSqlWithOutAnd("code", arrxsddh, 0, arrxsddh.size()); + ArrayList obj_arrhth = (ArrayList) baseDAO.executeQuery(sql, new ColumnListProcessor()); + if (obj_arrhth != null && obj_arrhth.size() > 0) { + arrxsddh.removeAll(obj_arrhth); + } + } + if (arrxsddh.size() > 0) { +// newarrvo.addAll(createDefVO(newxsddh,"BIP-ddh",o.toString())); + NCLocator.getInstance().lookup(IDefdocService.class).insertDefdocs(o, createDefVO(arrxsddh, "BIP-ddh", o.toString())); + } + // 生成自定义档案 +// if(newarrvo.size()>0) { +// NCLocator.getInstance().lookup(IDefdocService.class).insertDefdocs(o.toString(), newarrvo.toArray(new DefdocVO[newarrvo.size()])); +// } + + } + + private void createPro(String cprocode, String cproname, Map map) throws BusinessException { + String pk_org = (String) map.get("pk_org"); + String pk_org_v = (String) map.get("pk_vid"); + + ProjectHeadVO hvo = new ProjectHeadVO(); + hvo.setProject_code(cprocode); + hvo.setProject_name(cproname); + hvo.setPk_org(pk_org); + hvo.setPk_org_v(pk_org_v); + + hvo.setBill_type("4D10"); + hvo.setCreationtime(new UFDateTime()); + hvo.setCreator(InvocationInfoProxy.getInstance().getUserId()); + hvo.setPk_group(InvocationInfoProxy.getInstance().getGroupId()); + hvo.setDr(0); + hvo.setPk_duty_org(pk_org); + hvo.setTransi_type("4D10-01"); + hvo.setPk_eps("1001A110000000004K64"); + hvo.setPk_duty_dept_v(pk_org_v); + hvo.setEnablestate(2); + NCLocator.getInstance().lookup(IProject.class).insertProject(hvo); + } + + private DefdocVO[] createDefVO(List newhth, String defdoclistcode, String pk_org) throws BusinessException { + String sql = " select pk_defdoclist from bd_defdoclist where code='" + defdoclistcode + "' "; + String o = (String) getDao().executeQuery(sql, new ColumnProcessor()); + + ArrayList arrvo = new ArrayList(); + for (int i = 0; i < newhth.size(); i++) { + DefdocVO vo = new DefdocVO(); + vo.setEnablestate(2); + vo.setPk_defdoclist(o); + vo.setPk_org(pk_org); + vo.setCode(newhth.get(i)); + vo.setName(newhth.get(i)); + vo.setDataoriginflag(0); + vo.setDr(0); + vo.setPk_group(InvocationInfoProxy.getInstance().getGroupId()); + vo.setCreator(InvocationInfoProxy.getInstance().getUserId()); + vo.setCreationtime(new UFDateTime()); + + + arrvo.add(vo); + } + + return arrvo.toArray(new DefdocVO[arrvo.size()]); + + } + + /** + * @Description: 销售订单修改保存 + * @date: 2019-11-1 上午10:03:49 + * @version NCC1909 + */ + @POST + @Path("update") + @Consumes("application/json") + @Produces("application/json") + public JSONString update(Map paramMap) { + InvocationInfoProxy.getInstance().setGroupId("0001A110000000000677"); + try { + if (paramMap == null || !paramMap.containsKey(HEADTABLE) + || !paramMap.containsKey(BODYTABLE)) { + return NCCRestUtils.toJSONString(CallReturnBuildUtil + .buildHeadBodyResult()); + } + List> paramList = + new ArrayList>(); + paramList.add(paramMap); + // 参数形式转换为vo并翻译 + List vosList = + TransferMapToVOTool.transferMapToAggVO(paramList, SaleOrderVO.class, + true); + SaleOrderVO[] vos = vosList.toArray(new SaleOrderVO[vosList.size()]); + List> addMapList = new ArrayList>(); + 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 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 (num <= 0) { + bodydata.put("status", "add"); + Map map = new HashMap(); + map.put(headdata.get("csaleorderid"), objectMap); + addMapList.add(map); + } + + } + } + } + // 调用接口保存 + IAPISaleOrderMaitain service = + NCLocator.getInstance().lookup(IAPISaleOrderMaitain.class); + SaleOrderVO[] results = service.update(vos, addMapList); + // 包装返回信息 + return NCCRestUtils.toJSONString(CallReturnBuildUtil.buildSuccessResult( + results, "销售订单修改成功")); + } catch (Exception e) { + return NCCRestUtils.toJSONString(CallReturnBuildUtil.buildFailResult( + null, "销售订单修改异常:" + e.getMessage())); + } + } + + /** + * @Description: 根据查询方案查询销售订单 + * @date: 2019-11-1 上午10:04:20 + * @version NCC1909 + */ + @POST + @Path("querybyscheme") + @Consumes("application/json") + @Produces("application/json") + public JSONString queryByScheme(Map paramMap) { + SaleOrderVO[] results = null; + try { + // 翻译 + Map fields = + BillFieldsCodeToPkUtil.doTranslateFields(new SaleOrderFieldMapping(), + paramMap); + + // 创建查询方案 + QuerySchemeUtils schemeUtil = + new QuerySchemeUtils(SaleOrderVO.class, fields); + IQueryScheme queryScheme = schemeUtil.creatQueryScheme(); + + // 调用查询接口 + results = + NCLocator.getInstance().lookup(IAPISaleOrderQuery.class) + .queryByScheme(queryScheme); + // 包装返回信息 + return NCCRestUtils.toJSONString(CallReturnBuildUtil.buildSuccessResult( + results, "查询销售订单成功")); + } catch (Exception e) { + return NCCRestUtils.toJSONString(CallReturnBuildUtil.buildFailResult( + results, "查询销售订单失败:" + e.getMessage())); + } + } + + + @SuppressWarnings("unchecked") + @POST + @Path("/saleOrderReviseSaveCommit") + @Consumes("application/json") + @Produces("application/json") + public JSONString saleorderRevise(List> paramList) throws Exception { + InvocationInfoProxy.getInstance().setGroupId("0001A110000000000677"); + SaleOrderVO[] results = null; + try { + String id = ""; + + for (Map map : paramList) { + if (!map.containsKey(HEADTABLE) || !map.containsKey(BODYTABLE)) { + return NCCRestUtils.toJSONString(CallReturnBuildUtil + .buildHeadBodyResult()); + } + // 设置集团 + Map headdata = (Map) map.get(HEADTABLE); + headdata.put("pk_org", headdata.get("pk_org_v")); + + id = BFPubTools.getString_TrimAsNull(headdata.get("csaleorderid")); + if (id.equals("")) { + throw new Exception("csaleorderid" + "主键为空"); + } + String pk_group = AppContext.getInstance().getPkGroup(); + headdata.put("pk_group", pk_group); + List bodyArr = (List) map.get(BODYTABLE); + for (Object body : bodyArr) { + Map bodydata = (Map) body; + bodydata.put("pk_group", pk_group); + bodydata.put("ctaxcountryid", "CN"); + bodydata.put("fbuysellflag", 1); + bodydata.put("blargessflag", "N"); + setMaterl(bodydata); + } + } +// SaleOrderVO[] salevos=OpenAPIParaUtil.changeVO(paramList, HEADTABLE,BODYTABLE); + // 把最新数据传递至历史数据 + // 查询销售订单不存在 + String sql = " select csaleorderid from so_saleorder where csaleorderid='" + id + "' and nvl(dr,0)=0 "; + + String o = (String) getDao().executeQuery(sql, new ColumnProcessor()); + if (o == null) { + throw new Exception("csaleorderid" + "主键为空"); + } + + List vosList = + TransferMapToVOTool.transferMapToAggVO(paramList, SaleOrderVO.class, + true); + SaleOrderVO[] salevos = vosList.toArray(new SaleOrderVO[vosList.size()]); + + ISaleOrderReviseMaintainApp reviseService = (ISaleOrderReviseMaintainApp) NCLocator.getInstance().lookup(ISaleOrderReviseMaintainApp.class); + SaleOrderHistoryVO VOS = reviseService.queryM30ReviseApp(new String[]{id})[0]; + + ArrayList arrbvos = new ArrayList(); + + if (VOS != null) { + SaleOrderBVO[] newbvos = salevos[0].getChildrenVO(); + SaleOrderHistoryBVO[] oldbvos = VOS.getChildrenVO(); + for (int i = 0; i < newbvos.length; i++) { + SaleOrderBVO bvo = newbvos[i]; + // 新增数据 + if (bvo.getPrimaryKey() == null) { + SaleOrderHistoryBVO newvo = (SaleOrderHistoryBVO) oldbvos[0].clone(); + newvo.setCsaleorderbid(""); + newvo.setCrowno(bvo.getCrowno()); + newvo.setStatus(VOStatus.NEW); + // 重新设置数据 + createNewBVo(newvo, bvo); + arrbvos.add(newvo); + continue; + } + for (int j = 0; j < oldbvos.length; j++) { + if (bvo.getCsaleorderbid().equals(oldbvos[j].getCsaleorderbid())) { + // 交换变更数据 + oldbvos[j].setStatus(VOStatus.UPDATED); + createNewBVo(oldbvos[j], bvo); + arrbvos.add(oldbvos[j]); + break; + } + } + } + } + SaleOrderHistoryHVO headvo = VOS.getParentVO(); + headvo.setStatus(1); + headvo.setApprover(null); + headvo.setTaudittime(null); + headvo.setAttributeValue("pseudocolumn", 0); + check30And30RTS(VOS); + + VOS.setChildrenVO((SaleOrderHistoryBVO[]) CollectionUtils.listToArray(arrbvos)); + SaleOrderHistoryVO[] vodis = {VOS}; + VOEntityUtil.clearVOsValue(VOEntityUtil.getBodyVOs(vodis), new String[]{"corderhistorybid"}); + + IAPISaleOrderMaitain service = + NCLocator.getInstance().lookup(IAPISaleOrderMaitain.class); + results = service.modify(vodis); + return NCCRestUtils.toJSONString(CallReturnBuildUtil.buildSuccessResult( + results, "销售订单保存成功")); + } catch (Exception e) { + return NCCRestUtils.toJSONString(CallReturnBuildUtil.buildFailResult( + results, "销售订单修订失败:" + e.getMessage())); + } + + } + + private void createNewBVo(SaleOrderHistoryBVO newvo, SaleOrderBVO bvo) throws Exception { + // 重置物料信息 + newvo.setCmaterialid(bvo.getCmaterialid()); + newvo.setCmaterialvid(newvo.getCmaterialvid()); + newvo.setCunitid(bvo.getCunitid()); + newvo.setCastunitid(bvo.getCastunitid()); + newvo.setCqtunitid(bvo.getCqtunitid()); +// newvo.setStatus(VOStatus.NEW); + newvo.setNnum(bvo.getNnum()); + newvo.setNqtunitnum(bvo.getNqtunitnum()); + newvo.setNastnum(bvo.getNqtunitnum()); + newvo.setVchangerate(bvo.getVchangerate()); + newvo.setNtaxrate(bvo.getNtaxrate()); + newvo.setCrowno(bvo.getCrowno()); + newvo.setNqtorigtaxprice(bvo.getNqtorigtaxprice()); + newvo.setCtaxcodeid(bvo.getCtaxcodeid()); + + } + + private void cheageHVo(SaleOrderHistoryVO billvo, SaleOrderVO saleOrderVO) { + SaleOrderHistoryHVO hvo = billvo.getParentVO(); + SaleOrderHVO oldvo = saleOrderVO.getParentVO(); + hvo.setCinvoicecustid(oldvo.getCinvoicecustid()); + hvo.setCemployeeid(oldvo.getCemployeeid()); + } + + private void check30And30RTS(SaleOrderHistoryVO vo) { + /* 109 */ + ISaleOrderReviseMaintainApp service = (ISaleOrderReviseMaintainApp) NCLocator.getInstance().lookup(ISaleOrderReviseMaintainApp.class); + /* */ + try { + /* 111 */ + SaleOrderHistoryVO[] vos = service.queryM30ReviseApp(new String[]{vo.getPrimaryKey()}); + /* 112 */ + Map billMap = new HashMap(); + /* 113 */ + for (SaleOrderHistoryBVO bvo : vos[0].getChildrenVO()) { + /* 114 */ + billMap.put(bvo.getCsaleorderbid(), bvo.getTs()); + /* */ + } + /* 116 */ + for (SaleOrderHistoryBVO bvo : vo.getChildrenVO()) { + /* 117 */ + if (bvo.getStatus() != 2 && bvo.getStatus() != 0) { + /* 118 */ + UFDateTime ts = (UFDateTime) billMap.get(bvo.getCsaleorderbid()); + /* 119 */ + if (!ts.equals(bvo.getTs())) { + /* 120 */ + ExceptionUtils.wrapBusinessException(NCLangRes4VoTransl.getNCLangRes() + /* 121 */.getStrByID("4006013_0", "04006013-0006")); + /* */ + } + /* */ + } + /* */ + /* */ + } + /* 126 */ + } catch (BusinessException e) { + /* 127 */ + ExceptionUtils.wrapBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("4006013_0", "04006013-0006")); + /* */ + } + /* */ + } + + +}