Some checks failed
Go / build (push) Failing after 19s
- 新增联系人保存与删除逻辑处理 - 新增工厂信息保存逻辑,支持银行、财务等详细信息 - 部门与员工模块接口参数调整,统一使用实体对象返回 - 优化部门与员工的增删改查操作,去除冗余代码 - 统一使用 constant 包管理业务类型常量 - 增加性别转换与整型数组转字符串工具函数 - RPC 注册新增工厂与联系人服务路由 - 调整客户端调用参数结构,增强代码可读性与维护性
262 lines
7.4 KiB
Go
262 lines
7.4 KiB
Go
package ik3cloud
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"ik3cloud/app/common"
|
|
"ik3cloud/app/config"
|
|
"ik3cloud/app/lib/logger"
|
|
"log"
|
|
"strings"
|
|
|
|
"git.kumo.work/shama/service/ik3cloud"
|
|
"git.kumo.work/shama/service/ik3cloud/constant"
|
|
"github.com/deep-project/kingdee"
|
|
"github.com/deep-project/kingdee/adapters"
|
|
client2 "github.com/deep-project/kingdee/pkg/client"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
var Client = &client{}
|
|
|
|
type client struct {
|
|
config *Config
|
|
*client2.Client
|
|
}
|
|
type FNumber struct {
|
|
FNumber string `json:"FNumber"`
|
|
}
|
|
type Config struct {
|
|
Host string // 接口地址
|
|
AccountId string // 账套ID
|
|
Username string // 用户名
|
|
AppId string // 应用ID
|
|
AppSecret string // 应用秘钥
|
|
LanguageId string // 语言ID
|
|
}
|
|
|
|
// InitClient @TITLE 初始化
|
|
func InitClient(config *Config) (*client, error) {
|
|
var err error
|
|
Client.Client, err = kingdee.New(config.Host, &adapters.LoginBySign{
|
|
AccountID: config.AccountId,
|
|
Username: config.Username,
|
|
AppID: config.AppId,
|
|
AppSecret: config.AppSecret,
|
|
LanguageID: config.LanguageId,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
Client.config = config
|
|
return Client, nil
|
|
}
|
|
|
|
// GetResult @TITLE 获取结果
|
|
func (c *client) GetResult(raw []byte) (res result, err error) {
|
|
err = json.Unmarshal(raw, &res)
|
|
return
|
|
}
|
|
|
|
type result struct {
|
|
Result struct {
|
|
ResponseStatus struct {
|
|
ErrorCode int `json:"ErrorCode"`
|
|
IsSuccess bool `json:"IsSuccess"`
|
|
Errors []struct {
|
|
FieldName string `json:"FieldName"`
|
|
Message string `json:"Message"`
|
|
DIndex int `json:"DIndex"`
|
|
} `json:"Errors"`
|
|
SuccessEntitys []ik3cloud.Entity `json:"SuccessEntitys"`
|
|
SuccessMessages []interface{} `json:"SuccessMessages"`
|
|
MsgCode int `json:"MsgCode"`
|
|
} `json:"ResponseStatus"`
|
|
Id int64 `json:"Id"`
|
|
Number string `json:"Number"`
|
|
NeedReturnData []any `json:"NeedReturnData"`
|
|
} `json:"Result"`
|
|
}
|
|
|
|
// Save @TITLE 保存
|
|
func (c *client) Save(companyType constant.Action, editFields []string, model map[string]any) (entity ik3cloud.Entity, err error) {
|
|
raw, err := c.Client.Save(companyType, map[string]any{
|
|
"NeedUpDateFields": editFields,
|
|
"Model": model,
|
|
})
|
|
marshal, _ := json.Marshal(model)
|
|
log.Println(string(marshal))
|
|
log.Println(string(raw))
|
|
if err != nil {
|
|
return entity, errors.New("保存失败")
|
|
}
|
|
result, _ := c.GetResult(raw)
|
|
if !result.Result.ResponseStatus.IsSuccess {
|
|
for _, item := range result.Result.ResponseStatus.Errors {
|
|
logger.Logger.Error("保存失败", zap.Error(err))
|
|
return entity, errors.New(item.Message)
|
|
}
|
|
return entity, errors.New("保存失败")
|
|
}
|
|
entity = result.Result.ResponseStatus.SuccessEntitys[0]
|
|
return
|
|
}
|
|
|
|
// MultiSave @TITLE 批量保存
|
|
func (c *client) MultiSave(companyType constant.Action, editFields []string, model any) (Entities []ik3cloud.Entity, err error) {
|
|
raw, err := c.Client.BatchSave(companyType, map[string]any{
|
|
"NeedUpDateFields": editFields,
|
|
"Model": model,
|
|
})
|
|
if err != nil {
|
|
return Entities, errors.New("保存失败")
|
|
}
|
|
result, _ := c.GetResult(raw)
|
|
if !result.Result.ResponseStatus.IsSuccess {
|
|
for _, item := range result.Result.ResponseStatus.Errors {
|
|
logger.Logger.Error("保存失败", zap.Error(err))
|
|
return Entities, errors.New(item.Message)
|
|
}
|
|
return Entities, errors.New("保存失败")
|
|
}
|
|
Entities = result.Result.ResponseStatus.SuccessEntitys
|
|
return
|
|
}
|
|
|
|
// Submit @Title 提交
|
|
func (c *client) Submit(companyType constant.Action, numbers []string, ids []int64) error {
|
|
raw, err := c.Client.Submit(companyType, map[string]any{
|
|
"CreateOrgId": config.Config.Ik3cloud.OrganizationId,
|
|
"Numbers": strings.Join(numbers, ","),
|
|
"Ids": common.IntArrayToString(ids),
|
|
})
|
|
if err != nil {
|
|
return errors.New("提交失败")
|
|
}
|
|
result, err := c.GetResult(raw)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !result.Result.ResponseStatus.IsSuccess {
|
|
for _, item := range result.Result.ResponseStatus.Errors {
|
|
logger.Logger.Error("提交失败", zap.Error(err))
|
|
return errors.New(item.Message)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Audit @Title 审核
|
|
func (c *client) Audit(companyType constant.Action, numbers []string, ids []int64) error {
|
|
raw, err := c.Client.Audit(companyType, map[string]any{
|
|
"CreateOrgId": config.Config.Ik3cloud.OrganizationId,
|
|
"Numbers": strings.Join(numbers, ","),
|
|
"Ids": common.IntArrayToString(ids),
|
|
})
|
|
if err != nil {
|
|
return errors.New("审核失败")
|
|
}
|
|
result, err := c.GetResult(raw)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !result.Result.ResponseStatus.IsSuccess {
|
|
for _, item := range result.Result.ResponseStatus.Errors {
|
|
logger.Logger.Error("提交失败", zap.Error(err))
|
|
return errors.New(item.Message)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// UnAudit @Title 反审
|
|
func (c *client) UnAudit(companyType constant.Action, numbers []string, ids []int64) error {
|
|
raw, err := c.Client.UnAudit(companyType, map[string]any{
|
|
"CreateOrgId": config.Config.Ik3cloud.OrganizationId,
|
|
"Numbers": strings.Join(numbers, ","),
|
|
"Ids": common.IntArrayToString(ids),
|
|
})
|
|
if err != nil {
|
|
return errors.New("反审失败")
|
|
}
|
|
result, err := c.GetResult(raw)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !result.Result.ResponseStatus.IsSuccess {
|
|
for _, item := range result.Result.ResponseStatus.Errors {
|
|
logger.Logger.Error("提交失败", zap.Error(err))
|
|
return errors.New(item.Message)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Delete @TITLE 删除
|
|
func (c *client) Delete(companyType constant.Action, numbers []string, ids []int64) error {
|
|
if err := c.UnAudit(companyType, numbers, ids); err != nil {
|
|
logger.Logger.Error("删除失败", zap.Error(err))
|
|
}
|
|
raw, err := c.Client.Delete(companyType, map[string]any{
|
|
"CreateOrgId": config.Config.Ik3cloud.OrganizationId,
|
|
"Numbers": strings.Join(numbers, ","),
|
|
"Ids": common.IntArrayToString(ids),
|
|
})
|
|
if err != nil {
|
|
return errors.New("删除失败")
|
|
}
|
|
result, err := c.GetResult(raw)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !result.Result.ResponseStatus.IsSuccess {
|
|
for _, item := range result.Result.ResponseStatus.Errors {
|
|
logger.Logger.Error("提交失败", zap.Error(err))
|
|
return errors.New(item.Message)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Enable @TITLE 启用
|
|
func (c *client) Enable(companyType constant.Action, numbers []string, ids []int64) error {
|
|
raw, err := c.Client.ExecuteOperation(companyType, "Enable", map[string]any{
|
|
"CreateOrgId": config.Config.Ik3cloud.OrganizationId,
|
|
"Numbers": strings.Join(numbers, ","),
|
|
"Ids": common.IntArrayToString(ids),
|
|
})
|
|
if err != nil {
|
|
return errors.New("启用失败")
|
|
}
|
|
result, _ := c.GetResult(raw)
|
|
if !result.Result.ResponseStatus.IsSuccess {
|
|
for _, item := range result.Result.ResponseStatus.Errors {
|
|
logger.Logger.Error("提交失败", zap.Error(err))
|
|
return errors.New(item.Message)
|
|
}
|
|
return errors.New("启用失败")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Disable @TITLE 禁用账户
|
|
func (c *client) Disable(companyType constant.Action, numbers []string, ids []int64) error {
|
|
raw, err := c.Client.ExecuteOperation(companyType, "Forbid", map[string]any{
|
|
"CreateOrgId": config.Config.Ik3cloud.OrganizationId,
|
|
"Numbers": strings.Join(numbers, ","),
|
|
"Ids": common.IntArrayToString(ids),
|
|
})
|
|
if err != nil {
|
|
return errors.New("禁用失败")
|
|
}
|
|
result, _ := c.GetResult(raw)
|
|
if !result.Result.ResponseStatus.IsSuccess {
|
|
for _, item := range result.Result.ResponseStatus.Errors {
|
|
logger.Logger.Error("提交失败", zap.Error(err))
|
|
return errors.New(item.Message)
|
|
}
|
|
return errors.New("禁用失败")
|
|
}
|
|
return nil
|
|
}
|