-
Notifications
You must be signed in to change notification settings - Fork 0
/
processdh.py
369 lines (309 loc) · 9.01 KB
/
processdh.py
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
# -*- coding: utf-8 -*-
'''
#=============================================================================
# FileName: processdh.py
# Desc:
# Author: solomon
# Email: [email protected]
# HomePage:
# Version: 0.0.1
# LastChange: 2012-11-02 10:14:50
# History:
#=============================================================================
'''
import confsql
import psycopg2
import psycopg2.extensions
import functions
dataserver = {"host":"localhost",
"port":5432,
"user":"fengmu",
"pwd": "zj",
"database":"yq3"}
logfile="D:/vcms/lib/py/mana1/mylog.log"
def main():
conn = psycopg2.connect(host=dataserver["host"], port=dataserver["port"],user=dataserver["user"],password=dataserver["pwd"],database=dataserver["database"])
cur = conn.cursor()
init(conn,cur)
sugvalue_moban(conn,cur)
xiaoshou28_moban(conn,cur)
cl_moban(conn,cur)
dhalldata_insert(conn,cur)
dhalldata_update(conn,cur)
sp(conn,cur)
mdsp(conn, cur)
packetqty1(conn,cur)
yqmaxlimit(conn,cur)
yqminlimit(conn,cur)
delivery(conn,cur)
dhtag(conn,cur)
cuxiao(conn,cur)
sugvalue(conn,cur)
xiaoshou28_res(conn,cur)
cl(conn,cur)
def init(conn, cur):
try:
sqlstr = " delete from dhalldata_temp; "
sqlstr += " delete from dhalldata "
cur.execute(sqlstr)
conn.commit()
except:
functions.log("清除数据,准备数据加工")
def sugvalue_moban(conn,cur):
#1. 订货md,sp
try:
sqlstr="""
insert into dhalldata_temp
select braid, proid
from sugvalue
"""
cur.execute(sqlstr)
conn.commit()
except:
functions.log("创建门店代码商品代码sugvalue_moban失败!",logfile)
def xiaoshou28_moban(conn,cur):
#2. xiaoshou28
try:
sqlstr="""
insert into dhalldata_temp
select braid, proid
from xiaoshou28_res
"""
cur.execute(sqlstr)
conn.commit()
except:
functions.log("创建门店代码商品代码xiaoshou_moban失败!",logfile)
def cl_moban(conn,cur):
#3 cl
try:
sqlstr="""
insert into dhalldata_temp
select mdcode, spcode
from cl
"""
cur.execute(sqlstr)
conn.commit()
except:
functions.log("创建门店代码商品代码cl_moban失败!",logfile)
def dhalldata_insert(conn,cur):
#4
try:
sqlstr="""
insert into dhalldata
select mdcode, spcode from dhalldata_temp group by mdcode, spcode
"""
cur.execute(sqlstr)
conn.commit()
#*** 调试用 ××××
sqlstr = """
delete from dhalldata where mdcode not in ('02058','02186', '02203', '02204','02216','02196', '04340')"""
cur.execute(sqlstr)
conn.commit()
#*****************
except:
functions.log("向dhalldata插入数据失败!",logfile)
def dhalldata_update(conn,cur):
#5. mdcode
try:
sqlstr="""
update dhalldata
set mdname = t.braname
from branch as t
where mdcode = t.braid
"""
cur.execute(sqlstr)
conn.commit()
except:
functions.log("向dhalldata更新数据失败!",logfile)
def sp(conn,cur):
#6 sp
try:
sqlstr="""
update dhalldata
set spname = t.proname,
proxl_id = t.proxl_id,
proxl = t.proxl,
prozl_id = t.prozl_id,
prozl = t.prozl,
prodl_id = t.prodl_id,
prodl = t.prodl,
braxl_id = t.braxl_id,
braxl = t.braxl,
brazl_id = t.brazl_id,
brazl = t.brazl,
bradl_id = t.bradl_id,
bradl = t.bradl,
normalprice = t.normalprice,
status = '5',
barcode = t.barcode,
packetqty1 = t.packetqty1
from product_all as t
where spcode = t.proid
"""
cur.execute(sqlstr)
conn.commit()
except:
functions.log("sp更新数据失败!",logfile)
def mdsp(conn, cur):
#6.1 mdsp
try:
sqlstr = """
update dhalldata
set status = t.status
from v_com_product as t
where spcode = t.proid and mdcode = t.braid
"""
cur.execute(sqlstr)
conn.commit()
except:
functions.log("mdsp更新数据失败")
def packetqty1(conn,cur):
#7.packetqty1
try:
sqlstr="""
update dhalldata
set packetqty1 = t.packetqty1
from product_gl_packetqty as t
where spcode = t.proid
"""
cur.execute(sqlstr)
conn.commit()
except:
functions.log("packetqty1更新数据失败!",logfile)
def yqmaxlimit(conn,cur):
#8. yqmaxlimit
try:
sqlstr="""
update dhalldata
set yqmaxlimit = t.yqmaxlimit
from dhrules_today_maxlimit as t
where spcode = t.proid and mdcode = t.braid
"""
cur.execute(sqlstr)
conn.commit()
except:
functions.log("yqmaxlimit更新数据失败!",logfile)
def yqminlimit(conn,cur):
#9.yqminlimit
try:
sqlstr="""
update dhalldata
set yqminlimit = t.yqminlimit
from dhrules_today_minlimit as t
where spcode = t.proid and mdcode = t.braid
"""
cur.execute(sqlstr)
conn.commit()
except:
functions.log("yqminlimit更新数据失败!",logfile)
def delivery(conn,cur):
#9.1 delivery
try:
sqlstr="""
update dhalldata
set delivery = 'T'
from delivery as t
where mdcode = t.braid
"""
cur.execute(sqlstr)
conn.commit()
except:
functions.log("delivery更新数据失败!",logfile)
def dhtag(conn,cur):
#9.2 dhtag
try:
sqlstr="""
update dhalldata
set dhtag = 'T'
from dhpauserules_today as t
where mdcode = t.braid and spcode = t.proid
"""
cur.execute(sqlstr)
conn.commit()
except:
functions.log("dhtag更新数据失败!",logfile)
def cuxiao(conn,cur):
#9.3 cuxiao
try:
sqlstr="""
update dhalldata
set cuxiao_1 = 'T'
from pmt as t
where mdcode = t.braid and spcode = t.proid
"""
cur.execute(sqlstr)
conn.commit()
except:
functions.log("cuxiao更新数据失败!",logfile)
def sugvalue(conn,cur):
#10. sugvalue
try:
sqlstr="""
update dhalldata
set suggest = t.suggest,
suggestcost = t.suggestcost,
maxval = t.maxval,
minval = t.minval,
curqty = t.curqty,
allocqty = t.allocqty
from sugvalue as t
where mdcode = t.braid and spcode = t.proid
"""
cur.execute(sqlstr)
conn.commit()
except:
functions.log("sugvalue更新数据失败!",logfile)
def xiaoshou28_res(conn,cur):
#11. xiaoshou28_res
try:
sqlstr="""
update dhalldata
set week1_qty = t.week1_qty,
week2_qty = t.week2_qty,
week3_qty = t.week3_qty,
week4_qty = t.week4_qty,
total_qty = t.total_qty,
week1_amt = t.week1_amt,
week2_amt = t.week2_amt,
week3_amt = t.week3_amt,
week4_amt = t.week4_amt,
total_amt = t.total_amt
from xiaoshou28_res as t
where mdcode = t.braid and spcode = t.proid
"""
cur.execute(sqlstr)
conn.commit()
except:
functions.log("xiaoshou28_res更新数据失败!",logfile)
def cl(conn,cur):
#12. cl
try:
sqlstr="""
update dhalldata
set assortment = t.assortment,
spaceid = t.spaceid,
spacename = t.spacename,
hjcode = t.hjcode,
shelf = t.shelf,
drawer = t.drawer,
box = t.box
from cl as t
where dhalldata.mdcode = t.mdcode and dhalldata.spcode = t.spcode
"""
cur.execute(sqlstr)
conn.commit()
except:
functions.log("cl更新数据失败!",logfile)
def setMdTotal(conn,cur):
"""有效门店补货综合信息,供查询"""
sqlstr = " delete from brainfo "
sqlstr = " insert into brainfo "
sqlstr += " select braid,braname,count(distinct(proid)) ,sum(curqty) ,sum(suggest) ,sum(suggestcost) "
sqlstr += " from dhalldata"
sqlstr += " where deliveryval = 'T' and dhtag = 'T' "
sqlstr += " and assortment is not null and status < '5' and suggest > 0 and shelf > '-1' "
sqlstr += " group by braid,braname"
cur.execute(sqlstr)
conn.commit()
if __name__ == "__main__":
main()