瀏覽代碼

批次号档案接口

pancy 1 年之前
父節點
當前提交
f7f073d7a9

+ 23 - 0
scmpub/.classpath

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" output="scmpub/classes" path="scmpub/src/public"/>
+	<classpathentry kind="src" output="scmpub/classes" path="scmpub/src/client"/>
+	<classpathentry kind="src" output="scmpub/classes" path="scmpub/src/private"/>
+	<classpathentry kind="src" output="scmpub/classes" path="scmpub/src/test"/>
+	<classpathentry kind="src" output="scmpub/classes" path="scmpub/resources"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="con" path="com.yonyou.studio.udt.core.container/Ant_Library"/>
+	<classpathentry kind="con" path="com.yonyou.studio.udt.core.container/Product_Common_Library"/>
+	<classpathentry kind="con" path="com.yonyou.studio.udt.core.container/Middleware_Library"/>
+	<classpathentry kind="con" path="com.yonyou.studio.udt.core.container/Framework_Library"/>
+	<classpathentry kind="con" path="com.yonyou.studio.udt.core.container/Module_Public_Library"/>
+	<classpathentry kind="con" path="com.yonyou.studio.udt.core.container/Module_Client_Library"/>
+	<classpathentry kind="con" path="com.yonyou.studio.udt.core.container/Module_Private_Library">
+		<accessrules>
+			<accessrule kind="accessible" pattern="**"/>
+		</accessrules>
+	</classpathentry>
+	<classpathentry kind="con" path="com.yonyou.studio.udt.core.container/Module_Lang_Library"/>
+	<classpathentry kind="con" path="com.yonyou.studio.udt.core.container/Generated_EJB"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

+ 25 - 0
scmpub/.project

@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>scmpub</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>com.yonyou.studio.udt.core.builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>com.yonyou.studio.udt.core.nature</nature>
+		<nature>com.yonyou.studio.ria.core.ModuleProjectNature</nature>
+		<nature>com.yonyou.studio.ria.core.BizCompProjectNature</nature>
+	</natures>
+</projectDescription>

+ 7 - 0
scmpub/META-INF/module.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="gb2312"?>
+<module name="scmpub">
+    <public>
+    </public>
+    <private>
+    </private>
+</module>

+ 9 - 0
scmpub/META-INF/scmservice.upm

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding='gb2312'?>
+<module name="scmpub">
+    <!--Åú´ÎºÅµµ°¸½Ó¿Ú-->
+     <public>
+ 	   <component name="batchcodeadd" accessProtected="false"  remote="true" singleton="true" tx="NONE" supportAlias="true">
+       <implementation>nc.bs.scmpub.impl.BatchCodeAddImpl</implementation>
+ 	   </component>
+    </public>
+</module>

+ 23 - 0
scmpub/bin/.project

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>scmpub</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>com.yonyou.studio.udt.core.builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>com.yonyou.studio.udt.core.nature</nature>
+	</natures>
+</projectDescription>

+ 7 - 0
scmpub/bin/META-INF/module.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="gb2312"?>
+<module name="scmpub">
+    <public>
+    </public>
+    <private>
+    </private>
+</module>

+ 21 - 0
scmpub/manifest.xml

@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Manifest>
+  <BusinessComponet name="scmpub" dispname="scmpub">
+    <public>
+      <src name="src/public"/>
+    </public>
+    <client>
+      <src name="src/client"/>
+    </client>
+    <private>
+      <src name="src/private"/>
+    </private>
+    <test>
+      <src name="src/test"/>
+    </test>
+    <resource>
+      <src name="resources"/>
+    </resource>
+    <funnodes/>
+  </BusinessComponet>
+</Manifest>

二進制
scmpub/scmpub/classes/nc/bs/scmpub/impl/BatchCodeAddImpl.class


二進制
scmpub/scmpub/classes/nc/bs/servlet/test/service/BaseServlet.class


二進制
scmpub/scmpub/classes/nc/pub/test/util/DataSourceUtil.class


二進制
scmpub/scmpub/classes/nc/test/log/NcLog.class


+ 1 - 0
scmpub/scmpub/resources/resources.gitkeep

@@ -0,0 +1 @@
+ユシホサキ�

+ 1 - 0
scmpub/scmpub/src/client/client.gitkeep

@@ -0,0 +1 @@
+ユシホサキ�

+ 168 - 0
scmpub/scmpub/src/private/nc/bs/scmpub/impl/BatchCodeAddImpl.java

