Browse Source

形态转换异常处理

yaoyu 2 years ago
parent
commit
c9cc598178
1 changed files with 221 additions and 233 deletions
  1. 221 233
      xh/xh/src/private/nc/bs/xh/impl/TransformAddImpl.java

+ 221 - 233
xh/xh/src/private/nc/bs/xh/impl/TransformAddImpl.java

@@ -1,233 +1,221 @@
-package nc.bs.xh.impl;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import nc.bs.dao.BaseDAO;
-import nc.bs.dao.DAOException;
-import nc.bs.framework.adaptor.IHttpServletAdaptor;
-import nc.bs.framework.common.InvocationInfoProxy;
-import nc.bs.framework.common.NCLocator;
-import nc.bs.framework.server.ISecurityTokenCallback;
-import nc.bs.servlet.service.BaseServlet;
-import nc.itf.ic.m4n.ITransformMaitain;
-import nc.itf.pu.m21.IOrderMaintain;
-import nc.itf.uap.IUAPQueryBS;
-import nc.itf.uap.pf.IPFBusiAction;
-import nc.jdbc.framework.processor.ColumnProcessor;
-import nc.log.NcLog;
-import nc.vo.ic.m4n.entity.TransformHeadVO;
-import nc.vo.ic.m4n.entity.TransformVO;
-import nc.vo.mmsfc.operationrep.entity.OprepItemVO;
-import nc.vo.pub.BusinessException;
-import nc.vo.pub.lang.UFDate;
-import nc.vo.pub.lang.UFDateTime;
-import nc.vo.pub.lang.UFDouble;
-import net.sf.json.JSONArray;
-import net.sf.json.JSONObject;
-import nc.vo.ic.m4n.entity.TransformBodyVO;
-
-
-public class TransformAddImpl extends BaseServlet implements IHttpServletAdaptor{
-	
-	IUAPQueryBS iuap= (IUAPQueryBS) NCLocator.getInstance().lookup(IUAPQueryBS.class.getName());
-
-	@Override
-	public void doAction(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
-		// TODO Auto-generated method stub
-		NCLocator.getInstance().lookup(ISecurityTokenCallback.class).token("NCSystem".getBytes(),"pfxx".getBytes());
-        try {
-			String createStr = buildJson(req, resp, this.getClass().getName());
-			JSONObject json = JSONObject.fromObject(createStr);
-			String vbillcode = "";
-			PrintWriter out = resp.getWriter();
-			vbillcode = json.getString("vbillcode");
-			checkJson(json);//非空判断
-			
-			
-			InvocationInfoProxy.getInstance().setGroupId(SqlexecuteQuery("pk_group", "org_group", "code", json.getString("pk_group")));
-			InvocationInfoProxy.getInstance().setUserId(SqlexecuteQuery("cuserid", "sm_user", "user_code", json.getString("creator")));
-			
-			TransformVO[] transformvos = new TransformVO[1];
-			TransformVO transformvo = new TransformVO();
-			transformvos[0] = transformvo;
-			TransformHeadVO transformheadvo = new TransformHeadVO();
-			TransformBodyVO[] transformbodyvos = new TransformBodyVO[json.getJSONArray("cspecialbid").size()];
-			
-			/**
-			 * 封装表头VO
-			 */
-			transformheadvo.setVbillcode(vbillcode);
-			transformheadvo.setPk_group(SqlexecuteQuery("pk_group", "org_group", "code", json.getString("pk_group")));
-			transformheadvo.setPk_org(SqlexecuteQuery("pk_stockorg", "org_stockorg", "code", json.getString("pk_org")));
-			transformheadvo.setPk_org_v(SqlexecuteQuery("pk_vid", "org_stockorg_v", "code", json.getString("pk_org")));
-			transformheadvo.setCorpoid(SqlexecuteQuery("pk_corp", "org_corp", "code", json.getString("corpoid")));
-			transformheadvo.setCorpvid(SqlexecuteQuery("pk_vid", "org_corp", "code", json.getString("corpoid")));
-			transformheadvo.setDbilldate(new UFDate(json.getString("dbilldate")));
-			transformheadvo.setVtrantypecode(json.getString("vtrantypecode"));
-			transformheadvo.setCreator(SqlexecuteQuery("cuserid", "sm_user", "user_code", json.getString("creator")));
-			transformheadvo.setCreationtime(new UFDateTime(json.getString("dbilldate")));
-			transformheadvo.setBillmaker(SqlexecuteQuery("cuserid", "sm_user", "user_code", json.getString("creator")));
-			transformheadvo.setDmakedate(new UFDate(json.getString("dbilldate")));
-			transformheadvo.setCtrantypeid(QueryTrantype(json.getString("vtrantypecode"),SqlexecuteQuery("pk_group", "org_group", "code", json.getString("pk_group"))));
-			transformvo.setParentVO(transformheadvo);
-			
-			/**
-			 * 封装表体VO
-			 */
-			JSONArray bodyArray = json.getJSONArray("cspecialbid");
-			int i=0;
-			for (Object Object : bodyArray) {
-				JSONObject bodyObject = JSONObject.fromObject(Object);
-				TransformBodyVO transformbodyvo = new TransformBodyVO();
-				transformbodyvo.setCrowno(bodyObject.getString("crowno"));
-				transformbodyvo.setFbillrowflag(Integer.parseInt(bodyObject.getString("fbillrowflag")));
-				transformbodyvo.setPk_group(SqlexecuteQuery("pk_group", "org_group", "code", bodyObject.getString("pk_group")));
-				transformbodyvo.setPk_org(SqlexecuteQuery("pk_stockorg", "org_stockorg", "code", bodyObject.getString("pk_org")));
-				transformbodyvo.setPk_org_v(SqlexecuteQuery("pk_vid", "org_stockorg_v", "code", bodyObject.getString("pk_org")));
-				transformbodyvo.setCorpoid(SqlexecuteQuery("pk_corp", "org_corp", "code", bodyObject.getString("corpoid")));
-				transformbodyvo.setCorpvid(SqlexecuteQuery("pk_vid", "org_corp", "code", bodyObject.getString("corpoid")));
-				transformbodyvo.setCbodywarehouseid(SqlexecuteQuery("pk_stordoc", "bd_stordoc", "code", bodyObject.getString("cbodywarehouseid")));
-				transformbodyvo.setCmaterialoid(SqlexecuteQuery("pk_source", "bd_material_v", "code", bodyObject.getString("cmaterialoid")));
-				transformbodyvo.setCmaterialvid(SqlexecuteQuery("pk_material", "bd_material", "code", bodyObject.getString("cmaterialoid")));
-				transformbodyvo.setCunitid(SqlexecuteQuery("pk_measdoc", "bd_measdoc", "code", bodyObject.getString("cunitid")));
-				transformbodyvo.setCastunitid(SqlexecuteQuery("pk_measdoc", "bd_measdoc", "code", bodyObject.getString("castunitid")));
-				transformbodyvo.setVchangerate(bodyObject.getString("vchangerate"));
-				transformbodyvo.setNnum(new UFDouble(bodyObject.getString("nnum")));
-				transformbodyvo.setNassistnum(new UFDouble(bodyObject.getString("nassistnum")));
-				transformbodyvo.setNcostprice(new UFDouble(bodyObject.getString("ncostprice")));
-				transformbodyvo.setNcostmny(new UFDouble(bodyObject.getString("ncostmny")));
-				transformbodyvos[i] = transformbodyvo;
-				i++;
-			}
-			transformvo.setChildrenVO(transformbodyvos);
-			
-			ITransformMaitain itransform=(ITransformMaitain)NCLocator.getInstance().lookup(ITransformMaitain.class);
-			itransform.insert(transformvos);
-			IPFBusiAction service = NCLocator.getInstance().lookup(IPFBusiAction.class);
-			service.processAction("APPROVE",
-	                "4N", null, transformvos[0], null, null);
-			out.print(formatRSJsonData("成功","",vbillcode)); 
-			
-		} catch (Exception e) {
-			// TODO Auto-generated catch block
-			resp.getWriter().write(formatRSJsonData("失败",
-				     e.getMessage().toString(),"").toString());
-			StringWriter stringWriter = new StringWriter();
-			e.printStackTrace(new PrintWriter(stringWriter));
-			//获取详细信息
-			String msg=stringWriter.getBuffer().toString();
-			NcLog.info("接口返回值提示:"+msg);
-		}
-        
-	}
-	
-	/*
-	 * 非空判断
-	 */
-	private void checkJson(JSONObject json) throws Exception {
-		
-		StringBuffer mags = new StringBuffer();
-		Boolean empty = true;
-		
-		String vbillcode = "vbillcode";//单据号
-		String group = "pk_group";//集团编码
-		String creator = "creator";//创建人
-		
-		String body = "cspecialbid";//表体
- 
-		String[] HeadKey = {vbillcode,group,creator};
-		
-		for (String as : HeadKey) {
-
-			if (json.getString(as).isEmpty()) {
-				empty = false;
-				mags.append("'" + as + "'");
-			}
-		}
-		
-		if (json.getJSONArray(body)==null) {
-			empty = false;
-			mags.append("表体不存在! ");
-		}
-		
-		JSONArray oprepObjectBs = json.getJSONArray("cspecialbid");
-		
-		if (oprepObjectBs == null || oprepObjectBs.size() == 0) {
-			throw new Exception("表体内容不可为空!");
-		}
-		
-		String cmaterialoid = "cmaterialoid";//物料编码
-		
-		for(int i = 0; i < oprepObjectBs.size(); i++) {
-			
-			JSONObject oprepJsonObjectB = oprepObjectBs.getJSONObject(i);
-			String[] BodyKey = {cmaterialoid};
-			int num = i+1;
-			
-			mags.append("第"+num+"块表体:{");
-			for (String as : BodyKey) {
-
-				if (oprepJsonObjectB.getString(as).isEmpty()) {
-					empty = false;
-					mags.append("'" + as + "' ");
-				}
-			}
-			mags.append("}");
-		}
-		
-		if (!empty) {
-			throw new Exception("以下字段不可为空:"+mags);
-		}
-	}
-	
-	/*
-	 * 数据库查询
-	 */
-	private String SqlexecuteQuery(String out,String table,String key,String value) throws DAOException {
-		
-		String sql = "select "+out+" from "+table+" where "+key+" = '"+value+"' and nvl(dr,0)=0";
-		
-		Object object;
-		try {
-			object = iuap.executeQuery(sql, new ColumnProcessor());
-			if (object==null) {
-				throw new DAOException("未查询到数据!请检查编码"+value+"是否正确!");
-			}
-			
-			return object.toString();
-		} catch (BusinessException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-			return e.getMessage();
-		}
-	}
-	
-	/*
-	 * 查询转换类型pk
-	 */
-	private String QueryTrantype(String code,String group) throws DAOException {
-		
-		String sql = "select pk_billtypeid from bd_billtype where pk_billtypecode = '"+code+"' and pk_group = '"+group+"' and nvl(dr,0)=0";
-		
-		Object object;
-		try {
-			object = iuap.executeQuery(sql, new ColumnProcessor());
-			if (object==null) {
-				throw new DAOException("未查询到数据!请检查编码"+code+"是否正确!");
-			}
-			
-			return object.toString();
-		} catch (BusinessException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-			return e.getMessage();
-		}
-	}
-
-}
+package nc.bs.xh.impl;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import nc.bs.dao.BaseDAO;
+import nc.bs.dao.DAOException;
+import nc.bs.framework.adaptor.IHttpServletAdaptor;
+import nc.bs.framework.common.InvocationInfoProxy;
+import nc.bs.framework.common.NCLocator;
+import nc.bs.framework.server.ISecurityTokenCallback;
+import nc.bs.servlet.service.BaseServlet;
+import nc.itf.ic.m4n.ITransformMaitain;
+import nc.itf.pu.m21.IOrderMaintain;
+import nc.itf.uap.IUAPQueryBS;
+import nc.itf.uap.pf.IPFBusiAction;
+import nc.jdbc.framework.processor.ColumnProcessor;
+import nc.log.NcLog;
+import nc.vo.ic.m4n.entity.TransformHeadVO;
+import nc.vo.ic.m4n.entity.TransformVO;
+import nc.vo.mmsfc.operationrep.entity.OprepItemVO;
+import nc.vo.pub.BusinessException;
+import nc.vo.pub.lang.UFDate;
+import nc.vo.pub.lang.UFDateTime;
+import nc.vo.pub.lang.UFDouble;
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+import nc.vo.ic.m4n.entity.TransformBodyVO;
+
+
+public class TransformAddImpl extends BaseServlet implements IHttpServletAdaptor{
+	
+	IUAPQueryBS iuap= (IUAPQueryBS) NCLocator.getInstance().lookup(IUAPQueryBS.class.getName());
+
+	@Override
+	public void doAction(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+		// TODO Auto-generated method stub
+		NCLocator.getInstance().lookup(ISecurityTokenCallback.class).token("NCSystem".getBytes(),"pfxx".getBytes());
+        try {
+			String createStr = buildJson(req, resp, this.getClass().getName());
+			JSONObject json = JSONObject.fromObject(createStr);
+			String vbillcode = "";
+			PrintWriter out = resp.getWriter();
+			vbillcode = json.getString("vbillcode");
+			checkJson(json);//非空判断
+			
+			
+			InvocationInfoProxy.getInstance().setGroupId(SqlexecuteQuery("pk_group", "org_group", "code", json.getString("pk_group")));
+			InvocationInfoProxy.getInstance().setUserId(SqlexecuteQuery("cuserid", "sm_user", "user_code", json.getString("creator")));
+			
+			TransformVO[] transformvos = new TransformVO[1];
+			TransformVO transformvo = new TransformVO();
+			transformvos[0] = transformvo;
+			TransformHeadVO transformheadvo = new TransformHeadVO();
+			TransformBodyVO[] transformbodyvos = new TransformBodyVO[json.getJSONArray("cspecialbid").size()];
+			
+			/**
+			 * 封装表头VO
+			 */
+			transformheadvo.setVbillcode(vbillcode);
+			transformheadvo.setPk_group(SqlexecuteQuery("pk_group", "org_group", "code", json.getString("pk_group")));
+			transformheadvo.setPk_org(SqlexecuteQuery("pk_stockorg", "org_stockorg", "code", json.getString("pk_org")));
+			transformheadvo.setPk_org_v(SqlexecuteQuery("pk_vid", "org_stockorg_v", "code", json.getString("pk_org")));
+			transformheadvo.setCorpoid(SqlexecuteQuery("pk_corp", "org_corp", "code", json.getString("corpoid")));
+			transformheadvo.setCorpvid(SqlexecuteQuery("pk_vid", "org_corp", "code", json.getString("corpoid")));
+			transformheadvo.setDbilldate(new UFDate(json.getString("dbilldate")));
+			transformheadvo.setVtrantypecode(json.getString("vtrantypecode"));
+			transformheadvo.setCreator(SqlexecuteQuery("cuserid", "sm_user", "user_code", json.getString("creator")));
+			transformheadvo.setCreationtime(new UFDateTime(json.getString("dbilldate")));
+			transformheadvo.setBillmaker(SqlexecuteQuery("cuserid", "sm_user", "user_code", json.getString("creator")));
+			transformheadvo.setDmakedate(new UFDate(json.getString("dbilldate")));
+			transformheadvo.setCtrantypeid(QueryTrantype(json.getString("vtrantypecode"),SqlexecuteQuery("pk_group", "org_group", "code", json.getString("pk_group"))));
+			transformvo.setParentVO(transformheadvo);
+			
+			/**
+			 * 封装表体VO
+			 */
+			JSONArray bodyArray = json.getJSONArray("cspecialbid");
+			int i=0;
+			for (Object Object : bodyArray) {
+				JSONObject bodyObject = JSONObject.fromObject(Object);
+				TransformBodyVO transformbodyvo = new TransformBodyVO();
+				transformbodyvo.setCrowno(bodyObject.getString("crowno"));
+				transformbodyvo.setFbillrowflag(Integer.parseInt(bodyObject.getString("fbillrowflag")));
+				transformbodyvo.setPk_group(SqlexecuteQuery("pk_group", "org_group", "code", bodyObject.getString("pk_group")));
+				transformbodyvo.setPk_org(SqlexecuteQuery("pk_stockorg", "org_stockorg", "code", bodyObject.getString("pk_org")));
+				transformbodyvo.setPk_org_v(SqlexecuteQuery("pk_vid", "org_stockorg_v", "code", bodyObject.getString("pk_org")));
+				transformbodyvo.setCorpoid(SqlexecuteQuery("pk_corp", "org_corp", "code", bodyObject.getString("corpoid")));
+				transformbodyvo.setCorpvid(SqlexecuteQuery("pk_vid", "org_corp", "code", bodyObject.getString("corpoid")));
+				transformbodyvo.setCbodywarehouseid(SqlexecuteQuery("pk_stordoc", "bd_stordoc", "code", bodyObject.getString("cbodywarehouseid")));
+				transformbodyvo.setCmaterialoid(SqlexecuteQuery("pk_source", "bd_material_v", "code", bodyObject.getString("cmaterialoid")));
+				transformbodyvo.setCmaterialvid(SqlexecuteQuery("pk_material", "bd_material", "code", bodyObject.getString("cmaterialoid")));
+				transformbodyvo.setCunitid(SqlexecuteQuery("pk_measdoc", "bd_measdoc", "code", bodyObject.getString("cunitid")));
+				transformbodyvo.setCastunitid(SqlexecuteQuery("pk_measdoc", "bd_measdoc", "code", bodyObject.getString("castunitid")));
+				transformbodyvo.setVchangerate(bodyObject.getString("vchangerate"));
+				transformbodyvo.setNnum(new UFDouble(bodyObject.getString("nnum")));
+				transformbodyvo.setNassistnum(new UFDouble(bodyObject.getString("nassistnum")));
+				transformbodyvo.setNcostprice(new UFDouble(bodyObject.getString("ncostprice")));
+				transformbodyvo.setNcostmny(new UFDouble(bodyObject.getString("ncostmny")));
+				transformbodyvos[i] = transformbodyvo;
+				i++;
+			}
+			transformvo.setChildrenVO(transformbodyvos);
+			
+			ITransformMaitain itransform=(ITransformMaitain)NCLocator.getInstance().lookup(ITransformMaitain.class);
+			itransform.insert(transformvos);
+			IPFBusiAction service = NCLocator.getInstance().lookup(IPFBusiAction.class);
+			service.processAction("APPROVE",
+	                "4N", null, transformvos[0], null, null);
+			out.print(formatRSJsonData("成功","",vbillcode)); 
+			
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			resp.getWriter().write(formatRSJsonData("失败",
+				     e.getMessage().toString(),"").toString());
+			StringWriter stringWriter = new StringWriter();
+			e.printStackTrace(new PrintWriter(stringWriter));
+			//获取详细信息
+			String msg=stringWriter.getBuffer().toString();
+			NcLog.info("接口返回值提示:"+msg);
+		}
+        
+	}
+	
+	/*
+	 * 非空判断
+	 */
+	private void checkJson(JSONObject json) throws Exception {
+		
+		StringBuffer mags = new StringBuffer();
+		Boolean empty = true;
+		
+		String vbillcode = "vbillcode";//单据号
+		String group = "pk_group";//集团编码
+		String creator = "creator";//创建人
+		
+		String body = "cspecialbid";//表体
+ 
+		String[] HeadKey = {vbillcode,group,creator};
+		
+		for (String as : HeadKey) {
+
+			if (json.getString(as).isEmpty()) {
+				empty = false;
+				mags.append("'" + as + "'");
+			}
+		}
+		
+		if (json.getJSONArray(body)==null) {
+			empty = false;
+			mags.append("表体不存在! ");
+		}
+		
+		JSONArray oprepObjectBs = json.getJSONArray("cspecialbid");
+		
+		if (oprepObjectBs == null || oprepObjectBs.size() == 0) {
+			throw new Exception("表体内容不可为空!");
+		}
+		
+		String cmaterialoid = "cmaterialoid";//物料编码
+		
+		for(int i = 0; i < oprepObjectBs.size(); i++) {
+			
+			JSONObject oprepJsonObjectB = oprepObjectBs.getJSONObject(i);
+			String[] BodyKey = {cmaterialoid};
+			int num = i+1;
+			
+			mags.append("第"+num+"块表体:{");
+			for (String as : BodyKey) {
+
+				if (oprepJsonObjectB.getString(as).isEmpty()) {
+					empty = false;
+					mags.append("'" + as + "' ");
+				}
+			}
+			mags.append("}");
+		}
+		
+		if (!empty) {
+			throw new Exception("以下字段不可为空:"+mags);
+		}
+	}
+	
+	/*
+	 * 数据库查询
+	 */
+	private String SqlexecuteQuery(String out,String table,String key,String value) throws Exception {
+		
+		String sql = "select "+out+" from "+table+" where "+key+" = '"+value+"' and nvl(dr,0)=0";
+		
+		Object object;
+			object = iuap.executeQuery(sql, new ColumnProcessor());
+			if (object==null) {
+				throw new DAOException("未查询到数据!请检查编码"+value+"是否正确!");
+			}
+			
+			return object.toString();
+	}
+	
+	/*
+	 * 查询转换类型pk
+	 */
+	private String QueryTrantype(String code,String group) throws Exception {
+		
+		String sql = "select pk_billtypeid from bd_billtype where pk_billtypecode = '"+code+"' and pk_group = '"+group+"' and nvl(dr,0)=0";
+		
+		Object object;
+			object = iuap.executeQuery(sql, new ColumnProcessor());
+			if (object==null) {
+				throw new DAOException("未查询到数据!请检查编码"+code+"是否正确!");
+			}
+			
+			return object.toString();
+	}
+
+}