Browse Source

自定义项目集列表查询

dev
CODE 1 year ago
parent
commit
dced4131b2
  1. 20
      api/app/lib/controllers/equipment/index.js
  2. 10
      api/app/lib/controllers/operationData/index.js
  3. 27
      api/app/lib/controllers/project/group.js
  4. 6
      api/app/lib/routes/index.js
  5. 3
      api/app/lib/routes/project/index.js

20
api/app/lib/controllers/equipment/index.js

@ -2,13 +2,13 @@
const moment = require('moment');
//设备维护记录
async function getEquipment(ctx) {
async function getEquipment (ctx) {
try {
const { models } = ctx.fs.dc
const sequelize = ctx.fs.dc.ORM
const { clickHouse } = ctx.app.fs
const { startTime, endTime, pageSize, pageIndex, projectId } = ctx.query
console.log('ressss', ctx.query)
let whereOption = {}
if (projectId) {
whereOption.projectId = projectId
@ -16,7 +16,6 @@ async function getEquipment(ctx) {
whereOption = undefined
}
//console.log('6666', ctx.query)
let resCount = await models.EquipmentMaintenanceRecord.count({
include: [{
model: models.EquipmentMaintenanceRecordProject,
@ -28,8 +27,6 @@ async function getEquipment(ctx) {
// sequelize.where(sequelize.fn('date', sequelize.col('report_time')), '>=', moment(startTime).format('YYYY-MM-DD HH:mm:ss')),
// sequelize.where(sequelize.fn('date', sequelize.col('report_time')), '<=', moment(endTime).format('YYYY-MM-DD HH:mm:ss')),
// ],
}
})
const res = await models.EquipmentMaintenanceRecord.findAll({
@ -54,7 +51,6 @@ async function getEquipment(ctx) {
// sequelize.where(sequelize.fn('date', sequelize.col('report_time')), '>=', moment(startTime).format('YYYY-MM-DD HH:mm:ss')),
// sequelize.where(sequelize.fn('date', sequelize.col('report_time')), '<=', moment(endTime).format('YYYY-MM-DD HH:mm:ss')),
// ],
}
})
//用户id
@ -105,13 +101,13 @@ async function getEquipment(ctx) {
}
}
//编辑和新增
async function editEquipment(ctx) {
async function editEquipment (ctx) {
const transaction = await ctx.fs.dc.orm.transaction();
const query = ctx.request.body
try {
const { models } = ctx.fs.dc
const sequelize = ctx.fs.dc.ORM
console.log('query1111', query)
const { id, completedTime, deviceType, model, reason, reportTime, solution, status, solver, projectId } = query
if (id) {
await models.EquipmentMaintenanceRecord.update({
@ -162,8 +158,6 @@ async function editEquipment(ctx) {
}
}
await transaction.commit();
ctx.status = 204
} catch (error) {
@ -176,7 +170,7 @@ async function editEquipment(ctx) {
}
}
//删除
async function delEquipment(ctx) {
async function delEquipment (ctx) {
const transaction = await ctx.fs.dc.orm.transaction();
try {
const params = ctx.params
@ -196,10 +190,6 @@ async function delEquipment(ctx) {
}
}
module.exports = {
getEquipment, editEquipment, delEquipment
};

10
api/app/lib/controllers/operationData/index.js

@ -2,7 +2,7 @@
const moment = require('moment')
//const db = require('../')
async function getFailureTime(ctx) {
async function getFailureTime (ctx) {
const sequelize = ctx.fs.dc.orm
try {
const res = await sequelize.query(
@ -20,7 +20,7 @@ async function getFailureTime(ctx) {
GROUP BY w.wmonth,e.counts
ORDER BY w.wmonth asc`
)
console.log('111112232', res)
let resList = []
if (res.length > 0) {
res[0].forEach((item) => {
@ -39,7 +39,7 @@ async function getFailureTime(ctx) {
}
}
async function getSystemAvailability(ctx) {
async function getSystemAvailability (ctx) {
const sequelize = ctx.fs.dc.orm
try {
const res = await sequelize.query(
@ -80,7 +80,7 @@ async function getSystemAvailability(ctx) {
}
}
async function getProblemType(ctx) {
async function getProblemType (ctx) {
const sequelize = ctx.fs.dc.orm
try {
const res = await sequelize.query(`
@ -106,7 +106,7 @@ async function getProblemType(ctx) {
}
}
}
async function getOperationsPersonnel(ctx) {
async function getOperationsPersonnel (ctx) {
const sequelize = ctx.fs.dc.orm
const { clickHouse } = ctx.app.fs
try {

27
api/app/lib/controllers/project/group.js

@ -103,8 +103,35 @@ async function delGroup (ctx) {
}
}
async function groupStatic (ctx) {
try {
const { models } = ctx.fs.dc;
const { userId } = ctx.fs.api
const { clickHouse } = ctx.app.fs
const sequelize = ctx.fs.dc.orm
const groupProjectRes = await sequelize.query(`
SELECT * FROM project_correlation
LEFT JOIN project_group
ON project_correlation.id = ANY(project_group.poms_project_ids)
WHERE project_group.poms_user_id = ${userId}
`)
ctx.status = 200;
ctx.body = []
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`);
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined
}
}
}
module.exports = {
groupList,
editGroup,
delGroup,
groupStatic,
};

6
api/app/lib/routes/index.js

@ -8,7 +8,13 @@ module.exports = function (app, router, opts) {
if (filename.indexOf('.') !== 0 && fs.lstatSync(path.join(__dirname, filename)).isDirectory()) {
fs.readdirSync(path.join(__dirname, filename)).forEach((api) => {
if (api.indexOf('.') == 0 || api.indexOf('.js') == -1) return;
try {
console.log(`加载路由文件 ${filename}/${api}`);
require(`./${filename}/${api}`)(app, router, opts);
} catch (error) {
console.error(error);
process.exit(-1);
}
});
}
});

3
api/app/lib/routes/project/index.js

@ -39,4 +39,7 @@ module.exports = function (app, router, opts) {
app.fs.api.logAttr['DEL/project/group'] = { content: '删除项目分组', visible: true };
router.delete('/project/group', projectGroup.delGroup);
app.fs.api.logAttr['GET/project/group/static'] = { content: '获取项目分组统计信息', visible: true };
router.get('/project/group/static', projectGroup.groupStatic);
};
Loading…
Cancel
Save