diff --git a/api/app/lib/controllers/member/index.js b/api/app/lib/controllers/member/index.js index ae97fd8..92c310f 100644 --- a/api/app/lib/controllers/member/index.js +++ b/api/app/lib/controllers/member/index.js @@ -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) { + const dataToUpdate = []; if (data.length) { - const dataToSave = []; - const dataToUpdate = []; 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 = { diff --git a/web/client/src/sections/humanAffairs/components/importPositionRating.jsx b/web/client/src/sections/humanAffairs/components/importPositionRating.jsx index 3adcc5d..7db7f33 100644 --- a/web/client/src/sections/humanAffairs/components/importPositionRating.jsx +++ b/web/client/src/sections/humanAffairs/components/importPositionRating.jsx @@ -32,11 +32,12 @@ const ImportPositionRatingModal = props => { } const download = () => { - const head = [Object.keys(IMPORT_FIELD).map(key => IMPORT_FIELD[key].label)]; + const head = Object.keys(IMPORT_FIELD).map(key => IMPORT_FIELD[key].label); + head.unshift("姓名"); let workbook = { SheetNames: [SHEETNAME], Sheets: {} }; - workbook.Sheets[SHEETNAME] = XLSX.utils.aoa_to_sheet(head);//json转excel + workbook.Sheets[SHEETNAME] = XLSX.utils.aoa_to_sheet([head]);//json转excel workbook.Sheets[SHEETNAME]['!cols'] = [ - { wch: 13 }, { wch: 12 }, { wch: 18 }, { wch: 30 }, { wch: 11 }, + { wch: 13 }, { wch: 13 }, { wch: 12 }, { wch: 18 }, { wch: 30 }, { wch: 11 }, { wch: 30 }, { wch: 13 }]; let wopts = { bookType: 'xlsx', type: 'buffer' };// 生成excel的配置项 XLSX.writeFile(workbook, `${SHEETNAME}导入模板.xlsx`, wopts); @@ -152,9 +153,9 @@ const ImportPositionRatingModal = props => { if (!member) { errmsg = `第${i + 2}行【${IMPORT_FIELD[item].label}】${obj.userCode}未匹配到数据,请检查该员工是否添加`; break; - } else if (postData.find(m => m.userCode == obj.userCode)) { - errmsg = `第${i + 2}行【${IMPORT_FIELD[item].label}】${obj.userCode}已存在,请检查`; - break; + // } else if (postData.find(m => m.userCode == obj.userCode)) { + // errmsg = `第${i + 2}行【${IMPORT_FIELD[item].label}】${obj.userCode}已存在,请检查`; + // break; } else { obj.pepUserId = member.pepUserId; } diff --git a/web/client/src/sections/humanAffairs/containers/employeeInformation.jsx b/web/client/src/sections/humanAffairs/containers/employeeInformation.jsx index 1fcdeff..f3253ac 100644 --- a/web/client/src/sections/humanAffairs/containers/employeeInformation.jsx +++ b/web/client/src/sections/humanAffairs/containers/employeeInformation.jsx @@ -263,7 +263,7 @@ const employeeInformation = (props) => { width: 150, dataIndex: "technicalGrade", key: "technicalGrade", - render: (_, r, index) => -, + // render: (_, r, index) => -, }, { title: '证件号', width: 180, diff --git a/web/client/src/sections/humanAffairs/containers/positionRating.jsx b/web/client/src/sections/humanAffairs/containers/positionRating.jsx index c24c828..41b40b2 100644 --- a/web/client/src/sections/humanAffairs/containers/positionRating.jsx +++ b/web/client/src/sections/humanAffairs/containers/positionRating.jsx @@ -93,7 +93,7 @@ const PositionRating = (props) => { }, { title: (