JAVA直接跳转到HTML5页面

Posted JLCUI

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JAVA直接跳转到HTML5页面相关的知识,希望对你有一定的参考价值。

package net.joystart.taskagent.controller;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.SignatureException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.Callable;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.transaction.Transactional;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSON;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;

import net.joystart.City.entity.ServiceCity;
import net.joystart.City.service.ICityService;
import net.joystart.baojia.sign.ZCloudSignConfig;
import net.joystart.carManager.entity.CarManager;
import net.joystart.carManager.service.ICarManagerLogService;
import net.joystart.carManager.service.ICarManagerService;
import net.joystart.common.controller.BaseController;
import net.joystart.common.efence.EfenceBaseType;
import net.joystart.common.efence.EfenceBaseType.EfenceState;
import net.joystart.common.efence.EfenceBuilder;
import net.joystart.common.util.ConstantUtil;
import net.joystart.common.util.HttpRequestUtil;
import net.joystart.common.util.JSONProcesser;
import net.joystart.common.util.MessageResult;
import net.joystart.common.util.PostMsgHttpContent;
import net.joystart.common.util.StringUtil;
import net.joystart.common.util.VehicleControlUtil;
import net.joystart.common.util.baiDu.BaiDuAPIUtil;
import net.joystart.common.util.baiDu.BaiDuAPIUtil.Position;
import net.joystart.common.util.date.UtilTimeFormatter;
import net.joystart.common.util.log.Log4jTask;
import net.joystart.common.util.security.EncryptionUtil;
import net.joystart.common.util.tencent.TengXunAPIUtil;
import net.joystart.customer.entity.Customer;
import net.joystart.customer.entity.MessageTemplate;
import net.joystart.customer.service.ICustomerService;
import net.joystart.customer.service.IMessageTemplateService;
import net.joystart.data.DataBaseUtil;
import net.joystart.device.entity.QueryResult;
import net.joystart.device.service.IVehicleDevice;
import net.joystart.device.service.impl.VehicleDevice;
import net.joystart.fault.service.IFaultReportService;
import net.joystart.mapCoordinates.entity.ReturnForInterface;
import net.joystart.order.controller.OrderController;
import net.joystart.order.entity.DrivingTrack;
import net.joystart.order.entity.InstantOrder;
import net.joystart.order.entity.Order;
import net.joystart.order.service.IOrderService;
import net.joystart.task.vehicleTask.entity.TaskInfo;
import net.joystart.taskagent.controller.entity.TaskToken;
import net.joystart.vehicle.dao.VehicleMapper;
import net.joystart.vehicle.entity.CarState;
import net.joystart.vehicle.entity.Parkinglot;
import net.joystart.vehicle.entity.Vehicle;
import net.joystart.vehicle.entity.VehicleSite;
import net.joystart.vehicle.enums.VehicleStatus;
import net.joystart.vehicle.service.IOperationService;
import net.joystart.vehicle.service.IParkinglotService;
import net.joystart.vehicle.service.IVehicleService;
import net.joystart.vehicle.service.impl.VehicleLock;
import net.joystart.vehicleInterface.controller.VehicleUnLock;
import net.joystart.vehicleInterface.enums.TaskType;
import net.joystart.vehicleInterface.service.IVehicleUnLockService;
import net.joystart.vehicleTask.service.IVehicleTaskService;
import net.joystart.virtualData.AutoAddVirtualData;

/**
 * 第三方任务代理
 * 
 * @author [email protected]
 * @create 2017/07/19
 */
@Controller
@Scope("prototype")
@RequestMapping("/agent")
public class AgentController extends BaseController {

	private int AGENT_COMPANY = 1;
	private String AGENT_COMPANY_NAME = "e代驾";
	private final int EXPIRES_IN = 3600;

	@Resource
	IVehicleService vehicleService;

	@Resource
	IVehicleUnLockService vehicleUnLockService;

	@Resource
	ICustomerService customerService;

	@Resource
	ICarManagerService carManagerService;

	@Resource
	ICarManagerLogService carManagerLogService;

	@Resource
	private IFaultReportService faultReportService;

	@Resource
	private IMessageTemplateService messageTemplateService;

	@Resource
	AutoAddVirtualData autoAddVirtualData;

	@Resource
	ICityService cityService;

	@Resource
	IVehicleTaskService vehicleTaskService;

	@Resource
	IParkinglotService parkinglotService;

	@Resource
	IOrderService orderService;

	@Resource
	IOperationService ControlService;

	@Resource
	VehicleMapper vehicleMapper;

	@Resource
	RedisTemplate<String, Object> redisTemplate;

	final Logger logger = LoggerFactory.getLogger(VehicleUnLock.class);

	/***
	 * 合作伙伴ID
	 */
	private String agentId = "CH0110000223";

	/***
	 * 合作伙伴ID
	 */
	private String chanleId = "31";

	/***
	 * 合作伙伴Key
	 */
	private String agentKey = "a";

	private String agentHost = "https://baoyang.d.edaijia.cn/api/third/2/";

