Пример #1
0
def editFamily(session_id, tel, nickname, verifyCode):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    if tel == '':
        data = {'code': 1, 'msg': '手机号不能为空'}
        return data
    if nickname == '':
        data = {'code': 1, 'msg': '昵称不能为空'}
        return data
    if verifyCode == '':
        data = {'code': 1, 'msg': '验证码不能为空'}
        return data

    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data

    telCode = redisCon.get(tel)
    if telCode is None:
        data = {'code': 1, 'msg': '验证码错误或已失效'}
        return data
    if int(telCode) != int(verifyCode):
        data = {'code': 1, 'msg': '无法保存家属链接'}
        return data

    result = familyDao.updateFamily(userId, tel, nickname)
    if result == 0:
        data = {'code': 1, 'msg': '无法保存家属链接'}
    else:
        data = {'code': 0}
    return data
Пример #2
0
def retrieveUserPrivacy(session_id):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    userId = int(userId)
    privacy = userPrivacyDao.selectUserPrivacy(userId)
    if privacy is None:
        data = {'code': 1, 'msg': '无法获取隐私权限'}
    else:
        data = {
            'code': 0,
            'isTel': privacy.isTel,
            'isGender': privacy.isGender,
            'isAge': privacy.isAge,
            'isHeight': privacy.isHeight,
            'isWeight': privacy.isWeight,
            'isArea': privacy.isArea,
            'isJob': privacy.isJob,
            'isIntegral': privacy.isIntegral
        }
    return data
