| | |
| | | package com.lotaai.canguiayw; |
| | | |
| | | import android.content.Context; |
| | | import android.graphics.Canvas; |
| | | import android.graphics.Color; |
| | | import android.graphics.Paint; |
| | | import android.graphics.Rect; |
| | | import android.os.Bundle; |
| | | import android.os.Handler; |
| | | import android.os.Message; |
| | | import android.text.Editable; |
| | | import android.text.InputType; |
| | | import android.view.LayoutInflater; |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | | import android.widget.Button; |
| | | import android.widget.EditText; |
| | | import android.widget.TextView; |
| | | import android.widget.Toast; |
| | | |
| | | import androidx.fragment.app.Fragment; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.bin.david.form.core.SmartTable; |
| | | import com.bin.david.form.core.TableConfig; |
| | | import com.bin.david.form.data.CellInfo; |
| | | import com.bin.david.form.data.column.Column; |
| | | import com.bin.david.form.data.format.bg.IBackgroundFormat; |
| | | import com.bin.david.form.data.format.draw.IDrawFormat; |
| | | import com.bin.david.form.data.style.FontStyle; |
| | | import com.bin.david.form.data.table.TableData; |
| | | import com.blankj.utilcode.util.CacheDiskUtils; |
| | | import com.blankj.utilcode.util.DeviceUtils; |
| | | import com.blankj.utilcode.util.LogUtils; |
| | | import com.blankj.utilcode.util.ScreenUtils; |
| | | import com.blankj.utilcode.util.TimeUtils; |
| | | import com.lotaai.canguiayw.common.HttpLoggerInterceptor; |
| | | import com.lotaai.canguiayw.common.HttpUrlDefine; |
| | | import com.lotaai.canguiayw.common.SettingConfig; |
| | | import com.lotaai.canguiayw.device.CanguiStatus; |
| | | import com.lotaai.canguiayw.device.service.CrontrolGridModel; |
| | | import com.lotaai.canguiayw.sqllitedb.GridModel; |
| | | import com.lotaai.canguiayw.sqllitedb.Order; |
| | | import com.lotaai.canguiayw.sqllitedb.OrderDetail; |
| | | import com.lotaai.canguiayw.sqllitedb.SqlliteDbManage; |
| | | import com.pranavpandey.android.dynamic.toasts.DynamicToast; |
| | | |
| | | import org.w3c.dom.Text; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | import okhttp3.Call; |
| | | import okhttp3.Callback; |
| | | import okhttp3.FormBody; |
| | | import okhttp3.OkHttpClient; |
| | | import okhttp3.Request; |
| | | import okhttp3.RequestBody; |
| | | import okhttp3.Response; |
| | | |
| | | public class CunCanFragment extends Fragment { |
| | | |
| | | private View root; |
| | | private Context context; |
| | | private EditText editText; |
| | | private SmartTable orderDetailTable; |
| | | private TextView gekouTxt; |
| | | private TextView orderNotxt; |
| | | |
| | | @Override |
| | | public void onCreate(Bundle savedInstanceState) { |
| | |
| | | if (root == null) { |
| | | root = inflater.inflate(R.layout.framgment_cuncan, container, false); |
| | | } |
| | | DynamicToast.Config.getInstance().setTextSize(30).apply(); |
| | | context = container.getContext(); |
| | | editText = (EditText)root.findViewById(R.id.edt_borrow_case_number); |
| | | gekouTxt = root.findViewById(R.id.geKoueText); |
| | | orderNotxt = root.findViewById(R.id.orderNoText); |
| | | editText.setInputType(InputType.TYPE_NULL); // 屏蔽软键盘 |
| | | View.OnClickListener clickListener = new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | int index = editText.getSelectionEnd(); |
| | | Editable editable = editText.getText(); |
| | | int key = v.getId(); |
| | | if (key == R.id.borrow_bt_delete) { |
| | | if (0 != index) { |
| | | editable.delete(index - 1, index); |
| | | } |
| | | } else if (key == R.id.borrow_bt_confirm) { |
| | | // 调用后台 |
| | | String gridNo = editable.toString(); |
| | | if (null == gridNo || "".equals(gridNo.trim())) { |
| | | DynamicToast.makeError(context, "取餐序号不能为空。", 3).show(); |
| | | return; |
| | | } else { |
| | | if (gridNo.length() !=4) { |
| | | editText.setText(""); |
| | | DynamicToast.makeError(context, "取餐序号输入错误,请重试。", 3).show(); |
| | | return; |
| | | } |
| | | } |
| | | //处理存餐的问题 |
| | | //1、查询订单,并判断是否已经存过餐,如果存过 |
| | | Order od = SqlliteDbManage.getInstance().selectOrtderByXuhao(gridNo); |
| | | if (od!=null){ |
| | | if (od.getState() == 0 || od.getState() == 1){ |
| | | LogUtils.i("orderNo:" + od.getOrderNo() + " state:" + od.getState()); |
| | | } |
| | | initOrderDetailTableView(od.getOrderNo()); |
| | | }else { |
| | | DynamicToast.makeError(context, "取餐序号不存在,请重试。", 3).show(); |
| | | initOrderDetailTableView(""); |
| | | } |
| | | } else { |
| | | Button button = (Button) v; |
| | | editable.insert(index, button.getText()); |
| | | } |
| | | } |
| | | }; |
| | | |
| | | View view1 = root.findViewById(R.id.borrow_bt1); |
| | | View view2 = root.findViewById(R.id.borrow_bt2); |
| | | View view3 = root.findViewById(R.id.borrow_bt3); |
| | | View view4 = root.findViewById(R.id.borrow_bt4); |
| | | View view5 = root.findViewById(R.id.borrow_bt5); |
| | | View view6 = root.findViewById(R.id.borrow_bt6); |
| | | View view7 = root.findViewById(R.id.borrow_bt7); |
| | | View view8 = root.findViewById(R.id.borrow_bt8); |
| | | View view9 = root.findViewById(R.id.borrow_bt9); |
| | | View view0 = root.findViewById(R.id.borrow_bt0); |
| | | View view11 = root.findViewById(R.id.borrow_bt_delete); |
| | | View view12 = root.findViewById(R.id.borrow_bt_confirm); |
| | | view1.setOnClickListener(clickListener); |
| | | view2.setOnClickListener(clickListener); |
| | | view3.setOnClickListener(clickListener); |
| | | view4.setOnClickListener(clickListener); |
| | | view5.setOnClickListener(clickListener); |
| | | view6.setOnClickListener(clickListener); |
| | | view7.setOnClickListener(clickListener); |
| | | view8.setOnClickListener(clickListener); |
| | | view9.setOnClickListener(clickListener); |
| | | view0.setOnClickListener(clickListener); |
| | | view11.setOnClickListener(clickListener); |
| | | view12.setOnClickListener(clickListener); |
| | | initOrderDetailTableView(""); |
| | | return root; |
| | | } |
| | | |
| | | |
| | | public void initOrderDetailTableView(String orderNo){ |
| | | editText.setText(""); |
| | | gekouTxt.setText(""); |
| | | orderNotxt.setText(""); |
| | | Column<String> nameCol = new Column<>("名称", "itemName"); |
| | | nameCol.setComputeWidth(10); |
| | | Column<String> numCol = new Column<>("量", "num"); |
| | | numCol.setWidth(10); |
| | | nameCol.setComputeWidth(1); |
| | | |
| | | List<OrderDetail> details = new ArrayList<>(); |
| | | if (!"".equals(orderNo)) { |
| | | details = SqlliteDbManage.getInstance().selectOrtderDetails(orderNo); |
| | | if (details!=null && details.size()>0){ |
| | | //查找空余的格子进行分配 |
| | | GridModel model = SqlliteDbManage.getInstance().selectFreeGrid(); |
| | | String gStr = CrontrolGridModel.getGridNoStr(model.getGuiHao(),model.getGridNo()); |
| | | gekouTxt.setText(gStr); |
| | | orderNotxt.setText(orderNo); |
| | | model.setState(1); |
| | | SqlliteDbManage.getInstance().addGrid(model); |
| | | //需要把order数据更新了 |
| | | Order od = SqlliteDbManage.getInstance().selectOrtder(orderNo); |
| | | od.setGridNo(CrontrolGridModel.getGridNoStr(model.getGuiHao(),model.getGridNo())); |
| | | od.setPutInDate(TimeUtils.getNowString()); |
| | | od.setState(1); |
| | | od.setGridNo(gStr); |
| | | SqlliteDbManage.getInstance().insertOrderInfo(od); |
| | | //需要将存餐信息同步到服务端 |
| | | cuncan(gStr,od.getOrderId()); |
| | | |
| | | }else { |
| | | DynamicToast.makeError(context, "未查询到订单", 3).show(); |
| | | } |
| | | } |
| | | |
| | | TableData<OrderDetail> tableData = new TableData<OrderDetail>("订单详情",details,nameCol, numCol); |
| | | //设置数据 |
| | | orderDetailTable = root.findViewById(R.id.table); |
| | | orderDetailTable.getConfig().setShowTableTitle(true); |
| | | orderDetailTable.getConfig().setTableTitleStyle(new FontStyle(30,Color.WHITE)); |
| | | // // 设置表格标题名称文字样式 |
| | | // setTable.getConfig().setTableTitleStyle(new FontStyle(30, Color.GREEN)); |
| | | orderDetailTable.getConfig().setMinTableWidth(ScreenUtils.getScreenWidth()/2 -40); |
| | | // 设置表格标题文字样式 |
| | | orderDetailTable.getConfig().setColumnTitleStyle(new FontStyle(30, Color.WHITE)); |
| | | |
| | | IBackgroundFormat backgroundFormat = new IBackgroundFormat() { |
| | | @Override |
| | | public void drawBackground(Canvas canvas, Rect rect, Paint paint) { |
| | | canvas.drawColor(getResources().getColor(R.color.DarkGray)); |
| | | } |
| | | }; |
| | | orderDetailTable.getConfig().setColumnTitleBackground(backgroundFormat); |
| | | // 设置表格主体内容文字样式 |
| | | orderDetailTable.getConfig().setContentStyle(new FontStyle(30, Color.WHITE)); |
| | | // setTable.setZoom(true,1,0.5f); //开启缩放功能 |
| | | orderDetailTable.getConfig().setShowXSequence(false); //去掉表格顶部字母 |
| | | orderDetailTable.getConfig().setShowYSequence(false); //去掉左侧数字 |
| | | |
| | | // 设置表格主标题 |
| | | orderDetailTable.setTableData(tableData); |
| | | |
| | | } |
| | | |
| | | |
| | | public void cuncan(String gridNo,String orderId) { |
| | | 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(); |
| | | |
| | | RequestBody body = new FormBody.Builder() |
| | | .add("equipmentUid", DeviceUtils.getUniqueDeviceId()) |
| | | .add("gridNo", gridNo) |
| | | .add("orderId", orderId).build(); |
| | | final Request request = new Request.Builder() |
| | | .url(HttpUrlDefine.equipmentCunCan) |
| | | .addHeader("language", "zh-CN") |
| | | .post(body) |
| | | .build(); |
| | | client.newCall(request).enqueue(new Callback() { |
| | | @Override |
| | | public void onFailure(Call call, IOException e) { |
| | | Message message = new Message(); |
| | | message.what = 0; |
| | | message.obj = "存餐同步失败!"; |
| | | showHandler.sendMessage(message); |
| | | } |
| | | |
| | | @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"))) { |
| | | |
| | | } else { |
| | | String string = obj.getString("msg"); |
| | | Message message = new Message(); |
| | | message.what = 0; |
| | | message.obj = "存餐失败:" +string; |
| | | showHandler.sendMessage(message); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | 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(); |
| | | } |
| | | } |
| | | }; |
| | | } |