	/**
	 * 获取渠道下所有的商户列表
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping("/getbusinesslist")
	public void getBusinessList(HttpServletRequest request, HttpServletResponse response) {
		String url = agentHost + "business/listAll";
		Map<String, String> params = new HashMap<>();
		params.put("channel", chanleId);
		String sign = getSign(params, agentKey);
		params.put("sign", sign);
		String ret = HttpRequestUtil.doGetJson(url, getSendParam(params));
		this.out(response, ret);
	}

	/**
	 * 获取商户的账号余额
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping("/getbalance")
	public void getBalance(HttpServletRequest request, HttpServletResponse response) {
		String url = agentHost + "business/balance";
		Map<String, String> params = new HashMap<>();
		params.put("channel", chanleId);
		params.put("customerId", request.getParameter("chanleId"));
		String sign = getSign(params, agentKey);
		params.put("sign", sign);
		String ret = HttpRequestUtil.doGetJson(url, getSendParam(params));
		this.out(response, ret);
	}

	/**
	 * 获取服务支持城市列表
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping("/getcitylist")
	public void getCityList(HttpServletRequest request, HttpServletResponse response) {
		String url = agentHost + "queryCityList";
		Map<String, String> params = new HashMap<>();
		params.put("channel", chanleId);
		String sign = getSign(params, agentKey);
		params.put("sign", sign);
		String ret = HttpRequestUtil.doGetJson(url, getSendParam(params));
		this.out(response, ret);
	}

	/**
	 * 根据CODE获取城市信息
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping("/getcity")
	public void getCity(HttpServletRequest request, HttpServletResponse response) {
		String url = agentHost + "queryCity";
		Map<String, String> params = new HashMap<>();
		params.put("channel", chanleId);
		params.put("code", request.getParameter("code"));
		String sign = getSign(params, agentKey);
		params.put("sign", sign);
		String ret = HttpRequestUtil.doGetJson(url, getSendParam(params));
		this.out(response, ret);
	}

	/**
	 * 预估金额
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping("/predict")
	public void getPredict(HttpServletRequest request, HttpServletResponse response) {
		String url = agentHost + "price";
		Map<String, String> params = new HashMap<>();
		params.put("channel", chanleId);
		params.put("code", request.getParameter("code"));
		params.put("startLng", request.getParameter("startLng"));
		params.put("startLat", request.getParameter("startLat"));
		params.put("endLng", request.getParameter("endLng"));
		params.put("endLat", request.getParameter("endLat"));
		params.put("bookingTime", request.getParameter("bookingTime")); // String(yyyyMMddHHmmss)
		params.put("customerId", request.getParameter("customerId"));
		String sign = getSign(params, agentKey);
		params.put("sign", sign);
		String ret = HttpRequestUtil.doGetJson(url, getSendParam(params));
		this.out(response, ret);
	}

	/**
	 * 下单接口
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping("/createorder")
	public void createOrder(HttpServletRequest request, HttpServletResponse response) {
		String customerId = "CH0110000223";
		String taskId = request.getParameter("taskid");
		MessageResult message = createOrderByTaskId(Integer.valueOf(taskId), customerId);
		this.out(response, message);
	}

	/**
	 * 取消订单接口
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping("/cancelorder")
	public void cancelOrder(HttpServletRequest request, HttpServletResponse response) {
		String url = agentHost + "order/cancel";
		Map<String, String> params = new HashMap<>();
		params.put("channel", chanleId);
		params.put("orderId", request.getParameter("orderId"));
		String sign = getSign(params, agentKey);
		params.put("sign", sign);
		String result = HttpRequestUtil.doPostJson(url, getSendParam(params));
		HashMap<String, Object> retObj = JSON.parseObject(result, HashMap.class);
		String code = retObj.get("code").toString();
		String message = retObj.get("message").toString();
		// 下单成功
		if (code == "0") {
			String orderNo = retObj.get("data").toString();
		}
		// 下单失败
		else {

		}
		this.out(response, retObj);
	}

	/**
	 * 获取订单详情
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping("/orderdetail")
	public void getOrderDetail(HttpServletRequest request, HttpServletResponse response) {
		String url = agentHost + "order/detail";
		Map<String, String> params = new HashMap<>();
		params.put("channel", chanleId);
		params.put("orderId", request.getParameter("orderId"));
		String sign = getSign(params, agentKey);
		params.put("sign", sign);
		String ret = HttpRequestUtil.doGetJson(url, getSendParam(params));
		this.out(response, ret);
	}

	/**
	 * 获取订单轨迹
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping("/ordertrack")
	public void getOrderTrack(HttpServletRequest request, HttpServletResponse response) {
		String url = agentHost + "order/recordList";
		Map<String, String> params = new HashMap<>();
		params.put("channel", chanleId);
		params.put("orderId", request.getParameter("orderId"));
		String sign = getSign(params, agentKey);
		params.put("sign", sign);
		String ret = HttpRequestUtil.doGetJson(url, getSendParam(params));
		this.out(response, ret);
	}

	/**
	 * 获取司机代驾轨迹
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping("/ordertrace")
	public void getOrderTrace(HttpServletRequest request, HttpServletResponse response) {
		String url = agentHost + "order/trace";
		Map<String, String> params = new HashMap<>();
		params.put("channel", chanleId);
		params.put("orderId", request.getParameter("orderId"));
		params.put("type", request.getParameter("type"));
		String sign = getSign(params, agentKey);
		params.put("sign", sign);
		String ret = HttpRequestUtil.doGetJson(url, getSendParam(params));
		this.out(response, ret);
	}

	/**
	 * 获取司机信息
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping("/getdriverinfo")
	public void getDriverInfo(HttpServletRequest request, HttpServletResponse response) {
		String url = agentHost + "order/driverInfo";
		Map<String, String> params = new HashMap<>();
		params.put("channel", chanleId);
		params.put("orderId", request.getParameter("orderId"));
		params.put("type", request.getParameter("type"));
		String sign = getSign(params, agentKey);
		params.put("sign", sign);
		String result = HttpRequestUtil.doGetJson(url, getSendParam(params));
		JSONObject retObj = JSON.parseObject(result, JSONObject.class);
		String code = retObj.get("code").toString();
		String message = retObj.get("message").toString();
		if (code == "0") {
			JSONObject driver = retObj.getJSONObject("data");
		} else {

		}
		this.out(response, retObj);
	}

	/**
	 * 获取目的人收车验证码
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping("/getverifycode")
	public void getVerifyCode(HttpServletRequest request, HttpServletResponse response) {
		MessageResult message = new MessageResult();
		String orderId = request.getParameter("orderId");
		String type = request.getParameter("type");
		String code = getVerifyCode(orderId, type);
		if (code != null) {
			message.setCode("0");
			message.setData(code);
			message.setMessage("success");
		} else {
			message.setCode("1");
			message.setData(null);
			message.setMessage("failure");
		}
		this.out(response, message);
	}

	/***
	 * 获取收车验证码
	 * 
	 * @param orderId
	 * @param type
	 * @return
	 */
	public String getVerifyCode(String orderId, String type) {
		String url = agentHost + "order/verifyCode";
		Map<String, String> params = new HashMap<>();
		params.put("channel", chanleId);
		params.put("orderId", orderId);
		params.put("type", type);
		String sign = getSign(params, agentKey);
		params.put("sign", sign);
		String result = HttpRequestUtil.doGetJson(url, getSendParam(params));
		HashMap<String, Object> retObj = JSON.parseObject(result, HashMap.class);
		String code = retObj.get("code").toString();
		String message = retObj.get("message").toString();
		// String message = retObj.get("message").toString();
		if (code.equals("0")) {
			String VerifyCode = retObj.get("data").toString();
			return VerifyCode;
		} else {
			return null;
		}

	}

	/**
	 * 获取历史订单
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping("/getorderlist")
	public void getOrderList(HttpServletRequest request, HttpServletResponse response) {
		String url = agentHost + "order/queryList";
		Map<String, String> params = new HashMap<>();
		params.put("channel", chanleId);
		params.put("startDate", request.getParameter("startDate"));
		params.put("endDate", request.getParameter("endDate"));
		params.put("pageSize", request.getParameter("pageSize"));
		params.put("currentPage", request.getParameter("currentPage"));
		params.put("mobile", request.getParameter("mobile"));
		params.put("createMobile", request.getParameter("createMobile"));
		params.put("customerId", request.getParameter("customerId"));
		String sign = getSign(params, agentKey);
		params.put("sign", sign);
		String result = HttpRequestUtil.doGetJson(url, getSendParam(params));
		JSONObject retObj = JSON.parseObject(result, JSONObject.class);
		String code = retObj.get("code").toString();
		String message = retObj.get("message").toString();
		if (code == "0") {
			JSONObject orderList = retObj.getJSONObject("data");
			this.out(response, orderList);
		} else {
			this.out(response, retObj);
		}
	}

	/**
	 * 获取车辆信息照片
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping("/getcarphotos")
	public void getCarPhotos(HttpServletRequest request, HttpServletResponse response) {
		String url = agentHost + "order/getCarPhotos";
		Map<String, String> params = new HashMap<>();
		params.put("orderId", request.getParameter("orderId"));
		params.put("channel", chanleId);
		params.put("daijiaType", request.getParameter("daijiaType"));
		String sign = getSign(params, agentKey);
		params.put("sign", sign);
		String result = HttpRequestUtil.doGetJson(url, getSendParam(params));
		JSONObject retObj = JSON.parseObject(result, JSONObject.class);
		String code = retObj.get("code").toString();
		String message = retObj.get("message").toString();
		if (code == "0") {
			JSONObject orderList = retObj.getJSONObject("data");
			this.out(response, orderList);
		} else {
			this.out(response, retObj);
		}
	}

	/**
	 * 根据车辆Token登陆
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping("/logintoken")
	public void logintoken(HttpServletRequest request, HttpServletResponse response) {
		logger.info("=======================跳转成功================================");
		MessageResult message = new MessageResult();
		String token = request.getParameter("token");
		/*String sql = "SELECT * FROM t_base_task_token WHERE token=‘" + token
				+ "‘ AND DATE_ADD(createTime,INTERVAL expiresIn MINUTE)>NOW()";*/
		TaskToken taskToken =vehicleService.getTaskToken(token);
		//List<Map<String, Object>> result = DataBaseUtil.query(sql);
		if (taskToken == null) {
			message.setCode("10001");
			message.setMessage("错误的授权信息");
			message.setData(token);
			this.out(response, message);
			return;
		}
		String orderId = taskToken.getOrderid().toString();
		logger.info("=======================跳转成功orderId=" + orderId + "================================");
		String taskId = taskToken.getTaskid().toString();
		logger.info("=======================跳转成功taskId=" + taskId + "================================");
		String loginUUID = taskToken.getLoginuuid();
		logger.info("=======================跳转成功loginUUID=" + loginUUID + "================================");
		
