Spaces:
Sleeping

doluong6 commited on
Commit
2e86e19
·
verified ·
1 Parent(s): dba4d59

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -57
app.py CHANGED
@@ -274,79 +274,53 @@ def ty_le_dich_vu():
274
  @app.get("/ds_pyc_cho_xu_ly")
275
  def ds_pyc_cho_xu_ly():
276
  try:
277
- all_files = list_repo_files(
278
- repo_id=REPO_ID,
279
- repo_type="dataset",
280
- token=HF_TOKEN
281
- )
282
-
283
- pyc_files = [
284
- f for f in all_files
285
- if f.startswith("Khach_hang/")
286
- and "/Phieu_yeu_cau/" in f
287
- and f.lower().endswith(".xlsx")
288
- ]
289
-
290
- gcn_files = [
291
- f for f in all_files
292
- if f.startswith("Khach_hang/")
293
- and "/Scan/" in f
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)}
 
274
  @app.get("/ds_pyc_cho_xu_ly")
275
  def ds_pyc_cho_xu_ly():
276
  try:
277
+ from utils.list_repo_files import list_repo_files # Đảm bảo utils có hàm này
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
278
 
279
+ all_files = list_repo_files(repo_id=REPO_ID, repo_type="dataset", token=HF_TOKEN)
280
+ ds_pyc = [f for f in all_files if f.startswith("Khach_hang/") and "/Phieu_yeu_cau/" in f and f.endswith(".xlsx")]
 
 
 
 
281
 
282
+ danh_sach_cho_xu_ly = []
 
 
283
 
284
+ for f in ds_pyc:
285
  try:
286
+ khach = f.split("/")[1]
287
+ local_file = hf_hub_download(
288
  repo_id=REPO_ID,
289
  repo_type="dataset",
290
+ filename=f,
291
  token=HF_TOKEN,
292
  cache_dir="/tmp"
293
  )
294
+ wb = load_workbook(local_file, data_only=True)
 
295
  sheet = wb.active
296
 
297
+ # Người lập phiếu
298
+ nguoi_lap = sheet["AH51"].value
299
+ nguoi_lap = nguoi_lap.strip() if isinstance(nguoi_lap, str) else ""
300
+ ten_duoc_chap_nhan = [
301
+ "Nguyễn Duy Thảo", "Lê Danh Huy", "Nguyễn Mạnh Cường",
302
+ "Trần Văn Dương", "Nguyễn Ngọc Vinh"
 
 
 
303
  ]
304
+ if nguoi_lap not in ten_duoc_chap_nhan:
305
+ nguoi_lap = "Không xác định"
306
+
307
+ # Ngày lập phiếu
308
+ ngay = sheet["BM3"].value
309
+ thang = sheet["BS3"].value
310
+ nam = sheet["BX3"].value
311
+ ngay_lap = f"{ngay}/{thang}/{nam}" if all([ngay, thang, nam]) else "Không rõ"
312
+
313
+ danh_sach_cho_xu_ly.append({
314
+ "Khách hàng": khach,
315
+ "File PYC": os.path.basename(f),
316
+ "Người lập": nguoi_lap,
317
+ "Ngày lập": ngay_lap
318
  })
 
319
  except Exception as e:
320
+ print(f"Lỗi đọc file {f}: {e}")
321
  continue
322
 
323
+ return danh_sach_cho_xu_ly
324
 
325
  except Exception as e:
326
  return {"error": str(e)}