在连续两日使用《天猫店铺商品列表监控》流程的基础上,可以进一步调用本流程,将本地文件中保存的商品列表划分为今日和以前两张表格,然后以商品ID为键联接(LEFT JOIN)今日和以前两张表格。在得到的结果中,第一个字段a1是今日商品链接,第二个字段a2是商品标题,第三个字段a3是以前商品链接,只要是a1与a3不相等的任意一行,就必然是a3为空值的情况,此时a1的值就是某个上新的商品链接。
流程图如下所示。
Selection_999(306).png

流程配置内容如下所示,用户可复制后导入到流程管理系统。部署后,点击“注入时间戳”节点即可在“调试6”节点得到新品链接和标题信息。

[
    {
        "id": "234da22604e90c17",
        "type": "tab",
        "label": "天猫店铺商品列表上新",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "dbc3b849d274332e",
        "type": "file in",
        "z": "234da22604e90c17",
        "name": "",
        "filename": "data/8323_stdout.log",
        "filenameType": "str",
        "format": "lines",
        "chunk": false,
        "sendError": false,
        "encoding": "none",
        "allProps": false,
        "x": 345,
        "y": 165.45454025268555,
        "wires": [
            [
                "f2ac9d288efdfa67"
            ]
        ]
    },
    {
        "id": "3103c90b0a3ff09d",
        "type": "watch",
        "z": "234da22604e90c17",
        "name": "",
        "files": "data/8323_stdout.log",
        "recursive": "",
        "x": 105,
        "y": 165.45454025268555,
        "wires": [
            [
                "dbc3b849d274332e"
            ]
        ]
    },
    {
        "id": "47492eb008184e25",
        "type": "inject",
        "z": "234da22604e90c17",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 88.6363639831543,
        "y": 62.72726821899414,
        "wires": [
            [
                "dbc3b849d274332e"
            ]
        ]
    },
    {
        "id": "2e9a045f33545d83",
        "type": "switch",
        "z": "234da22604e90c17",
        "name": "按日期分为今天和以前",
        "property": "date",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "今天的日期",
                "vt": "global"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "repair": true,
        "outputs": 2,
        "x": 538.6363639831543,
        "y": 282.72726821899414,
        "wires": [
            [
                "3fecd7ec54686579"
            ],
            [
                "63b17d2c26fc34ad"
            ]
        ]
    },
    {
        "id": "d40591fda74561f5",
        "type": "json",
        "z": "234da22604e90c17",
        "name": "",
        "property": "payload",
        "action": "obj",
        "pretty": false,
        "x": 675,
        "y": 165.45454025268555,
        "wires": [
            [
                "1ede8af1b0e1d139"
            ]
        ]
    },
    {
        "id": "1ede8af1b0e1d139",
        "type": "change",
        "z": "234da22604e90c17",
        "name": "日期和列表",
        "rules": [
            {
                "t": "set",
                "p": "date",
                "pt": "msg",
                "to": "$substring(payload.日期, 0, 10)",
                "tot": "jsonata"
            },
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "$map(payload.数据, function($v, $index){$index > 0 ? $append($v, $substring(payload.日期, 0, 10))})",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 835,
        "y": 165.45454025268555,
        "wires": [
            [
                "a429cb014403e20c",
                "2d77339b60ed51d5"
            ]
        ]
    },
    {
        "id": "1d9ff32a4aafb67d",
        "type": "join",
        "z": "234da22604e90c17",
        "name": "所有日期",
        "mode": "auto",
        "build": "array",
        "property": "date",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": false,
        "timeout": "",
        "count": "",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "num",
        "reduceFixup": "",
        "x": 118.6363639831543,
        "y": 282.72726821899414,
        "wires": [
            [
                "e0b047bfe4106b03"
            ]
        ]
    },
    {
        "id": "e0b047bfe4106b03",
        "type": "change",
        "z": "234da22604e90c17",
        "name": "今天的日期",
        "rules": [
            {
                "t": "set",
                "p": "今天的日期",
                "pt": "global",
                "to": "$sort(payload)[-1]",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 288.6363639831543,
        "y": 282.72726821899414,
        "wires": [
            []
        ]
    },
    {
        "id": "3fecd7ec54686579",
        "type": "join",
        "z": "234da22604e90c17",
        "name": "今天的商品列表",
        "mode": "custom",
        "build": "array",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": false,
        "timeout": "1",
        "count": "",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "num",
        "reduceFixup": "",
        "x": 779.5454711914062,
        "y": 276.36363410949707,
        "wires": [
            [
                "cfd32cfcd7529f11"
            ]
        ]
    },
    {
        "id": "63b17d2c26fc34ad",
        "type": "join",
        "z": "234da22604e90c17",
        "name": "以前的商品列表",
        "mode": "custom",
        "build": "array",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": false,
        "timeout": "1",
        "count": "",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 145,
        "y": 365.45454025268555,
        "wires": [
            [
                "f18a4dc5e7ae9a09"
            ]
        ]
    },
    {
        "id": "f2ac9d288efdfa67",
        "type": "switch",
        "z": "234da22604e90c17",
        "name": "有效记录",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "cont",
                "v": "{",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": true,
        "outputs": 1,
        "x": 545,
        "y": 165.45454025268555,
        "wires": [
            [
                "d40591fda74561f5"
            ]
        ]
    },
    {
        "id": "a429cb014403e20c",
        "type": "change",
        "z": "234da22604e90c17",
        "name": "日期",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "date",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1015,
        "y": 165.45454025268555,
        "wires": [
            [
                "1d9ff32a4aafb67d"
            ]
        ]
    },
    {
        "id": "2d77339b60ed51d5",
        "type": "delay",
        "z": "234da22604e90c17",
        "name": "",
        "pauseType": "delay",
        "timeout": "1",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 270.45454025268555,
        "y": 210.90908432006836,
        "wires": [
            [
                "2e9a045f33545d83"
            ]
        ]
    },
    {
        "id": "d65d395e21265efa",
        "type": "debug",
        "z": "234da22604e90c17",
        "name": "调试 6",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1050,
        "y": 480,
        "wires": []
    },
    {
        "id": "cfd32cfcd7529f11",
        "type": "change",
        "z": "234da22604e90c17",
        "name": "插入表头",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "$append([[\"店内搜索网址\",\"页码\",\"坑位\",\"标题\",\"链接\",\"宝贝ID\",\"价格\",\"店铺\",\"成交\",\"评价\",\"主图\",\"主图2\",\"日期\"]], payload.$)",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 957.7272911071777,
        "y": 276.36363220214844,
        "wires": [
            [
                "44a6fbbb737c2492"
            ]
        ]
    },
    {
        "id": "f18a4dc5e7ae9a09",
        "type": "change",
        "z": "234da22604e90c17",
        "name": "插入表头",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "$append([[\"店内搜索网址\",\"页码\",\"坑位\",\"标题\",\"链接\",\"宝贝ID\",\"价格\",\"店铺\",\"成交\",\"评价\",\"主图\",\"主图2\",\"日期\"]], payload.$)",
                "tot": "jsonata"
            },
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "right",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 325,
        "y": 365.45454025268555,
        "wires": [
            [
                "97d2e2357fa86e92"
            ]
        ]
    },
    {
        "id": "13f3a9c089219abc",
        "type": "dsjrbql",
        "z": "234da22604e90c17",
        "name": "以商品ID联接今日和以前两表",
        "code": "select * left join b on a['宝贝ID'] == b['宝贝ID']",
        "join": true,
        "x": 680,
        "y": 480,
        "wires": [
            [
                "8f9481a03aa2dd55"
            ]
        ]
    },
    {
        "id": "44a6fbbb737c2492",
        "type": "dsjrbql",
        "z": "234da22604e90c17",
        "name": "商品ID和标题两个字段",
        "code": "SELECT a['宝贝ID'], ARRAY_AGG(a['标题'], v => v[0]) GROUP BY a['宝贝ID']",
        "join": false,
        "x": 800,
        "y": 340,
        "wires": [
            [
                "13f3a9c089219abc"
            ]
        ]
    },
    {
        "id": "97d2e2357fa86e92",
        "type": "dsjrbql",
        "z": "234da22604e90c17",
        "name": "商品ID字段",
        "code": "SELECT DISTINCT a['宝贝ID']",
        "join": false,
        "x": 410,
        "y": 480,
        "wires": [
            [
                "13f3a9c089219abc"
            ]
        ]
    },
    {
        "id": "8f9481a03aa2dd55",
        "type": "dsjrbql",
        "z": "234da22604e90c17",
        "name": "找到新品",
        "code": "select * where a1 != a3",
        "join": false,
        "x": 900,
        "y": 480,
        "wires": [
            [
                "d65d395e21265efa"
            ]
        ]
    }
]

此外,一旦部署,本流程还会监控本地文件“data/8323_stdout.log”。一旦用户调用了《天猫店铺商品列表监控》流程,本流程也会随机自动进行调用,无需用户手动注入。上新检测的结果显示在右侧调试区。
Selection_999(307).png

为集成到流程管理系统中,网页流程8323在开头和结尾有如下处理:
一处是在开头读取标准输入,这些内容来自《天猫店铺商品列表监控》的“注入”节点;
Selection_999(308).png

二是在结尾写入标准输出,这些内容将保存到data/8323_stdout.log文件中。一旦数据写入该文件,本文所述的上新检测流程就会自动运行,找到新出现的商品链接。
Selection_999(309).png