| | |
| | | import android.content.Intent; |
| | | import android.os.Build; |
| | | import android.os.Bundle; |
| | | import android.os.Handler; |
| | | import android.os.Message; |
| | | import android.text.Editable; |
| | | import android.text.InputType; |
| | | import android.view.View; |
| | |
| | | import android.widget.Toast; |
| | | import androidx.appcompat.app.AppCompatActivity; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.blankj.utilcode.util.CacheDiskUtils; |
| | | import com.blankj.utilcode.util.DeviceUtils; |
| | | import com.blankj.utilcode.util.LogUtils; |
| | | import com.lotaai.canguiayw.common.HttpLoggerInterceptor; |
| | | import com.lotaai.canguiayw.common.HttpUrlDefine; |
| | | import com.lotaai.canguiayw.common.SettingConfig; |
| | | import com.lotaai.canguiayw.device.CanGuiCommand; |
| | | import com.lotaai.canguiayw.device.DeviceMessage; |
| | | import com.lotaai.canguiayw.device.DeviceType; |
| | | import com.lotaai.canguiayw.device.MessageType; |
| | | import com.lotaai.canguiayw.mqtt.DeviceAction; |
| | | import com.lotaai.canguiayw.sqllitedb.Order; |
| | | import com.lotaai.canguiayw.sqllitedb.SqlliteDbManage; |
| | | import com.pranavpandey.android.dynamic.toasts.DynamicToast; |
| | | |
| | | import org.greenrobot.eventbus.EventBus; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.logging.Logger; |
| | | |
| | | import okhttp3.Call; |
| | | import okhttp3.Callback; |
| | | import okhttp3.FormBody; |
| | | import okhttp3.OkHttpClient; |
| | | import okhttp3.Request; |
| | | import okhttp3.RequestBody; |
| | | import okhttp3.Response; |
| | | |
| | | public class TakeActivity extends AppCompatActivity { |
| | | private Context context; |
| | |
| | | context = TakeActivity.this; |
| | | editText = (EditText)findViewById(R.id.edt_borrow_case_number); |
| | | editText.setInputType(InputType.TYPE_NULL); // 屏蔽软键盘 |
| | | DynamicToast.Config.getInstance().setTextSize(30).apply(); |
| | | // 软键盘设置统一按钮监听方法,数字键直接将text内容填充到edittext中,删除和确认才设置事件 |
| | | View.OnClickListener clickListener = new View.OnClickListener() { |
| | | @Override |
| | |
| | | return; |
| | | } |
| | | //调用判断是否可以取餐 |
| | | takeCheckCode(""); |
| | | takeCheckCode(gridNo); |
| | | } |
| | | } else { |
| | | Button button = (Button) v; |
| | |
| | | } |
| | | |
| | | public void takeCheckCode(String code){ |
| | | Order order = SqlliteDbManage.getInstance().selectOrtderByTakeCode(code); |
| | | if (order == null || order.getGridNo() == ""){ |
| | | //代表取餐码错误 |
| | | HttpLoggerInterceptor loggingInterceptor = new HttpLoggerInterceptor(true); |
| | | OkHttpClient client = new OkHttpClient.Builder() |
| | | .connectTimeout(20, TimeUnit.SECONDS)//响应时间,读取时间 |
| | | .readTimeout(20, TimeUnit.SECONDS) |
| | | .callTimeout(20, TimeUnit.SECONDS) |
| | | .addInterceptor(loggingInterceptor)//添加日志拦截器 |
| | | .build(); |
| | | |
| | | LogUtils.i(CacheDiskUtils.getInstance().getString(SettingConfig.getInstance().Cache_Device_Code),code); |
| | | RequestBody body = new FormBody.Builder() |
| | | .add("equipmentCode", CacheDiskUtils.getInstance().getString(SettingConfig.getInstance().Cache_Device_Code)) |
| | | .add("takeCode", code).build(); |
| | | final Request request = new Request.Builder() |
| | | .url(HttpUrlDefine.equipmentTakeOut) |
| | | .addHeader("language", "zh-CN") |
| | | .post(body) |
| | | .build(); |
| | | client.newCall(request).enqueue(new Callback() { |
| | | @Override |
| | | public void onFailure(Call call, IOException e) { |
| | | DynamicToast.makeError(context, "取餐失败!", 3).show(); |
| | | } |
| | | |
| | | @Override |
| | | public void onResponse(Call call, Response response) throws IOException { |
| | | String result = response.body().string(); |
| | | LogUtils.i("获取到的数据:"+result); |
| | | JSONObject obj = JSONObject.parseObject(result); |
| | | if ("0".equals(obj.getString("code"))) { |
| | | String g = obj.getString("data"); |
| | | //发送mqtt 进行开门 |
| | | JSONObject json = new JSONObject(); |
| | | json.put("action", DeviceAction.CONTROLDEVICE.name()); |
| | | json.put(DeviceAction.doorIsOpen.name(), "1"); |
| | | json.put(DeviceAction.xiaoDuIsOpen.name(), "0"); |
| | | json.put(DeviceAction.jiareIsOpen.name(), "0"); |
| | | json.put(DeviceAction.dengGuangIsOpen.name(), "0"); |
| | | json.put("gridNo", g); |
| | | DeviceMessage deviceMessage = new DeviceMessage(); |
| | | deviceMessage.setMessageType(MessageType.MQTT.ordinal()); |
| | | deviceMessage.setMsgString(json.toJSONString()); |
| | | EventBus.getDefault().post(deviceMessage); |
| | | }else { |
| | | //开门取餐,并弹出取餐号 |
| | | String string = obj.getString("msg"); |
| | | Message msg = new Message(); |
| | | msg.what = 0; |
| | | msg.obj = "取餐失败:" + string; |
| | | showHandler.sendMessage(msg); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | private Handler showHandler = new Handler() { |
| | | @Override |
| | | public void handleMessage(Message msg) { |
| | | if (msg.what == 0) { |
| | | DynamicToast.makeError(context, msg.obj.toString(), 3).show(); |
| | | } else if (msg.what == 1) { |
| | | DynamicToast.makeSuccess(context, msg.obj.toString(), 3).show(); |
| | | } else { |
| | | DynamicToast.makeWarning(context, msg.obj.toString(), 3).show(); |
| | | } |
| | | } |
| | | }; |
| | | |
| | | } |