@@ -0,0 +1,168 @@
+package nc.bs.scmpub.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.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.test.service.BaseServlet;
+import nc.impl.scmf.ic.mbatchcode.BatchcodeMaintainImpl;
+import nc.itf.scmf.ic.mbatchcode.IBatchcodeMaintainService;
+import nc.itf.uap.IUAPQueryBS;
+import nc.jdbc.framework.processor.ColumnProcessor;
+import nc.pub.test.util.DataSourceUtil;
+import nc.vo.bd.meta.BatchOperateVO;
+import nc.vo.ecpubapp.pattern.exception.ExceptionUtils;
+import nc.vo.pub.BusinessException;
+import nc.vo.pub.lang.UFDate;
+import nc.vo.scmf.ic.mbatchcode.BatchcodeVO;
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+
+//批次号档案接口
+public class BatchCodeAddImpl 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 自动生成的方法存根
+		try {
+			DataSourceUtil.setDataSource();
+			InvocationInfoProxy.getInstance().setGroupId(this.qryGroup());
+			NCLocator.getInstance().lookup(ISecurityTokenCallback.class).token("NCSystem".getBytes(),"pfxx".getBytes());
+			String createStr = buildJson(req, resp, this.getClass().getName());
+			JSONObject json = JSONObject.fromObject(createStr);
+			JSONArray results = json.getJSONArray("results");
+			PrintWriter out = resp.getWriter();
+			StringBuffer returnstr = new StringBuffer();
+			for(int i=0;i<results.size();i++){
+				JSONObject obj = (JSONObject) results.get(i);
+				String checkresult = checkJson(obj);//非空判断
+				if(!(checkresult.equals("")||checkresult.equals(null))){
+					returnstr.append("第"+i+"条记录"+checkresult+";");
+					continue;
+				}
+				String vbatchcode = obj.getString("vbatchcode");
+				BatchOperateVO operatevo = new BatchOperateVO();
+				BatchcodeVO[] vos = new BatchcodeVO[1];
+				BatchcodeVO batchcodevo = new BatchcodeVO();
+				batchcodevo.setVbatchcode(vbatchcode);
+				batchcodevo.setCmaterialoid(SqlexecuteQuery("pk_material", "bd_material", "code", obj.getString("cmaterialoid")));
+				batchcodevo.setCmaterialvid(SqlexecuteQuery("pk_source", "bd_material", "code", obj.getString("cmaterialoid")));
+				batchcodevo.setDinbounddate(new UFDate(obj.getString("dinbounddate")));
+				batchcodevo.setDproducedate(new UFDate(obj.getString("dproducedate")));
+				batchcodevo.setDvalidate(new UFDate(obj.getString("dvalidate")));
+				batchcodevo.setPk_group(this.qryGroup());
+				vos[0] = batchcodevo;
+				operatevo.setAddObjs(vos);
+				BatchcodeMaintainImpl impl = new BatchcodeMaintainImpl();
+				impl.batchSave(operatevo);
+				returnstr.append("第"+i+"条记录成功,批次号为"+vbatchcode+";");
+			}
+			resp.getWriter().write(formatRSJsonData("成功",
+					returnstr.toString(),"").toString());
+			return;
+		} catch (BusinessException e) {
+			// TODO 自动生成的 catch 块
+			resp.getWriter().write(formatRSJsonData("失败",
+				     e.getMessage().toString(),"").toString());
+			StringWriter stringWriter = new StringWriter();
+			e.printStackTrace(new PrintWriter(stringWriter));
+			//获取详细信息
+			String msg=stringWriter.getBuffer().toString();
+		} catch (Exception e) {
+			// TODO 自动生成的 catch 块
+			resp.getWriter().write(formatRSJsonData("失败",
+				     e.getMessage().toString(),"").toString());
+			StringWriter stringWriter = new StringWriter();
+			e.printStackTrace(new PrintWriter(stringWriter));
+			//获取详细信息
+			String msg=stringWriter.getBuffer().toString();
+		}
+	}
+
+	/*
+	 * 非空判断
+	 */
+	private String checkJson(JSONObject json) throws Exception {
+		
+		StringBuffer mags = new StringBuffer();
+		Boolean empty = true;
+		
+		String vbatchcode = "vbatchcode";//批次号
+		String cmaterialoid = "cmaterialoid";//物料编码
+		String dinbounddate = "dinbounddate";//首次入库日期
+		String dproducedate = "dproducedate";//生产日期
+		String dvalidate = "dvalidate";//失效日期
+ 
+		String[] HeadKey = {vbatchcode,cmaterialoid,dinbounddate,dproducedate,dvalidate};
+		
+		for (String as : HeadKey) {
+
+			if (json.getString(as).isEmpty()) {
+				empty = false;
+				mags.append("'" + as + "'");
+			}
+		}
+		
+		if (!empty) {
+			return "以下字段不可为空:"+mags;
+		}
+		return "";
+	}
+	
+	/**
+	 * 数据库查询
+	 * @param out
+	 * @param table
+	 * @param key
+	 * @param value
+	 * @return
+	 * @throws Exception
+	 */
+	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 and enablestate = '2' and latest = 'Y'";
+		
+		Object object;
+		try {
+			object = iuap.executeQuery(sql, new ColumnProcessor());
+			if (object==null) {
+				throw new Exception("未查询到数据!请检查编码"+value+"是否正确!");
+			}
+			
+			return object.toString();
+		} catch (BusinessException e) {
+			// TODO Auto-generated catch block
+			ExceptionUtils.wrappBusinessException(e.getMessage());
+			return e.getMessage();
+		}
+	}
+
+	
+	/**
+	 * 获取集团id
+	 * @return
+	 */
+	private String qryGroup() {
+		String qrysql = "select pk_group from org_group where nvl(dr,0)=0 and rownum = 1";
+		String pk_group;
+		try {
+			pk_group = (String) iuap.executeQuery(qrysql, new ColumnProcessor());
+			return pk_group;
+		} catch (BusinessException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		return null;
+	}
+}

