def create_non_usergroup_noti(args): #手动创建不在用户分群里的消息 start_time = int(time.time()) if 'data' in args and args['data'] and args['data'] !='' and 'project' in args and args['project'] !='': owner = args['owner'] if 'owner' in args else 'undefined' status = int(args['status']) if 'status' in args and args['status'] is not None else 9 if 'temple_id' in args and args['temple_id'] != '': result_temple = select_noti_temple(project=args['project'],temple_id=args['temple_id']) if 'result_temple' in dir(): medium_id = json.loads(result_temple[0][0][2])['meta']['medium_id'] elif 'medium_id' in args: medium_id = args['medium_id'] send_at = args['send_at'] if 'send_at' in args else int(time.time()) result_group = insert_noti_group(project=args['project'],plan_id=None,list_id=None,data_id=None,temple_id=args['temple_id'] if 'temple_id' in args else None,owner=owner,send_at=send_at,sent=0,total=len(args['data']),priority=13,status=status) inserted = 0 for noti in args['data']: if 'send_tracker' in noti and 'distinct_id' in noti['send_tracker'] and noti['send_tracker']['distinct_id'] != '': insert_result = insert_noti(project=args['project'],type_1=medium_id,created_at=int(time.time()),updated_at=int(time.time()),distinct_id=noti['send_tracker']['distinct_id'],content=noti,send_at=noti['send_at'] if 'send_at' in noti else send_at,plan_id=None,list_id=None,data_id=None,temple_id=result_temple[0][0][0],noti_group_id=result_group[2],priority=13,status=status,owner=owner,recall_result=None,key=noti['key'] if 'key' in noti else None,level=noti['level'] if 'level' in noti else None) inserted = inserted+insert_result[1] if 'temple_id' in args and args['temple_id'] != '': update_noti_temple(project=args['project'],temple_id=args['temple_id'],apply_times=1,lastest_apply_time=int(time.time()),lastest_apply_list = 0) update_noti_group(project=args['project'],noti_group_id=result_group[2]) return {'result':'success','inserted':inserted,'timecost':int(time.time())-start_time} else: return {'result':'failed','error':'no_distinct_id_or_miss_data'}
def create_noti_group(project, temple_id, user_group_id=None, data_id=None, owner='noti', send_at=None): #对分群应用模板,有data_id时,优先使用data_id result_temple = select_noti_temple(project=project, temple_id=temple_id) if not user_group_id and not data_id: return 'no_group' else: if user_group_id and not data_id: result_data = select_usergroup_data(project=project, group_list_id=user_group_id) elif data_id: result_data = select_usergroupdata_data(project=project, data_id=data_id) timenow = int(time.time()) result_group = insert_noti_group( project=project, plan_id=result_data[0][0][0], list_id=result_data[0][0][1], data_id=result_data[0][0][2], temple_id=result_temple[0][0][0], owner=owner, send_at=send_at if send_at else timenow, sent=0, total=result_data[1], priority=13, status=result_data[0][0][6]) for noti in result_data[0]: timenow = int(time.time()) temple_content = apply_temple( project=project, temple_args=json.loads(result_temple[0][0][2]), temple_content=json.loads(result_temple[0][0][3]), data_json=json.loads(noti[5]), data_key=noti[4], group_id=user_group_id, owner=owner, send_at=send_at if send_at else timenow) insert_result = insert_noti( project=project, type_1=json.loads(result_temple[0][0][2])['meta']['medium_id'], created_at=timenow, updated_at=timenow, distinct_id=noti[4], content=temple_content, send_at=send_at if send_at else timenow, plan_id=noti[0], list_id=noti[1], data_id=noti[2], temple_id=result_temple[0][0][0], noti_group_id=result_group[2], priority=13, status=noti[6], owner=owner, recall_result=None, key=temple_content['key'] if 'key' in temple_content else None, level=temple_content['level'] if 'level' in temple_content else None) update_noti_temple( project=project, temple_id=temple_id, apply_times=1, lastest_apply_time=timenow, lastest_apply_list=user_group_id if user_group_id else 0) update_noti_group(project=project, noti_group_id=result_group[2]) update_usergroup_list(project=project, list_id=result_data[0][0][1], apply_temple_times=1) update_usergroup_plan(project=project, plan_id=result_data[0][0][0], latest_apply_temple_id=temple_id, latest_apply_temple_time=timenow) return 'success'