Commit e4eb73bf6e9a7f1874c5aa7470c7185562ece40b

Authored by 杜方
1 parent da545be8

畅游通标准:修复打印数据为空时报错

src/android_serialport_api/print_tool/MobilePrintTool.java
... ... @@ -14,6 +14,7 @@ import android.os.Bundle;
14 14 import android.os.Handler;
15 15 import android.os.Looper;
16 16 import android.os.Message;
  17 +import android.text.TextUtils;
17 18 import android.view.View;
18 19 import android.view.View.OnClickListener;
19 20 import android.view.WindowManager;
... ... @@ -95,17 +96,19 @@ public class MobilePrintTool extends Activity {
95 96 });
96 97 }
97 98  
98   - public void init(String info) {
99   - this.info = info;
100   - if (printer == null) {
101   - printer = new PrinterEscCmd();
102   - }
103   - type = SharedPreferences2Obj.getInstance(MobilePrintTool.this)
104   - .setName("MachineType").getObject("type", Integer.class);
105   - if (initBlu()) {
106   - initBS();
107   - }
108   - }
  99 + public void init(String info) {
  100 + LogUtil.d(TAG, "info = " + info);
  101 + this.info = info;
  102 + if (printer == null) {
  103 + printer = new PrinterEscCmd();
  104 + }
  105 + type = SharedPreferences2Obj.getInstance(MobilePrintTool.this)
  106 + .setName("MachineType").getObject("type", Integer.class);
  107 + LogUtil.d(TAG, "type = " + type);
  108 + if (initBlu()) {
  109 + initBS();
  110 + }
  111 + }
109 112  
110 113 private boolean initBlu() { // 判断是否有蓝牙功能
111 114 // 得到本地的适配器
... ... @@ -265,7 +268,7 @@ public class MobilePrintTool extends Activity {
265 268 break;
266 269 }
267 270  
268   - }
  271 + }
