def get_trainfo(self, pk): """ 获取培训相关信息 :param pk: :return: """ matter = Matter.objects.get(pk=pk) instructors_id = matter.training_instructors if instructors_id == None: training_instructors = None else: training_instructors = instructors_id.last_name train_method = dict(TRAINING_METTART_METHOD).get(matter.training_method) start_time = matter.start_time if start_time is not None: start_time = date_to_str(start_time, format='%Y-%m-%d %H:%M:%S') end_time = matter.end_time if end_time is not None: end_time = date_to_str(end_time, format='%Y-%m-%d %H:%M:%S') training_contact = matter.training_contact training_model = matter.training_model if training_model != None: training_model = eval(training_model) data_dict = {"training_instructors": training_instructors, "training_method": train_method, "training_contact": training_contact, "start_time": start_time, "end_time": end_time, "training_model": training_model} return data_dict
def get_remark(self, request, pk=None, *args, **kwargs): mark_list = [] mark = RemarkEvolve.objects.filter(correlation_id=pk, mark_type=2).order_by('-operationtime') for m in mark: user = m.user.last_name operationtime = m.operationtime content = m.content mark_list.append({"user": user, "time": date_to_str(operationtime, format='%Y-%m-%d %H:%M:%S'), "content": content}) mark_sort = sorted(mark_list, key=operator.itemgetter('time'), reverse=True) # 获取改动记录 query_params = {"operationmodule": "培训管理", "action": 3, "title": pk} train_log = OperateLog.objects.filter(**query_params) # 查询基础日志列表 base_list = [] for train in train_log: user = train.user.last_name time = date_to_str(train.operationtime, format='%Y-%m-%d %H:%M:%S') log_id = train.id query_detail = DetailLog.objects.filter(log_id_id=log_id) for v in query_detail: name = v.name old_value = v.old_value new_value = v.new_value base_list.append({"user": user, "time": time, "modify_list": {"name": name, "old_value": old_value, "new_value": new_value}}) base_sort = sorted(base_list, key=operator.itemgetter('time'), reverse=True) remark = request.user.has_perm("add_remark") if remark is True or request.user.is_superuser is True: button = ["备注"] else: button = [] return Response({"mark": mark_sort, "log": base_sort, "button_list": button}, status=status.HTTP_200_OK)
def handle(self, *args, **options): # 清理前一天的图片和日志 now = datetime_now() if now.hour != 1: return yesterday = datetime_delta(now, days=-1) path = "%s/data/image/%s*" % (PROJECT_HOME, date_to_str(yesterday.date())) shell_command = "rm -rf %s" % path os.system(shell_command) log_path = "%s/data/logs/%s*" % (PROJECT_HOME, date_to_str(yesterday.date()).replace('-', "")) shell_command = "rm -rf %s" % log_path os.system(shell_command)
def get_history_data(self, start_date, end_date): for d in dates_during(start_date, end_date): dates = date_to_str(d) fetcher = ChannelFetcherHaiEr(dates) # 获取今天源数据 history_data = fetcher.get_data() # 解析数据 result = self.parse_data(history_data) # 插入数据 try: with transaction.atomic(): for each in result: s = RefactoringConsultingAndVisitors.objects.update_or_create( date=dates, company_id=each['siteid'], valid_consulting=each.get('valid_consulting', 0), invalid_consulting=each.get( 'invalid_consulting', 0), valid_visitors=0, invalid_visitors=0, channel=each['channel'], grid=each['grid'], industry=each['industry'], deploy=each['deploy'], unique_vistor=each.get('uv', 0)) except Exception as e: logging.info('数据回滚了:' + str(e)) return '数据回滚了:' + str(e)
def handle_channel_data(self, channel_list, channel_total, start_date, end_date): data_dict = {} for each in channel_total: inquires_num = each.get('inquires_num') channel = each.get('channel') date = date_to_str(each.get('date')) if data_dict.get(channel): data_dict[channel].update({date: inquires_num}) else: data_dict[channel] = {date: inquires_num} # 缺省数据补充默认值 data_dict = self.default_data(data_dict, start_date, end_date) # 把数据按时间排序,给前端 big_list = [] for channel, item in data_dict.items(): name = channel_list[channel] new_list = sorted(item.keys()) big_list.append({ 'name': name, 'data': [item[i] for i in new_list] }) return big_list
def get_change_record(self, operationmodule, action, correlation_id): """ 获取改动记录 :param operationmodule: :param action: :param correlation_id: :return: """ # 获取改动记录 query_params = {"operationmodule": operationmodule, "action": action, "title": correlation_id} train_log = OperateLog.objects.filter(**query_params) # 查询基础日志列表 base_list = [] for train in train_log: user = train.user.last_name time = date_to_str(train.operationtime, format='%Y-%m-%d %H:%M:%S') log_id = train.id query_detail = DetailLog.objects.filter(log_id_id=log_id) for v in query_detail: name = v.name old_value = v.old_value new_value = v.new_value base_list.append({"user": user, "time": time, "modify_list": {"name": name, "old_value": old_value, "new_value": new_value}}) base_sort = sorted(base_list, key=operator.itemgetter('time'), reverse=True) return base_sort
class VersionProduct(TimeStampModel): """版本产品""" version_id = models.ForeignKey(VersionRepository, related_name='version_product', null=True, help_text='版本号') # 发版时间 release_date = models.DateField() # 产品名称 product_name = models.CharField(max_length=50) # 产品版本 product_version = models.CharField(max_length=50, default='') # 版本说明 product_explain = models.TextField() # 产品分类 product_classify = models.SmallIntegerField(choices=PROD_SERV_VERSIONS, null=False, help_text="产品类别") # 是否发版 release_status = models.BooleanField(default=False, choices=RELEASE_STATUS_TYPES) # 发版次数 release_number = models.CharField(max_length=5, default='') product_time = date_to_str(datetime.datetime.now(), format='%Y-%m-%d %H:%M:%S') # 版本进度 schedule = models.TextField(default='[{"name": "项目立项","time": "%s","mileage": "1","index": 1},{"name": "产品设计","time": "","mileage": "0","index": 2},{"name": "研发","time": "","mileage": "","index": 3},{"name": "测试","time": "","mileage": "","index": 4},{"name": "产品验收","time": "","mileage": "","index": 5},{"name": "部署","time": "","mileage": "","index": 6},{"name": "发版","time": "","mileage": "","index": 7},{"button_log": {"old": "无","new": "无"},"index": 8}]' % product_time) class Meta: permissions = ( ("view_versionproduct", "Can see available versionproduct"), ) verbose_name = verbose_name_plural = "版本产品"
def derive_site(self, request): start_date = request.GET.get('start_date') end_date = request.GET.get('end_date') deploy = request.GET.get('deploy') industry = request.GET.get('industry') action_dict = dict(OPERATE_ACTION_CHOICES) # 去除续费客户 action_dict.pop(3) name = 'siteData' title_row = ['时间', '部署方式', '行业'] + list(action_dict.values()) title_key = ['date', 'deploy', 'industry'] + list(action_dict.values()) title = dict(zip(title_key, title_row)) content_list = [] params = {} if start_date: params["date__gte"] = str_to_date(start_date) if end_date: params["date__lte"] = str_to_date(end_date) if industry: params['industry'] = industry if deploy: params['deploy_way'] = deploy site_data = OperatingRecord.objects.all().filter(**params).values( 'date', 'action', 'num') if not site_data: content_list.append( dict(zip(title_key, [i - i for i in range(len(title_key))]))) re_dict = {} for item in site_data: key = date_to_str(item.get('date')) if re_dict.get(key): re_dict[key].append(item) else: re_dict[key] = [item] for date_key, each in re_dict.items(): write_list = {'date': date_key, 'industry': '全部', 'deploy': '全部'} if industry: write_list['industry'] = industry if deploy: write_list['deploy'] = deploy_dict.get(int(deploy)) write_list.update( dict( zip(action_dict.values(), [zero - zero for zero in range(len(action_dict))]))) for i in each: action = action_dict.get(i.get('action')) write_list[action] = i.get('num') content_list.append(write_list) excl = Excel_export(filename=name, title=title, content=content_list) response = excl.export_csv() return response
def default_data(self, data_dict, start_date, end_date): date_list = self.handle_get_date(start_date, end_date) # 进行 缺省数据补0 操作 for items in data_dict.values(): for date in date_list: date = date_to_str(date) if date not in list(items.keys()): items.update({date: 0}) return data_dict
def date_change(self, pk, log_id, new_start, new_end): """ 开始时间/结束时间变更记录 :param pk: :param log_id: :param new_start: :param new_end: :return: """ try: aa = str_to_date(new_start) except: pass matter = Matter.objects.get(pk=pk) old_start = matter.start_time if old_start is not None: old_start = date_to_str(old_start, format='%Y-%m-%d %H:%M:%S') if old_start != new_start: dict1 = { "word": "start_time", "name": "开始时间", "old_value": old_start, "new_value": new_start, "log_id": log_id } DetailLog.objects.create(**dict1) old_end = matter.end_time if old_end is not None: old_end = date_to_str(old_end, format='%Y-%m-%d %H:%M:%S') # 如果结束时间不为空 if old_end != new_end: dict2 = { "word": "end_time", "name": "结束时间", "old_value": old_end, "new_value": new_end, "log_id": log_id } DetailLog.objects.create(**dict2) return 'ok'
def list(self, request, *args, **kwargs): """ 产品配置列表 :param request: :return: """ matter = MatterFlowViewsets() khk_id = request.GET.get('khk_id') page = request.GET.get('page', 1) page = int(page) data_list = [] # 获取产品配置相关的信息 base_query = ProductConfig.objects.\ values('id', 'workorder_theme', 'subordinatemodule', 'func_name', 'func_value', 'product_stautus', 'created_at', 'open_id').order_by('-id') if khk_id: base_query = ProductConfig.objects.filter(khk_id=khk_id). \ values('id', 'workorder_theme', 'subordinatemodule', 'func_name', 'func_value', 'product_stautus', 'created_at', 'open_id').order_by('-id') total_count = base_query.count() total_page, total_count, start, end = matter.page_set( total_count, page) for query in base_query[start:end]: open_id = query["open_id"] station_info = StationInfo.objects.filter(open_station=open_id) if len(station_info) > 0: station_info = station_info.values('deploy_way', 'grid')[0] station_info["deploy_way"] = dict(DEPLOY_WAYS).get( station_info["deploy_way"]) station_info["grid"] = Grid.objects.get( pk=station_info["grid"]).grid_name else: station_info = dict() station_info["deploy_way"] = "无" station_info["grid"] = "无" query["product_stautus"] = dict(PRODUCT_STATUS).get( query["product_stautus"]) query.update(station_info) query["created_at"] = date_to_str(query["created_at"], format='%Y-%m-%d %H:%M:%S') data_list.append(query) page_dict = {"total_count": total_count, "total_page": total_page} return Response(data={ "page_num": page_dict, "result": data_list }, status=status.HTTP_200_OK)
def list(self, request, *args, **kwargs): queryset, version_id = self.filter_queryset(self.get_queryset()) serializer = self.get_serializer(queryset, many=True) data = serializer.data for da in data: da["schedule"] = eval(da["schedule"]) """ 如果version_id不为空,返回version_id """ if version_id != '': # 获取改动记录 query_params = { "operationmodule": "版本流程", "action": 3, "title": version_id } version_log = OperateLog.objects.filter(**query_params) # 查询基础日志列表 base_list = [] for version in version_log: user = version.user.last_name time = date_to_str(version.operationtime, format='%Y-%m-%d %H:%M:%S') log_id = version.id query_detail = DetailLog.objects.filter(log_id_id=log_id) for v in query_detail: name = v.name type = v.word old_value = v.old_value new_value = v.new_value base_list.append({ "user": user, "time": time, "modify_list": { "name": name, "type": type, "old_value": old_value, "new_value": new_value } }) base_sort = sorted(base_list, key=operator.itemgetter('time'), reverse=True) else: base_sort = [] result = {"version_info": data, "log": base_sort} return Response(result)
def get_martkdef(self, mark_type, correlation_id): """ 查看该关联对象的备注 :param mark_type: :param correlation_id: :return: """ mark_list = [] mark = RemarkEvolve.objects.filter(correlation_id=correlation_id, mark_type=mark_type).order_by('-operationtime') for m in mark: user = m.user.last_name operationtime = m.operationtime content = m.content mark_list.append( {"user": user, "time": date_to_str(operationtime, format='%Y-%m-%d %H:%M:%S'), "content": content}) mark_sort = sorted(mark_list, key=operator.itemgetter('time'), reverse=True) return mark_sort
def fetch_inquires(): """celery任务:经典版更新咨询量""" logger.info("start fetch inquires data") manager = InquiresFetcherManager() manager.update_inquires() today = date_to_str(date.today()) re_data = { "request_path": "", "request_method": "SCRIPT", "request_body": { "start_date": today, "end_date": today } } op_log = OperateLog.objects.all().create(operationmodule=MODULES_MAP.get( "applications.data_manage.views_script.get_consult"), action=110, operation=re_data) op_log.save() logger.info("fetch inquires data complete")
def fetch_channel_haier(): """celery任务:更新重构站点渠道咨询量访客量--海尔版/重构新版""" logger.info("start fetch channel data") info = UpdateChannelDataHaiEr() info.start() today = date_to_str(date.today()) re_data = { "request_path": "", "request_method": "SCRIPT", "request_body": { "start_date": today, "end_date": today } } op_log = OperateLog.objects.all().create(operationmodule=MODULES_MAP.get( "applications.data_manage.views_script.test_history_channel"), action=110, operation=re_data) op_log.save() logger.info("fetch channel end")
def fetch_vistors_yesterday(): """celery任务:经典版更新访客量""" logger.info("start fetch vistors_y data") manager = ReportManager() manager.update_yesterday() yes_day = date_to_str(date.today() + datetime.timedelta(days=-1)) re_data = { "request_path": "", "request_method": "SCRIPT", "request_body": { "start_date": yes_day, "end_date": yes_day } } op_log = OperateLog.objects.all().create(operationmodule=MODULES_MAP.get( "applications.data_manage.views_script.get_visitor"), action=110, operation=re_data) op_log.save() logger.info("fetch vistors_y data complete")
def fetch_vistors(): """celery任务:经典版更新访客量""" logger.info("start fetch vistors data") manager = ReportManager() today = date.today() # today = str_to_date('2018-08-24') manager.create_update(today) today = date_to_str(date.today()) re_data = { "request_path": "", "request_method": "SCRIPT", "request_body": { "start_date": today, "end_date": today } } op_log = OperateLog.objects.all().create(operationmodule=MODULES_MAP.get( "applications.data_manage.views_script.get_visitor"), action=110, operation=re_data) op_log.save() logger.info("fetch vistors data complete")
def handle_industry(self, data, start_date, end_date): data_dict = {} for each in data: inquires_num = each[1] industry = each[0] date = date_to_str(each[2]) if data_dict.get(industry): data_dict[industry].update({date: inquires_num}) else: data_dict[industry] = {date: inquires_num} # 缺省数据补充默认值 data_dict = self.default_data(data_dict, start_date, end_date) # 把数据按时间排序,给前端 big_list = [] for industry, item in data_dict.items(): new_list = sorted(item.keys()) big_list.append({ 'name': industry, 'data': [item[i] for i in new_list] }) return big_list
def retrieve(self, request, *args, **kwargs): """ 详情接口 :param request: :param args: :param kwargs: :return: """ # instance = self.get_object() # serializer = self.get_serializer(instance) pk = kwargs["pk"] config_tuple = ('id', 'children_station', 'workorder_theme', 'subordinatemodule', 'func_name', 'func_value', 'allocation_people', 'dealing_person', 'product_stautus', 'khk_id', 'allocate_time', 'actual_start_time', 'actual_completion_time', 'created_at', 'updated_at', 'open_id', 'describe') # 获取产品配置基础详情信息 config_dict = ProductConfig.objects.filter(pk=pk).values( *config_tuple)[0] # 获取该客户库的公司站点信息 matter = MatterFlowViewsets() # 公司id khk_id = config_dict["khk_id"] company_station = matter.get_comstaion(khk_id) # 将公司站点信息添加到产品配置的详情中 config_dict.update(company_station) # 附件 atta_exits = Attachment.objects.filter( atta_type=2, correlation_id=kwargs["pk"]).exists() atta_list = None if atta_exits: atta_list = Attachment.objects.filter( atta_type=2, correlation_id=kwargs["pk"]).values('id', 'enclosure') config_dict["matter_ofatta"] = atta_list """ 字段信息整理 """ # 处理人 if config_dict["dealing_person"] != None: config_dict["dealing_person"] = User.objects.get( pk=config_dict["dealing_person"]).last_name # 产品配置 config_dict["product_stautus"] = dict(PRODUCT_STATUS)[ config_dict["product_stautus"]] """ 时间格式化 """ # 创建时间 config_dict["created_at"] = date_to_str(config_dict["created_at"], format='%Y-%m-%d %H:%M:%S') # 更新时间 config_dict["updated_at"] = date_to_str(config_dict["updated_at"], format='%Y-%m-%d %H:%M:%S') # 分配时间 if config_dict["allocate_time"] != None: config_dict["allocate_time"] = date_to_str( config_dict["allocate_time"], format='%Y-%m-%d %H:%M:%S') # 实际开始时间 if config_dict["actual_start_time"] != None: config_dict["actual_start_time"] = date_to_str( config_dict["actual_start_time"], format='%Y-%m-%d %H:%M:%S') # 实际完成时间 if config_dict["actual_completion_time"] != None: config_dict["actual_completion_time"] = date_to_str( config_dict["actual_completion_time"], format='%Y-%m-%d %H:%M:%S') """ 增加数据库没有的数据 """ children_station = config_dict.get("children_station") children_id = None # 子站存在 if children_station != '': children_id = OpenStationManage.objects.filter( open_station__company_id=children_station).first().id # 如果有its_parent 该站点为子站,否则为父站 config_dict["children_id"] = children_id config_dict["matter_type"] = "产品配置" """ 产品配置按钮 """ button_list = SimpleProductConfigurationSet.product_button(pk) config_dict["button_list"] = button_list """ 驳回次数 """ reject_count = Reject.objects.filter(correlation_id=pk, reject_type=2).count() config_dict["reject_count"] = reject_count # 需求方不通过原因次数 config_dict["demand_count"] = Reject.objects.filter( correlation_id=pk, reject_type=4).count() # 操作方不通过原因次数 config_dict["operation_count"] = Reject.objects.filter( correlation_id=pk, reject_type=3).count() return Response(config_dict, status=status.HTTP_200_OK)
def put_schedule(self, request, pk=None, *args, **kwargs): """ 修改产品版本进度 :param request: :param pk:产品版本id :param args: :param kwargs: :return: """ """ [{"name": "项目立项","time": "%s","mileage": "1","index": 1, "course": ""}, {"name": "产品设计","time": "","mileage": "0","index": 2,"course": ""}, {"name": "研发","time": "","mileage": "","index": 3,"course": ""}, {"name": "测试","time": "","mileage": "","index": 4,}, {"name": "产品验收","time": "","mileage": "","index": 5}, {"name": "部署","time": "","mileage": "","index": 6}, {"name": "发版","time": "","mileage": "","index": 7}, {"button_log": {"old": "无","new": "无"},"index": 8}] 0:初始 1:完成 2: 驳回 3: 被驳回 4: 冒烟 """ data = request.data step = data.get("step") button = data.get("button") versionproduct = VersionProduct.objects.get(pk=pk) # 产品名称 product_name = versionproduct.product_name version_id = versionproduct.version_id.id # 获取该产品的当前版本进度 sche = eval(versionproduct.schedule) sche = sorted(sche, key=operator.itemgetter('index'), reverse=False) # 获取当前时间 pro_time = date_to_str(datetime.datetime.now(), format='%Y-%m-%d %H:%M:%S') if step == '产品设计': if button == "评审通过": sche[1]["mileage"] = '1' sche[1]["time"] = pro_time sche[2]["mileage"] = '0' elif step == '研发': if button == "提测": sche[2]["mileage"] = '1' sche[2]["time"] = pro_time sche[3]["mileage"] = '0' elif step == '测试': if button == "驳回": sche[3]["mileage"] = '2' sche[3]["time"] = pro_time sche[2]["mileage"] = '3' elif button == "冒烟通过": sche[3]["mileage"] = '4' sche[3]["time"] = pro_time elif button == "通过": sche[3]["mileage"] = '1' sche[3]["time"] = pro_time sche[4]["mileage"] = '0' elif step == '产品验收': if button == "驳回": sche[4]["mileage"] = '2' sche[4]["time"] = pro_time sche[3]["mileage"] = '3' elif button == "通过": sche[4]["mileage"] = '1' sche[4]["time"] = pro_time sche[5]["mileage"] = '0' elif step == '部署': if button == "确认": sche[5]["mileage"] = '1' sche[5]["time"] = pro_time sche[6]["mileage"] = '0' elif step == '发版': if button == "发版": sche[6]["mileage"] = '1' sche[6]["time"] = pro_time versionproduct.release_status = True sche[-1]["button_log"]["old"] = sche[-1]["button_log"]["new"] sche[-1]["button_log"]["new"] = button versionproduct.schedule = sche versionproduct.save() # 记录版本变更 VersionLog.change_status(request, sche, step, product_name, version_id) return Response({"info": "状态变更成功"}, status=status.HTTP_200_OK)
def derive_industry(self, request): start_date = request.GET.get('start_date') end_date = request.GET.get('end_date') deploy = request.GET.get('deploy') industry = request.GET.get('industry') version = request.GET.get('version', 0) name = 'siteData' title_row = ['时间', '部署方式', '行业', '咨询量', '访客量'] title_key = ['date', 'deploy', 'industry', 'pv', 'uv'] title = dict(zip(title_key, title_row)) content_list = [] params = {} if start_date: params["date__gte"] = str_to_date(start_date) if end_date: params["date__lte"] = str_to_date(end_date) if industry: params['industry'] = industry if int(version) == 1: if deploy: params['deploy'] = deploy re_data = RefactoringConsultingAndVisitors.objects.all().filter(**params)\ .values('date')\ .annotate(pv=Sum('valid_consulting'), in_pv=Sum('invalid_consulting'), uv=Sum('unique_vistor'))\ .values('date', 'pv', 'uv', 'in_pv') if not re_data: content_list.append( dict(zip(title_key, [i - i for i in range(len(title_key))]))) re_dict = {} for item in re_data: key = date_to_str(item.get('date')) if re_dict.get(key): re_dict[key].append(item) else: re_dict[key] = [item] for date_key, each in re_dict.items(): write_list = { 'date': date_key, 'industry': '全部', 'deploy': '全部', 'pv': 0, 'uv': 0 } if industry: write_list['industry'] = industry if deploy: write_list['deploy'] = deploy_dict.get(int(deploy)) for i in each: pv = int(i.get('pv')) + int(i.get('in_pv')) write_list['uv'] = int(i.get('uv')) write_list['pv'] = pv content_list.append(write_list) else: if deploy: params['deploy_way'] = deploy pv_data = InquiriesData.objects.all().filter(**params).values('date')\ .annotate(pv=Sum('inquires_num')).values('date', 'pv') uv_data = VistorData.objects.all().filter(**params).values('date')\ .annotate(uv=Sum('visitor_num')).values('date', 'uv') if not (uv_data and pv_data): content_list.append( dict(zip(title_key, [i - i for i in range(len(title_key))]))) long = pv_data short = uv_data if len(uv_data) >= len(pv_data): long = uv_data short = pv_data for item in long: date_value = date_to_str(item['date']) for each in short: if item['date'] == each['date']: v_value = item.get('uv') if item.get( 'uv') else each.get('uv') c_value = item.get('pv') if item.get( 'pv') else each.get('pv') write_list = { 'date': date_value, 'industry': '全部', 'deploy': '全部', 'pv': 0, 'uv': 0 } if industry: write_list['industry'] = industry if deploy: write_list['deploy'] = deploy_dict.get(int(deploy)) write_list['uv'] = v_value write_list['pv'] = c_value content_list.append(write_list) excl = Excel_export(filename=name, title=title, content=content_list) response = excl.export_csv() return response
def retrieve(self, request, *args, **kwargs): """ 问题详情 :param request: :param args: :param kwargs: :return: """ instance = self.get_object() serializer = self.get_serializer(instance) data = serializer.data simp = SimpleMatterViewsets() # 获取 button_list = simp.notice_button(request, data) # 添加公司&站点信息 company_pk = data["company_matter"] dic_comstaion = self.get_comstaion(company_pk) data.update(dic_comstaion) data.update({"button_list": button_list}) # 文题状态 data["matter_status"] = dict(MATTER_STATUS)[data["matter_status"]] # 问题类型 data["matter_type"] = dict(MATTER_TYPE)[data["matter_type"]] # 培训方式 data["training_method"] = dict(TRAINING_METTART_METHOD)[data["training_method"]] data["final_training_method"] = dict(TRAINING_METTART_METHOD).get(data["final_training_method"]) # 满意度等级 data["satisfaction_level"] = dict(SATISFACTION_SURVEY).get(data["satisfaction_level"]) # 沟通方式 communication_way = instance.communication_way if communication_way != None: data["communication_way"] = eval(communication_way) else: data["communication_way"] = [] # 上线模块 online_module = instance.online_module if online_module != None: data["online_module"] = eval(online_module) else: data["online_module"] = [] # 培训模块 training_model = instance.training_model if training_model != None: data["training_model"] = eval(training_model) else: data["training_model"] = [] # 培训讲师 training_instructors = instance.training_instructors if training_instructors != None: training_instructors = training_instructors.last_name data["training_instructors"] = training_instructors # 经办人 responsible = instance.responsible.last_name data["responsible"] = responsible # 问题处理人 dealing_person = instance.dealing_person if dealing_person != None: dealing_person = dealing_person.last_name data["dealing_person"] = dealing_person # 是否有遗留问题 legacy_issue = instance.legacy_issue if legacy_issue != None: legacy_issue = dict(Y_NLEGACY).get(data["legacy_issue"]) data["legacy_issue"] = legacy_issue # 调查人员 investigador = instance.investigador if investigador != None: investigador = investigador.last_name data["investigador"] = investigador # 调查开始时间 invest_start = instance.invest_start if invest_start != None: invest_start = date_to_str(invest_start, format='%Y-%m-%d %H:%M:%S') data["invest_start"] = invest_start # 调查结束时间 invest_end = instance.invest_end if invest_end != None: invest_end = date_to_str(invest_end, format='%Y-%m-%d %H:%M:%S') data["invest_end"] = invest_end # 附件 atta_exits = Attachment.objects.filter(atta_type=1, correlation_id=kwargs["pk"]).exists() atta_list = None if atta_exits: atta_list = Attachment.objects.filter(atta_type=1, correlation_id=kwargs["pk"]).values('id', 'enclosure') data.update({"matter_ofatta": atta_list}) # 添加驳回原因 dismiss_exits = Reject.objects.filter(correlation_id=kwargs["pk"], reject_type=1).exists() if dismiss_exits: dismiss_reason = Reject.objects.filter(correlation_id=kwargs["pk"], reject_type=1).order_by("updated_at").first().dismiss_reason dismiss_count = Reject.objects.filter(correlation_id=kwargs["pk"], reject_type=1).count() else: dismiss_reason = None dismiss_count = 0 data.update({"dismiss_reason": dismiss_reason, "dismiss_count": dismiss_count}) return Response(data)
def derive_channel(self, request): channel = request.GET.get('channel') start_date = request.GET.get('start_date') end_date = request.GET.get('end_date') deploy = request.GET.get('deploy') industry = request.GET.get('industry') version = request.GET.get('version', 0) deploy_dict = dict(DEPLOY_WAYS) re_channel = dict(REFACTORING_CHANNEL_CHOICES) channel_dict = dict(CHANNEL_CHOICES) name = 'enterpriseData' if channel: name = channel if not name: name = 'unknownSite' title = {} content_list = [] params = {} if start_date: params["date__gte"] = str_to_date(start_date) if end_date: params["date__lte"] = str_to_date(end_date) if industry: params['industry'] = industry if channel: params['channel'] = channel # 只要选择了行业或者部署方式就直接用 没有选择就显示全部 if int(version) == 1: title_row = ['时间', '部署方式', '行业'] + list(re_channel.values()) title_key = ['date', 'deploy', 'industry'] + list( re_channel.values()) title = dict(zip(title_key, title_row)) if deploy: params['deploy'] = deploy re_data = RefactoringConsultingAndVisitors.objects.all().filter(**params).values('date', 'channel')\ .annotate(con=Sum('valid_consulting'), in_con=Sum('invalid_consulting'))\ .values('date', 'channel', 'con', 'in_con') if not re_data: content_list.append( dict(zip(title_key, [i - i for i in range(len(title_key))]))) re_dict = {} for item in re_data: key = date_to_str(item['date']) if re_dict.get(key): re_dict[key].append(item) else: re_dict[key] = [item] for date_key, each in re_dict.items(): write_list = { 'date': date_key, 'industry': '全部', 'deploy': '全部' } if industry: write_list['industry'] = industry if deploy: write_list['deploy'] = deploy_dict.get(int(deploy)) write_list.update( dict( zip(re_channel.values(), [zero - zero for zero in range(len(re_channel))]))) for i in each: channel = re_channel.get(i.get('channel')) value = int(i.get('con')) + int(i.get('in_con')) write_list[channel] = value content_list.append(write_list) else: title_row = ['时间', '部署方式', '行业'] + list(channel_dict.values()) title_key = ['date', 'deploy', 'industry'] + list( channel_dict.values()) title = dict(zip(title_key, title_row)) if deploy: params['deploy_way'] = deploy con_data = InquiriesData.objects.all().filter(**params).values('date', 'channel')\ .annotate(num=Sum('inquires_num'))\ .values('date', 'channel', 'num') if not con_data: content_list.append( dict(zip(title_key, [i - i for i in range(len(title_key))]))) re_dict = {} for item in con_data: key = date_to_str(item['date']) if re_dict.get(key): re_dict[key].append(item) else: re_dict[key] = [item] for date_key, each in re_dict.items(): write_list = { 'date': date_key, 'industry': '全部', 'deploy': '全部' } if industry: write_list['industry'] = industry if deploy: write_list['deploy'] = deploy_dict.get(int(deploy)) write_list.update( dict( zip(channel_dict.values(), [zero - zero for zero in range(len(channel_dict))]))) for i in each: channel = channel_dict.get(i.get('channel')) value = i.get('num') write_list[channel] = value content_list.append(write_list) excl = Excel_export(filename=name, title=title, content=content_list) response = excl.export_csv() return response
def __init__(self): self.today = date_to_str(date.today()) self.yesterday = date_to_str(datetime_delta(date.today(), days=-1))
def __str__(self): str_date = date_to_str(self.date) return f"{self.product_id}-{str_date}"
def __str__(self): return date_to_str(self.date)
def __str__(self): str_date = date_to_str(self.date) return f"{self.company_id}-{str_date}"
def __init__(self, start_time): self.start_time = str(start_time) + ' 00:00:00' self.end_time = date_to_str( datetime_delta(str_to_date(start_time), days=1)) + ' 00:00:00' self.grid_data = self.get_grid()