Esempio n. 1
0
def create_SGlog(project, user, date, text, sgtqlog):
    """
    创建施工日志详细数据
    by:王健 at:2015-1-21
    :param project:
    :param user:
    :param date:
    :param text:
    :param sgtqlog:
    :return:
    """
    l = SGlog()
    l.project = project
    l.sg_tq_log = sgtqlog
    l.user = user
    l.text = text
    l.create_time = date
    l.save()
Esempio n. 2
0
def create_SGlog(project, user, date, text, sgtqlog):
    """
    创建施工日志详细数据
    by:王健 at:2015-1-21
    :param project:
    :param user:
    :param date:
    :param text:
    :param sgtqlog:
    :return:
    """
    l = SGlog()
    l.project = project
    l.sg_tq_log = sgtqlog
    l.user = user
    l.text = text
    l.create_time = date
    l.save()
Esempio n. 3
0
def update_log_by_date(request, project_id=None):
    """
    更新或添加新的施工日志根据日期、天气
    by:王健 at:2015-1-6
    修改属性名
    by:王健 at:2015-1-8
    修改属性名,天气和风力
    by:王健 at:2015-1-12
    修改Model名字,去除下划线
    by:王健 at:2015-1-13
    天气表增加 timeline、num、create_time 字段
    by:王健 at:2015-1-20
    返回的数据,包括施工天气信息
    by:王健 at:2015-1-28
    增加积分
    by:王健 at:2015-2-5
    记录日志最后上传人
    by:王健 at:2015-2-10
    修改权限校验 函数
    by:王健 at:2015-3-4
    提交日志时刷新阅读时间
    by:尚宗凯 at:2015-05-06
    增加最新数据时间缓存
    by:尚宗凯 at:2015-05-20
    修复小红点bug
    by:尚宗凯 at:2015-05-27
    增加项目状态为 0 装饰器
    by:尚宗凯 at:2015-05-31
	变更极光推送方法
	by:尚宗凯 at:2015-05-31
	添加用户活跃度缓存
    by:尚宗凯 at:2015-06-04
    """
    if not request.REQUEST.get('text'):
        return getResult(False, u'日志内容不能为空', None)
    sg_tq_id = request.REQUEST.get('sg_tq_id', '')
    if not sg_tq_id:
        sg_tq_log, create = SGTQlog.objects.get_or_create(
            project_id=project_id,
            file_group=FileGroup.objects.get(flag='gong_cheng_ri_zhi'),
            date=timezone.now())

    else:
        sg_tq_log = SGTQlog.objects.get(pk=sg_tq_id)
    f = False
    if not sg_tq_log.weather:
        sg_tq_log.weather = request.REQUEST.get('weather', '')
        f = True
    if not sg_tq_log.wind:
        sg_tq_log.wind = request.REQUEST.get('wind')
        f = True
    if not sg_tq_log.qiwen:
        sg_tq_log.qiwen = request.REQUEST.get('qiwen')
        f = True
    if f:
        sg_tq_log.save()
    pk = request.REQUEST.get('id')
    if pk:
        sg_log = SGlog.objects.get(pk=pk)
        if sg_log.project_id != int(
                project_id) or sg_log.user_id != request.user.pk:
            return getResult(False, u'不是一个项目的日志', status_code=2)
    else:
        sg_log = SGlog()
        sg_tq_log.create_time = timezone.now()
        sg_tq_log.num += 1
        sg_tq_log.last_create_user = request.user
        sg_tq_log.save()
    sgtqlog = MyEncoder.default(sg_tq_log)
    sg_log.project_id = int(project_id)
    sg_log.sg_tq_log = sg_tq_log
    sg_log.text = request.REQUEST.get('text', '')
    sg_log.user = request.user
    sg_log.save()
    sgtqlog.update(MyEncoder.default(sg_log))

    #更新项目应用节点最新数据时间
    user_id = request.user.pk
    flag = "gong_cheng_ri_zhi"
    from util.cache_handle import query_project_filegroup_data_
    all_flag = query_project_filegroup_data_(project_id)

    # file_group_id = get_file_group_id_by_flag_from_cache(project_id=project_id, flag="gong_cheng_ri_zhi")
    file_group_id = all_flag['flags2'][flag]
    cache.set(
        RED_DOT_PROJECT_FILE_GROUP_LAST_NEW_DATA_TIMELINE %
        (project_id, file_group_id), sg_log.timeline, settings.CACHES_TIMEOUT)
    cache.set(RED_DOT_PROJECT_LAST_NEW_DATA_TIMELINE % project_id,
              sg_log.timeline, settings.CACHES_TIMEOUT)
    # cache.delete(RED_DOT_USER_LAST_READ_TIMELINE % (project_id, file_group_id, user_id))
    UserLastReadTimeline.update_last_read_timeline(project_id, file_group_id,
                                                   user_id)
    UserLastReadTimeline.update_last_read_timeline(project_id, 0, user_id)

    alias = get_alias_by_project_id_flag(project_id, flag, file_group_id)
    alias = list(set(alias))
    NeedPush.send_jpush(flag=flag,
                        project_id=project_id,
                        title=Project.get_project_name_by_id(project_id),
                        msg=all_flag['file_group'][file_group_id]['name'],
                        alias=alias,
                        file_group=all_flag['file_group'][file_group_id])
    cache.delete(
        USER_ACTIVITY %
        (user_id, project_id, sg_log.create_time.strftime('%Y-%m-%d')))
    return getResult(True,
                     u'保存日志成功',
                     sgtqlog,
                     jifen=create_data_jifen(request, CREATE_DATA))
Esempio n. 4
0
def add_shuihu_user():
    """
    初始化108将
    by:尚宗凯 at:2015-04-13
    去掉一行
    by:尚宗凯 at:2015-04-13
    修改水浒的项目id
    by:尚宗凯 at:2015-04-15
    增加水浒日志
    by:尚宗凯 at:2015-04-16
	修改气温
	by:尚宗凯 at:2015-04-16
	删除已有的100个日志
	by:尚宗凯 at:2015-04-16
	修改阿里云水浒文件路径
	by:尚宗凯 at:2015-04-16
	修改阿里云水浒文件路径
	by:尚宗凯 at:2015-04-16
	删除错误的天气log
	by:尚宗凯 at:2015-04-16
    """

    a = SGlog.objects.filter(project_id=SHOW_PROJECT_ID)
    a.delete()
    b = SGTQlog.objects.filter(project_id=SHOW_PROJECT_ID)
    b.delete()

    shuihu_project = Project.objects.get(pk=SHOW_PROJECT_ID)

    file_dir = u'/web/Need_Server/dev_files/108.txt'
    f = codecs.open(file_dir, 'r', "utf-8-sig")
    # f = open(file_dir,'r')

    person_dict = {}

    for line in f.readlines():
        # for line in f.readlines():
        data = line.strip().split('\t')
        tel = data[0]
        nickname = data[1]
        name = data[2]
        title = data[3]
        group = data[4]
        group_type = data[5]
        sex = data[6]

        u = create_user_and_person(tel, name, nickname, sex, shuihu_project,
                                   title, group, group_type)
        person_dict[name] = u
    log_file_path = '/web/Need_Server/dev_files/shuihu_sglog.txt'
    f = codecs.open(log_file_path, 'r', "utf-8-sig")
    for line in f.readlines():
        d = line.split(' ')
        s, created = SGTQlog.objects.get_or_create(
            project_id=SHOW_PROJECT_ID,
            file_group=FileGroup.objects.get(flag='gong_cheng_ri_zhi'),
            date=datetime.datetime.strptime(d[1], '%Y-%m-%d'),
            weather="晴朗",
            wind='3-4级',
            qiwen="10-20")
        sglog = SGlog()
        sglog.user = person_dict[d[0]]
        sglog.text = ' '.join(d[2:])
        sglog.project_id = SHOW_PROJECT_ID
        sglog.sg_tq_log = s
        s.last_create_user_id = person_dict[d[0]].pk
        s.num += 1
        s.save()
        sglog.save()
