|
|
@ -707,7 +707,9 @@ async function getPositionRating(ctx) { |
|
|
|
const { models } = ctx.fs.dc; |
|
|
|
const { limit, page } = ctx.query; |
|
|
|
|
|
|
|
const findObj = {}; |
|
|
|
const findObj = { |
|
|
|
order: [["ratingTime", "desc"]] |
|
|
|
}; |
|
|
|
if (Number(limit) > 0 && Number(page) >= 0) { |
|
|
|
findObj.limit = Number(limit); |
|
|
|
findObj.offset = Number(page) * Number(limit); |
|
|
@ -786,25 +788,23 @@ async function postPositionRating(ctx) { |
|
|
|
|
|
|
|
//处理新增的
|
|
|
|
if (data) { |
|
|
|
if (data.length) { |
|
|
|
const dataToSave = []; |
|
|
|
const dataToUpdate = []; |
|
|
|
if (data.length) { |
|
|
|
data.map((item) => { |
|
|
|
const { pepUserId, technicalGrade } = item; |
|
|
|
dataToUpdate.push({ pepUserId, technicalGrade }); |
|
|
|
}) |
|
|
|
await models.PositionRating.bulkCreate(data, { transaction }); |
|
|
|
for (let item in dataToUpdate) { |
|
|
|
await models.Member.update({ technicalGrade: dataToUpdate[item].technicalGrade }, |
|
|
|
{ where: { pepUserId: dataToUpdate[item].pepUserId }, transaction }); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
await models.PositionRating.create(data, { transaction }); |
|
|
|
await models.Member.update({ technicalGrade: data.technicalGrade }, |
|
|
|
{ where: { pepUserId: data.pepUserId }, transaction }); |
|
|
|
dataToUpdate.push({ pepUserId: data.pepUserId, technicalGtechnicalGrade: data.technicalGraderade }); |
|
|
|
} |
|
|
|
|
|
|
|
for (let item in dataToUpdate) { |
|
|
|
await models.Member.update({ technicalGrade: dataToUpdate[item].technicalGrade }, |
|
|
|
{ where: { pepUserId: dataToUpdate[item].pepUserId }, transaction }); |
|
|
|
} |
|
|
|
//更新member表字段
|
|
|
|
} |
|
|
|
|
|
|
|
await transaction.commit(); |
|
|
@ -824,11 +824,30 @@ async function delPositionRating(ctx) { |
|
|
|
|
|
|
|
const oldData = await models.PositionRating.findOne({ where: { id: id } }); |
|
|
|
if (oldData) { |
|
|
|
//todo 更新memeber技术等级字段
|
|
|
|
const positionRating = await models.PositionRating.findAll({ |
|
|
|
where: { |
|
|
|
pepUserId: oldData.pepUserId, |
|
|
|
id: { $not: oldData.id } |
|
|
|
}, |
|
|
|
attributes: ["technicalGrade"], |
|
|
|
order: [["ratingTime", "desc"]] |
|
|
|
}); |
|
|
|
//更新员工信息中的技术等级
|
|
|
|
const technicalGrade = positionRating.length ? positionRating[0].technicalGrade : undefined; |
|
|
|
await models.Member.update({ technicalGrade: technicalGrade }, |
|
|
|
{ |
|
|
|
where: { pepUserId: oldData.pepUserId, del: false }, |
|
|
|
transaction |
|
|
|
}); |
|
|
|
|
|
|
|
await models.PositionRating.destroy({ where: { id: id }, transaction }); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
transaction.commit(); |
|
|
|
ctx.status = 204; |
|
|
|
} catch (error) { |
|
|
|
transaction.rollback(); |
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = { |
|
|
|