Untitled
unknown
plain_text
10 months ago
3.6 kB
12
Indexable
(async () => {
const app = {
isDebug: !__dirname.startsWith('/var/www/'),
fs: require('fs'),
path: require('path'),
};
let appConfig = require('../../package.json');
app.crypt = require('bcrypt');
app.assetPath = app.path.join(__dirname, '../../', appConfig.path.asset);
app.modulesPath = app.path.join(__dirname, '../../', appConfig.path.modules);
app.database = {};
app.model = {};
require('../../config/common')(app, appConfig);
require('../../config/database.mongoDB')(app, appConfig);
require('../../config/lib/excel')(app);
require('../../config/lib/fs')(app);
app.loadModules(false);
try {
const team_mapper = require('./team_mapper.json'),
division_mapper = require('./division_mapper.json'),
photos = await app.model.photo.getAll({}).then(i => i.slice(0, 100)),
count = photos.length;
const workBook = app.excel.create();
const ws = workBook.addWorksheet('HinhAnh');
ws.columns = [
{ header: 'Họ tên', key: 'fullname', width: 20 },
{ header: 'Số điện thoại', key: 'phone', width: 15 },
{ header: 'Chức vụ', key: 'position', width: 15 },
{ header: 'Loại phòng', key: 'loaiRoom', width: 15 },
{ header: 'Phòng', key: 'room', width: 15 },
{ header: 'Đơn vị', key: 'donVi', width: 30 },
{ header: 'Thư mục chứa', key: 'folderRelPath', width: 30 },
{ header: 'Trạng thái', key: 'active', width: 10 },
{ header: 'Thông điệp', key: 'note', width: 50 },
];
for (const [index, photo] of photos.entries()) {
console.log(`Start run ${index + 1}/${count}`)
let path = '', donVi = '';
if (photo.isTeam) {
if (photo.team) {
if (team_mapper[photo.team._id]) {
path = app.path.join(team_mapper[photo.team._id], photo.image);
} else path = app.path.join('bando/tw/tmp', photo.image);
donVi = photo.team.school;
}
} else {
if (photo.division) {
if (division_mapper[photo.division._id]) {
path = app.path.join(division_mapper[photo.division._id], photo.image);
} else path = app.path.join('bando/tw/tmp', photo.image);
donVi = photo.division.name;
}
}
if (photo.image && path) {
const src = app.path.join(app.assetPath, 'DivisionPhoto', photo.image);
const dest = app.path.join(app.assetPath, path);
if (app.fs.existsSync(src)) {
app.fs.copyFileSync(src, dest);
}
}
const row = ws.addRow({
'fullname': photo.fullname || '',
'phone': photo.phone || '',
'position': photo.position || '',
'loaiRoom': photo.loaiRoom || '',
'room': photo.room || '',
'note': photo.note || '',
'donVi': donVi,
'active': photo.active === true || photo.active === 1 ? 'Đã phê duyệt' : 'Chưa phê duyệt',
}, 'i');
row.getCell('folderRelPath').value = { text: photo.image, hyperlink: path || '' };
}
await workBook.xlsx.writeFile(app.path.join(app.assetPath, 'hinh_anh.xlsx'));
} catch (error) {
console.error('newBackup', error);
}
process.exit(1);
})();
Editor is loading...
Leave a Comment