Esempio n. 5
0
def update_log_by_date(request, project_id=None):
    """
    更新或添加新的施工日志根据日期、天气
    by:王健 at:2015-1-6
    修改属性名
    by:王健 at:2015-1-8
    修改属性名,天气和风力
    by:王健 at:2015-1-12
    修改Model名字,去除下划线
    by:王健 at:2015-1-13
    天气表增加 timeline、num、create_time 字段
    by:王健 at:2015-1-20
    返回的数据,包括施工天气信息
    by:王健 at:2015-1-28
    增加积分
    by:王健 at:2015-2-5
    记录日志最后上传人
    by:王健 at:2015-2-10
    修改权限校验 函数
    by:王健 at:2015-3-4
    提交日志时刷新阅读时间
    by:尚宗凯 at:2015-05-06
    增加最新数据时间缓存
    by:尚宗凯 at:2015-05-20
    修复小红点bug
    by:尚宗凯 at:2015-05-27
    增加项目状态为 0 装饰器
    by:尚宗凯 at:2015-05-31
	变更极光推送方法
	by:尚宗凯 at:2015-05-31
	添加用户活跃度缓存
    by:尚宗凯 at:2015-06-04
    """
    if not request.REQUEST.get('text'):
        return getResult(False, u'日志内容不能为空', None)
    sg_tq_id = request.REQUEST.get('sg_tq_id', '')
    if not sg_tq_id:
        sg_tq_log, create = SGTQlog.objects.get_or_create(project_id=project_id, file_group=FileGroup.objects.get(flag='gong_cheng_ri_zhi'), date=timezone.now())

    else:
        sg_tq_log = SGTQlog.objects.get(pk=sg_tq_id)
    f = False
    if not sg_tq_log.weather:
        sg_tq_log.weather = request.REQUEST.get('weather', '')
        f = True
    if not sg_tq_log.wind:
        sg_tq_log.wind = request.REQUEST.get('wind')
        f = True
    if not sg_tq_log.qiwen:
        sg_tq_log.qiwen = request.REQUEST.get('qiwen')
        f = True
    if f:
        sg_tq_log.save()
    pk = request.REQUEST.get('id')
    if pk:
        sg_log = SGlog.objects.get(pk=pk)
        if sg_log.project_id != int(project_id) or sg_log.user_id != request.user.pk:
            return getResult(False, u'不是一个项目的日志', status_code=2)
    else:
        sg_log = SGlog()
        sg_tq_log.create_time = timezone.now()
        sg_tq_log.num += 1
        sg_tq_log.last_create_user = request.user
        sg_tq_log.save()
    sgtqlog = MyEncoder.default(sg_tq_log)
    sg_log.project_id = int(project_id)
    sg_log.sg_tq_log = sg_tq_log
    sg_log.text = request.REQUEST.get('text', '')
    sg_log.user = request.user
    sg_log.save()
    sgtqlog.update(MyEncoder.default(sg_log))

    #更新项目应用节点最新数据时间
    user_id = request.user.pk
    flag = "gong_cheng_ri_zhi"
    from util.cache_handle import query_project_filegroup_data_
    all_flag = query_project_filegroup_data_(project_id)

    # file_group_id = get_file_group_id_by_flag_from_cache(project_id=project_id, flag="gong_cheng_ri_zhi")
    file_group_id = all_flag['flags2'][flag]
    cache.set(RED_DOT_PROJECT_FILE_GROUP_LAST_NEW_DATA_TIMELINE % (project_id, file_group_id), sg_log.timeline, settings.CACHES_TIMEOUT)
    cache.set(RED_DOT_PROJECT_LAST_NEW_DATA_TIMELINE % project_id, sg_log.timeline, settings.CACHES_TIMEOUT)
    # cache.delete(RED_DOT_USER_LAST_READ_TIMELINE % (project_id, file_group_id, user_id))
    UserLastReadTimeline.update_last_read_timeline(project_id, file_group_id, user_id)
    UserLastReadTimeline.update_last_read_timeline(project_id, 0, user_id)

    alias = get_alias_by_project_id_flag(project_id, flag, file_group_id)
    alias = list(set(alias))
    NeedPush.send_jpush(flag=flag,
                        project_id=project_id,
                        title=Project.get_project_name_by_id(project_id),
                        msg=all_flag['file_group'][file_group_id]['name'],
                        alias=alias,
                        file_group=all_flag['file_group'][file_group_id]
    )
    cache.delete(USER_ACTIVITY % (user_id, project_id, sg_log.create_time.strftime('%Y-%m-%d')))
    return getResult(True, u'保存日志成功', sgtqlog, jifen=create_data_jifen(request, CREATE_DATA))