销售订单推送qms
This commit is contained in:
		
							parent
							
								
									e5ebda0499
								
							
						
					
					
						commit
						1200e66287
					
				|  | @ -5,23 +5,46 @@ | |||
| 
 | ||||
| package nccloud.web.so.saleorder.action; | ||||
| 
 | ||||
| import com.alibaba.fastjson.JSON; | ||||
| import com.alibaba.fastjson.JSONArray; | ||||
| import com.alibaba.fastjson.JSONObject; | ||||
| import com.alibaba.fastjson.serializer.SerializerFeature; | ||||
| import nc.bs.dao.BaseDAO; | ||||
| import nc.bs.dao.DAOException; | ||||
| import nc.bs.logging.Log; | ||||
| import nc.bs.trade.business.HYPubBO; | ||||
| import nc.bs.trade.business.HYSuperDMO; | ||||
| import nc.bs.uapbd.util.MyHelper; | ||||
| import nc.bs.uapbd.util.ThirdPartyPostRequestUtil; | ||||
| import nc.jdbc.framework.processor.ColumnProcessor; | ||||
| import nc.jdbc.framework.processor.MapProcessor; | ||||
| import nc.vo.bd.defdoc.DefdocVO; | ||||
| import nc.vo.org.OrgVO; | ||||
| import nc.vo.pub.BusinessException; | ||||
| import nc.vo.pubapp.pattern.exception.ExceptionUtils; | ||||
| import nc.vo.so.m30.entity.SaleOrderBVO; | ||||
| import nc.vo.so.m30.entity.SaleOrderHVO; | ||||
| import nc.vo.so.m30.entity.SaleOrderVO; | ||||
| import nccloud.baseapp.core.log.NCCForUAPLogger; | ||||
| import nccloud.dto.so.saleorder.entity.QueryInfo; | ||||
| import nccloud.framework.core.json.IJson; | ||||
| import nccloud.framework.service.ServiceLocator; | ||||
| import nccloud.framework.web.action.itf.ICommonAction; | ||||
| import nccloud.framework.web.container.IRequest; | ||||
| import nccloud.framework.web.json.JsonFactory; | ||||
| import nccloud.framework.web.ui.pattern.billcard.BillCard; | ||||
| import nccloud.framework.web.ui.pattern.billcard.BillCardOperator; | ||||
| import nccloud.pubitf.so.saleorder.service.ISaleOrderQueryWebService; | ||||
| import nccloud.web.so.pub.tool.BatchCodeTranslatorUtils; | ||||
| import nccloud.web.so.saleorder.calproperty.SaleOrderCalPropertyProcess; | ||||
| import nccloud.web.so.saleorder.scale.SaleOrderScaleProcess; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| import java.util.Date; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| public class SaleOrderToQmsAction implements ICommonAction { | ||||
|     private static final String LOG_INFO_NAME = "qyMesLog"; | ||||
|     private static final Log logger = Log.getInstance(LOG_INFO_NAME); | ||||
|     private static final String reqUrl = "/IF_QyErpApi.ashx?action=addxsht"; | ||||
|     private Map<String, String> configParams; | ||||
|     public SaleOrderToQmsAction() { | ||||
|     } | ||||
| 
 | ||||
|  | @ -33,14 +56,182 @@ public class SaleOrderToQmsAction implements ICommonAction { | |||
|             ISaleOrderQueryWebService service = (ISaleOrderQueryWebService)ServiceLocator.find(ISaleOrderQueryWebService.class); | ||||
|             BillCardOperator operator = new BillCardOperator(info.getPageid()); | ||||
|             SaleOrderVO saleorderVO = service.querySaleOrderVObyId(info.getPk()); | ||||
|             BillCard result = operator.toCard(saleorderVO); | ||||
|             SaleOrderCalPropertyProcess.process(result); | ||||
|             SaleOrderScaleProcess.process(result); | ||||
|             BatchCodeTranslatorUtils.proBatchCode(result); | ||||
|             return result; | ||||
|             configParams = MyHelper.getConfigParams("xb-config", null); | ||||
|             if (configParams.isEmpty()) { | ||||
|                 throw new BusinessException("箱变的QMS接口缺少配置"); | ||||
|             } | ||||
|             return buildSyncData(new SaleOrderVO[]{saleorderVO}); | ||||
|         } catch (BusinessException e) { | ||||
|             ExceptionUtils.wrappException(e); | ||||
|             return null; | ||||
|         } | ||||
|     } | ||||
|     /** | ||||
|      * 构建同步数据 | ||||
|      * | ||||
|      * @return | ||||
|      */ | ||||
|     private List<Map<String, Object>> buildSyncData(SaleOrderVO[] useVOs) throws BusinessException { | ||||
|         BaseDAO baseDAO = new BaseDAO(); | ||||
|         List<Map<String, Object>> requestList = new ArrayList<>(); | ||||
|         Date now = new Date(); | ||||
|         HYPubBO hybo = new HYPubBO(); | ||||
|         for (SaleOrderVO vo : useVOs) { | ||||
|             // 判断业务单元是否是箱变公司,不是则跳过 | ||||
|             String pkOrg = vo.getParentVO().getPk_org(); | ||||
|             String orgCode = MyHelper.transferField(OrgVO.getDefaultTableName(), OrgVO.CODE, OrgVO.PK_ORG, pkOrg); | ||||
|             if (checkIfOrg(orgCode, configParams)) { | ||||
|                 continue; | ||||
|             } | ||||
|             // 组装数据 | ||||
|             JSONObject singleObj = new JSONObject(); | ||||
| 
 | ||||
|             SaleOrderHVO pmoHeadVO = vo.getParentVO(); | ||||
|             SaleOrderBVO[] itemVOS = vo.getChildrenVO(); | ||||
|             singleObj.put("batchid", now); | ||||
|             String vdef6 = pmoHeadVO.getVdef6(); | ||||
|             String contractNum = getDefCode("zdy-001", vdef6); | ||||
|             singleObj.put("hth", contractNum); | ||||
|             singleObj.put("fplx", pmoHeadVO.getDbilldate().toString().substring(0, 10)); | ||||
|             if (null != pmoHeadVO.getCemployeeid()) { | ||||
|                 String sql = " select name from bd_psndoc where pk_psndoc = '" + pmoHeadVO.getCemployeeid() + "' "; | ||||
|                 String billmakerName = (String) baseDAO.executeQuery(sql, new ColumnProcessor()); | ||||
| 
 | ||||
|                 singleObj.put("xsy", billmakerName); | ||||
|             } else { | ||||
|                 singleObj.put("xsy", ""); | ||||
|             } | ||||
| 
 | ||||
|             singleObj.put("dhdwid", pmoHeadVO.getCcustomerid()); | ||||
|             String customersql = " select name from bd_customer where pk_customer = '" + pmoHeadVO.getCcustomerid() + "' "; | ||||
|             String customerName = (String) baseDAO.executeQuery(customersql, new ColumnProcessor()); | ||||
|             singleObj.put("dhdw", customerName); | ||||
| 
 | ||||
| 
 | ||||
|             String lrrsql = " select user_name from sm_user where cuserid = '" + pmoHeadVO.getBillmaker() + "' "; | ||||
|             String lrrName = (String) baseDAO.executeQuery(lrrsql, new ColumnProcessor()); | ||||
| 
 | ||||
|             singleObj.put("lrr", lrrName); | ||||
|             singleObj.put("lrrq", pmoHeadVO.getDmakedate().toString().substring(0, 10)); | ||||
|             singleObj.put("bz", pmoHeadVO.getVnote()); | ||||
|             // 处理Content数组 | ||||
|             JSONArray contentArray = new JSONArray(); | ||||
|             for (SaleOrderBVO item : itemVOS) { | ||||
|                 JSONObject itemObj = new JSONObject(); | ||||
| //                itemObj.put("sgdh", item.getSgdh()); | ||||
| //                itemObj.put("xshth", item.getVdef1()); | ||||
| //                itemObj.put("htqdxh", item.getHtqdxh()); | ||||
| //                Object no = hybo.findColValue("bd_material", "code", "pk_material = '"+item.getCmaterialvid()+"' "); | ||||
| // | ||||
| //                Object name = hybo.findColValue("bd_material", "name", "pk_material = '"+item.getCmaterialvid()+"' "); | ||||
|                 String wlsql = " select code,name,materialspec,materialtype from bd_material where pk_material = '" + item.getCmaterialvid() + "' "; | ||||
|                 Map<String, Object> mrlmap = (Map<String, Object>) baseDAO.executeQuery(wlsql, new MapProcessor()); | ||||
| 
 | ||||
|                 itemObj.put("wlbh", mrlmap.get("code")); | ||||
|                 itemObj.put("wlmc", mrlmap.get("name")); | ||||
|                 String wlxhgg = (mrlmap.get("materialspec") != null ? mrlmap.get("materialspec").toString() : "") + (mrlmap.get("materialtype") != null ? mrlmap.get("materialtype").toString() : ""); | ||||
|                 itemObj.put("wlxhgg", wlxhgg); | ||||
|                 itemObj.put("dhsl", item.getNastnum().doubleValue()); | ||||
|                 itemObj.put("xsj", item.getNqtorigtaxprice().doubleValue()); | ||||
|                 itemObj.put("bxzje", item.getNqtorigtaxprice().doubleValue()); | ||||
|                 if (item.getDsenddate() != null) { | ||||
|                     itemObj.put("jhrq", item.getDsenddate().toString().substring(0, 10)); | ||||
|                 } else { | ||||
|                     itemObj.put("jhrq", ""); | ||||
|                 } | ||||
|                 itemObj.put("bz", item.getVrownote()); | ||||
|                 Object project_name = hybo.findColValue("bd_project", "project_name", " project_name = '" + item.getCprojectid() + "' "); | ||||
|                 itemObj.put("xmmc", project_name); | ||||
| 
 | ||||
|                 contentArray.add(itemObj); | ||||
|             } | ||||
| 
 | ||||
|             singleObj.put("Content", contentArray); | ||||
| 
 | ||||
|             /* | ||||
|              { | ||||
|               "batchid": "XS202408001", | ||||
|               "hth": "HT202408001", | ||||
|               "fplx": "增值税专用发票", | ||||
|               "xsy": "张三", | ||||
|               "xmmc": "某项目供电设备采购", | ||||
|               "dhdwid": "C001", | ||||
|               "dhdw": "某电力公司", | ||||
|               "lrr": "李四", | ||||
|               "lrrq": "2024-08-21", | ||||
|               "bz": "需加急处理", | ||||
|               "Content": [ | ||||
|                 { | ||||
|                   "wlbh": "ACC26711", | ||||
|                   "wlmc": "铜排", | ||||
|                   "wlxhgg": "15558190831", | ||||
|                   "dhsl": "200", | ||||
|                   "xsj": "50.00", | ||||
|                   "bxzje": "10000.00", | ||||
|                   "jhrq": "2024-09-30", | ||||
|                   "bz": "需符合国标材质" | ||||
|                 } | ||||
|               ] | ||||
|             } | ||||
| 
 | ||||
|              */ | ||||
|             pushData(singleObj); | ||||
|         } | ||||
|         return requestList; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * 推送同步数据 | ||||
|      */ | ||||
|     private void pushData(JSONObject param) throws BusinessException { | ||||
|         // String jsonString = param.toJSONString(); | ||||
|         // 转json字符串的时候保留null值 | ||||
|         String jsonStr = JSON.toJSONString(param, | ||||
|                 SerializerFeature.WriteMapNullValue, | ||||
|                 SerializerFeature.WriteNullStringAsEmpty | ||||
|         ); | ||||
|         logger.error("QMS-SaleOrder-param = " + jsonStr); | ||||
|         NCCForUAPLogger.debug("QMS-SaleOrder-param = " + jsonStr); | ||||
|         String baseUrl = configParams.get("qmsBaseUrl"); | ||||
|         String requestUrl = baseUrl + reqUrl; | ||||
|         logger.error("QMS-SaleOrder-url = " + requestUrl); | ||||
|         String result = ThirdPartyPostRequestUtil.sendPostRequest(requestUrl, jsonStr); | ||||
|         logger.error("QMS-SaleOrder-res = " + result); | ||||
|         JSONObject resultObj = JSONObject.parseObject(result); | ||||
| 
 | ||||
|         if (!"true".equals(resultObj.getString("success"))) { | ||||
|             logger.error("QMS-SaleOrder-error,result[" + resultObj.toJSONString() + "]"); | ||||
|             throw new BusinessException("QMS-SaleOrder-error:" + resultObj.getString("message")); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private boolean checkIfOrg(String code, Map<String, String> configParams) throws BusinessException { | ||||
|         String targetCode = configParams.get("xbOrg"); | ||||
|         if (targetCode == null || nc.vo.am.common.util.StringUtils.isEmpty(targetCode)) { | ||||
|             throw new BusinessException("未配置组织参数"); | ||||
|         } | ||||
|         String[] orgItem = targetCode.split(","); | ||||
|         for (String orgCode : orgItem) { | ||||
|             if (!orgCode.isEmpty() && orgCode.equals(code)) { | ||||
|                 return false; | ||||
|             } | ||||
|         } | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     private String getDefCode(String code, String pk_defdoc) { | ||||
|         String res = ""; | ||||
|         String strWhere = " pk_defdoclist in (select pk_defdoclist from bd_defdoclist where code='" + code + "' and dr=0 )  and dr = 0 and pk_defdoc = '" + pk_defdoc + "'"; | ||||
|         try { | ||||
|             DefdocVO[] defdocVOs = (DefdocVO[]) new HYSuperDMO().queryByWhereClause(DefdocVO.class, strWhere); | ||||
|             if (defdocVOs != null && defdocVOs.length > 0) { | ||||
|                 res = defdocVOs[0].getCode().trim(); | ||||
|             } | ||||
|         } catch (DAOException e) { | ||||
|             logger.error("QMS-SaleOrder-error,getDefCode[" + e.getMessage() + "]"); | ||||
|         } | ||||
|         return res; | ||||
| 
 | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -392,7 +392,7 @@ | |||
| 	</action> | ||||
| 	<action> | ||||
| 		<name>so.refer.SaleOrderToQms</name> | ||||
| 		<label>销售订单参照</label> | ||||
| 		<label>销售订单推送qms</label> | ||||
| 		<clazz>nccloud.web.so.saleorder.action.SaleOrderToQmsAction</clazz> | ||||
| 	</action> | ||||
| </actions> | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue