|
@ -242,6 +242,81 @@ async function qrCodeShow (ctx, next) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function q(ctx) { |
|
|
|
|
|
let error = { |
|
|
|
|
|
name: 'FindError', |
|
|
|
|
|
message: "获取失败!" |
|
|
|
|
|
}; |
|
|
|
|
|
const models = ctx.fs.dc.models; |
|
|
|
|
|
const { devices } = ctx.request.body |
|
|
|
|
|
const attachment = ctx.app.fs.qn_attachment |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
if (!Array.isArray(devices)) { |
|
|
|
|
|
error = { name: 'paramsError', message: '参数不能为空' }; |
|
|
|
|
|
ctx.throw(400); |
|
|
|
|
|
} |
|
|
|
|
|
const devicesArr = await models.Device.findAll({ |
|
|
|
|
|
attributes: ['deviceNo', 'periodCode', 'qrSrc'], |
|
|
|
|
|
where: { deviceNo: { $in: devices } } |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
let ids = [], idsMap = {}, qnImages = [] |
|
|
|
|
|
devicesArr.forEach(d => { |
|
|
|
|
|
const qrSrc = d.qrSrc |
|
|
|
|
|
const deviceNo = d.deviceNo |
|
|
|
|
|
const periodCode = d.periodCode |
|
|
|
|
|
if (qrSrc) { |
|
|
|
|
|
if (/^\d+$/.test(qrSrc)) { |
|
|
|
|
|
ids.push(qrSrc) |
|
|
|
|
|
idsMap[qrSrc] = { deviceNo, periodCode } |
|
|
|
|
|
} else { |
|
|
|
|
|
let domain = globalCache.getQnDomain() |
|
|
|
|
|
let imgUrl = `${domain}/${qrSrc}` |
|
|
|
|
|
qnImages.push({ src: imgUrl, deviceNo, periodCode }) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
const docs = await models.QrcodePng.findAll({ |
|
|
|
|
|
where: { |
|
|
|
|
|
id: { $in: ids } |
|
|
|
|
|
}, |
|
|
|
|
|
attributes: ["id", "base64"] |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
let pics = [] |
|
|
|
|
|
|
|
|
|
|
|
if (docs.length > 0) { |
|
|
|
|
|
pics = docs.map((d) => { |
|
|
|
|
|
let { deviceNo, periodCode } = idsMap[d.id] || {} |
|
|
|
|
|
let base64 = d.base64.replace(/^data:image\/\w+;base64,/, '') |
|
|
|
|
|
return { |
|
|
|
|
|
url: Buffer.from(base64, 'base64'), |
|
|
|
|
|
name: deviceNo, |
|
|
|
|
|
periodCode |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (qnImages.length > 0) { |
|
|
|
|
|
let qns = await downloadImgsAsBase64(qnImages) |
|
|
|
|
|
pics = pics.concat(qns) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let fileUrl = await downLoadImageBiz(pics, { zipName: "二维码_" + moment().format("YYYY-MM-DD-HH-mm-ss"), attachment }) |
|
|
|
|
|
add2CleanCache(fileUrl, attachment) |
|
|
|
|
|
ctx.status = 200 |
|
|
|
|
|
ctx.body = { fileUrl } |
|
|
|
|
|
|
|
|
|
|
|
} catch (err) { |
|
|
|
|
|
ctx.fs.logger.error(err); |
|
|
|
|
|
ctx.status = 400; |
|
|
|
|
|
ctx.body = error; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
module.exports = { |
|
|
module.exports = { |
|
|
projectList, |
|
|
projectList, |
|
|
postAddProject, |
|
|
postAddProject, |
|
@ -249,5 +324,6 @@ module.exports = { |
|
|
addPosition, |
|
|
addPosition, |
|
|
position, |
|
|
position, |
|
|
delPosition, |
|
|
delPosition, |
|
|
qrCodeShow |
|
|
qrCodeShow, |
|
|
|
|
|
q |
|
|
} |
|
|
} |