Spaces:
Sleeping

doluong6 commited on
Commit
d56193c
·
verified ·
1 Parent(s): a1612f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -26
app.py CHANGED
@@ -280,7 +280,6 @@ def ds_pyc_cho_xu_ly():
280
  token=HF_TOKEN
281
  )
282
 
283
- # Danh sách file phiếu yêu cầu
284
  pyc_files = [
285
  f for f in all_files
286
  if f.startswith("Khach_hang/")
@@ -288,7 +287,6 @@ def ds_pyc_cho_xu_ly():
288
  and f.lower().endswith(".xlsx")
289
  ]
290
 
291
- # Danh sách file GCN đã scan
292
  gcn_files = [
293
  f for f in all_files
294
  if f.startswith("Khach_hang/")
@@ -296,34 +294,59 @@ def ds_pyc_cho_xu_ly():
296
  and "GCN" in os.path.basename(f).upper()
297
  ]
298
 
299
- # Gom nhóm theo khách hàng
300
- thong_ke_pyc = defaultdict(list)
301
- for f in pyc_files:
302
- parts = f.split("/")
303
- if len(parts) >= 3:
304
- thong_ke_pyc[parts[1]].append(f)
305
 
306
- thong_ke_gcn = defaultdict(list)
307
- for f in gcn_files:
308
- parts = f.split("/")
309
- if len(parts) >= 3:
310
- thong_ke_gcn[parts[1]].append(f)
 
311
 
312
- # Trả ra danh sách phiếu đang chờ xử lý (PYC chưa có GCN tương ứng)
313
- danh_sach_cho_xu_ly = []
 
314
 
315
- for khach, ds_pyc in thong_ke_pyc.items():
316
- so_gcn = len(thong_ke_gcn.get(khach, []))
317
- so_pyc = len(ds_pyc)
 
 
 
 
 
318
 
319
- if so_pyc > so_gcn:
320
- for f in ds_pyc:
321
- danh_sach_cho_xu_ly.append({
322
- "Khách hàng": khach,
323
- "File PYC": f
324
- })
 
 
 
 
 
 
 
 
 
 
 
 
 
325
 
326
- return danh_sach_cho_xu_ly
 
 
 
 
 
 
 
 
 
 
327
 
328
  except Exception as e:
329
- return {"error": str(e)}
 
280
  token=HF_TOKEN
281
  )
282
 
 
283
  pyc_files = [
284
  f for f in all_files
285
  if f.startswith("Khach_hang/")
 
287
  and f.lower().endswith(".xlsx")
288
  ]
289
 
 
290
  gcn_files = [
291
  f for f in all_files
292
  if f.startswith("Khach_hang/")
 
294
  and "GCN" in os.path.basename(f).upper()
295
  ]
296
 
297
+ khach_co_gcn = set(f.split("/")[1] for f in gcn_files if len(f.split("/")) >= 3)
 
 
 
 
 
298
 
299
+ ket_qua = []
300
+
301
+ for file in pyc_files:
302
+ parts = file.split("/")
303
+ if len(parts) < 3:
304
+ continue
305
 
306
+ ten_khach = parts[1]
307
+ if ten_khach in khach_co_gcn:
308
+ continue # đã hoàn thành
309
 
310
+ try:
311
+ local = hf_hub_download(
312
+ repo_id=REPO_ID,
313
+ repo_type="dataset",
314
+ filename=file,
315
+ token=HF_TOKEN,
316
+ cache_dir="/tmp"
317
+ )
318
 
319
+ wb = load_workbook(local, data_only=True)
320
+ sheet = wb.active
321
+
322
+ pyc_code = str(sheet["D3"].value or "").strip()
323
+
324
+ cols_kh = [
325
+ "I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X",
326
+ "Y","Z","AA","AB","AC","AD","AE","AF","AG","AH","AI","AJ","AK",
327
+ "AL","AM","AN","AO","AP","AQ","AR","AS","AT","AU","AV","AW","AX",
328
+ "AY","AZ","BA","BB","BC","BD","BE","BF","BG","BH","BI","BJ","BK",
329
+ "BL","BM","BN","BO","BP","BQ","BR","BS","BT","BU","BV","BW","BX",
330
+ "BY","BZ","CA","CB","CC","CD"
331
+ ]
332
+ khach_hang = "".join(str(sheet[f"{col}8"].value or "") for col in cols_kh).strip()
333
+
334
+ ngay = "".join(str(sheet[f"{col}3"].value or "") for col in ["BM", "BN"]).strip()
335
+ thang = "".join(str(sheet[f"{col}3"].value or "") for col in ["BS", "BT"]).strip()
336
+ nam = "".join(str(sheet[f"{col}3"].value or "") for col in ["BX", "BY", "BZ", "CA"]).strip()
337
+ ngay_tao = f"{ngay}/{thang}/{nam}".strip("/")
338
 
339
+ ket_qua.append({
340
+ "Phiếu yêu cầu": pyc_code or "Không rõ",
341
+ "Khách hàng": khach_hang or ten_khach,
342
+ "Ngày tạo phiếu": ngay_tao or "Không rõ"
343
+ })
344
+
345
+ except Exception as e:
346
+ print(f"Lỗi đọc {file}: {e}")
347
+ continue
348
+
349
+ return ket_qua
350
 
351
  except Exception as e:
352
+ return {"error": str(e)}