两个项目间的附件交互

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<t:base type="jquery,easyui,tools,DatePicker"></t:base>


  <t:formvalid    formid="formobj" dialog="true" usePlugin="password" layout="table"  action="decMainController.do?fasong_lida&id=${ldcOrderPage.id }&type=${type }&meu=${meu }&btn=${btn }" beforeSubmit="fun_tel();">
  <input type="hidden" name="mydata" id="mydata" />
  
  </t:formvalid>

<div class="easyui-layout" fit="true">
  <div region="center" style="padding:0px;border:0px">
  <t:datagrid name="tSAttachmentList" checkbox="true" pagination="true" onClick="fun_tel(rowIndex,rowData)" fitColumns="true" title="附件表" actionUrl="tSAttachmentController.do?datagrid1&orderno=${ldcOrderPage.id }" idField="id" fit="true" queryMode="group">
   <t:dgCol title="ID"  field="id"  hidden="true"  queryMode="group"  width="120"></t:dgCol>
     
    <t:dgCol title="发送状态"  field="fstats" formatterjs="fujianfs"    queryMode="group"  width="120"  ></t:dgCol>
    <t:dgCol title="业务编号"  field="note" hidden="true"  queryMode="group"  width="120"  ></t:dgCol>
   <t:dgCol title="类型"  field="ftype"  queryMode="group"  width="120" hidden="true" ></t:dgCol>
   <t:dgCol title="字类型名称"  field="subtype"  queryMode="group" hidden="true"  width="120"></t:dgCol>
   <t:dgCol title="附件内容"  field="attachmentcontent" hidden="true"   queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="附件名称"  field="attachmenttitle"    queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="业务类主键"  field="businesskey"  queryMode="group"  width="120" hidden="true" ></t:dgCol>
   <t:dgCol title="扩展名"  field="extend"  queryMode="group"  width="120"></t:dgCol>
   <t:dgCol title="附件路径"  field="realpath"  downloadName="下载"  queryMode="group"  width="120"  ></t:dgCol>
   <t:dgCol title="子类名称全路径"  field="subclassname"  queryMode="group"  width="120" hidden="true" ></t:dgCol>
   <t:dgCol title="swf格式路径"  field="swfpath"  queryMode="group"  width="120" hidden="true" ></t:dgCol>
   <t:dgCol title="外键"  field="fid"  queryMode="group"  width="120" hidden="true" ></t:dgCol>
   <t:dgCol title="外表名"  field="ftable"  queryMode="group"  width="120" hidden="true" ></t:dgCol>
   <t:dgCol title="用户"  field="userid"  dictionary="t_s_base_user,id,username"     queryMode="single" width="120"></t:dgCol>
   <t:dgCol title="上传时间"  field="ctime"  formatter="yyyy-MM-dd"  hidden="true"  queryMode="group"  width="120"></t:dgCol>
   <t:dgCol title="创建名称"  field="createName"  queryMode="single"  width="120" hidden="true" ></t:dgCol>
   <t:dgCol title="创建人登陆名称"  field="createBy"  queryMode="single"  width="120"  hidden="true"></t:dgCol>
   <t:dgCol title="创建日期"  field="createDate" formatter="yyyy-MM-dd"  queryMode="group"  width="120" ></t:dgCol>
   <t:dgCol title="更新人名称"  field="updateName"  queryMode="single"  width="120" hidden="true" ></t:dgCol>
   <t:dgCol title="更新人登陆名称"  field="updateBy"  queryMode="single"  width="120" hidden="true" ></t:dgCol>
   <t:dgCol title="更新日期"  field="updateDate"  queryMode="single"  width="120" hidden="true" ></t:dgCol>
   <t:dgCol title="所属部门"  field="sysOrgCode"  queryMode="single"  width="120" hidden="true" ></t:dgCol>
   <t:dgCol title="所属公司"  field="sysCompanyCode"  queryMode="single"  width="120" hidden="true" ></t:dgCol>
  <%-- <t:dgCol title="操作" field="opt" width="100" hidden="true" ></t:dgCol>
   <t:dgDelOpt title="删除" url="tSAttachmentController.do?doDel&id={id}" urlclass="ace_button"  urlfont="fa-trash-o"/>
    <t:dgToolBar title="录入" icon="icon-add" url="tSAttachmentController.do?goAdd" funname="add"></t:dgToolBar>
   <t:dgToolBar title="编辑" icon="icon-edit" url="tSAttachmentController.do?goUpdate" funname="update"></t:dgToolBar>
   <t:dgToolBar title="批量删除"  icon="icon-remove" url="tSAttachmentController.do?doBatchDel" funname="deleteALLSelect"></t:dgToolBar>--%>
  <%--  <t:dgToolBar title="查看" icon="icon-search" url="tSAttachmentController.do?goUpdate" funname="detail"></t:dgToolBar>
   <t:dgToolBar title="发送" icon="icon-search" url="ldcOrderController.do?fasong1" funname="fasong"></t:dgToolBar> --%>
   <%-- <t:dgToolBar title="导入" icon="icon-put" funname="ImportXls"></t:dgToolBar>
   <t:dgToolBar title="导出" icon="icon-putout" funname="ExportXls"></t:dgToolBar>
   <t:dgToolBar title="模板下载" icon="icon-putout" funname="ExportXlsByT"></t:dgToolBar>--%>
  </t:datagrid>
  </div>
 </div> <script src = "webpage/com/jeecg/decmain/decMainList.js"></script>			
 <script type="text/javascript">
 function	fujianfs(value,row,index){
	 console.log(value)
	  if(value=='1'){
		return "<span style='color:#00BB00'>已发送</span>";
	}else{
		return "<span style='color:red'>未发送</span>";
	}

}

 //批量发送
 function fun_tel(rowIndex,rowData) {
	 
	    var rows = $("#tSAttachmentList").datagrid('getSelections');
	  
	   $("#mydata").val(JSON.stringify(rows));
	}
 
 
 $(document).ready(function(){
 });
 
   
 
//导入
function ImportXls() {
	openuploadwin('Excel导入', 'tSAttachmentController.do?upload', "tSAttachmentList");
}

//导出
function ExportXls() {
	JeecgExcelExport("tSAttachmentController.do?exportXls","tSAttachmentList");
}

//模板下载
function ExportXlsByT() {
	JeecgExcelExport("tSAttachmentController.do?exportXlsByT","tSAttachmentList");
}

 </script>

首先调用发送接口发送

@RequestMapping(params = "fasong_lida")
@ResponseBody
public AjaxJson fasong_lida(HttpServletRequest request) throws Exception {
	String jsonStr = request.getParameter("mydata");
	AjaxJson j = new AjaxJson();
	String message = "";
	String type = request.getParameter("type");
	String meu = request.getParameter("meu");
	String btn = request.getParameter("btn");
	String id = request.getParameter("id");
	
	message = "发送成功";
	HashMap<String, InputStream> maplist = new HashMap<String, InputStream>();
	InputStream in = null;
	try {
		LdcGoodsAppEntity decmain = systemService.getEntity(LdcGoodsAppEntity.class, id);
		
		List<TSAttachmentEntity> list = JSON.parseArray(jsonStr, TSAttachmentEntity.class);
		
		message = decMainService.toLida_lida(decmain, list, message, request);
		
		if(message.equals("发送成功")) {
			if (StringUtil.isNotEmpty(meu)) {
				
				if (meu.equals("1")) {
					
					ldcCommonStateService.first_sendlida(id);
				}
				
				if (meu.equals("3")) {
					
					ldcCommonStateService.thrid_sendlidaSystem(id);
				}
			}
		}
		// }
	} catch (Exception e) {
		e.printStackTrace();
		message = "发送失败";
		throw new BusinessException(e.getMessage());
	}
	
	j.setMsg(message);
	return j;
}

然后调用方法,先把数据发送给另一个项目,判断是否发送成功,成功则将附件放在阿里云上映射一个地址保存到另一个项目中

