parent
4f3cb9fe45
commit
130a73bf70
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,118 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql/driver"
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/fonchain_enterprise/fonchain-approval/api/approval"
|
||||||
|
"gorm.io/plugin/soft_delete"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CopyUser struct {
|
||||||
|
ID uint64
|
||||||
|
Name string
|
||||||
|
IsViewed bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type CopyUsers []CopyUser
|
||||||
|
|
||||||
|
type ApprovalUser struct {
|
||||||
|
ID uint64
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
|
type ApprovalUsers []ApprovalUser
|
||||||
|
|
||||||
|
// ApprovalSetting 部门抄送人设置
|
||||||
|
type ApprovalSetting struct {
|
||||||
|
ID uint64 `gorm:"primaryKey;column:id" json:"id"` // ID
|
||||||
|
DeletedAt soft_delete.DeletedAt `gorm:"column:deleted_at" json:"deletedAt"` // 删除标记
|
||||||
|
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt"` // 创建时间
|
||||||
|
UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt"` // 更新时间
|
||||||
|
KeyWord string `gorm:"column:key_word" json:"keyWord"`
|
||||||
|
ApprovalUsers ApprovalUsers `gorm:"column:approval_users" json:"approvalUsers"`
|
||||||
|
CopyUsers CopyUsers `gorm:"column:copy_users" json:"copyUsers"`
|
||||||
|
Domain string `gorm:"column:domain" json:"domain"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// TableName get sql table name.获取数据库表名
|
||||||
|
func (m *ApprovalSetting) TableName() string {
|
||||||
|
return "approval_setting"
|
||||||
|
}
|
||||||
|
|
||||||
|
type JSON json.RawMessage
|
||||||
|
|
||||||
|
func (j *CopyUsers) Scan(src interface{}) error {
|
||||||
|
return json.Unmarshal(src.([]byte), j)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (j CopyUsers) Value() (driver.Value, error) {
|
||||||
|
|
||||||
|
v, err := json.Marshal(j)
|
||||||
|
|
||||||
|
return string(v), err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (j *ApprovalUsers) Scan(src interface{}) error {
|
||||||
|
return json.Unmarshal(src.([]byte), j)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (j ApprovalUsers) Value() (driver.Value, error) {
|
||||||
|
|
||||||
|
v, err := json.Marshal(j)
|
||||||
|
|
||||||
|
return string(v), err
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetApprovalSettingFromKeyWord(Domain, keyWord string) (setting *ApprovalSetting, err error) {
|
||||||
|
|
||||||
|
err = DB.Model(&ApprovalSetting{}).Where(&ApprovalSetting{KeyWord: keyWord, Domain: Domain}).First(&setting).Error
|
||||||
|
|
||||||
|
return setting, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func FormatCopyUsers(copyUsers []*approval.CopyUser) CopyUsers {
|
||||||
|
var res CopyUsers
|
||||||
|
|
||||||
|
// copyer
|
||||||
|
for _, copyUser := range copyUsers {
|
||||||
|
temp := CopyUser{
|
||||||
|
ID: copyUser.ID,
|
||||||
|
Name: copyUser.Name,
|
||||||
|
}
|
||||||
|
res = append(res, temp)
|
||||||
|
}
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func FormatApproveUsers(copyUsers []*approval.ApprovalUser) ApprovalUsers {
|
||||||
|
var res ApprovalUsers
|
||||||
|
|
||||||
|
// copyer
|
||||||
|
for _, copyUser := range copyUsers {
|
||||||
|
temp := ApprovalUser{
|
||||||
|
ID: copyUser.ID,
|
||||||
|
Name: copyUser.Name,
|
||||||
|
}
|
||||||
|
res = append(res, temp)
|
||||||
|
}
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func FormatToResponse(copyUsers CopyUsers) []*approval.CopyUser {
|
||||||
|
var res []*approval.CopyUser
|
||||||
|
|
||||||
|
for _, copyUser := range copyUsers {
|
||||||
|
temp := &approval.CopyUser{
|
||||||
|
ID: copyUser.ID,
|
||||||
|
Name: copyUser.Name,
|
||||||
|
IsViewed: copyUser.IsViewed,
|
||||||
|
}
|
||||||
|
|
||||||
|
res = append(res, temp)
|
||||||
|
}
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gorm.io/plugin/soft_delete"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ApprovalType 审批类型
|
||||||
|
type ApprovalType struct {
|
||||||
|
ID uint64 `gorm:"primaryKey;column:id" json:"id"` // ID
|
||||||
|
DeletedAt soft_delete.DeletedAt `gorm:"column:deleted_at" json:"deletedAt"` // 删除时间
|
||||||
|
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt"` // 创建时间
|
||||||
|
UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt"` // 更新时间
|
||||||
|
KeyWord string `gorm:"column:key_word" json:"keyWord"` // 回复内容
|
||||||
|
Domain string `gorm:"column:domain" json:"domain"` // 回复内容
|
||||||
|
Title string `gorm:"column:title" json:"title"` // 回复内容
|
||||||
|
}
|
||||||
|
|
||||||
|
// TableName get sql table name.获取数据库表名
|
||||||
|
func (m *ApprovalType) TableName() string {
|
||||||
|
return "approval_type"
|
||||||
|
}
|
@ -0,0 +1,86 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"github.com/fonchain_enterprise/fonchain-approval/pkg/m"
|
||||||
|
"gorm.io/plugin/soft_delete"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ApprovalWorkFlow 审批流
|
||||||
|
type ApprovalWorkFlow struct {
|
||||||
|
ID uint64 `gorm:"primaryKey;column:id" json:"id"`
|
||||||
|
DeletedAt soft_delete.DeletedAt `gorm:"column:deleted_at" json:"deletedAt"`
|
||||||
|
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt"`
|
||||||
|
UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt"`
|
||||||
|
ApprovalID uint64 `gorm:"column:approval_id" json:"approvalId"`
|
||||||
|
UserId uint64 `gorm:"column:user_id" json:"userId"`
|
||||||
|
Name string `gorm:"column:name" json:"name"`
|
||||||
|
Level uint8 `gorm:"column:level" json:"Level"`
|
||||||
|
Status uint8 `gorm:"column:status" json:"Status"`
|
||||||
|
Reply string `gorm:"column:reply" json:"Reply"`
|
||||||
|
OperatedAt time.Time `gorm:"column:operated_at" json:"operatedAt"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetNowWorkFlowByApprovalId(approvalId uint64) (*ApprovalWorkFlow, error) {
|
||||||
|
var workFlow *ApprovalWorkFlow
|
||||||
|
|
||||||
|
if err := DB.Model(&ApprovalWorkFlow{ApprovalID: approvalId, Status: StatusDoing}).Order("level asc").First(&workFlow).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return workFlow, nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetWorkFlowByLevel(approvalId uint64, level uint8) (*ApprovalWorkFlow, error) {
|
||||||
|
var workFlow *ApprovalWorkFlow
|
||||||
|
|
||||||
|
if err := DB.Model(&ApprovalWorkFlow{ApprovalID: approvalId, Level: level}).First(&workFlow).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return workFlow, nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func BatchSave(users ApprovalUsers, approvalId uint64) error {
|
||||||
|
var insertRaws []*ApprovalWorkFlow
|
||||||
|
|
||||||
|
if users == nil && len(users) == 0 {
|
||||||
|
return errors.New(m.ErrorNotFound)
|
||||||
|
}
|
||||||
|
|
||||||
|
for index, user := range users {
|
||||||
|
temp := &ApprovalWorkFlow{
|
||||||
|
UserId: user.ID,
|
||||||
|
Name: user.Name,
|
||||||
|
ApprovalID: approvalId,
|
||||||
|
Level: uint8(index + 1),
|
||||||
|
}
|
||||||
|
|
||||||
|
insertRaws = append(insertRaws, temp)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB.Create(&insertRaws).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ApprovalWorkFlow) TableName() string {
|
||||||
|
return "approval_workflow"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ApprovalWorkFlow) Pass(replay string) error {
|
||||||
|
return m.SetStatus(StatusOk, replay)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ApprovalWorkFlow) Refuse(replay string) error {
|
||||||
|
return m.SetStatus(StatusFail, replay)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ApprovalWorkFlow) SetStatus(status uint8, reply string) error {
|
||||||
|
m.Status = status
|
||||||
|
m.Reply = reply
|
||||||
|
DB.Save(m)
|
||||||
|
return DB.Save(m).Error
|
||||||
|
}
|
@ -1,102 +0,0 @@
|
|||||||
package model
|
|
||||||
|
|
||||||
import (
|
|
||||||
"database/sql/driver"
|
|
||||||
"encoding/json"
|
|
||||||
"github.com/fonchain_enterprise/fonchain-approval/api/approval"
|
|
||||||
"gorm.io/plugin/soft_delete"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type CopyUser struct {
|
|
||||||
ID uint64
|
|
||||||
Name string
|
|
||||||
IsViewed bool
|
|
||||||
}
|
|
||||||
|
|
||||||
type CopyUsers []CopyUser
|
|
||||||
|
|
||||||
// DepartmentApprovalSetting 部门抄送人设置
|
|
||||||
type DepartmentApprovalSetting struct {
|
|
||||||
ID uint64 `gorm:"primaryKey;column:id" json:"id"` // ID
|
|
||||||
DeletedAt soft_delete.DeletedAt `gorm:"column:deleted_at" json:"deletedAt"` // 删除标记
|
|
||||||
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt"` // 创建时间
|
|
||||||
UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt"` // 更新时间
|
|
||||||
DepartmentID uint64 `gorm:"column:department_id" json:"departmentId"` // 绑定的部门ID
|
|
||||||
CopyUsers CopyUsers `gorm:"column:copy_users" json:"copyUsers"` // 抄送人
|
|
||||||
ApproverID uint64 `gorm:"column:approver_id" json:"approverId"` // 审批人ID
|
|
||||||
ApproverName string `gorm:"column:approver_name" json:"approverName"` // 审批人名称
|
|
||||||
Domain string `gorm:"column:domain" json:"domain"` // 环境env
|
|
||||||
}
|
|
||||||
|
|
||||||
// TableName get sql table name.获取数据库表名
|
|
||||||
func (m *DepartmentApprovalSetting) TableName() string {
|
|
||||||
return "department_approval_setting"
|
|
||||||
}
|
|
||||||
|
|
||||||
type JSON json.RawMessage
|
|
||||||
|
|
||||||
func (j *CopyUsers) Scan(src interface{}) error {
|
|
||||||
return json.Unmarshal(src.([]byte), j)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (j CopyUsers) Value() (driver.Value, error) {
|
|
||||||
|
|
||||||
v, err := json.Marshal(j)
|
|
||||||
|
|
||||||
return string(v), err
|
|
||||||
}
|
|
||||||
|
|
||||||
func FormatCopyUsers(copyUsers []*approval.CopyUser) CopyUsers {
|
|
||||||
var res CopyUsers
|
|
||||||
|
|
||||||
// copyer
|
|
||||||
for _, copyUser := range copyUsers {
|
|
||||||
temp := CopyUser{
|
|
||||||
ID: copyUser.ID,
|
|
||||||
Name: copyUser.Name,
|
|
||||||
}
|
|
||||||
res = append(res, temp)
|
|
||||||
}
|
|
||||||
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
func FormatToResponse(copyUsers CopyUsers) []*approval.CopyUser {
|
|
||||||
var res []*approval.CopyUser
|
|
||||||
|
|
||||||
for _, copyUser := range copyUsers {
|
|
||||||
temp := &approval.CopyUser{
|
|
||||||
ID: copyUser.ID,
|
|
||||||
Name: copyUser.Name,
|
|
||||||
IsViewed: copyUser.IsViewed,
|
|
||||||
}
|
|
||||||
|
|
||||||
res = append(res, temp)
|
|
||||||
}
|
|
||||||
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
// DepartmentApprovalSettingColumns get sql column name.获取数据库列名
|
|
||||||
var DepartmentApprovalSettingColumns = struct {
|
|
||||||
ID string
|
|
||||||
DeletedAt string
|
|
||||||
CreatedAt string
|
|
||||||
UpdatedAt string
|
|
||||||
DepartmentID string
|
|
||||||
CopyUsers string
|
|
||||||
ApproverID string
|
|
||||||
ApproverName string
|
|
||||||
Domain string
|
|
||||||
}{
|
|
||||||
ID: "id",
|
|
||||||
DeletedAt: "deleted_at",
|
|
||||||
CreatedAt: "created_at",
|
|
||||||
UpdatedAt: "updated_at",
|
|
||||||
DepartmentID: "department_id",
|
|
||||||
CopyUsers: "copy_users",
|
|
||||||
ApproverID: "approver_id",
|
|
||||||
ApproverName: "approver_name",
|
|
||||||
Domain: "domain",
|
|
||||||
}
|
|
@ -0,0 +1,28 @@
|
|||||||
|
package serializer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/fonchain_enterprise/fonchain-approval/api/approval"
|
||||||
|
"github.com/fonchain_enterprise/fonchain-approval/pkg/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
//BuildType 处理单个detail返回
|
||||||
|
func BuildType(entity *model.ApprovalType) *approval.CreateTypeRequest {
|
||||||
|
|
||||||
|
response := &approval.CreateTypeRequest{
|
||||||
|
ID: entity.ID,
|
||||||
|
Domain: entity.Domain,
|
||||||
|
KeyWord: entity.KeyWord,
|
||||||
|
Title: entity.Title,
|
||||||
|
}
|
||||||
|
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
|
||||||
|
func BuildTypes(entity []*model.ApprovalType) (details []*approval.CreateTypeRequest) {
|
||||||
|
|
||||||
|
for _, temp := range entity {
|
||||||
|
details = append(details, BuildType(temp))
|
||||||
|
}
|
||||||
|
|
||||||
|
return details
|
||||||
|
}
|
Loading…
Reference in New Issue