|
@@ -0,0 +1,138 @@
|
|
|
+package nc.bs.arap.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 com.alibaba.fastjson.JSONObject;
|
|
|
+
|
|
|
+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.yinhe.plugin.GetDataUtil;
|
|
|
+import nc.itf.bd.supplier.baseinfo.ISupplierBaseInfoService;
|
|
|
+import nc.log.NcLog;
|
|
|
+import nc.pub.billcode.itf.IBillcodeManage;
|
|
|
+import nc.vo.bd.supplier.SupplierVO;
|
|
|
+import nc.vo.pub.lang.UFBoolean;
|
|
|
+import nc.vo.pub.lang.UFDateTime;
|
|
|
+import nc.bs.servlet.service.BaseServlet;
|
|
|
+
|
|
|
+public class SupplierMaintainImpl extends BaseServlet implements IHttpServletAdaptor{
|
|
|
+ // 请求名称
|
|
|
+ private String name = "";
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void doAction(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
|
|
+ try {
|
|
|
+ String parameter = buildJson(req, resp, this.getClass().getName());
|
|
|
+ JSONObject arys = JSONObject.parseObject(parameter);
|
|
|
+ name = arys.getString("name");
|
|
|
+ checkJson(arys);
|
|
|
+ NcLog.info("供应商档案:" + parameter);
|
|
|
+ resp.getWriter().write(collect(arys));
|
|
|
+ } catch (Exception e) {
|
|
|
+ //前端控制台打印xml数据
|
|
|
+ resp.getWriter().write(formatData(name,"","0",e.getMessage()==null?e.toString():e.getMessage()));
|
|
|
+ StringWriter stringWriter = new StringWriter();
|
|
|
+ e.printStackTrace(new PrintWriter(stringWriter));
|
|
|
+ //获取详细信息
|
|
|
+ String msg=stringWriter.getBuffer().toString();
|
|
|
+ NcLog.info("供应商档案:"+msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private String collect(JSONObject arys) throws Exception{
|
|
|
+ //登录NCC
|
|
|
+ NCLocator.getInstance().lookup(ISecurityTokenCallback.class).token("NCSystem".getBytes(), "pfxx".getBytes());
|
|
|
+ //设置数据源
|
|
|
+ InvocationInfoProxy.getInstance().setUserDataSource("NCC01");
|
|
|
+ //用户主键
|
|
|
+ String userpk = GetDataUtil.getUser(arys.getString("creator")).getCuserid();
|
|
|
+ InvocationInfoProxy.getInstance().setUserId(userpk);
|
|
|
+ //指定集团pk
|
|
|
+ String grouppk = GetDataUtil.getGroup(arys.getString("group")).getPk_group();
|
|
|
+ InvocationInfoProxy.getInstance().setGroupId(grouppk);
|
|
|
+ //判断是否存在该供应商名称,有返回供应商编码,无调用供应商新增接口返回供应商编码
|
|
|
+ String code = GetDataUtil.queyrFWName(name);
|
|
|
+ if(code != null) {
|
|
|
+ return formatData(name,code,"1","");
|
|
|
+ }else {
|
|
|
+ SupplierVO supplierVO = new SupplierVO();
|
|
|
+ //集团
|
|
|
+ supplierVO.setPk_group(grouppk);
|
|
|
+ //组织
|
|
|
+ supplierVO.setPk_org(grouppk);
|
|
|
+ //创建时间
|
|
|
+ //supplierVO.setCreationtime(new UFDateTime(arys.getString("billDate")));
|
|
|
+ //创建人
|
|
|
+ supplierVO.setCreator(userpk);
|
|
|
+ //分布式
|
|
|
+ supplierVO.setDataoriginflag(0);
|
|
|
+ //启用状态
|
|
|
+ supplierVO.setEnablestate(2);
|
|
|
+ //客户Y
|
|
|
+ supplierVO.setIscustomer(new UFBoolean("N"));
|
|
|
+ //散户N
|
|
|
+ supplierVO.setIsfreecust(new UFBoolean("N"));
|
|
|
+ //外部检测机构N
|
|
|
+ supplierVO.setIsoutcheck(new UFBoolean("N"));
|
|
|
+ //VAT注册码N
|
|
|
+ supplierVO.setIsvat(new UFBoolean("N"));
|
|
|
+ //供应商名称
|
|
|
+ supplierVO.setName(name);
|
|
|
+ //调用编码规则接口获取供应商编码
|
|
|
+ IBillcodeManage iBillcodeManage = NCLocator.getInstance().lookup(IBillcodeManage.class);
|
|
|
+ supplierVO.setCode(iBillcodeManage.getPreBillCode_RequiresNew("supplier", grouppk, grouppk));
|
|
|
+ //国家/地区CN
|
|
|
+ supplierVO.setPk_country(GetDataUtil.getCountryzone("CN").getPk_country());
|
|
|
+ //注册资金币种CNY
|
|
|
+ supplierVO.setPk_currtype(GetDataUtil.getCurrtype("CNY").getPk_currtype());
|
|
|
+ //数据格式ZH-CN
|
|
|
+ supplierVO.setPk_format(GetDataUtil.getFormatDoc("ZH-CN").getPk_formatdoc());
|
|
|
+ //供应商基本分类
|
|
|
+ supplierVO.setPk_supplierclass(GetDataUtil.getSupplierclass(arys.getString("supplierclass")).getPk_supplierclass());
|
|
|
+ //时区
|
|
|
+ supplierVO.setPk_timezone(GetDataUtil.getTimezone("P0800").getPk_timezone());
|
|
|
+ //供应商类型
|
|
|
+ supplierVO.setSupprop(0);
|
|
|
+ //供应商状态
|
|
|
+ supplierVO.setSupstate(1);
|
|
|
+ ISupplierBaseInfoService iSupplierBaseInfoService = NCLocator.getInstance().lookup(ISupplierBaseInfoService.class);
|
|
|
+ SupplierVO supplierVOs = iSupplierBaseInfoService.insertSupplierVO(supplierVO, true);
|
|
|
+ return formatData(name,supplierVOs.getCode(),"2","");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 非空判断
|
|
|
+ */
|
|
|
+ private void checkJson(JSONObject arys) throws Exception {
|
|
|
+
|
|
|
+ StringBuffer mags = new StringBuffer();
|
|
|
+
|
|
|
+ String group = "group";//集团编码
|
|
|
+ String name = "name";//供应商名称
|
|
|
+ String supplierclass = "supplierclass";//供应商基本分类
|
|
|
+ String creator = "creator";//创建人
|
|
|
+
|
|
|
+ String[] HeadKey = {group,name,supplierclass,creator};
|
|
|
+
|
|
|
+ for (String as : HeadKey) {
|
|
|
+
|
|
|
+ if (arys.getString(as) == null || arys.getString(as).isEmpty()) {
|
|
|
+ mags.append("'" + as + "'");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (mags.length()!=0) {
|
|
|
+ throw new Exception("以下字段不可为空:"+mags);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|