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..e76f956 --- /dev/null +++ b/so/src/private/nccloud/api/impl/so/m30/APISaleOrderMaitainImpl.java @@ -0,0 +1,886 @@ +package nccloud.api.impl.so.m30; + +import nc.bd.itf.tools.BFPubTools; +import nc.bs.dao.BaseDAO; +import nc.bs.dao.DAOException; +import nc.bs.framework.common.NCLocator; +import nc.bs.trade.business.HYSuperDMO; +import nc.impl.pubapp.pattern.data.bill.BillQuery; +import nc.itf.fi.pub.Currency; +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.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.pub.BusinessException; +import nc.vo.pub.VOStatus; +import nc.vo.pub.billtype.BilltypeVO; +import nc.vo.pub.lang.UFBoolean; +import nc.vo.pub.lang.UFDouble; +import nc.vo.pubapp.AppContext; +import nc.vo.pubapp.pattern.exception.ExceptionUtils; +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.CollectionUtils; +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.enumeration.BillStatus; +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 java.math.BigDecimal; +import java.util.*; + +/** + * @Description: 销售订单维护实现类 + * @author: yanghff + * @date: 2019-10-23 下午4:57:49 + * @Copyright: + */ +public class APISaleOrderMaitainImpl implements IAPISaleOrderMaitain { + + private static String BODYTABLE = "so_saleorder_b"; + private static String HEADTABLE = "so_saleorder"; + + @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()); + } + +} + + +/* Location: D:\home_taikaijt\bipgj\home\yonyou\YonBIP2312\modules\so\META-INF\lib\so_openapi.jar!/nccloud/api/impl/so/m30/APISaleOrderMaitainImpl.class + * Java compiler version: 17 (61.0) + * JD-Core Version: 1.0.7 + */ \ No newline at end of file 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..07e12b0 --- /dev/null +++ b/so/src/public/nccloud/openapi/so/m30/SaleOrderResource.java @@ -0,0 +1,471 @@ + +package nccloud.openapi.so.m30; + +import nc.itf.bd.defdoc.IDefdocService; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import nc.jdbc.framework.processor.*; +import nc.bs.framework.common.InvocationInfoProxy; +import nc.bs.framework.common.NCLocator; +import nc.vo.bd.defdoc.DefdocVO; +import nc.vo.pub.BusinessException; +import nc.vo.pub.lang.UFDateTime; +import nc.vo.pubapp.AppContext; +import nc.vo.so.m30.entity.SaleOrderVO; +import nc.ws.opm.pub.utils.result.APIErrCodeEnum; +import nccloud.api.rest.utils.NCCRestUtils; +import nccloud.api.rest.utils.ResultMessageUtil; +import nccloud.api.so.m30.IAPISaleOrderMaitain; +import nccloud.api.so.m30.IAPISaleOrderQuery; +import nccloud.openapi.scmpub.pub.NCCPubRestResource; +import nccloud.openapi.scmpub.util.CallReturnBuildUtil; +import nc.bs.dao.BaseDAO; +import nc.bd.itf.tools.BFPubTools; +import org.json.JSONString; +import nc.vo.pim.project.ProjectHeadVO; +import nc.itf.pim.project.prv.IProject; + + +/** + * 销售订单接口适配2005代码 + * zhangxinah + */ + +@Path("so/saleorder") +public class SaleOrderResource extends NCCPubRestResource { + + 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; + } + + @POST + @Path("operation/save") + @Consumes({ "application/json" }) + @Produces({ "application/json" }) + public JSONString save(Map paramMap) { + List> paramList = (List) paramMap.get("array"); + return saveold(paramList); + } + + public JSONString saveold(List> paramList) { + try { + for (Map map : paramList) { + if (!map.containsKey(HEADTABLE) || !map.containsKey(BODYTABLE)) { + return ResultMessageUtil.exceptionToJSON("传入参数不能为空", APIErrCodeEnum.BUSINESSEXCCODE.getCode()); + } + } + + IAPISaleOrderMaitain service = (IAPISaleOrderMaitain) NCLocator.getInstance() + .lookup(IAPISaleOrderMaitain.class); + SaleOrderVO[] results = service.save(paramList); + + return ResultMessageUtil.toJSON(results, "销售订单新增保存成功"); + } catch (Exception e) { + return ResultMessageUtil.exceptionToJSON(e); + } + } + + /** + * + * @Description: 在2312基础上适配2005代码 + * @date: 2025年3月19日 18点11分 + * @version NCC2312 + */ + @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("ctaxcountryid", "CN"); + bodydata.put("crececountryid", "CN"); + bodydata.put("csendcountryid", "CN"); + bodydata.put("fbuysellflag", 1); + // 根据物料编码查询物料信息 + 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); + } + } + + // 调用接口保存 + IAPISaleOrderMaitain service = NCLocator.getInstance().lookup(IAPISaleOrderMaitain.class); + SaleOrderVO[] results = service.save(paramList); + // 包装返回信息 + return NCCRestUtils.toJSONString(CallReturnBuildUtil.buildSuccessResult(results, "销售订单保存成功")); + } catch (Exception e) { + return NCCRestUtils.toJSONString(CallReturnBuildUtil.buildFailResult(null, "销售单保存异常:" + e.getMessage())); + } + } + + private void genDef(SaleOrderVO[] salevos) throws BusinessException { + BaseDAO baseDAO = new BaseDAO(); + ArrayList arrhth = new ArrayList(); + ArrayList arrxmh = new ArrayList(); + ArrayList arrxsddh = new ArrayList(); + 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 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); + } + + String vdef2 = BFPubTools.getString_TrimAsNull(salevos[i].getParentVO().getVdef2()); + if (vdef2 != "" && !arrxmh.contains(vdef2)) { + arrxmh.add(vdef2); + } + + String vdef13 = BFPubTools.getString_TrimAsNull(salevos[i].getParentVO().getVdef13()); + if (vdef13 != "" && !arrxsddh.contains(vdef13)) { + arrxsddh.add(vdef13); + } + + } + 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())); + } + + 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) { + NCLocator.getInstance().lookup(IDefdocService.class).insertDefdocs(o, + createDefVO(arrxmh, "BQxmh", o.toString())); + } + + 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) { + NCLocator.getInstance().lookup(IDefdocService.class).insertDefdocs(o, + createDefVO(arrxsddh, "BIP-ddh", o.toString())); + } + + } + + 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()]); + + } + + 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); + + } + + @POST + @Path("update") + @Consumes({ "application/json" }) + @Produces({ "application/json" }) + public JSONString update(Map paramMap) { + try { + if (paramMap == null || !paramMap.containsKey(HEADTABLE) || !paramMap.containsKey(BODYTABLE)) { + return ResultMessageUtil.exceptionToJSON("传入参数不能为空", APIErrCodeEnum.BUSINESSEXCCODE.getCode()); + } + List> paramList = new ArrayList>(); + + paramList.add(paramMap); + + IAPISaleOrderMaitain service = (IAPISaleOrderMaitain) NCLocator.getInstance() + .lookup(IAPISaleOrderMaitain.class); + SaleOrderVO[] results = service.update(paramList); + + return ResultMessageUtil.toJSON(results, "销售订单修改成功"); + } catch (Exception e) { + return ResultMessageUtil.exceptionToJSON(e); + } + } + + @POST + @Path("operation/delete") + @Consumes({ "application/json" }) + @Produces({ "application/json" }) + public JSONString delete(Map paramMap) { + ArrayList paramArray = (ArrayList) paramMap.get("csaleorderid"); + String[] hids = (String[]) paramArray.toArray(new String[0]); + return delete(hids); + } + + @POST + @Path("delete") + @Consumes({ "application/json" }) + @Produces({ "application/json" }) + public JSONString delete(String[] hids) { + if (hids == null || hids.length == 0) { + return ResultMessageUtil.exceptionToJSON("传入参数为空,请检查", APIErrCodeEnum.BUSINESSEXCCODE.getCode()); + } + + try { + ((IAPISaleOrderMaitain) NCLocator.getInstance().lookup(IAPISaleOrderMaitain.class)).delete(hids); + String[] arr = new String[0]; + return ResultMessageUtil.toJSON(arr, "销售订单删除成功"); + } catch (Exception e) { + return ResultMessageUtil.exceptionToJSON(new BusinessException("删除销售订单出现异常", e)); + } + } + + @POST + @Path("querybyscheme") + @Consumes({ "application/json" }) + @Produces({ "application/json" }) + public JSONString queryByScheme(Map paramMap) { + SaleOrderVO[] resultVOs = null; + + try { + resultVOs = ((IAPISaleOrderQuery) NCLocator.getInstance().lookup(IAPISaleOrderQuery.class)) + .queryByScheme(paramMap); + + return ResultMessageUtil.toJSON(resultVOs, "查询销售订单成功"); + } catch (Exception e) { + return ResultMessageUtil.exceptionToJSON(e); + } + } + + @POST + @Path("sendapprove") + @Consumes({ "application/json" }) + @Produces({ "application/json" }) + public JSONString sendApprove(Map paramMap) { + SaleOrderVO[] sendApprove = null; + ArrayList paramArray = (ArrayList) paramMap.get("csaleorderid"); + String[] hids = (String[]) paramArray.toArray(new String[0]); + if (hids == null || hids.length == 0) { + return ResultMessageUtil.exceptionToJSON("传入参数为空,请检查", APIErrCodeEnum.BUSINESSEXCCODE.getCode()); + } + + try { + sendApprove = ((IAPISaleOrderMaitain) NCLocator.getInstance().lookup(IAPISaleOrderMaitain.class)) + .sendApprove(hids); + return ResultMessageUtil.toJSON(sendApprove, "销售订单提交成功"); + } catch (BusinessException e) { + return ResultMessageUtil.exceptionToJSON(e); + } + } + + @POST + @Path("unsend") + @Consumes({ "application/json" }) + @Produces({ "application/json" }) + public JSONString unSendApprove(Map paramMap) { + SaleOrderVO[] unSend = null; + ArrayList paramArray = (ArrayList) paramMap.get("csaleorderid"); + String[] hids = (String[]) paramArray.toArray(new String[0]); + if (hids == null || hids.length == 0) { + return ResultMessageUtil.exceptionToJSON("传入参数为空,请检查", APIErrCodeEnum.BUSINESSEXCCODE.getCode()); + } + + try { + unSend = ((IAPISaleOrderMaitain) NCLocator.getInstance().lookup(IAPISaleOrderMaitain.class)) + .unSendApprove(hids); + return ResultMessageUtil.toJSON(unSend, "销售订单收回成功"); + } catch (BusinessException e) { + return ResultMessageUtil.exceptionToJSON(e); + } + } + + @POST + @Path("approve") + @Consumes({ "application/json" }) + @Produces({ "application/json" }) + public JSONString approve(Map paramMap) { + SaleOrderVO[] aprove = null; + ArrayList paramArray = (ArrayList) paramMap.get("csaleorderid"); + String[] hids = (String[]) paramArray.toArray(new String[0]); + if (hids == null || hids.length == 0) { + return ResultMessageUtil.exceptionToJSON("传入参数为空,请检查", APIErrCodeEnum.BUSINESSEXCCODE.getCode()); + } + try { + aprove = ((IAPISaleOrderMaitain) NCLocator.getInstance().lookup(IAPISaleOrderMaitain.class)).approve(hids); + return ResultMessageUtil.toJSON(aprove, "销售订单审批成功"); + } catch (BusinessException e) { + return ResultMessageUtil.exceptionToJSON(e); + } + } + + @POST + @Path("unapprove") + @Consumes({ "application/json" }) + @Produces({ "application/json" }) + public JSONString unApprove(Map paramMap) { + SaleOrderVO[] unaprove = null; + ArrayList paramArray = (ArrayList) paramMap.get("csaleorderid"); + String[] hids = (String[]) paramArray.toArray(new String[0]); + if (hids == null || hids.length == 0) { + return ResultMessageUtil.exceptionToJSON("传入参数为空,请检查", APIErrCodeEnum.BUSINESSEXCCODE.getCode()); + } + try { + unaprove = ((IAPISaleOrderMaitain) NCLocator.getInstance().lookup(IAPISaleOrderMaitain.class)) + .unApprove(hids); + return ResultMessageUtil.toJSON(unaprove, "销售订单取消审批成功"); + } catch (BusinessException e) { + return ResultMessageUtil.exceptionToJSON(e); + } + } +}