|
@@ -0,0 +1,392 @@
|
|
|
+package nc.bs.ic.impl;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.PrintWriter;
|
|
|
+import java.io.StringWriter;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+import javax.servlet.ServletException;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+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.uap.IUAPQueryBS;
|
|
|
+import nc.jdbc.framework.processor.ColumnProcessor;
|
|
|
+import nc.jdbc.framework.processor.MapListProcessor;
|
|
|
+import nc.log.NcLog;
|
|
|
+import nc.vo.pub.BusinessException;
|
|
|
+import net.sf.json.JSONArray;
|
|
|
+import net.sf.json.JSONObject;
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * 查询NC单据状态返回给MES
|
|
|
+ * @author Administrator
|
|
|
+ *
|
|
|
+ */
|
|
|
+
|
|
|
+public class IntoBillStatusImpl extends BaseServlet implements IHttpServletAdaptor{
|
|
|
+
|
|
|
+
|
|
|
+ private IUAPQueryBS iuap = null;
|
|
|
+
|
|
|
+
|
|
|
+ private IUAPQueryBS getIuap() {
|
|
|
+ if (this.iuap == null) {
|
|
|
+ this.iuap = NCLocator.getInstance().lookup(IUAPQueryBS.class);
|
|
|
+ }
|
|
|
+ return this.iuap;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void doAction(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
|
|
+
|
|
|
+ NcLog.initUI("查询NC单据状态开始","status");
|
|
|
+ List<JSONObject> pljf = new ArrayList<JSONObject>();
|
|
|
+ NCLocator.getInstance().lookup(ISecurityTokenCallback.class).token("NCSystem".getBytes(),"pfxx".getBytes());
|
|
|
+ try {
|
|
|
+ String createStr = buildJson(req, resp, this.getClass().getName());
|
|
|
+ JSONObject json = JSONObject.fromObject(createStr);
|
|
|
+ PrintWriter out = resp.getWriter();
|
|
|
+ String tddtp = json.getString("tddtp");//表名
|
|
|
+ pljf = itSo(tddtp);
|
|
|
+// checkJson(json);//非空判断
|
|
|
+// InvocationInfoProxy.getInstance().setGroupId("0001V5100000000006BX");
|
|
|
+// InvocationInfoProxy.getInstance().setUserId(SqlexecuteQuery("cuserid", "sm_user", "user_code", json.getString("creator")));
|
|
|
+// out.print(formatRSJsonData("成功","",tddtp));
|
|
|
+
|
|
|
+ out.print(pljf);
|
|
|
+
|
|
|
+ } 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.initUI("接口返回值提示:"+msg,"status");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public List<JSONObject> itSo(String tddtp ){
|
|
|
+ List<JSONObject> pljf = new ArrayList<JSONObject>();
|
|
|
+ JSONObject jsonObj = new JSONObject();
|
|
|
+ String tablename=null;
|
|
|
+ String pkname=null;
|
|
|
+ boolean billType=false;//是否有审批流,默认为否
|
|
|
+ try {
|
|
|
+ if (tddtp.equals("saleorder")) {//销售订单
|
|
|
+ tablename="so_saleorder";
|
|
|
+ pkname="csaleorderid";
|
|
|
+ pljf = getDrJson(tablename,pkname,true,0);
|
|
|
+ }else if (tddtp.equals("delivery")) {//发货单/退货单
|
|
|
+ tablename="so_delivery";
|
|
|
+ pkname="cdeliveryid";
|
|
|
+ pljf = getDrJson(tablename,pkname,true,0);
|
|
|
+ }else if (tddtp.equals("saleout")) {//销售出库单-发货指示书
|
|
|
+ tablename="ic_saleout_h";
|
|
|
+ pkname="cgeneralhid";
|
|
|
+ pljf = getDrJson(tablename,pkname,billType,1);
|
|
|
+ }else if (tddtp.equals("shapechange")) {//形态转换单
|
|
|
+ tablename="ic_transform_h";
|
|
|
+ pkname="cspecialhid ";
|
|
|
+ pljf = getDrJson(tablename,pkname,true,1);
|
|
|
+ }else if (tddtp.equals("finprodin")) {// 产成品入库单
|
|
|
+ tablename="ic_finprodin_h";
|
|
|
+ pkname="cgeneralhid";
|
|
|
+ pljf = getDrJson(tablename,pkname,billType,1);
|
|
|
+ }else if (tddtp.equals("matout")) {// 材料进出库单
|
|
|
+ tablename="ic_material_h";
|
|
|
+ pkname="cgeneralhid";
|
|
|
+ pljf = getDrJson(tablename,pkname,billType,1);
|
|
|
+ }else if (tddtp.equals("generalout")) {//其他出库单
|
|
|
+ tablename="ic_generalout_h";
|
|
|
+ pkname="cgeneralhid";
|
|
|
+ pljf = getDrJson(tablename,pkname,billType,1);
|
|
|
+ }else if (tddtp.equals("wboxin")) {//其他入库单
|
|
|
+ tablename="ic_generalin_h";
|
|
|
+ pkname="cgeneralhid";
|
|
|
+ pljf = getDrJson(tablename,pkname,billType,1);
|
|
|
+ }else if (tddtp.equals("whstrans")) {// 转库单
|
|
|
+ tablename="ic_whstrans_h";
|
|
|
+ pkname="cspecialhid";
|
|
|
+ pljf = getDrJson(tablename,pkname,true,1);
|
|
|
+ }else if (tddtp.equals("locadjust")) {// 库存货位调整单
|
|
|
+ tablename="ic_locadjust_h";
|
|
|
+ pkname="cgeneralhid";
|
|
|
+ pljf = getDrJson(tablename,pkname,billType,1);
|
|
|
+ }else if (tddtp.equals("freightinner")) {// 采购发票-内外销运费
|
|
|
+ tablename="po_invoice";
|
|
|
+ pkname="pk_invoice";
|
|
|
+ pljf = getDrJson(tablename,pkname,billType,1);
|
|
|
+ }else {
|
|
|
+ jsonObj.put(tddtp, "请确认查询参数" + tddtp + "是否正确!");
|
|
|
+ pljf.add(jsonObj);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ jsonObj.put("同步状态错误:",e.getMessage());
|
|
|
+ pljf.add(jsonObj);
|
|
|
+ }
|
|
|
+ return pljf;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 以单据号为凭证的同步数据转态回传
|
|
|
+ * @param tablename 表名
|
|
|
+ * @param pkname 主键名
|
|
|
+ * @param billType 是否有审批流,默认为否
|
|
|
+ * @param flagType 0:fstatusflag,1:fbillflag
|
|
|
+ * @return
|
|
|
+ * @throws BusinessException
|
|
|
+ */
|
|
|
+ public List<JSONObject> getDrJson(String tablename,String pkname,boolean billType,int flagType) throws BusinessException{
|
|
|
+ List<JSONObject> pljf = new ArrayList<JSONObject>();
|
|
|
+ JSONObject jsonObj = new JSONObject();
|
|
|
+ String sql=null;
|
|
|
+ if(billType==false){
|
|
|
+ sql="select "+pkname+",vbillcode,dr,vdef20 from "+tablename+" where dr=1 and vdef20='6' ";
|
|
|
+ }else{
|
|
|
+ if(flagType==0){
|
|
|
+ sql="select "+pkname+",vbillcode,fstatusflag,dr,vdef20 from "+tablename+
|
|
|
+ " where nvl(dr,0)=0 and vdef20='6' and fstatusflag in (2,8) or dr=1 and vdef20='6' or dr=1 and vdef20='7' ";
|
|
|
+ }else if(flagType==1){
|
|
|
+ sql="select "+pkname+",vbillcode,fbillflag as fstatusflag,dr,vdef20 from "+tablename+
|
|
|
+ " where nvl(dr,0)=0 and vdef20='6' and fbillflag in (3,4) or dr=1 and vdef20='6' or dr=1 and vdef20='7' ";
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ List<Map<String, String>> pl = (List<Map<String, String>>) getIuap()
|
|
|
+ .executeQuery(sql, null,new MapListProcessor());
|
|
|
+ for (int i = 0; i < pl.size(); i++) {
|
|
|
+ Map<String, String> map = pl.get(i);
|
|
|
+ Set<String> keys = map.keySet();
|
|
|
+ jsonObj = new JSONObject();
|
|
|
+ String pkid=null;
|
|
|
+ String vbillcode=null;
|
|
|
+ String fstatusflag=null;
|
|
|
+ String dr=null;
|
|
|
+ String vdef20=null;
|
|
|
+ for (String key : keys) {
|
|
|
+ if(key.equals(pkname)){
|
|
|
+ pkid= map.get(key);
|
|
|
+ }else if(key.equals("vbillcode")){
|
|
|
+ vbillcode=String.valueOf(map.get(key));
|
|
|
+ }else if(key.equals("fstatusflag")){
|
|
|
+ fstatusflag=String.valueOf(map.get(key));
|
|
|
+ }else if(key.equals("dr")){
|
|
|
+ dr=String.valueOf(map.get(key));
|
|
|
+ }else if(key.equals("vdef20")){
|
|
|
+ vdef20=String.valueOf(map.get(key));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //状态回传后设值为7,删除传值为8
|
|
|
+ try {
|
|
|
+ String uds=null;
|
|
|
+ if(vdef20.equals("7")&&dr.equals("1")||vdef20.equals("6")&&dr.equals("1")){
|
|
|
+ uds ="update "+tablename+" set vdef20='8' " + " where "+pkname+"='"+pkid+"'";
|
|
|
+ }else{
|
|
|
+ uds ="update "+tablename+" set vdef20='7' " + " where "+pkname+"='"+pkid+"'";
|
|
|
+ }
|
|
|
+// getIuap().executeQuery(uds, null);
|
|
|
+ } catch (Exception e2) {
|
|
|
+ }
|
|
|
+ if(billType==false){
|
|
|
+ jsonObj.put("status","4");
|
|
|
+ jsonObj.put("vbillcode",vbillcode);
|
|
|
+ jsonObj.put("message","同步NC单据已删除!");
|
|
|
+ pljf.add(jsonObj);
|
|
|
+ }else{
|
|
|
+ if(flagType==0){
|
|
|
+ if(fstatusflag.equals("2")){
|
|
|
+ jsonObj.put("status","2");
|
|
|
+ jsonObj.put("vbillcode",vbillcode);
|
|
|
+ jsonObj.put("message","同步NC单据已审批!");
|
|
|
+ pljf.add(jsonObj);
|
|
|
+ }else if(fstatusflag.equals("8")){
|
|
|
+ jsonObj.put("status","3");
|
|
|
+ jsonObj.put("vbillcode",vbillcode);
|
|
|
+ jsonObj.put("message","同步NC单据审批未通过!");
|
|
|
+ pljf.add(jsonObj);
|
|
|
+ }
|
|
|
+ if(dr.equals("1")){
|
|
|
+ jsonObj.put("status","4");
|
|
|
+ jsonObj.put("vbillcode",vbillcode);
|
|
|
+ jsonObj.put("message","同步NC单据已删除!");
|
|
|
+ pljf.add(jsonObj);
|
|
|
+ }
|
|
|
+ }else if(flagType==1){
|
|
|
+ if(fstatusflag.equals("4")){
|
|
|
+ jsonObj.put("status","2");
|
|
|
+ jsonObj.put("vbillcode",vbillcode);
|
|
|
+ jsonObj.put("message","同步NC单据已审批!");
|
|
|
+ pljf.add(jsonObj);
|
|
|
+ }else if(fstatusflag.equals("3")){
|
|
|
+ jsonObj.put("status","3");
|
|
|
+ jsonObj.put("vbillcode",vbillcode);
|
|
|
+ jsonObj.put("message","同步NC单据审批未通过!");
|
|
|
+ pljf.add(jsonObj);
|
|
|
+ }
|
|
|
+ if(dr.equals("1")){
|
|
|
+ jsonObj.put("status","4");
|
|
|
+ jsonObj.put("vbillcode",vbillcode);
|
|
|
+ jsonObj.put("message","同步NC单据已删除!");
|
|
|
+ pljf.add(jsonObj);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return pljf;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 以Id为凭证的同步数据状态回传
|
|
|
+ * @param tablename 表名
|
|
|
+ * @return
|
|
|
+ * @throws BusinessException
|
|
|
+ */
|
|
|
+ public List<JSONObject> getDrJsonById(String tablename) throws BusinessException{
|
|
|
+ List<JSONObject> pljf = new ArrayList<JSONObject>();
|
|
|
+ JSONObject jsonObj = new JSONObject();
|
|
|
+ String sql="select vdef19 from "+tablename+" where dr=1 and vdef20='6' ";
|
|
|
+ List<Map<String, String>> pl = (List<Map<String, String>>) getIuap()
|
|
|
+ .executeQuery(sql, null,new MapListProcessor());
|
|
|
+ for (int i = 0; i < pl.size(); i++) {
|
|
|
+ Map<String, String> map = pl.get(i);
|
|
|
+ Set<String> keys = map.keySet();
|
|
|
+ jsonObj = new JSONObject();
|
|
|
+ String id=null;
|
|
|
+ for (String key : keys) {
|
|
|
+ if(key.equals("vdef19")){
|
|
|
+ id= map.get(key);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //状态回传后设值为2
|
|
|
+ try {
|
|
|
+ String uds ="update "+tablename+" set vdef20='2' " +
|
|
|
+ " where vdef19='"+id+"'";
|
|
|
+// getIuap().executeQuery(uds, null);
|
|
|
+ } catch (Exception e2) {
|
|
|
+ }
|
|
|
+ jsonObj.put("status","4");
|
|
|
+ jsonObj.put("vbillcode",id);
|
|
|
+ jsonObj.put("message","同步NC单据已删除!");
|
|
|
+ pljf.add(jsonObj);
|
|
|
+ }
|
|
|
+ return pljf;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 非空判断
|
|
|
+ */
|
|
|
+ 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;
|
|
|
+ try {
|
|
|
+ object = getIuap().executeQuery(sql, new ColumnProcessor());
|
|
|
+ if (object==null) {
|
|
|
+ throw new Exception("未查询到数据!请检查编码"+value+"是否正确!");
|
|
|
+ }
|
|
|
+
|
|
|
+ return object.toString();
|
|
|
+ } catch (BusinessException e) {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ e.printStackTrace();
|
|
|
+ return e.getMessage();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|