Пример #3
0
def editHealth(session_id, insulin, sportTime, weight, bloodPressure,
               healthTime, healthDate):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    if insulin == '':
        data = {'code': 1, 'msg': '胰岛素用量不能为空'}
        return data
    if sportTime == '':
        data = {'code': 1, 'msg': '运动时间不能为空'}
        return data
    if weight == '':
        data = {'code': 1, 'msg': '体重不能为空'}
        return data
    if bloodPressure == '':
        data = {'code': 1, 'msg': '血压不能为空'}
        return data
    if healthTime == '':
        data = {'code': 1, 'msg': '保存时间不能为空'}
        return data
    if healthDate == '':
        data = {'code': 1, 'msg': '日期不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data

    result = healthDao.updateHealth(userId, insulin, sportTime, weight,
                                    bloodPressure, healthTime, healthDate)
    if result == 0:
        data = {'code': 1, 'msg': '无法保存健康记录'}
    else:
        data = {'code': 0}
    return data
Пример #4
0
def createSubReply(session_id, replyId, content):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    if replyId == '':
        data = {'code': 1, 'msg': '跟帖ID不能为空'}
        return data
    if content == '':
        data = {'code': 1, 'msg': 'content不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    replyId = int(replyId)
    userId = int(userId)
    effect_row = subReplyDao.insertSubReply(userId, replyId, content)
    if effect_row == 1:
        data = {'code': 0}

        # 更新话题评论数量、最后回复时间
        reply = replyDao.selectReplyByReplyId(replyId)
        if reply is not None:
            topicId = reply.topicId
            topicDao.updateComnumber(topicId, 1)
            topicDao.updateTopicLastTime(topicId)

        # 更新跟帖评论数
        replyDao.updateComNumber(replyId, 1)

    else:
        data = {'code': 1, 'msg': '评论失败'}
    return data
Пример #5
0
def retrieveUserOneDayHealth(session_id, healthDate):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    if healthDate == '':
        data = {'code': 1, 'msg': '日期不能为空'}
        return data

    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    health = healthDao.selectUserOneDayHealth(userId, healthDate)
    if health is None:
        data = {'code': 1, 'msg': '健康记录获取失败'}
    else:
        data = {
            'code': 0,
            'healthId': health.healthId,
            'insulin': health.insulin,
            'sportTime': health.sportTime,
            'weight': health.weight,
            'bloodPressure': health.bloodPressure,
            'healthTime': health.healthTime
        }
    return data
Пример #6
0
def userRetrieveArticle(session_id, articleId):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    if articleId == '':
        data = {'code': 1, 'msg': 'articleId不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    userId = int(userId)
    articleId = int(articleId)
    articleData = articleDao.selectArticle(articleId)
    favoriteData = favoriteArticleDao.seletcFavoriteArticle(userId, articleId)
    if favoriteData == 1:
        favorite = 1
    else:
        favorite = 0
    if articleData is None:
        data = {'code': 1, 'msg': '查看文章失败'}
    else:
        title = articleData.title
        contentUrl = '/getArticle?articleId=' + str(articleId)
        comNumber = articleData.comNumber
        data = {
            'code': 0,
            'title': title,
            'contentUrl': contentUrl,
            'comNumber': comNumber,
            'favorite': favorite
        }
    return data
Пример #7
0
def removeSubReply(session_id, subreplyId):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    if subreplyId == '':
        data = {'code': 1, 'msg': '跟帖评论ID不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    subreplyId = int(subreplyId)
    subreply = subReplyDao.selectSubReplyBySubReplyId(subreplyId)
    replyId = subreply.replyId
    reply = replyDao.selectReplyByReplyId(replyId)
    topicId = reply.topicId
    result = subReplyDao.deleteSubReply(subreplyId)
    if result == 1:
        # 更新话题中记录的跟帖评论的数量
        topicDao.updateComnumber(topicId, -1)

        # 更新跟帖中记录的跟帖评论的数量
        replyDao.updateComNumber(replyId, -1)

        data = {'code': 0, 'msg': '跟帖评论删除成功'}
    else:
        data = {'code': 1, 'msg': '跟帖评论无法删除'}
    return data
Пример #8
0
def editLikes(session_id, topicId, likes):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    if topicId == '':
        data = {'code': 1, 'msg': '话题ID不能为空'}
        return data
    if likes == '':
        data = {'code': 1, 'msg': '点赞数不能为空'}
        return data
    userId = redisCon.get(session_id)
    topicId = int(topicId)
    likes = int(likes)
    if likes != 1 and likes != -1:
        data = {'code': 1, 'msg': '点赞失败'}
        return data
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    effect_row = topicDao.updateLikes(topicId, likes)
    if effect_row == 1:
        data = {'code': 0}
    else:
        data = {'code': 1, 'msg': '点赞失败'}
    return data
Пример #9
0
def retrieveUserBySessionId(session_id):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    try:
        userId = redisCon.get(session_id)
        result = usersDao.selectUserByUserId(userId)
    except Exception:
        data = {'code': 1, 'msg': '用户信息获取失败'}
        return data
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    if result is None:
        data = {'code': 1, 'msg': '用户信息获取失败'}
    else:
        data = {
            'code': 0,
            'tel': result['tel'],
            'username': result['username'],
            'gender': result['gender'],
            'age': result['age'],
            'height': result['height'],
            'weight': result['weight'],
            'area': result['area'],
            'job': result['job'],
            'iconUrl': result['iconUrl'],
            'integral': result['integral']
        }
    return data
Пример #10
0
def editLikes(session_id, replyId, isLike):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    if replyId == '':
        data = {'code': 1, 'msg': '跟帖ID不能为空'}
        return data
    if isLike == '':
        data = {'code': 1, 'msg': '点赞数不能为空'}
        return data
    userId = redisCon.get(session_id)
    replyId = int(replyId)
    isLike = int(isLike)
    if isLike != 1 and isLike != -1:
        data = {'code': 1, 'msg': '点赞失败'}
        return data
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    effect_row = replyDao.updateLikes(replyId, isLike)
    if effect_row == 1:
        data = {'code': 0}
    else:
        data = {'code': 1, 'msg': '点赞失败'}
    return data
Пример #11
0
def retrieveFamilyList(session_id):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data

    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data

    familyData = familyDao.selectFamilyByUserId(userId)
    if familyData is None:
        data = {'code': 1, 'msg': '家属连接获取失败'}
    else:
        data = []
        total = familyDao.selectSumFamily(userId)
        for family in familyData:
            familyId = family.familyId
            tel = family.tel
            nickname = family.nickname
            data.append({
                'familyId': familyId,
                'tel': tel,
                'nickname': nickname
            })
        data = {'code': 0, 'data': data, 'total': total}
    return data
Пример #12
0
def createUser(tel, username, verifyCode, password):
    if tel == '':
        data = {'code': 1, 'msg': '手机号不能为空'}
        return data
    if username == '':
        data = {'code': 1, 'msg': '用户名不能为空'}
        return data
    if verifyCode == '':
        data = {'code': 1, 'msg': '验证码不能为空'}
        return data
    if password == '':
        data = {'code': 1, 'msg': '密码不能为空'}
        return data

    tableCode = redisCon.get(tel)
    if tableCode is None:
        data = {'code': 1, 'msg': '验证码错误或已失效'}
        return data
    if int(tableCode) == int(verifyCode):
        result = usersDao.insertUser(tel, password, username)
        if result == 0:
            userData = usersDao.selectUserByTel(tel)
            userId = userData.userId
            effect_raw = userPrivacyDao.insertUserPrivacy(userId)
            if effect_raw == 1:
                data = {'code': 0}
            else:
                data = {'code': 1, 'msg': '注册失败'}
        elif result == 2:
            data = {'code': 1, 'msg': '该用户已经注册'}
        else:
            data = {'code': 1, 'msg': '注册失败'}
    else:
        data = {'code': 1, 'msg': '验证码错误或已失效'}
    return data
Пример #13
0
def retrieveFollowMeList(session_id, x, n):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data

    userId = int(userId)
    x = int(x)
    n = int(n)
    if x < 0 or n <= 0:
        data = {'code': 1, 'msg': '关注获取失败'}
        return data
    result = followDao.selectFollowMeList(userId, x, n)
    if result is None:
        data = {'code': 1, 'msg': '请先登录'}
    else:
        data = []
        total = followDao.selectSumFollowByFollowId(userId)
        for followMe in result:
            followMeId = followMe.userId
            userData = usersDao.selectUserByUserId(int(followMeId))
            fol = {
                'followMeId ': followMeId,
                'username': userData['username'],
                'iconUrl': userData['iconUrl']
            }
            data.append(fol)
        data = {'code': 0, 'data': data, 'total': total}
    return data
Пример #14
0
def getArticleLikeTitle(session_id, labelName, keyword, x, n):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    if keyword == '':
        data = {'code': 1, 'msg': '关键词不能为空'}
        return data
    if x == '':
        data = {'code': 1, 'msg': '起始位置不能为空'}
        return data
    if n == '':
        data = {'code': 1, 'msg': '文章数量不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    labelList = eval(labelName)
    while len(labelList) < 5:
        labelList.append('')
    labelOne = str(labelList[0])
    labelTwo = str(labelList[1])
    labelThree = str(labelList[2])
    labelFour = str(labelList[3])
    labelFive = str(labelList[4])
    x = int(x)
    n = int(n)
    if n <= 0 or x < 0:
        data = {'code': 1, 'msg': '搜索失败'}
        return data
    result = articleDao.selectArticleLikeTitle(labelOne, labelTwo, labelThree,
                                               labelFour, labelFive, keyword,
                                               x, n)
    if result is None:
        data = {'code': 1, 'msg': '无法搜索文章'}
    else:
        data = []
        total = articleDao.selectSumArticleLikeTitle(labelOne, labelTwo,
                                                     labelThree, labelFour,
                                                     labelFive, keyword)
        for article in result:
            articleId = article.articleId
            title = article.title
            content = article.content[:30]
            articleTime = article.articleTime.strftime('%Y-%m-%d %H:%M:%S')
            imgData = getImgUrlByArticleId(articleId)
            imgUrl = imgData['imgUrl']
            views = article.views
            art = {
                'articleId': articleId,
                'title': title,
                'content': content,
                'articleTime': articleTime,
                'imgUrl': imgUrl,
                'views': views
            }
            data.append(art)
        data = {'code': 0, 'data': data, 'total': total}
    return data
Пример #15
0
def adminGetFromXGetNTopic(session_id, x, n):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    if x == '':
        data = {'code': 1, 'msg': 'x不能为空'}
        return data
    if n == '':
        data = {'code': 1, 'msg': 'n不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    x = int(x)
    n = int(n)
    if x < 0 or n <= 0:
        data = {'code': 1, 'msg': '话题获取失败'}
        return data
    result = topicDao.selectFromXGetNTopic(x, n)
    if result is None:
        data = {'code': 1, 'msg': '话题获取失败'}
        return data
    else:
        data = []
        total = topicDao.selectSumTopic()
        for topic in result:
            topicId = topic.topicId
            userId = topic.userId
            lastTime = topic.lastTime.strftime('%Y-%m-%d %H:%M:%S')
            content = topic.content[:40]
            picture1 = topic.picture1
            picture2 = topic.picture2
            picture3 = topic.picture3
            replyNum = topic.replyNum
            comNum = topic.comNum
            user = usersDao.selectUserByUserId(userId)
            if user is None:
                data = {'code': 1, 'msg': '话题获取失败'}
                return data
            username = user['username']
            iconUrl = user['iconUrl']

            top = {'topicId': topicId,
                   'userId': userId,
                   'username': username,
                   'iconUrl': iconUrl,
                   'lastTime': lastTime,
                   'content': content,
                   'picture1': picture1,
                   'picture2': picture2,
                   'picture3': picture3,
                   'replyNum': replyNum,
                   'comNum': comNum}
            data.append(top)
        data = {'code': 0, 'rows': data, 'total': total}
    return data
Пример #16
0
def retireveHealthWeekly(session_id):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    dietData = dietPlanDao.selectDietPlan(userId)
    sportData = sportPlanDao.selectSportPlan(userId)
    controlData = controlPlanDao.selectConteolPlan(userId)
    cerealsValue = int(dietData.cereals)
    fruitValue = int(dietData.fruit)
    meatValue = int(dietData.meat)
    milkValue = int(dietData.milk)
    fatValue = int(dietData.fat)
    vegetablesValue = int(dietData.vegetables)

    diet = {'cereals': str(25 * cerealsValue) + '克大米, 麦片,面食, 面包, '+str(50 * cerealsValue)+'克马铃薯',
            'fruit': str(500*fruitValue) + '克西瓜, +' + str(300*fruitValue) + '克草莓,'+str(200*fruitValue)+'克葡萄,橙子,橘子 '+str(150*fruitValue)+'克香蕉,荔枝',
            'meat': str(25*meatValue) + '克大豆,' + str(20*meatValue) + '克腐竹,' + str(60*meatValue) + '克鸡蛋,' + str(50*meatValue) + '克鸭肉,猪肉,' + str(80*meatValue) + '克草鱼,' + str(100*meatValue) +'克鲫鱼',
            'milk': str(20*milkValue) + '克奶粉,' + str(160*milkValue) + '克牛奶,羊奶',
            'fat': '(一汤勺为准)' + str(10*fatValue) + '克花生油,豆油,黄油,菜籽油,'+ str(15*fatValue) + '克核桃,杏仁,花生',
            'vegetables': str(500*vegetablesValue) + '克白菜,韭菜,西红柿,冬瓜,茄子,丝瓜,' + str(200*vegetablesValue)+'克胡萝卜,' + str(150*vegetablesValue) + '克山药,' + str(70*vegetablesValue) +'克毛豆',
            'cerealsValue': cerealsValue,
            'fruitValue': fruitValue,
            'meatValue': meatValue,
            'milkValue': milkValue,
            'fatValue': fatValue,
            'vegetablesValue': vegetablesValue}

    sport = {
        'sport1': sportData.sport1,
        'sport2': sportData.sport2,
        'sport3': sportData.sport3,
        'sport4': sportData.sport4,
        'time1': sportData.time1,
        'time2': sportData.time2,
        'time3': sportData.time3,
        'time4': sportData.time4,
        'week1': sportData.week1,
        'week2': sportData.week1,
        'week3': sportData.week1,
        'week4': sportData.week1,
    }
    control = {
        'min1': controlData.min1,
        'max1': controlData.max1,
        'min2': controlData.min1,
        'max2': controlData.max2,
        'sleep1': controlData.sleep1,
        'sleep2': controlData.sleep2,

    }
    data = {'code': 0, 'diet': diet, 'sport': sport, 'control': control}
    return data
Пример #17
0
def retrieveSubReplyFromXGetN(session_id, replyId, x, n):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    if replyId == '':
        data = {'code': 1, 'msg': '跟帖ID不能为空'}
        return data
    if x == '':
        data = {'code': 1, 'msg': 'x不能为空'}
        return data
    if n == '':
        data = {'code': 1, 'msg': 'n不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    replyId = int(replyId)
    x = int(x)
    n = int(n)
    if x < 0 or n <= 0:
        data = {'code': 1, 'msg': '跟帖评论获取失败'}
        return data
    result = subReplyDao.selectSubReplyFromXGetN(replyId, x, n)
    if result is None:
        data = {'code': 1, 'msg': '跟帖评论获取失败'}
        return data
    else:
        data = []
        total = subReplyDao.selectSumSubReplyByReplyId(replyId)
        for subreply in result:
            subreplyId = subreply.subreplyId
            userId = subreply.userId
            subreplyTime = subreply.subreplyTime.strftime('%Y-%m-%d %H:%M:%S')
            content = subreply.content
            likes = subreply.likes

            user = usersDao.selectUserByUserId(userId)
            if user is None:
                data = {'code': 1, 'msg': '跟帖评论获取失败'}
                return data
            username = user['username']
            iconUrl = user['iconUrl']

            subrep = {
                'subreplyId': subreplyId,
                'userId': userId,
                'iconUrl': iconUrl,
                'username': username,
                'content': content,
                'subreplyTime': subreplyTime,
                'likes': likes
            }
            data.append(subrep)
        data = {'code': 0, 'data': data}
    return data
Пример #18
0
def retrieveLastTopicList(session_id, topicIdList, n):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    if topicIdList == '':
        data = {'code': 1, 'msg': '已有话题列表不能为空'}
        return data
    if n == '':
        data = {'code': 1, 'msg': 'n不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    n = int(n)
    if n <= 0:
        data = {'code': 1, 'msg': '话题获取失败'}
        return data
    topicIdList = eval(topicIdList)
    result = topicDao.selectLastTopicList(topicIdList, n)
    if result is None:
        data = {'code': 1, 'msg': '话题获取失败'}
        return data
    else:
        data = []
        for topic in result:
            topicId = topic.topicId
            userId = topic.userId
            lastTime = topic.lastTime.strftime('%Y-%m-%d %H:%M:%S')
            content = topic.content[:40]
            picture1 = topic.picture1
            picture2 = topic.picture2
            picture3 = topic.picture3
            replyNum = topic.replyNum
            comNum = topic.comNum
            user = usersDao.selectUserByUserId(userId)
            if user is None:
                data = {'code': 1, 'msg': '话题获取失败'}
                return data
            username = user['username']
            iconUrl = user['iconUrl']

            top = {'topicId': topicId,
                   'userId': userId,
                   'username': username,
                   'iconUrl': iconUrl,
                   'lastTime': lastTime,
                   'content': content,
                   'picture1': picture1,
                   'picture2': picture2,
                   'picture3': picture3,
                   'replyNum': replyNum,
                   'comNum': comNum}
            data.append(top)
        data = {'code': 0, 'data': data}
    return data
Пример #19
0
def adminGetFromXGetNUser(session_id, x, n):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    if x == '':
        data = {'code': 1, 'msg': 'x不能为空'}
        return data
    if n == '':
        data = {'code': 1, 'msg': 'n不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    x = int(x)
    n = int(n)
    if x < 0 or n <= 0:
        data = {'code': 1, 'msg': '无法获取用户'}
        return data
    result = usersDao.selectFromXGetNUser(x, n)
    if result is None:
        data = {'code': 1, 'msg': '无法获取x之后n个用户'}
        return data
    else:
        data = []
        total = usersDao.selectSumUsers()
        for user in result:
            userId = user.userId
            tel = user.tel
            username = user.username
            gender = user.gender
            age = user.age
            signTime = user.signTime.strftime('%Y-%m-%d %H:%M:%S')
            height = user.height
            weight = user.weight
            area = user.area
            job = user.job
            integral = user.integral
            users = {
                'userId': userId,
                'tel': tel,
                'username': username,
                'gender': gender,
                'age': age,
                'signTime': signTime,
                'height': height,
                'weight': weight,
                'area': area,
                'job': job,
                'integral': integral
            }
            data.append(users)
        temp = {'total': total, 'rows': data, 'code': 0}
        return temp
Пример #20
0
def retrieveFavoriteTopic(session_id, x, n):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    if x == '':
        data = {'code': 1, 'msg': 'x不能为空'}
        return data
    if n == '':
        data = {'code': 1, 'msg': 'n不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    userId = int(userId)
    x = int(x)
    n = int(n)
    if x < 0 or n <= 0:
        data = {'code': 1, 'msg': '获取收藏的话题失败'}
        return data
    favoriteData = favoriteTopicDao.seletcUserFavoriteTopic(userId, x, n)
    if favoriteData is None:
        data = {'code': 1, 'msg': '获取收藏的话题失败'}
    else:
        data = []
        total = favoriteTopicDao.selectSumFavoriteTopicByUserId(userId)
        for favorite in favoriteData:
            topicId = favorite.topicId
            topic = topicDao.selectTopicByTopicId(topicId)
            user = usersDao.selectUserByUserId(userId)
            if topic is None or user is None:
                data = {'code': 1, 'msg': '获取收藏的话题失败'}
                return data

            content = topic.content[:40]
            picture1 = topic.picture1
            picture2 = topic.picture2
            picture3 = topic.picture3
            iconUrl = user['iconUrl']
            username = user['username']

            data.append({
                'topicId': topicId,
                'content': content,
                'picture1': picture1,
                'picture2': picture2,
                'picture3': picture3,
                'userId': userId,
                'iconUrl': iconUrl,
                'username': username
            })
        data = {'code': 0, 'data': data, 'total': total}
    return data
Пример #21
0
def userLogout(session_id):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '无法登出'}
    else:
        redisCon.delete(userId)
        redisCon.delete(session_id)
        data = {'code': 0}
    return data
Пример #22
0
def retrieveTopicByUserId(session_id, x, n):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    if x == '':
        data = {'code': 1, 'msg': 'x不能为空'}
        return data
    if n == '':
        data = {'code': 1, 'msg': 'n不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    x = int(x)
    n = int(n)
    if x < 0 or n <= 0:
        data = {'code': 1, 'msg': '获取话题失败'}
        return data
    topicData = topicDao.selectFromXGetNTopicByUserId(userId, x, n)
    if topicData is None:
        data = {'code': 1, 'msg': '获取话题失败'}
    else:
        data = []
        total = topicDao.selectSumTopicByUserId(userId)
        for topic in topicData:
            topicId = topic.topicId
            content = topic.content[:40]
            picture1 = topic.picture1
            picture2 = topic.picture2
            picture3 = topic.picture3
            replyNum = topic.replyNum
            comNum = topic.comNum
            likes = topic.likes
            topicTime = topic.topicTime.strftime('%Y-%m-%d %H:%M:%S')
            favoriteNum = favoriteTopicDao.selectSumTopicByTopicId(topicId)

            top = {'topicId': topicId,
                   'content': content,
                   'picture1': picture1,
                   'picture2': picture2,
                   'picture3': picture3,
                   'replyNum': replyNum,
                   'comNum': comNum,
                   'likes': likes,
                   'topicTime': topicTime,
                   'favoriteNum': favoriteNum
                   }
            data.append(top)
        data = {'code': 0, 'data': data}
    return data
Пример #23
0
def getFromXGetNCommentByArticleId(session_id, articleId, x, n):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    if articleId == '':
        data = {'code': 1, 'msg': 'articleId不能为空'}
        return data
    if x == '':
        data = {'code': 1, 'msg': 'x不能为空'}
        return data
    if n == '':
        data = {'code': 1, 'msg': 'n不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    articleId = int(articleId)
    x = int(x)
    n = int(n)
    if x < 0 or n <= 0:
        data = {'code': 1, 'msg': '评论获取失败'}
        return data
    result = commentDao.selectFromXGetNCommentByArticleId(articleId, x, n)
    if result is None:
        data = {'code': 1, 'msg': '无法获取x之后n个评论'}
    else:
        data = []
        total = commentDao.selectSumCommentByArticleId(articleId)
        for comment in result:
            commentId = comment.commentId
            content = comment.content
            commentTime = comment.commentTime.strftime('%Y-%m-%d %H:%M:%S')
            userId = comment.userId
            likes = comment.likes
            userData = usersDao.selectUserByUserId(userId)
            username = userData['username']
            iconUrl = userData['iconUrl']

            art = {'commentId': commentId,
                   'content': content,
                   'commentTime': commentTime,
                   'userId': userId,
                   'likes': likes,
                   'username': username,
                   'iconUrl': iconUrl
                   }
            data.append(art)
        data = {'code': 0, 'data': data, 'total': total}
    return data
Пример #24
0
def retrieveTopicLikeTopic(session_id, keyword, x, n):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    if keyword == '':
        data = {'code': 1, 'msg': '关键词不能为空'}
        return data
    if x == '':
        data = {'code': 1, 'msg': '起始位置不能为空'}
        return data
    if n == '':
        data = {'code': 1, 'msg': '文章数量不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    x = int(x)
    n = int(n)
    if n <= 0 or x < 0:
        data = {'code': 1, 'msg': '搜索失败'}
        return data
    result = topicDao.selectTopicLikeContent(keyword, x, n)
    if result is None:
        data = {'code': 1, 'msg': '无法搜索文章'}
    else:
        data = []
        total = topicDao.selectSumTopicLikeContent(keyword)
        for topic in result:
            topicId = topic.topicId
            lastTime = topic.lastTime.strftime('%Y-%m-%d %H:%M:%S')
            content = topic.content[:40]
            userId = topic.userId
            user = usersDao.selectUserByUserId(userId)
            if user is None:
                data = {'code': 1, 'msg': '话题获取失败'}
                return data
            username = user['username']
            iconUrl = user['iconUrl']
            top = {'topicId': topicId,
                   'lastTime': lastTime,
                   'content': content,
                   'userId': userId,
                   'username': username,
                   'iconUrl': iconUrl
                   }
            data.append(top)
        data = {'code': 0, 'data': data, 'total': total}
    return data
Пример #25
0
def retrieveTopicByTopicId(session_id, topicId):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    if topicId == '':
        data = {'code': 1, 'msg': 'topicId不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data

    userId = int(userId)
    topicId = int(topicId)
    topic = topicDao.selectTopicByTopicId(topicId)
    if topic is None:
        data = {'code': 1, 'msg': '获取话题失败'}
    else:
        topicTime = topic.topicTime.strftime('%Y-%m-%d %H:%M:%S')
        likes = topic.likes
        content = topic.content
        picture1 = topic.picture1
        picture2 = topic.picture2
        picture3 = topic.picture3
        picture4 = topic.picture4
        picture5 = topic.picture5
        favorite = favoriteTopicDao.seletcFavoriteTopic(userId, topicId)
        topicUserId = topic.userId
        user = usersDao.selectUserByUserId(topicUserId)
        if user is None:
            data = {'code': 1, 'msg': '话题获取失败'}
            return data
        username = user['username']
        iconUrl = user['iconUrl']
        top = {'userId': topicUserId,
               'username': username,
               'iconUrl': iconUrl,
               'topicTime': topicTime,
               'favorite': favorite,
               'likes': likes,
               'content': content,
               'picture1': picture1,
               'picture2': picture2,
               'picture3': picture3,
               'picture4': picture4,
               'picture5': picture5,
               }
        data = {'code': 0, 'data': top}
    return data
Пример #26
0
def removeUser(session_id, userId):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    user = redisCon.get(session_id)
    if user is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    userId = int(userId)
    result = usersDao.deleteUser(userId)
    if result == 1:
        data = {'code': 0, 'msg': '用户删除成功'}
    else:
        data = {'code': 1, 'msg': '用户删除失败'}
    return data
Пример #27
0
def editUserCheckTime(session_id):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    userId = int(userId)
    result = usersDao.updateCheckTime(userId)
    if result == 1:
        data = {'code': 0}
    else:
        data = {'code': 1, 'msg': '签到失败'}
    return data
Пример #28
0
def retrieveUserBlood(session_id, x, n):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    if x == '':
        data = {'code': 1, 'msg': 'x不能为空'}
        return data
    if n == '':
        data = {'code': 1, 'msg': 'n不能为空'}
        return data
    x = int(x)
    n = int(n)
    if x < 0 or n <= 0:
        data = {'code': 1, 'msg': '血糖记录获取失败'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    bloodData = bloodDao.selectUserBloodFromXGetN(userId, x, n)
    if bloodData is None:
        data = {'code': 1, 'msg': '血糖记录获取失败'}
    else:
        data = []
        total = bloodDao.selectSumBlood(userId)
        for blood in bloodData:
            bloodId = blood.bloodId
            level = json.loads(blood.level)
            bloodData = blood.bloodDate.strftime('%Y-%m-%d')
            levelList = [float(v) for v in level.values()]
            averageBlood = '%.2f' % (sum(levelList) / 7.0)
            maxBlood = max(levelList)
            minBlood = 1000
            for i in range(len(levelList)):
                if levelList[i] != 0:
                    minBlood = min(minBlood, levelList[i])

            data.append({
                'bloodId': bloodId,
                'averageBlood': averageBlood,
                'maxBlood': maxBlood,
                'minBlood': minBlood,
                'bloodDate': bloodData
            })
        data = {'code': 0, 'data': data, 'total': total}
    return data
Пример #29
0
def removeFavoriteArticle(session_id, articleId):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    if articleId == '':
        data = {'code': 1, 'msg': 'articleId不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    effect_row = favoriteArticleDao.deleteFavoriteArticle(userId, articleId)
    if effect_row == 1:
        data = {'code': 0}
    else:
        data = {'code': 1, 'msg': '已取消收藏'}
    return data
Пример #30
0
def retrieveCommentByUserId(session_id, x, n):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    if x == '':
        data = {'code': 1, 'msg': 'x不能为空'}
        return data
    if n == '':
        data = {'code': 1, 'msg': 'n不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    x = int(x)
    n = int(n)
    if x < 0 or n <= 0:
        data = {'code': 1, 'msg': '获取收藏的文章失败'}
        return data
    commentData = commentDao.selectCommentByUser(userId, x, n)
    if commentData is None:
        data = {'code': 1, 'msg': '无法获取评论'}
    else:
        data = []
        total = commentDao.selectSumCommentByUserId(userId)
        for comment in commentData:
            commentId = comment.commentId
            content = comment.content[:20]
            likes = comment.likes
            commentTime = comment.commentTime.strftime('%Y-%m-%d %H:%M:%S')
            articleId = comment.articleId
            article = articleDao.selectArticle(articleId)
            if article is None:
                data = {'code': 1, 'msg': '无法获取评论'}
            else:
                title = article.title
                com = {'commentId': commentId,
                       'content': content,
                       'title': title,
                       'articleId': articleId,
                       'likes': likes,
                       'commentTime': commentTime
                       }
                data.append(com)
        data = {'code': 0, 'data': data, 'total': total}
    return data