Commit 027e538b by 王昆

'恒昌小程序导出数据'

parent 241621ec
...@@ -87,5 +87,34 @@ class BmuserbizDao extends Dao{ ...@@ -87,5 +87,34 @@ class BmuserbizDao extends Dao{
sql.push("AND t1.idcard = :idcard"); sql.push("AND t1.idcard = :idcard");
} }
} }
async findExportAll() {
let sql = [];
sql.push("SELECT ");
sql.push("t1.id,");
sql.push("t1.legal_name,");
sql.push("t1.legal_mobile,");
sql.push("t1.idcard,");
sql.push("t1.idcard_front,");
sql.push("t1.idcard_back,");
sql.push("REPLACE(t1.companyNames, '#com#', ',') AS names,");
sql.push("t1.bank,");
sql.push("t1.bankno,");
sql.push("t1.bank_front,");
sql.push("t1.bank_back,");
sql.push("t1.bankMobile,");
sql.push("t1.`front_half_img`,");
sql.push("t1.`declaration_file`,");
sql.push("DATE_FORMAT(t1.created_at, '%Y-%m-%d') AS submit_time,");
sql.push("CASE t2.audit_status WHEN '0' THEN '待审核' WHEN '1' THEN '审核通过' WHEN '2' THEN '审核失败' ELSE '' END AS audit_status_name,");
sql.push("t2.reject_reason");
sql.push("FROM");
sql.push("`bm_user_biz` t1");
sql.push("INNER JOIN `bm_order` t2 ON t1.`orderId` = t2.`id`");
sql.push("WHERE 1 = 1");
sql.push("ORDER BY id DESC");
return await this.customQuery(sql.join(" "));
}
} }
module.exports=BmuserbizDao; module.exports=BmuserbizDao;
const Sequelize = require('sequelize'); const Sequelize = require('sequelize');
const settings=require("../../../config/settings") const settings = require("../../../config/settings")
const fs=require("fs") const fs = require("fs")
const path=require("path"); const path = require("path");
class DbFactory{ class DbFactory {
constructor(){ constructor() {
const dbConfig=settings.database(); const dbConfig = settings.database();
this.db=new Sequelize(dbConfig.dbname, this.db = new Sequelize(dbConfig.dbname,
dbConfig.user, dbConfig.user,
dbConfig.password, dbConfig.password,
dbConfig.config); dbConfig.config);
this.db.Sequelize=Sequelize;
this.db.Op=Sequelize.Op; this.db.Sequelize = Sequelize;
this.db.Op = Sequelize.Op;
this.initModels(); this.initModels();
this.initRelations(); this.initRelations();
} }
async initModels(){ async initModels() {
var self=this; var self = this;
var modelpath=path.normalize(path.join(__dirname, '..'))+"/models/"; var modelpath = path.normalize(path.join(__dirname, '..')) + "/models/";
var models=fs.readdirSync(modelpath); var models = fs.readdirSync(modelpath);
models.forEach(function(m){ models.forEach(function (m) {
self.db.import(modelpath+m); self.db.import(modelpath + m);
}); });
console.log("init models...."); console.log("init models....");
} }
async initRelations(){ async initRelations() {
/**
一个账户对应多个登陆用户
一个账户对应一个commany
一个APP对应多个登陆用户
一个APP有多个角色
登陆用户和角色多对多
**/
/*建立用户和角色之间的关系*/
this.db.models.user.belongsToMany(this.db.models.role, {as:"Roles",through: 'p_userrole',constraints: false,});
this.db.models.role.belongsToMany(this.db.models.user, {as:"Users",through: 'p_userrole',constraints: false,});
/*建立频道和文章之间的关系*/
this.db.models.article.belongsTo(this.db.models.newschannel,{constraints: false,});
this.db.models.newschannel.hasMany(this.db.models.article,{constraints: false,});
} }
//async getCon(){,用于使用替换table模型内字段数据使用 //async getCon(){,用于使用替换table模型内字段数据使用
getCon(){ getCon() {
var that=this; var that = this;
// await this.db.authenticate().then(()=>{ // await this.db.authenticate().then(()=>{
// console.log('Connection has been established successfully.'); // console.log('Connection has been established successfully.');
// }).catch(err => { // }).catch(err => {
...@@ -49,9 +37,15 @@ class DbFactory{ ...@@ -49,9 +37,15 @@ class DbFactory{
// throw err; // throw err;
// }); // });
//同步模型 //同步模型
if(settings.env=="dev"){ if (settings.env == "dev") {}
}
return this.db; return this.db;
} }
getSettleDBCon() {
var that = this;
if (settings.env == "dev") {}
return this.settledb;
}
} }
module.exports=DbFactory; module.exports = DbFactory;
...@@ -11,14 +11,14 @@ function getBizFilePath(appJson,bizCode){ ...@@ -11,14 +11,14 @@ function getBizFilePath(appJson,bizCode){
} }
//异常日志处理todo //异常日志处理todo
function initAppBizs(appJson){ function initAppBizs(appJson){
for(var bizCode in appJson.config.bizs) for(var bizCode in appJson.config.bizs)
{ {
const bizfilePath=getBizFilePath(appJson,bizCode); const bizfilePath=getBizFilePath(appJson,bizCode);
delete require.cache[bizfilePath]; delete require.cache[bizfilePath];
const bizConfig=require(bizfilePath); const bizConfig=require(bizfilePath);
appJson.config.bizs[bizCode].config=bizConfig; appJson.config.bizs[bizCode].config=bizConfig;
} }
return appJson; return appJson;
} }
//初始化资源树 //初始化资源树
function initRsTree(appjson,appidfolder,objJson,parentCodePath){ function initRsTree(appjson,appidfolder,objJson,parentCodePath){
...@@ -42,12 +42,12 @@ function initRsTree(appjson,appidfolder,objJson,parentCodePath){ ...@@ -42,12 +42,12 @@ function initRsTree(appjson,appidfolder,objJson,parentCodePath){
} }
} }
} }
fs.readdirSync(appsPath,{withFileTypes:true}).forEach(f=>{ fs.readdirSync(appsPath).forEach(f=>{
const ff=path.join(appsPath,f); const ff=path.join(appsPath,f);
delete require.cache[ff]; delete require.cache[ff];
var appJson=require(ff); var appJson=require(ff);
appJson= initAppBizs(appJson); appJson= initAppBizs(appJson);
initRsTree(appJson,appJson.appid,appJson.config.rstree,null); initRsTree(appJson,appJson.appid,appJson.config.rstree,null);
appJsons[appJson.appid]=appJson; appJsons[appJson.appid]=appJson;
}); });
module.exports=appJsons; module.exports=appJsons;
...@@ -92,6 +92,10 @@ class BmuserbizService extends ServiceBase { ...@@ -92,6 +92,10 @@ class BmuserbizService extends ServiceBase {
} }
return page; return page;
} }
async findExportAll() {
return await this.dao.findExportAll();
}
} }
module.exports = BmuserbizService; module.exports = BmuserbizService;
var excel = require('exceljs'); var excel = require('exceljs');
const system=require("../system"); const system = require("../system");
const uuidv4 = require('uuid/v4'); const uuidv4 = require('uuid/v4');
const fs=require("fs"); const fs = require("fs");
const xlsx = require('node-xlsx')
const json2csv = require('json2csv');
class ExcelClient { class ExcelClient {
constructor() { constructor() {
this.columns = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']; this.columns = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
this.ossClient=system.getObject("util.ossClient"); this.ossClient = system.getObject("util.ossClient");
this.filedownloadDao = system.getObject("db.filedownloadDao"); this.restClient = system.getObject("util.restClient");
}
async download(params, cb) {
var self = this;
var title = params.title || "";
var code = params.code || uuidv4();
var fileName = params.fileName || code + ".xlsx";
var filePath = params.filePath || "/tmp/" + fileName;
var rows = params.rows || [];
var wb = new excel.Workbook();
wb.properties.date1904 = true;
var sheet = wb.addWorksheet("sheet1");
var headers = rows[0];
console.log(headers, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2 headers");
if (title) {
sheet.addRow([title]);
sheet.getCell("A1").font = {
name: '微软雅黑',
family: 4,
size: 12,
bold: true
};
sheet.getCell('A1').alignment = {
vertical: 'middle',
horizontal: 'center'
};
var colkey = 0;
if (headers.length > 0) {
colkey = headers.length - 1;
}
var endColumn = this.columns[colkey] || "A";
sheet.mergeCells("A1:" + endColumn + "1");
} }
async download(params) { for (var r of rows) {
var self = this; sheet.addRow(r);
}
var title = params.title || "";
var code = params.code || uuidv4(); wb.xlsx.writeFile(filePath).then(async function (d) {
var fileName = params.fileName || code + ".xlsx"; var rtn = await self.ossClient.upfile(fileName, filePath);
var filePath = params.filePath || "/tmp/" + fileName; // fs.unlink(filePath, function (err) {});
var rows = params.rows || []; fs.unlinkSync(filePath);
var user = params.user || {}; if (cb) {
cb(rtn.url);
var wb = new excel.Workbook(); }
wb.properties.date1904 = true; });
var sheet = wb.addWorksheet("sheet1"); }
var headers = rows[0];
console.log(headers, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2 headers"); async readExcel(id, ossurl) {
if(title) { var result = {
sheet.addRow([title]); code: 0,
sheet.getCell("A1").font = { data: [],
    name: '微软雅黑', };
    family: 4, var names = [];
    size: 12, var filePath = "/tmp/ecompany_contract_" + id + ".xlsx";
    bold: true try {
}; await this.restClient.execDownload("'" + ossurl + "'", filePath);
sheet.getCell('A1').alignment = { vertical: 'middle', horizontal: 'center' };
var sheets = xlsx.parse(filePath);
var colkey = 0; // fs.unlink(filePath, e => {
if(headers.length > 0) { // console.log("fail");
colkey = headers.length - 1; // });
} fs.unlinkSync(filePath);
var endColumn = this.columns[colkey] || "A";
sheet.mergeCells("A1:" + endColumn + "1");
if (!sheets || sheets.length == 0) {
return result;
} }
for(var r of rows) { var sheet = sheets[0];
sheet.addRow(r); if (!sheet || !sheet.data || sheet.data.length == 0) {
return result;
} }
wb.xlsx.writeFile(filePath).then(async function(d) { var rows = sheet.data;
var rtn = await self.ossClient.upfile(fileName, filePath);
fs.unlink(filePath,function(err){}); for (var idx in rows) {
var obj = { if (idx == 0) {
user_id : user.id || 0, continue;
userName : user.userName || "", }
code : code,
fileName : fileName, var cells = rows[idx];
filePath : rtn.url || "", if (!cells || cells.length == 0 || !cells[0]) {
isDownload : false, continue;
} }
var obj = await self.filedownloadDao.create(obj); var c = cells[0];
}); if (names.indexOf(c) > -1) {
continue;
}
names.push(c);
}
console.log(sheet);
result.code = 1;
result.data = names;
return result;
} catch (error) {
console.log(error.stack);
return result;
}
}
async exportCsv(req, res, csvobj) {
var userAgent = (req.headers['user-agent'] || '').toLowerCase();
var fileName = csvobj.fileName || new Date().getTime();
if (userAgent.indexOf('msie') >= 0 || userAgent.indexOf('chrome') >= 0) {
await res.setHeader('Content-Disposition', 'attachment; filename=' + encodeURIComponent(fileName));
} else if (userAgent.indexOf('firefox') >= 0) {
await res.setHeader('Content-Disposition', 'attachment; filename*="utf8\'\'' + encodeURIComponent(fileName) + '"');
} else {
await res.setHeader('Content-Disposition', 'attachment; filename=' + new Buffer(fileName).toString('binary'));
}
await res.writeHead(200,{'Content-Type':'application/octet-stream;charset=utf-8'});
let csv = json2csv.parse(csvobj.rows, csvobj.opts);
if(csvobj.headers) {
for(var field of csvobj.opts.fields) {
csv = csv.replace(field, csvobj.headers[field]);
}
} }
await res.write("\uFEFF" + csv);
await res.write('\n');
}
} }
module.exports = ExcelClient; module.exports = ExcelClient;
\ No newline at end of file
...@@ -22,6 +22,7 @@ class xggApplet extends AppletBase { ...@@ -22,6 +22,7 @@ class xggApplet extends AppletBase {
this.uploadCtl=system.getObject("web.uploadCtl"); this.uploadCtl=system.getObject("web.uploadCtl");
this.idcardClient = system.getObject("util.idcardClient"); this.idcardClient = system.getObject("util.idcardClient");
this.excelClient = system.getObject("util.excelClient");
this.merchantId = 1; this.merchantId = 1;
} }
...@@ -569,5 +570,48 @@ class xggApplet extends AppletBase { ...@@ -569,5 +570,48 @@ class xggApplet extends AppletBase {
return {code: 500}; return {code: 500};
} }
} }
async exportAll(gobj, req, res){
try {
let list = await this.bmuserbizSve.findExportAll();
let csvobj = {
fileName: "恒昌小程序数据" + moment().format("YYYYMMDDHHmmss") + ".csv",
rows: list,
opts: {
fields: ['id', 'legal_name', 'legal_mobile', 'idcard', 'idcard_front', 'idcard_back', 'names',
'bank', 'bankno', 'bank_front', 'bank_back', 'bankMobile',
'front_half_img', 'declaration_file', 'submit_time', 'audit_status_name', 'reject_reason'],
unwind: [],
unwindBlank: true,
excelStrings: true,
},
headers: {
'id': '编号',
'legal_name': '姓名',
'legal_mobile': '手机号',
'idcard': '身份证',
'idcard_front': '身份证正面',
'idcard_back': '身份证反面',
'names': '注册名称',
'bank': '开户行',
'bankno': '银行卡号',
'bank_front': '银行卡正面',
'bank_back': '银行卡背面',
'bankMobile': '预留手机号',
'front_half_img': '半身照',
'declaration_file': '声明书',
'submit_time': '提交时间',
'audit_status_name': '审核状态',
'reject_reason': '不通过原因',
},
};
await this.excelClient.exportCsv(req, res, csvobj);
} catch (e) {
console.log(e);
return system.getErrResult2("您的网络不稳, 请稍后重试");
}
}
} }
module.exports = xggApplet; module.exports = xggApplet;
\ No newline at end of file
...@@ -27,6 +27,7 @@ module.exports = function (app) { ...@@ -27,6 +27,7 @@ module.exports = function (app) {
} }
} }
params.push(req); params.push(req);
params.push(res);
var p = null; var p = null;
var invokeObj = System.getObject("applet." + classPath); var invokeObj = System.getObject("applet." + classPath);
if (invokeObj[methodName]) { if (invokeObj[methodName]) {
...@@ -65,6 +66,7 @@ module.exports = function (app) { ...@@ -65,6 +66,7 @@ module.exports = function (app) {
var cacheManager = System.getObject("db.cacheManager"); var cacheManager = System.getObject("db.cacheManager");
params.push(req); params.push(req);
params.push(res);
var key = req.body.key; var key = req.body.key;
if (key) { if (key) {
//如果是 创富 merchantId=3 key = merchant_openId //如果是 创富 merchantId=3 key = merchant_openId
......
...@@ -228,6 +228,7 @@ ...@@ -228,6 +228,7 @@
<div> <div>
<div style="line-height: 36px;padding-bottom: 20px;"> <div style="line-height: 36px;padding-bottom: 20px;">
<span style="float:left;color:#2F2F2F;font-size: 14px;">共{{search.total}}条记录</span> <span style="float:left;color:#2F2F2F;font-size: 14px;">共{{search.total}}条记录</span>
<el-button @click="exportAll()" style="float:right;width:110px;height:36px;color: #FFFFFF;font-weight: 400;border-radius: 4px;font-size: 14px;background-color: #59C1A6;padding-top:11px">导出全部</el-button>
</div> </div>
<div> <div>
<el-table <el-table
......
...@@ -135,6 +135,11 @@ var app = new Vue({ ...@@ -135,6 +135,11 @@ var app = new Vue({
self.auditLoading = false; self.auditLoading = false;
}); });
}, },
exportAll(){
console.log('export all');
window.open("/applet/xggApplet/exportAll");
},
topic_preview(filed) { topic_preview(filed) {
let url = this.auditItem[filed || ""]; let url = this.auditItem[filed || ""];
if(url) { if(url) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment