node多条件查询接口例子

这个博客展示了如何在Node.js中创建一个接受多种查询条件的接口。接口名为GetTasksFlow,通过参数如registno、licenseno、taskstate等进行过滤和检索任务数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

node多条件查询接口例子
GetTasksFlow: function () {
console.log(“进入接口-GetTasksFlow”);
var Me, registno, licenseno, taskstate, is_cuiban,
assess_name, fzr_name, taskattribute, city, county, team, carrole,
startdate, enddate, _startdate, _enddate,scene_type,scene_type_reason,
start, limit;
Me = this;
registno = Me.getParam(‘registno’);
licenseno = Me.getParam(‘licenseno’);
taskstate = Me.getParam(‘taskstate’);
is_cuiban = Me.getParam(‘is_cuiban’);
assess_name = Me.getParam(‘assess_name’);
fzr_name = Me.getParam(‘fzr_name’);
taskattribute = Me.getParam(‘taskattribute’);
city = Me.getParam(‘city’);
county = Me.getParam(‘county’);
team = Me.getParam(‘team’);
carrole = Me.getParam(‘carrole’);

        startdate = Me.getParam('startdate');
        enddate = Me.getParam('enddate');
        scene_type = Me.getParam('scene_type');
        scene_type_reason = Me.getParam('scene_type_reason');
        start = Me.getParam('start');
        limit = Me.getParam('limit');
        var reg = new RegExp("^[0-9]*$");
        if (isNaN(start) || start < 0 || !reg.test(start)) {
            return cbError(40003, Me.cb);
        }
        if (isNaN(limit) || limit <= 0 || !reg.test(limit)) {
            return cbError(40003, Me.cb);
        }
        start = start * 1;
        limit = limit * 1;
        if (startdate) {
            startdate = hcUti.formatDate(new Date(startdate), "yyyy-MM-dd");
            _startdate = hcUti.formatDate(new Date(startdate), "yyyy-MM-dd 00:00:00");
            _startdate = new Date(_startdate).getTime();
        }
        if (enddate) {
            enddate = hcUti.formatDate(new Date(enddate), "yyyy-MM-dd");
            _enddate = hcUti.formatDate(new Date(enddate), "yyyy-MM-dd 23:59:59");
            _enddate = new Date(_enddate).getTime();
        }

        var sqlCmd = "";
        var sqlParams = [];
        var sqlWhere = '';
        sqlCmd = 'select a.*,b.Area1Code as code1,b.Area2Code as code2,b.Area3Code as code3,b.Area4Code as code4,b.Area5Code as code5 ' +
            'from tasks_flow a left join area b on b.id=a.fzr_areaid ' +
            'where a.is_special=0 ';
        if (startdate) {
            sqlWhere += " and a.reporttime >= ? ";
            sqlParams.push(_startdate);
        }
        if (enddate) {
            sqlWhere += " and a.reporttime <= ? ";
            sqlParams.push(_enddate);
        }
        if (registno) {
            sqlWhere += " and a.registno = ? ";
            sqlParams.push(registno);
        }
        if (licenseno) {
            sqlWhere += " and a.licenseno = ? ";
            sqlParams.push(licenseno);
        }
        if (taskstate) {
            sqlWhere += " and a.taskstate = ? ";
            sqlParams.push(taskstate);
        }
        if (is_cuiban == "1") {
            sqlWhere += " and a.is_cuiban >= 1 ";
        } else if (is_cuiban == "0") {
            sqlWhere += " and a.is_cuiban = 0 ";
        }
        if (assess_name) {
            sqlWhere += " and a.assess_name = ? ";
            sqlParams.push(assess_name);
        }
        if (fzr_name) {
            sqlWhere += " and a.fzr_name = ? ";
            sqlParams.push(fzr_name);
        }
        var _taskattribute='';
        if(taskattribute == 1){
            _taskattribute='01';
        }else if(taskattribute == 2){
            _taskattribute='03';
        }else if(taskattribute == 3){
            _taskattribute='06';
        }else {
            _taskattribute='';
        }
        if (_taskattribute) {
            sqlWhere += " and a.taskattribute = ? ";
            sqlParams.push(_taskattribute);
        }
        if (city) {
            sqlWhere += " and b.Area2Code = ? ";
            sqlParams.push(city);
        }
        if (county) {
            sqlWhere += " and b.Area3Code = ? ";
            sqlParams.push(county);
        }
        if (team) {
            sqlWhere += " and b.Area5Code = ? ";
            sqlParams.push(team);
        }
        if (carrole) {
            sqlWhere += " and a.carrole = ? ";
            sqlParams.push(carrole);
        }
        if (scene_type != 0 && scene_type != '' && scene_type != null && scene_type != undefined) {
            if(scene_type==-1){
                sqlWhere += " and a.scene_type = ? ";
                sqlParams.push(scene_type);
            }else if(scene_type==1){
                sqlWhere += " and a.scene_type >= 0 ";
            }
        }
        if (scene_type_reason != '' && scene_type_reason != null && scene_type_reason != undefined) {
            sqlWhere += " and a.scene_type = ? ";
            sqlParams.push(scene_type_reason);
        }
        sqlCmd = sqlCmd + sqlWhere + " order by a.reporttime desc limit ?,?;";
        sqlParams.push(start);
        sqlParams.push(limit);
        //分页
        sqlCmd += "select count(0) as totalCount " +
            "from tasks_flow a left join area b on b.id=a.fzr_areaid " +
            "where a.is_special = 0 " + sqlWhere+';';
        if (startdate) {
            sqlParams.push(_startdate);
        }
        if (enddate) {
            sqlParams.push(_enddate);
        }
        if (registno) {
            sqlParams.push(registno);
        }
        if (licenseno) {
            sqlParams.push(licenseno);
        }
        if (taskstate) {
            sqlParams.push(taskstate);
        }
        if (is_cuiban == 1) {
        } else if (is_cuiban == 0) {
        }
        if (assess_name) {
            sqlParams.push(assess_name);
        }
        if (fzr_name) {
            sqlParams.push(fzr_name);
        }
        if (_taskattribute) {
            sqlParams.push(_taskattribute);
        }
        if (city) {
            sqlParams.push(city);
        }
        if (county) {
            sqlParams.push(county);
        }
        if (team) {
            sqlParams.push(team);
        }
        if (carrole) {
            sqlParams.push(carrole);
        }
        if (scene_type) {
            if(scene_type==-1){
                sqlParams.push(scene_type);
            }else if(scene_type==1){

            }
        }
        if (scene_type_reason != '') {
            sqlParams.push(scene_type_reason);
        }
        Me.db.query(sqlCmd, sqlParams, function (err, result) {
            if (err) {
                return cbError('50003', Me.cb);
            }
            else {
                Me.cb(200, "", {
                    "totalCount": result[1][0].totalCount,
                    'topics': result[0]
                });
            }
        });
    },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值