liyr 11 mesiacov pred
rodič
commit
56edc29806

+ 4 - 0
xc/META-INF/xc.upm

@@ -15,6 +15,10 @@
        <implementation>u8c.impl.CustdocAddImpl</implementation>
  	</component>
  	
+ 	 <component name="custadd" priority="0" singleton="true" remote="true" tx="BMT" supportAlias="true">
+       <implementation>u8c.impl.CustAddImpl</implementation>
+ 	</component>
+ 	
     <component name="demandadd" priority="0" singleton="true" remote="true" tx="BMT" supportAlias="true">
        <implementation>u8c.impl.DemandAddImpl</implementation>
  	</component>

+ 249 - 0
xc/cg/src/private/u8c/impl/CustAddImpl.java

@@ -0,0 +1,249 @@
+package u8c.impl;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+
+import nc.bs.dao.BaseDAO;
+import nc.bs.framework.adaptor.IHttpServletAdaptor;
+import nc.bs.framework.common.InvocationInfoProxy;
+import nc.bs.framework.common.NCLocator;
+import nc.itf.uap.IPKLockBS;
+import nc.itf.uap.IUAPQueryBS;
+import nc.itf.uap.LockableVO;
+import nc.itf.uap.bd.cust.ICustManDocOperate;
+import nc.jdbc.framework.processor.ColumnProcessor;
+import nc.vo.bd.b08.CubasdocVO;
+import nc.vo.bd.b08.CustBasVO;
+import nc.vo.bd.b09.CumandocVO;
+import nc.vo.bd.b09.CustManVO;
+import nc.vo.pub.BusinessException;
+import u8c.bs.servlet.service.BaseServlet;
+import u8c.log.NcLog;
+
+public class CustAddImpl extends BaseServlet implements IHttpServletAdaptor{
+	private  IUAPQueryBS iuap = NCLocator.getInstance().lookup(IUAPQueryBS.class);
+	@Override
+	public void doAction(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+		try {
+			String createStr = buildJson(req, resp, this.getClass().getName());
+			JSONObject json = JSON.parseObject(createStr);
+			//接口返回结果
+			JSONObject returnobj = new JSONObject();
+			//正常返回json
+			JSONArray result = new JSONArray();
+			//报错返回json
+			JSONArray errMessage = new JSONArray();
+			
+			String token =req.getParameter("token");
+			if(!(token!=null && !token.equals("")&&("07a81a68-c60c-4ee4-83dc-25aa51a51497").equals(token))){
+				errMessage.add(formatRSJsonData("失败","请确认通讯密码是否正确!",""));
+				returnobj.put("info", "失败");
+				returnobj.put("errMessage", "请确认通讯密码是否正确!");
+				returnobj.put("result", errMessage);
+				resp.getWriter().write(returnobj.toString());
+				NcLog.info(returnobj.toString());
+				return;
+			}
+			JSONArray jsdata = json.getJSONArray("result");
+			NcLog.info("客商新增开始:" + jsdata);
+			JSONArray resultJSONArray = handle(jsdata);
+			returnobj.put("info", "成功");
+			returnobj.put("errMessage", "");
+			returnobj.put("result", resultJSONArray);
+			resp.getWriter().write(returnobj.toString()); // 返回
+		}  catch (Exception e) {
+			NcLog.info("客商新增报错:" + e.getMessage());
+			JSONArray errMessage = new JSONArray();
+			JSONObject returnobj = new JSONObject();
+			errMessage.add(formatRSJsonData("失败",e.getMessage(),""));
+			returnobj.put("info", "失败");
+			returnobj.put("errMessage", e.getMessage());
+			returnobj.put("result", errMessage);
+			resp.getWriter().write(returnobj.toString()); // 返回
+		}
+		
+	}
+	
+	public JSONArray handle(JSONArray array) throws Exception {
+		JSONArray res = new JSONArray();
+		// 操作员
+		String user = "";
+		try {
+			for (int i = 0; i < array.size(); i++) {
+			
+				JSONObject headjs = array.getJSONObject(i);
+				user = getStringNotNullException(headjs.get("user"), "user");
+				InvocationInfoProxy.getInstance().setUserCode(getUser(user));
+				String corp = getStringNotNullException(headjs.get("corp"), "corp");
+				CubasdocVO cuBasDocVo = getCustvo(headjs);						
+				ICustManDocOperate custManDocOperate = NCLocator.getInstance().lookup(ICustManDocOperate.class);
+				CustManVO custManVO=new CustManVO();
+				CustBasVO cusVos = (CustBasVO) cuBasDocVo.getParentVO();
+				CumandocVO cumandocVO=new CumandocVO();
+				cumandocVO.setCustcode(cusVos.getCustcode());// 客商档案编码
+				cumandocVO.setCustname(cusVos.getCustname());// 客商名称
+				cumandocVO.setCreator(getUser(user));// 制单人
+				cumandocVO.setPk_areacl(cusVos.getPk_areacl());// 区域
+				cumandocVO.setPk_corp(corp);// 公司
+				cumandocVO.setDr(0);
+				cumandocVO.setCustflag("");
+				cumandocVO.setPk_currtype1("00010000000000000001");
+				CumandocVO cumandocVO2=new CumandocVO();
+				cumandocVO2.setCustcode(cusVos.getCustcode());// 客商档案编码
+				cumandocVO2.setCustname(cusVos.getCustname());// 客商名称
+				cumandocVO2.setCreator(getUser(user));// 制单人
+				cumandocVO2.setPk_areacl(cusVos.getPk_areacl());// 区域
+				cumandocVO2.setPk_corp(corp);// 公司
+				cumandocVO2.setDr(0);
+				cumandocVO2.setCustflag("1");
+				custManVO.setChildrenVO(new CumandocVO[]{cumandocVO,cumandocVO2});
+				custManVO.setParentVO(cusVos);
+	
+			    String[] strArray=	custManDocOperate.insertCustMan(custManVO, false);
+				
+				// 返回关键信息:主键&&编码
+				res.add(formatRSJsonData("成功","",cusVos.getCustcode()));
+			}
+			return res;
+		} catch (Exception e) {
+			
+			
+			// 解pk锁,不报错不用解锁
+			IPKLockBS pkbs = NCLocator.getInstance().lookup(IPKLockBS.class);
+			LockableVO[] pkvo = pkbs.getUserLockVOs_RequiresNew(user,
+					InvocationInfoProxy.getInstance().getUserDataSource());
+			if (pkvo != null) {
+				for (int j = 0; j < pkvo.length; j++) {
+					pkbs.releaseLock_RequiresNew(
+							pkvo[j].getLockType() == 1 ? pkvo[j].getLockable() + IPKLockBS.STR_SHARED_LOCK
+									: pkvo[j].getLockable(),
+							user, InvocationInfoProxy.getInstance().getUserDataSource());
+				}
+			}
+			NcLog.info("客商新增报错:" + e);
+			throw new BusinessException("客商新增保存错误:" + e.getMessage());
+		}
+	}
+	
+	/**
+	 * 拼装客商基本档案vo
+	 * 
+	 * @param headjs
+	 * @return
+	 * @throws BusinessException
+	 */
+	private CubasdocVO getCustvo(JSONObject headjs) throws BusinessException {
+		CubasdocVO cuBasDocVo = new CubasdocVO();
+		CustBasVO cusVos = new CustBasVO();
+
+		String user = getStringNotNullException(headjs.get("user"), "user");
+		String custcode = getStringNotNullException(headjs.get("custcode"), "custcode");
+		String custname = getStringNotNullException(headjs.get("custname"), "custname");
+		String areacl = getStringNotNullException(headjs.get("areacl"), "areacl");
+		String corp = getStringNotNullException(headjs.get("corp"), "corp");
+		String custshortname = getStringNotNullException(headjs.get("custshortname"), "custshortname");
+		getpk_cubasdocByCustcode(custcode);//验证客商编码是否存在
+		cusVos.setCustcode(custcode);// 客商档案编码
+		getpk_cubasdocByCustname(custname);//验证客商名称是否存在
+		cusVos.setCustname(custname);// 客商名称
+		getpk_cubasdocByCustshortname(custshortname);//验证客商简称是否存在
+		cusVos.setCustshortname(custshortname);// 客户简称
+		cusVos.setCreator(getUser(user));// 制单人
+		cusVos.setPk_areacl(getAreacl(areacl));// 区域
+		cusVos.setPk_corp("0001");// 公司
+		cusVos.setCustprop(0);// 客商类型
+		cusVos.setDr(0);
+		cuBasDocVo.setParentVO(cusVos);
+		return cuBasDocVo;
+	}
+
+	
+	
+	// 查询客商主键
+    public  String getpk_cubasdocByCustcode(String custcode) throws BusinessException {
+        String sql = "select pk_cubasdoc from bd_cubasdoc  where custcode ='"+custcode+"' and isnull(dr,0) = 0";
+        String pk_cubasdoc = (String) iuap.executeQuery(sql, new ColumnProcessor());
+        if (pk_cubasdoc != null) {
+        	throw new BusinessException("客商编号已经存在:" + custcode);
+        }
+        return pk_cubasdoc;
+    }
+    
+    public  String getpk_cubasdocByCustname(String custname) throws BusinessException {
+        String sql = "select pk_cubasdoc from bd_cubasdoc  where custname ='"+custname+"' and isnull(dr,0) = 0";
+        String pk_cubasdoc = (String) iuap.executeQuery(sql, new ColumnProcessor());
+        if (pk_cubasdoc != null) {
+        	throw new BusinessException("客商名称已经存在:" + custname);
+        }
+        return pk_cubasdoc;
+    }
+    
+    public  String getpk_cubasdocByCustshortname(String custshortname) throws BusinessException {
+        String sql = "select pk_cubasdoc from bd_cubasdoc  where custshortname ='"+custshortname+"' and isnull(dr,0) = 0";
+        String pk_cubasdoc = (String) iuap.executeQuery(sql, new ColumnProcessor());
+        if (pk_cubasdoc != null) {
+        	throw new BusinessException("客商简称已经存在:" + custshortname);
+        }
+        return pk_cubasdoc;
+    }
+    
+
+	/**
+	 * 用户信息查询
+	 * 
+	 * @param cuserid
+	 * @return
+	 * @throws BusinessException
+	 */
+	public String getUser(String code) throws BusinessException {
+		String cuserid = null;
+
+		String sql = " select cuserid from sm_user" + " where user_code  ='" + code + "' and dr =0 ";
+		cuserid = (String) new BaseDAO().executeQuery(sql.toString(), new ColumnProcessor());
+		if (cuserid == null) {
+			throw new BusinessException("U8C不存在当前操作用户:" + code);
+		}
+		return cuserid;
+	}
+	
+	
+	
+	/**
+	 * 查询区域信息
+	 * @param areaclcode
+	 * @return
+	 * @throws BusinessException
+	 */
+	public String getAreacl(String areaclcode) throws BusinessException {
+		String areacl = null;
+		String sql = " select pk_areacl from bd_areacl" + " where areaclcode  ='" + areaclcode + "' and dr =0 ";
+		areacl = (String) new BaseDAO().executeQuery(sql.toString(), new ColumnProcessor());
+		if (areacl == null) {
+			throw new BusinessException("U8C不存在当前区域:" + areaclcode);
+		}
+		return areacl;
+	}
+
+
+	public String getStringNotNullException(Object value, String itemname) throws BusinessException {
+		if (value == null || value.toString().trim().length() == 0) {
+			throw new BusinessException(itemname + "不能为空!");
+		}
+		return value.toString();
+	}
+
+	public String getStringIsNullException(Object value, String itemname) throws BusinessException {
+		if (value == null || value.toString().trim().length() == 0) {
+			return null;
+		}
+		return value.toString();
+	}
+
+}