|
@@ -6,24 +6,19 @@ import java.io.ByteArrayOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.io.InputStreamReader;
|
|
|
-import java.io.OutputStreamWriter;
|
|
|
import java.io.PrintWriter;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
-import java.util.Calendar;
|
|
|
-import java.util.Date;
|
|
|
import java.util.Properties;
|
|
|
-import java.util.UUID;
|
|
|
-
|
|
|
import javax.servlet.ServletException;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.owasp.esapi.ESAPI;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
import nc.bcmanage.bs.IBusiCenterManageService;
|
|
|
import nc.pubitf.erm.expenseaccount.IinsertLog_RequiresNew;
|
|
|
-import nc.bs.arap.api.psapitool.WuYePSApiUtil;
|
|
|
import nc.bs.dao.BaseDAO;
|
|
|
import nc.bs.framework.adaptor.IHttpServletAdaptor;
|
|
|
import nc.bs.framework.common.InvocationInfoProxy;
|
|
@@ -32,14 +27,11 @@ import nc.bs.framework.comn.NetStreamContext;
|
|
|
import nc.bs.framework.server.ISecurityTokenCallback;
|
|
|
import nc.itf.uap.print.IPrintEntry;
|
|
|
import nc.jdbc.framework.processor.BeanProcessor;
|
|
|
-import nc.net.servlet.IReturnStatus;
|
|
|
import nc.pub.sap.constant.SapConstants;
|
|
|
+import nc.pubimpl.erm.expenseaccount.InsertLog_RequiresNewImpl;
|
|
|
import nc.pubitf.para.SysInitQuery;
|
|
|
import nc.vo.erm.bgyimageconfig.BgyimageconfigVO;
|
|
|
-import nc.vo.esb.EsbInfoVO;
|
|
|
-import nc.vo.esb.QueryInfoVO;
|
|
|
-import nc.vo.esb.ResultEsbVO;
|
|
|
-import nc.vo.esb.ResultVO;
|
|
|
+import nc.vo.erm.image.ImageTMLogVO;
|
|
|
import nc.vo.pub.BusinessException;
|
|
|
import nccloud.base.reflect.NCClass;
|
|
|
import nccloud.dto.arap.arappub.PrintDataInfo;
|
|
@@ -59,23 +51,22 @@ import nccloud.vo.platform.print.LightPrintTemplateHelper;
|
|
|
|
|
|
public class NccToImage implements IHttpServletAdaptor {
|
|
|
private static Properties _prop = new Properties();
|
|
|
-
|
|
|
@Override
|
|
|
public void doAction(HttpServletRequest request, HttpServletResponse response)
|
|
|
throws ServletException, IOException {
|
|
|
- String rsdata = null;
|
|
|
- ResultEsbVO<ResultVO> esb = new ResultEsbVO<ResultVO>();
|
|
|
- ResultVO result = new ResultVO();
|
|
|
- result.setResult("");
|
|
|
- esb.setResultInfo(result);
|
|
|
-
|
|
|
String appcode = request.getParameter("appcode");//"20080PBM408";
|
|
|
String Oids = request.getParameter("Oids");//"1001H8100000000DU0K2";
|
|
|
+
|
|
|
+ try {
|
|
|
+ Thread.sleep(3 * 1000);
|
|
|
+ } catch (InterruptedException e2) {
|
|
|
+ }
|
|
|
+
|
|
|
try {
|
|
|
+ initInvocationInfo();
|
|
|
// TODO Auto-generated method stub
|
|
|
// 获取请求参数,
|
|
|
//URLhttp://127.0.0.1/service/~erm/nc.impl.erm.servlet.bgywy.NccToImage?appcode=20080EBM410&Oids=1001H9100000000A34KT
|
|
|
- initInvocationInfo();
|
|
|
BgyimageconfigVO imconfig = new BgyimageconfigVO();
|
|
|
try {
|
|
|
//通过表erm_bgyimageconfig,查询出打印相关参数
|
|
@@ -83,10 +74,8 @@ public class NccToImage implements IHttpServletAdaptor {
|
|
|
imconfig = queryImageConfig(appcode);
|
|
|
} catch (BusinessException e1) {
|
|
|
// TODO Auto-generated catch block
|
|
|
- throw new BusinessException(e1.getMessage());
|
|
|
+ ExceptionUtils.wrapBusinessException(e1.getMessage());
|
|
|
}
|
|
|
- if(null==imconfig)
|
|
|
- throw new BusinessException("未能根据appcode找到对应的打印模板,请检查erm_bgyimageconfig表");
|
|
|
//String Nodekey = imconfig.getTranstype(); // 交易类型,"F1-Cxx-W04";// request.getParameter("Nodekey");
|
|
|
String PrintServiceModule = imconfig.getModule();// 模块名,"arap";// request.getParameter("PrintServiceModule");
|
|
|
String PrintServiceName = imconfig.getServicename();// 打印服务类全路径"nccloud.pubimpl.arap.arappub.ArapPrintService";
|
|
@@ -96,6 +85,8 @@ public class NccToImage implements IHttpServletAdaptor {
|
|
|
PrintDataInfo ArApPrintinfo = new PrintDataInfo();
|
|
|
PrintInfo ErmPrintinfo = new PrintInfo();
|
|
|
PrintInfo PuPrintinfo = new PrintInfo();
|
|
|
+ PrintInfo IcPrintinfo = new PrintInfo();
|
|
|
+
|
|
|
ByteArrayOutputStream print = new ByteArrayOutputStream();
|
|
|
IPrintEntry printEntry = LightPrintTemplateHelper.getPrintEntry();
|
|
|
if (PrintServiceModule.equals("arap")) {
|
|
@@ -135,9 +126,21 @@ public class NccToImage implements IHttpServletAdaptor {
|
|
|
PuPrintinfo.setNodeKey(NodeKey);
|
|
|
printEntry.exportPdf(getPrintService(PuPrintinfo).getDataSources(PuPrintinfo), PrintTemplateID, print);
|
|
|
};
|
|
|
+ if (PrintServiceModule.equals("ic")) {
|
|
|
+ IcPrintinfo.setAppcode(appcode);
|
|
|
+ IcPrintinfo.setIds(new String[] { Oids });
|
|
|
+ IcPrintinfo.setNodeKey("print");
|
|
|
+ NCClass printServiceClazz = new NCClass();
|
|
|
+ printServiceClazz.setModule(PrintServiceModule);
|
|
|
+ printServiceClazz.setName(PrintServiceName);
|
|
|
+ IcPrintinfo.setPrintServiceClazz(printServiceClazz);
|
|
|
+ IcPrintinfo.setPrintTemplateID(PrintTemplateID);
|
|
|
+ //IcPrintinfo.setNodeKey(NodeKey);
|
|
|
+ printEntry.exportPdf(getPrintService(IcPrintinfo).getDataSources(IcPrintinfo), PrintTemplateID, print);
|
|
|
+ };
|
|
|
// 下载输出
|
|
|
|
|
|
-
|
|
|
+
|
|
|
InputStream in = new ByteArrayInputStream(print.toByteArray());
|
|
|
PrintWriter out = null;
|
|
|
try {
|
|
@@ -159,66 +162,51 @@ public class NccToImage implements IHttpServletAdaptor {
|
|
|
out.close();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- result.setCode(IReturnStatus.SUCCEED);// 成功
|
|
|
- result.setMessage("打开成功");
|
|
|
- createResultEsbVO(esb);
|
|
|
- esb.setResultInfo(result);
|
|
|
} catch (Exception e) {
|
|
|
// TODO Auto-generated catch block
|
|
|
-
|
|
|
-
|
|
|
try {
|
|
|
- String err = getExceptionDetail(e);
|
|
|
-
|
|
|
- JSONObject errjson = new JSONObject();
|
|
|
- errjson.put("err", err);
|
|
|
- result.setCode(IReturnStatus.ERROR);// 异常
|
|
|
- result.setError(errjson.toString());
|
|
|
- result.setMessage(result.getError());
|
|
|
- createResultEsbVO(esb);// 初始化响应对象
|
|
|
- esb.getEsbInfo().setReturnStatus(IReturnStatus.ESB_ERROR);
|
|
|
- esb.getEsbInfo().setReturnMsg("异常");
|
|
|
- esb.setResultInfo(result);// 设置响应内容
|
|
|
- NCLocator.getInstance().lookup(IinsertLog_RequiresNew.class).insertImageLog_RequiresNew(Oids, appcode, null, errjson, "IMAGE_NCCFM_VIEW");
|
|
|
-
|
|
|
+ String a =getExceptionDetail(e);
|
|
|
+ JSONObject err = new JSONObject();
|
|
|
+ err.put("err", a);
|
|
|
+ insertImageLog(Oids, appcode, null, err, "IMAGE_NCCFM_VIEW");
|
|
|
} catch (BusinessException e1) {
|
|
|
// TODO Auto-generated catch block
|
|
|
- JSONObject errjson = new JSONObject();
|
|
|
- errjson.put("err", e1);
|
|
|
- result.setCode(IReturnStatus.ERROR);// 异常
|
|
|
- result.setError(errjson.toString());
|
|
|
- result.setMessage(result.getError());
|
|
|
- createResultEsbVO(esb);// 初始化响应对象
|
|
|
- esb.getEsbInfo().setReturnStatus(IReturnStatus.ESB_ERROR);
|
|
|
- esb.getEsbInfo().setReturnMsg("异常");
|
|
|
- esb.setResultInfo(result);// 设置响应内容
|
|
|
+ e1.printStackTrace();
|
|
|
}
|
|
|
- }finally {
|
|
|
- rsdata = com.alibaba.fastjson.JSONObject.toJSONString(esb);
|
|
|
- sendResponse(response, rsdata);
|
|
|
}
|
|
|
}
|
|
|
//登陆信息
|
|
|
- private void initInvocationInfo() throws BusinessException {
|
|
|
+ private void initInvocationInfo() {
|
|
|
try {
|
|
|
+ IBusiCenterManageService busiCenterManageService=NCLocator.getInstance().lookup(IBusiCenterManageService.class);
|
|
|
+ String[] datasources=busiCenterManageService.getAvailableBusiCenterDsNames();
|
|
|
+ //由于UAT环境与生产的数据源不一致
|
|
|
+ String ds="NCCDATA";//生产环境数据源:NCCDATA
|
|
|
+ for (int i = 0; i < datasources.length; i++) {
|
|
|
+ if (datasources[i].equals("NCCDATA"))
|
|
|
+ {
|
|
|
+ ds="NCCDATA";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ ds="ncclcdata";//连测环境数据源:ncclcdata
|
|
|
+ }
|
|
|
+ InvocationInfoProxy.getInstance().setUserDataSource(ds);
|
|
|
//InvocationInfoProxy.getInstance().setGroupId(SysInitQuery.getParaString("GLOBLE00000000000000", "GROUP"));
|
|
|
//InvocationInfoProxy.getInstance().setUserId(SysInitQuery.getParaString("GLOBLE00000000000000", "ITFUSER"));
|
|
|
- InputStream in = NccToImage.class.getResourceAsStream("login_message.properties");
|
|
|
- BufferedReader bf = new BufferedReader(new InputStreamReader(in));
|
|
|
- _prop.load(bf);
|
|
|
- //IBusiCenterManageService busiCenterManageService=NCLocator.getInstance().lookup(IBusiCenterManageService.class);
|
|
|
-// InvocationInfoProxy.getInstance().setUserDataSource(busiCenterManageService.getAvailableBusiCenterDsNames()[0]);
|
|
|
- InvocationInfoProxy.getInstance().setUserDataSource( _prop.getProperty("userDataSource") );
|
|
|
- InvocationInfoProxy.getInstance().setGroupId(_prop.getProperty("pkGroup"));
|
|
|
- InvocationInfoProxy.getInstance().setUserId(_prop.getProperty("userId"));
|
|
|
+// InputStream in = NccToImage.class.getResourceAsStream("login_message.properties");
|
|
|
+// BufferedReader bf = new BufferedReader(new InputStreamReader(in));
|
|
|
+// _prop.load(bf);
|
|
|
+// InvocationInfoProxy.getInstance().setGroupId(_prop.getProperty("pkGroup"));
|
|
|
+// InvocationInfoProxy.getInstance().setUserId(_prop.getProperty("userId"));
|
|
|
+ InvocationInfoProxy.getInstance().setGroupId("0001H810000000000HS2");
|
|
|
+ InvocationInfoProxy.getInstance().setUserId("NC_USER0000000000000");
|
|
|
ISecurityTokenCallback tc = NCLocator.getInstance().lookup(ISecurityTokenCallback.class);
|
|
|
byte[] token = tc.token("__system".getBytes(), "NC".getBytes());
|
|
|
NetStreamContext.setToken(token);
|
|
|
} catch (Exception e) {
|
|
|
// TODO Auto-generated catch block
|
|
|
- throw new BusinessException(e.getMessage());
|
|
|
-
|
|
|
+ ExceptionUtils.wrapBusinessException(e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -226,9 +214,8 @@ public class NccToImage implements IHttpServletAdaptor {
|
|
|
* 获取打印服务
|
|
|
* @param info
|
|
|
* @return
|
|
|
- * @throws BusinessException
|
|
|
*/
|
|
|
- private AbstractPrintService getPrintService(IPrintInfo info) throws BusinessException {
|
|
|
+ private AbstractPrintService getPrintService(IPrintInfo info) {
|
|
|
Object instance = null;
|
|
|
try {
|
|
|
Class<?> clazz = info.getPrintServiceClazz().load();
|
|
@@ -242,7 +229,7 @@ public class NccToImage implements IHttpServletAdaptor {
|
|
|
service = (AbstractPrintService) instance;
|
|
|
|
|
|
} else {
|
|
|
- throw new BusinessException("找不到打印服务!");
|
|
|
+ ExceptionUtils.wrapBusinessException("找不到打印服务!");
|
|
|
}
|
|
|
|
|
|
return service;
|
|
@@ -282,47 +269,20 @@ public class NccToImage implements IHttpServletAdaptor {
|
|
|
return stringBuffer.toString();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
- * 生成ESB响应对象
|
|
|
- * @param esb
|
|
|
- */
|
|
|
- public static void createResultEsbVO(ResultEsbVO esb){
|
|
|
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
|
|
|
- EsbInfoVO esbInfo=new EsbInfoVO();
|
|
|
- QueryInfoVO queryInfo=new QueryInfoVO();
|
|
|
- Date date=Calendar.getInstance().getTime();//获取当前时间
|
|
|
- //设置响应时间
|
|
|
- esbInfo.setInstId(UUID.randomUUID().toString());//使用UUID作为流水号
|
|
|
- esbInfo.setRequestTime(dateFormat.format(Calendar.getInstance().getTime()));//设置请求开始时间
|
|
|
- esbInfo.setResponseTime(dateFormat.format(date));//设置响应时间
|
|
|
- esbInfo.setReturnStatus(IReturnStatus.ESB_SUCCEED);//默认响应成功
|
|
|
- esbInfo.setReturnCode(IReturnStatus.ESB_SUCCEED_CODE);//默认成功code
|
|
|
- esbInfo.setReturnMsg("成功");//默认响应成功提示
|
|
|
- esb.setEsbInfo(esbInfo);
|
|
|
- esb.setQueryInfo(queryInfo);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 发送响应信息
|
|
|
- * @param response
|
|
|
- * @param esb
|
|
|
- */
|
|
|
- private void sendResponse(final HttpServletResponse response, String jsondata) {
|
|
|
- PrintWriter out = null;
|
|
|
- try {
|
|
|
- response.setHeader("Content-type", "application/json;charset=UTF-8");
|
|
|
- out = new PrintWriter(new OutputStreamWriter(response.getOutputStream(), "UTF-8"));
|
|
|
- out.write(jsondata);
|
|
|
- out.flush();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } finally {
|
|
|
- if (out != null) {
|
|
|
- out.close();
|
|
|
- }
|
|
|
+ public void insertImageLog(String billid, String billcode, JSONObject send, JSONObject result, String urlcode) throws BusinessException {
|
|
|
+ String code = result.getString("code");
|
|
|
+ ImageTMLogVO log = new ImageTMLogVO();
|
|
|
+ log.setBillid(billid);
|
|
|
+ log.setBillno(billcode);
|
|
|
+ log.setTm_content(JSONObject.toJSONString(send));
|
|
|
+ log.setTm_result(JSONObject.toJSONString(result));
|
|
|
+ log.setApicode(urlcode);
|
|
|
+ if(!StringUtils.isBlank(code) && "200".equals(code)) {
|
|
|
+ log.setTm_status("S");
|
|
|
+ } else {
|
|
|
+ log.setTm_status("F");
|
|
|
}
|
|
|
+ // 插入日志表
|
|
|
+ new BaseDAO().insertVO(log);
|
|
|
}
|
|
|
}
|