card_collection.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # coding=utf-8
  2. from base import init_env
  3. init_env(interactive = True)
  4. from apps.web.user.models import Card
  5. from apps.web.agent.models import Agent
  6. """
  7. 把所有的厂商下面的卡都找出来
  8. 相同厂商下应该只有一张卡
  9. 统计相同厂商下 卡号相同的卡的数量
  10. """
  11. cards = Card.objects.all()
  12. no_agent_cards = list()
  13. normal_cards = list()
  14. repetitive_cards = list()
  15. checked_cards = list()
  16. def check():
  17. for card in cards:
  18. print str(card.id)
  19. if str(card.id) in checked_cards:
  20. continue
  21. if not card.agentId:
  22. continue
  23. agent = Agent.objects.get(id=card.agentId)
  24. if not agent:
  25. no_agent_cards.append(str(card.id))
  26. continue
  27. check_cards = Card.objects.filter(cardNo=card.cardNo, agentId__in=agent.agentIds)
  28. if check_cards.count() > 1:
  29. temp = [str(item.id) for item in check_cards]
  30. repetitive_cards.append("----".join(temp))
  31. checked_cards.extend(temp)
  32. continue
  33. normal_cards.append(str(card.id))
  34. def write_files():
  35. from pprint import pprint
  36. print "no agent cards"
  37. pprint(no_agent_cards)
  38. print "normal cards"
  39. pprint(normal_cards)
  40. print "error cards"
  41. pprint(repetitive_cards)
  42. with open("card_check_report.txt", "w") as f:
  43. f.write(" no agent cards %s \n" % len(no_agent_cards))
  44. f.write("\n".join(no_agent_cards))
  45. f.write("\n normal cards %s \n" % len(normal_cards))
  46. f.write("\n".join(normal_cards))
  47. f.write("\n repetitive cards %s \n" % len(repetitive_cards))
  48. f.write("\n".join(repetitive_cards))
  49. def main():
  50. check()
  51. write_files()
  52. if __name__ == '__main__':
  53. main()