async def get_sales_volume(ns={}): orgid = ns.get('orgid') if ns.get('orgid') else 'mIWUHBeeDM8mwAFPIQ8pS' db = DBPools() async with db.sqlorContext('kboss') as sor: count_sql = f""" SELECT month_list.month, COALESCE(SUM(b.amount), 0) AS total_sales FROM (SELECT DATE_FORMAT(date_add(@start_date, INTERVAL t.i MONTH), '%%Y-%%m') AS month FROM (SELECT @start_date := '2024-03-01') AS vars JOIN (SELECT @row := @row + 1 AS i FROM (SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9 UNION SELECT 10 UNION SELECT 11 UNION SELECT 12) a, (SELECT @row := -1) b ) t WHERE DATE_FORMAT(date_add(@start_date, INTERVAL t.i MONTH), '%%Y-%%m') <= DATE_FORMAT(NOW(), '%%Y-%%m') ) month_list LEFT JOIN (SELECT o.id AS orgid, bc.* FROM bill bc JOIN organization o ON bc.customerid = o.id WHERE bc.business_op = 'BUY' AND o.parentid = '{orgid}') b ON DATE_FORMAT(b.bill_date, '%%Y-%%m') = month_list.month AND b.business_op = 'BUY' GROUP BY month_list.month ORDER BY month_list.month LIMIT 20;""" count_li = await sor.sqlExe(count_sql, {}) # for index, sale in enumerate(count_li): # sale['total_sales'] = round(sale['total_sales'] + 4 * 1000000 + (index + 1) * 10024, 2) return { 'status': True, 'msg': '获取销售额记录成功', 'data': count_li } async def large_screen_third_page(ns={}): orgid = ns.get('orgid') if ns.get('orgid') else 'mIWUHBeeDM8mwAFPIQ8pS' n = 9 # 获取当前时间戳 now = time.time() # 获取当前年月 current_time = time.localtime(now) current_year = current_time.tm_year current_month = current_time.tm_mon x = [] y = [] for i in range(0, n + 1): # 计算之前的月份 month = current_month - i year = current_year if month <= 0: # 处理年份的变更 year -= (abs(month) // 12) + 1 if month % 12 == 0: month = 12 else: month = (month % 12) x.append(f"{year}-{month:02d}") y.append(int(f"{year}{month}") * 16 + 78390) # 获取销售额 get_sales_volume_res = await get_sales_volume({'orgid': orgid}) get_sales_volume_month = [] get_sales_volume_value = [] for i in get_sales_volume_res['data']: get_sales_volume_month.append(i['month']) get_sales_volume_value.append(i['total_sales']) if ns.get('flag') == '1': LeftUp = { 'configname': '销售额', 'x': get_sales_volume_month, 'y': get_sales_volume_value } else: LeftUp = { 'configname': '销售额', 'x': x[::-1], 'y': [1502350, 1701232, 1602326, 1902310, 1802294, 2202278, 2262262, 2302246, 3115382, 3315366, 3631550] } # 统计用户量 user_count_sql = f""" SELECT DATE_FORMAT(create_at, '%%Y-%%m') AS month, COUNT(*) AS new_users_count FROM organization WHERE parentid = '{orgid}' GROUP BY month ORDER BY month ASC; """ user_count_time_li = [] user_count_li = [] db = DBPools() async with db.sqlorContext('kboss') as sor: user_count = await sor.sqlExe(user_count_sql, {}) for i in user_count: user_count_time_li.append(i['month']) user_count_li.append(i['new_users_count']) if ns.get('flag') == 1: RightDown = { 'configname': '用户量', 'x': user_count_time_li[-10:], 'y': user_count_li[-10:] } else: RightDown = { 'configname': '用户量', 'x': x[::-1], 'y': [502, 701, 602, 702, 1002, 3102, 1602, 1302, 1511, 1791, 1331] } return { 'LeftUp': LeftUp, 'LeftDown': { 'configname': '前沿产业动态', 'data': [ {'title': '角逐“算力之都”:中国八大算力枢纽交“答卷”', 'tags': ['数字经济', '算力枢纽', '数据集群', '人工智能'], 'date': time.strftime('%Y-%m-%d')}, {'title': 'AI公司被算力「卡脖子」,a16z想当创业公司的「制氧机」', 'tags': ['氧气计划', '算力枢纽', '大模型时代', 'AI芯片'], 'date': '2024-08-10'}, {'title': '工信部加快建设5G、算力等新型信息基础设施', 'tags': ['数字经济', '基础设施', '数字化转型', '工业互联网'], 'date': '2024-08-09'}, {'title': '数据基础设施加快落地 全国一体化算力网建设提速', 'tags': ['数字经济', '算力网络', '数据冷链', '大数据智算'], 'date': '2024-08-09'}, {'title': '算力促进线上市场稳健发展', 'tags': ['数据交易', '算力应用', '信息石油', '云计算'], 'date': '2024-08-08'}, {'title': '算力竞逐:从车端到云端', 'tags': ['汽车行业数字化', '智能驾驶', '云端算力', '车端算力'], 'date': '2024-08-08'}, ] }, 'RightUp': { 'configname': '全球投资热点', 'data': [ {'title': '总投资140亿元的“智能算力+”项目落户鸡西', 'tags': ['智能算力+', '数字孪生', '智慧城市', '人工智能'], 'date': time.strftime('%Y-%m-%d')}, {'title': '总投资100亿 又一算力中心落户韶关', 'tags': ['数据中心', '大模型', '云计算', 'AI芯片'], 'date': '2024-08-10'}, {'title': '零一万物、月之暗面再掀国产大模型资本战:年内亿元级融资已有20起', 'tags': ['国产大模型', '独角兽', '月之暗面', '百川智能'], 'date': '2024-08-09'}, {'title': '算力板块密集上涨AI投资开始了吗?', 'tags': ['存储芯片', '半导体', '英伟达', '医疗保健'], 'date': '2024-08-09'}, ] }, 'RightDown': RightDown, } ret = await large_screen_third_page(params_kw) return ret