如何根据某两个字段值快速整合数据?

我有24条数据,想要快速整合成4条数据,如下图:
image.png

希望大佬们能提供一些思路,不想写那么多 if 条件判断。

这是返回的6周的全部数据的规则:

louceng_category 的不同来显示每一周的 数量(wk_order_qty)、环比(order_qty_chain

期望返回格式如下:

[
  {
    louceng_category: 'A',
    wk1_order_qty:1,
    wk1_order_qty_chain: '-',
    wk2_order_qty: 2,
    wk2_order_qty_chain: '-',
    wk3_order_qty: 3,
    wk3_order_qty_chain: '-',
    wk4_order_qty: 4,
    wk4_order_qty_chain: '-',
    wk5_order_qty: 5,
    wk5_order_qty_chain: '-',
    wk6_order_qty: 6,
    wk6_order_qty_chain: '-',
  }, 
  {
    louceng_category: 'B',
    wk1_order_qty:1,
    wk1_order_qty_chain: '-',
    wk2_order_qty: 2,
    wk2_order_qty_chain: '-',
    wk3_order_qty: 3,
    wk3_order_qty_chain: '-',
    wk4_order_qty: 4,
    wk4_order_qty_chain: '-',
    wk5_order_qty: 5,
    wk5_order_qty_chain: '-',
    wk6_order_qty: 6,
    wk6_order_qty_chain: '-',
  },
  ...
]

以下是后端接口返回的原始数据

{
  "data": [{
    "wk_order_qty": 4.0000,
    "order_area_chain": -2.92220531,
    "hzzs_amt_chain": -98.35281984,
    "wk_sign_qty": 1.0000,
    "sign_area_chain": -95.48641859,
    "wk_order_amt_last": 10225437.0000,
    "w_insert_date": "2023-04-04 13:44:07",
    "period_wid_qz": "04.03-04.04",
    "a.period_wid": "20230404",
    "louceng_category": "其它",
    "order_qty_chain": 0E-8,
    "wk_hzzs_amt": -1082197.4000,
    "level_code": "1",
    "sign_qty_chain": -88.88888889,
    "org_name": "其他公司",
    "wk_order_area_last": 637.1900,
    "wk_sign_area": 237.5200,
    "wk_sign_area_last": 5262.3400,
    "wk_sign_amt": 6101595.0000,
    "wk_order_qty_last": 4.0000,
    "period_wid_tq": "04.03-04.04",
    "wk_order_amt": 11766892.0000,
    "org_id": "A30003353",
    "wk_sign_qty_last": 9.0000,
    "sign_amt_chain": -79.86318864,
    "wk_order_area": 618.5700,
    "wk_hzzs_amt_last": -65700001.9766,
    "order_amt_chain": 15.07471025,
    "week_end_name": "第1周",
    "wk_sign_amt_last": 30300701.0000
  }, {
    "wk_order_qty": 30.0000,
    "order_area_chain": -29.31229233,
    "hzzs_amt_chain": -105.02674606,
    "wk_sign_qty": 34.0000,
    "sign_area_chain": -83.71498426,
    "wk_order_amt_last": 76813089.0000,
    "w_insert_date": "2023-04-04 13:44:07",
    "period_wid_qz": "04.03-04.04",
    "a.period_wid": "20230404",
    "louceng_category": "B",
    "order_qty_chain": -36.17021277,
    "wk_hzzs_amt": 12329254.6393,
    "level_code": "1",
    "sign_qty_chain": -61.36363636,
    "org_name": "其他公司",
    "wk_order_area_last": 5152.4800,
    "wk_sign_area": 4236.2700,
    "wk_sign_area_last": 26013.3000,
    "wk_sign_amt": 47976616.0000,
    "wk_order_qty_last": 47.0000,
    "period_wid_tq": "04.03-04.04",
    "wk_order_amt": 42925648.0000,
    "org_id": "A30003353",
    "wk_sign_qty_last": 88.0000,
    "sign_amt_chain": -61.71137792,
    "wk_order_area": 3642.1700,
    "wk_hzzs_amt_last": -245273074.9019,
    "order_amt_chain": -44.11675333,
    "week_end_name": "第1周",
    "wk_sign_amt_last": 125302540.0000
  }, {
    "wk_order_qty": 20.0000,
    "order_area_chain": -14.82862962,
    "hzzs_amt_chain": -105.33692935,
    "wk_sign_qty": 34.0000,
    "sign_area_chain": -76.50418213,
    "wk_order_amt_last": 46824042.0000,
    "w_insert_date": "2023-04-04 13:44:07",
    "period_wid_qz": "04.03-04.04",
    "a.period_wid": "20230404",
    "louceng_category": "A",
    "order_qty_chain": -28.57142857,
    "wk_hzzs_amt": 8468575.5433,
    "level_code": "1",
    "sign_qty_chain": -54.66666667,
    "org_name": "其他公司",
    "wk_order_area_last": 2911.5300,
    "wk_sign_area": 4357.7200,
    "wk_sign_area_last": 18546.7900,
    "wk_sign_amt": 63306330.0000,
    "wk_order_qty_last": 28.0000,
    "period_wid_tq": "04.03-04.04",
    "wk_order_amt": 32805901.0000,
    "org_id": "A30003353",
    "wk_sign_qty_last": 75.0000,
    "sign_amt_chain": -47.16688068,
    "wk_order_area": 2479.7900,
    "wk_hzzs_amt_last": -158678801.8403,
    "order_amt_chain": -29.93791309,
    "week_end_name": "第1周",
    "wk_sign_amt_last": 119823192.0000
  }, {
    "wk_order_qty": 19.0000,
    "order_area_chain": -50.06862004,
    "hzzs_amt_chain": -102.41089561,
    "wk_sign_qty": 29.0000,
    "sign_area_chain": -78.66580516,
    "wk_order_amt_last": 52947527.0000,
    "w_insert_date": "2023-04-04 13:44:07",
    "period_wid_qz": "04.03-04.04",
    "a.period_wid": "20230404",
    "louceng_category": "C",
    "order_qty_chain": -50.00000000,
    "wk_hzzs_amt": 3632020.2450,
    "level_code": "1",
    "sign_qty_chain": -48.21428571,
    "org_name": "其他公司",
    "wk_order_area_last": 4539.4900,
    "wk_sign_area": 3499.9600,
    "wk_sign_area_last": 16405.4000,
    "wk_sign_amt": 42434921.0000,
    "wk_order_qty_last": 38.0000,
    "period_wid_tq": "04.03-04.04",
    "wk_order_amt": 26901877.0000,
    "org_id": "A30003353",
    "wk_sign_qty_last": 56.0000,
    "sign_amt_chain": -40.04551689,
    "wk_order_area": 2266.6300,
    "wk_hzzs_amt_last": -150650249.2825,
    "order_amt_chain": -49.19143816,
    "week_end_name": "第1周",
    "wk_sign_amt_last": 70778562.0000
  }, {
    "wk_order_qty": 186.0000,
    "order_area_chain": -35.19384299,
    "hzzs_amt_chain": -102.17977294,
    "wk_sign_qty": 304.0000,
    "sign_area_chain": -33.77952587,
    "wk_order_amt_last": 474971398.0000,
    "w_insert_date": "2023-04-03 20:17:53",
    "period_wid_qz": "03.27-04.02",
    "a.period_wid": "20230402",
    "louceng_category": "B",
    "order_qty_chain": -37.37373737,
    "wk_hzzs_amt": 6078390.2359,
    "level_code": "1",
    "sign_qty_chain": 3.75426621,
    "org_name": "其他公司",
    "wk_order_area_last": 33733.2300,
    "wk_sign_area": 36497.5600,
    "wk_sign_area_last": 55115.2200,
    "wk_sign_amt": 505387953.0000,
    "wk_order_qty_last": 297.0000,
    "period_wid_tq": "03.27-03.28",
    "wk_order_amt": 315329908.0000,
    "org_id": "A30003353",
    "wk_sign_qty_last": 293.0000,
    "sign_amt_chain": 7.10664802,
    "wk_order_area": 21861.2100,
    "wk_hzzs_amt_last": -278854284.4021,
    "order_amt_chain": -33.61075860,
    "week_end_name": "第2周",
    "wk_sign_amt_last": 471854887.0000
  }, {
    "wk_order_qty": 21.0000,
    "order_area_chain": 34.68599571,
    "hzzs_amt_chain": -94.44351600,
    "wk_sign_qty": 40.0000,
    "sign_area_chain": -5.51926283,
    "wk_order_amt_last": 53924704.0000,
    "w_insert_date": "2023-04-03 20:17:53",
    "period_wid_qz": "03.27-04.02",
    "a.period_wid": "20230402",
    "louceng_category": "其它",
    "order_qty_chain": 16.66666667,
    "wk_hzzs_amt": -4846458.6915,
    "level_code": "1",
    "sign_qty_chain": 135.29411765,
    "org_name": "其他公司",
    "wk_order_area_last": 2879.2600,
    "wk_sign_area": 7468.5700,
    "wk_sign_area_last": 7904.8600,
    "wk_sign_amt": 133634624.0000,
    "wk_order_qty_last": 18.0000,
    "period_wid_tq": "03.27-03.28",
    "wk_order_amt": 72753727.0000,
    "org_id": "A30003353",
    "wk_sign_qty_last": 17.0000,
    "sign_amt_chain": 125.53286646,
    "wk_order_area": 3877.9600,
    "wk_hzzs_amt_last": -87221679.9633,
    "order_amt_chain": 34.91724869,
    "week_end_name": "第2周",
    "wk_sign_amt_last": 59252838.0000
  }, {
    "wk_order_qty": 167.0000,
    "order_area_chain": -13.13153558,
    "hzzs_amt_chain": -89.25254581,
    "wk_sign_qty": 211.0000,
    "sign_area_chain": -28.36672517,
    "wk_order_amt_last": 301139200.0000,
    "w_insert_date": "2023-04-03 20:17:53",
    "period_wid_qz": "03.27-04.02",
    "a.period_wid": "20230402",
    "louceng_category": "C",
    "order_qty_chain": -12.56544503,
    "wk_hzzs_amt": -19047253.6172,
    "level_code": "1",
    "sign_qty_chain": 8.76288660,
    "org_name": "其他公司",
    "wk_order_area_last": 22295.2600,
    "wk_sign_area": 25515.4000,
    "wk_sign_area_last": 35619.4800,
    "wk_sign_amt": 319617395.0000,
    "wk_order_qty_last": 191.0000,
    "period_wid_tq": "03.27-03.28",
    "wk_order_amt": 257307190.0000,
    "org_id": "A30003353",
    "wk_sign_qty_last": 194.0000,
    "sign_amt_chain": 2.97032372,
    "wk_order_area": 19367.5500,
    "wk_hzzs_amt_last": -177225725.1640,
    "order_amt_chain": -14.55539830,
    "week_end_name": "第2周",
    "wk_sign_amt_last": 310397582.0000
  }, {
    "wk_order_qty": 141.0000,
    "order_area_chain": -36.48906094,
    "hzzs_amt_chain": -92.49532872,
    "wk_sign_qty": 217.0000,
    "sign_area_chain": -37.10325736,
    "wk_order_amt_last": 367412221.0000,
    "w_insert_date": "2023-04-03 20:17:53",
    "period_wid_qz": "03.27-04.02",
    "a.period_wid": "20230402",
    "louceng_category": "A",
    "order_qty_chain": -37.88546256,
    "wk_hzzs_amt": -15617654.2230,
    "level_code": "1",
    "sign_qty_chain": -5.65217391,
    "org_name": "其他公司",
    "wk_order_area_last": 25227.0400,
    "wk_sign_area": 26269.2900,
    "wk_sign_area_last": 41765.7400,
    "wk_sign_amt": 373965738.0000,
    "wk_order_qty_last": 227.0000,
    "period_wid_tq": "03.27-03.28",
    "wk_order_amt": 251413386.0000,
    "org_id": "A30003353",
    "wk_sign_qty_last": 230.0000,
    "sign_amt_chain": -0.33169957,
    "wk_order_area": 16021.9300,
    "wk_hzzs_amt_last": -208105773.5935,
    "order_amt_chain": -31.57184992,
    "week_end_name": "第2周",
    "wk_sign_amt_last": 375210309.0000
  }, {
    "wk_order_qty": 191.0000,
    "order_area_chain": 14.96728150,
    "hzzs_amt_chain": -18.63271706,
    "wk_sign_qty": 194.0000,
    "sign_area_chain": -12.78010495,
    "wk_order_amt_last": 265319387.0000,
    "w_insert_date": "2023-04-03 20:17:18",
    "period_wid_qz": "03.20-03.26",
    "a.period_wid": "20230326",
    "louceng_category": "C",
    "order_qty_chain": 15.06024096,
    "wk_hzzs_amt": -177225725.1640,
    "level_code": "1",
    "sign_qty_chain": -5.36585366,
    "org_name": "其他公司",
    "wk_order_area_last": 19392.7000,
    "wk_sign_area": 35619.4800,
    "wk_sign_area_last": 40838.7100,
    "wk_sign_amt": 310397582.0000,
    "wk_order_qty_last": 166.0000,
    "period_wid_tq": "03.20-03.21",
    "wk_order_amt": 301139200.0000,
    "org_id": "A30003353",
    "wk_sign_qty_last": 205.0000,
    "sign_amt_chain": -10.24896325,
    "wk_order_area": 22295.2600,
    "wk_hzzs_amt_last": -217809565.1789,
    "order_amt_chain": 13.50063914,
    "week_end_name": "第3周",
    "wk_sign_amt_last": 345842893.0000
  }, {
    "wk_order_qty": 297.0000,
    "order_area_chain": 6.09285145,
    "hzzs_amt_chain": -10.28695722,
    "wk_sign_qty": 293.0000,
    "sign_area_chain": -9.22740918,
    "wk_order_amt_last": 491218010.0000,
    "w_insert_date": "2023-04-03 20:17:18",
    "period_wid_qz": "03.20-03.26",
    "a.period_wid": "20230326",
    "louceng_category": "B",
    "order_qty_chain": 8.79120879,
    "wk_hzzs_amt": -278854284.4021,
    "level_code": "1",
    "sign_qty_chain": -5.48387097,
    "org_name": "其他公司",
    "wk_order_area_last": 31795.9500,
    "wk_sign_area": 55115.2200,
    "wk_sign_area_last": 60717.9100,
    "wk_sign_amt": 471854887.0000,
    "wk_order_qty_last": 273.0000,
    "period_wid_tq": "03.20-03.21",
    "wk_order_amt": 474971398.0000,
    "org_id": "A30003353",
    "wk_sign_qty_last": 310.0000,
    "sign_amt_chain": -14.83849705,
    "wk_order_area": 33733.2300,
    "wk_hzzs_amt_last": -310829145.6259,
    "order_amt_chain": -3.30741375,
    "week_end_name": "第3周",
    "wk_sign_amt_last": 554070643.0000
  }, {
    "wk_order_qty": 227.0000,
    "order_area_chain": 11.95175259,
    "hzzs_amt_chain": -10.68783934,
    "wk_sign_qty": 230.0000,
    "sign_area_chain": -8.47704691,
    "wk_order_amt_last": 359967621.0000,
    "w_insert_date": "2023-04-03 20:17:18",
    "period_wid_qz": "03.20-03.26",
    "a.period_wid": "20230326",
    "louceng_category": "A",
    "order_qty_chain": 16.41025641,
    "wk_hzzs_amt": -208105773.5935,
    "level_code": "1",
    "sign_qty_chain": -2.12765957,
    "org_name": "其他公司",
    "wk_order_area_last": 22533.8500,
    "wk_sign_area": 41765.7400,
    "wk_sign_area_last": 45634.1700,
    "wk_sign_amt": 375210309.0000,
    "wk_order_qty_last": 195.0000,
    "period_wid_tq": "03.20-03.21",
    "wk_order_amt": 367412221.0000,
    "org_id": "A30003353",
    "wk_sign_qty_last": 235.0000,
    "sign_amt_chain": -15.46252939,
    "wk_order_area": 25227.0400,
    "wk_hzzs_amt_last": -233009449.1794,
    "order_amt_chain": 2.06813046,
    "week_end_name": "第3周",
    "wk_sign_amt_last": 443839053.0000
  }, {
    "wk_order_qty": 18.0000,
    "order_area_chain": -48.86061291,
    "hzzs_amt_chain": -17.73367284,
    "wk_sign_qty": 17.0000,
    "sign_area_chain": -29.05642022,
    "wk_order_amt_last": 91095830.0000,
    "w_insert_date": "2023-04-03 20:17:18",
    "period_wid_qz": "03.20-03.26",
    "a.period_wid": "20230326",
    "louceng_category": "其它",
    "order_qty_chain": -37.93103448,
    "wk_hzzs_amt": -87221679.9633,
    "level_code": "1",
    "sign_qty_chain": -46.87500000,
    "org_name": "其他公司",
    "wk_order_area_last": 5630.2200,
    "wk_sign_area": 7904.8600,
    "wk_sign_area_last": 11142.4600,
    "wk_sign_amt": 59252838.0000,
    "wk_order_qty_last": 29.0000,
    "period_wid_tq": "03.20-03.21",
    "wk_order_amt": 53924704.0000,
    "org_id": "A30003353",
    "wk_sign_qty_last": 32.0000,
    "sign_amt_chain": -40.69181738,
    "wk_order_area": 2879.2600,
    "wk_hzzs_amt_last": -106023549.3311,
    "order_amt_chain": -40.80442101,
    "week_end_name": "第3周",
    "wk_sign_amt_last": 99906683.0000
  }, {
    "wk_order_qty": 195.0000,
    "order_area_chain": -38.79937446,
    "hzzs_amt_chain": -28.27610214,
    "wk_sign_qty": 235.0000,
    "sign_area_chain": -18.88399338,
    "wk_order_amt_last": 616756508.0000,
    "w_insert_date": "2023-04-03 20:16:44",
    "period_wid_qz": "03.13-03.19",
    "a.period_wid": "20230319",
    "louceng_category": "A",
    "order_qty_chain": -39.44099379,
    "wk_hzzs_amt": -233009449.1794,
    "level_code": "1",
    "sign_qty_chain": -16.07142857,
    "org_name": "其他公司",
    "wk_order_area_last": 36819.6400,
    "wk_sign_area": 45634.1700,
    "wk_sign_area_last": 56257.9100,
    "wk_sign_amt": 443839053.0000,
    "wk_order_qty_last": 322.0000,
    "period_wid_tq": "03.13-03.14",
    "wk_order_amt": 359967621.0000,
    "org_id": "A30003353",
    "wk_sign_qty_last": 280.0000,
    "sign_amt_chain": -12.70424188,
    "wk_order_area": 22533.8500,
    "wk_hzzs_amt_last": -324870030.9747,
    "order_amt_chain": -41.63537533,
    "week_end_name": "第4周",
    "wk_sign_amt_last": 508431409.0000
  }, {
    "wk_order_qty": 273.0000,
    "order_area_chain": -27.99415999,
    "hzzs_amt_chain": -20.31630771,
    "wk_sign_qty": 310.0000,
    "sign_area_chain": -8.18716793,
    "wk_order_amt_last": 704871631.0000,
    "w_insert_date": "2023-04-03 20:16:44",
    "period_wid_qz": "03.13-03.19",
    "a.period_wid": "20230319",
    "louceng_category": "B",
    "order_qty_chain": -29.27461140,
    "wk_hzzs_amt": -310829145.6259,
    "level_code": "1",
    "sign_qty_chain": -1.58730159,
    "org_name": "其他公司",
    "wk_order_area_last": 44157.4600,
    "wk_sign_area": 60717.9100,
    "wk_sign_area_last": 66132.2700,
    "wk_sign_amt": 554070643.0000,
    "wk_order_qty_last": 386.0000,
    "period_wid_tq": "03.13-03.14",
    "wk_order_amt": 491218010.0000,
    "org_id": "A30003353",
    "wk_sign_qty_last": 315.0000,
    "sign_amt_chain": -5.55243945,
    "wk_order_area": 31795.9500,
    "wk_hzzs_amt_last": -390078743.4410,
    "order_amt_chain": -30.31099729,
    "week_end_name": "第4周",
    "wk_sign_amt_last": 586643678.0000
  }, {
    "wk_order_qty": 29.0000,
    "order_area_chain": -26.05398505,
    "hzzs_amt_chain": -15.25719742,
    "wk_sign_qty": 32.0000,
    "sign_area_chain": 8.59250741,
    "wk_order_amt_last": 147469366.0000,
    "w_insert_date": "2023-04-03 20:16:44",
    "period_wid_qz": "03.13-03.19",
    "a.period_wid": "20230319",
    "louceng_category": "其它",
    "order_qty_chain": -36.95652174,
    "wk_hzzs_amt": -106023549.3311,
    "level_code": "1",
    "sign_qty_chain": 14.28571429,
    "org_name": "其他公司",
    "wk_order_area_last": 7613.9600,
    "wk_sign_area": 11142.4600,
    "wk_sign_area_last": 10260.8000,
    "wk_sign_amt": 99906683.0000,
    "wk_order_qty_last": 46.0000,
    "period_wid_tq": "03.13-03.14",
    "wk_order_amt": 91095830.0000,
    "org_id": "A30003353",
    "wk_sign_qty_last": 28.0000,
    "sign_amt_chain": 24.62981464,
    "wk_order_area": 5630.2200,
    "wk_hzzs_amt_last": -125112158.3276,
    "order_amt_chain": -38.22728579,
    "week_end_name": "第4周",
    "wk_sign_amt_last": 80162747.0000
  }, {
    "wk_order_qty": 166.0000,
    "order_area_chain": -40.49225295,
    "hzzs_amt_chain": -29.03861283,
    "wk_sign_qty": 205.0000,
    "sign_area_chain": -16.58605174,
    "wk_order_amt_last": 505838179.0000,
    "w_insert_date": "2023-04-03 20:16:44",
    "period_wid_qz": "03.13-03.19",
    "a.period_wid": "20230319",
    "louceng_category": "C",
    "order_qty_chain": -41.13475177,
    "wk_hzzs_amt": -217809565.1789,
    "level_code": "1",
    "sign_qty_chain": -16.32653061,
    "org_name": "其他公司",
    "wk_order_area_last": 32588.5300,
    "wk_sign_area": 40838.7100,
    "wk_sign_area_last": 48959.0900,
    "wk_sign_amt": 345842893.0000,
    "wk_order_qty_last": 282.0000,
    "period_wid_tq": "03.13-03.14",
    "wk_order_amt": 265319387.0000,
    "org_id": "A30003353",
    "wk_sign_qty_last": 245.0000,
    "sign_amt_chain": -19.54801114,
    "wk_order_area": 19392.7000,
    "wk_hzzs_amt_last": -306940963.0659,
    "order_amt_chain": -47.54856434,
    "week_end_name": "第4周",
    "wk_sign_amt_last": 429874883.0000
  }, {
    "wk_order_qty": 386.0000,
    "order_area_chain": -2.39217041,
    "hzzs_amt_chain": 38.83265062,
    "wk_sign_qty": 315.0000,
    "sign_area_chain": -9.77108866,
    "wk_order_amt_last": 672424844.0000,
    "w_insert_date": "2023-04-03 20:16:06",
    "period_wid_qz": "03.06-03.12",
    "a.period_wid": "20230312",
    "louceng_category": "B",
    "order_qty_chain": -1.02564103,
    "wk_hzzs_amt": -390078743.4410,
    "level_code": "1",
    "sign_qty_chain": -28.57142857,
    "org_name": "其他公司",
    "wk_order_area_last": 45239.6700,
    "wk_sign_area": 66132.2700,
    "wk_sign_area_last": 73293.8800,
    "wk_sign_amt": 586643678.0000,
    "wk_order_qty_last": 390.0000,
    "period_wid_tq": "03.06-03.07",
    "wk_order_amt": 704871631.0000,
    "org_id": "A30003353",
    "wk_sign_qty_last": 441.0000,
    "sign_amt_chain": -22.27452510,
    "wk_order_area": 44157.4600,
    "wk_hzzs_amt_last": -280970464.5762,
    "order_amt_chain": 4.82534030,
    "week_end_name": "第5周",
    "wk_sign_amt_last": 754763710.0000
  }, {
    "wk_order_qty": 322.0000,
    "order_area_chain": 5.14844009,
    "hzzs_amt_chain": 33.88048915,
    "wk_sign_qty": 280.0000,
    "sign_area_chain": 8.55038750,
    "wk_order_amt_last": 552491437.0000,
    "w_insert_date": "2023-04-03 20:16:06",
    "period_wid_qz": "03.06-03.12",
    "a.period_wid": "20230312",
    "louceng_category": "A",
    "order_qty_chain": 5.57377049,
    "wk_hzzs_amt": -324870030.9747,
    "level_code": "1",
    "sign_qty_chain": 0.71942446,
    "org_name": "其他公司",
    "wk_order_area_last": 35016.8200,
    "wk_sign_area": 56257.9100,
    "wk_sign_area_last": 51826.5400,
    "wk_sign_amt": 508431409.0000,
    "wk_order_qty_last": 305.0000,
    "period_wid_tq": "03.06-03.07",
    "wk_order_amt": 616756508.0000,
    "org_id": "A30003353",
    "wk_sign_qty_last": 278.0000,
    "sign_amt_chain": -2.00134582,
    "wk_order_area": 36819.6400,
    "wk_hzzs_amt_last": -242656740.3743,
    "order_amt_chain": 11.63186734,
    "week_end_name": "第5周",
    "wk_sign_amt_last": 518814685.0000
  }, {
    "wk_order_qty": 282.0000,
    "order_area_chain": 13.60921270,
    "hzzs_amt_chain": 32.03647984,
    "wk_sign_qty": 245.0000,
    "sign_area_chain": 0.59623279,
    "wk_order_amt_last": 411465393.0000,
    "w_insert_date": "2023-04-03 20:16:06",
    "period_wid_qz": "03.06-03.12",
    "a.period_wid": "20230312",
    "louceng_category": "C",
    "order_qty_chain": 13.25301205,
    "wk_hzzs_amt": -306940963.0659,
    "level_code": "1",
    "sign_qty_chain": -8.92193309,
    "org_name": "其他公司",
    "wk_order_area_last": 28684.7600,
    "wk_sign_area": 48959.0900,
    "wk_sign_area_last": 48668.9100,
    "wk_sign_amt": 429874883.0000,
    "wk_order_qty_last": 249.0000,
    "period_wid_tq": "03.06-03.07",
    "wk_order_amt": 505838179.0000,
    "org_id": "A30003353",
    "wk_sign_qty_last": 269.0000,
    "sign_amt_chain": -6.04396400,
    "wk_order_area": 32588.5300,
    "wk_hzzs_amt_last": -232466787.5393,
    "order_amt_chain": 22.93577725,
    "week_end_name": "第5周",
    "wk_sign_amt_last": 457527692.0000
  }, {
    "wk_order_qty": 46.0000,
    "order_area_chain": 19.19851338,
    "hzzs_amt_chain": 89.75931755,
    "wk_sign_qty": 28.0000,
    "sign_area_chain": 11.18274700,
    "wk_order_amt_last": 119089359.0000,
    "w_insert_date": "2023-04-03 20:16:06",
    "period_wid_qz": "03.06-03.12",
    "a.period_wid": "20230312",
    "louceng_category": "其它",
    "order_qty_chain": 15.00000000,
    "wk_hzzs_amt": -125112158.3276,
    "level_code": "1",
    "sign_qty_chain": -26.31578947,
    "org_name": "其他公司",
    "wk_order_area_last": 6387.6300,
    "wk_sign_area": 10260.8000,
    "wk_sign_area_last": 9228.7700,
    "wk_sign_amt": 80162747.0000,
    "wk_order_qty_last": 40.0000,
    "period_wid_tq": "03.06-03.07",
    "wk_order_amt": 147469366.0000,
    "org_id": "A30003353",
    "wk_sign_qty_last": 38.0000,
    "sign_amt_chain": -20.80482480,
    "wk_order_area": 7613.9600,
    "wk_hzzs_amt_last": -65932023.7550,
    "order_amt_chain": 23.83085041,
    "week_end_name": "第5周",
    "wk_sign_amt_last": 101221756.0000
  }, {
    "wk_order_qty": 40.0000,
    "order_area_chain": -3.98223238,
    "hzzs_amt_chain": 21.21458346,
    "wk_sign_qty": 38.0000,
    "sign_area_chain": -16.96288385,
    "wk_order_amt_last": 123068493.0000,
    "w_insert_date": "2023-04-03 20:14:48",
    "period_wid_qz": "02.27-03.05",
    "a.period_wid": "20230305",
    "louceng_category": "其它",
    "order_qty_chain": 2.56410256,
    "wk_hzzs_amt": -65932023.7550,
    "level_code": "1",
    "sign_qty_chain": -19.14893617,
    "org_name": "其他公司",
    "wk_order_area_last": 6652.5500,
    "wk_sign_area": 9228.7700,
    "wk_sign_area_last": 11114.0300,
    "wk_sign_amt": 101221756.0000,
    "wk_order_qty_last": 39.0000,
    "period_wid_tq": "02.27-02.28",
    "wk_order_amt": 119089359.0000,
    "org_id": "A30003353",
    "wk_sign_qty_last": 47.0000,
    "sign_amt_chain": -31.60010058,
    "wk_order_area": 6387.6300,
    "wk_hzzs_amt_last": -54392814.6861,
    "order_amt_chain": -3.23326784,
    "week_end_name": "第6周",
    "wk_sign_amt_last": 147985241.0000
  }, {
    "wk_order_qty": 390.0000,
    "order_area_chain": -7.25828142,
    "hzzs_amt_chain": -24.92403573,
    "wk_sign_qty": 441.0000,
    "sign_area_chain": -8.91404546,
    "wk_order_amt_last": 725995299.0000,
    "w_insert_date": "2023-04-03 20:14:48",
    "period_wid_qz": "02.27-03.05",
    "a.period_wid": "20230305",
    "louceng_category": "B",
    "order_qty_chain": -9.09090909,
    "wk_hzzs_amt": -280970464.5762,
    "level_code": "1",
    "sign_qty_chain": -3.28947368,
    "org_name": "其他公司",
    "wk_order_area_last": 48780.2800,
    "wk_sign_area": 73293.8800,
    "wk_sign_area_last": 80466.7200,
    "wk_sign_amt": 754763710.0000,
    "wk_order_qty_last": 429.0000,
    "period_wid_tq": "02.27-02.28",
    "wk_order_amt": 672424844.0000,
    "org_id": "A30003353",
    "wk_sign_qty_last": 456.0000,
    "sign_amt_chain": -3.76484102,
    "wk_order_area": 45239.6700,
    "wk_hzzs_amt_last": -374248226.2001,
    "order_amt_chain": -7.37889833,
    "week_end_name": "第6周",
    "wk_sign_amt_last": 784291020.0000
  }, {
    "wk_order_qty": 305.0000,
    "order_area_chain": -0.23607053,
    "hzzs_amt_chain": 17.87260662,
    "wk_sign_qty": 278.0000,
    "sign_area_chain": -14.74692144,
    "wk_order_amt_last": 533692653.0000,
    "w_insert_date": "2023-04-03 20:14:48",
    "period_wid_qz": "02.27-03.05",
    "a.period_wid": "20230305",
    "louceng_category": "A",
    "order_qty_chain": -3.48101266,
    "wk_hzzs_amt": -242656740.3743,
    "level_code": "1",
    "sign_qty_chain": -29.79797980,
    "org_name": "其他公司",
    "wk_order_area_last": 35099.6800,
    "wk_sign_area": 51826.5400,
    "wk_sign_area_last": 60791.4000,
    "wk_sign_amt": 518814685.0000,
    "wk_order_qty_last": 316.0000,
    "period_wid_tq": "02.27-02.28",
    "wk_order_amt": 552491437.0000,
    "org_id": "A30003353",
    "wk_sign_qty_last": 396.0000,
    "sign_amt_chain": -24.46295398,
    "wk_order_area": 35016.8200,
    "wk_hzzs_amt_last": -205863556.7178,
    "order_amt_chain": 3.52239887,
    "week_end_name": "第6周",
    "wk_sign_amt_last": 686834755.0000
  }, {
    "wk_order_qty": 249.0000,
    "order_area_chain": -8.84414618,
    "hzzs_amt_chain": -19.41335563,
    "wk_sign_qty": 269.0000,
    "sign_area_chain": -7.07372482,
    "wk_order_amt_last": 453062632.0000,
    "w_insert_date": "2023-04-03 20:14:48",
    "period_wid_qz": "02.27-03.05",
    "a.period_wid": "20230305",
    "louceng_category": "C",
    "order_qty_chain": -8.79120879,
    "wk_hzzs_amt": -232466787.5393,
    "level_code": "1",
    "sign_qty_chain": -5.94405594,
    "org_name": "其他公司",
    "wk_order_area_last": 31467.8200,
    "wk_sign_area": 48668.9100,
    "wk_sign_area_last": 52373.6800,
    "wk_sign_amt": 457527692.0000,
    "wk_order_qty_last": 273.0000,
    "period_wid_tq": "02.27-02.28",
    "wk_order_amt": 411465393.0000,
    "org_id": "A30003353",
    "wk_sign_qty_last": 286.0000,
    "sign_amt_chain": -3.41382072,
    "wk_order_area": 28684.7600,
    "wk_hzzs_amt_last": -288468131.8534,
    "order_amt_chain": -9.18134405,
    "week_end_name": "第6周",
    "wk_sign_amt_last": 473698924.0000
  }],
  "errorCode": 200,
  "errorMessage": "正常",
  "pageNo": 1,
  "pageSize": 10000,
  "success": true,
  "totalCount": 24
}
阅读 1.7k
3 个回答

没有用 reduce,单纯的使用 Map 数据结构做了一下分类,其实用数组也可以,但是 Map 比较方便,以下是面向过程的业务代码:

先做一下排序,也不知道你的周次数据是否后端返回前有没有做过排序,所以一并排序了,也可以在最后一步排序,但其实差不太多。

// 排序数据
const sortData = data.sort((a, b) => {
  // 按照 louceng_category 排序数据,如果 louceng_category 相同,按照 week_end_name 排序
  if (a.louceng_category === b.louceng_category) {
    return a.week_end_name > b.week_end_name ? 1 : -1
  } else {
    return a.louceng_category > b.louceng_category ? 1 : -1
  }
})

然后是数据分类:

// 临时存储数据的 map
const tmpMap = new Map()

// 按 louceng_category 分类分类数据
sortData.forEach(item => {
  // 获取分类数据
  const d = tmpMap.get(item.louceng_category)
  if (d) {
    // 分类是否已经存在则直接插入需求数据,排除了无用数据,如果有需要自行添加即可
    d.weekData.push({
      weekName: item.week_end_name,
      orderQty: item.wk_order_qty,
      orderQtyChain: item.order_qty_chain
    })
  } else {
    // 分类不存在则插入倒新Map数据中
    tmpMap.set(item.louceng_category, {
      category: item.louceng_category,
      weekData: [{
        weekName: item.week_end_name,
        orderQty: item.wk_order_qty,
        orderQtyChain: item.order_qty_chain
      }]
    })
  }
})

const categoryData = [...tmpMap.values()]

获得到的数据结果为:

[
  {
    category: "A",
    weekData: [
      { weekName: '第1周', orderQty: 30, orderQtyChain: -36.17021277 },
      { weekName: '第2周', orderQty: 186, orderQtyChain: -37.37373737 },
      { weekName: '第3周', orderQty: 297, orderQtyChain: 8.79120879 },
      { weekName: '第4周', orderQty: 273, orderQtyChain: -29.2746114 },
      { weekName: '第5周', orderQty: 386, orderQtyChain: -1.02564103 },
      { weekName: '第6周', orderQty: 390, orderQtyChain: -9.09090909 }
    ]
  },{
    category: "B",
    weekData: [
      { weekName: '第1周', orderQty: 20, orderQtyChain: -28.57142857 },
      { weekName: '第2周', orderQty: 141, orderQtyChain: -37.88546256 },
      { weekName: '第3周', orderQty: 227, orderQtyChain: 16.41025641 },
      { weekName: '第4周', orderQty: 195, orderQtyChain: -39.44099379 },
      { weekName: '第5周', orderQty: 322, orderQtyChain: 5.57377049 },
      { weekName: '第6周', orderQty: 305, orderQtyChain: -3.48101266 }
    ]
  },{
    category: "C",
    weekData: [
      { weekName: '第1周', orderQty: 19, orderQtyChain: -50 },
      { weekName: '第2周', orderQty: 167, orderQtyChain: -12.56544503 },
      { weekName: '第3周', orderQty: 191, orderQtyChain: 15.06024096 },
      { weekName: '第4周', orderQty: 166, orderQtyChain: -41.13475177 },
      { weekName: '第5周', orderQty: 282, orderQtyChain: 13.25301205 },
      { weekName: '第6周', orderQty: 249, orderQtyChain: -8.79120879 },
    ]
  },{
    category: "其它",
    weekData:[
      {weekName: '第1周', orderQty: 4, orderQtyChain: 0}, 
      {weekName: '第2周', orderQty: 21, orderQtyChain: 16.66666667}, 
      {weekName: '第3周', orderQty: 18, orderQtyChain: -37.93103448}, 
      {weekName: '第4周', orderQty: 29, orderQtyChain: -36.95652174}, 
      {weekName: '第5周', orderQty: 46, orderQtyChain: 15}, 
      {weekName: '第6周', orderQty: 40, orderQtyChain: 2.56410256}
    ]
  }
]

最后是组装成你需求的 tableData 格式

// 生成需求的 TableData 数据
const tableData = categoryData.map(({ weekData, category }) => {
  // 一类商品的6周数据整合
  const weekDataObj = Object.fromEntries(weekData.map((data,index) => ([
    // 排序过可以用 index,没有排序可以用 data.weekName.slice(1, 2)
    [`wk${index+1}_order_qty`, d.orderQty],
    [`wk${index+1}_order_qty_chain`, d.orderQtyChain]
  ])).flat())
  return {
    category: category,
    ...weekDataObj
  }
})

获得到的最终数据结果为:

[
  {
    category: "A",
    wk1_order_qty: 20,
    wk1_order_qty_chain: -28.57142857,
    wk2_order_qty: 141,
    wk2_order_qty_chain: -37.88546256,
    wk3_order_qty: 227,
    wk3_order_qty_chain: 16.41025641,
    wk4_order_qty: 195,
    wk4_order_qty_chain: -39.44099379,
    wk5_order_qty: 322,
    wk5_order_qty_chain: 5.57377049,
    wk6_order_qty: 305,
    wk6_order_qty_chain: -3.48101266,
  }, {
    category: "B",
    wk1_order_qty: 30,
    wk1_order_qty_chain: -36.17021277,
    wk2_order_qty: 186,
    wk2_order_qty_chain: -37.37373737,
    wk3_order_qty: 297,
    wk3_order_qty_chain: 8.79120879,
    wk4_order_qty: 273,
    wk4_order_qty_chain: -29.2746114,
    wk5_order_qty: 386,
    wk5_order_qty_chain: -1.02564103,
    wk6_order_qty: 390,
    wk6_order_qty_chain: -9.09090909,
  }, {
    category: "C",
    wk1_order_qty: 19,
    wk1_order_qty_chain: -50,
    wk2_order_qty: 167,
    wk2_order_qty_chain: -12.56544503,
    wk3_order_qty: 191,
    wk3_order_qty_chain: 15.06024096,
    wk4_order_qty: 166,
    wk4_order_qty_chain: -41.13475177,
    wk5_order_qty: 282,
    wk5_order_qty_chain: 13.25301205,
    wk6_order_qty: 249,
    wk6_order_qty_chain: -8.79120879,
  },
  {
    category: "其它",
    wk1_order_qty: 4,
    wk1_order_qty_chain: 0,
    wk2_order_qty: 21,
    wk2_order_qty_chain: 16.66666667,
    wk3_order_qty: 18,
    wk3_order_qty_chain: -37.93103448,
    wk4_order_qty: 29,
    wk4_order_qty_chain: -36.95652174,
    wk5_order_qty: 46,
    wk5_order_qty_chain: 15,
    wk6_order_qty: 40,
    wk6_order_qty_chain: 2.56410256,
  },
]

louceng_category分组?

Object.values(data.reduce((res,v) => ( (res[v.louceng_category] ||= []).push(v), res), {}))

看到图搞明白了需要什么东西。如果只看第一层列头,那么需要的行数据大概是这样:

[
  {
    louceng_category: "A",
    第一周: 123,
    第二周: 234,
    ...
  },
  ...
]

由于每周的数组是两个,所以其对应的值不是 123 或者 234 这样的简单值,而是一个包含 wk_order_qty 和 order_area_chain 的对象(或数组),大概是这样

第一周: {
  wk_order_qty: 1234,
  order_area_chain: 324
}

这样的话,按 louceng_category 分组。每组内部每周的数组是一个单一数据,不需要汇总,所以这里只需要把每个元素转换成一个以周为键的键值对,再转换成对象,就是行对象。

function makeTableData(data) {
    return _(data)
        // 先按 louceng_category 分组,这样每组就是按 louceng_category 分类的,也就是一行的数据源
        .groupBy("louceng_category")
        .map((list, louceng_category) => {
            // 这里每周只有一个数据,所以不需要分组,直接映射到列就好
            const row = Object.fromEntries(
                // list 映射一个键值对,键是周,值是两个数据组成的对象
                // 然后面外面把这个键值对转换成对象,就是行对象(还缺少 louceng_category)
                list.map(({ week_end_name, wk_order_qty, order_area_chain }) => [
                    week_end_name,
                    { wk_order_qty, order_area_chain }
                ])
            );

            // 把 louceng_category 补上就是一个完整的行对象了
            return {
                louceng_category,
                ...row
            };
        })
        .value();
}

转出来的结果是这样的(省略了部分数据,应该看得明白)

[
  {
    louceng_category: '其它',
    '第1周': { wk_order_qty: 4, order_area_chain: -2.92220531 },
    '第2周': {}, '第3周': {}, '第4周': {}, '第5周': {}, '第6周': {}
  },
  {
    louceng_category: 'B',
    '第1周': {}, '第2周': {}, '第3周': {}, '第4周': {}, '第5周': {}, '第6周': {}
  },
  {
    louceng_category: 'A',
    '第1周': {}, '第2周': {}, '第3周': {}, '第4周': {}, '第5周': {}, '第6周': {}
  },
  {
    louceng_category: 'C',
    '第1周': {}, '第2周': {}, '第3周': {}, '第4周': {}, '第5周': {}, '第6周': {}
  }
]

现在是每周一列,共 6 列,再通过子对象来裂分。如果想直接做成 12 列,可以在 list.map 那里改成 list.flatMap,一个对象转成两个键值对:

list.flatMap(({ week_end_name, wk_order_qty, order_area_chain }) => [
    [`${week_end_name}_qty`, wk_order_qty],
    [`${week_end_name}_chain`, order_area_chain]
])

结果(其中一个行对象)是这样的

[
  {
    louceng_category: 'C',
    '第1周_qty': 19, '第1周_chain': -50.06862004,
    '第2周_qty': 167, '第2周_chain': -13.13153558,
    '第3周_qty': 191, '第3周_chain': 14.9672815,
    '第4周_qty': 166, '第4周_chain': -40.49225295,
    '第5周_qty': 282, '第5周_chain': 13.6092127,
    '第6周_qty': 249, '第6周_chain': -8.84414618
  },
  ...
]

然后可做表格应该好处理了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题