更新密码找回uniapp
This commit is contained in:
1 parent
7f9a66da0f
commit
3fdda89833
1304 files changed
+3503
-26132
No files matched your search
@@ -17,10 +17,6 @@ import (
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// BackendEmployeeFileController 员工档案管理(OA 人事档案)。
|
||||
// 档案与员工(yz_backend_employee)按 tid + employee_id 一对一,
|
||||
// 子记录表统一存放教育经历 / 工作经历 / 合同信息 / 证照附件。
|
||||
// 数据按 JWT 中的租户隔离。
|
||||
type BackendEmployeeFileController struct {
|
||||
beego.Controller
|
||||
}
|
||||
@@ -42,7 +38,6 @@ func (c *BackendEmployeeFileController) efErr(httpStatus, bizCode int, msg strin
|
||||
|
||||
var efDatePattern = regexp.MustCompile(`^\d{4}-\d{2}-\d{2}$`)
|
||||
|
||||
// efIsValidDate 校验 "YYYY-MM-DD" 日期字符串;允许为空(可空字段)。
|
||||
func efIsValidDate(s string) bool {
|
||||
s = strings.TrimSpace(s)
|
||||
if s == "" {
|
||||
@@ -55,7 +50,6 @@ func efIsValidDate(s string) bool {
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// efNormalizeDate 将可空 DATE 列统一输出为 "YYYY-MM-DD"。
|
||||
func efNormalizeDate(value *time.Time) string {
|
||||
if value == nil {
|
||||
return ""
|
||||
@@ -63,7 +57,6 @@ func efNormalizeDate(value *time.Time) string {
|
||||
return value.Format("2006-01-02")
|
||||
}
|
||||
|
||||
// efDatePointer 将前端可选日期转为可空 DATE 值;空字符串明确保存为 SQL NULL。
|
||||
func efDatePointer(value string) *time.Time {
|
||||
value = strings.TrimSpace(value)
|
||||
if value == "" {
|
||||
@@ -76,21 +69,18 @@ func efDatePointer(value string) *time.Time {
|
||||
return &date
|
||||
}
|
||||
|
||||
// efQuery 档案查询基座:强制附加租户过滤与未删除条件。
|
||||
func (c *BackendEmployeeFileController) efQuery(tid int) orm.QuerySeter {
|
||||
return models.Orm.QueryTable(new(models.BackendEmployeeFile)).
|
||||
Filter("tid", tid).
|
||||
Filter("is_deleted", 0)
|
||||
}
|
||||
|
||||
// efEmployeeQuery 员工查询基座(与组织架构控制器保持同一过滤口径)。
|
||||
func efEmployeeQuery(tid int) orm.QuerySeter {
|
||||
return models.Orm.QueryTable(new(models.BackendEmployee)).
|
||||
Filter("tid", tid).
|
||||
Filter("delete_time__isnull", true)
|
||||
}
|
||||
|
||||
// efOrgNameMap 组织ID -> 名称映射,用于展示员工的隶属单位/部门名称。
|
||||
func (c *BackendEmployeeFileController) efOrgNameMap(tid int) map[uint64]string {
|
||||
var rows []models.BackendOrganization
|
||||
if _, err := models.Orm.QueryTable(new(models.BackendOrganization)).
|
||||
@@ -106,7 +96,6 @@ func (c *BackendEmployeeFileController) efOrgNameMap(tid int) map[uint64]string
|
||||
return names
|
||||
}
|
||||
|
||||
// efOrgNameByID 组织ID字符串转名称;非数字时原样返回(手输文本兜底)。
|
||||
func efOrgNameByID(names map[uint64]string, id string) string {
|
||||
if id == "" {
|
||||
return ""
|
||||
@@ -117,7 +106,6 @@ func efOrgNameByID(names map[uint64]string, id string) string {
|
||||
return id
|
||||
}
|
||||
|
||||
// efSubtreeOrgIDs 收集组织节点及其全部下级的ID(BFS,含环保护)。
|
||||
func (c *BackendEmployeeFileController) efSubtreeOrgIDs(tid int, rootID uint64) []uint64 {
|
||||
var rows []models.BackendOrganization
|
||||
if _, err := models.Orm.QueryTable(new(models.BackendOrganization)).
|
||||
@@ -149,7 +137,6 @@ func (c *BackendEmployeeFileController) efSubtreeOrgIDs(tid int, rootID uint64)
|
||||
return result
|
||||
}
|
||||
|
||||
// efEmployeeIDsInOrgs 取部门集合内的员工ID(档案按员工过滤时使用)。
|
||||
func (c *BackendEmployeeFileController) efEmployeeIDsInOrgs(tid int, orgIDs []uint64) []uint64 {
|
||||
values := make([]string, 0, len(orgIDs))
|
||||
for _, id := range orgIDs {
|
||||
@@ -166,7 +153,6 @@ func (c *BackendEmployeeFileController) efEmployeeIDsInOrgs(tid int, orgIDs []ui
|
||||
return ids
|
||||
}
|
||||
|
||||
// efEmployeeIDsByKeyword 取姓名/账号/手机命中的员工ID(档案关键词搜索联动员工字段)。
|
||||
func (c *BackendEmployeeFileController) efEmployeeIDsByKeyword(tid int, keyword string) []uint64 {
|
||||
cond := orm.NewCondition().
|
||||
Or("name__icontains", keyword).
|
||||
@@ -183,7 +169,6 @@ func (c *BackendEmployeeFileController) efEmployeeIDsByKeyword(tid int, keyword
|
||||
return ids
|
||||
}
|
||||
|
||||
// employeeFileDTO 档案 + 关联员工展示信息(JSON 平铺,前端表格/详情直接用)。
|
||||
type employeeFileDTO struct {
|
||||
models.BackendEmployeeFile
|
||||
EmployeeName string `json:"employee_name"`
|
||||
@@ -205,8 +190,6 @@ type employeeFileDTO struct {
|
||||
Completeness int `json:"completeness"`
|
||||
}
|
||||
|
||||
// efFileCompleteness 计算档案资料完整度。仅统计应由档案模块维护的有效字段:
|
||||
// 离职日期仅在离职时要求,转正日期仅在正式员工时要求,备注为可选项不计入。
|
||||
func efFileCompleteness(file models.BackendEmployeeFile) int {
|
||||
items := []bool{
|
||||
strings.TrimSpace(file.IDCard) != "",
|
||||
@@ -245,7 +228,6 @@ func efFileCompleteness(file models.BackendEmployeeFile) int {
|
||||
return filled * 100 / len(items)
|
||||
}
|
||||
|
||||
// efAssembleDTOList 档案列表批量组装员工展示信息。
|
||||
func (c *BackendEmployeeFileController) efAssembleDTOList(tid int, files []models.BackendEmployeeFile) []employeeFileDTO {
|
||||
list := make([]employeeFileDTO, 0, len(files))
|
||||
if len(files) == 0 {
|
||||
@@ -299,9 +281,6 @@ func (c *BackendEmployeeFileController) efAssembleDTOList(tid int, files []model
|
||||
return list
|
||||
}
|
||||
|
||||
// List GET /backend/oa/employeefile/list
|
||||
// 分页查询档案,支持 keyword(档案编号/身份证/员工姓名/账号/手机)、
|
||||
// status(在职状态)、org_id(部门,含下级)筛选。
|
||||
func (c *BackendEmployeeFileController) List() {
|
||||
claims, err := c.efClaims()
|
||||
if err != nil {
|
||||
@@ -342,7 +321,6 @@ func (c *BackendEmployeeFileController) List() {
|
||||
qs = qs.Filter("employment_status", int8(status))
|
||||
}
|
||||
if keyword != "" {
|
||||
// 关键词同时命中档案自身字段(编号/身份证)与员工字段(姓名/账号/手机)
|
||||
empIDs := c.efEmployeeIDsByKeyword(tid, keyword)
|
||||
cond := orm.NewCondition().
|
||||
Or("file_no__icontains", keyword).
|
||||
@@ -367,8 +345,6 @@ func (c *BackendEmployeeFileController) List() {
|
||||
})
|
||||
}
|
||||
|
||||
// Stats GET /backend/oa/employeefile/stats
|
||||
// 返回档案总数与在职状态分布,供页面顶部统计卡片展示。
|
||||
func (c *BackendEmployeeFileController) Stats() {
|
||||
claims, err := c.efClaims()
|
||||
if err != nil {
|
||||
@@ -391,8 +367,6 @@ func (c *BackendEmployeeFileController) Stats() {
|
||||
})
|
||||
}
|
||||
|
||||
// Detail GET /backend/oa/employeefile/detail/:id
|
||||
// 返回档案详情(含员工展示信息)与全部子记录(教育/工作/合同/证照)。
|
||||
func (c *BackendEmployeeFileController) Detail() {
|
||||
claims, err := c.efClaims()
|
||||
if err != nil {
|
||||
@@ -431,7 +405,6 @@ func (c *BackendEmployeeFileController) Detail() {
|
||||
c.efOk(map[string]interface{}{"file": list[0], "records": records})
|
||||
}
|
||||
|
||||
// employeeFilePayload 建档/编辑档案请求体。
|
||||
type employeeFilePayload struct {
|
||||
EmployeeID uint64 `json:"employee_id"`
|
||||
FileNo string `json:"file_no"`
|
||||
@@ -457,7 +430,6 @@ type employeeFilePayload struct {
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
|
||||
// efParsePayload 读取并校验建档/编辑档案的请求体;校验失败时直接输出错误响应。
|
||||
func (c *BackendEmployeeFileController) efParsePayload() (employeeFilePayload, bool) {
|
||||
var payload employeeFilePayload
|
||||
raw, err := io.ReadAll(c.Ctx.Request.Body)
|
||||
@@ -475,7 +447,6 @@ func (c *BackendEmployeeFileController) efParsePayload() (employeeFilePayload, b
|
||||
c.efErr(400, 400, "身份证号过长")
|
||||
return payload, false
|
||||
}
|
||||
// 证照附件地址长度限制(与列宽一致)
|
||||
for label, url := range map[string]string{
|
||||
"身份证正面": payload.IDCardFront,
|
||||
"身份证反面": payload.IDCardBack,
|
||||
@@ -509,8 +480,6 @@ func (c *BackendEmployeeFileController) efParsePayload() (employeeFilePayload, b
|
||||
return payload, true
|
||||
}
|
||||
|
||||
// Create POST /backend/oa/employeefile/create
|
||||
// 为员工建档;一人一档,重复建档会被唯一约束与前置校验拦截。
|
||||
func (c *BackendEmployeeFileController) Create() {
|
||||
claims, err := c.efClaims()
|
||||
if err != nil {
|
||||
@@ -529,26 +498,22 @@ func (c *BackendEmployeeFileController) Create() {
|
||||
return
|
||||
}
|
||||
|
||||
// 员工必须存在
|
||||
var emp models.BackendEmployee
|
||||
if err := efEmployeeQuery(tid).Filter("id", payload.EmployeeID).One(&emp); err != nil {
|
||||
c.efErr(404, 404, "员工不存在")
|
||||
return
|
||||
}
|
||||
// 一人一档
|
||||
dup, _ := c.efQuery(tid).Filter("employee_id", payload.EmployeeID).Count()
|
||||
if dup > 0 {
|
||||
c.efErr(400, 400, "该员工已建档,请勿重复创建")
|
||||
return
|
||||
}
|
||||
|
||||
// 档案编号留空自动生成:EF + 时间戳
|
||||
fileNo := payload.FileNo
|
||||
if fileNo == "" {
|
||||
fileNo = "EF" + time.Now().Format("20060102150405")
|
||||
}
|
||||
|
||||
// 证照资料只能在建档完成后,于档案详情中维护;创建接口不接受附件。
|
||||
payload.IDCardFront = ""
|
||||
payload.IDCardBack = ""
|
||||
payload.EducationPhoto = ""
|
||||
@@ -588,14 +553,11 @@ func (c *BackendEmployeeFileController) Create() {
|
||||
return
|
||||
}
|
||||
|
||||
// 建档后同步通讯录(工作邮箱、家庭地址以档案为准)
|
||||
SyncContactOnEmployeeFileChange(uint64(tid), item.EmployeeID)
|
||||
|
||||
c.efOk(item)
|
||||
}
|
||||
|
||||
// Update POST /backend/oa/employeefile/update/:id
|
||||
// 更新档案基本资料;员工归属(employee_id)不允许修改。
|
||||
func (c *BackendEmployeeFileController) Update() {
|
||||
claims, err := c.efClaims()
|
||||
if err != nil {
|
||||
@@ -625,7 +587,6 @@ func (c *BackendEmployeeFileController) Update() {
|
||||
now := time.Now()
|
||||
item.FileNo = payload.FileNo
|
||||
item.IDCard = payload.IDCard
|
||||
// 证照字段由 UpdateCertificates 独立维护,基础资料保存不得覆盖已有附件。
|
||||
item.PoliticalStatus = payload.PoliticalStatus
|
||||
item.Education = payload.Education
|
||||
item.Nation = payload.Nation
|
||||
@@ -654,22 +615,17 @@ func (c *BackendEmployeeFileController) Update() {
|
||||
return
|
||||
}
|
||||
|
||||
// 档案变更后同步通讯录(工作邮箱、家庭地址以档案为准)
|
||||
SyncContactOnEmployeeFileChange(uint64(tid), item.EmployeeID)
|
||||
|
||||
c.efOk(item)
|
||||
}
|
||||
|
||||
// employeeFileCertificatesPayload 证照资料单独更新请求体。
|
||||
// 该接口仅在档案详情中使用,避免上传附件时覆盖基础资料。
|
||||
type employeeFileCertificatesPayload struct {
|
||||
IDCardFront string `json:"id_card_front"`
|
||||
IDCardBack string `json:"id_card_back"`
|
||||
EducationPhoto string `json:"education_photo"`
|
||||
}
|
||||
|
||||
// UpdateCertificates POST /backend/oa/employeefile/certificates/:id
|
||||
// 仅更新学历照片、身份证正反面;档案必须已创建,不能通过建档接口上传。
|
||||
func (c *BackendEmployeeFileController) UpdateCertificates() {
|
||||
claims, err := c.efClaims()
|
||||
if err != nil {
|
||||
@@ -722,12 +678,6 @@ func (c *BackendEmployeeFileController) UpdateCertificates() {
|
||||
c.efOk(item)
|
||||
}
|
||||
|
||||
// Delete DELETE /backend/oa/employeefile/delete/:id 档案离职/禁用(档案不做删除)。
|
||||
//
|
||||
// 与员工同理:人事档案属于企业数据,通讯录(yz_backend_erp_contact)也以 employee_id 关联,
|
||||
// 软删档案会让通讯录里对应的人失去数据来源。因此这里只把在职状态置为"离职"(3),
|
||||
// 不写 is_deleted / delete_time,档案与通讯录记录始终保留可查。
|
||||
// 在职状态调整(试用/正式/离职)走 update 接口即可,这里只是给"删除"动作一个不毁数据的语义。
|
||||
func (c *BackendEmployeeFileController) Delete() {
|
||||
claims, err := c.efClaims()
|
||||
if err != nil {
|
||||
@@ -750,7 +700,6 @@ func (c *BackendEmployeeFileController) Delete() {
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
// 离职日期留空时补当天,保证档案资料(离职需填离职日期)完整
|
||||
if item.LeaveDate == nil {
|
||||
today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
|
||||
item.LeaveDate = &today
|
||||
@@ -767,8 +716,6 @@ func (c *BackendEmployeeFileController) Delete() {
|
||||
c.efOk(nil)
|
||||
}
|
||||
|
||||
// FiledEmployees GET /backend/oa/employeefile/filedEmployees
|
||||
// 返回已建档的员工ID列表,前端用于过滤出可建档(未建档)员工。
|
||||
func (c *BackendEmployeeFileController) FiledEmployees() {
|
||||
claims, err := c.efClaims()
|
||||
if err != nil {
|
||||
@@ -790,8 +737,6 @@ func (c *BackendEmployeeFileController) FiledEmployees() {
|
||||
c.efOk(ids)
|
||||
}
|
||||
|
||||
// employeeFileRecordPayload 档案子记录请求体。
|
||||
// type: 1-教育经历 2-工作经历 3-合同信息 4-证照附件。
|
||||
type employeeFileRecordPayload struct {
|
||||
EmployeeID uint64 `json:"employee_id"`
|
||||
Type int8 `json:"type"`
|
||||
@@ -805,7 +750,6 @@ type employeeFileRecordPayload struct {
|
||||
Sort int `json:"sort"`
|
||||
}
|
||||
|
||||
// efParseRecordPayload 读取并校验子记录请求体;校验失败时直接输出错误响应。
|
||||
func (c *BackendEmployeeFileController) efParseRecordPayload() (employeeFileRecordPayload, bool) {
|
||||
var payload employeeFileRecordPayload
|
||||
raw, err := io.ReadAll(c.Ctx.Request.Body)
|
||||
@@ -848,7 +792,6 @@ func (c *BackendEmployeeFileController) efParseRecordPayload() (employeeFileReco
|
||||
return payload, true
|
||||
}
|
||||
|
||||
// CreateRecord POST /backend/oa/employeefile/record/create 新增子记录。
|
||||
func (c *BackendEmployeeFileController) CreateRecord() {
|
||||
claims, err := c.efClaims()
|
||||
if err != nil {
|
||||
@@ -863,7 +806,6 @@ func (c *BackendEmployeeFileController) CreateRecord() {
|
||||
return
|
||||
}
|
||||
|
||||
// 档案必须存在(记录挂在员工上,但以建档为前提)
|
||||
exists, _ := c.efQuery(tid).Filter("employee_id", payload.EmployeeID).Count()
|
||||
if exists == 0 {
|
||||
c.efErr(404, 404, "档案不存在,请先建档")
|
||||
@@ -895,7 +837,6 @@ func (c *BackendEmployeeFileController) CreateRecord() {
|
||||
c.efOk(item)
|
||||
}
|
||||
|
||||
// UpdateRecord POST /backend/oa/employeefile/record/update/:id 更新子记录。
|
||||
func (c *BackendEmployeeFileController) UpdateRecord() {
|
||||
claims, err := c.efClaims()
|
||||
if err != nil {
|
||||
@@ -948,7 +889,6 @@ func (c *BackendEmployeeFileController) UpdateRecord() {
|
||||
c.efOk(item)
|
||||
}
|
||||
|
||||
// DeleteRecord DELETE /backend/oa/employeefile/record/delete/:id 软删除子记录。
|
||||
func (c *BackendEmployeeFileController) DeleteRecord() {
|
||||
claims, err := c.efClaims()
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user