public String toLida_lida(LdcGoodsAppEntity decmain,List<TSAttachmentEntity> list,String message,HttpServletRequest request){
		LdcGoodsAppEntity decmainnew =new LdcGoodsAppEntity();
		TSUser user = ResourceUtil.getSessionUser();
		 JSONObject json1 = new JSONObject();
		try {
			decmainnew.setCreateDate(null);
			decmainnew.setUpdateDate(null);
			MyBeanUtils.copyBeanNotNull2Bean(decmain,decmainnew);
			
// 			LdcGoodsAppEntity decmainpage = JSONObject.parseObject(decmain.toString(), LdcGoodsAppEntity.class);
			
			 String sq = "SELECT typecode,typename from t_s_type \n" + 
				 "where typegroupid=(select id from t_s_typegroup where typegroupcode='companycode')";
		 List<Map<String,Object>> queryForList = jdbcTemplate.queryForList(sq);
		 
		 decmainnew.setSysOrgCode("");	//清空部门
		 json1.put("companycode", queryForList.get(0).get("typecode").toString());
		 json1.put("username", user.getRealName());
		 json1.put("ldcGoodsapp", decmainnew);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	
// 		Object obj=  GsonUtil.toJson(decmainnew);//将对象转化为json格式对象

		
		String token = Connect.getToken_lida("test","123456");
		if(token.equals("")){
			message = "发送失败,请检查网络";
		}else{
			message = "发送成功";
			
			JSONObject jsonobject=  tolidaguanwu_lida(token, json1.toJSONString());
// 			JSONObject data = jsonobject.getJSONObject("data");
			//String content =data.getString("content");
			
			
			//mobanlist
			TSDepart tsdepart = new TSDepart();
			String departname = "";
			List listdepart = new ArrayList<>();
			JSONObject json = null;
			String str = null;
			StringBuilder stringBuilder2 = null;
			String id = oConvertUtils.getString(user.getId());
			TSBaseUser tsbaseUser = systemService.getEntity(TSBaseUser.class,id);
			List<String> departlist = jdbcTemplate.queryForList("select org_id from t_s_user_org where user_id = ?", String.class,id);
			System.out.println(departlist  + "departlist");
			for(int i = 0 ; i < departlist.size() ; i++) {
				String departid = departlist.get(i).toString();
				tsdepart = systemService.getEntity(TSDepart.class,departid);
				departname = tsdepart.getDepartname();
				listdepart.add(departname);
			}
			
			
			if(StringUtil.isNotEmpty(jsonobject)){
				//订单成功
				if(jsonobject.get("context").equals("发送成功")){
					if(list.size()!=0){
						Vector<File> file = new Vector<File>() ;
						for(int i=0;i<list.size();i++)
						{
							if(!list.get(i).getFstats().equals("1")){
								//腾讯云附件
								String cosFilePath = "/test/"+list.get(i).getNote()+"/"+list.get(i).getRealpath().split("/")[list.get(i).getRealpath().split("/").length-1];
								
								String localFilePath1 = request.getRealPath("/")+list.get(i).getRealpath();
								JSONObject getFileResult= QCloudUtils.upload(cosFilePath,localFilePath1);
								//服务器附件信息传输
								
								if(getFileResult.get("message").equals("SUCCESS")){
									list.get(i).setRealpath(getFileResult.getJSONObject("data").get("source_url").toString());
									list.get(i).setUpdateDate(null);
									// list.get(i).setCreateDate(null);
									
									SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
									Object obj1=  GsonUtil.toJson(list.get(i));//将对象转化为json格式对象
									JSONObject jsonObject1 = JSONObject.parseObject(obj1.toString());//转化为json对象
									System.out.println("shuju:"+jsonObject1 );
									//附件传输成功
									//再次获取服务器token
									token = Connect.getToken_lida("test","123456");
									if(!token.equals("")){
										JSONObject jsonobject1=    Connect.fujian_lida(token,jsonObject1.toString());
										if(jsonobject1.get("message").equals("成功")){
											TSAttachmentEntity ts = systemService.getEntity(TSAttachmentEntity.class,list.get(i).getId());
											ts.setFstats("1");
											systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
										}
									}
								}else{
									message="网络不稳定,请重新发送附件";
								}
								
							}
						}
					}
					decmain.setStateId(decmain.getId());
					decmain.setSendState(1);
				}else{
					message=jsonobject.get("message").toString();
				}
				
				
			}else{
				message="发送失败";
			}
			systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
		}
		
		return message;
		
	}

发送地址

public static String getToken_lida(String userName,String password){
	//public static  String urlToken_lida="http://192.168.1.112:8080/jeecg/rest/tokens";
	String url = urlConfig.urlToken_lida+"?username="+userName+"&password="+password;
	String token= JwtHttpUtil.httpRequest(url, "POST", null);
	return token;
}

发送方法使用HttpURLConnection

/**
* 发起https请求并获取结果
* 
* @param requestUrl
*            请求地址
* @param requestMethod
*            请求方式(GET、POST)
* @param outputStr
*            提交的数据
* @return JSONObject(通过JSONObject.get(key)的方式获取json对象的属性值)
*/
public static String httpRequest(String requestUrl, String requestMethod, String outputStr) {
String res = "";
StringBuffer buffer = new StringBuffer();
HttpURLConnection httpUrlConn = null;
try {
	// 创建SSLContext对象,并使用我们指定的信任管理器初始化
	URL url = new URL(requestUrl);
	httpUrlConn = (HttpURLConnection) url.openConnection();
	httpUrlConn.setDoOutput(true);
	httpUrlConn.setDoInput(true);
	httpUrlConn.setUseCaches(false);
	httpUrlConn.setRequestProperty("Accept", "text/plain");
	 httpUrlConn.setRequestProperty("Content-Type", "application/json");
	// 设置请求方式(GET/POST)
	httpUrlConn.setRequestMethod(requestMethod);
	if ("GET".equalsIgnoreCase(requestMethod))
		httpUrlConn.connect();

	// 当有数据需要提交时
	if (null != outputStr) {
		OutputStream outputStream = httpUrlConn.getOutputStream();
		// 注意编码格式,防止中文乱码
		outputStream.write(outputStr.getBytes("UTF-8"));
		outputStream.close();
	}

	// 将返回的输入流转换成字符串
	InputStream inputStream = httpUrlConn.getInputStream();
	InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8");
	BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

	String str = null;
	while ((str = bufferedReader.readLine()) != null) {
		buffer.append(str);
	}
	bufferedReader.close();
	inputStreamReader.close();
	// 释放资源
	inputStream.close();
	inputStream = null;
	httpUrlConn.disconnect();
	res = buffer.toString();
	System.out.println(res);
//			jsonObject = JSONObject.parseObject(buffer.toString());
	// jsonObject = JSONObject.fromObject(buffer.toString());
} catch (ConnectException ce) {
	LogUtil.info("Weixin server connection timed out.");
} catch (Exception e) {
	e.printStackTrace();
	org.jeecgframework.core.util.LogUtil.info("https request error:{}" + e.getMessage());
} finally {
	try {
		httpUrlConn.disconnect();
	} catch (Exception e) {
		e.printStackTrace();
		org.jeecgframework.core.util.LogUtil.info("http close error:{}" + e.getMessage());
	}
}
return res;
}

发送地址

public static JSONObject tolidaguanwu_lida(String token,String json){
	//public   static String sendShopInfo= "http://192.168.1.112:8080/jeecg/ICommonApi.do?getSendInfo";
	String url =urlConfig.sendShopInfo;
	JSONObject resp= JwtHttpUtil.httpRequest(url, "GET", json, token);
	return resp;
}

发送地址

public static JSONObject fujian_lida(String token,String json){
	//public static String urlLdServer_lida="http://192.168.1.112:8080/jeecg/rest/";
	String url =urlConfig.urlLdServer_lida+ "tSAttachmentController";
	JSONObject resp= JwtHttpUtil.httpRequest(url, "POST", json,token);
	return resp;
}

添加流程信息

@Override
public void thrid_sendlidaSystem(String id) throws Exception {
	// TODO Auto-generated method stub
	// TODO Auto-generated method stub
	TSUser user = ResourceUtil.getSessionUser();
	// TODO Auto-generated method stub
	String num=jdbcTemplate.queryForObject("select count(*) from ldc_common_state where state_fid=? and state_operatorid='3'", String.class,id);
	if(!num.equals("0")){
		String id1=jdbcTemplate.queryForObject("select id from ldc_common_state where state_fid=? and state_operatorid='3'", String.class,id);
		LdcCommonStateEntity lc1=new LdcCommonStateEntity();
		lc1.setStateFid(id);
		lc1.setStateOperator(user.getUserName());
		lc1.setStateTime(new Date()); 
		lc1.setStateComment("发送代理"); 
		lc1.setStatePid(id1);
		this.save(lc1);
	}else{
		LdcCommonStateEntity lc=new LdcCommonStateEntity();
		lc.setStateFid(id); 
		lc.setStatePname("商品归类"); 
		lc.setStateOperatorid("3");
		this.save(lc);
		
		
		LdcCommonStateEntity lc1=new LdcCommonStateEntity();
		lc1.setStateFid(id);
		lc1.setStateOperator(user.getUserName());
		lc1.setStateTime(new Date()); 
		lc1.setStateComment("发送代理"); 
		lc1.setStatePid(lc.getId());
		this.save(lc1);
	}
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值