Browse Source

(*) 去掉无用代码

master
liujiangyong 2 years ago
parent
commit
e26d8f4776
  1. 4
      api/.vscode/launch.json
  2. 208
      api/app/lib/schedule/hideDangerStatistic.js
  3. 16
      api/config.js

4
api/.vscode/launch.json

@ -27,10 +27,6 @@
"--qnsk w6j2ixR_i-aelc6I7S3HotKIX-ukMzcKmDfH6-M5",
"--qnbkt anxinyun-test",
"--qndmn http://test.resources.anxinyun.cn",
"--aliOssAccessKey LTAI5tNDfn7UhStYQcn3JBtw",
"--aliOssSecretKey rnoXtDWQA1djJ5Xqcdn1OSEol0lVyv",
"--aliOssBucket test-c371",
"--aliOssRegion oss-cn-hangzhou",
"--wxDomain https://api.weixin.qq.com",
"--wxAppId wxdd82ae635b22ccdb",
"--wxAppSecret 08e3d4ea9484cd7837d171e7af7c7db8",

208
api/app/lib/schedule/hideDangerStatistic.js

@ -1,208 +0,0 @@
const fs = require('fs');
const moment = require('moment')
const path = require('path')
const OSS = require('ali-oss');
const uuid = require('uuid');
const TEST = false
// const TEST = true
module.exports = function (app, opts) {
const hideDangerStatistic = app.fs.scheduleInit(
// 按月、季度、年统计隐患整改
{
interval: '0 32 4 1 */1 *',
immediate: TEST,
proRun: !TEST,
},
async () => {
const { aliOss } = opts
const { utils: { simpleExcelDown } } = app.fs;
try {
const { models } = app.fs.dc
const today = moment()
const date = today.date()
const month = today.month() + 1
const quarter = today.quarter()
const year = today.year()
const client = new OSS({
// yourRegion填写Bucket所在地域。以华东1(杭州)为例,Region填写为oss-cn-hangzhou。
region: aliOss.region,
// 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
accessKeyId: aliOss.accessKey,
accessKeySecret: aliOss.secretKey,
// 填写Bucket名称,例如examplebucket。
bucket: aliOss.bucket,
});
const statistic = async (startTime, endTime, type, timeShow, typeEnglish, time) => {
const siteRectifyRes = await models.HideDangerRectifySites.findAll({
where: {},
distinct: true,
include: [{
model: models.Site,
attributes: ['id', 'name'],
}, {
model: models.HideDangerDispose,
order: [['id', 'ASC']],
// include: [{
// model: models.User,
// attributes: ['id', 'displayName'],
// }]
}, {
model: models.HideDangerRectify,
where: {
createTime: {
$between: [
startTime.format('YYYY-MM-DD HH:mm:ss'),
endTime.format('YYYY-MM-DD HH:mm:ss')
]
}
},
},]
})
let reportHeader = [{
title: "工程项目名称",
key: "siteName",
}, {
title: "整改任务名称",
key: "name",
}, {
title: "提交时间",
key: "submitTime",
}, {
title: "审批状态",
key: "state",
},]
let reportData = []
let siteMap = new Set()
let completedRectifyCount = 0
let uncompletedRectifyCount = 0
for (let s of siteRectifyRes) {
siteMap.add(s.siteId);
let sts = s.status
let stsChinese = ''
if (sts == 0) {
stsChinese = '待整改'
} else if (sts == 1) {
stsChinese = '待审批'
} else if (sts == 2) {
stsChinese = '待复审'
} else if (sts == 3 || sts == 4) {
stsChinese = '审批驳回'
} else if (sts == 5) {
stsChinese = '审批通过'
}
if (
s.hideDangerDisposes.length
&& s.hideDangerDisposes.some(sd => sd.type == 3 && sd.admit)
) {
completedRectifyCount++
} else {
uncompletedRectifyCount++
}
reportData.push({
siteName: s.dataValues.site.dataValues.name,
name: s.dataValues.hideDangerRectify.dataValues.name,
submitTime: s.dataValues.lastDisposeTime ? moment(s.dataValues.lastDisposeTime).format('YYYY-MM-DD HH:mm:ss') : '',
state: stsChinese
})
}
const fileName = `中鼎国际隐患整改数据报表-${type}-${timeShow}` + '.xlsx'
const filePath = await simpleExcelDown({
data: reportData, header: reportHeader, fileName
})
// const fileData = fs.readFileSync(filePath);
// 保存文件到云
let uploadPath = path.posix.join('hideDangerReport', uuid.v4(), fileName);
let uploadResult = await client.put(
uploadPath,
filePath,
// { contentLength: size }
);
//保存信息到数据库
const existReportRes = await models.HideDangerReport.findOne({
where: {
type: typeEnglish,
time: String(time),
}
})
const storageData = {
siteCount: siteMap.size,
rectifyCount: completedRectifyCount + uncompletedRectifyCount,
completedRectifyCount,
uncompletedRectifyCount,
report: uploadResult.name,
type: typeEnglish,
time: String(time),
}
if (existReportRes) {
await models.HideDangerReport.update(storageData, {
where: {
id: existReportRes.id
}
})
} else {
await models.HideDangerReport.create(storageData)
}
}
if (month == 1) {
// 统计一下上一年
let startTime = today.clone().subtract(1, 'year').startOf('year')
let endTime = today.clone().subtract(1, 'year').endOf('year')
await statistic(
startTime,
endTime,
'年报',
`${startTime.year()}${startTime.month() + 1}-${endTime.month() + 1}`,
'year',
startTime.year()
)
}
if ([1, 4, 7, 10].includes(month)) {
// 统计一下上季度
let startTime = today.clone().subtract(3, 'month').startOf('month')
let endTime = today.clone().subtract(1, 'month').endOf('month')
await statistic(
startTime,
endTime,
'季报',
`${startTime.year()}${startTime.month() + 1}-${endTime.month() + 1}`,
'quarter',
`${startTime.year()}-${month == 1 ? 'Q4' : month == 4 ? 'Q1' : month == 7 ? 'Q2' : 'Q3'}`
)
}
// 统计一下上个月
let startTime = today.clone().subtract(1, 'month').startOf('month')
let endTime = today.clone().subtract(1, 'month').endOf('month')
await statistic(
startTime,
endTime,
'月报',
`${startTime.year()}${startTime.month() + 1}`,
'month',
startTime.format('YYYY-MM')
)
} catch (error) {
app.fs.logger.error(`sechedule: hideDangerStatistic, error: ${error}`);
}
}
);
return {
hideDangerStatistic
}
}

