- 添加部门新增、编辑、删除接口及逻辑实现 - 添加员工新增、编辑、启用、禁用、删除接口及逻辑实现 - 更新配置文件支持组织ID配置 - 初始化金蝶客户端连接配置 - 优化部门与员工数据查询结构 - 增加提交、审核、反审等业务流程处理 - 完善错误处理与日志记录机制
320 lines
8.2 KiB
Go
320 lines
8.2 KiB
Go
package logic
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"ik3cloud/app/common"
|
|
"ik3cloud/app/config"
|
|
"ik3cloud/app/lib/ik3cloud"
|
|
"ik3cloud/app/lib/logger"
|
|
"log"
|
|
"strings"
|
|
"time"
|
|
|
|
ik3cloud2 "git.kumo.work/shama/service/ik3cloud"
|
|
"git.kumo.work/shama/service/lib/bean"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
var StaffLogic = &staffLogic{}
|
|
|
|
type staffLogic struct {
|
|
}
|
|
type staffItem struct {
|
|
Id int64 `json:"FID"` // id
|
|
Number *string `json:"FStaffNumber"` // 工号
|
|
Name *string `json:"FName"` // 姓名
|
|
Position *string `json:"FBaseProperty"` // 职位
|
|
Mobile *string `json:"FMobile"` // 手机号
|
|
Tel *string `json:"FTel"` // 账号
|
|
Status *string `json:"FForbidStatus"` // 状态
|
|
}
|
|
|
|
// List @TITLE 员工列表
|
|
func (s *staffLogic) List(page bean.Page, search ik3cloud2.StaffSearch) (list []ik3cloud2.StaffItem, total int64, err error) {
|
|
where := []map[string]interface{}{
|
|
{
|
|
"FieldName": "FCreateOrgId.FNumber",
|
|
"Compare": "67",
|
|
"Value": config.Config.Ik3cloud.OrganizationNumber,
|
|
"Left": "",
|
|
"Right": "",
|
|
"Logic": 0,
|
|
},
|
|
}
|
|
{
|
|
// 搜索
|
|
// 状态
|
|
if search.Status > 0 {
|
|
status := "B"
|
|
if search.Status == 1 {
|
|
status = "A"
|
|
}
|
|
where = append(where, map[string]interface{}{
|
|
"FieldName": "FForbidStatus",
|
|
"Compare": "105",
|
|
"Value": status,
|
|
"Left": "",
|
|
"Right": "",
|
|
"Logic": 0,
|
|
})
|
|
}
|
|
|
|
// 姓名
|
|
if search.Name != "" {
|
|
where = append(where, map[string]interface{}{
|
|
"FieldName": "FName",
|
|
"Compare": "17",
|
|
"Value": search.Name,
|
|
"Left": "",
|
|
"Right": "",
|
|
"Logic": 0,
|
|
})
|
|
}
|
|
|
|
// 手机号
|
|
if search.Phone != "" {
|
|
where = append(where, map[string]interface{}{
|
|
"FieldName": "FBaseProperty",
|
|
"Compare": "17",
|
|
"Value": search.Phone,
|
|
"Left": "",
|
|
"Right": "",
|
|
"Logic": 0,
|
|
})
|
|
}
|
|
}
|
|
raw, err := ik3cloud.Client.BillQuery(map[string]interface{}{
|
|
"FormId": "BD_Empinfo",
|
|
"FieldKeys": "FName,FStaffNumber,FBaseProperty,FMobile,FTel,FForbidStatus",
|
|
"FilterString": where,
|
|
"StartRow": page.GetStart(),
|
|
"Limit": page.GetLimit(),
|
|
})
|
|
if err != nil {
|
|
return
|
|
}
|
|
log.Println(string(raw))
|
|
var data []staffItem
|
|
if err = json.Unmarshal(raw, &data); err != nil {
|
|
return
|
|
}
|
|
for _, item := range data {
|
|
status := "禁用"
|
|
if common.PtrCmp(item.Status, common.Ptr("A")) {
|
|
status = "启用"
|
|
}
|
|
list = append(list, ik3cloud2.StaffItem{
|
|
Id: item.Id,
|
|
Number: item.Number,
|
|
Name: item.Name,
|
|
Position: item.Position,
|
|
Mobile: item.Mobile,
|
|
Tel: item.Tel,
|
|
Status: &status,
|
|
})
|
|
}
|
|
return
|
|
}
|
|
|
|
// Add @TITLE 添加员工
|
|
func (s *staffLogic) Add(data ik3cloud2.ArgsStaffAdd) (staffId int64, err error) {
|
|
raw, err := ik3cloud.Client.Save("BD_Empinfo", map[string]any{
|
|
"Model": map[string]any{
|
|
"FCreateOrgId": map[string]any{
|
|
"FNumber": config.Config.Ik3cloud.OrganizationNumber,
|
|
},
|
|
"FName": data.Name,
|
|
"FStaffNumber": data.Number,
|
|
"FUseOrgId": map[string]any{
|
|
"FNumber": config.Config.Ik3cloud.OrganizationNumber,
|
|
},
|
|
"FMobile": data.Mobile,
|
|
"FTel": data.Tel,
|
|
"FEmail": data.Email,
|
|
"FCreateSaler": false,
|
|
"FCreateUser": false,
|
|
"FCreateCashier": false,
|
|
"FJoinDate": time.Now().Format("2006-01-02 15:04:05"),
|
|
},
|
|
})
|
|
if err != nil {
|
|
err = errors.New("添加员工失败")
|
|
return
|
|
}
|
|
result, err := ik3cloud.Client.GetResult(raw)
|
|
if err != nil {
|
|
err = errors.New("添加员工失败")
|
|
return
|
|
}
|
|
if !result.Result.ResponseStatus.IsSuccess {
|
|
for _, item := range result.Result.ResponseStatus.Errors {
|
|
return staffId, errors.New(item.Message)
|
|
}
|
|
}
|
|
staffId = result.Result.Id
|
|
if err1 := s.submit([]string{data.Number}); err1 != nil {
|
|
logger.Logger.Error("员工提交失败", zap.Error(err1))
|
|
return
|
|
}
|
|
if err1 := s.audit([]string{data.Number}); err1 != nil {
|
|
logger.Logger.Error("员工审核失败", zap.Error(err1))
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// Edit @TITLE 员工编辑
|
|
func (s *staffLogic) Edit(staffId int64, data ik3cloud2.ArgsStaffAdd) error {
|
|
if staffId == 0 {
|
|
return errors.New("员工错误")
|
|
}
|
|
raw, err := ik3cloud.Client.Save("BD_Empinfo", map[string]any{
|
|
"NeedUpDateFields": []string{"FStaffNumber", "FName", "FMobile", "FTel", "FEmail"},
|
|
"Model": map[string]any{
|
|
"FID": staffId,
|
|
"FStaffNumber": data.Number,
|
|
"FName": data.Name,
|
|
"FMobile": data.Mobile,
|
|
"FTel": data.Tel,
|
|
"FEmail": data.Email,
|
|
},
|
|
})
|
|
if err != nil {
|
|
return errors.New("编辑员工失败")
|
|
}
|
|
result, _ := ik3cloud.Client.GetResult(raw)
|
|
if !result.Result.ResponseStatus.IsSuccess {
|
|
for _, item := range result.Result.ResponseStatus.Errors {
|
|
return errors.New(item.Message)
|
|
}
|
|
return errors.New("编辑员工失败")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Disable @TITLE 禁用账户
|
|
func (s *staffLogic) Disable(numbers []string) error {
|
|
raw, err := ik3cloud.Client.ExecuteOperation("BD_Empinfo", "Forbid", map[string]any{
|
|
"CreateOrgId": config.Config.Ik3cloud.OrganizationId,
|
|
"Numbers": strings.Join(numbers, ","),
|
|
})
|
|
if err != nil {
|
|
return errors.New("禁用员工失败")
|
|
}
|
|
result, _ := ik3cloud.Client.GetResult(raw)
|
|
if !result.Result.ResponseStatus.IsSuccess {
|
|
for _, item := range result.Result.ResponseStatus.Errors {
|
|
return errors.New(item.Message)
|
|
}
|
|
return errors.New("禁用员工失败")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Enable @TITLE 启用账户
|
|
func (s *staffLogic) Enable(numbers []string) error {
|
|
raw, err := ik3cloud.Client.ExecuteOperation("BD_Empinfo", "Enable", map[string]any{
|
|
"CreateOrgId": config.Config.Ik3cloud.OrganizationId,
|
|
"Numbers": strings.Join(numbers, ","),
|
|
})
|
|
if err != nil {
|
|
return errors.New("启用员工失败")
|
|
}
|
|
result, _ := ik3cloud.Client.GetResult(raw)
|
|
if !result.Result.ResponseStatus.IsSuccess {
|
|
for _, item := range result.Result.ResponseStatus.Errors {
|
|
return errors.New(item.Message)
|
|
}
|
|
return errors.New("启用员工失败")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Delete @TITLE 删除
|
|
func (s *staffLogic) Delete(numbers []string) error {
|
|
if err := s.unAudit(numbers); err != nil {
|
|
logger.Logger.Error("部门反审失败", zap.Error(err))
|
|
}
|
|
raw, err := ik3cloud.Client.Delete("BD_Empinfo", map[string]any{
|
|
"CreateOrgId": config.Config.Ik3cloud.OrganizationId,
|
|
"Numbers": strings.Join(numbers, ","),
|
|
})
|
|
if err != nil {
|
|
return errors.New("删除员工失败")
|
|
}
|
|
result, err := ik3cloud.Client.GetResult(raw)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !result.Result.ResponseStatus.IsSuccess {
|
|
for _, item := range result.Result.ResponseStatus.Errors {
|
|
return errors.New(item.Message)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// @Title 提交
|
|
func (s *staffLogic) submit(numbers []string) error {
|
|
raw, err := ik3cloud.Client.Submit("BD_Empinfo", map[string]any{
|
|
"CreateOrgId": config.Config.Ik3cloud.OrganizationId,
|
|
"Numbers": strings.Join(numbers, ","),
|
|
})
|
|
if err != nil {
|
|
return errors.New("员工提交失败")
|
|
}
|
|
result, err := ik3cloud.Client.GetResult(raw)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !result.Result.ResponseStatus.IsSuccess {
|
|
for _, item := range result.Result.ResponseStatus.Errors {
|
|
return errors.New(item.Message)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// @Title 审核
|
|
func (s *staffLogic) audit(numbers []string) error {
|
|
raw, err := ik3cloud.Client.Audit("BD_Empinfo", map[string]any{
|
|
"CreateOrgId": config.Config.Ik3cloud.OrganizationId,
|
|
"Numbers": strings.Join(numbers, ","),
|
|
})
|
|
if err != nil {
|
|
return errors.New("员工审核失败")
|
|
}
|
|
result, err := ik3cloud.Client.GetResult(raw)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !result.Result.ResponseStatus.IsSuccess {
|
|
for _, item := range result.Result.ResponseStatus.Errors {
|
|
return errors.New(item.Message)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// @Title 反审
|
|
func (s *staffLogic) unAudit(numbers []string) error {
|
|
raw, err := ik3cloud.Client.UnAudit("BD_Empinfo", map[string]any{
|
|
"CreateOrgId": config.Config.Ik3cloud.OrganizationId,
|
|
"Numbers": strings.Join(numbers, ","),
|
|
})
|
|
if err != nil {
|
|
return errors.New("员工反审失败")
|
|
}
|
|
result, err := ik3cloud.Client.GetResult(raw)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !result.Result.ResponseStatus.IsSuccess {
|
|
for _, item := range result.Result.ResponseStatus.Errors {
|
|
return errors.New(item.Message)
|
|
}
|
|
}
|
|
return nil
|
|
}
|