123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- # coding=utf-8
- from base import init_env
- init_env(interactive = True)
- from apps.web.user.models import Card
- from apps.web.agent.models import Agent
- """
- 把所有的厂商下面的卡都找出来
- 相同厂商下应该只有一张卡
- 统计相同厂商下 卡号相同的卡的数量
- """
- cards = Card.objects.all()
- no_agent_cards = list()
- normal_cards = list()
- repetitive_cards = list()
- checked_cards = list()
- def check():
- for card in cards:
- print str(card.id)
- if str(card.id) in checked_cards:
- continue
- if not card.agentId:
- continue
- agent = Agent.objects.get(id=card.agentId)
- if not agent:
- no_agent_cards.append(str(card.id))
- continue
- check_cards = Card.objects.filter(cardNo=card.cardNo, agentId__in=agent.agentIds)
- if check_cards.count() > 1:
- temp = [str(item.id) for item in check_cards]
- repetitive_cards.append("----".join(temp))
- checked_cards.extend(temp)
- continue
- normal_cards.append(str(card.id))
- def write_files():
- from pprint import pprint
- print "no agent cards"
- pprint(no_agent_cards)
- print "normal cards"
- pprint(normal_cards)
- print "error cards"
- pprint(repetitive_cards)
- with open("card_check_report.txt", "w") as f:
- f.write(" no agent cards %s \n" % len(no_agent_cards))
- f.write("\n".join(no_agent_cards))
- f.write("\n normal cards %s \n" % len(normal_cards))
- f.write("\n".join(normal_cards))
- f.write("\n repetitive cards %s \n" % len(repetitive_cards))
- f.write("\n".join(repetitive_cards))
- def main():
- check()
- write_files()
- if __name__ == '__main__':
- main()
|