16
api/config.js

@ -16,10 +16,6 @@ args.option('qnak', 'qiniuAccessKey');
args.option('qnsk', 'qiniuSecretKey');
args.option('qnbkt', 'qiniuBucket');
args.option('qndmn', 'qiniuDomain');
args.option('aliOssAccessKey', '阿里OSS AccessKey');
args.option('aliOssSecretKey', '阿里OSS SecretKey');
args.option('aliOssBucket', '阿里OSS Bucket');
args.option('aliOssRegion', '阿里OSS Region');
args.option('wxDomain', '微信API Domain');
args.option('wxAppId', '微信小程序appid');
args.option('wxAppSecret', '微信小程序AppSecret');
@ -34,12 +30,6 @@ const QINIU_BUCKET_RESOURCE = process.env.ANXINCLOUD_QINIU_BUCKET_RESOURCE || fl
const QINIU_AK = process.env.ANXINCLOUD_QINIU_ACCESSKEY || flags.qnak;
const QINIU_SK = process.env.ANXINCLOUD_QINIU_SECRETKEY || flags.qnsk;
//阿里OSS
const ALI_OSS_ACCESSKEY = process.env.ALI_OSS_ACCESSKEY || flags.aliOssAccessKey;
const ALI_OSS_SECRETKET = process.env.ALI_OSS_SECRETKET || flags.aliOssSecretKey;
const ALI_OSS_BUCKET = process.env.ALI_OSS_BUCKET || flags.aliOssBucket;
const ALI_OSS_REGION = process.env.ALI_OSS_REGION || flags.aliOssRegion;
// 微信小程序参数
const WX_DOMAIN = process.env.WX_DOMAIN || flags.wxDomain;
const WX_APP_ID = process.env.WX_APP_ID || flags.wxAppId;
@ -92,12 +82,6 @@ const product = {
accessKey: QINIU_AK,
secretKey: QINIU_SK
},
aliOss: {
accessKey: ALI_OSS_ACCESSKEY,
secretKey: ALI_OSS_SECRETKET,
bucket: ALI_OSS_BUCKET,
region: ALI_OSS_REGION
},
sms: {
///阿里云-安心云
accessKey: 'LTAI5tAFdjz7j38aNF2C9Qe8',

Loading…
Cancel
Save