nc/ncc 接口集成 附件上传下载

2 篇文章 0 订阅
1 篇文章 0 订阅

nc 65 接口集成附件上传


/**
 * 附件上传
 * @author xl
 *
 */
public class UpFileServlet extends HttpServlet{
	private static final long serialVersionUID = 2752936832927872870L;
	private static final String UTF8 = "text/json;charset=utf-8";
	
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		JSONObject response = new JSONObject();
		JSONObject Response = new JSONObject();
		 req.setCharacterEncoding("UTF-8");
		resp.setHeader("Content-Type", UTF8);
		PrintWriter out = resp.getWriter();
		ISecurityTokenCallback sc = NCLocator.getInstance().lookup(ISecurityTokenCallback.class);
		sc.token("NCSystem".getBytes(), "pfxx".getBytes());
		
		
		JSONObject rebillObject = CommonApiUtil.getJsonData(req);
		
		String  creator = rebillObject.getString("user");
		String  billid = rebillObject.getString("billid");
		String filename = rebillObject.getString("filename");
		String filetype = rebillObject.getString("filetype");
		String file = rebillObject.getString("file");
		
		
		
		
		JSONArray psnArray = new JSONArray();
		
		//附件的创建人
		String  user = null;
		try {
			//判断用户是否存在,不存在返回错误信息
			
			
			//判断单据是否存在
			String isentBill =  (String)NCLocator.getInstance().lookup(IUAPQueryBS.class).executeQuery("select pk_entryapply from  hi_entryapply where pk_entryapply='"+billid+"' ", new ColumnProcessor());
			if(null==isentBill || isentBill.isEmpty()){
				String isstaBill =  (String)NCLocator.getInstance().lookup(IUAPQueryBS.class).executeQuery("select pk_hi_stapply from  hi_stapply where pk_hi_stapply='"+billid+"' ", new ColumnProcessor());
				if(null == isstaBill || isstaBill.isEmpty()){
					throw new BusinessException("单据不存在,无法上传附件!");
				}
				
			}
			
			
			byte[] destBuffer = new sun.misc.BASE64Decoder().decodeBuffer(file);
		    InputStream stream = new ByteArrayInputStream(destBuffer);
			String fileName = filename+filetype;
			//调用附件上传服务
			FileStorageClient fsclient = FileStorageClient.getInstance();
			FileHeader header = fsclient.uploadFile( IAttachManageConst.RIAMoudleID, fileName, stream, false, new IFileStorageExt[0]);
			if (header != null) {
				String pk_doc = header.getPath();
				
				
				String name = header.getName();
				long size1 = header.getFileSize().longValue();
				NCFileVO attach = new NCFileVO();
				attach.setPath(name);
				attach.setCreator(user);
				attach.setIsdoc("z");
				attach.setFileLen(size1);
				attach.setPk_doc(pk_doc);
				IFileSystemService fsysService = NCLocator.getInstance().lookup(IFileSystemService.class);
				fsysService.createCloudFileNode(billid, user, attach);
				response.put("filepk", pk_doc);
			}
				
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
//			e.printStackTrace();
			
		}
		out.print(Response);
		out.flush();
		out.close();
		
	}
	
	/***
	 * 上传文件
	 * 
	 * @param fileName
	 * @param billpk
	 * @param input
	 * @throws BusinessException
	 */
	private void upLoad(String fileName, String billpk, InputStream input) throws BusinessException {
//		Random random = new Random(6);
//		String r = String.valueOf(random.nextInt()).replace("-", "");
//		fileName = fileName.replace(".", "_".concat(r).concat("."));
		FileStorageClient fsclient = FileStorageClient.getInstance();
		FileHeader header = fsclient.uploadFile(IAttachManageConst.RIAMoudleID, fileName, input, false, new IFileStorageExt[0]);
		if (header != null) {
			String pk_doc = header.getPath();
			String name = header.getName();
			long size1 = header.getFileSize().longValue();
			NCFileVO attach = new NCFileVO();
			attach.setPath(name);
			attach.setCreator("");
			attach.setIsdoc("z");
			attach.setFileLen(size1);
			attach.setPk_doc(pk_doc);
			getService().createCloudFileNode(billpk + "/" + fileName, "", attach);
		}
	}
	
	private IFileSystemService service = null;
	private IFileSystemService getService() {
		if (service == null) {
			service = NCLocator.getInstance().lookup(IFileSystemService.class);
		}
		return service;
	}
	
}

附件查询下载


/**
 * 附件查询 
 * @author xuelin
 *
 */
public class FileQueryServlet extends HttpServlet{
	private static final long serialVersionUID = 2752936832927872870L;
	private static final String UTF8 = "text/json;charset=utf-8";
	
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		JSONObject response = new JSONObject();
		JSONObject Response = new JSONObject();
		 req.setCharacterEncoding("UTF-8");
		resp.setHeader("Content-Type", UTF8);
		PrintWriter out = resp.getWriter();
		ISecurityTokenCallback sc = NCLocator.getInstance().lookup(ISecurityTokenCallback.class);
		sc.token("NCSystem".getBytes(), "pfxx".getBytes());
		
