更新密码找回uniapp
This commit is contained in:
1 parent
7f9a66da0f
commit
3fdda89833
1304 files changed
+3503
-26132
No files matched your search
@@ -16,18 +16,14 @@ import (
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// BackendErpContactController 通讯录管理接口
|
||||
type BackendErpContactController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// contactClaims 从请求头解析登录态 JWT,返回后端用户 Claims
|
||||
func (c *BackendErpContactController) contactClaims() (*jwtutil.Claims, error) {
|
||||
return identity.Claims(c.Ctx.Request.Header.Get("Authorization"), identity.EndBackend)
|
||||
}
|
||||
|
||||
// contactTenantID 获取当前请求的租户 ID:一律以登录态 JWT 为准。
|
||||
// ?tid= 参数不再参与,否则 backend 账号改参数即可读写其他企业的通讯录。
|
||||
func (c *BackendErpContactController) contactTenantID() (uint64, error) {
|
||||
claims, err := c.contactClaims()
|
||||
if err != nil {
|
||||
@@ -49,7 +45,6 @@ type erpContactDTO struct {
|
||||
ContactName string `json:"contact_name"`
|
||||
Gender int8 `json:"gender"`
|
||||
Phone string `json:"phone"`
|
||||
// 手机号可登记多个(有的人有多个号码):JSON 数组,最多 5 个;phone 保留为第一个
|
||||
Mobiles string `json:"mobiles"`
|
||||
WorkPhone string `json:"work_phone"`
|
||||
Email string `json:"email"`
|
||||
@@ -68,8 +63,6 @@ type erpContactDTO struct {
|
||||
CreateTime string `json:"create_time"`
|
||||
}
|
||||
|
||||
// List 获取通讯录列表(支持分页、搜索、按组织筛选)
|
||||
// GET /backend/erp/contact/list
|
||||
func (c *BackendErpContactController) List() {
|
||||
tid, err := c.contactTenantID()
|
||||
if err != nil {
|
||||
@@ -137,8 +130,6 @@ func (c *BackendErpContactController) List() {
|
||||
})
|
||||
}
|
||||
|
||||
// Detail 获取通讯录详情
|
||||
// GET /backend/erp/contact/detail/:id
|
||||
func (c *BackendErpContactController) Detail() {
|
||||
id, ok := c.contactPathUint64(":id")
|
||||
if !ok {
|
||||
@@ -159,8 +150,6 @@ func (c *BackendErpContactController) Detail() {
|
||||
c.contactJsonOK(c.contactDTO(row))
|
||||
}
|
||||
|
||||
// Create 创建联系人(手动添加外部联系人)
|
||||
// POST /backend/erp/contact/create
|
||||
func (c *BackendErpContactController) Create() {
|
||||
body := c.contactParseJSONBody()
|
||||
|
||||
@@ -177,7 +166,6 @@ func (c *BackendErpContactController) Create() {
|
||||
gender, _ := c.contactGetIntValue(body, "gender")
|
||||
phone, _ := c.contactGetStringValue(body, "phone")
|
||||
mobilesJSON, _ := c.contactGetStringValue(body, "mobiles")
|
||||
// 多手机号:优先使用 mobiles 字段;未传手机号时从 mobiles 取第一个回填 phone(兼容旧调用方)
|
||||
if strings.TrimSpace(phone) == "" {
|
||||
phone = firstMobile(strings.TrimSpace(mobilesJSON))
|
||||
}
|
||||
@@ -195,7 +183,7 @@ func (c *BackendErpContactController) Create() {
|
||||
sortVal, _ := c.contactGetUintValue(body, "sort")
|
||||
|
||||
if contactType == 0 {
|
||||
contactType = 2 // 默认外部联系人
|
||||
contactType = 2
|
||||
}
|
||||
|
||||
row := models.BackendErpContact{
|
||||
@@ -234,8 +222,6 @@ func (c *BackendErpContactController) Create() {
|
||||
c.contactJsonOK(map[string]interface{}{"id": id})
|
||||
}
|
||||
|
||||
// Update 更新联系人
|
||||
// POST /backend/erp/contact/update/:id
|
||||
func (c *BackendErpContactController) Update() {
|
||||
id, ok := c.contactPathUint64(":id")
|
||||
if !ok {
|
||||
@@ -272,7 +258,6 @@ func (c *BackendErpContactController) Update() {
|
||||
}
|
||||
if v, has := c.contactGetStringValue(body, "mobiles"); has {
|
||||
update["mobiles"] = contactNullableString(v)
|
||||
// 多手机号下,phone 始终为第一个号码,保持两者一致
|
||||
if p := firstMobile(strings.TrimSpace(v)); p != "" {
|
||||
update["phone"] = contactNullableString(p)
|
||||
}
|
||||
@@ -345,8 +330,6 @@ func (c *BackendErpContactController) Update() {
|
||||
c.contactJsonOK(nil)
|
||||
}
|
||||
|
||||
// Delete 删除联系人(软删除)
|
||||
// DELETE /backend/erp/contact/delete/:id
|
||||
func (c *BackendErpContactController) Delete() {
|
||||
id, ok := c.contactPathUint64(":id")
|
||||
if !ok {
|
||||
@@ -371,8 +354,6 @@ func (c *BackendErpContactController) Delete() {
|
||||
c.contactJsonOK(nil)
|
||||
}
|
||||
|
||||
// Star 收藏/取消收藏联系人
|
||||
// POST /backend/erp/contact/star/:id
|
||||
func (c *BackendErpContactController) Star() {
|
||||
id, ok := c.contactPathUint64(":id")
|
||||
if !ok {
|
||||
@@ -399,10 +380,7 @@ func (c *BackendErpContactController) Star() {
|
||||
c.contactJsonOK(nil)
|
||||
}
|
||||
|
||||
// SyncAllContacts 全量同步:将当前租户的员工同步到通讯录
|
||||
// POST /backend/erp/contact/syncAll
|
||||
func (c *BackendErpContactController) SyncAllContacts() {
|
||||
// 此处必须走登录态:早期直接取 ?tid=,不带 token 也能调,会把所有企业的员工一起同步
|
||||
tid, err := c.contactTenantID()
|
||||
if err != nil {
|
||||
c.contactJsonError(401, err.Error())
|
||||
@@ -446,8 +424,6 @@ func (c *BackendErpContactController) SyncAllContacts() {
|
||||
})
|
||||
}
|
||||
|
||||
// GetContactOrgTree 获取通讯录组织树(带各部门联系人数量)
|
||||
// GET /backend/erp/contact/orgTree
|
||||
func (c *BackendErpContactController) GetContactOrgTree() {
|
||||
tid, err := c.contactTenantID()
|
||||
if err != nil {
|
||||
@@ -481,10 +457,8 @@ func (c *BackendErpContactController) GetContactOrgTree() {
|
||||
var counts []orgCount
|
||||
_, err = cqs.GroupBy("org_id").All(&counts, "org_id")
|
||||
if err == nil {
|
||||
// Beego ORM GroupBy doesn't support raw count in All, so count manually
|
||||
}
|
||||
|
||||
// Fallback: count per org manually
|
||||
for _, org := range orgs {
|
||||
cnt, _ := models.Orm.QueryTable(new(models.BackendErpContact)).
|
||||
Filter("org_id", org.ID).
|
||||
@@ -496,16 +470,13 @@ func (c *BackendErpContactController) GetContactOrgTree() {
|
||||
orgContactCounts[org.ID] = cnt
|
||||
}
|
||||
|
||||
// Also get total internal contacts count for root
|
||||
totalInternal, _ := cqs.Count()
|
||||
|
||||
// Build tree
|
||||
tree := c.buildContactOrgTree(orgs, orgContactCounts, uint64(totalInternal))
|
||||
|
||||
c.contactJsonOK(tree)
|
||||
}
|
||||
|
||||
// buildContactOrgTree 构建通讯录组织树
|
||||
func (c *BackendErpContactController) buildContactOrgTree(
|
||||
orgs []models.BackendOrganization,
|
||||
counts map[uint64]int64,
|
||||
@@ -542,8 +513,6 @@ func (c *BackendErpContactController) buildContactOrgTree(
|
||||
return tree
|
||||
}
|
||||
|
||||
// --- DTO builder ---
|
||||
|
||||
func (c *BackendErpContactController) contactDTO(row models.BackendErpContact) erpContactDTO {
|
||||
orgName := ""
|
||||
if row.OrgID != nil && *row.OrgID > 0 {
|
||||
@@ -584,19 +553,14 @@ func (c *BackendErpContactController) contactDTO(row models.BackendErpContact) e
|
||||
}
|
||||
}
|
||||
|
||||
// --- Sync from Employee ---
|
||||
|
||||
func init() {
|
||||
services.OnEmployeeCreatedHook = SyncContactOnEmployeeCreate
|
||||
}
|
||||
|
||||
// SyncContactOnEmployeeCreate 员工创建后同步到通讯录(由组织架构控制器调用)
|
||||
func SyncContactOnEmployeeCreate(tid uint64, employeeID uint64, emp *models.BackendEmployee) {
|
||||
syncContactFromEmployee(tid, employeeID, emp)
|
||||
}
|
||||
|
||||
// SyncContactOnEmployeeRefresh 员工信息变更后重新全量同步通讯录(由组织架构控制器调用)。
|
||||
// 走的是与建档同步同一套逻辑:先取员工基础字段,再用人事档案字段覆盖(工作邮箱、家庭地址优先)。
|
||||
func SyncContactOnEmployeeRefresh(tid uint64, employeeID uint64) {
|
||||
var emp models.BackendEmployee
|
||||
if err := models.Orm.QueryTable(new(models.BackendEmployee)).
|
||||
@@ -608,14 +572,10 @@ func SyncContactOnEmployeeRefresh(tid uint64, employeeID uint64) {
|
||||
syncContactFromEmployee(tid, employeeID, &emp)
|
||||
}
|
||||
|
||||
// SyncContactOnEmployeeFileChange 人事档案建档/变更后同步通讯录(由 OA 档案控制器调用)。
|
||||
// 通讯录以 employee_id 关联员工,档案里的字段(工作邮箱、家庭地址)优先级高于员工自身字段。
|
||||
// 只做字段同步:不会新增/删除员工,也不会清理通讯录记录。
|
||||
func SyncContactOnEmployeeFileChange(tid uint64, employeeID uint64) {
|
||||
SyncContactOnEmployeeRefresh(tid, employeeID)
|
||||
}
|
||||
|
||||
// SyncContactOnEmployeeUpdate 员工更新后同步到通讯录(由 ERP 控制器调用)
|
||||
func SyncContactOnEmployeeUpdate(employeeID uint64, update orm.Params) {
|
||||
var contact models.BackendErpContact
|
||||
err := models.Orm.QueryTable(new(models.BackendErpContact)).
|
||||
@@ -677,8 +637,6 @@ func SyncContactOnEmployeeUpdate(employeeID uint64, update orm.Params) {
|
||||
if v, ok := update["home_address"]; ok {
|
||||
contactUpdate["address"] = v
|
||||
}
|
||||
// 员工账号状态(启用/禁用/离职)不同步到通讯录:
|
||||
// 通讯录是企业数据,员工离职或账号被删除都不代表联系人应当停用,是否停用由通讯录模块自行维护。
|
||||
|
||||
if len(contactUpdate) > 0 {
|
||||
models.Orm.QueryTable(new(models.BackendErpContact)).
|
||||
@@ -687,9 +645,6 @@ func SyncContactOnEmployeeUpdate(employeeID uint64, update orm.Params) {
|
||||
}
|
||||
}
|
||||
|
||||
// SyncContactOnEmployeeDelete 清理员工关联的通讯录记录。
|
||||
// 注意:员工离职/禁用(deleteEmployee)与后台账号删除(deleteUser)都不得调用本函数——
|
||||
// 通讯录是企业数据,账号或状态变化不等于联系人消失。仅在员工数据被真正物理清理时使用。
|
||||
func SyncContactOnEmployeeDelete(employeeID uint64) {
|
||||
now := time.Now().Format("2006-01-02 15:04:05")
|
||||
models.Orm.QueryTable(new(models.BackendErpContact)).
|
||||
@@ -698,8 +653,6 @@ func SyncContactOnEmployeeDelete(employeeID uint64) {
|
||||
Update(orm.Params{"delete_time": now, "status": 0})
|
||||
}
|
||||
|
||||
// syncContactFromEmployee 内部同步函数
|
||||
// 从员工信息和人事档案同步数据到通讯录
|
||||
func syncContactFromEmployee(tid uint64, employeeID uint64, emp *models.BackendEmployee) string {
|
||||
var existing models.BackendErpContact
|
||||
err := models.Orm.QueryTable(new(models.BackendErpContact)).
|
||||
@@ -707,15 +660,12 @@ func syncContactFromEmployee(tid uint64, employeeID uint64, emp *models.BackendE
|
||||
Filter("delete_time__isnull", true).
|
||||
One(&existing)
|
||||
|
||||
// 获取人事档案数据
|
||||
fileData := getEmployeeFileForContact(employeeID)
|
||||
|
||||
// 通讯录字段优先级:人事档案 > 员工(档案字段为空时回退员工自身字段)
|
||||
email := contactFirstNonEmptyPtr(&fileData.WorkEmail, emp.Email)
|
||||
address := contactFirstNonEmptyPtr(&fileData.HouseholdAddress, &fileData.CurrentAddress, emp.HomeAddress)
|
||||
|
||||
if err != nil {
|
||||
// Not found - create new contact
|
||||
var orgID *uint64
|
||||
if emp.Department != nil {
|
||||
if oid, err := strconv.ParseUint(strings.TrimSpace(*emp.Department), 10, 64); err == nil && oid > 0 {
|
||||
@@ -741,7 +691,6 @@ func syncContactFromEmployee(tid uint64, employeeID uint64, emp *models.BackendE
|
||||
return "created"
|
||||
}
|
||||
|
||||
// Found - update
|
||||
update := orm.Params{
|
||||
"contact_name": emp.Name,
|
||||
"gender": emp.Gender,
|
||||
@@ -767,8 +716,6 @@ func syncContactFromEmployee(tid uint64, employeeID uint64, emp *models.BackendE
|
||||
return "updated"
|
||||
}
|
||||
|
||||
// getEmployeeFileForContact 获取员工人事档案数据(用于通讯录同步)
|
||||
// 返回档案中与通讯录相关的字段
|
||||
func getEmployeeFileForContact(employeeID uint64) struct {
|
||||
WorkEmail string
|
||||
HouseholdAddress string
|
||||
@@ -785,7 +732,6 @@ func getEmployeeFileForContact(employeeID uint64) struct {
|
||||
One(&file)
|
||||
|
||||
if err != nil {
|
||||
// 档案不存在,返回空值
|
||||
return struct {
|
||||
WorkEmail string
|
||||
HouseholdAddress string
|
||||
@@ -816,8 +762,6 @@ func getEmployeeFileForContact(employeeID uint64) struct {
|
||||
}
|
||||
}
|
||||
|
||||
// --- Helper functions (package-level, shared with ERP controller) ---
|
||||
|
||||
func contactDerefString(v *string) string {
|
||||
if v == nil {
|
||||
return ""
|
||||
@@ -848,8 +792,6 @@ func contactNullableString(v string) interface{} {
|
||||
return v
|
||||
}
|
||||
|
||||
// --- Controller-level helpers ---
|
||||
|
||||
func (c *BackendErpContactController) contactParseJSONBody() map[string]interface{} {
|
||||
body := map[string]interface{}{}
|
||||
contentType := strings.ToLower(c.Ctx.Input.Header("Content-Type"))
|
||||
@@ -975,8 +917,6 @@ func (c *BackendErpContactController) contactJsonError(code int, msg string) {
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
// contactFirstNonEmptyPtr 按优先级取第一个非空字符串(去空格后判断),全部为空时返回 nil。
|
||||
// 用于通讯录"档案字段 > 员工字段"的取值优先级,避免用空字符串覆盖已有数据。
|
||||
func contactFirstNonEmptyPtr(values ...*string) *string {
|
||||
for _, v := range values {
|
||||
if v == nil {
|
||||
|
||||
Reference in new issue
Block a user