Skip to content

Commit

Permalink
feat: 完善任务列表,消息列表接口;
Browse files Browse the repository at this point in the history
任务列表增加:创建的开始时间、创建的结束时间搜索字段;
  • Loading branch information
Imfdj committed Apr 16, 2021
1 parent 8f3036f commit 88d1235
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 7 deletions.
16 changes: 15 additions & 1 deletion app/controller/v1/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,28 @@ class RoleController extends Controller {
example: [1, 2],
},
};
const roles2 = {
date_start_created: {
type: 'dateTime',
required: false,
description: '创建的开始时间',
example: 'YYYY-MM-DD HH:mm:ss',
},
date_end_created: {
type: 'dateTime',
required: false,
description: '创建的结束时间',
example: 'YYYY-MM-DD HH:mm:ss',
},
};
const queries = Object.assign({}, ctx.query);
for (const key in rules) {
const data = ctx.queries[key];
if (data) {
queries[key] = lodash.isArray(data) ? lodash.map(data, lodash.parseInt) : data;
}
}
const { allRule, query } = ctx.helper.tools.findAllParamsDeal(ctx.rule.taskBodyReq, queries, rules);
const { allRule, query } = ctx.helper.tools.findAllParamsDeal(ctx.rule.taskBodyReq, queries, { ...rules, ...roles2 });
ctx.validate(allRule, query);
const res = await service.tasks.findAll(query);
ctx.helper.body.SUCCESS({ ctx, res });
Expand Down
1 change: 1 addition & 0 deletions app/model/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module.exports = app => {

message.associate = function(models) {
// associations can be defined here
message.hasOne(app.model.Users, { foreignKey: 'id', sourceKey: 'actor_id', as: 'actor' });
};
return message;
};
7 changes: 7 additions & 0 deletions app/service/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ class _objectName_Service extends Service {
offset,
where,
order: Order,
include: [
{
model: ctx.model.Users,
attributes: ['username', 'id', 'avatar'],
as: 'actor',
},
],
});
}

Expand Down
34 changes: 28 additions & 6 deletions app/service/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,36 @@ const { Op } = require('sequelize');
class _objectName_Service extends Service {
async findAll(payload) {
const { ctx } = this;
const { limit, offset, prop_order, order, name, executor_ids, creator_ids, task_priority_ids, task_state_ids } = payload;
const {
limit,
offset,
prop_order,
order,
name,
executor_ids,
creator_ids,
task_priority_ids,
task_state_ids,
date_start_created,
date_end_created,
} = payload;
const where = payload.where;
const Order = [];
where[Op.or] = [];
executor_ids ? where[Op.or].push({ executor_id: executor_ids }) : null;
creator_ids ? where[Op.or].push({ creator_id: creator_ids }) : null;
task_priority_ids ? where[Op.or].push({ task_priority_id: task_priority_ids }) : null;
task_state_ids ? where[Op.or].push({ task_state_id: task_state_ids }) : null;
date_start_created || date_end_created
? (where[Op.and] = [
{
created_at: {
[Op.gte]: date_start_created || '0001-01-01 00:00:01',
[Op.lte]: date_end_created || '9001-01-01 00:00:01',
},
},
])
: null;
if (!where[Op.or].length) {
delete where[Op.or];
}
Expand Down Expand Up @@ -110,7 +132,7 @@ class _objectName_Service extends Service {
const task = await ctx.model.Tasks.findOne({
where: { id: payload.id },
});
const taskNameSpan = `<span class="name">${task.name}</span>`;
const taskNameSpan = `<span class="task-name">${task.name}</span>`;
const taskLog = {
remark: '',
task_id: payload.id,
Expand Down Expand Up @@ -142,7 +164,7 @@ class _objectName_Service extends Service {
taskLog.remark = `修改执行状态为 ${state.name}`;
taskLog.icon = 'el-icon-pie-chart';
taskLog.type = 'state';
message.content = `更改了任务 ${taskNameSpan} 的执行状态为 ${state.name}`;
message.content = `更改了任务 ${taskNameSpan} 的执行状态为 <span class="state" style="color: ${state.color};">${state.name}</span>`;
}
if (app.lodash.has(payload, 'task_type_id')) {
const type = await ctx.model.TaskTypes.findOne({
Expand Down Expand Up @@ -194,7 +216,7 @@ class _objectName_Service extends Service {
});
taskLog.type = 'executor_assign';
taskLog.remark = `指派给了 ${executor.username}`;
message.content = `将任务 ${taskNameSpan} 指派给了 ${executor.username}`;
message.content = `将任务 ${taskNameSpan} 指派给了 <span class="executor">${executor.username}</span>`;
}
taskLog.icon = 'el-icon-user';
}
Expand Down Expand Up @@ -232,7 +254,7 @@ class _objectName_Service extends Service {
taskLog.remark = is_done === 1 ? '完成了任务' : '重做了任务';
taskLog.type = 'is_done';
taskLog.icon = 'el-icon-check';
message.content = `更改了任务 ${taskNameSpan} 的完成状态为 ${is_done === 1 ? '已完成' : '未完成'}`;
message.content = `更改了任务 ${taskNameSpan} 的完成状态为 ${is_done === 1 ? '<span class="done">已完成</span>' : '<span class="redo">未完成</span>'}`;
}
await ctx.model.TaskLogs.create(taskLog, { transaction });
const res = await ctx.model.Tasks.update(payload, {
Expand All @@ -251,7 +273,7 @@ class _objectName_Service extends Service {
message.receiver_id = userTask.user_id;
// 如果是执行者更改的指派情况,message的接收者和执行者的id相同
if (taskLog.type === 'executor_assign' && payload.executor_id === message.receiver_id) {
message.content = `指派给你一个任务 <span class="name">${task.name}</span>`;
message.content = `指派给你一个任务 ${taskNameSpan}`;
}
ctx.model.Messages.create(message);
});
Expand Down

0 comments on commit 88d1235

Please sign in to comment.