+ 85 - 0
scmpub/scmpub/src/private/nc/bs/servlet/test/service/BaseServlet.java

@@ -0,0 +1,85 @@
+package nc.bs.servlet.test.service;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+
+
+import org.codehaus.jettison.json.JSONException;
+
+import uap.json.JSONObject;
+
+/**
+ * 提供一些公共方法
+ * 具体业务请在实际服务类实现
+ */
+public class BaseServlet {
+
+	public static String STATUS_SUCCESS ="success";
+	public static String STATUS_FAILURE ="fail";
+
+	/**
+	 * 格式化传入的数据,JSON化在具体服务类实现
+	 * @param req
+	 * @param resp
+	 * @param 类名
+	 * @return
+	 * @throws ServletException
+	 * @throws IOException
+	 */
+	protected String buildJson(HttpServletRequest req,
+							   HttpServletResponse resp, String classname)
+			throws ServletException, IOException {
+		req.setCharacterEncoding("UTF-8");
+		/* 设置格式为text/json */
+		resp.setContentType("text/json");
+		/* 设置字符集为'UTF-8' */
+		resp.setCharacterEncoding("UTF-8");
+		String reqJsonData = null;
+		// 接收流
+		BufferedReader reader = new BufferedReader(new InputStreamReader(
+				req.getInputStream(), "UTF-8"));
+		StringBuffer jsonStr = new StringBuffer();
+		try {
+			String line = "";
+			while ((line = reader.readLine()) != null) {
+				jsonStr.append(line);
+			}
+			if (jsonStr != null && !"".equals(jsonStr.toString())) {
+				reqJsonData = jsonStr.toString();
+//				PrLogger.error(new UFDateTime(System.currentTimeMillis()).toString()
+//						+ "客户端传入:" + classname + "~~" + reqJsonData);
+			} else {
+				throw new ServletException("传入的数据不合法!");
+			}
+		} catch (IOException e) {
+			throw new IOException("数据读取失败" + e.getMessage());
+		} finally {
+			reader.close();
+		}
+		return reqJsonData;
+	}
+
+
+
+	/**
+	 * 格式返回json数据
+	 *
+	 * @return
+	 * @throws JSONException
+	 * @throws Exception
+	 */
+	public static JSONObject formatRSJsonData(String status,String error,String message){
+		JSONObject rs = new JSONObject();
+		rs.put("status", status);
+		rs.put("message", message);
+		rs.put("error", error);
+		return rs;
+	}
+	
+}

+ 47 - 0
scmpub/scmpub/src/private/nc/pub/test/util/DataSourceUtil.java

@@ -0,0 +1,47 @@
+package nc.pub.test.util;
+
+import nc.bcmanage.bs.IBusiCenterManageService;
+import nc.bcmanage.vo.BusiCenterVO;
+import nc.bs.framework.common.InvocationInfoProxy;
+import nc.bs.framework.common.NCLocator;
+import nc.test.log.NcLog;
+import nc.vo.pub.BusinessException;
+
+public class DataSourceUtil {
+	
+	
+	
+	/**
+	 * 
+	 * 设置NC数据源
+	 * 
+	 */
+	public static void setDataSource() throws BusinessException{
+	   BusiCenterVO[] centerVOs = getBusiCenterVOs();
+	   if (centerVOs != null && centerVOs.length > 0) {
+	   // 设置数据源,默认只有一个账套
+	  InvocationInfoProxy.getInstance().setUserDataSource(
+	  centerVOs[0].getDataSourceName());//设置数据源----第一条数据
+	  NcLog.initUI("查询数据源名称为:"+centerVOs[0].getDataSourceName(),"status");
+	  NcLog.initUI("查询数据源名称为:"+centerVOs[1].getDataSourceName(),"status");
+     }
+   }
+	
+	
+
+	/**
+	 * 
+	 * 获取当前所有数据源
+	 * 
+	 */
+	
+	  private static BusiCenterVO[] getBusiCenterVOs() throws BusinessException{
+          IBusiCenterManageService service = NCLocator.getInstance().lookup(
+                      IBusiCenterManageService.class);
+       
+          BusiCenterVO[]   centerVOs = service.getBusiCenterVOs();
+       
+          return centerVOs;
+	  }
+
+}