269 272  
270 273 private void print(final String str) {
271 274 if (isprint && isprint2) {
... ... @@ -385,59 +388,60 @@ public class MobilePrintTool extends Activity {
385 388 }
386 389 }
387 390  
388   - @SuppressLint("SimpleDateFormat") private void printThread(int printNum, String str) {
389   - for (int x = 0; x < printNum; x++) {
390   - if (x == 1 && isStatistic.equals("1")) {
391   - if (dialog != null) {
392   - dialog.dismiss();
393   - }
394   - return;
395   - }
396   - try {
397   - if (isStatistic != null && isStatistic.equals("1")) {
398   - printer.escPrintText(" 统计信息" + "\n");
399   - } else {
400   - printer.escPrintText(" 订单信息");
401   - // 当时重打小票的时候,多打一段字符
402   - int Select = SharedPreferences2Obj
403   - .getInstance(MobilePrintTool.this)
404   - .setName("SelectAction")
405   - .getObject("Select", Integer.class);
406   - if (Select == 2) {
407   - printer.escEnter();
408   - printer.escPrintText(" (重打小票)");
409   - }
410   - }
411   - printer.escEnter();
412   - } catch (Exception e) {
413   - e.printStackTrace();
414   - }
415   -
416   - if (str == null) {
417   - return;
418   - }
419   - // 打印信息
420   - try {
421   - if (isStatistic != null && isStatistic.equals("1")) {
422   - System.out.println(str);
423   - try {
424   - printer.escPrintText(str);// 订单信息
425   - } catch (Exception e) {
426   - e.printStackTrace();
427   - }
428   - } else {
429   - // 重打时间
430   - int Select = SharedPreferences2Obj
431   - .getInstance(MobilePrintTool.this)
432   - .setName("SelectAction")
433   - .getObject("Select", Integer.class);
434   - if (Select == 2) {
435   - SimpleDateFormat df = new SimpleDateFormat(
436   - "yyyy-MM-dd HH:mm:ss");// 设置日期格式
437   - printer.escPrintText("重打时间:" + df.format(new Date()));// new
438   - printer.escEnter();
439   - // Date()为获取当前系统时间
440   - }
  391 + @SuppressLint("SimpleDateFormat")
  392 + private void printThread(int printNum, String str) {
  393 + for (int x = 0; x < printNum; x++) {
  394 + if (x == 1 && isStatistic.equals("1")) {
  395 + if (dialog != null) {
  396 + dialog.dismiss();
  397 + }
  398 + return;
  399 + }
  400 + try {
  401 + if (isStatistic != null && isStatistic.equals("1")) {
  402 + printer.escPrintText(" 统计信息" + "\n");
  403 + } else {
  404 + printer.escPrintText(" 订单信息");
  405 + // 当时重打小票的时候,多打一段字符
  406 + int Select = SharedPreferences2Obj
  407 + .getInstance(MobilePrintTool.this)
  408 + .setName("SelectAction")
  409 + .getObject("Select", Integer.class);
  410 + if (Select == 2) {
  411 + printer.escEnter();
  412 + printer.escPrintText(" (重打小票)"+ "\n");
  413 + }
  414 + }
  415 + printer.escEnter();
  416 + } catch (Exception e) {
  417 + e.printStackTrace();
  418 + }
  419 +
  420 + if (TextUtils.isEmpty(str)) {
  421 + return;
  422 + }
  423 + // 打印信息
  424 + try {
  425 + if (isStatistic != null && isStatistic.equals("1")) {
  426 + System.out.println(str);
  427 + try {
  428 + printer.escPrintText(str);// 订单信息
  429 + } catch (Exception e) {
  430 + e.printStackTrace();
  431 + }
  432 + } else {
  433 + // 重打时间
  434 + int Select = SharedPreferences2Obj
  435 + .getInstance(MobilePrintTool.this)
  436 + .setName("SelectAction")
  437 + .getObject("Select", Integer.class);
  438 + if (Select == 2) {
  439 + SimpleDateFormat df = new SimpleDateFormat(
  440 + "yyyy-MM-dd HH:mm:ss");// 设置日期格式
  441 + printer.escPrintText("重打时间:" + df.format(new Date()));// new
  442 + printer.escEnter();
  443 + // Date()为获取当前系统时间
  444 + }
441 445  
442 446 printer.escPrintText(str);// 订单信息
443 447 printer.escEnter();
... ...
src/com/ectrip/cyt/center/ReprintHandle.java
... ... @@ -34,6 +34,7 @@ import com.ectrip.cyt.response.OrderConsumedItem;
34 34 import com.ectrip.cyt.response.QueryConsumedDetailResponse;
35 35 import com.ectrip.cyt.response.ReprintVoucherResponse;
36 36 import com.ectrip.cyt.ui.BaseActivity;
  37 +import com.ectrip.cyt.utils.LogUtil;
37 38 import com.ectrip.cyt.utils.SharedPreferences2Obj;
38 39 import com.ectrip.trips.check.R;
39 40 import com.ectrip.trips.net.DataTool;
... ... @@ -42,467 +43,472 @@ import com.ectrip.trips.net.HttpHelper;
42 43 /**
43 44 * @author jigo 补打小票
44 45 */
45   -public class ReprintHandle implements ReprintInteface,OnItemClickListener {
46   - private String orid;
47   - private View v;
48   - private AtomicBoolean isClick;
49   - private BaseActivity activity;
50   - private Integer type;
51   - private Resources resources;
52   -
53   - @Override
54   - public void reprintHandle(String orid, ListOnclickCallback callback,
55   - final View v, final AtomicBoolean isClick, BaseActivity activity) {
56   - this.resources = activity.getResources();
57   - this.orid = orid;
58   - this.v = v;
59   - this.isClick = isClick;
60   - this.activity = activity;
61   - type = SharedPreferences2Obj.getInstance(activity)
62   - .setName("MachineType").getObject("type", Integer.class);
63   - if (isClick.get()) {
64   - isClick.set(false);
65   - v.setClickable(false);
66   - HttpHelper.getInstance(activity).queryConsumedDetail(orid,
67   - new ReprintListCallback());
68   - } else {
69   - activity.MToast(activity, "点击过快,稍等两秒!", Toast.LENGTH_SHORT);
70   - }
71   - }
72   -
73   - /**
74   - * @author jigo 获取补打列表
75   - */
76   - public class ReprintListCallback extends HttpCallback<DataTrans> {
77   - private String signed;
78   - private String data;
79   - ProgressDialog progressDialog = null;
80   -
81   - @Override
82   - public void onPreCallback() {
83   - if (progressDialog == null) {
84   - // 显示ProgressDialog
85   - progressDialog = new ProgressDialog(activity);
86   - progressDialog.setMessage(resources
87   - .getString(R.string.get_ticket_info));
88   - progressDialog.setCanceledOnTouchOutside(false);
89   - progressDialog.setCancelable(true);
90   - if (type == 8) {
91   - progressDialog.getWindow().setType(
92   - WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
93   - }
94   - try {
95   - if (progressDialog != null && !progressDialog.isShowing()) {
96   - progressDialog.show();
97   - }
98   - } catch (Exception e) {
99   - e.printStackTrace();
100   - }
101   - } else {
102   - progressDialog.setMessage(resources
103   - .getString(R.string.get_ticket_info));
104   - }
105   - }
106   -
107   - @Override
108   - public void onCompletedCallback(DataTrans result) {
109   - }
110   -
111   - @Override
112   - public void afterCompletedCallback(DataTrans result) {
113   - if (result != null) {
114   - signed = result.getSigned();
115   - data = result.getData();
116   - parse2(result.getData(), QueryConsumedDetailResponse.class,activity);
117   - } else {
118   - isClick.set(true);
119   - v.setClickable(true);
120   - if (progressDialog != null && progressDialog.isShowing()) {
121   - try {
122   - progressDialog.dismiss();
123   - } catch (Exception e) {
124   - e.printStackTrace();
125   - } catch (Throwable e) {
126   - e.printStackTrace();
127   - }
128   - }
129   - activity.MToast(activity,
130   - resources.getString(R.string.get_order_error),
131   - Toast.LENGTH_SHORT);
132   - }
133   -
134   - }
135   -
136   - @Override
137   - public void onAgainParseCallback(Object parse) {
138   - isClick.set(true);
139   - v.setClickable(true);
140   - if (progressDialog != null && progressDialog.isShowing()) {
141   - try {
142   - progressDialog.dismiss();
143   - } catch (Exception e) {
144   - e.printStackTrace();
145   - } catch (Throwable e) {
146   - e.printStackTrace();
147   - }
148   - }
149   - if (parse != null) {
150   - QueryConsumedDetailResponse detailResponse = (QueryConsumedDetailResponse) parse;
151   - String code = detailResponse.getCode();
152   - if (code != null && OrderCode.SUCESS.getValue().equals(code)) {
153   - if (signed == null
154   - || signed.equals(DataTool.getSign(MyApp
155   - .getInstance().getSignkey(), data))) {
156   - // 获取一个订单中每个记录
157   - List<OrderConsumedItem> items = detailResponse
158   - .getOrderConsumedItems();
159   - dialog(items);
160   - } else {
161   - onFailureCallback(resources
162   - .getString(R.string.sign_not_pass));
163   - activity.MToast(activity,
164   - resources.getString(R.string.sign_not_pass),
165   - Toast.LENGTH_SHORT);
166   - }
167   - } else {
168   - onFailureCallback(detailResponse.getDescribe());
169   - activity.MToast(activity, detailResponse.getDescribe(),
170   - Toast.LENGTH_SHORT);
171   - }
172   - }
173   - }
174   -
175   - @Override
176   - public void onFailureCallback(String FailureStr) {
177   - isClick.set(true);
178   - v.setClickable(true);
179   - if (progressDialog != null && progressDialog.isShowing()) {
180   - try {
181   - progressDialog.dismiss();
182   - } catch (Exception e) {
183   - e.printStackTrace();
184   - } catch (Throwable e) {
185   - e.printStackTrace();
186   - }
187   - }
188   - try {
189   - activity.MToast(activity, FailureStr, Toast.LENGTH_SHORT);
190   - } catch (Exception e) {
191   - e.printStackTrace();
192   - }
193   - }
194   -
195   - @Override
196   - public void onStopCallback() {
197   - }
198   - }
199   -
200   - /**
201   - * @author jigo 获取打票信息
202   - */
203   - public class ReprintInfoCallback extends HttpCallback<DataTrans> {
204   -
205   - private String signed;
206   - private String data;
207   - ProgressDialog progressDialog = null;
208   -
209   - @Override
210   - public void onPreCallback() {
211   - if (progressDialog == null) {
212   - // 显示ProgressDialog
213   - progressDialog = new ProgressDialog(activity);
214   - progressDialog.setMessage(resources
215   - .getString(R.string.ready_to_print));
216   - progressDialog.setCanceledOnTouchOutside(false);
217   - progressDialog.setCancelable(true);
218   - if (type == 8) {
219   - progressDialog.getWindow().setType(
220   - WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
221   - }
222   - try {
223   - if (progressDialog != null && !progressDialog.isShowing()) {
224   - progressDialog.show();
225   - }
226   - } catch (Exception e) {
227   - e.printStackTrace();
228   - }
229   - } else {
230   - progressDialog.setMessage(resources
231   - .getString(R.string.ready_to_print));
232   - }
233   - }
234   -
235   - @Override
236   - public void onCompletedCallback(DataTrans result) {
237   - }
238   -
239   - @Override
240   - public void afterCompletedCallback(DataTrans result) {
241   - if (result != null) {
242   - signed = result.getSigned();
243   - data = result.getData();
244   - parse2(result.getData(), ReprintVoucherResponse.class,activity);
245   - } else {
246   - isClick.set(true);
247   - v.setClickable(true);
248   - if (progressDialog != null && progressDialog.isShowing()) {
249   - try {
250   - progressDialog.dismiss();
251   - } catch (Exception e) {
252   - e.printStackTrace();
253   - } catch (Throwable e) {
254   - e.printStackTrace();
255   - }
256   - }
257   - activity.MToast(activity,
258   - resources.getString(R.string.get_order_error),
259   - Toast.LENGTH_SHORT);
260   - }
261   -
262   - }
263   -
264   - @Override
265   - public void onAgainParseCallback(Object parse) {
266   - isClick.set(true);
267   - v.setClickable(true);
268   - if (progressDialog != null && progressDialog.isShowing()) {
269   - try {
270   - progressDialog.dismiss();
271   - } catch (Exception e) {
272   - e.printStackTrace();
273   - } catch (Throwable e) {
274   - e.printStackTrace();
275   - }
276   - }
277   - if (parse != null) {
278   - ReprintVoucherResponse voucherResponse = (ReprintVoucherResponse) parse;
279   - String code = voucherResponse.getCode();
280   - if (code != null && OrderCode.SUCESS.getValue().equals(code)) {
281   - if (signed == null
282   - || signed.equals(DataTool.getSign(MyApp
283   - .getInstance().getSignkey(), data))) {
284   - // 获取一个订单中每个记录
  46 +public class ReprintHandle implements ReprintInteface, OnItemClickListener {
  47 + private String orid;
  48 + private View v;
  49 + private AtomicBoolean isClick;
  50 + private BaseActivity activity;
  51 + private Integer type;
  52 + private Resources resources;
  53 +
  54 + @Override
  55 + public void reprintHandle(String orid, ListOnclickCallback callback,
  56 + final View v, final AtomicBoolean isClick, BaseActivity activity) {
  57 + this.resources = activity.getResources();
  58 + this.orid = orid;
  59 + this.v = v;
  60 + this.isClick = isClick;
  61 + this.activity = activity;
  62 + type = SharedPreferences2Obj.getInstance(activity)
  63 + .setName("MachineType").getObject("type", Integer.class);
  64 + if (isClick.get()) {
  65 + isClick.set(false);
  66 + v.setClickable(false);
  67 + HttpHelper.getInstance(activity).queryConsumedDetail(orid,
  68 + new ReprintListCallback());
  69 + } else {
  70 + activity.MToast(activity, "点击过快,稍等两秒!", Toast.LENGTH_SHORT);
  71 + }
  72 + }
  73 +
  74 + /**
  75 + * @author jigo 获取补打列表
  76 + */
  77 + public class ReprintListCallback extends HttpCallback<DataTrans> {
  78 + private String signed;
  79 + private String data;
  80 + ProgressDialog progressDialog = null;
  81 +
  82 + @Override
  83 + public void onPreCallback() {
  84 + if (progressDialog == null) {
  85 + // 显示ProgressDialog
  86 + progressDialog = new ProgressDialog(activity);
  87 + progressDialog.setMessage(resources
  88 + .getString(R.string.get_ticket_info));
  89 + progressDialog.setCanceledOnTouchOutside(false);
  90 + progressDialog.setCancelable(true);
  91 + if (type == 8) {
  92 + progressDialog.getWindow().setType(
  93 + WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
  94 + }
  95 + try {
  96 + if (progressDialog != null && !progressDialog.isShowing()) {
  97 + progressDialog.show();
  98 + }
  99 + } catch (Exception e) {
  100 + e.printStackTrace();
  101 + }
  102 + } else {
  103 + progressDialog.setMessage(resources
  104 + .getString(R.string.get_ticket_info));
  105 + }
  106 + }
  107 +
  108 + @Override
  109 + public void onCompletedCallback(DataTrans result) {
  110 + }
  111 +
  112 + @Override
  113 + public void afterCompletedCallback(DataTrans result) {
  114 + if (result != null) {
  115 + signed = result.getSigned();
  116 + data = result.getData();
  117 + parse2(result.getData(), QueryConsumedDetailResponse.class, activity);
  118 + } else {
  119 + isClick.set(true);
  120 + v.setClickable(true);
  121 + if (progressDialog != null && progressDialog.isShowing()) {
  122 + try {
  123 + progressDialog.dismiss();
  124 + } catch (Exception e) {
  125 + e.printStackTrace();
  126 + } catch (Throwable e) {
  127 + e.printStackTrace();
  128 + }
  129 + }
  130 + activity.MToast(activity,
  131 + resources.getString(R.string.get_order_error),
  132 + Toast.LENGTH_SHORT);
  133 + }
  134 +
  135 + }
  136 +
  137 + @Override
  138 + public void onAgainParseCallback(Object parse) {
  139 + isClick.set(true);
  140 + v.setClickable(true);
  141 + if (progressDialog != null && progressDialog.isShowing()) {
  142 + try {
  143 + progressDialog.dismiss();
  144 + } catch (Exception e) {
  145 + e.printStackTrace();
  146 + } catch (Throwable e) {
  147 + e.printStackTrace();
  148 + }
  149 + }
  150 + if (parse != null) {
  151 + QueryConsumedDetailResponse detailResponse = (QueryConsumedDetailResponse) parse;
  152 + String code = detailResponse.getCode();
  153 + if (code != null && OrderCode.SUCESS.getValue().equals(code)) {
  154 + if (signed == null
  155 + || signed.equals(DataTool.getSign(MyApp
  156 + .getInstance().getSignkey(), data))) {
  157 + // 获取一个订单中每个记录
  158 + List<OrderConsumedItem> items = detailResponse
  159 + .getOrderConsumedItems();
  160 + dialog(items);
  161 + } else {
  162 + onFailureCallback(resources
  163 + .getString(R.string.sign_not_pass));
  164 + activity.MToast(activity,
  165 + resources.getString(R.string.sign_not_pass),
  166 + Toast.LENGTH_SHORT);
  167 + }
  168 + } else {
  169 + onFailureCallback(detailResponse.getDescribe());
  170 + activity.MToast(activity, detailResponse.getDescribe(),
  171 + Toast.LENGTH_SHORT);
  172 + }
  173 + }
  174 + }
  175 +
  176 + @Override
  177 + public void onFailureCallback(String FailureStr) {
  178 + isClick.set(true);
  179 + v.setClickable(true);
  180 + if (progressDialog != null && progressDialog.isShowing()) {
  181 + try {
  182 + progressDialog.dismiss();
  183 + } catch (Exception e) {
  184 + e.printStackTrace();
  185 + } catch (Throwable e) {
  186 + e.printStackTrace();
  187 + }
  188 + }
  189 + try {
  190 + activity.MToast(activity, FailureStr, Toast.LENGTH_SHORT);
  191 + } catch (Exception e) {
  192 + e.printStackTrace();
  193 + }
  194 + }
  195 +
  196 + @Override
  197 + public void onStopCallback() {
  198 + }
  199 + }
  200 +
  201 + /**
  202 + * @author jigo 获取打票信息
  203 + */
  204 + public class ReprintInfoCallback extends HttpCallback<DataTrans> {
  205 +
  206 + private String signed;
  207 + private String data;
  208 + ProgressDialog progressDialog = null;
  209 +
  210 + @Override
  211 + public void onPreCallback() {
  212 + if (progressDialog == null) {
  213 + // 显示ProgressDialog
  214 + progressDialog = new ProgressDialog(activity);
  215 + progressDialog.setMessage(resources
  216 + .getString(R.string.ready_to_print));
  217 + progressDialog.setCanceledOnTouchOutside(false);
  218 + progressDialog.setCancelable(true);
  219 + if (type == 8) {
  220 + progressDialog.getWindow().setType(
  221 + WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
  222 + }
  223 + try {
  224 + if (progressDialog != null && !progressDialog.isShowing()) {
  225 + progressDialog.show();
  226 + }
  227 + } catch (Exception e) {
  228 + e.printStackTrace();
  229 + }
  230 + } else {
  231 + progressDialog.setMessage(resources
  232 + .getString(R.string.ready_to_print));
  233 + }
  234 + }
  235 +
  236 + @Override
  237 + public void onCompletedCallback(DataTrans result) {
  238 + }
  239 +
  240 + @Override
  241 + public void afterCompletedCallback(DataTrans result) {
  242 + if (result != null) {
  243 + signed = result.getSigned();
  244 + data = result.getData();
  245 + parse2(result.getData(), ReprintVoucherResponse.class, activity);
  246 + } else {
  247 + isClick.set(true);
  248 + v.setClickable(true);
  249 + if (progressDialog != null && progressDialog.isShowing()) {
  250 + try {
  251 + progressDialog.dismiss();
  252 + } catch (Exception e) {
  253 + e.printStackTrace();
  254 + } catch (Throwable e) {
  255 + e.printStackTrace();
  256 + }
  257 + }
  258 + activity.MToast(activity,
  259 + resources.getString(R.string.get_order_error),
  260 + Toast.LENGTH_SHORT);
  261 + }
  262 +
  263 + }
  264 +
  265 + @Override
  266 + public void onAgainParseCallback(Object parse) {
  267 + isClick.set(true);
  268 + v.setClickable(true);
  269 + if (progressDialog != null && progressDialog.isShowing()) {
  270 + try {
  271 + progressDialog.dismiss();
  272 + } catch (Exception e) {
  273 + e.printStackTrace();
  274 + } catch (Throwable e) {
  275 + e.printStackTrace();
  276 + }
  277 + }
  278 + if (parse != null) {
  279 + ReprintVoucherResponse voucherResponse = (ReprintVoucherResponse) parse;
  280 + String code = voucherResponse.getCode();
  281 + if (code != null && OrderCode.SUCESS.getValue().equals(code)) {
  282 + if (signed == null
  283 + || signed.equals(DataTool.getSign(MyApp
  284 + .getInstance().getSignkey(), data))) {
  285 + // 获取一个订单中每个记录
285 286 // List<LinkedHashMap<String, String>> items = voucherResponse
286 287 // .getPrintInfos();
287   - List<String> items = voucherResponse
288   - .getPrintInfos();
289   - PrintHandle.getInstance().print(saveInfo(items),
290   - activity);
291   - } else {
292   - onFailureCallback(resources
293   - .getString(R.string.sign_not_pass));
294   - activity.MToast(activity,
295   - resources.getString(R.string.sign_not_pass),
296   - Toast.LENGTH_SHORT);
297   - }
298   - } else {
299   - onFailureCallback(voucherResponse.getDescribe());
300   - activity.MToast(activity, voucherResponse.getDescribe(),
301   - Toast.LENGTH_SHORT);
302   - }
303   - }
304   - }
305   -
306   - @Override
307   - public void onFailureCallback(String FailureStr) {
308   - isClick.set(true);
309   - v.setClickable(true);
310   - if (progressDialog != null && progressDialog.isShowing()) {
311   - try {
312   - progressDialog.dismiss();
313   - } catch (Exception e) {
314   - e.printStackTrace();
315   - } catch (Throwable e) {
316   - e.printStackTrace();
317   - }
318   - }
319   - try {
320   - activity.MToast(activity, FailureStr, Toast.LENGTH_SHORT);
321   - } catch (Exception e) {
322   - e.printStackTrace();
323   - }
324   - }
325   -
326   - @Override
327   - public void onStopCallback() {
328   - }
329   - }
330   -
331   - private LayoutInflater inflater;
332   - private AlertDialog dialog; // 打票列表
333   - private View layout;
334   - private RePrintAdapter adapter;
335   - private ListView orderListView;
336   - private List<Integer> rePrintList;
337   -
338   - @SuppressLint("InflateParams")
339   - private void dialog(final List<OrderConsumedItem> items) {
340   - try {
341   - if (dialog == null) {
342   - rePrintList = new ArrayList<Integer>();
343   - adapter = new RePrintAdapter(activity, items, rePrintList);
344   - inflater = LayoutInflater.from(activity);
345   - layout = inflater.inflate(R.layout.dialog_order_consumed, null);
346   - orderListView = (ListView) layout
347   - .findViewById(R.id.orderListView);
348   - orderListView.setOnItemClickListener(this);
349   - Builder builder = new AlertDialog.Builder(activity);
350   - builder.setTitle(R.string.select_print);
351   - builder.setPositiveButton(R.string.btn_ok, null);
352   - builder.setView(layout);
353   - builder.setNegativeButton(R.string.btn_cancel,
354   - new DialogInterface.OnClickListener() {
355   - @Override
356   - public void onClick(DialogInterface dialog,
357   - int which) {
358   - if (dialog != null) {
359   - dialog.dismiss();
360   - }
361   - }
362   - });
363   - orderListView.setAdapter(adapter);
364   - dialog = builder.create();
365   - }
366   -
367   - if (dialog != null && !dialog.isShowing()) {
368   - if (MyApp.getInstance().isHandset) {
369   - dialog.getWindow().setType(
370   - WindowManager.LayoutParams.TYPE_SYSTEM_ERROR);
371   - }
372   - dialog.show();
373   - }
374   - dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(
375   - new View.OnClickListener() {
376   - @Override
377   - public void onClick(View v) {
378   - getPrintInfo(items, dialog);
379   - return;
380   - }
381   - });
382   - } catch (Exception e) {
383   - e.printStackTrace();
384   - }
385   - }
386   -
387   - /********************** 获取信息,再请求 **************************/
388   - List<String> orderDetailIds;
389   -
390   - private void getPrintInfo(List<OrderConsumedItem> items, AlertDialog dialog) {
391   - if (orderDetailIds == null) {
392   - orderDetailIds = new ArrayList<String>();
393   - } else {
394   - orderDetailIds.clear();
395   - }
396   - if (rePrintList != null && rePrintList.size() == 0) {
397   - activity.MToast(activity,
398   - activity.getString(R.string.select_at_least_one_item),
399   - Toast.LENGTH_SHORT);
400   - return;
401   - }
402   - if (dialog != null && dialog.isShowing()) {
403   - dialog.dismiss();
404   - }
405   - for (int i = 0; i < rePrintList.size(); i++) {
406   - orderDetailIds.add(items.get(rePrintList.get(i)).getOrderDetailId()
407   - + "");
408   - }
409   - rePrintList.clear();
410   - HttpHelper.getInstance(activity).reprintVoucher(orid, orderDetailIds,
411   - new ReprintInfoCallback());
412   - }
413   -
414   - /******************** 打印信息转化 *************************/
415   - private String list2Str(List<LinkedHashMap<String, String>> list) {
416   - StringBuffer sb = new StringBuffer();
417   - if (list != null && list.size() > 0) {
418   - for (LinkedHashMap<String, String> temp : list) {
419   - for (LinkedHashMap.Entry<String, String> entry : temp.entrySet()) {
420   - if (entry != null) {
421   - if (entry.getValue() != null) {
422   - sb.append(entry.getValue() + "\n");
423   - }
424   - }
425   - }
426   - sb.append("\n\n\n");
427   - }
428   - try {// 加了时间有问题
429   - if (type != null && type == 8) {
430   - } else {
431   - sb.append("\n");
432   - }
433   - } catch (Exception e) {
434   - e.printStackTrace();
435   - }
436   - }
437   - return sb.toString();
438   - }
439   -
440   - @Override
441   - public void onItemClick(AdapterView<?> parent, View view, final int position,
442   - long id) {
443   - if(parent.getId()==R.id.orderListView){
444   - CheckBox check=(CheckBox) view.findViewById(R.id.check);
445   - if (!check.isChecked()) {
446   - rePrintList.add(position);
447   - check.setChecked(true);
448   - } else {
449   - if (rePrintList.contains(new Integer(position))) {
450   - rePrintList.remove(rePrintList.indexOf(new Integer(position)));
451   - }
452   - check.setChecked(false);
453   - }
454   - }
455   - }
456   -
457   -
458   -
459   -
460   -
461   - /**************************打印数据******************************/
462   - /**
463   - * @param PrintInfos
464   - * @return 保存打印信息
465   - */
466   - @SuppressLint("SimpleDateFormat")
467   - public String saveInfo(List<String> PrintInfos) {
468   - // 保存打印票的信息
469   - String[] str = null;
470   - String orderNumber = null;
471   - StringBuilder sb = new StringBuilder();
472   - for (String temp : PrintInfos) {
473   - if (temp != null) {
474   -
475   - if (temp.contains("证件号码")&&temp.length()>24){
476   - String buf = temp.substring(13, 21);
477   - temp = temp.replace(buf, "****");
478   - }
479   - if (temp.contains(resources.getString(R.string.orderid))) {
480   - try {
481   - str = temp.split(resources.getString(R.string.orderid));
482   - orderNumber = str[1].split(":")[1].trim();
483   - } catch (Exception e) {
484   - e.printStackTrace();
485   - }
486   - }
487   - sb.append(temp + "\n");
488   - }
489   - }
490   -
491   - SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");// 设置日期格式
492   - String currentData = df.format(new Date());// new
493   - // Date()为获取当前系统时间
494   - try {
495   - if (orderNumber != null
496   - && DbManager.queryOrderNumber(orderNumber) == null) {
497   - DbManager
498   - .insertPrint(currentData, sb.toString(), str[1].trim());
499   - } else {
500   - DbManager
501   - .ModifyPrint(currentData, sb.toString(), str[1].trim());
502   - }
503   - } catch (Exception e) {
504   - e.printStackTrace();
505   - }
506   - return sb.toString();
507   - }
  288 + List<String> items = voucherResponse
  289 + .getPrintInfos();
  290 + LogUtil.d("ReprintHandle",items.size()+"");
  291 + LogUtil.d("ReprintHandle2",items+"");
  292 + if (items.size() > 0) {
  293 + PrintHandle.getInstance().print(saveInfo(items),
  294 + activity);
  295 + } else {
  296 + activity.MToast(activity,
  297 + resources.getString(R.string.no_data_print),
  298 + Toast.LENGTH_SHORT);
  299 + }
  300 + } else {
  301 + onFailureCallback(resources
  302 + .getString(R.string.sign_not_pass));
  303 + activity.MToast(activity,
  304 + resources.getString(R.string.sign_not_pass),
  305 + Toast.LENGTH_SHORT);
  306 + }
  307 + } else {
  308 + onFailureCallback(voucherResponse.getDescribe());
  309 + activity.MToast(activity, voucherResponse.getDescribe(),
  310 + Toast.LENGTH_SHORT);
  311 + }
  312 + }
  313 + }
  314 +
  315 + @Override
  316 + public void onFailureCallback(String FailureStr) {
  317 + isClick.set(true);
  318 + v.setClickable(true);
  319 + if (progressDialog != null && progressDialog.isShowing()) {
  320 + try {
  321 + progressDialog.dismiss();
  322 + } catch (Exception e) {
  323 + e.printStackTrace();
  324 + } catch (Throwable e) {
  325 + e.printStackTrace();
  326 + }
  327 + }
  328 + try {
  329 + activity.MToast(activity, FailureStr, Toast.LENGTH_SHORT);
  330 + } catch (Exception e) {
  331 + e.printStackTrace();
  332 + }
  333 + }
  334 +
  335 + @Override
  336 + public void onStopCallback() {
  337 + }
  338 + }
  339 +
  340 + private LayoutInflater inflater;
  341 + private AlertDialog dialog; // 打票列表
  342 + private View layout;
  343 + private RePrintAdapter adapter;
  344 + private ListView orderListView;
  345 + private List<Integer> rePrintList;
  346 +
  347 + @SuppressLint("InflateParams")
  348 + private void dialog(final List<OrderConsumedItem> items) {
  349 + try {
  350 + if (dialog == null) {
  351 + rePrintList = new ArrayList<Integer>();
  352 + adapter = new RePrintAdapter(activity, items, rePrintList);
  353 + inflater = LayoutInflater.from(activity);
  354 + layout = inflater.inflate(R.layout.dialog_order_consumed, null);
  355 + orderListView = (ListView) layout
  356 + .findViewById(R.id.orderListView);
  357 + orderListView.setOnItemClickListener(this);
  358 + Builder builder = new AlertDialog.Builder(activity);
  359 + builder.setTitle(R.string.select_print);
  360 + builder.setPositiveButton(R.string.btn_ok, null);
  361 + builder.setView(layout);
  362 + builder.setNegativeButton(R.string.btn_cancel,
  363 + new DialogInterface.OnClickListener() {
  364 + @Override
  365 + public void onClick(DialogInterface dialog,
  366 + int which) {
  367 + if (dialog != null) {
  368 + dialog.dismiss();
  369 + }
  370 + }
  371 + });
  372 + orderListView.setAdapter(adapter);
  373 + dialog = builder.create();
  374 + }
  375 +
  376 + if (dialog != null && !dialog.isShowing()) {
  377 + if (MyApp.getInstance().isHandset) {
  378 + dialog.getWindow().setType(
  379 + WindowManager.LayoutParams.TYPE_SYSTEM_ERROR);
  380 + }
  381 + dialog.show();
  382 + }
  383 + dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(
  384 + new View.OnClickListener() {
  385 + @Override
  386 + public void onClick(View v) {
  387 + getPrintInfo(items, dialog);
  388 + return;
  389 + }
  390 + });
  391 + } catch (Exception e) {
  392 + e.printStackTrace();
  393 + }
  394 + }
  395 +
  396 + /********************** 获取信息,再请求 **************************/
  397 + List<String> orderDetailIds;
  398 +
  399 + private void getPrintInfo(List<OrderConsumedItem> items, AlertDialog dialog) {
  400 + if (orderDetailIds == null) {
  401 + orderDetailIds = new ArrayList<String>();
  402 + } else {
  403 + orderDetailIds.clear();
  404 + }
  405 + if (rePrintList != null && rePrintList.size() == 0) {
  406 + activity.MToast(activity,
  407 + activity.getString(R.string.select_at_least_one_item),
  408 + Toast.LENGTH_SHORT);
  409 + return;
  410 + }
  411 + if (dialog != null && dialog.isShowing()) {
  412 + dialog.dismiss();
  413 + }
  414 + for (int i = 0; i < rePrintList.size(); i++) {
  415 + orderDetailIds.add(items.get(rePrintList.get(i)).getOrderDetailId()
  416 + + "");
  417 + }
  418 + rePrintList.clear();
  419 + HttpHelper.getInstance(activity).reprintVoucher(orid, orderDetailIds,
  420 + new ReprintInfoCallback());
  421 + }
  422 +
  423 + /******************** 打印信息转化 *************************/
  424 + private String list2Str(List<LinkedHashMap<String, String>> list) {
  425 + StringBuffer sb = new StringBuffer();
  426 + if (list != null && list.size() > 0) {
  427 + for (LinkedHashMap<String, String> temp : list) {
  428 + for (LinkedHashMap.Entry<String, String> entry : temp.entrySet()) {
  429 + if (entry != null) {
  430 + if (entry.getValue() != null) {
  431 + sb.append(entry.getValue() + "\n");
  432 + }
  433 + }
  434 + }
  435 + sb.append("\n\n\n");
  436 + }
  437 + try {// 加了时间有问题
  438 + if (type != null && type == 8) {
  439 + } else {
  440 + sb.append("\n");
  441 + }
  442 + } catch (Exception e) {
  443 + e.printStackTrace();
  444 + }
  445 + }
  446 + return sb.toString();
  447 + }
  448 +
  449 + @Override
  450 + public void onItemClick(AdapterView<?> parent, View view, final int position,
  451 + long id) {
  452 + if (parent.getId() == R.id.orderListView) {
  453 + CheckBox check = (CheckBox) view.findViewById(R.id.check);
  454 + if (!check.isChecked()) {
  455 + rePrintList.add(position);
  456 + check.setChecked(true);
  457 + } else {
  458 + if (rePrintList.contains(new Integer(position))) {
  459 + rePrintList.remove(rePrintList.indexOf(new Integer(position)));
  460 + }
  461 + check.setChecked(false);
  462 + }
  463 + }
  464 + }
  465 +
  466 +
  467 + /**************************打印数据******************************/
  468 + /**
  469 + * @param PrintInfos
  470 + * @return 保存打印信息
  471 + */
  472 + @SuppressLint("SimpleDateFormat")
  473 + public String saveInfo(List<String> PrintInfos) {
  474 + // 保存打印票的信息
  475 + String[] str = null;
  476 + String orderNumber = null;
  477 + StringBuilder sb = new StringBuilder();
  478 + for (String temp : PrintInfos) {
  479 + if (temp != null) {
  480 +
  481 + if (temp.contains("证件号码") && temp.length() > 24) {
  482 + String buf = temp.substring(13, 21);
  483 + temp = temp.replace(buf, "****");
  484 + }
  485 + if (temp.contains(resources.getString(R.string.orderid))) {
  486 + try {
  487 + str = temp.split(resources.getString(R.string.orderid));
  488 + orderNumber = str[1].split(":")[1].trim();
  489 + } catch (Exception e) {
  490 + e.printStackTrace();
  491 + }
  492 + }
  493 + sb.append(temp + "\n");
  494 + }
  495 + }
  496 +
  497 + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");// 设置日期格式
  498 + String currentData = df.format(new Date());// new
  499 + // Date()为获取当前系统时间
  500 + try {
  501 + if (orderNumber != null
  502 + && DbManager.queryOrderNumber(orderNumber) == null) {
  503 + DbManager
  504 + .insertPrint(currentData, sb.toString(), str[1].trim());
  505 + } else {
  506 + DbManager
  507 + .ModifyPrint(currentData, sb.toString(), str[1].trim());
  508 + }
  509 + } catch (Exception e) {
  510 + e.printStackTrace();
  511 + }
  512 + return sb.toString();
  513 + }
508 514 }
... ...
src/com/ectrip/cyt/request/ConsumeCodeRequest.java 0 → 100644
  1 +package com.ectrip.cyt.request;
  2 +
  3 +import com.ectrip.cyt.base.Request;
  4 +
  5 +import java.util.List;
  6 +
  7 +/**
  8 + * 作者:dufang on 2026/3/3 17:07
  9 + */
  10 +public class ConsumeCodeRequest extends Request {
  11 + public String orderId;// 订单 ID
  12 + public String consumedAmount;// 消费数量
  13 + public String password;// 密码
  14 + public String verifyPassword;// 验证密码
  15 + private Long accountId; //操作员ID
  16 + public List<ProductOfConsumeOrder> products;//产品信息
  17 + private String voucher;
  18 +
  19 + public String consumedSeq;//流水号
  20 + public String code;
  21 + public String credentials;
  22 + public String note2;//
  23 + public String note3;//
  24 + public String note4;//
  25 + public String note5;//
  26 + public String note6;//
  27 + public String note7;//
  28 + public String note8;//
  29 +
  30 + public ConsumeCodeRequest(String orderId, String consumeCount,
  31 + String password, String verifyPassword,String consumedSeq,List<ProductOfConsumeOrder> products) {
  32 + super();
  33 + this.orderId = orderId;
  34 + this.consumedAmount = consumeCount;
  35 + this.password = password;
  36 + this.verifyPassword = verifyPassword;
  37 + this.products = products;
  38 + this.consumedSeq = consumedSeq;
  39 +
  40 + }
  41 +
  42 + public void setOrderId(String orderId) {
  43 + this.orderId = orderId;
  44 + }
  45 +
  46 + public String getOrderId() {
  47 +
  48 + return orderId;
  49 + }
  50 +
  51 + public void setAccountId(Long accountId) {
  52 +
  53 + this.accountId = accountId;
  54 + }
  55 +
  56 + public Long getAccountId() {
  57 +
  58 + return accountId;
  59 + }
  60 +
  61 + public List<ProductOfConsumeOrder> getProducts() {
  62 + return products;
  63 + }
  64 +
  65 + public void setProducts(List<ProductOfConsumeOrder> products) {
  66 + this.products = products;
  67 + }
  68 +
  69 + public String getorderId() {
  70 + return orderId;
  71 + }
  72 +
  73 + public void setorderId(String orderId) {
  74 + this.orderId = orderId;
  75 + }
  76 +
  77 + public String getConsumedAmount() {
  78 + return consumedAmount;
  79 + }
  80 +
  81 + public void setConsumedAmount(String consumedAmount) {
  82 + this.consumedAmount = consumedAmount;
  83 + }
  84 +
  85 + public String getPassword() {
  86 + return password;
  87 + }
  88 +
  89 + public void setPassword(String password) {
  90 + this.password = password;
  91 + }
  92 +
  93 + public String getVerifyPassword() {
  94 + return verifyPassword;
  95 + }
  96 +
  97 + public void setVerifyPassword(String verifyPassword) {
  98 + this.verifyPassword = verifyPassword;
  99 + }
  100 +
  101 + public String getConsumedSeq() {
  102 + return consumedSeq;
  103 + }
  104 +
  105 + public void setConsumedSeq(String consumedSeq) {
  106 + this.consumedSeq = consumedSeq;
  107 + }
  108 +
  109 + public String getNote2() {
  110 + return note2;
  111 + }
  112 +
  113 + public void setNote2(String note2) {
  114 + this.note2 = note2;
  115 + }
  116 +
  117 + public String getNote3() {
  118 + return note3;
  119 + }
  120 +
  121 + public void setNote3(String note3) {
  122 + this.note3 = note3;
  123 + }
  124 +
  125 + public String getNote4() {
  126 + return note4;
  127 + }
  128 +
  129 + public void setNote4(String note4) {
  130 + this.note4 = note4;
  131 + }
  132 +
  133 + public String getNote5() {
  134 + return note5;
  135 + }
  136 +
  137 + public void setNote5(String note5) {
  138 + this.note5 = note5;
  139 + }
  140 +
  141 + public String getNote6() {
  142 + return note6;
  143 + }
  144 +
  145 + public void setNote6(String note6) {
  146 + this.note6 = note6;
  147 + }
  148 +
  149 + public String getNote7() {
  150 + return note7;
  151 + }
  152 +
  153 + public void setNote7(String note7) {
  154 + this.note7 = note7;
  155 + }
  156 +
  157 + public String getNote8() {
  158 + return note8;
  159 + }
  160 +
  161 + public void setNote8(String note8) {
  162 + this.note8 = note8;
  163 + }
  164 +
  165 + public String getCode() {
  166 + return code;
  167 + }
  168 +
  169 + public void setCode(String code) {
  170 + this.code = code;
  171 + }
  172 +
  173 + public String getCredentials() {
  174 + return credentials;
  175 + }
  176 +
  177 + public void setCredentials(String credentials) {
  178 + this.credentials = credentials;
  179 + }
  180 +
  181 + public String getVoucher() {
  182 + return voucher;
  183 + }
  184 +
  185 + public void setVoucher(String voucher) {
  186 + this.voucher = voucher;
  187 + }{
  188 +
  189 + }
  190 +}
... ...
src/com/ectrip/cyt/ui/MainActivity.java
... ... @@ -162,7 +162,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, V
162 162 // 得到存储的类型
163 163 Integer type = SharedPreferences2Obj.getInstance(MainActivity.this)
164 164 .setName("MachineType").getObject("type", Integer.class);
165   -
  165 + LogUtil.d(TAG, "MachineType = " + type);
166 166 //如果未存储类型
167 167 if (type == null || type == 0) {
168 168 DisplayMetrics metrics = new DisplayMetrics();
... ...
src/com/ectrip/cyt/ui/PhomeScanerOrderActivity.java
... ... @@ -181,10 +181,10 @@ public class PhomeScanerOrderActivity extends BaseActivity implements Callback {
181 181 } catch (Exception e) {
182 182 e.printStackTrace();
183 183 }
184   - Intent intent;
  184 + Intent intent = null;
185 185 if (resultString.startsWith("OCP_")) {
186   - intent = new Intent(PhomeScanerOrderActivity.this,
187   - PhoneCodeListActivity.class);
  186 +// intent = new Intent(PhomeScanerOrderActivity.this,
  187 +// PhoneCodeListActivity.class);
188 188 } else {
189 189 intent = new Intent(PhomeScanerOrderActivity.this,
190 190 QRCodeOrderListActivity.class);
... ...