diff --git a/app/common/function.go b/app/common/function.go index 3367187..998bb95 100644 --- a/app/common/function.go +++ b/app/common/function.go @@ -11,6 +11,7 @@ import ( "path/filepath" "reflect" "regexp" + "strconv" "strings" "time" @@ -336,3 +337,21 @@ func InsertSorted[T any](array []T, value T, comp func(int) bool) []T { array[i] = value // 插入值 return array } + +// GetGender @TITLE 获取性别 +func GetGender(sex string) string { + if InArray(sex, []string{"男", "M"}) { + return "SEX01_SYS" + } else if InArray(sex, []string{"女", "F"}) { + return "SEX02_SYS" + } + return "" +} + +func IntArrayToString(args []int64) string { + var result []string + for _, item := range args { + result = append(result, strconv.FormatInt(item, 10)) + } + return strings.Join(result, ",") +} diff --git a/app/controller/contact.go b/app/controller/contact.go new file mode 100644 index 0000000..10bb34c --- /dev/null +++ b/app/controller/contact.go @@ -0,0 +1,22 @@ +package controller + +import ( + "context" + "ik3cloud/app/logic" + + "git.kumo.work/shama/service/ik3cloud" +) + +type Contact struct { +} + +// Save @TITLE 保存联系人 +func (f *Contact) Save(ctx context.Context, args ik3cloud.ArgsContactSave, entity *[]ik3cloud.Entity) (err error) { + *entity, err = logic.ContactLogic.Save(args.CompanyType, args.Contacts) + return err +} + +// Delete @TITLE 删除联系人 +func (f *Contact) Delete(ctx context.Context, args ik3cloud.Unique, reply *int) error { + return logic.ContactLogic.Delete(args.Numbers, args.Ids) +} diff --git a/app/controller/department.go b/app/controller/department.go index 89d79ae..07c109d 100644 --- a/app/controller/department.go +++ b/app/controller/department.go @@ -17,8 +17,8 @@ func (d *Department) All(ctx context.Context, args int, reply *[]ik3cloud.Depart } // Add @TITLE 添加部门 -func (d *Department) Add(ctx context.Context, args ik3cloud.ArgsDepartmentAdd, departmentId *int64) (err error) { - *departmentId, err = logic.DepartmentLogic.Add(args) +func (d *Department) Add(ctx context.Context, args ik3cloud.ArgsDepartmentAdd, entity *ik3cloud.Entity) (err error) { + *entity, err = logic.DepartmentLogic.Add(args) return err } @@ -28,6 +28,6 @@ func (d *Department) Edit(ctx context.Context, args ik3cloud.ArgsDepartmentEdit, } // Delete @TITLE 删除部门 -func (d *Department) Delete(ctx context.Context, numbers []string, reply *int) error { - return logic.DepartmentLogic.Delete(numbers) +func (d *Department) Delete(ctx context.Context, args ik3cloud.Unique, reply *int) error { + return logic.DepartmentLogic.Delete(args.Numbers, args.Ids) } diff --git a/app/controller/factory.go b/app/controller/factory.go new file mode 100644 index 0000000..29a225d --- /dev/null +++ b/app/controller/factory.go @@ -0,0 +1,17 @@ +package controller + +import ( + "context" + "ik3cloud/app/logic" + + "git.kumo.work/shama/service/ik3cloud" +) + +type Factory struct { +} + +// Save @TITLE 保存工厂 +func (f *Factory) Save(ctx context.Context, args ik3cloud.ArgsFactorySave, entity *ik3cloud.Entity) (err error) { + *entity, err = logic.FactoryLogic.Save(args) + return err +} diff --git a/app/controller/staff.go b/app/controller/staff.go index 448a012..3522f8b 100644 --- a/app/controller/staff.go +++ b/app/controller/staff.go @@ -21,8 +21,8 @@ func (s *Staff) List(ctx context.Context, args ik3cloud.ArgsStaffList, reply *ik } // Add @TITLE 添加员工 -func (s *Staff) Add(ctx context.Context, args ik3cloud.ArgsStaffAdd, staffId *int64) (err error) { - *staffId, err = logic.StaffLogic.Add(args) +func (s *Staff) Add(ctx context.Context, args ik3cloud.ArgsStaffAdd, entity *ik3cloud.Entity) (err error) { + *entity, err = logic.StaffLogic.Add(args) return } @@ -32,16 +32,16 @@ func (s *Staff) Edit(ctx context.Context, args ik3cloud.ArgsStaffEdit, reply *in } // Disable @TITLE 禁用员工 -func (s *Staff) Disable(ctx context.Context, numbers []string, reply *int) error { - return logic.StaffLogic.Disable(numbers) +func (s *Staff) Disable(ctx context.Context, args ik3cloud.Unique, reply *int) error { + return logic.StaffLogic.Disable(args.Numbers, args.Ids) } // Enable @TITLE 启用员工 -func (s *Staff) Enable(ctx context.Context, numbers []string, reply *int) error { - return logic.StaffLogic.Enable(numbers) +func (s *Staff) Enable(ctx context.Context, args ik3cloud.Unique, reply *int) error { + return logic.StaffLogic.Enable(args.Numbers, args.Ids) } // Delete @TITLE 删除 -func (s *Staff) Delete(ctx context.Context, numbers []string, reply *int) error { - return logic.StaffLogic.Delete(numbers) +func (s *Staff) Delete(ctx context.Context, args ik3cloud.Unique, reply *int) error { + return logic.StaffLogic.Delete(args.Numbers, args.Ids) } diff --git a/app/lib/ik3cloud/bean/contact.go b/app/lib/ik3cloud/bean/contact.go new file mode 100644 index 0000000..a2b1746 --- /dev/null +++ b/app/lib/ik3cloud/bean/contact.go @@ -0,0 +1,18 @@ +package bean + +import "ik3cloud/app/lib/ik3cloud" + +type ContactData struct { + FCreateOrgId ik3cloud.FNumber `json:"FCreateOrgId"` + FCompanyType string `json:"FCompanyType"` + FCompany ik3cloud.FNumber `json:"FCompany"` + FEmail string `json:"FEmail"` + FFax string `json:"FFax"` + FIsDefaultContact bool `json:"FIsDefaultContact"` + FMobile string `json:"FMobile"` + FName string `json:"FName"` + FNumber string `json:"FNumber"` + FPost string `json:"FPost"` + FTel string `json:"FTel"` + Fex ik3cloud.FNumber `json:"Fex"` +} diff --git a/app/lib/ik3cloud/client.go b/app/lib/ik3cloud/client.go index e5bf356..5a5ba1f 100644 --- a/app/lib/ik3cloud/client.go +++ b/app/lib/ik3cloud/client.go @@ -2,10 +2,19 @@ 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{} @@ -14,7 +23,9 @@ type client struct { config *Config *client2.Client } - +type FNumber struct { + FNumber string `json:"FNumber"` +} type Config struct { Host string // 接口地址 AccountId string // 账套ID @@ -57,16 +68,194 @@ type result struct { Message string `json:"Message"` DIndex int `json:"DIndex"` } `json:"Errors"` - SuccessEntitys []struct { - Id int `json:"Id"` - Number string `json:"Number"` - DIndex int `json:"DIndex"` - } `json:"SuccessEntitys"` - SuccessMessages []interface{} `json:"SuccessMessages"` - MsgCode int `json:"MsgCode"` + 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 +} diff --git a/app/logic/contact.go b/app/logic/contact.go new file mode 100644 index 0000000..a623400 --- /dev/null +++ b/app/logic/contact.go @@ -0,0 +1,55 @@ +package logic + +import ( + "ik3cloud/app/common" + "ik3cloud/app/config" + "ik3cloud/app/lib/ik3cloud" + + ik3cloud2 "git.kumo.work/shama/service/ik3cloud" + "git.kumo.work/shama/service/ik3cloud/constant" +) + +var ContactLogic = &contactLogic{} + +type contactLogic struct { +} + +// Save @TITLE 保存联系人 +func (c *contactLogic) Save(companyType constant.Action, datas []ik3cloud2.ContactItem) (entities []ik3cloud2.Entity, err error) { + var model []map[string]any + for _, data := range datas { + fex := "" + if common.InArray(data.Sex, []string{"男", "M"}) { + fex = "SEX01_SYS" + } else if common.InArray(data.Sex, []string{"女", "F"}) { + fex = "SEX02_SYS" + } + model = append(model, map[string]any{ + "FCONTACTID": data.ContactId, + "FCreateOrgId": map[string]any{ + "FNumber": config.Config.Ik3cloud.OrganizationNumber, + }, + "FNumber": data.Number, + "FName": data.Name, + "Fex": map[string]any{ + "FNumber": fex, + }, // 性别 + "FPost": data.Job, // 职务 + "FCompanyType": companyType, + "FCompany": map[string]any{ + "FNumber": data.CompanyNumber, + }, + "FTel": data.Tel, + "FMobile": data.Phone, + "FFax": data.Fax, + "FEmail": data.Email, + "FIsDefaultContact": data.IsDefault, + }) + } + return ik3cloud.Client.MultiSave(constant.ActionContact, nil, model) +} + +// Delete @TITLE 删除联系人 +func (c *contactLogic) Delete(numbers []string, ids []int64) error { + return ik3cloud.Client.Delete(constant.ActionContact, numbers, ids) +} diff --git a/app/logic/department.go b/app/logic/department.go index e6062aa..a4dafac 100644 --- a/app/logic/department.go +++ b/app/logic/department.go @@ -6,12 +6,10 @@ import ( "ik3cloud/app/common" "ik3cloud/app/config" "ik3cloud/app/lib/ik3cloud" - "ik3cloud/app/lib/logger" - "strings" "time" ik3cloud2 "git.kumo.work/shama/service/ik3cloud" - "go.uber.org/zap" + "git.kumo.work/shama/service/ik3cloud/constant" ) var DepartmentLogic = &departmentLogic{} @@ -29,7 +27,7 @@ type departmentItem struct { // All @TITLE 全部部门 func (d *departmentLogic) All() (result []ik3cloud2.DepartmentItem, err error) { raw, err := ik3cloud.Client.BillQuery(map[string]any{ - "FormId": "BD_Department", + "FormId": constant.ActionDepartment, "FieldKeys": "FNumber,FName,FParentID.FNumber,FParentID.FName,FDEPTID", "FilterString": []map[string]any{{ "FieldName": "FUseOrgId.FNumber", @@ -60,53 +58,27 @@ func (d *departmentLogic) All() (result []ik3cloud2.DepartmentItem, err error) { } // Add @TITLE 添加部门 -func (d *departmentLogic) Add(data ik3cloud2.ArgsDepartmentAdd) (departmentId int64, err error) { - raw, err := ik3cloud.Client.Save("BD_Department", map[string]any{ - "Model": map[string]any{ - "FCreateOrgId": map[string]any{ - "FNumber": config.Config.Ik3cloud.OrganizationNumber, - }, - "FNumber": data.Number, - "FName": data.Name, - "FUseOrgId": map[string]any{ - "FNumber": config.Config.Ik3cloud.OrganizationNumber, - }, - "FEffectDate": time.Now().Format("2006-01-02 15:04:05"), - "FLapseDate": "9999-12-31 00:00:00", - "FGroup": map[string]any{ - "FNumber": data.GroupNumber, - }, - "FParentID": map[string]any{ - "FNumber": data.ParentNumber, - }, - "FIsCopyFlush": false, - "FIsDetailDpt": false, +func (d *departmentLogic) Add(data ik3cloud2.ArgsDepartmentAdd) (entity ik3cloud2.Entity, err error) { + return ik3cloud.Client.Save(constant.ActionDepartment, nil, map[string]any{ + "FCreateOrgId": map[string]any{ + "FNumber": config.Config.Ik3cloud.OrganizationNumber, }, + "FNumber": data.Number, + "FName": data.Name, + "FUseOrgId": map[string]any{ + "FNumber": config.Config.Ik3cloud.OrganizationNumber, + }, + "FEffectDate": time.Now().Format("2006-01-02 15:04:05"), + "FLapseDate": "9999-12-31 00:00:00", + "FGroup": map[string]any{ + "FNumber": data.GroupNumber, + }, + "FParentID": map[string]any{ + "FNumber": data.ParentNumber, + }, + "FIsCopyFlush": false, + "FIsDetailDpt": false, }) - 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 departmentId, errors.New(item.Message) - } - } - departmentId = result.Result.Id - if err1 := d.submit([]string{data.Number}); err1 != nil { - logger.Logger.Error("部门提交失败", zap.Error(err1)) - return - } - if err1 := d.audit([]string{data.Number}); err1 != nil { - logger.Logger.Error("部门审核失败", zap.Error(err1)) - return - } - return } // Edit @TITLE 编辑部门 @@ -114,52 +86,22 @@ func (d *departmentLogic) Edit(departmentId int64, data ik3cloud2.ArgsDepartment if departmentId == 0 { return errors.New("部门错误") } - raw, err := ik3cloud.Client.Save("BD_Department", map[string]any{ - "NeedUpDateFields": []string{"FName", "FNumber", "FParentID.FNumber"}, - "Model": map[string]any{ - "FDEPTID": departmentId, - "FNumber": data.Number, - "FName": data.Name, - "FParentID": map[string]any{ - "FNumber": data.ParentNumber, - }, + if _, err := ik3cloud.Client.Save(constant.ActionDepartment, []string{"FName", "FNumber", "FParentID.FNumber"}, map[string]any{ + "FDEPTID": departmentId, + "FNumber": data.Number, + "FName": data.Name, + "FParentID": map[string]any{ + "FNumber": data.ParentNumber, }, - }) - 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("编辑部门失败") + }); err != nil { + return errors.New("部门编辑失败") } return nil } // Delete @TITLE 删除部门 -func (d *departmentLogic) Delete(numbers []string) error { - if err := d.unAudit(numbers); err != nil { - logger.Logger.Error("部门反审失败", zap.Error(err)) - } - raw, err := ik3cloud.Client.Delete("BD_Department", 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 +func (d *departmentLogic) Delete(numbers []string, ids []int64) error { + return ik3cloud.Client.Delete(constant.ActionDepartment, numbers, ids) } // @Title 获取菜单树 @@ -182,66 +124,3 @@ func (d *departmentLogic) getTree(datas []ik3cloud2.DepartmentItem) (result []ik } return } - -// @Title 提交 -func (d *departmentLogic) submit(numbers []string) error { - raw, err := ik3cloud.Client.Submit("BD_Department", 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 (d *departmentLogic) audit(numbers []string) error { - raw, err := ik3cloud.Client.Audit("BD_Department", 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 (d *departmentLogic) unAudit(numbers []string) error { - raw, err := ik3cloud.Client.UnAudit("BD_Department", 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 -} diff --git a/app/logic/factory.go b/app/logic/factory.go new file mode 100644 index 0000000..368aab0 --- /dev/null +++ b/app/logic/factory.go @@ -0,0 +1,81 @@ +package logic + +import ( + "ik3cloud/app/common" + "ik3cloud/app/config" + "ik3cloud/app/lib/ik3cloud" + + ik3cloud2 "git.kumo.work/shama/service/ik3cloud" + "git.kumo.work/shama/service/ik3cloud/constant" +) + +var FactoryLogic = &factoryLogic{} + +type factoryLogic struct { +} + +// Save @TITLE 保存工厂 +func (f *factoryLogic) Save(data ik3cloud2.ArgsFactorySave) (entity ik3cloud2.Entity, err error) { + var contants []map[string]any + for _, contact := range data.Contacts { + contants = append(contants, map[string]any{ + "FContactNumber": contact.ContactNumber, + "FContact": contact.Name, + "FPost": contact.Job, + "FTel": contact.Tel, + "FMobile": contact.Phone, + "FFax": contact.Fax, + "FEmail": contact.Email, + "FGender": map[string]any{"FNumber": common.GetGender(contact.Sex)}, // 性别 + "FContactIsDefault": contact.IsDefault, + }) + } + return ik3cloud.Client.Save(constant.ActionFactory, nil, map[string]any{ + "FSupplierId": data.FactoryId, + "FCreateOrgId": map[string]any{ + "FNumber": config.Config.Ik3cloud.OrganizationNumber, + }, + "FNumber": data.Number, + "FName": data.Name, + "FUseOrgId": map[string]any{ + "FNumber": config.Config.Ik3cloud.OrganizationNumber, + }, + "FShortName": data.ShortName, + "FBaseInfo": map[string]any{ + "FAddress": data.Address, + "FZip": data.ZipCode, + "FLegalPerson": data.LegalPerson, + "FRegisterCode": data.TaxNumber, + "FTendPermit": data.TaxNumber, + "FSOCIALCRECODE": data.TaxNumber, + "FRegisterAddress": data.RegAddress, + //"FRegisterFund": 11.0, + "FSupplyClassify": "CG", + }, + "FFinanceInfo": map[string]any{ + "FPayCurrencyId": map[string]any{ + "FNumber": "PRE001", + }, + "FPayAdvanceAmount": 0, + "FTaxType": map[string]any{ + "FNumber": "SFL02_SYS", + }, + "FInvoiceType": 0, + "FTaxRateId": map[string]any{ + "FNumber": "SL02_SYS", + }, + }, + "FBankInfo": []map[string]any{ + { + "FBankCountry": map[string]any{ + "FNumber": "China", + }, + "FBankCode": data.BankAccount, + "FBankHolder": data.Name, + "FOpenBankName": data.Bank, + "FBankIsDefault": true, + }, + }, + "FSupplierContact": contants, + }) +} diff --git a/app/logic/staff.go b/app/logic/staff.go index 3a32f7b..91e6d2f 100644 --- a/app/logic/staff.go +++ b/app/logic/staff.go @@ -6,14 +6,12 @@ import ( "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/ik3cloud/constant" "git.kumo.work/shama/service/lib/bean" - "go.uber.org/zap" ) var StaffLogic = &staffLogic{} @@ -85,7 +83,7 @@ func (s *staffLogic) List(page bean.Page, search ik3cloud2.StaffSearch) (list [] } } raw, err := ik3cloud.Client.BillQuery(map[string]interface{}{ - "FormId": "BD_Empinfo", + "FormId": constant.ActionStaff, "FieldKeys": "FName,FStaffNumber,FBaseProperty,FMobile,FTel,FForbidStatus", "FilterString": where, "StartRow": page.GetStart(), @@ -118,50 +116,24 @@ func (s *staffLogic) List(page bean.Page, search ik3cloud2.StaffSearch) (list [] } // 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"), +func (s *staffLogic) Add(data ik3cloud2.ArgsStaffAdd) (entity ik3cloud2.Entity, err error) { + return ik3cloud.Client.Save(constant.ActionStaff, nil, 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 员工编辑 @@ -169,151 +141,30 @@ 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) - } + if _, err := ik3cloud.Client.Save(constant.ActionStaff, []string{"FStaffNumber", "FName", "FMobile", "FTel", "FEmail"}, map[string]any{ + "FID": staffId, + "FStaffNumber": data.Number, + "FName": data.Name, + "FMobile": data.Mobile, + "FTel": data.Tel, + "FEmail": data.Email, + }); err != nil { 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 +func (s *staffLogic) Disable(numbers []string, ids []int64) error { + return ik3cloud.Client.Disable(constant.ActionStaff, numbers, ids) } // 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 +func (s *staffLogic) Enable(numbers []string, ids []int64) error { + return ik3cloud.Client.Enable(constant.ActionStaff, numbers, ids) } // 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 +func (s *staffLogic) Delete(numbers []string, ids []int64) error { + return ik3cloud.Client.Delete(constant.ActionStaff, numbers, ids) } diff --git a/app/router/router.go b/app/router/router.go index 881d2ef..316254a 100644 --- a/app/router/router.go +++ b/app/router/router.go @@ -16,4 +16,10 @@ func SetRouter(server *server.Server) { if err := server.RegisterName("department", &controller.Department{}, ""); err != nil { return } + // 工厂 + if err := server.RegisterName("factory", &controller.Factory{}, ""); err != nil { + } + // 联系人 + if err := server.RegisterName("contact", &controller.Contact{}, ""); err != nil { + } } diff --git a/client/rpc/main.go b/client/rpc/main.go index 5061089..4e9325c 100644 --- a/client/rpc/main.go +++ b/client/rpc/main.go @@ -5,6 +5,7 @@ import ( "ik3cloud" "ik3cloud/app/config" "ik3cloud/app/router" + "log" "strings" "time" "unsafe" @@ -21,12 +22,10 @@ func main() { defer fn() } - //query.SetDefault(mysql.Db) - s := server.NewServer() // 注册中心 - ik3cloud.AddRegistryPlugin(s) + //ik3cloud.AddRegistryPlugin(s) // 设置路由 router.SetRouter(s) @@ -64,7 +63,7 @@ func main() { } *((*time.Time)(ptr)) = location }) - + log.Println(config.Config.Server.Port) if err := s.Serve("tcp", fmt.Sprintf(":%d", config.Config.Server.Port)); err != nil { return }