wenlele 2 years ago
parent
commit
02862348fa
  1. 78
      api/app/lib/controllers/projectRegime/projectSituation.js
  2. 3
      api/app/lib/index.js
  3. 3
      api/app/lib/routes/projectRegime/index.js
  4. 10
      web/client/src/sections/projectRegime/actions/projectSituation.js
  5. 2
      web/client/src/sections/projectRegime/containers/qrCode.js
  6. 1
      web/client/src/utils/webapi.js

78
api/app/lib/controllers/projectRegime/projectSituation.js

@ -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 = {
projectList,
postAddProject,
@ -249,5 +324,6 @@ module.exports = {
addPosition,
position,
delPosition,
qrCodeShow
qrCodeShow,
q
}

3
api/app/lib/index.js

@ -53,8 +53,7 @@ module.exports.models = function (dc) { // dc = { orm: Sequelize对象, ORM: Seq
require(`./models/${filename}`)(dc)
});
const { Camera, Company, Department, Post, RoleGroup, Role, RoleResource, User, UserDepartment, UserPost, Site, ProjectDisclosure, ProjectDisclosureFiles, Coordinate, ProblemReport, ProblemReportFile, Worker, WorkerAttendance,
RiskReport, Metting, HideDangerRectify, HideDangerRectifySites, HideDangerDispose, UserResource, Resource, Project, Point
const { Department, User, UserResource, Resource, Project, Point
} = dc.models;
UserResource.belongsTo(User, { foreignKey: 'userId', targetKey: 'id' });

3
api/app/lib/routes/projectRegime/index.js

@ -25,4 +25,7 @@ module.exports = function (app, router, opts) {
app.fs.api.logAttr['GET/qrCodeShow'] = { content: '获取二维码列表', visible: false };
router.get('/qrCodeShow', projectSituation.qrCodeShow);
app.fs.api.logAttr['GET/q'] = { content: '获取二维码列表', visible: false };
router.get('/q', projectSituation.q);
}

10
web/client/src/sections/projectRegime/actions/projectSituation.js

@ -88,3 +88,13 @@ export function qrCodeShow (query) {
});
}
export function q () {
return (dispatch) => basicAction({
type: 'get',
dispatch,
actionType: 'GET_CODE',
url: ApiTable.q,
msg: { error: '获取二维码列表失败', },
});
}

2
web/client/src/sections/projectRegime/containers/qrCode.js

@ -34,6 +34,8 @@ const QrCode = (props) => {
}
})
projectList({})
dispatch(projectRegime.q())
}, [])
const projectList = (obj) => {

1
web/client/src/utils/webapi.js

@ -102,6 +102,7 @@ export const ApiTable = {
position: 'position',
delPosition: 'delPosition/{id}',
qrCodeShow: 'qrCodeShow',
q:'q',
//视频接入配置
siteList: 'siteList',

Loading…
Cancel
Save