123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311 |
- 'use strict';
- const Service = require('egg').Service;
- const gm = require('gm');
- const qr = require('qr-image');
- const moment = require('moment');
- class InfoService extends Service {
- // 单条查询
- async one(id) {
- const { model } = this.ctx;
- return await model.InfoModel.findById(id);
- }
- // 不分页查询
- async list(data) {
- const { model } = this.ctx;
- return await model.InfoModel.find(data).sort({ time: -1 });
- }
- // 不分页查询
- async noVisitList(data) {
- const { model } = this.ctx;
- const noVisitData = [];
- const noVisitList = await model.InfoModel.aggregate(
- [
- { $match: { status: '3', userid: this.app.mongoose.Types.ObjectId(data.userid) } },
- {
- $lookup: {
- from: 'visit',
- localField: '_id',
- foreignField: 'infoId',
- as: 'inventory_docs',
- },
- },
- { $group: {
- _id: '$_id',
- name: { $first: '$name' },
- userid: { $first: '$userid' },
- time: { $first: '$inventory_docs.visitTime' },
- regularsInfo: { $first: '$regularsInfo' },
- },
- },
- {
- $unwind: { path: '$time' },
- },
- { $sort: { time: -1 } },
- { $group: {
- _id: '$_id',
- name: { $first: '$name' },
- userid: { $first: '$userid' },
- time: { $first: '$time' },
- regularsInfo: { $first: '$regularsInfo' },
- },
- },
- ]
- );
- const visitList = await model.InfoModel.aggregate(
- [
- { $match: { status: '3', userid: this.app.mongoose.Types.ObjectId(data.userid) } },
- {
- $lookup: {
- from: 'visit',
- localField: '_id',
- foreignField: 'infoId',
- as: 'inventory_docs',
- },
- },
- ]
- );
- if (visitList.map(item => {
- if (item.inventory_docs.length === 0) {
- const visitCount = JSON.parse(item.regularsInfo).visitCount;
- const time = item.time.getTime();
- let is = null;
- switch (visitCount) {
- case '每天':
- is = time >= moment().subtract(1, 'day').valueOf();
- break;
- case '每周':
- is = time >= moment().subtract(7, 'day').valueOf();
- break;
- case '每月':
- is = time >= moment().subtract(1, 'month').valueOf();
- break;
- case '每季':
- is = time >= moment().subtract(3, 'month').valueOf();
- break;
- default:
- is = true;
- }
- if (!is) {
- noVisitData.push({ _id: item._id, name: item.name, userid: item.userid, visitCount: JSON.parse(item.regularsInfo).visitCount, visitCountExt: JSON.parse(item.regularsInfo).visitCountExt });
- }
- }
- })) {
- noVisitList.map(item => {
- const visitCount = JSON.parse(item.regularsInfo).visitCount;
- const time = item.time.getTime();
- let is = null;
- switch (visitCount) {
- case '每天':
- is = time >= moment().subtract(1, 'day').valueOf();
- break;
- case '每周':
- is = time >= moment().subtract(7, 'day').valueOf();
- break;
- case '每月':
- is = time >= moment().subtract(1, 'month').valueOf();
- break;
- case '每季':
- is = time >= moment().subtract(3, 'month').valueOf();
- break;
- default:
- is = true;
- }
- if (!is) {
- noVisitData.push({ ...item, visitCount: JSON.parse(item.regularsInfo).visitCount, visitCountExt: JSON.parse(item.regularsInfo).visitCountExt });
- }
- });
- }
- return noVisitData;
- }
- // 根据户id查询
- async listByFid(data) {
- const { model } = this.ctx;
- return await model.InfoModel.find(data);
- }
- // 根据身份证号查询
- async listByNumber(data) {
- const { model } = this.ctx;
- return await model.InfoModel.find(data);
- }
- // 分页查询
- async listForPage(data) {
- const { model } = this.ctx;
- const page = data.page;
- const rows = Number.parseInt(data.rows) || this.app.config.defaultPageSize;
- delete data.page;
- delete data.rows;
- const where = {};
- if (data.dept1) {
- where.dept1 = this.app.mongoose.Types.ObjectId(data.dept1);// 省
- }
- if (data.dept2) {
- where.dept2 = this.app.mongoose.Types.ObjectId(data.dept2);// 市
- }
- if (data.dept3) {
- where.dept3 = this.app.mongoose.Types.ObjectId(data.dept3);// 区
- }
- if (data.dept4) {
- where.dept4 = this.app.mongoose.Types.ObjectId(data.dept4);// 乡
- }
- if (data.dept5) {
- where.dept5 = this.app.mongoose.Types.ObjectId(data.dept5);// 社区
- }
- // userid.loginName
- if (data.cjname) {
- // where.userName = { $regex: data.cjname }; // 管理员
- // where['userInfo.loginName'] = { $regex: data.cjname };
- const result = await model.SysUserModel.find({ loginName: { $regex: data.cjname } });
- if (result.length > 0) {
- where.userid = result[0]._id;
- } else {
- return '';
- }
- }
- // 状态
- if (data.status) {
- where.status = '' + data.status;
- }
- // 老人常用联系电话
- if (data.phone) {
- where.phone = { $regex: data.phone };
- }
- // 老人姓名
- if (data.name) {
- where.name = { $regex: data.name };
- }
- // 老人年龄
- if (data.age) {
- const myDate = new Date();
- const year = myDate.getFullYear();
- const month = (myDate.getMonth() + 1) > 9 ? (myDate.getMonth() + 1) : '0' + (myDate.getMonth() + 1);
- const day = myDate.getDate() > 9 ? (myDate.getDate()) : '0' + (myDate.getDate());
- if (data.age > 0) {
- where.idNumber = { $ne: '' };
- where.birthday = { $lte: '' + year + month + day - (data.age * 10000) + '' };
- } else {
- where.idNumber = { $ne: '' };
- where.birthday = { $gte: '' + year + month + day - (-data.age * 10000) + '' };
- }
- }
- // 关爱服务需求
- if (data.demand) {
- const ts = data.demand.split(',');
- where.demand = { $in: ts };
- }
- // 老人类别
- if (data.oldType) {
- const ts = data.oldType.split(',');
- where.oldType = { $in: ts };
- }
- // 离线采集
- if (data.online) {
- if (data.online == 'false') {
- where.online = data.online;
- }
- if (data.online == 'true') {
- // where.online = data.online;
- where.$or = [{ online: { $exists: false } }, { online: data.online }];
- }
- }
- // 身份证号码搜索
- if (data.idNumber) {
- where.idNumber = { $regex: data.idNumber };
- }
- // 老年人能力状况(公众号和小程序的括号不一致)
- if (data.ability) {
- // where.ability = data.ability;
- where.ability = { $regex: '^' + data.ability };
- }
- // 时间
- if (data.startTime && data.endTime) {
- where.time = { $gte: new Date(data.startTime + ' 00:00:00'), $lt: new Date(data.endTime + ' 23:59:59') };
- }
- // if (data.isDeath) {
- // if (data.isDeath == '1') {
- // where.isDeath = data.isDeath;
- // } else {
- // where.$or = [{ isDeath: { $exists: false } }, { isDeath: data.isDeath }];
- // }
- // }
- // 是否是党员
- // if (data.partyMember) {
- // if (data.partyMember == '1') {
- // where.partyMember = data.partyMember;
- // } else {
- // where.$or = [{ partyMember: { $exists: false } }, { partyMember: data.partyMember }];
- // }
- // }
- // 自主填报
- if (data.ownerId === 'true') {
- where.ownerId = { $ne: null };
- } else if (data.ownerId === 'false') {
- where.ownerId = { $eq: null };
- }
- if (data.partyMember == 1) {
- where.partyMember = { $eq: 1 };
- } else if (data.partyMember == '0') {
- where.partyMember = { $in: [ 0, null ] };
- } else {
- delete data.partyMember;
- }
- if (data.isDeath == 1) {
- where.isDeath = { $eq: 1 };
- } else if (data.isDeath == '0') {
- where.isDeath = { $in: [ 0, null ] };
- } else {
- delete data.isDeath;
- }
- this.ctx.logger.info('条件===============================================', where);
- const pop = [
- {
- path: 'userid',
- select: 'loginName userName',
- },
- {
- path: 'dept1',
- select: 'name',
- },
- {
- path: 'dept2',
- select: 'name',
- },
- {
- path: 'dept3',
- select: 'name',
- },
- {
- path: 'dept4',
- select: 'name',
- },
- {
- path: 'dept5',
- select: 'name',
- },
- // {
- // path: 'fid',
- // select: 'openId',
- // },
- ];
- const fidCount = await model.InfoModel.aggregate([
- { $match: where },
- { $group: { _id: '$fid', count: { $sum: 1 } } },
- { $group: { _id: null, count: { $sum: 1 } } },
- { $project: { _id: 0, count: '$count' } },
- ]);
- const total = await model.InfoModel.find(where).populate(pop).countDocuments();
- const result = await model.InfoModel.find(where).populate(pop).skip((page - 1) * rows)
- .limit(rows)
- .sort({ time: -1 });
- return {
- fidCount: fidCount[0] !== undefined ? fidCount[0].count : 0,
- count: total,
- list: result,
- };
- }
- // 添加
- async add(data) {
- const { model } = this.ctx;
- const result = await model.InfoModel.create(data);
- return result;
- }
- // 修改
- async update(id, data) {
- const { model } = this.ctx;
- const status = data.status;
- delete data.status;
- // console.log('data', data);
- if (data.idNumber && data.idNumber !== '') {
- const birthday = data.idNumber.substr(6, 8);
- data.birthday = birthday;
- }
- // 身份证修改为空时,将birthday置空
- if (data.idNumber == '') {
- data.birthday = '';
- }
- data.time = Date.now();
- if (data.health) {
- data.health = JSON.parse(data.health);
- }
- if (data.disabilityCategory) {
- data.disabilityCategory = JSON.parse(data.disabilityCategory);
- }
- if (data.majorDiseases) {
- data.majorDiseases = JSON.parse(data.majorDiseases);
- }
- if (data.oldType) {
- data.oldType = JSON.parse(data.oldType);
- }
- if (data.demand) {
- data.demand = JSON.parse(data.demand);
- }
- if (data.lookAfter) {
- data.lookAfter = JSON.parse(data.lookAfter);
- }
- if (data.accompany) {
- data.accompany = JSON.parse(data.accompany);
- }
- if (data.rescueState) {
- data.rescueState = JSON.parse(data.rescueState);
- }
- if (data.sourceOfIncome) {
- data.sourceOfIncome = JSON.parse(data.sourceOfIncome);
- }
- const result = await model.InfoModel.updateOne({ _id: id }, data);
- // 修改采集状态
- delete data.time;
- await this.ctx.service.infoService.updateStatus(id, data);
- return result;
- }
- // 检查采集状态
- async checkInfoStatus(id) {
- const ctx = this.ctx;
- const flag = true;
- const oneInfo = await this.ctx.service.infoService.one(id);
- if (oneInfo) {
- // 姓名
- if (oneInfo.name && oneInfo.name !== '') {
- } else {
- ctx.logger.info('name', flag);
- console.log('name', flag);
- return flag;
- }
- // 性别
- if (oneInfo.sex && oneInfo.sex !== '') {
- } else {
- ctx.logger.info('sex', flag);
- console.log('sex', flag);
- return flag;
- }
- // 民族
- if (oneInfo.nation && oneInfo.nation !== '') {
- } else {
- ctx.logger.info('nation', flag);
- console.log('nation', flag);
- return flag;
- }
- // 身份证
- if (oneInfo.idNumber && oneInfo.idNumber !== '') {
- } else {
- ctx.logger.info('idNumber', flag);
- console.log('idNumber', flag);
- return flag;
- }
- // 生日
- if (oneInfo.birthday && oneInfo.birthday !== '') {
- } else {
- ctx.logger.info('birthday', flag);
- console.log('birthday', flag);
- return flag;
- }
- // 电话
- if (oneInfo.phone && oneInfo.phone !== '') {
- } else {
- ctx.logger.info('phone', flag);
- console.log('phone', flag);
- return flag;
- }
- // 户籍地址
- if (oneInfo.nativePlace && oneInfo.nativePlace !== '') {
- } else {
- ctx.logger.info('nativePlace', flag);
- console.log('nativePlace', flag);
- return flag;
- }
- // 现居地址
- if (oneInfo.address && oneInfo.address !== '') {
- } else {
- ctx.logger.info('address', flag);
- console.log('address', flag);
- return flag;
- }
- // 婚姻及配偶情况
- if (oneInfo.partnerState && oneInfo.partnerState !== '') {
- if (oneInfo.partnerState == '已婚') {
- if (oneInfo.partnerName && oneInfo.partnerName !== '') {
- } else {
- ctx.logger.info('partnerName', flag);
- console.log('partnerName', flag);
- return flag;
- }
- if (oneInfo.partnerIdNumber && oneInfo.partnerIdNumber !== '') {
- } else {
- ctx.logger.info('partnerIdNumber', flag);
- console.log('partnerIdNumber', flag);
- return flag;
- }
- }
- } else {
- ctx.logger.info('partnerState', flag);
- console.log('partnerState', flag);
- return flag;
- }
- // 是否为失独家庭
- if (oneInfo.isLoss && oneInfo.isLoss !== '') {
- } else {
- ctx.logger.info('isLoss', flag);
- console.log('isLoss', flag);
- return flag;
- }
- // 老年人能力状况
- if (oneInfo.ability && oneInfo.ability !== '') {
- } else {
- ctx.logger.info('ability', flag);
- console.log('ability', flag);
- return flag;
- }
- // 健康状况
- if (oneInfo.health && oneInfo.health.length > 0) {
- if (oneInfo.health.indexOf('残疾') !== -1) {
- if (oneInfo.disabilityCategory && oneInfo.disabilityCategory.length > 0) {
- } else {
- ctx.logger.info('disabilityCategory', flag);
- console.log('disabilityCategory', flag);
- return flag;
- }
- if (oneInfo.disabilityLevel && oneInfo.disabilityLevel !== '') {
- } else {
- ctx.logger.info('disabilityLevel', flag);
- console.log('disabilityLevel', flag);
- return flag;
- }
- }
- if (oneInfo.health.indexOf('患重特大疾病') !== -1) {
- if (oneInfo.majorDiseases && oneInfo.majorDiseases.length > 0) {
- } else {
- ctx.logger.info('majorDiseases', flag);
- console.log('majorDiseases', flag);
- return flag;
- }
- }
- } else {
- return flag;
- }
- // 生活经济状况
- if (oneInfo.livingCondition && oneInfo.livingCondition !== '') {
- } else {
- ctx.logger.info('livingCondition', flag);
- console.log('livingCondition', flag);
- return flag;
- }
- // 收入来源
- if (oneInfo.sourceOfIncome && oneInfo.sourceOfIncome.length > 0) {
- if (oneInfo.sourceOfIncome.indexOf('其它') !== -1) {
- if (oneInfo.sourceOfIncomeExt && oneInfo.sourceOfIncomeExt !== '') {
- } else {
- ctx.logger.info('sourceOfIncomeExt', flag);
- console.log('sourceOfIncomeExt', flag);
- return flag;
- }
- }
- } else {
- ctx.logger.info('sourceOfIncome', flag);
- console.log('sourceOfIncome', flag);
- return flag;
- }
- // 本人上年度可支配收入
- if (oneInfo.income && oneInfo.income !== '') {
- } else {
- ctx.logger.info('income', flag);
- console.log('income', flag);
- return flag;
- }
- // 家庭救助帮扶情况
- if (oneInfo.rescueState && oneInfo.rescueState.length > 0) {
- } else {
- ctx.logger.info('rescueState', flag);
- console.log('rescueState', flag);
- return flag;
- }
- // 陪伴居住情况
- if (oneInfo.accompany && oneInfo.accompany.length > 0) {
- if (oneInfo.accompany.indexOf('其他情形') !== -1) {
- if (oneInfo.accompanyExt && oneInfo.accompanyExt !== '') {
- } else {
- ctx.logger.info('accompanyExt', flag);
- console.log('accompanyExt', flag);
- return flag;
- }
- }
- } else {
- ctx.logger.info('accompany', flag);
- console.log('accompany', flag);
- return flag;
- }
- // 日常生活照料人
- if (oneInfo.lookAfter && oneInfo.lookAfter.length > 0) {
- if (oneInfo.lookAfter.indexOf('其他人员') !== -1) {
- if (oneInfo.lookAfterExt && oneInfo.lookAfterExt !== '') {
- } else {
- ctx.logger.info('lookAfterExt', flag);
- console.log('lookAfterExt', flag);
- return flag;
- }
- }
- if (oneInfo.lookAfter.indexOf('无人照料') !== -1) {
- } else {
- if (oneInfo.mainLookName && oneInfo.mainLookName !== '') {
- } else {
- ctx.logger.info('mainLookName', flag);
- console.log('mainLookName', flag);
- return flag;
- }
- if (oneInfo.mainLookSex && oneInfo.mainLookSex !== '') {
- } else {
- ctx.logger.info('mainLookSex', flag);
- console.log('mainLookSex', flag);
- return flag;
- }
- if (oneInfo.mainLookPhone && oneInfo.mainLookPhone !== '') {
- } else {
- ctx.logger.info('mainLookPhone', flag);
- console.log('mainLookPhone', flag);
- return flag;
- }
- }
- } else {
- ctx.logger.info('lookAfter', flag);
- console.log('lookAfter', flag);
- return flag;
- }
- // 关爱服务需求
- if (oneInfo.demand && oneInfo.demand.length > 0) {
- if (oneInfo.demand.indexOf('其它') !== -1) {
- if (oneInfo.demandExt && oneInfo.demandExt !== '') {
- } else {
- ctx.logger.info('demandExt', flag);
- console.log('demandExt', flag);
- return flag;
- }
- }
- } else {
- ctx.logger.info('demand', flag);
- console.log('demand', flag);
- return flag;
- }
- // 老年人类别
- if (oneInfo.oldType && oneInfo.oldType.length > 0) {
- } else {
- ctx.logger.info('oldType', flag);
- console.log('oldType', flag);
- return flag;
- }
- // 老年人照片
- if (oneInfo.photo && oneInfo.photo !== '') {
- } else {
- ctx.logger.info('photo', flag);
- console.log('photo', flag);
- return flag;
- }
- // 定位信息
- if (oneInfo.photoAndLocation && oneInfo.photoAndLocation !== '') {
- } else {
- ctx.logger.info('photoAndLocation', flag);
- console.log('photoAndLocation', flag);
- return flag;
- }
- // 子女
- if (oneInfo.childInfo) {
- const childs = JSON.parse(oneInfo.childInfo);
- if (childs.length > 0) {
- // 检查子女信息是否填全
- for (let index = 0; index < childs.length; index++) {
- const child = childs[index];
- if (child.name && child.name !== '') {
- } else {
- ctx.logger.info('childName', flag);
- console.log('childName', flag);
- return flag;
- }
- if (child.phone && child.phone !== '') {
- } else {
- ctx.logger.info('childPhone', flag);
- console.log('childPhone', flag);
- return flag;
- }
- // 子女配偶
- if (child.isHasPartner && child.isHasPartner !== '') {
- if (child.isHasPartner == '是') {
- if (child.name2 && child.name2 !== '') {
- } else {
- ctx.logger.info('childPartnerName', flag);
- console.log('childPartnerName', flag);
- return flag;
- }
- if (child.phone2 && child.phone2 !== '') {
- } else {
- ctx.logger.info('childPartnerphone2', flag);
- console.log('childPartnerphone2', flag);
- return flag;
- }
- }
- // ctx.logger.info('child.isHasPartner == 1', flag);
- } else {
- ctx.logger.info('childisHasPartner', flag);
- console.log('childisHasPartner', flag);
- return flag;
- }
- // 是否外出
- if (child.isHasGoOut && child.isHasGoOut !== '' && child.isHasGoOut == '否') {
- // if (child.isHasGoOut == '是') {
- // }
- } else {
- if (child.outgoingplace && child.outgoingplace !== '') {
- } else {
- ctx.logger.info('child.outgoingplace', flag);
- console.log('child.outgoingplace', flag);
- return flag;
- }
- if (child.outgoingTime && child.outgoingTime !== '') {
- } else {
- ctx.logger.info('child.outgoingTime', flag);
- console.log('child.outgoingTime', flag);
- return flag;
- }
- if (child.outgoingCause && child.outgoingCause !== '') {
- } else {
- ctx.logger.info('child.outgoingCause', flag);
- console.log('child.outgoingCause', flag);
- return flag;
- }
- }
- // if (child.outgoingplace && child.outgoingplace !== '') {
- // } else {
- // // ctx.logger.info('outgoingplace', flag);
- // console.log('outgoingplace', flag);
- // return flag;
- // }
- // if (child.outgoingTime && child.outgoingTime !== '') {
- // } else {
- // // ctx.logger.info('outgoingTime', flag);
- // console.log('outgoingTime', flag);
- // return flag;
- // }
- // if (child.outgoingCause && child.outgoingCause !== '') {
- // } else {
- // // ctx.logger.info('outgoingCause', flag);
- // console.log('outgoingCause', flag);
- // return flag;
- // }
- if (child.visit && child.visit !== '') {
- } else {
- ctx.logger.info('child.visit', flag);
- console.log('child.visit', flag);
- return flag;
- }
- }
- }
- } else {
- return flag;
- }
- // 其他赡养人
- if (oneInfo.otherInfo) {
- const others = JSON.parse(oneInfo.otherInfo);
- if (others) {
- // 检查赡养人信息是否填全
- if (others.name && others.name !== '') {
- } else {
- ctx.logger.info('others.name', flag);
- console.log('others.name', flag);
- return flag;
- }
- if (others.sex && others.sex !== '') {
- } else {
- ctx.logger.info('others.sex', flag);
- console.log('others.sex', flag);
- return flag;
- }
- if (others.phone && others.phone !== '') {
- } else {
- ctx.logger.info('others.phone', flag);
- console.log('others.phone', flag);
- return flag;
- }
- // 与被赡养人关系
- if (others.relation && others.relation !== '') {
- if (others.relation == '其他') {
- if (others.relationExt && others.relationExt !== '') {
- } else {
- ctx.logger.info('others.relationExt', flag);
- console.log('others.relationExt', flag);
- return flag;
- }
- }
- } else {
- ctx.logger.info('others.relation', flag);
- console.log('others.relation', flag);
- return flag;
- }
- // 配偶
- if (others.isHasPartner && others.isHasPartner !== '') {
- if (others.isHasPartner == '是') {
- if (others.name2 && others.name2 !== '') {
- } else {
- ctx.logger.info('others.name2', flag);
- console.log('others.name2', flag);
- return flag;
- }
- if (others.phone2 && others.phone2 !== '') {
- } else {
- ctx.logger.info('others.phone2', flag);
- console.log('others.phone2', flag);
- return flag;
- }
- }
- } else {
- ctx.logger.info('others.isHasPartner', flag);
- console.log('others.isHasPartner', flag);
- return flag;
- }
- // 是否外出
- if (others.isHasGoOut && others.isHasGoOut !== '' && others.isHasGoOut == '否') {
- } else {
- if (others.outgoingplace && others.outgoingplace !== '') {
- } else {
- ctx.logger.info('others.outgoingplace', flag);
- console.log('others.outgoingplace', flag);
- return flag;
- }
- if (others.outgoingTime && others.outgoingTime !== '') {
- } else {
- ctx.logger.info('others.outgoingTime', flag);
- console.log('others.outgoingTime', flag);
- return flag;
- }
- if (others.outgoingCause && others.outgoingCause !== '') {
- } else {
- ctx.logger.info('others.outgoingCause', flag);
- console.log('others.outgoingCause', flag);
- return flag;
- }
- }
- if (others.visit && others.visit !== '') {
- } else {
- ctx.logger.info('others.visit', flag);
- console.log('others.visit', flag);
- return flag;
- }
- }
- }
- // 巡访联系人信息
- if (oneInfo.regularsInfo && oneInfo.regularsInfo !== '') {
- const regulars = JSON.parse(oneInfo.regularsInfo);
- if (regulars) {
- // 检查巡访联系人信息是否填全
- if (regulars.visitMode && regulars.visitMode !== '' && regulars.visitMode !== '[]') {
- if (regulars.visitMode.indexOf('其它') !== -1) {
- if (regulars.visitModeExt && regulars.visitModeExt !== '') {
- } else {
- ctx.logger.info('regulars.visitModeExt', flag);
- console.log('regulars.visitModeExt', flag);
- return flag;
- }
- }
- } else {
- ctx.logger.info('regulars.visitMode', flag);
- console.log('regulars.visitMode', flag);
- return flag;
- }
- if (regulars.visitCount && regulars.visitCount !== '') {
- if (regulars.visitCount == '其它') {
- if (regulars.visitCountExt && regulars.visitCountExt !== '') {
- } else {
- ctx.logger.info('regulars.visitCountExt', flag);
- console.log('regulars.visitCountExt', flag);
- return flag;
- }
- }
- } else {
- ctx.logger.info('regulars.visitCount', flag);
- console.log('regulars.visitCount', flag);
- return flag;
- }
- } else {
- ctx.logger.info('regulars', flag);
- console.log('regulars', flag);
- return flag;
- }
- } else {
- ctx.logger.info('regularsInfo', flag);
- console.log('regularsInfo ', flag);
- return flag;
- }
- ctx.logger.info('false', flag);
- console.log('false', flag);
- return false;
- }
- ctx.logger.info('true', flag);
- console.log('true', flag);
- return flag;
- }
- // 审核成功时,不允许修改为空
- async checkInfoUpdate(oneInfo) {
- const ctx = this.ctx;
- let flag = true;
- Object.keys(oneInfo).forEach(item => {
- if (item == 'childInfo') {
- return flag;
- }
- if (item == 'otherInfo') {
- return flag;
- }
- if (item == 'regularsInfo') {
- return flag;
- }
- if (!oneInfo[item] || oneInfo[item] == '' || oneInfo[item] == '[]') {
- // 当值不存在,为'',为 '[]'时,不可以修改
- flag = false;
- }
- });
- // console.log('完成');
- return flag;// 可以修改
- }
- // 修改采集状态
- async updateStatus(id, data) { // data 修改内容
- const { ctx } = this;
- const { model } = this.ctx;
- const oneInfo = await this.ctx.service.infoService.one(id);
- // 检查采集状态是否完成
- const checkStatus = await this.ctx.service.infoService.checkInfoStatus(id);
- const status = checkStatus ? '0' : '1';
- // ctx.logger.info('status=================', status)
- let query = {};
- // 审核完成后,采集状态不允许修改
- if (oneInfo.status == '3') {
- query = { status: oneInfo.status };
- } else {
- query = { status };
- }
- if (status == '1') {
- if (this.isNoNull(oneInfo, 'pic')) {
- // pic != '' 是否修改了name idNumber
- if (data.name || data.idNumber) {
- // 根据修改的name,idNumber重新生成二维码
- const picUrl = await this.ctx.service.infoService.createImage(oneInfo._id, data.name, data.idNumber);
- // update 图片地址
- console.log('我修改了图片');
- query.pic = picUrl;
- }
- } else {
- // 生成二维码
- const picUrl = await this.ctx.service.infoService.createImage(oneInfo._id, oneInfo.name, oneInfo.idNumber);
- console.log('我未修改了图片');
- // add图片地址
- query.pic = picUrl;
- }
- }
- const result = await model.InfoModel.updateOne({ _id: id }, query);
- return result;
- }
- // 生成二维码
- async createImage(id, name, idNumber) {
- const { service } = this;
- if (id && name && idNumber && id !== '' && name !== '' && idNumber !== '') {
- // 生成二维码
- const qr_png = qr.image(this.app.config.weiXinUrl + id, { type: 'png' });
- let number = '';
- if (idNumber && idNumber !== '') {
- number = idNumber.substring(0, 4) + 'xxxxxxxxxxx' + idNumber.substring(15, 18);
- }
- // 添加水印
- const fileStream = await service.infoService.handleImage(qr_png, name, number);
- const fileName = name + '_' + (number || '') + '_' + Date.now() + '.png';
- // TODO 传图至OSS -CH (已完成)
- await this.ctx.oss.get('bucket1').putStream(this.app.config.scanAliOSSPath + fileName, fileStream);
- const url = this.app.config.scanPathPre + fileName;
- return url;
- }
- return '';
- }
- isNoNull(obj, key) {
- return obj.hasOwnProperty(key) && obj[key];
- }
- // gm 二维码添加文字水印
- async handleImage(qr_png, name, number) {
- return new Promise((resolve, reject) => {
- // 添加水印
- gm(qr_png)
- .font('./app/public/font/msyh.ttf') // 设置字体
- .fill('#000000') // 设置颜色
- .fontSize('12px') // 设置字号
- .drawText(0, 5, name + (number || ''), 'South') // 设定位置
- .stream(function(err, stdout, stderr) {
- if (!err) {
- resolve(stdout);
- } else {
- reject(err.message);
- console.log('err.message:', err.message);
- }
- });
- console.log('done!');
- });
- }
- // 删除
- async dele(id) {
- const { model } = this.ctx;
- const result = await model.InfoModel.deleteOne({ _id: id });
- return result;
- }
- // 审批
- async approval(id, data) {
- const { model } = this.ctx;
- const status = data.status;
- if (id) {
- const oneInfo = await this.ctx.service.infoService.one(id);
- if (oneInfo) {
- if (oneInfo.status == '2') {
- if (status == '3') {
- // 审批成功 修改状态==3
- const result = await model.InfoModel.updateOne({ _id: id }, data);
- // 自主上报采集不加积分
- if (!oneInfo.ownerId) {
- // 判断是否是离线采集,离线采集没有积分
- if (oneInfo.online && oneInfo.online == 'false') {
- // 无积分
- } else {
- // 添加积分记录
- const oneValue = await this.ctx.service.valueService.list({ fid: oneInfo.fid });
- if (oneValue.length <= 0) {
- const addQuery = {};
- addQuery.dept1 = oneInfo.dept1;
- addQuery.dept2 = oneInfo.dept2;
- addQuery.dept3 = oneInfo.dept3;
- addQuery.dept4 = oneInfo.dept4;
- addQuery.dept5 = oneInfo.dept5;
- // addQuery.dept1 = this.app.mongoose.Types.ObjectId(oneInfo.dept1);
- // addQuery.dept2 = this.app.mongoose.Types.ObjectId(oneInfo.dept2);
- // addQuery.dept3 = this.app.mongoose.Types.ObjectId(oneInfo.dept3);
- // addQuery.dept4 = this.app.mongoose.Types.ObjectId(oneInfo.dept4);
- // addQuery.dept5 = this.app.mongoose.Types.ObjectId(oneInfo.dept5);
- addQuery.type = '0';
- addQuery.fid = oneInfo.fid;
- addQuery.userid = oneInfo.userid;
- // addQuery.userName = oneInfo.userName;
- addQuery.infoId = oneInfo._id;
- await model.ValueModel.create(addQuery);
- }
- return result;
- }
- }
- } else if (status == '4') {
- // 修改状态==4 审核失败
- const result = await model.InfoModel.updateOne({ _id: id }, data);
- return result;
- }
- }
- if (oneInfo.status == '1') {
- if (status == '2') {
- // 修改状态==2 审批中
- const result = await model.InfoModel.updateOne({ _id: id }, data);
- return result;
- } else if (status == '4') {
- // 修改状态==4
- const result = await model.InfoModel.updateOne({ _id: id }, data);
- return result;
- }
- }
- }
- }
- return '';
- }
- async isDeath(id, data) {
- const { model } = this.ctx;
- const result = await model.InfoModel.updateOne({ _id: id }, data);
- return result;
- }
- // 修改离线状态
- // async updateOffLine(id, offLineStatus) {
- // const { model } = this.ctx;
- // const result = await model.InfoModel.updateOne({ _id: id }, { offLine: offLineStatus });
- // return result;
- // }
- /**
- * 筛选----身份证重复录入
- * */
- async groupByNumber(data) {
- const { model } = this.ctx;
- const page = data.page || 1;
- const rows = Number.parseInt(data.rows) || this.app.config.defaultPageSize;
- delete data.page;
- delete data.rows;
- const where = {};
- if (data.dept1) {
- where.dept1 = this.app.mongoose.Types.ObjectId(data.dept1);// 省
- }
- if (data.dept2) {
- where.dept2 = this.app.mongoose.Types.ObjectId(data.dept2); // 市
- }
- if (data.dept3) {
- where.dept3 = this.app.mongoose.Types.ObjectId(data.dept3); // 区
- }
- if (data.dept4) {
- where.dept4 = this.app.mongoose.Types.ObjectId(data.dept4); // 乡
- }
- if (data.dept5) {
- where.dept5 = this.app.mongoose.Types.ObjectId(data.dept5); // 社区
- }
- where.$and = [{ idNumber: { $exists: true } }, { idNumber: { $ne: '' } }];
- const countResult = await model.InfoModel.aggregate([
- { $match: where },
- { $group: {
- _id: '$idNumber',
- count: { $sum: 1 },
- } },
- { $match: { count: { $gt: 1 } } },
- {
- $count: 'count', // 总数
- },
- ]);
- const result = await model.InfoModel.aggregate([
- { $match: where },
- { $group: {
- _id: '$idNumber',
- count: { $sum: 1 },
- } },
- { $match: { count: { $gt: 1 } } },
- {
- $sort: { time: -1 },
- },
- {
- $skip: rows * (parseInt(page) - 1),
- },
- {
- $limit: rows,
- },
- ]).allowDiskUse(true);
- const returmData = {};
- returmData.list = result;
- returmData.count = 0;
- if (countResult.length > 0) {
- returmData.count = countResult[0].count;
- }
- returmData.page = data.page;
- returmData.pageSize = data.rows;
- return returmData;
- }
- async exportData(data) {
- const { model } = this.ctx;
- const where = {};
- if (data.dept1) {
- where.dept1 = data.dept1;// 省
- }
- if (data.dept2) {
- where.dept2 = data.dept2; // 市
- }
- if (data.dept3) {
- where.dept3 = data.dept3; // 区
- }
- if (data.dept4) {
- where.dept4 = data.dept4; // 乡
- }
- if (data.dept5) {
- where.dept5 = data.dept5; // 社区
- }
- // userid.loginName
- if (data.cjname) {
- // where.userName = { $regex: data.cjname }; // 管理员
- // where['userInfo.loginName'] = { $regex: data.cjname };
- const result = await model.SysUserModel.find({ loginName: { $regex: data.cjname } });
- if (result.length > 0) {
- where.userid = result[0]._id;
- } else {
- return '';
- }
- }
- // 状态
- where.status = '3';
- // 老人常用联系电话
- if (data.phone) {
- where.phone = { $regex: data.phone };
- }
- // 老人姓名
- if (data.name) {
- where.name = { $regex: data.name };
- }
- // 老人年龄
- if (data.age) {
- const myDate = new Date();
- const year = myDate.getFullYear();
- const month = (myDate.getMonth() + 1) > 9 ? (myDate.getMonth() + 1) : '0' + (myDate.getMonth() + 1);
- const day = myDate.getDate() > 9 ? (myDate.getDate()) : '0' + (myDate.getDate());
- if (data.age > 0) {
- where.idNumber = { $ne: '' };
- where.birthday = { $lte: '' + year + month + day - (data.age * 10000) };
- } else {
- where.idNumber = { $ne: '' };
- where.birthday = { $gte: '' + year + month + day - (-data.age * 10000) };
- }
- }
- // 关爱服务需求
- if (data.demand) {
- // console.log('oldtype', data.oldType)
- if (data.demand.indexOf(',') > -1) {
- const ts = data.demand.split(',');
- where.demand = { $in: ts };
- } else {
- where.demand = { $in: data.demand };
- }
- }
- // 老人类别
- if (data.oldType) {
- // console.log('oldtype', data.oldType)
- if (data.oldType.indexOf(',') > -1) {
- const ts = data.oldType.split(',');
- where.oldType = { $in: ts };
- } else {
- where.oldType = { $in: data.oldType };
- }
- }
- // 离线采集
- if (data.online) {
- if (data.online == 'false') {
- where.online = data.online;
- }
- if (data.online == 'true') {
- // where.online = data.online;
- where.$or = [{ online: { $exists: false } }, { online: data.online }];
- }
- }
- // 身份证号码搜索
- if (data.idNumber) {
- where.idNumber = { $regex: data.idNumber };
- }
- // 老年人能力状况
- if (data.ability) {
- where.ability = data.ability;
- }
- this.ctx.logger.info('条件', where);
- const pop = [
- {
- path: 'userid',
- select: 'loginName userName',
- },
- {
- path: 'dept1',
- select: 'name',
- },
- {
- path: 'dept2',
- select: 'name',
- },
- {
- path: 'dept3',
- select: 'name',
- },
- {
- path: 'dept4',
- select: 'name',
- },
- {
- path: 'dept5',
- select: 'name',
- },
- ];
- const result = await model.InfoModel.find(where, { dept1: 1, dept2: 1, dept3: 1, dept4: 1, dept5: 1, name: 1, sex: 1, nation: 1, idNumber: 1,
- nativePlace: 1, address: 1, userid: 1, status: 1, phone: 1, ability: 1, demand: 1, birthday: 1, oldType: 1 }).sort({ time: -1 });
- return result;
- }
- async yestdayNum(data, user) {
- const { model } = this.ctx;
- const level = user.dept.level;
- const match = {};
- // admin的dept 存在冲突,所以它不需要结合
- if (user.role._id != this.app.config.defaultAdminRoleId) {
- match['dept' + level] = this.app.mongoose.Types.ObjectId(user.dept._id);
- }
- match.time = { $gte: data.yestday + ' 00:00:00', $lt: data.yestday + ' 23:59:59' };
- this.ctx.logger.info('条件===============================================', match);
- const finalarr = [];
- const vote = {};
- const nodonem = {};
- if (user.role._id != this.app.config.defaultAdminRoleId) {
- nodonem['dept' + level] = this.app.mongoose.Types.ObjectId(user.dept._id);
- }
- nodonem.time = { $gte: data.yestday + ' 00:00:00', $lt: data.yestday + ' 23:59:59' };
- nodonem.status = 0;
- const writenostum = {};
- if (user.role._id != this.app.config.defaultAdminRoleId) {
- writenostum['dept' + level] = this.app.mongoose.Types.ObjectId(user.dept._id);
- }
- writenostum.time = { $gte: data.yestday + ' 00:00:00', $lt: data.yestday + ' 23:59:59' };
- writenostum.status = 1;
- const stuingm = {};
- if (user.role._id != this.app.config.defaultAdminRoleId) {
- stuingm['dept' + level] = this.app.mongoose.Types.ObjectId(user.dept._id);
- }
- stuingm.time = { $gte: data.yestday + ' 00:00:00', $lt: data.yestday + ' 23:59:59' };
- stuingm.status = 2;
- const stuedm = {};
- if (user.role._id != this.app.config.defaultAdminRoleId) {
- stuedm['dept' + level] = this.app.mongoose.Types.ObjectId(user.dept._id);
- }
- stuedm.time = { $gte: data.yestday + ' 00:00:00', $lt: data.yestday + ' 23:59:59' };
- stuedm.status = 3;
- const fullstum = {};
- if (user.role._id != this.app.config.defaultAdminRoleId) {
- fullstum['dept' + level] = this.app.mongoose.Types.ObjectId(user.dept._id);
- }
- fullstum.time = { $gte: data.yestday + ' 00:00:00', $lt: data.yestday + ' 23:59:59' };
- fullstum.status = 4;
- const sumnum = await model.InfoModel.find(match).countDocuments();
- const nodone = await model.InfoModel.find(nodonem).countDocuments();
- const writenostu = await model.InfoModel.find(writenostum).countDocuments();
- const stuing = await model.InfoModel.find(stuingm).countDocuments();
- const stued = await model.InfoModel.find(stuedm).countDocuments();
- const fullstu = await model.InfoModel.find(fullstum).countDocuments();
- vote.sumnum = sumnum;
- vote.nodone = nodone;
- vote.writenostu = writenostu;
- vote.stuing = stuing;
- vote.stued = stued;
- vote.fullstu = fullstu;
- finalarr.push(vote);
- return finalarr;
- }
- }
- module.exports = InfoService;
|