package com.sino.rrs.action;

import java.io.IOException;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.sino.publicclass.base.BaseAction;
import com.sino.weixin.oauth.util.Constants;
import com.sino.weixin.oauth.util.HttpsUtil;

public class ConnectionAction extends BaseAction{
	public void connection(){
		System.out.println("可以走到此处");
		setNextPage("/supplier/uploadPhoto.jsp");
	}
	
	//历史服务上传图片
	public void connectionImg(){
		System.out.println("可以走到此处");
		setNextPage("/supplier/photo.jsp");
	}
	
	//模糊查询订单任务
	public void queryOrder() throws IOException{
		String rescueCode=getParameter("rescueCode");
		String code=getParameter("code");
		JSONObject jsonObject=new JSONObject();
		jsonObject.put("rescue_company_id", rescueCode);
		jsonObject.put("taskCode", code);
		
		JSONObject list=JSON.parseObject(HttpsUtil.doPost(Constants.url+"/getSupplierTasks", jsonObject, "utf-8"));
		response.setContentType("text/html;charset=utf-8");
		response.getWriter().print(list);
		setNext(false);
	}
	
	//查询任务的所有照片信息
	public void queryAllPhotos() throws IOException{
		String taskOrderId=getParameter("taskOrderId");
		String taskState=getParameter("taskState");
		JSONObject jsonObject=new JSONObject();
		jsonObject.put("taskOrderId", taskOrderId);
		jsonObject.put("taskState", taskState);
		JSONObject list=JSON.parseObject(HttpsUtil.doPost(Constants.url+"/queryImages", jsonObject, "utf-8"));
		response.setContentType("text/html;charset=utf-8");
		response.getWriter().print(list);
		setNext(false);
	}
	
	//删除对应的照片信息
	public void deleteSelectedPhoto() throws IOException{
		String photoId=getParameter("photoId");
		String url=getParameter("imageUrl");
		String imageUrl=url.substring(url.indexOf("8888/")+5);
		JSONObject jsonObject=new JSONObject();
		jsonObject.put("id", photoId);
		jsonObject.put("imageUrl", imageUrl);
		
		boolean flag=false;
		JSONObject httpRsponse=JSON.parseObject(HttpsUtil.doPost(Constants.url+"/deleteImages", jsonObject, "utf-8"));
		if(httpRsponse.getIntValue("errorCode")==0){
			  flag=true;
		  }
		  httpRsponse.put("code", flag);
		  response.setContentType("text/html;charset=UTF-8");
		  response.getWriter().print(httpRsponse.toJSONString());
		  setNext(false);
	}
	
	public static void main(String[] args) {
		String str="http://192.168.1.220:8888//group1/M00/00/03/wKgB3FqqFYmAPHBZAAHv6Iz0LJk34.jpeg";
		String qw=str.substring(str.indexOf("8888/")+5);
		System.out.println(qw);
	}
}
