Commit cc175c07 by liimin

.

1 parent f98c12e2
/*
* @Author: limin
* @Date: 2019-12-06 14:58:35
* @Last Modified by: limin
* @Last Modified time: 2019-12-06 18:22:13
*/
const items = new WeakMap(); //WeakMap对象是密钥/值对的集合,其中密钥被弱引用。键必须是对象,值可以是任意值。
module.exports = class Queue {
constructor() {
items.set(this, []);
}
enqueue(...element) {
//向队列尾部添加一个(或多个)新的项
let q = items.get(this);
q.push(...element);
}
dequeue() {
//移除队列的第一个(排在队列最前面的)项,并返回被移除的元素。
let q = items.get(this);
let r = q.shift();
return r;
}
front() {
//返回队列中第一个元素——最先被添加,也将是最先被移除的元素。队列不做任何变动(不移除元素,只返回元素信息)
let q = items.get(this);
return q[0];
}
isEmpty() {
//如果队列中不包含任何元素,返回true,否则返回false。
return items.get(this).length == 0;
}
size() {
//返回队列包含的元素个数,与数组的length属性类似。
let q = items.get(this);
return q.length;
}
clear() {
//清空队列里面的元素。
items.set(this, []);
}
print() {
//打印队列为String到控制台
console.log(this.toString());
}
toString() {
//输出队列以String模式。
return items.get(this).toString();
}
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: limin * @Author: limin
* @Date: 2019-11-21 11:20:01 * @Date: 2019-11-21 11:20:01
* @Last Modified by: limin * @Last Modified by: limin
* @Last Modified time: 2019-12-05 17:26:22 * @Last Modified time: 2019-12-06 18:22:23
*/ */
"use strict"; "use strict";
...@@ -84,15 +84,6 @@ class UserController extends Controller { ...@@ -84,15 +84,6 @@ class UserController extends Controller {
} }
return result return result
} }
/**
* 内部帮助方法
* @param {*} obj
* @param {*} field
*/
_reduce_(obj,field){
return obj.reduce((pre,next)=>pre + +next[field],0)
}
/** /**
* 内部帮助方法 * 内部帮助方法
* @param {*} field * @param {*} field
...@@ -189,9 +180,13 @@ class UserController extends Controller { ...@@ -189,9 +180,13 @@ class UserController extends Controller {
* @Request query integer pid 省份id * @Request query integer pid 省份id
*/ */
async total({ query: { pid,cid } }) { async total({ query: { pid,cid } }) {
// const queue = new this.helper.Queue()
// queue.enqueue(1,2,3,4,5);
// console.log(queue.dequeue(5));
// console.log(queue.size());
var total = await this._fetch_total_last_day_({ pid,cid,field:'u'}) var total = await this._fetch_total_last_day_({ pid,cid,field:'u'})
const realtime = await this.UserService.user_realtime({ pid, cid }); const realtime = await this.UserService.user_realtime({ pid, cid });
const realtime_total = this._reduce_(realtime,'increase'); const realtime_total = realtime.reduce((pre,next)=>pre + +next['increase'],0);
total += ~~realtime_total; total += ~~realtime_total;
const data = { total }; const data = { total };
this.ctx.body = this.ServerResponse.Success(data); this.ctx.body = this.ServerResponse.Success(data);
......
...@@ -2,13 +2,15 @@ ...@@ -2,13 +2,15 @@
* @Author: limin * @Author: limin
* @Date: 2019-11-21 11:19:43 * @Date: 2019-11-21 11:19:43
* @Last Modified by: limin * @Last Modified by: limin
* @Last Modified time: 2019-12-04 17:28:07 * @Last Modified time: 2019-12-06 15:10:08
*/ */
const moment = require("moment"); const moment = require("moment");
const constant = require("../common/constant"); const constant = require("../common/constant");
const queue = require("../common/queue");
exports.moment = moment; exports.moment = moment;
exports.Queue = queue;
/* /*
* string.replace_all()---字符替换所有指定字符 * string.replace_all()---字符替换所有指定字符
* @parameter: from--原文本要替换值 * @parameter: from--原文本要替换值
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!