From b8c532cef39d0f9361e3f84a2d87f0077c6fd4a3 Mon Sep 17 00:00:00 2001 From: wuqun Date: Mon, 17 Oct 2022 11:02:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=BA=E5=91=98=E6=A1=A3=E6=A1=88-=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E5=91=98=E5=B7=A5=E4=BF=A1=E6=81=AF,=20=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E6=A0=A1=E9=AA=8C,=20=E6=8E=A5=E5=8F=A3=E8=B0=83?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/member/index.js | 4 +- .../containers/import-members-modal.js | 131 ++++++++++++------ .../containers/personnelFiles.jsx | 12 +- .../containers/table-input-rule.js | 2 +- 4 files changed, 95 insertions(+), 54 deletions(-) diff --git a/api/app/lib/controllers/member/index.js b/api/app/lib/controllers/member/index.js index e154269..7e91a28 100644 --- a/api/app/lib/controllers/member/index.js +++ b/api/app/lib/controllers/member/index.js @@ -385,7 +385,7 @@ async function list(ctx) { } async function addMembersBulk(ctx) { - let errorMsg = { message: '批量添加员工信息失败' }; + let errorMsg = { message: '导入员工信息失败' }; const transaction = await ctx.fs.dc.orm.transaction(); try { const models = ctx.fs.dc.models; @@ -396,7 +396,7 @@ async function addMembersBulk(ctx) { attributes: ['pepUserId'] }); data.map(d => { - let exist = memberList.find(d => d.pepUserId == d.number);//项企的人员编号字段还没有 + let exist = memberList.find(d => d.pepUserId == d.pepUserId);//项企的人员编号字段还没有 if (exist) { editMembers.push(d); } else { diff --git a/web/client/src/sections/humanAffairs/containers/import-members-modal.js b/web/client/src/sections/humanAffairs/containers/import-members-modal.js index c0795cc..923591e 100644 --- a/web/client/src/sections/humanAffairs/containers/import-members-modal.js +++ b/web/client/src/sections/humanAffairs/containers/import-members-modal.js @@ -1,4 +1,5 @@ 'use strict'; +import moment from 'moment'; import React, { useState } from 'react'; import { connect } from 'react-redux'; import { Modal, Form, Button, Notification } from '@douyinfe/semi-ui'; @@ -10,7 +11,7 @@ import ExportJsonExcel from 'js-export-excel'; import { rule } from './table-input-rule' //下载模板和上传文件读取 const ImportMembersModal = props => { - const { dispatch, onCancel } = props + const { dispatch, onCancel, xqMembers } = props const [msg, setMsg] = useState('') const [loading, setLoading] = useState('') const [postData, setPostData] = useState([]) @@ -20,13 +21,13 @@ const ImportMembersModal = props => { setLoading(true) dispatch(membersBulkAdd(postData)).then(res => { if (res.success) { - Notification.success('导入员工信息成功') + //Notification.success({ content: '导入员工信息成功', duration: 2 }) onCancel() } setLoading(false) }) } else { - Notification.warn('没有数据可以提交,请上传数据文件') + Notification.warning({ content: '没有数据可以提交,请上传数据文件', duration: 2 }) } } @@ -110,6 +111,9 @@ const ImportMembersModal = props => { const judgePlace = (place) => { let valid = true; + if (!place) {//可以不填 + return valid; + } if (place.split('-').length == 1) {//判断籍贯 if (['北京市', '上海市', '天津市', '重庆市'].indexOf(place) == -1) { valid = false; @@ -132,10 +136,35 @@ const ImportMembersModal = props => { return valid; } + const judgeTimeValid = (time) => { + let valid = true; + if (!time) { + return valid;//可以不填 + } + const ymd = /^((19|20)[0-9]{2})[\/\-]((0[1-9])|(1[0-2]))[\/\-]((0[1-9])|((1|2)[0-9])|(3[0-1]))$/;//年月日 + if (time instanceof Date) { + let timeStr = moment(time).format('YYYY/MM/DD'); + if (!ymd.test(timeStr)) { + valid = false; + } + } else { + valid = false; + } + return valid; + } + const judgeNull = (value) => { return value ? String(value).trim().replace(/\s*/g, "") : null; } + const judgeNullTime = (v) => { + //注意的点:xlsx将excel中的时间内容解析后,会小一天 + //如2020/8/1,xlsx会解析成 Fri Jul 31 2020 23:59:17 GMT+0800 小了43秒 + let a = new Date(v); + a.setTime(a.getTime() + 43 * 1000); + return v ? a : null; + } + return ( { label={'员工信息'} labelPosition='left' action={'/'} accept={fileLimit} maxSize={200} limit={1} + onRemove={(currentFile, fileList, fileItem) => { + setMsg(''); + setPostData([]); + }} customRequest={(data) => { const { file, onSuccess, onError } = data getFileBlob(file.url).then(res => { @@ -173,7 +206,7 @@ const ImportMembersModal = props => { const zmsz = /^[A-Za-z0-9]+$/;//字母数字组合 const pattern = /^1[3|4|5|6|7|8|9]\d{9}$/; const sfz = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;//身份证 - const ymd = /^((19|20)[0-9]{2})[\/\-]((0[1-9])|(1[0-2]))[\/\-]((0[1-9])|((1|2)[0-9])|(3[0-1]))$/;//年月日 + //const ymd = /^((19|20)[0-9]{2})[\/\-]((0[1-9])|(1[0-2]))[\/\-]((0[1-9])|((1|2)[0-9])|(3[0-1]))$/;//年月日 const num0 = /^\d+$/;//正整数+0 for (let i = 0; i < res.length; i++) { let d = res[i]; @@ -182,7 +215,7 @@ const ImportMembersModal = props => { let name = judgeNull(d['姓名']); let idNumber = judgeNull(d['证件号']); let gender = judgeNull(d['性别(男/女)']); - let birthday = judgeNull(d['出生年月日(例2022/02/01)']); + let birthday = judgeNullTime(d['出生年月日(例2022/02/01)']);//-------判断时间 let nativePlace = judgeNull(d['籍贯']); let marital = judgeNull(d['婚育状态(已婚/未婚/已婚已育)']); @@ -192,12 +225,12 @@ const ImportMembersModal = props => { let graduatedFrom = judgeNull(d['毕业院校']); let educationBackground = judgeNull(d['学历']); let specialty = judgeNull(d['专业']); - let graduationDate = judgeNull(d['毕业时间']); + let graduationDate = judgeNullTime(d['毕业时间']);//-------------------判断时间 - let hiredate = judgeNull(d['入职时间']); - let turnProbationPeriod = judgeNull(d['转试用期时间']); - let regularDate = judgeNull(d['转正时间']); - let dimissionDate = judgeNull(d['离职日期']); + let hiredate = judgeNullTime(d['入职时间']);//-------------------------判断时间 + let turnProbationPeriod = judgeNullTime(d['转试用期时间']);//-----------判断时间 + let regularDate = judgeNullTime(d['转正时间']);//----------------------判断时间 + let dimissionDate = judgeNullTime(d['离职日期']);//---------------------判断时间 let experienceYear = judgeNull(d['工作经验(年)']); let occupationalHistory = judgeNull(d['历史工作经历与职务']); @@ -217,18 +250,20 @@ const ImportMembersModal = props => { error(`第${i + 1}行姓名为空,请填写`) return } - if (!sfz.test(idNumber)) { + if (idNumber && !sfz.test(idNumber)) { error(`第${i + 1}行证件号错误`) return } - if (['男', '女'].indexOf(gender) == -1) { + if (gender && ['男', '女'].indexOf(gender) == -1) { error(`第${i + 1}行性别错误`) return } - // if (!ymd.test(birthday)) { - // error(`第${i + 1}行出生年月日错误,请填写yyyy/mm/dd格式`) - // return - // } + + let bsdValid = judgeTimeValid(birthday); + if (!bsdValid) { + error(`第${i + 1}行出生年月日错误,请填写yyyy/mm/dd格式`) + return + } let jgValid = judgePlace(nativePlace); if (!jgValid) { @@ -236,15 +271,15 @@ const ImportMembersModal = props => { return } - if (['已婚', '未婚', '已婚已育'].indexOf(marital) == -1) { + if (marital && ['已婚', '未婚', '已婚已育'].indexOf(marital) == -1) { error(`第${i + 1}行婚育状态错误`) return } - if (['群众', '党员'].indexOf(politicsStatus) == -1) { + if (politicsStatus && ['群众', '党员'].indexOf(politicsStatus) == -1) { error(`第${i + 1}行政治面貌错误`) return } - if (!pattern.test(phoneNumber)) { + if (phoneNumber && !pattern.test(phoneNumber)) { error(`第${i + 1}行联系方式错误`) return } @@ -253,43 +288,49 @@ const ImportMembersModal = props => { error(`第${i + 1}行工作地点错误`) return } - if (['小学', '初中', '高中', '大专', '本科', '研究生', '博士'].indexOf(educationBackground) == -1) { + if (educationBackground && ['小学', '初中', '高中', '大专', '本科', '研究生', '博士'].indexOf(educationBackground) == -1) { error(`第${i + 1}行学历错误`) return } - // if (!ymd.test(graduationDate)) { - // error(`第${i + 1}行毕业时间错误,请填写yyyy/mm/dd格式`) - // return - // } - // if (!ymd.test(hiredate)) { - // error(`第${i + 1}行入职时间错误,请填写yyyy/mm/dd格式`) - // return - // } - // if (!ymd.test(turnProbationPeriod)) { - // error(`第${i + 1}行转试用期时间错误,请填写yyyy/mm/dd格式`) - // return - // } - // if (!ymd.test(regularDate)) { - // error(`第${i + 1}行转正时间错误,请填写yyyy/mm/dd格式`) - // return - // } - // if (!ymd.test(dimissionDate)) { - // error(`第${i + 1}行离职日期错误,请填写yyyy/mm/dd格式`) - // return - // } - if (!num0.test(experienceYear)) { + let byValid = judgeTimeValid(graduationDate); + if (!byValid) { + error(`第${i + 1}行毕业时间错误,请填写yyyy/mm/dd格式`) + return + } + let rzhValid = judgeTimeValid(hiredate); + if (!rzhValid) { + error(`第${i + 1}行入职时间错误,请填写yyyy/mm/dd格式`) + return + } + let shyValid = judgeTimeValid(turnProbationPeriod); + if (!shyValid) { + error(`第${i + 1}行转试用期时间错误,请填写yyyy/mm/dd格式`) + return + } + let zhzhValid = judgeTimeValid(regularDate); + if (!zhzhValid) { + error(`第${i + 1}行转正时间错误,请填写yyyy/mm/dd格式`) + return + } + let lzhValid = judgeTimeValid(dimissionDate); + if (!lzhValid) { + error(`第${i + 1}行离职日期错误,请填写yyyy/mm/dd格式`) + return + } + if (experienceYear && !num0.test(experienceYear)) { error(`第${i + 1}行工作经验(年)错误,请填写非负整数`) return } postData.push({//人员编号 待办todotodo pepUserId: 555, name, idNumber, gender, birthday, nativePlace, marital, politicsStatus, phoneNumber, workPlace, graduatedFrom, educationBackground, specialty, graduationDate, - hiredate, turnProbationPeriod, regularDate, dimissionDate, experienceYear, occupationalHistory + hiredate, turnProbationPeriod, regularDate, dimissionDate, experienceYear, occupationalHistory, + del: false }) } - if (postData.length) { - setPostData(postData) - } + //if (postData.length) { + setPostData(postData) + //} let msg = '文件解析完成,点击确定按钮上传保存!' setMsg(msg) onSuccess({ message: msg }) diff --git a/web/client/src/sections/humanAffairs/containers/personnelFiles.jsx b/web/client/src/sections/humanAffairs/containers/personnelFiles.jsx index 9c996d3..e3f55da 100644 --- a/web/client/src/sections/humanAffairs/containers/personnelFiles.jsx +++ b/web/client/src/sections/humanAffairs/containers/personnelFiles.jsx @@ -3,11 +3,11 @@ import { connect } from 'react-redux'; import { Select, Input, Button, CheckboxGroup } from '@douyinfe/semi-ui'; import { IconSearch } from '@douyinfe/semi-icons'; import PersonnelModal from '../components/personnelModal'; -import ExportMembersModal from './import-members-modal' +import ImportMembersModal from './import-members-modal' import '../style.less' const Rest = (props) => { - const { dispatch, actions, history, user, loading, socket } = props + const { dispatch, actions, history, user, loading, socket, xqMembers } = props const { humanAffairs } = actions; let [departmentValue, setDepartmentValue] = useState(''); @@ -250,20 +250,20 @@ const Rest = (props) => { : '' } { - exportModalVs ? setExportModalVs(false)} /> : '' + exportModalVs ? setExportModalVs(false)} xqMembers={xqMembers} /> : '' } ) } function mapStateToProps(state) { - const { auth, global, members, webSocket } = state; + const { auth, global, MemberSearch, webSocket } = state; return { // loading: members.isRequesting, user: auth.user, actions: global.actions, - // members: members.data, + xqMembers: MemberSearch.data, // socket: webSocket.socket }; } diff --git a/web/client/src/sections/humanAffairs/containers/table-input-rule.js b/web/client/src/sections/humanAffairs/containers/table-input-rule.js index b1a9a98..22f4fd9 100644 --- a/web/client/src/sections/humanAffairs/containers/table-input-rule.js +++ b/web/client/src/sections/humanAffairs/containers/table-input-rule.js @@ -5,6 +5,6 @@ export const rule = [ "地址:格式为“省-市”,如“江苏省-镇江市”,直辖市直接显示市,如“北京市”;", "政治面貌:党员或群众;", "学历:小学、初中、高中、大专、本科、研究生或博士;", - "工作经验:0或正整数;", + "工作经验:0或正数;", "没有的数据可不填写。" ] \ No newline at end of file