HandleDeviceSn.py
6.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import openpyxl
from SupplyChain.CommonDef import log, DEVICEINFO
from SupplyChain.DataBase import DateBase
class HandleDeviceSn:
dataBase = None
fileName = ''
def __init__(self):
self.dataBase = DateBase()
self.fileName = ''
def setFileName(self,fileName):
self.fileName = fileName
def ReadExcelC(self):
workbook = openpyxl.load_workbook(self.fileName)
listIccid = []
sheet = workbook.active
rows = sheet.max_row
for i in range(2, rows + 1):
iccid = sheet['A%d' % (i)].value
if iccid is None:
continue
listIccid.append(iccid)
workbook.close()
return listIccid
def WriteExcelC(self,mapIccid):
workbook = openpyxl.load_workbook(self.fileName)
sheet = workbook.active
rows = sheet.max_row
for i in range(2, rows + 1):
iccid = sheet['A%d' % (i)].value
if iccid is None:
continue
deviceCard = mapIccid.get(iccid)
if deviceCard is None:
continue
sheet['B%d' % (i)] = deviceCard.sn
sheet['C%d' % (i)] = deviceCard.devcetype
sheet['D%d' % (i)] = deviceCard.outtime
sheet['E%d' % (i)] = deviceCard.sendmerchant
sheet['F%d' % (i)] = deviceCard.activetime
sheet['G%d' % (i)] = deviceCard.deviceCode
sheet['H%d' % (i)] = deviceCard.deviceName
workbook.save(self.fileName)
workbook.close()
def DoWork1(self):
listIccid = self.ReadExcelC()
mapIccid = self.dataBase.mapDeviceCard(listIccid)
self.WriteExcelC(mapIccid)
log.info("Ok")
def DoWork(self):
listIccid = self.ReadExcelB()
mapIccid = self.dataBase.mapDeviceCard(listIccid)
self.WriteExcelB(mapIccid)
log.info("Ok")
# listDeviceInfo = self.ReadExcelA()
# listDeviceInfo = self.SendCard(listDeviceInfo)
# for item in listDeviceInfo:
# self.dataBase.updateDeviceFileCard(item.sn,item.cardid)
# self.dataBase.updateDeviceFileSnapshot(item.sn,item.cardid)
# log.info("Ok")
def ReadExcelB(self):
workbook = openpyxl.load_workbook(self.fileName)
listIccid = []
sheet = workbook.active
rows = sheet.max_row
for i in range(2, rows + 1):
iccid = sheet['B%d'%(i)].value
if iccid is None:
continue
listIccid.append(iccid)
workbook.close()
return listIccid
def WriteExcelB(self,mapIccid):
workbook = openpyxl.load_workbook(self.fileName)
sheet = workbook.active
rows = sheet.max_row
for i in range(2, rows + 1):
iccid = sheet['B%d' % (i)].value
if iccid is None:
continue
deviceCard = mapIccid.get(iccid)
if deviceCard is None:
continue
sheet['E%d' % (i)] = deviceCard.sn
sheet['F%d' % (i)] = deviceCard.devcetype
sheet['G%d' % (i)] = deviceCard.outtime
sheet['H%d' % (i)] = deviceCard.sendmerchant
sheet['I%d' % (i)] = deviceCard.activetime
workbook.save(self.fileName)
workbook.close()
def ReadExcelA(self):
workbook = openpyxl.load_workbook(self.fileName)
listDeviceInfo = []
sheet = workbook.active
rows = sheet.max_row
for i in range(2, rows + 1):
sn = sheet['A%d'%(i)].value
iccid = sheet['B%d'%(i)].value
imsi = sheet['D%d'%(i)].value
deviceInfo = DEVICEINFO()
deviceInfo.sn = sn
deviceInfo.imsi = imsi
deviceInfo.iccid = iccid
listDeviceInfo.append(deviceInfo)
return listDeviceInfo
def SendCard(self,listDeviceInfo):
mapSnCard = {}
if listDeviceInfo is None:
return listDeviceInfo
self.dataBase.insertDeviceCardManager(listDeviceInfo);
listDeviceInfo = self.dataBase.filtIdDeviceCardManager(listDeviceInfo);
return listDeviceInfo
def StartWork(self):
listSn = self.ReadExcel();
mapSendOrderMerchant = self.dataBase.mapOrderSendMerchant(listSn)
mapStockOrderMerchant = self.dataBase.mapStockSendMerchant(listSn)
mapShopOrderMerchant = self.dataBase.mapShopSendMerchant(listSn)
self.WriteExcel(mapSendOrderMerchant,mapStockOrderMerchant,mapShopOrderMerchant)
log.info("Ok")
def ReadExcel(self):
listSn = []
workbook = openpyxl.load_workbook(self.fileName)
sheet = workbook.active
rows = sheet.max_row
for i in range(2, rows + 1):
sn = sheet['C%d'%(i)].value
if sn is not None:
listSn.append(sn)
workbook.close()
return listSn
def WriteExcel(self,mapSendOrderMerchant,mapStockOrderMerchant,mapShopOrderMerchant):
workbook = openpyxl.load_workbook(self.fileName)
sheet = workbook.active
rows = sheet.max_row
for i in range(2, rows + 1):
sn = sheet['C%d'%(i)].value
if sn is None:
continue
snInMerchant = mapStockOrderMerchant.get(sn)
if snInMerchant is not None:
sheet['S%d' % (i)] = snInMerchant.merchantCode
sheet['T%d' % (i)] = snInMerchant.merchantName
sheet['U%d' % (i)] = snInMerchant.shopMerchantCode
sheet['V%d' % (i)] = snInMerchant.shopMerchantName
continue
snInMerchant = mapShopOrderMerchant.get(sn)
if snInMerchant is not None:
sheet['S%d' % (i)] = snInMerchant.merchantCode
sheet['T%d' % (i)] = snInMerchant.merchantName
sheet['U%d' % (i)] = snInMerchant.shopMerchantCode
sheet['V%d' % (i)] = snInMerchant.shopMerchantName
continue
snInMerchant = mapSendOrderMerchant.get(sn)
if snInMerchant is not None:
sheet['S%d' % (i)] = snInMerchant.merchantCode
sheet['T%d' % (i)] = snInMerchant.merchantName
sheet['U%d' % (i)] = snInMerchant.shopMerchantCode
sheet['V%d' % (i)] = snInMerchant.shopMerchantName
continue
workbook.save(self.fileName)
workbook.close()
if __name__ == "__main__":
handleDeviceSn = HandleDeviceSn()
handleDeviceSn.setFileName("F:\\xiaochuan\\需查询设备名称和入库时间2021.11.12.xlsx")
handleDeviceSn.DoWork1()
#handleDeviceSn.DoWork()
#handleDeviceSn.StartWork()