将mysql数据表的数据转成百度ECharts可用的数据

数据表转换echarts数据格式录入数据库,方便查询使用。

表格: tp_table_analysis

备注: 表格分析 创建对某个表格进行分析的任务列表

索引:

名称类型属性备注
主索引idunique

字段:

名称类型默认值属性备注
idint(10) unsigned<auto_increment>
titlevarchar(255)任务的标题
descriptionvarchar(255)任务的描述(比如:某某的用户的某某表的分析)
uuidchar(32)任务的唯一参数
table_namevarchar(255)当前任务要分析的表格名称
table_analy_wherevarchar(255)deleted_at=0分析任务表格的查询条件如:deleted_at=0&status=1
table_analy_fieldvarchar(255)updated_at对这个表格中的这个字段进行分析拆分数据(年月日时分)
table_analy_field_typetinyint(3) unsigned0数据类型:0 int ; 1 datetime ;表中table_analy_field的数据类型是哪一种时间格式
table_calculate_fieldvarchar(255)id表格中的某个字段(用于数据分析使用的字段)默认使用id 如统计总数时使用count('id')
table_calculate_methodvarchar(255)count使用mysql的计算方式 对table_calculate_field进行处理 如count('id')、sum('score') 等等
analy_typetinyint(3) unsigned2【分析类型-分析包含的数据】0 :按照年,月,日,时,分;1:按照年,月,日,时;2:按照年,月,日;3:按照年,月;4:按照年
drag_sortnumeric(16,6)82980478.000000排序值:拖拽排序可用;建议值为使用2051年减去今天的时间得到的数字
statustinyint(3) unsigned1是否可用
delete_timeint(11) unsigned0软删除时间
update_timeint(11) unsigned0更新时间
create_timeint(11) unsigned0上传时间
idtitledescriptionuuidtable_nametable_analy_wheretable_analy_fieldtable_analy_field_typetable_calculate_fieldtable_calculate_methodanaly_typedrag_sortstatusdelete_timeupdate_timecreate_time
1药品消耗统计任务称重表(tp_drug_weigh_list)-药品消耗统计e56d241c518a4f2adc9015098c4e605ftp_drug_weigh_listdelete_time=0 and specs="500ml" and purification="化学纯" and drug_id=242create_time0wastagesum21106154643.1758001001643098395
2药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计5e39c8faedc3e0f2f1bac00d1dcfc3fftp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "500ml" and purification="化学纯" and drug_id=242create_time0idcount21106154643.1758001001643098395
3药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计2d14561eb124130e0c68e5b252282823tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "500ml" and purification="化学纯" and drug_id=242create_time0idcount21106154643.1758001001643098395
4药品入库统计任务入库表(tp_drug_in_list)-药品入库统计e298ee5cb0c8ca121b6d0ec8f6f5da21tp_drug_in_listdelete_time=0 and status!=0 and specs= "500ml" and purification="化学纯" and drug_id=242create_time0idcount21106154643.1758001001643098395
5药品消耗统计任务称重表(tp_drug_weigh_list)-药品消耗统计c775e33792189dc43c08142f1c535704tp_drug_weigh_listdelete_time=0 and specs="100ml" and purification="化学纯" and drug_id=153create_time0wastagesum21106154627.9668001001643098411
6药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计67d8bc9af14b07139c7b275eee76707atp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "100ml" and purification="化学纯" and drug_id=153create_time0idcount21106154627.9668001001643098411
7药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计1e4bb6d697711f9316114565c101add7tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "100ml" and purification="化学纯" and drug_id=153create_time0idcount21106154627.9668001001643098411
8药品入库统计任务入库表(tp_drug_in_list)-药品入库统计e47d03af3d74726369a52d4cd43b0224tp_drug_in_listdelete_time=0 and status!=0 and specs= "100ml" and purification="化学纯" and drug_id=153create_time0idcount21106154627.9668001001643098411
9药品消耗统计任务称重表(tp_drug_weigh_list)-药品消耗统计cdd4b8c51ac13bb1d0d64df095a1d0cdtp_drug_weigh_listdelete_time=0 and specs="100ml" and purification="高纯试剂" and drug_id=153create_time0wastagesum21106154626.2969001001643098412
10药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计a5f3218439aabc3feb05ec47641e0478tp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "100ml" and purification="高纯试剂" and drug_id=153create_time0idcount21106154626.2969001001643098412
11药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计630f393f118960e1ad7188d1312a5528tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "100ml" and purification="高纯试剂" and drug_id=153create_time0idcount21106154626.2969001001643098412
12药品入库统计任务入库表(tp_drug_in_list)-药品入库统计0aac29dd1b01ee67c8747d34f216c4bftp_drug_in_listdelete_time=0 and status!=0 and specs= "100ml" and purification="高纯试剂" and drug_id=153create_time0idcount21106154626.2969001001643098412
13药品消耗统计任务称重表(tp_drug_weigh_list)-药品消耗统计3f522b89069e57f4dc0df9e446e6147ftp_drug_weigh_listdelete_time=0 and specs="100ml" and purification="化学纯" and drug_id=278create_time0wastagesum21106154623.6467001001643098415
14药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计b261955bc5d0f081020c8abb902c8803tp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "100ml" and purification="化学纯" and drug_id=278create_time0idcount21106154623.6467001001643098415
15药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计32b4b20998146e5f8f2ec27cd58b90d4tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "100ml" and purification="化学纯" and drug_id=278create_time0idcount21106154623.6467001001643098415
16药品入库统计任务入库表(tp_drug_in_list)-药品入库统计2d94eafb90a5bcf22a9208ca30f80bdftp_drug_in_listdelete_time=0 and status!=0 and specs= "100ml" and purification="化学纯" and drug_id=278create_time0idcount21106154623.6467001001643098415
17药品消耗统计任务称重表(tp_drug_weigh_list)-药品消耗统计09546e9fd4b5f53e0eb460d45303f740tp_drug_weigh_listdelete_time=0 and specs="500ml" and purification="化学纯" and drug_id=154create_time0wastagesum21106154622.7774001001643098416
18药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计583c89f15cacb12b4d2cc2005dc5f99btp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "500ml" and purification="化学纯" and drug_id=154create_time0idcount21106154622.7774001001643098416
19药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计887af62c5fe492268e12b686c2fff577tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "500ml" and purification="化学纯" and drug_id=154create_time0idcount21106154622.7774001001643098416
20药品入库统计任务入库表(tp_drug_in_list)-药品入库统计2cff8ab417e27dfaf5ed4e05a6020676tp_drug_in_listdelete_time=0 and status!=0 and specs= "500ml" and purification="化学纯" and drug_id=154create_time0idcount21106154622.7774001001643098416
21药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计a5f3218439aabc3feb05ec47641e0478tp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "100ml" and purification="高纯试剂" and drug_id=153create_time0idcount21106154621.8254001001643098417
22药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计630f393f118960e1ad7188d1312a5528tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "100ml" and purification="高纯试剂" and drug_id=153create_time0idcount21106154621.8254001001643098417
23药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计67d8bc9af14b07139c7b275eee76707atp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "100ml" and purification="化学纯" and drug_id=153create_time0idcount21106154619.7704001001643098419
24药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计1e4bb6d697711f9316114565c101add7tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "100ml" and purification="化学纯" and drug_id=153create_time0idcount21106154619.7704001001643098419
25药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计5e39c8faedc3e0f2f1bac00d1dcfc3fftp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "500ml" and purification="化学纯" and drug_id=242create_time0idcount21106154613.8237001001643098425
26药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计2d14561eb124130e0c68e5b252282823tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "500ml" and purification="化学纯" and drug_id=242create_time0idcount21106154613.8237001001643098425
27药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计5e39c8faedc3e0f2f1bac00d1dcfc3fftp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "500ml" and purification="化学纯" and drug_id=242create_time0idcount21105162714.4478001001643182364
28药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计2d14561eb124130e0c68e5b252282823tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "500ml" and purification="化学纯" and drug_id=242create_time0idcount21105162714.4478001001643182364
29药品消耗统计任务称重表(tp_drug_weigh_list)-药品消耗统计6a84a40a2e227c345235a0455e83897atp_drug_weigh_listdelete_time=0 and specs="500ml" and purification="丁真很纯" and drug_id=2884create_time0wastagesum21104163400.6341001001643268358
30药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计e4868005cca5645fb7b6432ae1b30a5ftp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "500ml" and purification="丁真很纯" and drug_id=2884create_time0idcount21104163400.6341001001643268358
31药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计33ea492b4c878480fd1a632dd19bdef5tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "500ml" and purification="丁真很纯" and drug_id=2884create_time0idcount21104163400.6341001001643268358
32药品入库统计任务入库表(tp_drug_in_list)-药品入库统计fd0cecf4bd836e8a6eff61bb8f70fff2tp_drug_in_listdelete_time=0 and status!=0 and specs= "500ml" and purification="丁真很纯" and drug_id=2884create_time0idcount21104163400.6341001001643268358
33药品消耗统计任务称重表(tp_drug_weigh_list)-药品消耗统计9e5fda7932d1c336516a3de7da247324tp_drug_weigh_listdelete_time=0 and specs="500ml" and purification="分析纯" and drug_id=9create_time0wastagesum2943002253.5567401001644677745
34药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计8668bea4a4b30842121c5edad6586505tp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "500ml" and purification="分析纯" and drug_id=9create_time0idcount2943002253.5567401001644677745
35药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计309df9ff3e4df8caa112f7b8779aa506tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "500ml" and purification="分析纯" and drug_id=9create_time0idcount2943002253.5567401001644677745
36药品入库统计任务入库表(tp_drug_in_list)-药品入库统计55f3a76e198fe34dba521eb6b7a778c0tp_drug_in_listdelete_time=0 and status!=0 and specs= "500ml" and purification="分析纯" and drug_id=9create_time0idcount2943002253.5567401001644677745
37药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计67d8bc9af14b07139c7b275eee76707atp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "100ml" and purification="化学纯" and drug_id=153create_time0idcount2943002243.2911901001644677755
38药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计1e4bb6d697711f9316114565c101add7tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "100ml" and purification="化学纯" and drug_id=153create_time0idcount2943002243.2911901001644677755
39药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计8668bea4a4b30842121c5edad6586505tp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "500ml" and purification="分析纯" and drug_id=9create_time0idcount2942791029.7707301001644888969
40药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计309df9ff3e4df8caa112f7b8779aa506tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "500ml" and purification="分析纯" and drug_id=9create_time0idcount2942791029.7707301001644888969
41药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计e4868005cca5645fb7b6432ae1b30a5ftp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "500ml" and purification="丁真很纯" and drug_id=2884create_time0idcount2942790999.7619501001644888999
42药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计33ea492b4c878480fd1a632dd19bdef5tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "500ml" and purification="丁真很纯" and drug_id=2884create_time0idcount2942790999.7619501001644888999
43药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计67d8bc9af14b07139c7b275eee76707atp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "100ml" and purification="化学纯" and drug_id=153create_time0idcount2942790996.7316601001644889002
44药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计1e4bb6d697711f9316114565c101add7tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "100ml" and purification="化学纯" and drug_id=153create_time0idcount2942790996.7316601001644889002
45药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计8668bea4a4b30842121c5edad6586505tp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "500ml" and purification="分析纯" and drug_id=9create_time0idcount2942787611.2717201001644892387
46药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计309df9ff3e4df8caa112f7b8779aa506tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "500ml" and purification="分析纯" and drug_id=9create_time0idcount2942787611.2717201001644892387
47药品消耗统计任务称重表(tp_drug_weigh_list)-药品消耗统计06281463ee6024f7cb509fb92f299ee6tp_drug_weigh_listdelete_time=0 and specs="100ml" and purification="实验纯" and drug_id=43create_time0wastagesum2942787605.5651601001644892393
48药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计084f7fd183522838990f9473fbf1c2ddtp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "100ml" and purification="实验纯" and drug_id=43create_time0idcount2942787605.5651601001644892393
49药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计33210a1538049da22b4b96f605b02bf5tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "100ml" and purification="实验纯" and drug_id=43create_time0idcount2942787605.5651601001644892393
50药品入库统计任务入库表(tp_drug_in_list)-药品入库统计e8a05fa14eecd4a8cac75153231c7d54tp_drug_in_listdelete_time=0 and status!=0 and specs= "100ml" and purification="实验纯" and drug_id=43create_time0idcount2942787605.5651601001644892393
51药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计e4868005cca5645fb7b6432ae1b30a5ftp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "500ml" and purification="丁真很纯" and drug_id=2884create_time0idcount2942787601.8198601001644892397
52药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计33ea492b4c878480fd1a632dd19bdef5tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "500ml" and purification="丁真很纯" and drug_id=2884create_time0idcount2942787601.8198601001644892397
53药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计5e39c8faedc3e0f2f1bac00d1dcfc3fftp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "500ml" and purification="化学纯" and drug_id=242create_time0idcount2942787597.5244501001644892401
54药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计2d14561eb124130e0c68e5b252282823tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "500ml" and purification="化学纯" and drug_id=242create_time0idcount2942787597.5244501001644892401
55药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计67d8bc9af14b07139c7b275eee76707atp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "100ml" and purification="化学纯" and drug_id=153create_time0idcount2942787530.7937901001644892468
56药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计1e4bb6d697711f9316114565c101add7tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "100ml" and purification="化学纯" and drug_id=153create_time0idcount2942787530.7937901001644892468
57药品消耗统计任务称重表(tp_drug_weigh_list)-药品消耗统计4da0ae7a47a17fc0d4d152ed51ee0199tp_drug_weigh_listdelete_time=0 and specs="500ml" and purification="丁真很纯" and drug_id=242create_time0wastagesum2942686640.1428601001644993358
58药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计096e770d3ea2aa50a7d7ce909db2b38ctp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "500ml" and purification="丁真很纯" and drug_id=242create_time0idcount2942686640.1428601001644993358
59药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计3416f9f3c2f21c763a185d24241913eftp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "500ml" and purification="丁真很纯" and drug_id=242create_time0idcount2942686640.1428601001644993358
60药品入库统计任务入库表(tp_drug_in_list)-药品入库统计e108f874b2b0369c1b74f0a4531da16atp_drug_in_listdelete_time=0 and status!=0 and specs= "500ml" and purification="丁真很纯" and drug_id=242create_time0idcount2942686640.1428601001644993358
61药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计8668bea4a4b30842121c5edad6586505tp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "500ml" and purification="分析纯" and drug_id=9create_time0idcount2942686635.3614801001644993363
62药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计309df9ff3e4df8caa112f7b8779aa506tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "500ml" and purification="分析纯" and drug_id=9create_time0idcount2942686635.3614801001644993363
63药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计e4868005cca5645fb7b6432ae1b30a5ftp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "500ml" and purification="丁真很纯" and drug_id=2884create_time0idcount2942686631.4521601001644993367
64药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计33ea492b4c878480fd1a632dd19bdef5tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "500ml" and purification="丁真很纯" and drug_id=2884create_time0idcount2942686631.4521601001644993367
65药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计b261955bc5d0f081020c8abb902c8803tp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "100ml" and purification="化学纯" and drug_id=278create_time0idcount2942686602.6312301001644993396
66药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计32b4b20998146e5f8f2ec27cd58b90d4tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "100ml" and purification="化学纯" and drug_id=278create_time0idcount2942686602.6312301001644993396
67药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计e4868005cca5645fb7b6432ae1b30a5ftp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "500ml" and purification="丁真很纯" and drug_id=2884create_time0idcount2942686495.3010101001644993503
68药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计33ea492b4c878480fd1a632dd19bdef5tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "500ml" and purification="丁真很纯" and drug_id=2884create_time0idcount2942686495.3010101001644993503
69药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计096e770d3ea2aa50a7d7ce909db2b38ctp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "500ml" and purification="丁真很纯" and drug_id=242create_time0idcount2942686406.8705801001644993592
70药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计3416f9f3c2f21c763a185d24241913eftp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "500ml" and purification="丁真很纯" and drug_id=242create_time0idcount2942686406.8705801001644993592
71药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计67d8bc9af14b07139c7b275eee76707atp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "100ml" and purification="化学纯" and drug_id=153create_time0idcount2942686346.3661401001644993652
72药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计1e4bb6d697711f9316114565c101add7tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "100ml" and purification="化学纯" and drug_id=153create_time0idcount2942686346.3661401001644993652
73药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计67d8bc9af14b07139c7b275eee76707atp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "100ml" and purification="化学纯" and drug_id=153create_time0idcount2942686298.8315301001644993700
74药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计1e4bb6d697711f9316114565c101add7tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "100ml" and purification="化学纯" and drug_id=153create_time0idcount2942686298.8315301001644993700
75药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计a5f3218439aabc3feb05ec47641e0478tp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "100ml" and purification="高纯试剂" and drug_id=153create_time0idcount2942686293.6386801001644993705
76药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计630f393f118960e1ad7188d1312a5528tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "100ml" and purification="高纯试剂" and drug_id=153create_time0idcount2942686293.6386801001644993705
77药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计583c89f15cacb12b4d2cc2005dc5f99btp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "500ml" and purification="化学纯" and drug_id=154create_time0idcount2942686289.1540601001644993709
78药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计887af62c5fe492268e12b686c2fff577tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "500ml" and purification="化学纯" and drug_id=154create_time0idcount2942686289.1540601001644993709
79药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计a5f3218439aabc3feb05ec47641e0478tp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "100ml" and purification="高纯试剂" and drug_id=153create_time0idcount2942686286.4064401001644993712
80药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计630f393f118960e1ad7188d1312a5528tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "100ml" and purification="高纯试剂" and drug_id=153create_time0idcount2942686286.4064401001644993712
81药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计67d8bc9af14b07139c7b275eee76707atp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "100ml" and purification="化学纯" and drug_id=153create_time0idcount2942686283.3113401001644993715
82药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计1e4bb6d697711f9316114565c101add7tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "100ml" and purification="化学纯" and drug_id=153create_time0idcount2942686283.3113401001644993715
83药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计67d8bc9af14b07139c7b275eee76707atp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "100ml" and purification="化学纯" and drug_id=153create_time0idcount2942686233.1101101001644993765
84药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计1e4bb6d697711f9316114565c101add7tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "100ml" and purification="化学纯" and drug_id=153create_time0idcount2942686233.1101101001644993765
85药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计67d8bc9af14b07139c7b275eee76707atp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "100ml" and purification="化学纯" and drug_id=153create_time0idcount2942686171.2430401001644993827
86药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计1e4bb6d697711f9316114565c101add7tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "100ml" and purification="化学纯" and drug_id=153create_time0idcount2942686171.2430401001644993827
87药品消耗统计任务称重表(tp_drug_weigh_list)-药品消耗统计8e395041be9c84aafc5eec4204a35bd6tp_drug_weigh_listdelete_time=0 and specs="50ml" and purification="化学纯" and drug_id=1create_time0wastagesum2941662604.5224401001646017394
88药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计a9f5571e872b03c3335d5928ab905bf6tp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "50ml" and purification="化学纯" and drug_id=1create_time0idcount2941662604.5224401001646017394
89药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计311967fc2391aeaad94004b7fa1e8d36tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "50ml" and purification="化学纯" and drug_id=1create_time0idcount2941662604.5224401001646017394
90药品入库统计任务入库表(tp_drug_in_list)-药品入库统计bcefef0c487726fce856c23b5ca0995ctp_drug_in_listdelete_time=0 and status!=0 and specs= "50ml" and purification="化学纯" and drug_id=1create_time0idcount2941662604.5224401001646017394
91药品消耗统计任务称重表(tp_drug_weigh_list)-药品消耗统计7fc3985772db79b3061e75a0f3332937tp_drug_weigh_listdelete_time=0 and specs="500ml" and purification="分析纯" and drug_id=17create_time0wastagesum2941662601.0720101001646017397
92药品交接出库(预废弃A=>B)统计任务入库表(tp_drug_out_list)-药品入库统计0a5d568c7f8b7f9f271e530e8f146af9tp_drug_out_listdelete_time=0 and order_type=1 and status=7 and specs= "500ml" and purification="分析纯" and drug_id=17create_time0idcount2941662601.0720101001646017397
93药品交接出库(预废弃AB=>C)统计任务入库表(tp_drug_out_list)-药品入库统计b96e941fa5ab2796c833e55fe4db8c33tp_drug_out_listdelete_time=0 and order_type=2 and status=7 and specs= "500ml" and purification="分析纯" and drug_id=17create_time0idcount2941662601.0720101001646017397
94药品入库统计任务入库表(tp_drug_in_list)-药品入库统计1f125ba371448563fc9e9c1546db9661tp_drug_in_listdelete_time=0 and status!=0 and specs= "500ml" and purification="分析纯" and drug_id=17create_time0idcount2941662601.0720101001646017397