		TaskInfo taskInfo = vehicleUnLockService.selectByPrimaryKey(Integer.parseInt(taskId));
		String verifyCode = getVerifyCode(taskInfo.getOutorderid(), "1");
		Order order = orderService.selectByPrimaryKey(Integer.valueOf(orderId));
		if (order != null && (order.getOrderstatus() == 0 || order.getOrderstatus() == 10)) {
			Integer customerId = order.getCustomerid();
			Customer cus = customerService.selectByPrimaryKey(customerId);
			if (cus != null) {
				request.getSession().setAttribute("customer", cus);
			}
			request.getSession().setAttribute("orderid", orderId);
			request.getSession().setAttribute("taskid", taskId);
			request.getSession().setAttribute("loginuuid", loginUUID);
			request.getSession().setAttribute("token", token);
			request.getSession().setAttribute("verifyCode", verifyCode);
			try {
				response.sendRedirect(request.getContextPath() + "/jsp/agent/vehiclecontrol.jsp");
			} catch (IOException e) {
				e.printStackTrace();
			}
		} else {
			message.setCode("11001");
			message.setMessage("订单不存在或已经过期");
			message.setData(token);
			this.out(response, message);
		}
	}

	/**
	 * 车辆控制接口
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping("/control")
	public void control(HttpServletRequest request, HttpServletResponse response) {
		MessageResult message = new MessageResult();
		String orderId = request.getParameter("orderid");
		String taskid = request.getParameter("taskid");
		String token = request.getParameter("token");
		String type = request.getParameter("type");
		TaskInfo taskInfo = vehicleUnLockService.selectByPrimaryKey(Integer.parseInt(taskid));
		Order order = orderService.selectByPrimaryKey(Integer.valueOf(orderId));
		if (StringUtils.isBlank(token)) {
			message.setCode("10001");
			message.setMessage("禁止访问");
			message.setData(orderId);
			this.out(response, message);
			return;
		} else if (checkToken(token) == false) {
			message.setCode("10002");
			message.setMessage("未授权访问");
			message.setData(orderId);
			this.out(response, message);
			return;
		}
		if (order == null) {
			message.setCode("1");
			message.setMessage("订单不存在");
			message.setData(orderId);
			this.out(response, message);
			return;
		}
		if (taskInfo.getTaskstatus()==4 || taskInfo.getTaskstatus()==5){
			message.setCode("1");
			message.setMessage("任务已完成不能控制车辆");
			message.setData(taskInfo.getId());
			this.out(response, message);
			return;
		}

		/*
		 * if (order.getOrderstatus() != 0 && order.getOrderstatus() != 10) {
		 * message.setCode("2"); message.setMessage("订单编号无效");
		 * message.setData(orderId); this.out(response, message); return; }
		 */
		// 订单未取车,更新为已取车

		// 通过订单ID获取车辆的SN和Code
		IVehicleDevice vehicleDevice = new VehicleDevice(vehicleMapper.selectByPrimaryKey(order.getVehicleid()));
		int result = 0;
		switch (type) {
		case "0":
			result = vehicleDevice.speak();
			break;
		case "1":
			if (order.getOrderstatus() == 0) {//开锁成功后才更新订单状态
				order.setChargingstartdate(new Date());
				order.setOrderstatus(10);
				orderService.updateByPrimaryKeySelective(order);
			}
			result = vehicleDevice.turnOnAndOpen();
			taskInfo.setTaskstatus(2);// 开锁成功后更新任务状态
			vehicleUnLockService.updateTaskInfoId(taskInfo);
			List<Integer> list = this.vehicleUnLockService.selectByPrimaryKeyVehidInt(taskInfo.getVehicleid());
			if (list != null && list.size() > 0) {//开锁成功后删除车位关系完成任务会从新绑定车位关系
				 vehicleUnLockService.deleteByPrimaryKeyForEach(list);
			}
			break;
		case "2":
			result = vehicleDevice.shutDown();
			break;
		default:
			break;
		}

		message.setCode("0");
		message.setMessage("操作成功");
		message.setData(result);
		this.out(response, message);
		return;
	}

	/**
	 * 获取车辆信息
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping("/getvehicleinfo")
	public void getvehicleinfo(HttpServletRequest request, HttpServletResponse response) {
		MessageResult message = new MessageResult();
		String orderId = request.getParameter("orderId");
		String token = request.getParameter("token");
		String type = request.getParameter("type");
		Order order = orderService.selectByPrimaryKey(Integer.valueOf(orderId));
		if (order == null) {
			message.setCode("1");
			message.setMessage("订单不存在");
			message.setData(orderId);
			this.out(response, message);
			return;
		}
		// 通过订单ID获取车辆的SN和Code
		IVehicleDevice vehicleDevice = new VehicleDevice(vehicleMapper.selectByPrimaryKey(order.getVehicleid()));
		QueryResult qr = vehicleDevice.queryInfo();
		CarState carSate = qr.getCarState();
		this.out(response, carSate);
	}

	/**
	 * 更改订单状态主动通知接口
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping("/changeorder")
	public void changeOrder(HttpServletRequest request, HttpServletResponse response) {
		logger.info("============================E代驾回调成功==========================================");
		Date now = new Date();
		MessageResult message = new MessageResult();
		String channel = request.getParameter("channel");
		logger.info(
				"============================E代驾回调成功:channel" + channel + "==========================================");
		String orderId = request.getParameter("orderId");
		logger.info(
				"============================E代驾回调成功:orderId" + orderId + "==========================================");
		String status = request.getParameter("status"); // 订单状态 Int 是 状态值参考订单详情
		logger.info(
				"============================E代驾回调成功:status" + status + "==========================================");
		String driverNo = request.getParameter("driverNo"); // 司机工号 String
															// ,司机抢单后或者客服派单后不为空
		if (StringUtils.isNotEmpty(driverNo)) {
			logger.info("============================E代驾回调成功:driverNo" + driverNo
					+ "==========================================");
		} else {
			logger.info("============================E代驾回调成功:driverNo" + null
					+ "==========================================");
		}
		String sign = request.getParameter("sign"); // 签名 String 是
		logger.info("============================E代驾回调成功:sign" + sign + "==========================================");

		Map<String, String> params = new HashMap<>();
		params.put("channel", channel);
		params.put("orderId", orderId);
		params.put("status", status);
		params.put("driverNo", driverNo);

		String vsign = getSign(params, agentKey);
		logger.info("============================E代驾回调成功:" + vsign + "==========================================");

		/************
		 * 订单状态说明 0 已下单 2 资金已冻结 5 订单取消 用户取消、司机取消、坐席取消或者客服取消 6 等待司机接单 4 司机已接单
		 * 调用司机抢单模式的时候通知,调用派单模式则跳过此状态 7 司机已开启订单 8 司机已就位 11 司机开车中 12 司机到达目的地 50
		 * 已收车 55 订单已完成
		 ************/
		if (!vsign.equals(sign)) {
			logger.info("============================E代驾回调成功验证不一致==========================================");
			message.setCode("1");
			message.setMessage("签名错误");
			message.setData(vsign);
			this.out(response, message);
			return;
		}
		/***** 根据订单号订单号获取任务编号 ********/
		TaskInfo taskInfo = vehicleTaskService.selectByOutOrderId(orderId);
		if (taskInfo == null) {
			message.setCode("3");
			message.setMessage("订单不存在");
			message.setData(orderId);
			this.out(response, message);
			return;
		}

		/*** 获取司机信息,发送短信 *****/
		if (status.equals("6") || status.equals("4") || status.equals("7")) {
			String verifyCode = getVerifyCode(taskInfo.getOutorderid(), "1");// 获取验证码
																				// add
																				// cjl
			taskInfo.setOrderkey(verifyCode);
			String url = agentHost + "order/driverInfo";
			Map<String, String> sendParams = new HashMap<>();
			sendParams.put("channel", chanleId);
			sendParams.put("orderId", orderId);
			sign = getSign(sendParams, agentKey);
			sendParams.put("sign", sign);
			String result = HttpRequestUtil.doGetJson(url, getSendParam(sendParams));
			GsonBuilder gb = new GsonBuilder();
			Gson g = gb.create();
			Map<Object, Object> map1 = g.fromJson(result, new TypeToken<Map<Object, Object>>() {
			}.getType());
			String code = map1.get("code").toString();
			Double codeInt = Double.parseDouble(code);
			if (codeInt.intValue() == 0) {
				String data = g.toJson(map1.get("data"));
				Map<Object, Object> map2 = g.fromJson(data, new TypeToken<Map<Object, Object>>() {
				}.getType());
				String driverId = "";
				String driverPhone = "";
				String name = "";
				String pictureSmall = "";
				String pictureMiddle = "";
				String pictureLarge = "";
				String idCard = "";
				if (map2.get("driverId") != null) {
					driverId = map2.get("driverId").toString();
				}
				if (map2.get("driverPhone") != null) {
					driverPhone = map2.get("driverPhone").toString();
				}
				if (map2.get("name") != null) {
					name = map2.get("name").toString();
				}
				if (map2.get("newLevel") != null) {
					Double newLeveld = Double.parseDouble(map2.get("newLevel").toString());
					Integer newLevel = newLeveld.intValue();
				}
				if (map2.get("pictureSmall") != null) {
					pictureSmall = map2.get("pictureSmall").toString();
				}
				if (map2.get("pictureMiddle") != null) {
					pictureMiddle = map2.get("pictureMiddle").toString();
				}
				if (map2.get("pictureLarge") != null) {
					pictureLarge = map2.get("pictureLarge").toString();
				}
				if (map2.get("year") != null) {
					Double yeard = Double.parseDouble(map2.get("year").toString());
					Integer year = yeard.intValue();
				}
				if (map2.get("idCard") != null) {
					idCard = map2.get("idCard").toString();
				}

				//
				if (StringUtils.isBlank(driverPhone)) {
					message.setCode("2");
					message.setMessage("无法获取司机信息");
					message.setData(orderId);
					this.out(response, message);
					return;
				} else {
					CarManager carManager = this.carManagerService.selectByMobile(driverPhone);
					if (carManager == null) {
						carManager = new CarManager();
						carManager.setUsername(driverPhone);
						carManager.setName(name);
						carManager.setDrivinglicensephoto(pictureSmall);
						carManager.setMobile(driverPhone);
						if (map2.get("driverId") != null) {
							carManager.setRemark("e代驾司机:" + driverId + ",身份证:" + idCard);
						} else {
							carManager.setRemark("e代驾司机:" + null + ",身份证:" + idCard);
						}
						carManager.setIdphoto(idCard);
						try {
							carManager.setPassword(EncryptionUtil.md5(ConstantUtil.CAR_MANAGER_INITPWD));
						} catch (Exception e1) {
							e1.printStackTrace();
						}
						carManager.setWorkstatus(ConstantUtil.WORKSTATUS);
						carManager.setTaskstatus(ConstantUtil.TASKSTATUS);
						carManager.setCreatedate(now);
						carManager.setSex(0);
						carManager.setIdphoto("e代驾人员");
						carManager.setHoldingidphoto("e代驾人员");
						carManager.setDrivinglicensephoto("e代驾人员");
						this.carManagerService.insertManager(carManager);

						// 获取司机ID
						carManager = this.carManagerService.selectByMobile(driverPhone);
					}

					Customer cus = new Customer();
					cus.setUsername(driverPhone);
					cus.setName(name);
					cus.setIdcardno(idCard);
					cus.setIsValidateIdCard(new Byte("1"));
					cus.setIsValidateDrivingLicence(new Byte("1"));
					cus.setIsCompany(new Byte("1"));
					cus.setCompanyID(152);// 后续在该暂时没有想到取E代驾企业的方法
					cus.setCompanyName(AGENT_COMPANY_NAME);
					cus.setAuditstatus(new Byte("1"));
					cus.setIscanorder(new Byte("1"));
					cus.setMobile(driverPhone);
					cus.setSourcechannelid(1);
					cus.setCreatedate(new Date());
					cus.setDepartmentid(223);//E代驾使用部门ID
					try {
						cus.setPassword(EncryptionUtil.md5(ConstantUtil.CAR_MANAGER_INITPWD));
					} catch (Exception e) {
						e.printStackTrace();
					}
					Customer tempCus = customerService.isExistCustomer(cus);

					// 如果用户不存在,注册新用户
					if (tempCus == null) {
						// 获取注册模板的信息
						MessageTemplate mTemplate = messageTemplateService
								.selectTitleAndContentByIdentification(ConstantUtil.M_REGISTER_SUCCESS);
						net.joystart.customer.entity.Message mes = null;
						if (mTemplate != null) {
							// 添加站内信
							mes = new net.joystart.customer.entity.Message();
							mes.setTitle(mTemplate.getTitle());
							mes.setContent(mTemplate.getContent());
							mes.setSenddate(new Date());
							mes.setReadstatus(new Byte("0"));
							mes.setIsdelete(new Byte("0"));
							mes.setCreatedate(new Date());
						}
						cus = customerService.Register(cus, mes);
					} else {
						cus.setId(tempCus.getId());
					}

					// 更新用户UUID
					UUID uuid = UUID.randomUUID();
					cus.setLoginUUID(uuid.toString());
					customerService.updaeCustomer(cus);

					message = acceptTask(taskInfo.getId().toString(), carManager, cus);
					this.out(response, message);

					return;
				}
			} else {
				message.setCode("2");
				message.setMessage("无法获取司机信息");
				message.setData(orderId);
				this.out(response, message);
				return;
			}

		} else if (status.equals("5")) {
			if (cancelOrderByTask(taskInfo.getId())) {
				message.setCode("0");
				message.setMessage("success");
				this.out(response, message);
				return;
			} else {
				message.setCode("4");
				message.setMessage("取消订单失败");
				message.setData(orderId);
				this.out(response, message);
				return;
			}
		} else if (status.equals("50")) // 已收车
		{
			message.setCode("0");
			message.setMessage("success");
			this.out(response, message);
			return;
		} else if (status.equals("55")) // 已完成
		{
			message.setCode("0");
			message.setMessage("success");
			this.out(response, message);
			return;
		} else {
			message.setCode("0");
			message.setMessage("success");
			this.out(response, message);
			return;
		}

	}

	/**
	 * 领取任务
	 * 
	 * @param request
	 * @param response
	 */
	public MessageResult acceptTask(String taskId, CarManager carManager, Customer cus) {

		MessageResult message = new MessageResult();

		try {

			if (taskId == null) {
				message.setCode(ConstantUtil.M_EXCEPTION);
				message.setMessage("参数taskId不能为空");
				return message;
			}

			if (vehicleTaskService.IsCanAcceptTask(Integer.valueOf(taskId))) {
				message.setCode(ConstantUtil.M_EXCEPTION);
				message.setMessage("当前车辆已被用户下单,请联系管理人员删除此任务");
				return message;
			}

			TaskInfo taskInfo = vehicleTaskService.selectByPrimaryKey(Integer.valueOf(taskId));
			if (taskInfo.getTaskstatus() != 0 && taskInfo.getTaskuserid() != null) {
				message.setCode(ConstantUtil.M_EXCEPTION);
				message.setMessage("这个任务已经分配给了其他人");
				return message;
			}

			// 判断是充电,且有调度
			if (taskInfo.getTaskimg() != null && taskInfo.getTaskimg().intValue() == 0
					&& taskInfo.getDispatchType().intValue() == 3) {
				taskInfo.setTaskimg(5);
			}

			VehicleLock lock = new VehicleLock(taskInfo.getVehicleid().toString());
			String ret = lock.wrap(new Callable<String>() {
				@Override
				public String call() {
					String uuid = cus.getLoginUUID();
					MessageResult result = new MessageResult();
					InstantOrder instantOrder = new InstantOrder();
					instantOrder.setCustomerId(cus.getId());
					instantOrder.setVehicleId(taskInfo.getVehicleid());
					instantOrder.setIsEnterprise(new Byte("1"));
					instantOrder.setLoginUUID(uuid);
					String token = StringUtil.getRandomString(8, ConstantUtil.REDPACKET_NUMBER_SEEDSOURCE);
					/*** 生成随机控制密码 ***/
					try {
						token = EncryptionUtil.md5(token + uuid);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}

					// 订单来源代驾
					instantOrder.setSourceType(4);

					// 插入订单
					result = orderService.insertInstantOrder(instantOrder);
					HashMap<String, Object> orderMap = new HashMap<String, Object>();
					// dataMap.put("orderId", orderId);
					if (result != null) {
						orderMap = (HashMap<String, Object>) result.getData();
					}
					// IVehicleService vehicleService;
					String orderId = orderMap.get("orderId").toString();

					taskInfo.setAllocationtime(new Date());
					taskInfo.setTaskstatus(1);
					taskInfo.setTaskuserid(carManager.getId());
					taskInfo.setOrderid(Integer.valueOf(orderId)); // 设置订单关联任务
					// taskInfo.setOrderkey(orderLoginCode);
					taskInfo.setExpires(EXPIRES_IN);
					vehicleTaskService.acceptTask(taskInfo);

					int taskType = taskInfo.getTasktype();
					String temp = "充电";
					if (0 == taskType) {
						temp = "充电";
					} else if (1 == taskType) {
						temp = "调度";
					} else if (2 == taskType) {
						temp = "整备";
					} else if (3 == taskType) {
						temp = "调度充电";
					} else if (4 == taskType) {
						temp = "加油";
					}
					Vehicle vh = vehicleService.selectByPrimaryKey(taskInfo.getVehicleid());

					// 插入登录信息
					/*String sql = "insert into `t_base_task_token`(orderid,taskid,loginUUID,token,expiresIn,createTime) values("
							+ orderId + "," + taskId.toString() + ",‘" + cus.getLoginUUID() + "‘,‘" + token + "‘,"
							+ EXPIRES_IN + ",‘" + new Date() + "‘)";*/
					//DataBaseUtil.query(sql);
					TaskToken taskToken = new TaskToken();
					taskToken.setCreatetime(new Date());
					taskToken.setOrderid(Integer.parseInt(orderId));
					taskToken.setTaskid(Integer.parseInt(taskId));
					taskToken.setLoginuuid(cus.getLoginUUID());
					taskToken.setToken(token);
					taskToken.setExpiresin(EXPIRES_IN);
					vehicleService.insertSelectiveTaskToken(taskToken);
					
					carManagerLogService.insertLog(carManager.getId(), "接受" + temp + "任务 车牌号:"
							+ (vh != null ? vh.getPlatenumber() : "未知") + " \r\n任务单号:" + taskInfo.getTaskNo());

					/*********************
					 * 发送短信任务链接给代驾人员
					 ******************/
					String taskurl = "http://t.bagechuxing.cn/l/" + token;
					PostMsgHttpContent.sendMessage("13401149982", "您成功领取了任务,点击以下链接完成任务 " + taskurl);
					return "SUCCESS";
				}

			});

			if ("SUCCESS".equals(ret)) {
				message.setCode(ConstantUtil.M_SUCCESS);
				message.setMessage("接受任务成功");
			} else {
				message.setCode(ConstantUtil.M_SYSTEM_ERROR);
				message.setMessage("系统异常");
			}

			return message;

		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(ConstantUtil.M_SYSTEM_ERROR);
			message.setMessage("系统异常");
			return message;
		}
	}

	/***
	 * 根据任务生成e代驾订单
	 * 
	 * @param taskid
	 */
	public MessageResult createOrderByTaskId(Integer taskId, String customerId) {
		MessageResult message = new MessageResult();
		if (vehicleTaskService.IsCanAcceptTask(taskId)) {
			message.setCode(ConstantUtil.M_EXCEPTION);
			message.setMessage("当前车辆已被用户下单,请联系管理人员删除此任务");
			return message;
		}

		TaskInfo taskInfo = vehicleTaskService.selectByPrimaryKey(taskId);
		if (taskInfo.getTaskstatus() != 0 && taskInfo.getTaskuserid() != null) {
			message.setCode(ConstantUtil.M_EXCEPTION);
			message.setMessage("这个任务已经分配给了其他人");
			return message;
		}

		Integer vehicleId = taskInfo.getVehicleid();
		Vehicle vehicle = vehicleService.selectByPrimaryKey(vehicleId);

		Integer parkId = vehicle.getParkid();
		Parkinglot parkinglot = parkinglotService.selectParkinglotByPrimaryKey(parkId);
		if (parkinglot == null) {
			message.setCode(ConstantUtil.M_EXCEPTION);
			message.setMessage("该车未在任何车场");
			return message;
		}
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.MINUTE, +31);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");

		String url = agentHost + "order/create";
		Map<String, String> params = new HashMap<>();
		params.put("channel", chanleId);
		params.put("customerId", customerId);
		params.put("type", "1"); // 订单类型 Int 是 1-取送车
		params.put("mode", "1"); // 订单成单模式 1-司机抢单(订单所在城市预约开启时生效,否则为客服派单) 0-客服派单
		params.put("createMobile", parkinglot.getTelephone()); // 下单人手机号 String
																// 是 手机号
		params.put("mobile", parkinglot.getTelephone()); // 车主手机号 String 是 手机号
		params.put("username", "巴歌出行"); // 车主姓名 String 是
		params.put("pickupContactName", "巴歌出行"); // 取车地址联系人姓名 String 是 最多20个字符
		params.put("pickupContactPhone", parkinglot.getTelephone()); // 取车地址联系人手机号
																		// String
																		// 是 手机号
		params.put("pickupAddress", parkinglot.getAddress()); // 取车地址 String 是
																// 最多100个字符
		params.put("pickupAddressLng", parkinglot.getLongitude()); // 取车地址经度
																	// Double 是
		params.put("pickupAddressLat", parkinglot.getLatitude()); // 取车地址纬度
																	// Double 是
		params.put("returnContactName", "巴歌出行"); // 还车地址联系人姓名 String 是 最多20个字符
		params.put("returnContactPhone", "13401149982"); // 还车地址联系人手机号
															// String
															// 是 手机号

		List<DrivingTrack> listTack = null;
		listTack = vehicleService.getAllCarsPoint(vehicle.getSn());
		if (listTack != null && listTack.size() > 0) {
			DrivingTrack dt = new DrivingTrack();
			dt = listTack.get(0);
			params.put("returnAddressLng", dt.getLongitude().toString()); // 还车地址经度
			// Double
			// 是
			params.put("returnAddressLat", dt.getLatitude().toString()); // 还车地址纬度
			// Double
			// 是
		}
		String returnAddress = BaiDuAPIUtil.getDetailByGPS(
				Double.parseDouble(params.get("returnAddressLng").toString()),
				Double.parseDouble(params.get("returnAddressLat").toString()));
		GsonBuilder gb = new GsonBuilder();
		Gson g = gb.create();
		Map<Object, Object> mapOne = g.fromJson(returnAddress, new TypeToken<Map<Object, Object>>() {
		}.getType());
		Map<Object, Object> mapTwo = (Map<Object, Object>) mapOne.get("result");

		String strOne = mapTwo.get("formatted_address").toString();
		params.put("returnAddress", strOne); // 还车地址 String 是
												// 最多100个字符

		params.put("bookingTime", sdf.format(cal.getTime())); // 预约时间 String
																// (yyyyMMddHHmmss)
																// 是
																// 必须比当前时间晚至少半个小时
		params.put("carNo", vehicle.getPlatenumber()); // 车牌号 String 是
		params.put("carBrandName", vehicle.getCarname()); // 车辆品牌名称 String 否
															// 最多50个字符
		params.put("carSeriesName", vehicle.getCarname()); // 车辆品牌名称 String 否
															// 最多50个字符
		String sign = getSign(params, agentKey);
		params.put("sign", sign);
		String result = HttpRequestUtil.doPostJson(url, getSendParam(params));
		logger.info("e代驾下单接口调用:" + params + ",返回结果:" + result);

		HashMap<String, Object> retObj = JSON.parseObject(result, HashMap.class);
		String code = retObj.get("code").toString();
		String msg = retObj.get("message").toString();

		/**** 更新外部订单号 *****/
		if (code.equals("0")) {
			String orderNo = retObj.get("data").toString();
			/*
			 * String verifyCode = getVerifyCode(orderNo, "1"); if (verifyCode
			 * == null) { message.setCode(ConstantUtil.M_EXCEPTION);
			 * message.setMessage("获取验证码失败"); return message; } else {
			 * taskInfo.setOrderkey(verifyCode);
			 * taskInfo.setOutorderid(orderNo);
			 * vehicleTaskService.acceptTask(taskInfo);
			 * message.setCode(ConstantUtil.M_SUCCESS);
			 * message.setMessage("SUCCESS"); message.setData(orderNo); return
			 * message; }
			 */
			taskInfo.setOutorderid(orderNo);
			taskInfo.setEdFlag(1);//推送成功
			taskInfo.setEdCreateDate(new Date());
			vehicleTaskService.acceptTask(taskInfo);
			logger.info("=================" + retObj.get("data").toString() + "====================");
			message.setCode(ConstantUtil.M_SUCCESS);
			message.setMessage("推送成功");
			return message;
		} else {
			message.setCode(ConstantUtil.M_EXCEPTION);
			message.setMessage("推送失败");
			return message;
		}
	}

	/***
	 * 取消订单接口
	 */
	private boolean cancelOrderByTask(Integer taskId) {
		try {
			TaskInfo taskInfo = vehicleTaskService.selectByPrimaryKey(taskId);
			if (taskInfo != null) {
				taskInfo.setIsdelete(1);
				vehicleTaskService.cancle(taskId);
				Integer orderId = taskInfo.getOrderid();
				if (orderId != null) {
					Order o = orderService.selectByPrimaryKey(orderId);
					Order order = new Order();
					order.setId(new Integer(orderId));
					order.setOrderstatus(40);
					orderService.updateByPrimaryKeySelective(order);
					redisTemplate.opsForHash().delete(ConstantUtil.ORDER_CACHE_KEY, o.getOrderno());
					Vehicle vehicle = new Vehicle(o.getVehicleid(), VehicleStatus.CANRENT.getValue());
					vehicleService.updateByPrimaryKeySelective(vehicle);
				}
				return true;
			} else {
				return false;
			}
		} catch (Exception ex) {
			Log4jTask.addLog("结束订单报错", System.currentTimeMillis(), Log4jTask.ERROR, OrderController.class.getName(),
					ex);
			return false;
		}
	}

	/**
	 * @author 完成任务商任务完成接口
	 */
	@Transactional
	@RequestMapping("/finishTask")
	public void taskfinish(HttpServletResponse response, HttpServletRequest request) {
		MessageResult messageResult = new MessageResult();
		String taskid = request.getParameter("taskid");
		String imgUrl = request.getParameter("imgUrl");
		String imgUrlTwo = request.getParameter("imgUrlTwo");
		String accidentType = request.getParameter("accidentType");
		String parkid = request.getParameter("parkid");
		String branchid = request.getParameter("branchid");

		// 整备id插入整备信息表
		String reorgids = request.getParameter("reorgids");
		logger.info("=================任务ID" + taskid + "=================================");
		logger.info("=================完成状态" + accidentType + "===========================");
		logger.info("=================车场ID" + parkid + "=================================");
		logger.info("=================网点" + branchid + "=================================");
		logger.info("=================整备" + reorgids + "=================================");
		try {
			VehicleSite vs = new VehicleSite();
			TaskInfo taskInfo = vehicleUnLockService.selectByPrimaryKey(Integer.parseInt(taskid));
			taskInfo.setAccidentType(Integer.parseInt(accidentType));
			Integer orderId = taskInfo.getOrderid();
			Order order = orderService.selectByPrimaryKey(orderId);
			int result = 0;

			// 结束订单信息
			if (order != null) {
				Integer customerId = order.getCustomerid();
				result = ControlService.vehicleControl(customerId, orderId, 3, null, null, "2",2);
			}

			if (StringUtils.isEmpty(parkid) && StringUtils.isEmpty(branchid)) {
				Vehicle vh = vehicleService.selectByPrimaryKey(taskInfo.getVehicleid());
				int siteid = selectSiteid(vh.getSn());
				if (siteid != 0) {
					vs.setId(siteid);
				} else {
					Map<String, Object> params = new HashMap<String, Object>();
					HashMap<String, Object> dataMap = new HashMap<>();
					List<Position> list = VehicleControlUtil.getVehicleLocationBaiDuAndCarLifeFromSn(vh.getSn());
					Position position = list.get(0);
					ServiceCity city = null;

					// 通过坐标获取城市信息
					city = this.cityService.getBaiduServiceCityByGPS(position.getX(), position.getY());
					params.put("cityId", city.getId());

					Parkinglot parkinglot = parkinglotService.findParkinglotCanCharging(params, position.getX(),
							position.getY());
					if (parkinglot == null) {
						messageResult.setData(dataMap);
						messageResult.setCode(ConstantUtil.M_EXCEPTION);
						messageResult.setMessage("车辆在允许的还车区域内");
						this.out(response, messageResult);
						return;
					}

					if (parkinglot.getParktype() != null) {
						EfenceBaseType efenceType;
						try {
							efenceType = EfenceBuilder.BuildEfence(parkinglot.getParktype(),
									parkinglot.getCoordinatepoints());
							EfenceState efenceState = efenceType.GetEfenceState(Double.parseDouble(position.getX()),
									Double.parseDouble(position.getY()));
							if (EfenceState.In.equals(efenceState)) {
								parkid = String.valueOf(parkinglot.getCountyid());
								branchid = String.valueOf(parkinglot.getId());
							}
						} catch (Exception e) {
							messageResult.setCode(ConstantUtil.M_EXCEPTION);
							messageResult.setMessage("获取站点围栏信息错误");
							this.out(response, messageResult);
							return;
						}
					}

					if (StringUtils.isBlank(branchid)) {
						messageResult.setCode(ConstantUtil.M_EXCEPTION);
						messageResult.setMessage("车辆未在允许的还车区域内");
						this.out(response, messageResult);
						return;
					}
				}
			}

			VehicleLock lock = new VehicleLock(taskInfo.getVehicleid().toString());
			String branchId = branchid;
			String parkId = parkid;
			String ret = lock.wrap(new Callable<String>() {
				@Override
				public String call() {

					if (taskInfo != null && taskInfo.getTaskstatus() != 1 && taskInfo.getTaskstatus() != 0) {
						if (taskInfo.getTaskstatus() == 4) {
							logger.info("当前任务已完成,请刷新 " + taskInfo.getId());
							return ConstantUtil.M_PARAMTER_NULL;
						} else {
							if (branchId != null && !"".equals(branchId)) {
								List<VehicleSite> list = vehicleUnLockService
										.getVehicleSiteLists(Integer.parseInt(branchId));
								if (list.size() == 0) {
									logger.info("该网点暂无车位" + taskInfo.getId());
									return ConstantUtil.M_SITENO;
								}
							} else {
								if (parkId != null && !"".equals(parkId)) {
									List<VehicleSite> list = vehicleUnLockService
											.getVehicleSiteList(Integer.parseInt(parkId));
									if (list.size() == 0) {
										logger.info("该网点暂无车位" + taskInfo.getId());
										return ConstantUtil.M_SITENO;
									}
								}
							}
							Calendar now = Calendar.getInstance(); // 获取当前系统时间
							Calendar calendar = Calendar.getInstance();
							calendar.setTime(taskInfo.getAllocationtime());
							long timeOne = now.getTimeInMillis();
							long timeTwo = calendar.getTimeInMillis();
							boolean flag = true;

							// 校验超时日期是否小于一分钟 add cjl
							if (taskInfo.getChargingtime() != null) { // 充电任务
								Long min = UtilTimeFormatter.seconds(new Date(), taskInfo.getAllocationtime(),
										taskInfo.getChargingtime(), taskInfo.getCountdown());
								if (min != null && min < 60) {
									flag = false;
								}
							} else {
								Long min = UtilTimeFormatter.seconds(new Date(), taskInfo.getAllocationtime(), null,
										taskInfo.getCountdown());
								if (min != null && min < 60) {
									flag = false;
								}
							}
							if (flag) {
								if (taskInfo.getAllocationtime() != null && taskInfo.getTasktype() == 0) {
									if (taskInfo.getChargingtime() != null
											&& taskInfo.getChargingtime().toString().equals("0.5")) {// 充电时间为半个小时
										int minute = new Long((timeOne - timeTwo) / (1000 * 60)).intValue();// 转化minute搜索
										if (taskInfo.getCountdown() != null
												&& (minute - 30) > taskInfo.getCountdown()) {
											taskInfo.setTimeout(minute - taskInfo.getCountdown() - 30);
										}
									} else if (taskInfo.getChargingtime() != null
											&& taskInfo.getChargingtime().toString().equals("1")) {// 充电时间为一个小时
										int minute = new Long((timeOne - timeTwo) / (1000 * 60)).intValue();// 转化minute搜索
										if (taskInfo.getCountdown() != null
												&& (minute - 60) > taskInfo.getCountdown()) {
											taskInfo.setTimeout(minute - taskInfo.getCountdown() - 60);
										}
									} else if (taskInfo.getChargingtime() != null
											&& taskInfo.getChargingtime().toString().equals("1.5")) {// 一个半小时
										int minute = new Long((timeOne - timeTwo) / (1000 * 60)).intValue();// 转化minute搜索
										if (taskInfo.getCountdown() != null
												&& (minute - 90) > taskInfo.getCountdown()) {
											taskInfo.setTimeout(minute - taskInfo.getCountdown() - 90);
										}
									} else if (taskInfo.getChargingtime() != null
											&& taskInfo.getChargingtime().toString().equals("2")) {// 俩个小时
										int minute = new Long((timeOne - timeTwo) / (1000 * 60)).intValue();// 转化minute搜索
										if (taskInfo.getCountdown() != null
												&& (minute - 120) > taskInfo.getCountdown()) {
											taskInfo.setTimeout(minute - taskInfo.getCountdown() - 120);
										}
									} else if (taskInfo.getChargingtime() == null
											|| taskInfo.getChargingtime().toString().equals("")) {
										int minute = new Long((timeOne - timeTwo) / (1000 * 60)).intValue();// 转化minute搜索
										if (taskInfo.getCountdown() != null && minute > taskInfo.getCountdown()) {
											taskInfo.setTimeout(minute - taskInfo.getCountdown());
										}
									}
								} else {
									int minute = new Long((timeOne - timeTwo) / (1000 * 60)).intValue();// 转化minute搜索
									if (taskInfo.getCountdown() != null && minute > taskInfo.getCountdown()) {
										taskInfo.setTimeout(minute - taskInfo.getCountdown());
									}
								}
							} else {
								taskInfo.setTimeout(0);// 小于1分钟
							}
							if (accidentType != null && !accidentType.equals("")) {
								taskInfo.setAccidentType(Integer.parseInt(accidentType));
							}
							taskInfo.setAccomplishtime(new Date());
							int res = vehicleUnLockService.updateByPrimaryKeySelective(reorgids, taskInfo, imgUrl,
									imgUrlTwo, parkId, branchId, vs);

							if (res == 1) {
								Vehicle vh = vehicleService.selectByPrimaryKey(taskInfo.getVehicleid());
								carManagerLogService.insertLog(taskInfo.getTaskuserid(),
										TaskType.valueOf(taskInfo.getTasktype()).getName() + " 任务完成 车牌号:"
												+ (vh != null ? vh.getPlatenumber() : "未知") + " \r\n任务单号:"
												+ taskInfo.getTaskNo());
								logger.info("任务完成" + taskInfo.getId());
								return ConstantUtil.M_SUCCESS;
							} else {
								logger.info("任务完成失败了,请稍后再试" + taskInfo.getId());
								return String.valueOf(res);
							}
						}
					} else {
						logger.info("请操作开锁功能" + taskInfo.getId());
						return ConstantUtil.M_PARAMTER_NULL;
					}
				}
			});

			if (ret.equals(ConstantUtil.M_SUCCESS)) {
				messageResult.setData(taskInfo.getOrderkey());
				messageResult.setCode(ConstantUtil.M_SUCCESS);
				messageResult.setMessage("任务完成成功");
				this.out(response, messageResult);
			} else {
				messageResult.setData("0");
				messageResult.setCode(ret);
				messageResult.setMessage("任务完成失败");
				this.out(response, messageResult);
			}
		} catch (Exception ex) {
			messageResult.setData("");
			messageResult.setCode(ConstantUtil.M_EXCEPTION);
			messageResult.setMessage("任务完成失败");
			this.out(response, messageResult);
			ex.printStackTrace();
		}
	}

	/***
	 * 根据任务生成e代驾订单(静态方法供外部调用)
	 * 
	 * @param taskid
	 */
	public static MessageResult createOrderByTask(Integer taskId, String customerId) {
		AgentController agent = new AgentController();
		return agent.createOrderByTaskId(taskId, customerId);
	}

	/***
	 * 选择站点
	 * 
	 * @param sn
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public int selectSiteid(String sn) {
		int result = 0;
		int parkId = 0;
		int branchId = 0;
		Integer siteID = 0;
		String str = VehicleControlUtil.getGpsInfoFromSn(sn); // 获取原始GPS坐标 ADD
																// CJL
		if (str != null && !"".equals(str)) {
			Map<Object, Object> m = JSONProcesser.parseDataToMap(str);
			if ((double) m.get("result") == 1 && m.get("cars") != null
					&& ((List<Map<Object, Object>>) m.get("cars")).size() > 0) {
				List<Map<Object, Object>> listdetail = (List<Map<Object, Object>>) m.get("cars");
				if (listdetail != null && listdetail.size() > 0) {
					Map<Object, Object> map = listdetail.get(0);
					String lat = map.get("latitude").toString();
					String lon = map.get("longitude").toString();
					List<Parkinglot> parkList = getEfenceByGPS(Double.parseDouble(lon), Double.parseDouble(lat), 1);
					if (parkList == null || parkList.size() == 0) {
						// 车辆不在任何还车区域内
						return result;
					} else {
						int type = 0; // 0车场 1网点
						// 调用接口判断车辆是否在还车区域内,如果在返回网点或车场的id
						for (int i = 0; i < parkList.size(); i++) {
							Parkinglot parkinglot = parkList.get(i);
							if (parkinglot.getParktype() != null) {
								EfenceBaseType efenceType;
								try {
									efenceType = EfenceBuilder.BuildEfence(parkinglot.getParktype(),
											parkinglot.getCoordinatepoints());
									EfenceState efenceState = efenceType.GetEfenceState(Double.parseDouble(lon),
											Double.parseDouble(lat));
									if (EfenceState.In.equals(efenceState)) {
										parkId = parkinglot.getCountyid();
										branchId = parkinglot.getId();
										type = parkinglot.getStatus();
										break;
									}
								} catch (Exception e) {
									// TODO Auto-generated catch block
									// e.printStackTrace();
								}
							}
						}

						// 如果等于0 说明所有区域都不符合还车条件
						if (parkId == 0 && branchId == 0) {
							return result;
						}

						// 根据返回的车场或网点id,查找是否有车位可以进行还车
						if (type == 0) {
							// 如果是车场
							siteID = this.vehicleUnLockService.selectSiteIDByID(parkId);
							branchId = 0;
							if (siteID == null) {
								return 0;
							}
							return siteID;
						} else {
							// 如果是网点
							siteID = this.vehicleUnLockService.selectSiteIDByBranchID(branchId);
							if (siteID == null) {
								return 0;
							}
							return siteID;
						}
					}
				}
				return result;
			}
			return result;
		}
		return result;
	}

	/***
	 * 通过当前车辆GPS点获取可以使用的车场或网点还车范围信息
	 * 
	 * @param lng
	 * @param lat
	 * @param Type
	 * @return
	 */
	public List<Parkinglot> getEfenceByGPS(double lng, double lat, int Type) {
		ReturnForInterface rfi = new ReturnForInterface();

		String resutl = TengXunAPIUtil.getDetailByGPS(lng, lat, Type);
		if (!StringUtils.isBlank(resutl)) {
			// 将地图返回json转化为实体
			net.joystart.mapCoordinates.entity.ReturnResult RR = (net.joystart.mapCoordinates.entity.ReturnResult) JSONProcesser
					.jsonProcesser(resutl, net.joystart.mapCoordinates.entity.ReturnResult.class);

			if (RR != null) {
				// 获取城市的名称
				String CityName = RR.getResult().getAddress_component().getCity();
				// 获取城市名称的前2个字
				String smallCityName = "";
				if (!StringUtils.isBlank(resutl) && !StringUtils.isBlank(CityName)) {
					smallCityName = CityName.substring(0, 2);
				}

				// 根据2个城市名字筛选获取所有城市对应的id
				Map<String, Object> params = new HashMap<String, Object>();
				params.put("fullname", "%" + CityName + "%");
				params.put("name", "%" + smallCityName + "%");

				// 获取当前时间的小时和分钟
				Calendar calendar_as = Calendar.getInstance();

				Date dtnow = new Date();
				SimpleDateFormat sdf = new SimpleDateFormat("HHmm");

				String curtime = sdf.format(dtnow);

				params.put("minsec", Integer.valueOf(curtime));

				return vehicleUnLockService.selectEfenceByCity(params);
			}
		}

		return null;
	}

	/***
	 * 生成e代驾签名
	 * 
	 * @param params
	 * @param md5_key
	 * @return
	 */
	public boolean checkToken(String token) {
		String sql = "SELECT * FROM t_base_task_token WHERE token=‘" + token + "‘";
		List<Map<String, Object>> result = DataBaseUtil.query(sql);
		if (result == null || result.size() == 0) {
			return false;
		}
		return true;
	}

	/***
	 * 生成e代驾签名
	 * 
	 * @param params
	 * @param md5_key
	 * @return
	 */
	public String getSign(Map<String, String> params, String md5_key) {
		Map<String, String> sParaNew = paraFiltere(params);
		String preSignStr = createLinkString(sParaNew);
		String tmp = sign(preSignStr);
		return sign(tmp + md5_key);
	}

	/**
	 * 除去数组中的空值和签名参数
	 * 
	 * @param sArray
	 *            签名参数组
	 * @return 去掉空值与签名参数后的新签名参数组
	 */
	public Map<String, String> paraFilter(Map<String, String> sArray) {

		Map<String, String> result = new HashMap<String, String>();

		if (sArray == null || sArray.size() <= 0) {
			return result;
		}

		for (String key : sArray.keySet()) {
			String value = sArray.get(key);
			if (value == null || value.equals("") || key.equalsIgnoreCase("sign") || key.equalsIgnoreCase("msg")) {
				continue;
			}
			result.put(key, value);
		}

		return result;
	}

	/**
	 * 除去数组中的空值和签名参数
	 * 
	 * @param sArray
	 *            签名参数组
	 * @return 去掉空值与签名参数后的新签名参数组
	 */
	public Map<String, String> paraFiltere(Map<String, String> sArray) {

		Map<String, String> result = new HashMap<String, String>();

		if (sArray == null || sArray.size() <= 0) {
			return result;
		}

		for (String key : sArray.keySet()) {
			String value = sArray.get(key);
			if (value == null || value.equals("") || key.equalsIgnoreCase("sign") || key.equalsIgnoreCase("msg")) {
				result.put(key, "");
				continue;
			}
			result.put(key, value);
		}

		return result;
	}

	/**
	 * 把数组所有元素排序,并按照“参数=参数值”的模式用“&”字符拼接成字符串
	 * 
	 * @param params
	 *            需要排序并参与字符拼接的参数组
	 * @return 拼接后字符串
	 */
	public String createLinkString(Map<String, String> params) {

		List<String> keys = new ArrayList<String>(params.keySet());
		Collections.sort(keys);
		String prestr = "";
		for (int i = 0; i < keys.size(); i++) {
			String key = keys.get(i);
			String value = params.get(key);
			prestr = prestr + key + "=" + value;
		}
		return prestr;
	}

	/**
	 * 把数组所有元素排序,并按照“参数=参数值”的模式用“&”字符拼接成字符串
	 * 
	 * @param params
	 *            需要排序并参与字符拼接的参数组
	 * @return 拼接后字符串
	 */
	public String getSendParam(Map<String, String> params) {

		List<String> keys = new ArrayList<String>(params.keySet());
		Collections.sort(keys);
		String prestr = "";
		for (int i = 0; i < keys.size(); i++) {
			String key = keys.get(i);
			String value = params.get(key);
			if (i == keys.size() - 1) {
				prestr = prestr + key + "=" + value;
			} else {
				prestr = prestr + key + "=" + value + "&";
			}
		}
		return prestr;
	}

	/**
	 * 签名字符串
	 * 
	 * @param text
	 *            需要签名的字符串
	 * @param key
	 *            密钥
	 * @param input_charset
	 *            编码格式
	 * @return 签名结果
	 */
	public String sign(String text) {
		return DigestUtils.md5Hex(getContentBytes(text));
	}

	/**
	 * @param content
	 * @param charset
	 * @return
	 * @throws SignatureException
	 * @throws UnsupportedEncodingException
	 */
	private byte[] getContentBytes(String content) {
		try {
			return content.getBytes(ZCloudSignConfig.charset);
		} catch (UnsupportedEncodingException e) {
			throw new RuntimeException("MD5签名过程中出现错误,指定的编码集不对,");
		}
	}

	/**
	 * 故障完成逻辑 add cjl
	 */
	@RequestMapping("/faultFinishTask")
	public void faultFinishTask(HttpServletResponse response, HttpServletRequest request) {
		MessageResult messageResult = new MessageResult();
		String taskid = request.getParameter("taskid");
		if (!taskid.equals("null")) {
			TaskInfo taskInfo = vehicleUnLockService.selectByPrimaryKey(Integer.parseInt(taskid));
			List<Integer> list = this.vehicleUnLockService.selectByPrimaryKeyVehidInt(taskInfo.getVehicleid());
			if (list != null && list.size() > 0) {//防止车位绑定重复 因为故障完成不需要开锁操作无法删除车位关系
				 vehicleUnLockService.deleteByPrimaryKeyForEach(list);
			}
			Order order = orderService.selectByPrimaryKey(taskInfo.getOrderid());
			order.setOrderstatus(10);
			order.setId(taskInfo.getOrderid());
			orderService.updateByPrimaryKeySelectiveStaus(order);//故障完成无需开锁,所以订单状体强制改成10
			// 结束订单信息
			if (taskInfo.getOrderid() != null) {
				int result = ControlService.vehicleControl(order.getCustomerid(), order.getId(), 3, null, null, "2",1);
			}
			Vehicle vehicle = vehicleService.selectByPrimaryKey(taskInfo.getVehicleid());
			int recReport = vehicleUnLockService.getFaultReportCount(vehicle.getPlatenumber());
			if (recReport > 0) {
				messageResult.setCode(ConstantUtil.M_EXCEPTION);
				messageResult.setMessage("有未处理完的故障报修,请处理后再上报");
				this.out(response, messageResult);
				return;
			} else {
				taskInfo.setTaskstatus(5);
				int res = vehicleUnLockService.updateTaskInfo(taskInfo);
				if (res != 0) {
					MessageTemplate mTemplate = messageTemplateService
							.selectTitleAndContentByIdentification(ConstantUtil.E_FAULTREPORT);
					Parkinglot parkinglot = vehicleService.selectByPrimaryKeyParkinglot(vehicle.getParkid());
					CarManager carManager =carManagerService.selectByPrimaryKey(taskInfo.getTaskuserid());
					String content = mTemplate.getContent().replaceAll("【plateNumber】", vehicle.getPlatenumber());
					content = content.replaceAll("【name】", carManager.getName());
					content = content.replaceAll("【phone】", carManager.getUsername());
					if(mTemplate!=null)
					{
					  PostMsgHttpContent.sendMessage(parkinglot.getTelephone(),content);
					  logger.info("<----------------故障完成发短信:短信发送成功" + "---------------------->");
					}
					else
					{
					  logger.info("<----------------故障完成发短信:短信模板为空" + "---------------------->"); 
					}
					
					carManagerLogService.insertLog(taskInfo.getTaskuserid(), "上报故障,车牌号:" + vehicle.getPlatenumber());// +
					// "
					// 故障ID:"
					// +
					// faultReport.getId()
					messageResult.setCode(ConstantUtil.M_SUCCESS);
					messageResult.setMessage("故障上报成功");
					this.out(response, messageResult);
				} else {
					messageResult.setCode(ConstantUtil.M_EXCEPTION);
					messageResult.setMessage("故障上报失败了,请稍后再试");
					this.out(response, messageResult);
				}
			}
		} else {
			messageResult.setCode(ConstantUtil.M_PARAMTER_NULL);
			messageResult.setMessage("无任务信息");
			this.out(response, messageResult);
		}

	}
}

 

以上是关于JAVA直接跳转到HTML5页面的主要内容,如果未能解决你的问题,请参考以下文章

java 如何在登录之后跳转到之前想跳转的页面?

通过手机点了这个链接之后可以跳转到微信支付,这个源码怎么写

html5页面上的按钮怎么模拟点击

android内嵌html5页面不能播放视频

用java怎样编写登录页面,成功登录跳转到下一个页面,求代码

ViewPager系列:代码控制直接跳转到某一个页面