import_damage_override.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import pymysql
  2. conn = pymysql.connect(
  3. host="127.0.0.1",
  4. user="root",
  5. password="root",
  6. database="recycle",
  7. charset="utf8mb4"
  8. )
  9. damage_groups = [
  10. ("boot", "开机状态组", 1.00, 1.00),
  11. ("body", "机身外观组", 1.20, 1.00),
  12. ("screen", "屏幕综合组", 1.25, 1.10),
  13. ("account", "账号状态组", 1.00, 1.00),
  14. ("function", "功能异常组", 1.15, 1.00),
  15. ("hinge", "转轴结构组", 1.10, 1.00),
  16. ("repair", "维修履历组", 1.30, 1.10),
  17. ("other_special", "其他功能问题组", 1.00, 1.00),
  18. ]
  19. group_overrides = [
  20. # 有维修 → 屏幕组权重下降
  21. ("repair", "screen", "weight", 0.85),
  22. # 无法开机类问题存在时,功能异常组跳过
  23. ("boot", "function", "skip", None),
  24. ]
  25. with conn.cursor() as cur:
  26. # ----------------------------
  27. # price_damage_group
  28. # ----------------------------
  29. for g in damage_groups:
  30. cur.execute("""
  31. INSERT INTO price_damage_group
  32. (group_code, group_name, cap_ratio, group_weight)
  33. VALUES (%s,%s,%s,%s)
  34. ON DUPLICATE KEY UPDATE
  35. group_name=VALUES(group_name),
  36. cap_ratio=VALUES(cap_ratio),
  37. group_weight=VALUES(group_weight)
  38. """, g)
  39. # ----------------------------
  40. # price_group_override
  41. # ----------------------------
  42. for o in group_overrides:
  43. cur.execute("""
  44. INSERT INTO price_group_override
  45. (trigger_group_code, target_group_code, override_type, override_value)
  46. VALUES (%s,%s,%s,%s)
  47. ON DUPLICATE KEY UPDATE
  48. override_type=VALUES(override_type),
  49. override_value=VALUES(override_value)
  50. """, o)
  51. conn.commit()
  52. print("price_damage_group / price_group_override 初始化完成")