欧美人与禽2O2O性论交,秋霞免费视频,国产美女视频免费观看网址,国产成人亚洲综合网色欲网

實(shí)現(xiàn)特定格式編號(hào)自動(dòng)生成(實(shí)現(xiàn)特定格式編號(hào)自動(dòng)生成的方法)

在生成諸如訂單、合同等單據(jù)的時(shí)候,往往有生成特定格式編號(hào)的需求,下面介紹如何實(shí)現(xiàn)生成“特定前綴 年份 固定長(zhǎng)度序號(hào)”的編號(hào),其他類型可在此基礎(chǔ)上進(jìn)行調(diào)整。

準(zhǔn)備工作:

在白碼低代碼開發(fā)平臺(tái)上創(chuàng)建一個(gè)“編號(hào)表”數(shù)據(jù)表,添加兩個(gè)字段:編號(hào)(字符),序號(hào)(數(shù)字)

實(shí)現(xiàn)特定格式編號(hào)自動(dòng)生成(實(shí)現(xiàn)特定格式編號(hào)自動(dòng)生成的方法)

實(shí)現(xiàn)步驟:

1、創(chuàng)建“生編號(hào)”功能,添加“數(shù)據(jù)-獲取-編號(hào)表”步驟(當(dāng)前最新編號(hào)),點(diǎn)擊步驟的“設(shè)置”按鈕加載數(shù)據(jù)表屬性。

實(shí)現(xiàn)特定格式編號(hào)自動(dòng)生成(實(shí)現(xiàn)特定格式編號(hào)自動(dòng)生成的方法)

2、加“數(shù)據(jù)-新增-編號(hào)表”步驟(新建數(shù)據(jù)),點(diǎn)擊設(shè)置按鈕,將編號(hào)、序號(hào)、日期屬性隱藏,并把日期設(shè)為當(dāng)前時(shí)間。

實(shí)現(xiàn)特定格式編號(hào)自動(dòng)生成(實(shí)現(xiàn)特定格式編號(hào)自動(dòng)生成的方法)實(shí)現(xiàn)特定格式編號(hào)自動(dòng)生成(實(shí)現(xiàn)特定格式編號(hào)自動(dòng)生成的方法)

3、獲取到相關(guān)id:

編號(hào)表id(entity):

實(shí)現(xiàn)特定格式編號(hào)自動(dòng)生成(實(shí)現(xiàn)特定格式編號(hào)自動(dòng)生成的方法)

編號(hào)表的編號(hào)屬性id(field):

實(shí)現(xiàn)特定格式編號(hào)自動(dòng)生成(實(shí)現(xiàn)特定格式編號(hào)自動(dòng)生成的方法)

編號(hào)表的序號(hào)屬性id(field):

實(shí)現(xiàn)特定格式編號(hào)自動(dòng)生成(實(shí)現(xiàn)特定格式編號(hào)自動(dòng)生成的方法)

編號(hào)表的日期屬性id(field):

實(shí)現(xiàn)特定格式編號(hào)自動(dòng)生成(實(shí)現(xiàn)特定格式編號(hào)自動(dòng)生成的方法)

4、添加“編程”步驟,引用前面兩個(gè)步驟的數(shù)據(jù):

實(shí)現(xiàn)特定格式編號(hào)自動(dòng)生成(實(shí)現(xiàn)特定格式編號(hào)自動(dòng)生成的方法)

5、繼續(xù)編寫代碼生成編號(hào),完整代碼如下:

async function runProcess($model = model, $plugin = plugin, $params) {    let index = new Number($params.index || 0);//當(dāng)前最新編號(hào)步驟的序號(hào)屬性,轉(zhuǎn)為數(shù)字,不存在時(shí)設(shè)為0    let date = $params.date;//當(dāng)前最新編號(hào)步驟的日期屬性    let inserted = $params.inserted;//新建數(shù)據(jù)步驟整個(gè)數(shù)據(jù)     let entity = "60936206dec57120cee73e2e";//編號(hào)表id    let codeField = "6093620b6d8eaf20d45ed568";//編號(hào)表的編號(hào)屬性id    let indexField = "6093620f17f01720c753c60c";//編號(hào)表的序號(hào)屬性id    let size = 5;//格式序號(hào)長(zhǎng)度    let max = Array(size   1).join('9');//合法的最大編號(hào)值    //溢出    if (index   "" == max) {        $plugin.data.removeData(entity, inserted);//刪除新增的數(shù)據(jù)        $model.error(-1, "編號(hào)已達(dá)到允許的最大值!");//拋出錯(cuò)誤提示        return;    }    //生成id    let year = date.substr(0, 4);//當(dāng)前系統(tǒng)最新數(shù)據(jù)的年份    let thisYear = new Date().getFullYear()   "";//今年    let isNewId = false;    let id = "";    while (!isNewId) {        id = await createId(index);        //查詢此工程編號(hào)是否存在,保證唯一性        let selected = await $plugin.data.queryData(entity, { [codeField]: id });//數(shù)據(jù)庫查詢        isNewId = selected.length == 0;    }    //將編號(hào)更新到新增數(shù)據(jù)    await $plugin.data.updateData(entity, inserted._id, {        [codeField]: id,//編號(hào)        [indexField]: index,//序號(hào)    });    //生成id的方法    function createId(i) {        index = i;        if (year != thisYear) {            //新的一年,重新從1開始            index = 1;            year = thisYear;        } else {            //仍然是當(dāng)年,繼續(xù)編號(hào)            index ;        }        //組成id        return "DD"   year   "-"   (Array(size).join('0')   index).slice(-size);    }}

6、將功能發(fā)布上線。

效果:

實(shí)現(xiàn)特定格式編號(hào)自動(dòng)生成(實(shí)現(xiàn)特定格式編號(hào)自動(dòng)生成的方法)

相關(guān)新聞

聯(lián)系我們
聯(lián)系我們
公眾號(hào)
公眾號(hào)
在線咨詢
分享本頁
返回頂部