Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
supplier
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王宇航
supplier
Commits
367c421b
Commit
367c421b
authored
Apr 11, 2020
by
Wyh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
04-11 打印問題修復
parent
1354332c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
10 deletions
+34
-10
print-module/src/main/java/com/joe/print/mvp/print/PrintKitchen.java
+5
-1
print-module/src/main/java/com/joe/print/mvp/print/PrintSlip.java
+19
-1
print-module/src/main/java/com/joe/print/mvp/print/PrinterInIt.java
+7
-6
print-module/src/main/java/com/joe/print/mvp/ui/activity/PrinterAddActivity.java
+3
-2
No files found.
print-module/src/main/java/com/joe/print/mvp/print/PrintKitchen.java
View file @
367c421b
...
...
@@ -29,19 +29,23 @@ import java.util.Objects;
*/
public
class
PrintKitchen
extends
PrinterInIt
{
String
[]
printLocation
=
new
String
[]{
"k1"
,
"k2"
};
@Override
public
Map
<
String
,
List
<
Bitmap
>>
getPrintBitmap
(
Context
mContext
)
{
Map
<
String
,
List
<
Bitmap
>>
bitmapMaps
=
new
HashMap
<>();
List
<
OrderDetail
>
orderDetails
=
MyOrderManage
.
getInstance
().
getNewFoodList
();
if
(
orderDetails
!=
null
)
{
for
(
int
i
=
0
;
i
<
orderDetails
.
size
();
i
++)
{
orderDetails
.
get
(
i
).
setPrintseting
(
printLocation
[
i
%
2
]);
}
//廚房單,可能會有多個IP打印
//獲得ip打印列表,
//再將食品數據根據打印位置分組。
//打印一組之後,關閉連接,切換第二台打印機ip,如此循環
//打印完成之後,返回所有打印結果。
Map
<
String
,
List
<
OrderDetail
>>
foodMaps
=
new
HashMap
<>();
String
emptyPrintLocation
=
"
null
"
;
//部分食品沒有打印位置時設置為此key,比如這是第一個食品,沒有打印位置時
String
emptyPrintLocation
=
""
;
//部分食品沒有打印位置時設置為此key,比如這是第一個食品,沒有打印位置時
int
lastEmptyPrintLocationIndex
=
0
;
//上一次遍歷到第一個食品時都沒有打印位置時,開始的食品位置
//將所有食品進行遍歷,分組
for
(
int
i
=
0
;
i
<
orderDetails
.
size
();
i
++)
{
...
...
print-module/src/main/java/com/joe/print/mvp/print/PrintSlip.java
View file @
367c421b
...
...
@@ -22,6 +22,7 @@ import com.joe.print.R;
import
java.math.BigDecimal
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -38,10 +39,27 @@ public class PrintSlip extends PrinterInIt {
//這裡可能還需要加上廚房單的內容,有未送單的食品時。
PrintKitchen
kitchen
=
new
PrintKitchen
();
Map
<
String
,
List
<
Bitmap
>>
bitmapMaps
=
new
HashMap
<>(
kitchen
.
getPrintBitmap
(
mContext
));
bitmapMaps
.
put
(
""
,
bitmaps
);
merge2ResultMap
(
bitmapMaps
,
""
,
bitmaps
);
return
bitmapMaps
;
}
/**
* 把Map中Key相同,则各个value添加到一起,汇总值
* 把partMap数据合并放到resultMap中。
*
* @param resultMap
*/
public
static
<
T
,
F
,
K
extends
Collection
<
F
>>
Map
merge2ResultMap
(
Map
<
T
,
K
>
resultMap
,
T
key2
,
K
value
)
{
for
(
Map
.
Entry
<
T
,
K
>
entry
:
resultMap
.
entrySet
())
{
T
key
=
entry
.
getKey
();
if
(
resultMap
.
containsKey
(
key2
))
{
resultMap
.
get
(
key2
).
addAll
(
value
);
}
else
{
resultMap
.
put
(
key2
,
value
);
}
}
return
resultMap
;
}
/**
* 獲取"印單"圖片
...
...
print-module/src/main/java/com/joe/print/mvp/print/PrinterInIt.java
View file @
367c421b
...
...
@@ -106,7 +106,7 @@ public abstract class PrinterInIt implements PrintSocketHolder.OnStateChangedLis
// 第一步先查看map中的key是不是空的"",有key就要獲取打印機列表,找到對應打印機打印。如果沒有找到打印機再去找默認打印機
// 如果沒有key,則是走默認打印機流程
for
(
Map
.
Entry
<
String
,
List
<
Bitmap
>>
entry
:
listMap
.
entrySet
())
{
if
(
entry
.
getKey
().
equals
(
""
))
{
if
(
entry
.
getKey
().
equals
(
""
)
||
entry
.
getKey
().
equals
(
"null"
)
)
{
//沒有打印位置,獲取默認打印位置
defaultPrint
(
deviceBeans
,
entry
.
getValue
());
}
else
{
...
...
@@ -259,7 +259,7 @@ public abstract class PrinterInIt implements PrintSocketHolder.OnStateChangedLis
int
lastIndex
=
key
.
lastIndexOf
(
DELIMITER
);
key
=
key
.
substring
(
lastIndex
+
1
);
if
(
key
.
replaceAll
(
"\\*"
,
""
).
trim
().
equals
(
printerDeviceBeans
.
get
(
i
).
getName
()
.
trim
()
))
{
if
(
key
.
replaceAll
(
"\\*"
,
""
).
trim
().
equals
(
printerDeviceBeans
.
get
(
i
).
getName
()))
{
//如果key(打印位置)去掉*號和打印機名稱相同,則在這台機器上打印
ipDevicePrint
(
printerDeviceBeans
.
get
(
i
),
bitmaps
);
isPrint
=
true
;
...
...
@@ -500,9 +500,10 @@ public abstract class PrinterInIt implements PrintSocketHolder.OnStateChangedLis
recyclerView
.
addItemDecoration
(
new
DefaultItemDecoration
(
ContextCompat
.
getColor
(
mContext
,
R
.
color
.
line_color
)));
adapter
.
setOnItemClickListener
((
adapter12
,
view
,
position
)
->
{
//顯示打印失敗的食品。
PrintFileBitmapAdapter
bitmapAdapter
=
new
PrintFileBitmapAdapter
(
getPrintBitmapByPrintLocation
(
printerFileDevices
.
get
(
position
).
getName
().
trim
()));
recyclerView
.
setAdapter
(
bitmapAdapter
);
if
(
printerFileDevices
.
get
(
position
).
getName
()
!=
null
)
{
PrintFileBitmapAdapter
bitmapAdapter
=
new
PrintFileBitmapAdapter
(
getPrintBitmapByPrintLocation
(
printerFileDevices
.
get
(
position
).
getName
()));
recyclerView
.
setAdapter
(
bitmapAdapter
);
}
});
adapter
.
setSwitchPrintListenter
(
position
->
{
if
(
printerDeviceBeans
!=
null
&&
printerDeviceBeans
.
size
()
>
0
)
{
...
...
@@ -522,7 +523,7 @@ public abstract class PrinterInIt implements PrintSocketHolder.OnStateChangedLis
});
adapter
.
setTryAgainPrintListenter
(
position
->
{
//重試打印。
ipDevicePrint
(
printerFileDevices
.
get
(
position
),
getPrintBitmapByPrintLocation
(
printerFileDevices
.
get
(
position
).
getName
()
.
trim
()
),
(
state
,
printerDeviceBean
)
->
{
ipDevicePrint
(
printerFileDevices
.
get
(
position
),
getPrintBitmapByPrintLocation
(
printerFileDevices
.
get
(
position
).
getName
()),
(
state
,
printerDeviceBean
)
->
{
//打印機打印狀態切換回調
},
(
errorCode
,
printerDeviceBean
)
->
{
switch
(
errorCode
)
{
...
...
print-module/src/main/java/com/joe/print/mvp/ui/activity/PrinterAddActivity.java
View file @
367c421b
...
...
@@ -202,15 +202,16 @@ public class PrinterAddActivity extends BaseActivity<PrinterAddPresenter> implem
String
port
=
etPort
.
getText
().
toString
();
PrinterDeviceBean
deviceBean
;
if
(
TextUtil
.
isEmptyOrNullOrUndefined
(
port
))
{
deviceBean
=
new
PrinterDeviceBean
(
mEdPrintName
.
getText
().
toString
().
trim
(),
printerDeviceBean
.
getId
()
,
GsaCloudApplication
.
getRestaurantId
(
mContext
),
ipAddress
.
substring
(
0
,
ipAddress
.
lastIndexOf
(
"."
)),
null
,
paperType
);
deviceBean
=
new
PrinterDeviceBean
(
mEdPrintName
.
getText
().
toString
().
trim
(),
0
,
GsaCloudApplication
.
getRestaurantId
(
mContext
),
ipAddress
.
substring
(
0
,
ipAddress
.
lastIndexOf
(
"."
)),
null
,
paperType
);
}
else
{
deviceBean
=
new
PrinterDeviceBean
(
mEdPrintName
.
getText
().
toString
().
trim
(),
printerDeviceBean
.
getId
()
,
GsaCloudApplication
.
getRestaurantId
(
mContext
),
ipAddress
.
substring
(
0
,
ipAddress
.
lastIndexOf
(
"."
)),
Integer
.
parseInt
(
port
),
paperType
);
deviceBean
=
new
PrinterDeviceBean
(
mEdPrintName
.
getText
().
toString
().
trim
(),
0
,
GsaCloudApplication
.
getRestaurantId
(
mContext
),
ipAddress
.
substring
(
0
,
ipAddress
.
lastIndexOf
(
"."
)),
Integer
.
parseInt
(
port
),
paperType
);
}
//添加打印機
if
(
v
.
getId
()
==
R
.
id
.
printer_add
)
{
if
(
isEditPrinter
&&
printerDeviceBean
!=
null
)
{
deviceBean
.
setRestaurantId
(
null
);
deviceBean
.
setId
(
printerDeviceBean
.
getId
());
mPresenter
.
updatePrinterInfo
(
deviceBean
);
}
else
{
mPresenter
.
addPrinter
(
deviceBean
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment