当前位置:网站首页>Three simple steps to quickly complete order data processing through workflow (ASW)
Three simple steps to quickly complete order data processing through workflow (ASW)
2022-06-24 17:25:00 【Tencent cloud workflow】
How does this article describe workflow ASW Edit and arrange cloud function , Quickly complete the order data processing .
working principle
- Workflow calls function to get order data in a certain period of time , Preprocess the data .
- Give the preprocessed data to Map Iterative task processing : After data processing of each order , Write to different database tables , Or draw a chart to show .
Operation steps
Creating a workflow requires first creating a state machine , By choreographing the different components of the state machine , Change the state machine structure , So as to achieve user-defined function set .
It's a simple three-step process : Create cloud functions → Create workflow → Running state machine
Step 1: Create cloud functions
establish GetOrder function
- Sign in Cloud function console , Click... On the left navigation bar 【 Function service 】.
- Select Guangzhou in the function service area above the main interface , And click 【 newly build 】, Enter the function creation process .
- On the new function page , Fill in the following information in the basic information :
- The name of the function :GetOrder.
- Running environment :Nodejs10.15.
- How it was created : Select the blank function , single click 【 next step 】 Go to function configuration .
- In the function configuration page Cloud Studio In the pane , Delete the original code , Copy the code shown below :
'use strict';
exports.main_handler = async (event, context) => {
console.log("this is get order function");
# You can api Request for real order data , The data in the example is convenient to simulate workflow execution
var orderlist = [
{
"orderId":"202012200001",
"goodsId":"1004",
"goodsName":" a mandarin orange #1004",
"unit":" Pieces of ",
"specific":"5 One kilo a box ",
"linePrice":100,
"salePrice":90,
"costPrice":80,
"number":30,
"isVoucher":1,
"voucherPrice":2,
"voucherId":"3dr55678hj",
"isDiscount":1,
"discountPrice":3,
"carriage": 8,
"receiver":"susu",
"phone":"18633567898",
"address":" Tencent building, Nanshan District, Shenzhen 20 floor ",
"createTime":"2020-12-20 10:00:00",
"payTime":"2020-12-20 11:00:00",
"payMethod":1,
"payOrder":"202012201100003940",
"orderStatus":3,
"deliveryTime":"2020-12-21 11:00:00",
"finishTime":"2020-12-25 11:00:00",
"deliveryOrder":"ZT12345789d786",
"isReturn":1,
"returnId":"2020122600012",
"returnNumber":2,
},
{
"orderId":"202012200001",
"goodsId":"2001",
"goodsName":" pears #2001",
"unit":" Pieces of ",
"specific":"6 One kilo a box ",
"linePrice":150,
"salePrice":120,
"costPrice":90,
"number":20,
"isVoucher":1,
"voucherPrice":3,
"voucherId":"3dr55678hj",
"isDiscount":1,
"discountPrice":5,
"carriage": 0,
"receiver":"susu",
"phone":"18633567898",
"address":" Tencent building, Nanshan District, Shenzhen 20 floor ",
"createTime":"2020-12-20 10:00:00",
"payTime":"2020-12-20 11:00:00",
"payMethod":1,
"payOrder":"202012201100003940",
"orderStatus":3,
"deliveryTime":"2020-12-21 11:00:00",
"finishTime":"2020-12-25 11:00:00",
"deliveryOrder":"ZT12345789d786",
"isReturn":0,
"returnId":"",
"returnNumber":0,
},
{
"orderId":"202012200001",
"goodsId":"3005",
"goodsName":" Banana #3005",
"unit":" Pieces of ",
"specific":"10 One kilo a box ",
"linePrice":180,
"salePrice":150,
"costPrice":98,
"number":6,
"isVoucher":1,
"voucherPrice":8,
"voucherId":"3dr55678hj",
"isDiscount":1,
"discountPrice":20,
"carriage": 0,
"receiver":"susu",
"phone":"18633567898",
"address":" Tencent building, Nanshan District, Shenzhen 20 floor ",
"createTime":"2020-12-20 10:00:00",
"payTime":"2020-12-20 11:00:00",
"payMethod":1,
"payOrder":"202012201100003940",
"orderStatus":3,
"deliveryTime":"2020-12-21 11:00:00",
"finishTime":"2020-12-25 11:00:00",
"deliveryOrder":"ZT12345789d786",
"isReturn":1,
"returnId":"2020122600013",
"returnNumber":3,
}
];
return {"orderList":orderlist};
};- single click 【 preservation 】, The cloud function is created successfully
establish ProcessOrder function
Reference resources 【 establish GetOrder function 】 The way , establish ProcessOrder function , The code is as follows :
'use strict';
exports.main_handler = async (event, context) => {
console.log("this is processOrder function");
var order = event;
# Data processing
var income = order["salePrice"]-order["costPrice"];
var goodsInfo = {"goodsId":order["goodId"],"goodsName":order["goodsName"],"number":order["number"]};
var incomeInfo = {"goodsId":order["goodId"],"goodsName":order["goodsName"],"number":order["number"],"income":income};
return {
"goodsInfo":goodsInfo,
"incomeInfo":incomeInfo,
"salesInfo":salesInfo
};
}establish GoodsSold function
Reference resources 【 establish GetOrder function 】 The way , establish GoodsSold function , The code is as follows :
'use strict';
exports.main_handler = async (event, context) => {
console.log("this is goodsSold function");
// Some write to database or graph display operations
console.log(event);
return "GoodsSold success";
};establish Income function
Reference resources 【 establish GetOrder function 】 The way , establish Income function , The code is as follows :
'use strict';
exports.main_handler = async (event, context) => {
console.log("this is income function");
// Some write to database or graph display operations
console.log(event);
return "Income success";
};establish SalesReturn function
Reference resources 【 establish GetOrder function 】 The way , establish SalesReturn function , The code is as follows :
'use strict';
exports.main_handler = async (event, context) => {
console.log("this is salesReturn function");
// Some write to database or graph display operations
console.log(event);
return "SalesReturn success";
};Step 2: Create workflow
- Sign in Application and choreography service flow console .
- On the state machine page , single click 【 newly build 】, Go to the create workflow page , Choose to use 【 Code creation 】:
- Paste the following directly in the code edit box TCSL Code :
{
"Comment": " The order processing ",
"StartAt": "GetOrder",
"States": {
"GetOrder": {
"Type": "Task",
"Comment": " Pull data ",
"Resource": "qrn:qcs:asw:ap-guangzhou:12345678:sdk:json:qcloud:scf:Invoke/GetOrder",
"Next": "MapProcess"
},
"MapProcess": {
"Type": "Map",
"ItemsPath": "$.orderList",
"MaxConcurrency": 6,
"Iterator": {
"StartAt": "ProcessOrder",
"States": {
"ProcessOrder": {
"Type": "Task",
"Resource": "qrn:qcs:asw:ap-guangzhou:12345678:sdk:json:qcloud:scf:Invoke/ProcessOrder",
"Next": "ParallelDataProcess"
},
"ParallelDataProcess": {
"Type": "Parallel",
"End": true,
"Branches": [
{
"StartAt": "GoodsSold",
"States": {
"GoodsSold": {
"InputPath": "$.goodsInfo",
"Type": "Task",
"Resource": "qrn:qcs:asw:ap-guangzhou:12345678:sdk:json:qcloud:scf:Invoke/GoodsSold",
"End": true
}
}
},
{
"StartAt": "Income",
"States": {
"Income": {
"InputPath": "$.incomeInfo",
"Type": "Task",
"Resource": "qrn:qcs:asw:ap-guangzhou:12345678:sdk:json:qcloud:scf:Invoke/Income",
"End": true
}
}
},
{
"StartAt": "SalesReturn",
"States": {
"SalesReturn": {
"InputPath": "$.salesInfo",
"Type": "Task",
"Resource": "qrn:qcs:asw:ap-guangzhou:12345678:sdk:json:qcloud:scf:Invoke/SalesReturn",
"End": true
}
}
}
]
}
}
},
"End": true
}
}
}- Click in the upper right corner 【 next step 】, Enter the save interface , Enter the name of the state machine , Run role selection 【 New character 】, Type selection 【 Standard state machine 】, Click in the upper right corner 【 complete 】, You can see the created state machine on the state machine list page .
To use an existing role, you need to create a role first , And empower the role with relevant policies , Please refer to Running roles .
Step 3: Running state machine
After the state machine is created , You can view the created state machine on the main page after login .
- Click... Of the state machine you want to run 【 name 】, Enter the state machine .
- You can see the basic information of the state machine in the interface . single click 【 Workflow execution 】 Under the 【 Start execution 】 .
- In the pop-up “ Input ” Window , With JSON Format the input required by the state machine . for example :
{"comment": "invoke workflow"}- single click 【 determine 】, After completing the state execution , You can view the execution results on the details page :
- Slide to the bottom of the page , stay 【 Execution history 】 Under entry , You can view the operation of the child node .
The above steps introduce the basic workflow of an order data processing scenario .
In a real business scenario, every Task Nodes will be involved in configuring some relevant parameter information , For example, do parameter transfer 、 Exception retrial and error capture processing, etc , For more details, please refer to State machine language .
Apply for probation ASW
ASW At present, it is in the public beta stage , The public beta stage is free of charge . Welcome to suggest product improvements , After the feedback is adopted, you can get Tencent Mengxin short goose doll !
immediately Apply for the public test , We're going to be 3 Complete the approval within working days , And inform you through SMS and on-site letters , Thank you for your support .
边栏推荐
- Implement typescript runtime type checking
- Tiktok Kwai, e-commerce enters the same river
- MySQL learning -- table structure of SQL test questions
- Realize business development on behalf of small programs, and 99% restore the function of service category management in the background of official account
- 网站SEO排名越做越差是什么原因造成的?
- Pagoda activities, team members can enjoy a lightweight server 1 core 2g5m 28 yuan for two years
- Cloud native monitoring practice (2) monitoring and collection of components outside the TKE cluster
- 04. Tencent cloud IOT device side learning - network connection and device authentication
- What is the problem that the data is not displayed on the login web page after the configuration of the RTSP video security intelligent monitoring system easynvr is completed
- How to troubleshoot and solve the problem that the ultra-low delay security live broadcast system webrtc client plays no audio in the browser?
猜你喜欢
随机推荐
## Kubernetes集群中流量暴露的几种方案 Kubernetes集群中流量暴露的几种方案
Elastic searchable snapshot function (frozen Tier 3)
Tiktok Kwai, e-commerce enters the same river
zblog判断某个插件是否安装启用的内置函数代码
Kubernetes 1.20.5 helm installation Jenkins
Erc-20 Standard Specification
Five steps to effectively monitor network traffic
跟着Vam一起学习Typescript(第一期)
Ramda 鲜为人知的一面
Zabix5.0-0 - agent2 monitoring MariaDB database (Linux based)
实现TypeScript运行时类型检查
Radiology: contralateral preoperative resting state MRI functional network integration is related to the surgical results of temporal lobe epilepsy
2021-04-02: given a square or rectangular matrix, zigzag printing can be realized.
March 27, 2021: give you a head node of the linked list, and rotate the linked list
test
区块哈希游戏竞猜系统开发(成熟代码)
Sigai intelligent container damage identification products are deployed in Rizhao Port and Yingkou Port
The RTSP video image intelligent analysis platform easynvr cascades to the superior platform through the national standard for playback optimization
集体突破之后,中国公有云的下一步落在哪里?
Using easyjson to improve the efficiency of serialization transmission