+ 158 - 0
scmpub/scmpub/src/private/nc/test/log/NcLog.java

@@ -0,0 +1,158 @@
+package nc.test.log;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import nc.bs.framework.common.RuntimeEnv;
+
+import org.apache.log4j.Logger;
+/**
+ * nclog
+ * @author YY
+ * @datetime 2021-9-29 
+ */
+public class NcLog
+{
+  private static final Logger logger = Logger.getLogger(NcLog.class);
+  private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+  private static SimpleDateFormat format$ = new SimpleDateFormat("yyyy-MM-dd");
+
+ 
+  public static void initUI(String str){
+	  info(str);
+  }
+  
+  public static void initUI(String str,String logname){
+	  info2(str,logname);
+  }
+  
+  
+  public static void info(String str)
+  {
+    String logFilePath = getLogFile();
+    File file = new File(logFilePath);
+    BufferedWriter fos = null;
+    try
+    {
+      fos = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, true)));
+      str = format.format(new Date()) + " " + str + "\r\n";
+      
+      fos.write(str + "\r\n");
+      fos.flush();
+    }
+    catch (Exception localException)
+    {
+      if (fos != null)
+        try
+        {
+          fos.close();
+        }
+        catch (IOException localIOException)
+        {
+        }
+    }
+    finally {
+      if (fos != null)
+        try
+        {
+          fos.close();
+        }
+        catch (IOException localIOException2)
+        {
+        }
+    }
+  }
+  
+  
+  
+  
+  public static void info2(String str,String logname)
+  {
+    String logFilePath = getLogFile(logname);
+    File file = new File(logFilePath);
+    BufferedWriter fos = null;
+    try
+    {
+      fos = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, true)));
+      str = format.format(new Date()) + " " + str + "\r\n";
+      
+      fos.write(str + "\r\n");
+      fos.flush();
+    }
+    catch (Exception localException)
+    {
+      if (fos != null)
+        try
+        {
+          fos.close();
+        }
+        catch (IOException localIOException)
+        {
+        }
+    }
+    finally {
+      if (fos != null)
+        try
+        {
+          fos.close();
+        }
+        catch (IOException localIOException2)
+        {
+        }
+    }
+  }
+
+  private static String getLogFile() {
+    String destFileFolder = RuntimeEnv.getInstance().getNCHome() + File.separator + "mancLog" + File.separator + format$.format(new Date());
+    String destFilePath = destFileFolder + File.separator + "org.log";
+    File destFolder = new File(destFileFolder);
+    if (!destFolder.exists()) {
+      destFolder.mkdirs();
+    }
+    File destFile = new File(destFilePath);
+    if (!destFile.exists()) {
+      try
+      {
+        destFile.createNewFile();
+      }
+      catch (Exception e)
+      {
+        logger.info(e);
+      }
+    }
+    return destFilePath;
+  }
+  
+  
+  private static String getLogFile(String logname) {
+	    String destFileFolder = RuntimeEnv.getInstance().getNCHome() + File.separator + "mancLog" + File.separator + format$.format(new Date());
+	    String destFilePath = destFileFolder + File.separator + logname + ".log" ;
+	    File destFolder = new File(destFileFolder);
+	    if (!destFolder.exists()) {
+	      destFolder.mkdirs();
+	    }
+	    File destFile = new File(destFilePath);
+	    if (!destFile.exists()) {
+	      try
+	      {
+	        destFile.createNewFile();
+	      }
+	      catch (Exception e)
+	      {
+	        logger.info(e);
+	      }
+	    }
+	    return destFilePath;
+	  }
+  
+  
+  
+  
+  
+  
+}

+ 1 - 0
scmpub/scmpub/src/public/public.gitkeep

@@ -0,0 +1 @@
+ユシホサキ�

+ 1 - 0
scmpub/scmpub/src/test/test.gitkeep

@@ -0,0 +1 @@
+ユシホサキ