Files

131 lines
5.2 KiB
JavaScript

'use strict';
const Service = require('../core/base_service');
const { Op } = require('sequelize');
const fs = require('fs');
const path = require('path');
const fileName = "Search";
class SearchService extends Service {
// 管理系统检索考生姓名
async searchUserName(uid, body) {
const { ctx } = this;
try {
const result = await ctx.model.Examinee.findAll({ where: { user_name: { [Op.substring]: body.user_name } } });
return result.length == 0 ? false : result;
} catch (error) {
const blockName = fileName + "--" + "searchUserName";
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
return 'error';
}
}
// 管理系统检索考生身份证号
async searchIdentityCard(uid, body) {
const { ctx } = this;
try {
const result = await ctx.model.Examinee.findAll({ where: { identity_card: { [Op.substring]: body.identity_card } } });
return result.length == 0 ? false : result;
} catch (error) {
const blockName = fileName + "--" + "searchIdentityCard";
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
return 'error';
}
}
// 管理系统检索考生 uid
async searchUserUid(identity_card, user_name) {
const { ctx } = this;
try {
let attributes = ['uid'],
where = { identity_card, user_name },
dbOptions = { attributes, where };
const result = await ctx.model.Examinee.findOne(dbOptions);
return result || false;
} catch (error) {
const blockName = fileName + "--" + "searchUserUid";
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
return 'error';
}
}
// 管理系统检索考试 uid
async searchExamUid(uid, body) {
const { ctx } = this;
try {
const result = await ctx.model.Examination.findAll({ where: { uid: { [Op.substring]: body.exam_uid } } });
return result.length == 0 ? false : result;
} catch (error) {
const blockName = fileName + "--" + "searchExamUid";
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
return 'error';
}
}
// 管理系统检索工作单位
async searchWorkplace(uid, body) {
const { ctx } = this;
try {
const result = await ctx.model.Examinee.findAll({ where: { workplace: { [Op.substring]: body.workplace } } });
return result.length == 0 ? false : result;
} catch (error) {
const blockName = fileName + "--" + "searchWorkplace";
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
return 'error';
}
}
// 管理系统检索报名结果说明
async searchResult(uid, body) {
const { ctx } = this;
try {
const result = await ctx.model.Application.findAll({ where: { result: { [Op.substring]: body.result } } });
return result.length == 0 ? false : result;
} catch (error) {
const blockName = fileName + "--" + "searchResult";
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
return 'error';
}
}
// 用户照片是否存在判断
async checkPhoto(idCardArr) {
const { ctx } = this;
try {
let attributes = ['uid', 'identity_card'],
where = { identity_card: idCardArr },
dbOptions = { attributes, where };
const result = await ctx.model.Examinee.findAll(dbOptions);
if (result.length == 0) return false;
let photoUrlArr = [];
result.forEach(element => {
const filePath = path.join(__dirname.replace(/\bbd-training-exam-manager\b/g, "bd-training-exam"), `../public/userPhoto/${element.dataValues.identity_card}.jpg`);
// const filePath = `/disk/a/userPhoto/${element.dataValues.identity_card}.jpg`;
const fileExists = fs.existsSync(filePath);
if (fileExists) {
// 文件存在
// 本机服务器地址
// 'http://127.0.0.1:8019'
// 'http://192.168.31.28:8019'
// 公司服务器地址
// 'http://123.57.205.46:8019'
// 'http://certlogin.hwasmart.com//bdTrainingExam'
photoUrlArr.push({ identity_card: element.dataValues.identity_card, photoUrl: 'http://127.0.0.1:8019' + `/public/userPhoto/${element.dataValues.identity_card}.jpg?time=${new Date().getTime()}` });
} else {
// 文件不存在
photoUrlArr.push({ identity_card: element.dataValues.identity_card, photoUrl: '#' });
}
});
return photoUrlArr;
} catch (error) {
const blockName = fileName + "--" + "checkPhoto";
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
return 'error';
}
}
}
module.exports = SearchService;