表格: tp_table_statistic

备注: 通过分析表的任务生成的统计数据

索引:

名称类型属性备注
主索引idunique

字段:

名称类型默认值属性备注
idint(10) unsigned<auto_increment>
analy_uuidchar(32)对应分析任务的参数
time_periodschar(16)1970/01/01 08:00时间周期:格式如: 【1970/01/01 08:00】表示从1970/01/01 08:00到1970/01/01 08:01的时段;【1970/01/01】:表示从1970/01/01的0点到1970/01/02的0点
time_typechar(1)ytime_periods的类型
count_numint(10) unsigned0对应时间段的 统计数据值
delete_timeint(11) unsigned0软删除时间
update_timeint(11) unsigned0更新时间
create_timeint(11) unsigned0上传时间
data_last_timevarchar(255)0最后一条数据的时间(可以是字符串):用于排序【任务表的table_calculate_field】

数据: (例子数据生成)

idanaly_uuidtime_periodstime_typecount_numdelete_timeupdate_timecreate_time
1e298ee5cb0c8ca121b6d0ec8f6f5da212022y5016448924011643098396
2e298ee5cb0c8ca121b6d0ec8f6f5da212022/01m5016448924011643098396
3e298ee5cb0c8ca121b6d0ec8f6f5da212022/01/21d5016448924011643098396
45e39c8faedc3e0f2f1bac00d1dcfc3ff2022y3016448924011643098396
55e39c8faedc3e0f2f1bac00d1dcfc3ff2022/01m3016448924011643098396
65e39c8faedc3e0f2f1bac00d1dcfc3ff2022/01/24d3016448924011643098396
7e47d03af3d74726369a52d4cd43b02242022y10016449938281643098411
8e47d03af3d74726369a52d4cd43b02242022/01m10016449938281643098411
9e47d03af3d74726369a52d4cd43b02242022/01/20d10016449938281643098411
1067d8bc9af14b07139c7b275eee76707a2022y9016449938281643098411
1167d8bc9af14b07139c7b275eee76707a2022/01m1016446777551643098411
1267d8bc9af14b07139c7b275eee76707a2022/01/24d1016446777551643098411
1367d8bc9af14b07139c7b275eee76707a2022/01/25d0001644677755
1467d8bc9af14b07139c7b275eee76707a2022/01/26d0001644677755
1567d8bc9af14b07139c7b275eee76707a2022/01/27d0001644677755
1667d8bc9af14b07139c7b275eee76707a2022/01/28d0001644677755
1767d8bc9af14b07139c7b275eee76707a2022/01/29d0001644677755
1867d8bc9af14b07139c7b275eee76707a2022/01/30d0001644677755
1967d8bc9af14b07139c7b275eee76707a2022/01/31d0001644677755
2067d8bc9af14b07139c7b275eee76707a2022/02m8016449938281644677755
2167d8bc9af14b07139c7b275eee76707a2022/02/01d0001644677755
2267d8bc9af14b07139c7b275eee76707a2022/02/02d0001644677755
2367d8bc9af14b07139c7b275eee76707a2022/02/03d0001644677755
2467d8bc9af14b07139c7b275eee76707a2022/02/04d0001644677755
2567d8bc9af14b07139c7b275eee76707a2022/02/05d0001644677755
2667d8bc9af14b07139c7b275eee76707a2022/02/06d0001644677755
2767d8bc9af14b07139c7b275eee76707a2022/02/07d0001644677755
2867d8bc9af14b07139c7b275eee76707a2022/02/08d0001644677755
2967d8bc9af14b07139c7b275eee76707a2022/02/09d0001644677755
3067d8bc9af14b07139c7b275eee76707a2022/02/10d0001644677755
3167d8bc9af14b07139c7b275eee76707a2022/02/11d5016448890021644677755
3267d8bc9af14b07139c7b275eee76707a2022/02/12d0001644889002
3367d8bc9af14b07139c7b275eee76707a2022/02/13d0001644889002
3467d8bc9af14b07139c7b275eee76707a2022/02/14d3016449938281644889002
351f125ba371448563fc9e9c1546db96612022y5001646017398
361f125ba371448563fc9e9c1546db96612022/02m5001646017398
371f125ba371448563fc9e9c1546db96612022/02/24d5001646017398
380a5d568c7f8b7f9f271e530e8f146af92022y3001646017398
390a5d568c7f8b7f9f271e530e8f146af92022/02m3001646017398
400a5d568c7f8b7f9f271e530e8f146af92022/02/24d3001646017398

 /**
     * 数据量不能过多,过多的时候需要考虑按照查询大表中数据的按照每年的数据进行分开查询数据写入,再不行就分月 分日 
     * 需要参数uuid
     * 1.获取分析数据的配置
     * 2.查询统计表table_statistic中是否存在已有的分析数据,获取最后的分析数据的最新【(年)数据、(年月)数据、(年月日)数据、(年月日时)、(年月日时分)】的数据各一条(这几个数据需要重新修改(因为有可能不是最新的了))
     * 3.根据第1点和第2点得到数据--生成sql语句
     * 4.执行sql语句--查询
     * 5.将查询到数据封装成二维数组--
     * 6.写入到统计表中table_statistic
     */
    public function analyTable($analyUuid = ''){
        //第1步:根据uuid,获取分析数据的配置
        $analyData = $this->getDataByUUID();
        if($analyData['code'] !== 0){
            return $analyData;
        }

        if(empty($analyUuid)){
            $analyUuid = input('get.uuid');
        }

        // dump($analyData);

        //第2步:根据analy_uuid获取最新的数据
        $statisticData = $this->findByAnalyUUIDWithLastData(input('get.uuid'));
        if($statisticData['code'] !== 0){
            return $statisticData;
        }

        // dump($statisticData);

        //第3步:根据配置数据生成sql语句
        $sql = '';

        if($analyData['data']['table_analy_field_type'] == 1){
            $analyData['data']['table_analy_where'] = !empty($analyData['data']['table_analy_where'])?(($statisticData['data']['time_periods_int'] == 0)?$analyData['data']['table_analy_where']:$analyData['data']['table_analy_where']." and TO_DAYS(".$analyData['data']['table_analy_field'] . ") >= TO_DAYS('" .$statisticData['data']['time_periods']."')"):$analyData['data']['table_analy_where'];
            $sql = $sql."select UNIX_TIMESTAMP(".$analyData['data']['table_analy_field'].") as ".$analyData['data']['table_analy_field'].",".$analyData['data']['table_calculate_field']. " from ".$analyData['data']['table_name']." where ".$analyData['data']['table_analy_where'] ." order by ".$analyData['data']['table_analy_field'] ." asc";
        }else{
            $analyData['data']['table_analy_where'] = !empty($analyData['data']['table_analy_where'])?$analyData['data']['table_analy_where']." and ".$analyData['data']['table_analy_field'] . ">=" .$statisticData['data']['time_periods_int']:$analyData['data']['table_analy_where'];
            $sql = $sql."select ".$analyData['data']['table_analy_field'].",".$analyData['data']['table_calculate_field']. " from ".$analyData['data']['table_name']." where ".$analyData['data']['table_analy_where'] ." order by ".$analyData['data']['table_analy_field'] ." asc";
        }

        // dump($sql);

        // dump("第二步的数据需要拼至sql的where中,未完成");

        if(empty($sql)){
            return app('api_result')->returnArray(3,['msg'=>'sql语句不能为空!']);
        }
        //第4步:执行sql语句--如果数据过大- 下面的其他步骤就需要修改-- 解决方案是:将表进行拆分查询 然后再写入--比如将上面一步的查询数据修改为只查1万条数据即可,然后再重新进行分析
        // query方法用于执行SQL查询操作,如果数据非法或者查询错误则返回false,否则返回查询结果数据集(同select方法)。
        // Db::query("select * from think_user where status=1");
        // execute用于更新和写入数据的sql操作,如果数据非法或者查询错误则返回false,否则返回影响的记录数。
        // Db::execute("update think_user set name='thinkphp' where status=1");
        $dbData =  Db::query($sql);

        // dump($sql);

        if(empty($dbData)){
            return app('api_result')->returnArray(0,['msg'=>'执行sql语句,查询不到任何数据']);
        }
        // dump($dbData);
        // die;

        //第5步:封装数据
        //第一条数据为最开始的数据,最后一条数据为最新的数据
        $totalLength = count($dbData);
        $firstIndexData = $dbData[0];
        $lastIndexData = $dbData[count($dbData)-1];
        $firstYear = date("Y",$firstIndexData[$analyData['data']['table_analy_field']]);//最开始的年
        $firstMonth = date("m",$firstIndexData[$analyData['data']['table_analy_field']]);//最开始的月
        $firstDate = date("d",$firstIndexData[$analyData['data']['table_analy_field']]);//最开始的日
        $firstHour = date("H",$firstIndexData[$analyData['data']['table_analy_field']]);//最开始的小时
        $firstMinute = date("i",$firstIndexData[$analyData['data']['table_analy_field']]);//最开始的分钟
        $lastYear = date("Y",$lastIndexData[$analyData['data']['table_analy_field']]);//最后的年
        $lastMonth = date("m",$lastIndexData[$analyData['data']['table_analy_field']]);//最后的的月
        $lastDate = date("d",$lastIndexData[$analyData['data']['table_analy_field']]);//最后的的日
        $lastHour = date("H",$lastIndexData[$analyData['data']['table_analy_field']]);//最后的的小时
        $lastMinute = date("i",$lastIndexData[$analyData['data']['table_analy_field']]);//最后的的分钟

        // dump(date("Y-m-d h:i:s"),$firstIndexData);
        // dump(date("Y-m-d h:i:s"),$lastIndexData);
        // dump( $dbData);die;

        $data = []; //直接写入的数据
        $updateData = []; //直接更新的数据
        $backData = []; //需要重新计算的数据
        $startYear = $firstYear;
        //生成数据-从年-月-日-小时-分钟逐一开始
        for($y=$startYear; $y<=$lastYear;$y++){
           $yearNum = 0;//当前年数据
           for($j=0; $j<$totalLength; $j++){
                if(date("Y",$dbData[$j][$analyData['data']['table_analy_field']])==$y){
                    if($analyData['data']['table_calculate_method'] == 'count'){
                        $yearNum +=1;//加1
                    }
                    if($analyData['data']['table_calculate_method'] == 'sum'){
                        $yearNum += $dbData[$j][$analyData['data']['table_calculate_field']];//按照字段的值进行加
                    }
                }
           }
           //等于当前年的时候,需要写到更新数据中
           if($statisticData['data']['year'] == $y){
                //【分析类型-分析包含的数据】0 :按照年,月,日,时,分;1:按照年,月,日,时;2:按照年,月,日;3:按照年,月;4:按照年
                if($analyData['data']['analy_type'] == 4){
                    //更新的数据需要重新查询  === 等于当前年时 只需要更新即可
                    $updateData = array_merge($updateData,[[
                        'analy_uuid'=>$analyUuid,
                        'time_periods'=>$y,
                        'count_num'=>$yearNum,
                        'time_type'=>'y',
                        'update_time'=>time()
                    ]]);
                }else{
                    //这个年份需要重新计算-- 正年的数据--- 包含历史数据和现在的数据 
                    //count_num == 按照分析任务的类型; 比如 年月 那么计算当前年的所有的月的总数据sum ; 年月日 则就算当前年的所有的日的总数据sum 其他的类比
                    $backData = array_merge($backData,[[
                        'analy_uuid'=>$analyUuid,
                        'time_periods'=>$y,
                        'count_num'=>0, // 需重算--- 
                        'update_time'=>time(),
                        'time_type'=>'y',
                        'analy_type'=>$analyData['data']['analy_type']
                    ]]);
                }
               
            }else{
                $data = array_merge($data,[[
                    'analy_uuid'=>$analyUuid,
                    'time_periods'=>$y,
                    'time_type'=>'y',
                    'count_num'=>$yearNum,
                    'create_time'=>time()
                ]]);
            }
           //analy_type的值有0,1,2,3,4 ---其中0是计算到分钟,1是计算到小时;2是计算到天,3是计算到月份,4计算到年
            if($analyData['data']['analy_type'] > 3){
                continue;
            }
           //月数据开始
           $startMonth = $y == $firstYear?$firstMonth:1;//最开始的一年,计算最开始的月份,其他的从1月份开始
           $lastMonthLength = $y == $lastYear?$lastMonth:12;//如果是最后一年,那么就计算到数据的最后一个月,其他的年份都是到12月
           for($m=$startMonth;$m<=$lastMonthLength;$m++){
                $monthNum = 0; //当前月数据
                for($j=0; $j<$totalLength; $j++){
                    if(date("Y/m",$dbData[$j][$analyData['data']['table_analy_field']]) == $y."/".sprintf('%02d',$m)){
                        if($analyData['data']['table_calculate_method'] == 'count'){
                            $monthNum +=1;//加1
                        }
                        if($analyData['data']['table_calculate_method'] == 'sum'){
                            $monthNum += $dbData[$j][$analyData['data']['table_calculate_field']];//按照字段的值进行加
                        }
                    }
                }
                //等于当前年当前月的时候,需要写到更新数据中
                if($statisticData['data']['year'] == $y && $statisticData['data']['month'] == sprintf('%02d',$m)){
                    //【分析类型-分析包含的数据】0 :按照年,月,日,时,分;1:按照年,月,日,时;2:按照年,月,日;3:按照年,月;4:按照年
                    if($analyData['data']['analy_type'] == 3){
                        //更新的数据需要重新查询  === 等于当前年月时 只需要更新即可
                        $updateData = array_merge($updateData,[[
                            'analy_uuid'=>$analyUuid,
                            'time_periods'=>$y."/".sprintf('%02d',$m),
                            'count_num'=>$monthNum,
                            'time_type'=>'m',
                            'update_time'=>time()
                        ]]);
                    }else{
                        //这个年份需要重新计算-- 正年的数据--- 包含历史数据和现在的数据 
                        //count_num == 按照分析任务的类型; 比如 年月 那么计算当前年的所有的月的总数据sum ; 年月日 则就算当前年的所有的日的总数据sum 其他的类比
                        $backData = array_merge($backData,[[
                            'analy_uuid'=>$analyUuid,
                            'time_periods'=>$y."/".sprintf('%02d',$m),
                            'count_num'=>0,
                            'update_time'=>time(),
                            'time_type'=>'m',
                            'analy_type'=>$analyData['data']['analy_type']
                        ]]);
                    }

                }else{
                    $data = array_merge($data,[[
                        'analy_uuid'=>$analyUuid,
                        'time_periods'=>$y."/".sprintf('%02d',$m),
                        'time_type'=>'m',
                        'count_num'=>$monthNum,
                        'create_time'=>time()
                    ]]);
                }
                
                //analy_type的值有0,1,2,3,4 ---其中0是计算到分钟,1是计算到小时;2是计算到天,3是计算到月份,4计算到年
                if($analyData['data']['analy_type'] > 2){
                    continue;
                }
                //日数据开始
                $dateLength = cal_days_in_month(CAL_GREGORIAN, $m, $y);//计算当前月份中的天数
                // $dateLength = date('t', strtotime($m."-".$y));//计算当前月份中的天数 --- 如果没有装 

                $startDate = ($y == $firstYear && sprintf('%02d',$m) == $firstMonth)?$firstDate:1;//如果是最开始的一年的那个月,则计算最开始的一天的当天开始算
                $lastDateLength = ($y == $lastYear && sprintf('%02d',$m) == $lastMonth)?$lastDate:$dateLength;//如果是最后一年,那么就只计算到最后一天,否则就是当月的总天数
                for($d=$startDate;$d<=$lastDateLength;$d++){
                    $dateNum = 0;//当前日数据
                    for($j=0; $j<$totalLength; $j++){
                        if(date("Y/m/d",$dbData[$j][$analyData['data']['table_analy_field']]) == $y."/".sprintf('%02d',$m)."/".sprintf('%02d',$d)){
                            if($analyData['data']['table_calculate_method'] == 'count'){
                                $dateNum +=1;//加1
                            }
                            if($analyData['data']['table_calculate_method'] == 'sum'){
                                $dateNum += $dbData[$j][$analyData['data']['table_calculate_field']];//按照字段的值进行加
                            }
                        }
                    }
                    //等于当前年当前月当前日的时候,需要写到更新数据中
                    if($statisticData['data']['year'] == $y && $statisticData['data']['month'] == sprintf('%02d',$m) && $statisticData['data']['date'] == sprintf('%02d',$d)){
                         //【分析类型-分析包含的数据】0 :按照年,月,日,时,分;1:按照年,月,日,时;2:按照年,月,日;3:按照年,月;4:按照年
                        if($analyData['data']['analy_type'] == 2){
                            //更新的数据需要重新查询  === 等于当前年月时 只需要更新即可
                            $updateData = array_merge($updateData,[[
                                'analy_uuid'=>$analyUuid,
                                'time_periods'=>$y."/".sprintf('%02d',$m)."/".sprintf('%02d',$d),
                                'count_num'=>$dateNum,
                                'time_type'=>'d',
                                'update_time'=>time()
                            ]]);
                        }else{
                            //这个年份需要重新计算-- 正年的数据--- 包含历史数据和现在的数据 
                            //count_num == 按照分析任务的类型; 比如 年月 那么计算当前年的所有的月的总数据sum ; 年月日 则就算当前年的所有的日的总数据sum 其他的类比
                            $backData = array_merge($backData,[[
                                'analy_uuid'=>$analyUuid,
                                'time_periods'=>$y."/".sprintf('%02d',$m)."/".sprintf('%02d',$d),
                                'count_num'=>0,
                                'update_time'=>time(),
                                'time_type'=>'d',
                                'analy_type'=>$analyData['data']['analy_type']
                            ]]);
                        }
                    }else{
                        $data = array_merge($data,[[
                            'analy_uuid'=>$analyUuid,
                            'time_periods'=>$y."/".sprintf('%02d',$m)."/".sprintf('%02d',$d),
                            'time_type'=>'d',
                            'count_num'=>$dateNum,
                            'create_time'=>time()
                        ]]);
                    }
                    //analy_type的值有0,1,2,3,4 ---其中0是计算到分钟,1是计算到小时;2是计算到天,3是计算到月份,4计算到年
                    if($analyData['data']['analy_type'] > 1){
                        continue;
                    }
                    //小时数据开始
                    $startHour = ($y == $firstYear && sprintf('%02d',$m) == $firstMonth && sprintf('%02d',$d) == $firstDate)?$firstHour:0;//如果是最开始的一年的那个月那一天,则计算最开始的一天的当天开始算
                    $lastHourLength = ($y == $lastYear && sprintf('%02d',$m) == $lastMonth && sprintf('%02d',$d) == $lastDate)?$lastHour:23;//如果是最后一年,那么就只计算到最后一天,否则就是当月的当天的当前小时
                    for($h=$startHour;$h<=$lastHourLength;$h++){
                        $hourNum = 0;//当前小时数据
                        for($j=0; $j<$totalLength; $j++){
                            if(date("Y/m/d H",$dbData[$j][$analyData['data']['table_analy_field']]) == $y."/".sprintf('%02d',$m)."/".sprintf('%02d',$d)." ".sprintf('%02d',$h)){
                                if($analyData['data']['table_calculate_method'] == 'count'){
                                    $hourNum +=1;//加1
                                }
                                if($analyData['data']['table_calculate_method'] == 'sum'){
                                    $hourNum += $dbData[$j][$analyData['data']['table_calculate_field']];//按照字段的值进行加
                                }
                            }
                        }
                        //等于当前年当前月当前日当前小时的时候,需要写到更新数据中
                        if($statisticData['data']['year'] == $y && $statisticData['data']['month'] == sprintf('%02d',$m) && $statisticData['data']['date'] == sprintf('%02d',$d) && $statisticData['data']['hour'] == sprintf('%02d',$h)){
                             //【分析类型-分析包含的数据】0 :按照年,月,日,时,分;1:按照年,月,日,时;2:按照年,月,日;3:按照年,月;4:按照年
                            if($analyData['data']['analy_type'] == 1){
                                //更新的数据需要重新查询  === 等于当前年月时 只需要更新即可
                                $updateData = array_merge($updateData,[[
                                    'analy_uuid'=>$analyUuid,
                                    'time_periods'=>$y."/".sprintf('%02d',$m)."/".sprintf('%02d',$d)." ".sprintf('%02d',$h),
                                    'count_num'=>$hourNum,
                                    'time_type'=>'h',
                                    'update_time'=>time()
                                ]]);
                            }else{
                                //这个年份需要重新计算-- 正年的数据--- 包含历史数据和现在的数据 
                                //count_num == 按照分析任务的类型; 比如 年月 那么计算当前年的所有的月的总数据sum ; 年月日 则就算当前年的所有的日的总数据sum 其他的类比
                                $backData = array_merge($backData,[[
                                    'analy_uuid'=>$analyUuid,
                                    'time_periods'=>$y."/".sprintf('%02d',$m)."/".sprintf('%02d',$d)." ".sprintf('%02d',$h),
                                    'count_num'=>$hourNum,
                                    'update_time'=>time(),
                                    'time_type'=>'h',
                                    'analy_type'=>$analyData['data']['analy_type']
                                ]]);
                            }

                        }else{
                            $data = array_merge($data,[[
                                'analy_uuid'=>$analyUuid,
                                'time_periods'=>$y."/".sprintf('%02d',$m)."/".sprintf('%02d',$d)." ".sprintf('%02d',$h),
                                'time_type'=>'h',
                                'count_num'=>$hourNum,
                                'create_time'=>time()
                            ]]);
                        }    
                        //analy_type的值有0,1,2,3,4 ---其中0是计算到分钟,1是计算到小时;2是计算到天,3是计算到月份,4计算到年
                        if($analyData['data']['analy_type'] > 0){
                            continue;
                        }
                        //分钟数据开始
                        $startMinute = ($y == $firstYear && sprintf('%02d',$m) == $firstMonth && sprintf('%02d',$d) == $firstDate && sprintf('%02d',$h) == $firstHour)?$firstMinute:0;//如果是最开始的一年的那个月那一天那一小时,则计算最开始的一天的当天开始算
                        $lastMinuteLength = ($y == $lastYear && sprintf('%02d',$m) == $lastMonth && sprintf('%02d',$d) == $lastDate && sprintf('%02d',$h) == $lastHour)?$lastMinute:59;//如果是最后一年,那么就只计算到最后一天,否则就是当月的当天的当前小时
                        for($minute = $startMinute; $minute<=$lastMinuteLength;$minute++){
                            $minuteNum = 0;//当前小时数据
                            for($j=0; $j<$totalLength; $j++){
                                if(date("Y/m/d H",$dbData[$j][$analyData['data']['table_analy_field']]) == $y."/".sprintf('%02d',$m)."/".sprintf('%02d',$d)." ".sprintf('%02d',$h).":".sprintf('%02d',$minute)){
                                    if($analyData['data']['table_calculate_method'] == 'count'){
                                        $minuteNum +=1;//加1
                                    }
                                    if($analyData['data']['table_calculate_method'] == 'sum'){
                                        $minuteNum += $dbData[$j][$analyData['data']['table_calculate_field']];//按照字段的值进行加
                                    }
                                }
                            }
                            //等于当前年当前月当前日当前小时的时候,需要写到更新数据中
                            if($statisticData['data']['year'] == $y && $statisticData['data']['month'] == sprintf('%02d',$m) && $statisticData['data']['date'] == sprintf('%02d',$d) && $statisticData['data']['hour'] == sprintf('%02d',$h) && $statisticData['data']['minute'] == sprintf('%02d',$minute)){
                             //【分析类型-分析包含的数据】0 :按照年,月,日,时,分;1:按照年,月,日,时;2:按照年,月,日;3:按照年,月;4:按照年
                                
                                if($analyData['data']['analy_type'] == 0){
                                    //更新的数据需要重新查询  === 等于当前年月时 只需要更新即可
                                    $updateData = array_merge($updateData,[[
                                        'analy_uuid'=>$analyUuid,
                                        'time_periods'=>$y."/".sprintf('%02d',$m)."/".sprintf('%02d',$d)." ".sprintf('%02d',$h).":".sprintf('%02d',$minute),
                                        'count_num'=>$minuteNum,
                                        'time_type'=>'i',
                                        'update_time'=>time()
                                    ]]);
                                }else{
                                    //这里应该没有作用  因为我的任务只计算到分钟 没有秒钟  但是保留代码
                                    //这个年份需要重新计算-- 正年的数据--- 包含历史数据和现在的数据 
                                    //count_num == 按照分析任务的类型; 比如 年月 那么计算当前年的所有的月的总数据sum ; 年月日 则就算当前年的所有的日的总数据sum 其他的类比
                                    // $backData = array_merge($backData,[[
                                    //     'analy_uuid'=>$analyUuid,
                                    //     'time_periods'=>$y."/".sprintf('%02d',$m)."/".sprintf('%02d',$d)." ".sprintf('%02d',$h).":".sprintf('%02d',$minute),
                                    //     'count_num'=>0,
                                    //     'update_time'=>time(),
                                    //     'time_type'=>'i',
                                    //     'analy_type'=>$analyData['data']['analy_type']
                                    // ]]);
                                }
                            }else{
                                $data = array_merge($data,[[
                                    'analy_uuid'=>$analyUuid,
                                    'time_periods'=>$y."/".sprintf('%02d',$m)."/".sprintf('%02d',$d)." ".sprintf('%02d',$h).":".sprintf('%02d',$minute),
                                    'time_type'=>'i',
                                    'count_num'=>$minuteNum,
                                    'create_time'=>time()
                                ]]);
                            }
                            
                        }//分钟-end      
                    }//小时-end
                }//天-end
            }//月-end
        }//年-end
      
        return $this->saveStatistic($data,$updateData,$backData,$analyUuid);

    }

    /**
     * 写入统计数据
     * @param $data 批量写入的数据
     * @param $updateData 批量要更新的数据 没有主键id
     * @param $backData 需要重新计算的数组
     * @param $analy_type 分析任务的类型
     */
    public function saveStatistic($data=[],$updateData=[],$backData = [],$analy_uuid=''){
        Db::startTrans();
        try {
            // dump($data);die;
            if(!empty($data)){
                // 分批写入 每次最多100条数据
                $list = Db::name('table_statistic')->limit(100)->insertAll($data);
            }
            
            //更新这一块数据 -- 只更新最后一条数据
            if(!empty($updateData)){
                for($i=0; $i<count($updateData); $i++){
                    Db::name('table_statistic') ->where([['analy_uuid','eq',$updateData[$i]['analy_uuid']],['time_periods','eq',$updateData[$i]['time_periods']]]) ->update($updateData[$i]);
                }
            }  
            $wheres = [];
            if(!empty($backData)){
                $wheres = $this->createBackDataWhere($backData);
                for($i=0; $i<count($backData); $i++){
                    $updateBackData = [
                        'analy_uuid'=>$backData[$i]['analy_uuid'],
                        'time_periods'=>$backData[$i]['time_periods'],
                        'time_type'=>$backData[$i]['time_type'],
                        'count_num'=>Db::name('table_statistic')->where($wheres[$i])->sum('count_num'),
                        'update_time'=>time()
                    ];
                    Db::name('table_statistic')
                        ->where([['analy_uuid','eq',$backData[$i]['analy_uuid']],['time_periods','eq',$backData[$i]['time_periods']]])
                        ->update($updateBackData);
                }
            }
            // 提交事务
            Db::commit();
            return app('api_result')->echoJson(0,['uuid'=>$analy_uuid,'msg'=>'任务成功']);
        } catch (\Exception $e) {
            // 回滚事务
            Db::rollback();
            return app('api_result')->echoJson(3,['uuid'=>$analy_uuid,'msg'=>'任务失败!']);
        }
       
    }

    /**
     * 返回 构造的查询条件
     */
    public function createBackDataWhere($backData){
        $wheres = [];
        for($i=0; $i<count($backData); $i++){
            $wheres[$i] = [];
            if(isset($backData[$i]['analy_type']) && isset($backData[$i]['time_type'])){
               //【分析类型-分析包含的数据】0 :按照年,月,日,时,分;1:按照年,月,日,时;2:按照年,月,日;3:按照年,月;4:按照年
               switch ($backData[$i]['time_type']) {
                    case 'y':
                        switch ($backData[$i]['analy_type']) {
                            case 0:
                                $y = substr($backData[$i]['time_periods'],0,4);
                                for($m = 1; $m <= 12; $m++){
                                    $dateLength = cal_days_in_month(CAL_GREGORIAN, $m, $y);//计算当前月份中的天数
                                    for($d = 1; $d<= $dateLength; $d++){
                                        for($h = 0; $h< 24; $h++){
                                            for($minute = 0; $minute<60; $minute++){
                                                $wheres[$i] = array_merge($wheres[$i],[$y."/".sprintf('%02d',$m)."/".sprintf('%02d',$d)." ".sprintf('%02d',$h).":".sprintf('%02d',$minute)]);
                                            }
                                        }
                                    }
                                }
                                break;
                            case 1:
                                $y = substr($backData[$i]['time_periods'],0,4);
                                for($m = 1; $m <= 12; $m++){
                                    $dateLength = cal_days_in_month(CAL_GREGORIAN, $m, $y);//计算当前月份中的天数
                                    for($d = 1; $d<= $dateLength; $d++){
                                        for($h = 0; $h< 24; $h++){
                                            $$wheres[$i] = array_merge($wheres[$i],[$y."/".sprintf('%02d',$m)."/".sprintf('%02d',$d)." ".sprintf('%02d',$h)]);
                                        }
                                    }
                                }
                                break;
                            case 2:
                                $y = substr($backData[$i]['time_periods'],0,4);
                                for($m = 1; $m <= 12; $m++){
                                    $dateLength = cal_days_in_month(CAL_GREGORIAN, $m, $y);//计算当前月份中的天数
                                    for($d = 1; $d<= $dateLength; $d++){
                                        $wheres[$i] = array_merge($wheres[$i],[$y."/".sprintf('%02d',$m)."/".sprintf('%02d',$d)]);
                                    }
                                }
                                break;
                            case 3:
                                $y = substr($backData[$i]['time_periods'],0,4);
                                for($m = 1; $m <= 12; $m++){
                                    $wheres[$i] = array_merge($wheres[$i],$y."/".sprintf('%02d',$m));
                                }
                                break;
                            case 4:
                                //年分析任务的话 此时不需要重算了 在上面的更新数据中,即statistic中的最后一条数据是使用更新 不需要重新计算
                                break;
                            default:
                                break;
                        }//end-switch
                        break;
                    case 'm':
                        switch ($backData[$i]['analy_type']) {
                            case 0:
                                $y = substr($backData[$i]['time_periods'],0,4);
                                $m = substr($backData[$i]['time_periods'],5,2);
                                $dateLength = cal_days_in_month(CAL_GREGORIAN, $m, $y);//计算当前月份中的天数
                                for($d = 1; $d<= $dateLength; $d++){
                                    for($h = 0; $h< 24; $h++){
                                        for($minute = 0; $minute<60; $minute++){
                                            $wheres[$i] = array_merge($wheres[$i],[$y."/".sprintf('%02d',$m)."/".sprintf('%02d',$d)." ".sprintf('%02d',$h).":".sprintf('%02d',$minute)]);
                                        }
                                    }
                                }
                                break;
                            case 1:
                                $y = substr($backData[$i]['time_periods'],0,4);
                                $m = substr($backData[$i]['time_periods'],5,2);
                                $dateLength = cal_days_in_month(CAL_GREGORIAN, $m, $y);//计算当前月份中的天数
                                for($d = 1; $d<= $dateLength; $d++){
                                    for($h = 0; $h< 24; $h++){
                                        $wheres[$i] = array_merge($wheres[$i],[$y."/".sprintf('%02d',$m)."/".sprintf('%02d',$d)." ".sprintf('%02d',$h)]);
                                    }
                                }
                                break;
                            case 2:
                                $y = substr($backData[$i]['time_periods'],0,4);
                                $m = substr($backData[$i]['time_periods'],5,2);
                                $dateLength = cal_days_in_month(CAL_GREGORIAN, $m, $y);//计算当前月份中的天数
                                for($d = 1; $d<= $dateLength; $d++){
                                    $wheres[$i] = array_merge($wheres[$i],[$y."/".sprintf('%02d',$m)."/".sprintf('%02d',$d)]);
                                }
                                break;
                            case 3:
                                //月分析任务的话 此时不需要重算了 在上面的更新数据中,即statistic中的最后一条数据是使用更新 不需要重新计算
                                break;
                            case 4:
                                //年分析任务的话 此时不需要重算了 在上面的更新数据中,即statistic中的最后一条数据是使用更新 不需要重新计算
                                break;
                            default:
                                break;
                        }//end-switch  
                    break;
                    case "d":
                        switch ($backData[$i]['analy_type']) {
                            case 0:
                                $y = substr($backData[$i]['time_periods'],0,4);
                                $m = substr($backData[$i]['time_periods'],5,2);
                                $d = substr($backData[$i]['time_periods'],8,2);
                                for($h = 0; $h< 24; $h++){
                                    for($minute = 0; $minute<60; $minute++){
                                        $wheres[$i] = array_merge($wheres[$i],[$y."/".sprintf('%02d',$m)."/".sprintf('%02d',$d)." ".sprintf('%02d',$h).":".sprintf('%02d',$minute)]);
                                    }
                                }
                                break;
                            case 1:
                                $y = substr($backData[$i]['time_periods'],0,4);
                                $m = substr($backData[$i]['time_periods'],5,2);
                                $d = substr($backData[$i]['time_periods'],8,2);
                                for($h = 0; $h< 24; $h++){
                                    $wheres[$i] = array_merge($wheres[$i],[$y."/".sprintf('%02d',$m)."/".sprintf('%02d',$d)." ".sprintf('%02d',$h)]);
                                }
                                break;
                            case 2:
                               //日分析任务的话 此时不需要重算了 在上面的更新数据中,即statistic中的最后一条数据是使用更新 不需要重新计算
                                break;
                            case 3:
                                //月分析任务的话 此时不需要重算了 在上面的更新数据中,即statistic中的最后一条数据是使用更新 不需要重新计算
                                break;
                            case 4:
                                //年分析任务的话 此时不需要重算了 在上面的更新数据中,即statistic中的最后一条数据是使用更新 不需要重新计算
                                break;
                            default:
                                break;
                        }//end-switch 
                        break;
                        case "h":
                            switch ($backData[$i]['analy_type']) {
                                case 0:
                                    $y = substr($backData[$i]['time_periods'],0,4);
                                    $m = substr($backData[$i]['time_periods'],5,2);
                                    $d = substr($backData[$i]['time_periods'],8,2);
                                    $h = substr($backData[$i]['time_periods'],11,2);
                                    for($minute = 0; $minute<60; $minute++){
                                        $wheres[$i] = array_merge($wheres[$i],[$y."/".sprintf('%02d',$m)."/".sprintf('%02d',$d)." ".sprintf('%02d',$h).":".sprintf('%02d',$minute)]);
                                    }
                                    break;
                                case 1:
                                    //时分析任务的话 此时不需要重算了 在上面的更新数据中,即statistic中的最后一条数据是使用更新 不需要重新计算
                                    break;
                                case 2:
                                   //日分析任务的话 此时不需要重算了 在上面的更新数据中,即statistic中的最后一条数据是使用更新 不需要重新计算
                                    break;
                                case 3:
                                    //月分析任务的话 此时不需要重算了 在上面的更新数据中,即statistic中的最后一条数据是使用更新 不需要重新计算
                                    break;
                                case 4:
                                    //年分析任务的话 此时不需要重算了 在上面的更新数据中,即statistic中的最后一条数据是使用更新 不需要重新计算
                                    break;
                                default:
                                    break;
                            }//end-switch 
                            break;
                    default:
                        # code...
                        break;

                }//end-switch 
                $where = [['analy_uuid','eq',$backData[$i]['analy_uuid']]];  
                $wheres[$i] = !empty($wheres[$i])?array($where,[['time_periods','in',$wheres[$i]]]):$where;
            }//end-if
        }//end-for
        return $wheres;
    }

测试图:这里分析了最近12个月的数据,由于只有一个月的数据,其他月份数据为0,所以柱状图比较大 。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值