		IUAPQueryBS bs = NCLocator.getInstance().lookup(IUAPQueryBS.class);
		
		JSONObject rebillObject = CommonApiUtil.getJsonData(req);
		
		String  pk = rebillObject.getString("billid");        //单据主键
		String name = rebillObject.getString("billtype"); //单据类型
		String creator = rebillObject.getString("user");//附件创建人
		
		try {
			
			if(null==pk || null==name || null==creator){
				
				throw new BusinessException("附件信息为空,请确认!");
			}
			
			StringBuffer fileSql =new StringBuffer();
			fileSql.append(" select substr(bap_fs_header.name,0,instr(bap_fs_header.name,'.')-1) as name, substr(bap_fs_header.name,instr(bap_fs_header.name,'.')+1) as type , ");
			fileSql.append(" sm_pub_filesystem.pk_doc, sm_user.user_name,bap_fs_header.filesize ");
			fileSql.append(" from  sm_pub_filesystem left join bap_fs_header on sm_pub_filesystem.pk_doc=bap_fs_header.path ");
			fileSql.append(" left join sm_user on bap_fs_header.creator=sm_user.cuserid");
			fileSql.append(" where sm_pub_filesystem.filepath like '%"+pk+"%' and sm_pub_filesystem.pk_doc is not null");
//			if(null !=creator){
			if(!creator.isEmpty()){
//				fileSql.append(" and bap_fs_header.creator='"+creator+"' ");
				fileSql.append(" and bap_fs_header.creator=(select  cuserid from sm_user where user_code='"+creator+"') ");
				
			}
			
			List<Map<String,String>> file = (List<Map<String,String>>)bs.executeQuery(fileSql.toString(), new MapListProcessor());
			
			JSONArray fileArray = new JSONArray();
			if(null!=file && file.size()>0){
				// 返回信息
//				(1)附件名称
//				(2)附件类型
//				(3)附件主键
//				(4)单据主键
//				(5)文件的所有者
//				(6)文件大小(精确字节数,企微预览下载使用)
				for(Map<String,String> map : file){
					
					JSONObject fileObj = new JSONObject();
					fileObj.put("billid", pk);
					fileObj.put("filename", map.get("name"));
					fileObj.put("filetype", map.get("type"));
					fileObj.put("pk_doc", map.get("pk_doc"));
//					fileObj.put("user_name", map.get("user_name"));
					fileObj.put("filesize", map.get("filesize"));
					fileObj.put("creator", creator);
					
					//附件GET下载的地址
					String fileUrl = null;
					try{
						
						FileStorageClient fileClient =FileStorageClient.getInstance();
//						fileUrl = fileClient.getDownloadURL("uapattachroot", map.get("pk_doc"), "http://10.32.224.112:8086/");
						fileUrl = fileClient.getDownloadURL("uapattachroot", map.get("pk_doc"));
					}catch(Exception e ){
						throw new BusinessException(e.getMessage());
//						e.printStackTrace();
						
					}
					fileObj.put("fileUrl", fileUrl);
					fileArray.add(fileObj);
				}

				
			}

		} catch (Exception e) {
			// TODO Auto-generated catch block
//			e.printStackTrace();

		}
		out.print(Response);
		out.flush();
		out.close();
		
	}
	
	
}
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
NCC restful是指在NCC(New Century Corporation)框架中使用的一种RESTful风格的架构。根据提供的引用内容,可以了解到在NCC框架中,需要进行一系列的配置和文件添加才能实现NCC restful的功能。 首先,在当前模块的META-INF目录下,需要创建一个.rest文件,并在该文件中添加相应的配置信息,包括指定一个资源(resource)的类名和相关的额外信息。这样可以将该资源与restful服务关联起来。 其次,在nchome中的modules目录下,对应的业务模块的META-INF目录中需要添加occ.rest文件。同样地,开发项目中也是在项目对应的META-INF目录下添加该文件。这样可以在NCC框架中识别和加载restful服务。 此外,对于NCC restful的处理,NCC框架中有一个Restful对应的Servlet,即uap.ws.rest.servlet.UAPRSServerServlet,它用于处理一些环境变量,如token、usercode、datasource等。另外,还有一个UAPRestJaxRsApplication类用于处理应用程序级别的参数,并在第一次调用servlet时进行初始化。通过这些配置和处理,可以实现NCC框架中的restful功能。 综上所述,NCC restful是指在NCC框架中使用的一种RESTful风格的架构,需要进行相应的配置和文件添加以实现其功能。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [NCC restful接口笔记](https://blog.csdn.net/csh_on_route/article/details/121675243)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [NC65实现Restful接口开发及调试](https://blog.csdn.net/u010741112/article/details/116265784)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [NCC-OpenAPI示例文档.zip](https://download.csdn.net/download/liuhuizhong123/12326527)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值