diff --git a/__pycache__/crud.cpython-312.pyc b/__pycache__/crud.cpython-312.pyc index b460eda..1819740 100644 Binary files a/__pycache__/crud.cpython-312.pyc and b/__pycache__/crud.cpython-312.pyc differ diff --git a/__pycache__/main.cpython-312.pyc b/__pycache__/main.cpython-312.pyc index 2274479..a1c3f7f 100644 Binary files a/__pycache__/main.cpython-312.pyc and b/__pycache__/main.cpython-312.pyc differ diff --git a/__pycache__/models.cpython-312.pyc b/__pycache__/models.cpython-312.pyc index 9a8fb0e..55ac971 100644 Binary files a/__pycache__/models.cpython-312.pyc and b/__pycache__/models.cpython-312.pyc differ diff --git a/__pycache__/schemas.cpython-312.pyc b/__pycache__/schemas.cpython-312.pyc index 156f437..31f4f90 100644 Binary files a/__pycache__/schemas.cpython-312.pyc and b/__pycache__/schemas.cpython-312.pyc differ diff --git a/crud.py b/crud.py index fe3d8c1..9c1e311 100644 --- a/crud.py +++ b/crud.py @@ -2,7 +2,8 @@ from sqlalchemy.orm import Session # from . import models, schemas import models, schemas - +import json +import time # 通过id获取用户 def get_user(db: Session, user_id: int): @@ -23,6 +24,7 @@ def get_users(db: Session, skip: int = 0, limit: int = 100): # user:schemas.UserCreate # **user def create_user(db: Session, user:schemas.User): +# def create_user(db: Session, user): db_user = models.User( wxid=user.wxid, openId=user.openId, @@ -35,7 +37,12 @@ def create_user(db: Session, user:schemas.User): wxaccount=user.wxaccount, remark=user.remark, smallhead=user.smallhead, + bighead=user.bighead, + labels=user.labels, + source=user.source, + v1=user.v1 ) + db.add(db_user) db.commit() db.refresh(db_user) diff --git a/kunpeng.db b/kunpeng.db index efbb397..5ab9185 100644 Binary files a/kunpeng.db and b/kunpeng.db differ diff --git a/main.py b/main.py index 005929e..bb19d30 100644 --- a/main.py +++ b/main.py @@ -48,6 +48,9 @@ async def root(): @app.post("/users/") # schemas.UserCreate决定了swagger文档 def create_user(user: schemas.User, db: Session = Depends(get_db)): + print('user',user) + print('typeuser',type(user)) + db_user = crud.create_user(db, user) if db_user: raise HTTPException(status_code=400, @@ -212,8 +215,9 @@ def kp(event_data): # 将好友信息=>保存到数据库 newFriendDict=WXBotService.get_friend_info(account_wxid, wxid) print('newFriendDict[data]---',newFriendDict['data']) - # print(type(newFriendDict['data'])) - crud.create_user(db=get_db(),user=json.dumps(newFriendDict['data'])) + userClass=models.User(**(newFriendDict['data'])) + print('userClass====',type(userClass)) + crud.create_user(db=SessionLocal(),user=userClass) elif msg_type == 3: # 3 图片消息 @@ -237,8 +241,9 @@ def kp(event_data): xml_msg.get('scene')) newFriendWxid=xml_msg.get('alias') # 将好友信息=>保存到数据库 - newFriendDict=WXBotService.get_friend_info(account_wxid, newFriendWxid) - crud.create_user(db=get_db(),user=newFriendDict) + # newFriendDict=WXBotService.get_friend_info(account_wxid, newFriendWxid) + # userClass=models.User(**(newFriendDict['data'])) + # crud.create_user(db= SessionLocal(),user=userClass) elif msg_type == 42: # 42 名片消息 xml_msg = ET.fromstring(msg) diff --git a/models.py b/models.py index ad7138c..2446fa0 100644 --- a/models.py +++ b/models.py @@ -20,11 +20,11 @@ class User(Base): wxaccount = Column(String) #微信号 remark = Column(String) #备注 smallhead = Column(String) #头像 - # bighead = Column(String) #头像-打 - # labels = Column(String) # - # source = Column(String) #来源 - # generator = Column(String) - # v1 = Column(String) + bighead = Column(String) #头像-打 + labels = Column(String) # + source = Column(String) #来源 + generator = Column(String) + v1 = Column(String) diff --git a/schemas.py b/schemas.py index 45fb242..104272c 100644 --- a/schemas.py +++ b/schemas.py @@ -13,6 +13,12 @@ class UserCreate(BaseModel): wxaccount: str remark: str smallhead: str + bighead: str + labels: str + source: str + v1: str + +