/** 取消预订 */ @PUT @Path("cancelorder") @Produces("application/json") public Representation cancelOrder(Representation entity) { JSONReader reader = new JSONValidatingReader(); HashMap result = null; HashMap returnInfo = new HashMap(); try { result = (HashMap) reader.read(entity.getText()); } catch (IOException e) { e.printStackTrace(); returnInfo.put(RestCallInfo.REST_STATUS, RestCallStatus.fail); returnInfo.put(RestCallInfo.REST_ERROR_CODE, RestCallErrorCode.json_format_error); return new JsonRepresentation(returnInfo); } if (result == null || !result.containsKey("sessionKey") || !result.containsKey("orderId")) { returnInfo.put(RestCallInfo.REST_STATUS, RestCallStatus.fail); returnInfo.put(RestCallInfo.REST_ERROR_CODE, RestCallErrorCode.json_format_error); return new JsonRepresentation(returnInfo); } String sessionKey = result.get("sessionKey").toString(); int orderId = Integer.parseInt(result.get("orderId").toString()); SLUser slUser = SLSessionManager.getSession(sessionKey); if (slUser == null) { returnInfo.put(RestCallInfo.REST_STATUS, RestCallStatus.fail); returnInfo.put(RestCallInfo.REST_ERROR_CODE, RestCallErrorCode.need_login); return new JsonRepresentation(returnInfo); } SLOrder slOrder = orderDao.getSLOrderByOrderId(orderId); if (!slOrder.getUserEmail().equals(slUser.getUserEmail()) && !slUser.getUserType().equals("管理员")) { returnInfo.put(RestCallInfo.REST_STATUS, RestCallStatus.fail); returnInfo.put(RestCallInfo.REST_ERROR_CODE, RestCallErrorCode.can_not_modify_other_person); return new JsonRepresentation(returnInfo); } slOrder.setStatus(ORDER_CANCElED); if (!orderDao.updateOrder(slOrder)) { returnInfo.put(RestCallInfo.REST_STATUS, RestCallStatus.fail); returnInfo.put(RestCallInfo.REST_ERROR_CODE, RestCallErrorCode.db_operate_error); return new JsonRepresentation(returnInfo); } returnInfo.put(RestCallInfo.REST_STATUS, RestCallStatus.success); returnInfo.put(RestCallInfo.REST_ERROR_CODE, RestCallErrorCode.no_error); return new JsonRepresentation(returnInfo); }