Browse Source

freature(日志): 请求钉钉接口或钉钉事件回调日志功能实现

likai 2 years ago
parent
commit
5781a53b55

+ 36 - 0
opms_parent/app/dao/dingtalk_log/dingtalk_log.go

@@ -0,0 +1,36 @@
+// ============================================================================
+// This is auto-generated by gf cli tool only once. Fill this file as you wish.
+// ============================================================================
+
+package dingtalk_log
+
+import (
+	"dashoo.cn/micro/app/dao/dingtalk_log/internal"
+)
+
+// dingtalkLogDao is the manager for logic model data accessing
+// and custom defined data operations functions management. You can define
+// methods on it to extend its functionality as you wish.
+type dingtalkLogDao struct {
+	internal.DingtalkLogDao
+}
+
+var (
+	// DingtalkLog is globally public accessible object for table dingtalk_log operations.
+	DingtalkLog = dingtalkLogDao{
+		internal.DingtalkLog,
+	}
+)
+
+type DingtalkLogDao struct {
+	internal.DingtalkLogDao
+}
+
+func NewDingtalkLogDao(tenant string) *DingtalkLogDao {
+	dao := internal.NewDingtalkLogDao(tenant)
+	return &DingtalkLogDao{
+		dao,
+	}
+}
+
+// Fill with you ideas below.

+ 425 - 0
opms_parent/app/dao/dingtalk_log/internal/dingtalk_log.go

@@ -0,0 +1,425 @@
+// ==========================================================================
+// This is auto-generated by gf cli tool. DO NOT EDIT THIS FILE MANUALLY.
+// ==========================================================================
+
+package internal
+
+import (
+	"context"
+	"dashoo.cn/micro/app/model/dingtalk_log"
+	"database/sql"
+	"github.com/gogf/gf/database/gdb"
+	"github.com/gogf/gf/frame/g"
+	"github.com/gogf/gf/frame/gmvc"
+	"time"
+)
+
+// DingtalkLogDao is the manager for logic model data accessing
+// and custom defined data operations functions management.
+type DingtalkLogDao struct {
+	gmvc.M
+	DB      gdb.DB
+	Table   string
+	Columns dingtalkLogColumns
+}
+
+// DingtalkLogColumns defines and stores column names for table dingtalk_log.
+type dingtalkLogColumns struct {
+	Id          string // 主键
+	Type        string // 类型:10 调用钉钉接口;20 钉钉事件回调
+	Content     string // 请求或响应参数
+	Remark      string // 备注
+	CreatedBy   string // 创建者
+	CreatedName string // 创建人
+	CreatedTime string // 创建时间
+	UpdatedBy   string // 更新者
+	UpdatedName string // 更新人
+	UpdatedTime string // 更新时间
+	DeletedTime string // 删除时间
+}
+
+var (
+	// DingtalkLog is globally public accessible object for table dingtalk_log operations.
+	DingtalkLog = DingtalkLogDao{
+		M:     g.DB("default").Model("dingtalk_log").Safe(),
+		DB:    g.DB("default"),
+		Table: "dingtalk_log",
+		Columns: dingtalkLogColumns{
+			Id:          "id",
+			Type:        "type",
+			Content:     "content",
+			Remark:      "remark",
+			CreatedBy:   "created_by",
+			CreatedName: "created_name",
+			CreatedTime: "created_time",
+			UpdatedBy:   "updated_by",
+			UpdatedName: "updated_name",
+			UpdatedTime: "updated_time",
+			DeletedTime: "deleted_time",
+		},
+	}
+)
+
+func NewDingtalkLogDao(tenant string) DingtalkLogDao {
+	var dao DingtalkLogDao
+	dao = DingtalkLogDao{
+		M:     g.DB(tenant).Model("dingtalk_log").Safe(),
+		DB:    g.DB(tenant),
+		Table: "dingtalk_log",
+		Columns: dingtalkLogColumns{
+			Id:          "id",
+			Type:        "type",
+			Content:     "content",
+			Remark:      "remark",
+			CreatedBy:   "created_by",
+			CreatedName: "created_name",
+			CreatedTime: "created_time",
+			UpdatedBy:   "updated_by",
+			UpdatedName: "updated_name",
+			UpdatedTime: "updated_time",
+			DeletedTime: "deleted_time",
+		},
+	}
+	return dao
+}
+
+// Ctx is a chaining function, which creates and returns a new DB that is a shallow copy
+// of current DB object and with given context in it.
+// Note that this returned DB object can be used only once, so do not assign it to
+// a global or package variable for long using.
+func (d *DingtalkLogDao) Ctx(ctx context.Context) *DingtalkLogDao {
+	return &DingtalkLogDao{M: d.M.Ctx(ctx)}
+}
+
+// As sets an alias name for current table.
+func (d *DingtalkLogDao) As(as string) *DingtalkLogDao {
+	return &DingtalkLogDao{M: d.M.As(as)}
+}
+
+// TX sets the transaction for current operation.
+func (d *DingtalkLogDao) TX(tx *gdb.TX) *DingtalkLogDao {
+	return &DingtalkLogDao{M: d.M.TX(tx)}
+}
+
+// Master marks the following operation on master node.
+func (d *DingtalkLogDao) Master() *DingtalkLogDao {
+	return &DingtalkLogDao{M: d.M.Master()}
+}
+
+// Slave marks the following operation on slave node.
+// Note that it makes sense only if there's any slave node configured.
+func (d *DingtalkLogDao) Slave() *DingtalkLogDao {
+	return &DingtalkLogDao{M: d.M.Slave()}
+}
+
+// Args sets custom arguments for model operation.
+func (d *DingtalkLogDao) Args(args ...interface{}) *DingtalkLogDao {
+	return &DingtalkLogDao{M: d.M.Args(args...)}
+}
+
+// LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
+// The parameter <table> can be joined table and its joined condition,
+// and also with its alias name, like:
+// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
+// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
+func (d *DingtalkLogDao) LeftJoin(table ...string) *DingtalkLogDao {
+	return &DingtalkLogDao{M: d.M.LeftJoin(table...)}
+}
+
+// RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
+// The parameter <table> can be joined table and its joined condition,
+// and also with its alias name, like:
+// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
+// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
+func (d *DingtalkLogDao) RightJoin(table ...string) *DingtalkLogDao {
+	return &DingtalkLogDao{M: d.M.RightJoin(table...)}
+}
+
+// InnerJoin does "INNER JOIN ... ON ..." statement on the model.
+// The parameter <table> can be joined table and its joined condition,
+// and also with its alias name, like:
+// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
+// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
+func (d *DingtalkLogDao) InnerJoin(table ...string) *DingtalkLogDao {
+	return &DingtalkLogDao{M: d.M.InnerJoin(table...)}
+}
+
+// Fields sets the operation fields of the model, multiple fields joined using char ','.
+// The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
+func (d *DingtalkLogDao) Fields(fieldNamesOrMapStruct ...interface{}) *DingtalkLogDao {
+	return &DingtalkLogDao{M: d.M.Fields(fieldNamesOrMapStruct...)}
+}
+
+// FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
+// The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
+func (d *DingtalkLogDao) FieldsEx(fieldNamesOrMapStruct ...interface{}) *DingtalkLogDao {
+	return &DingtalkLogDao{M: d.M.FieldsEx(fieldNamesOrMapStruct...)}
+}
+
+// Option sets the extra operation option for the model.
+func (d *DingtalkLogDao) Option(option int) *DingtalkLogDao {
+	return &DingtalkLogDao{M: d.M.Option(option)}
+}
+
+// OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
+// the data and where attributes for empty values.
+func (d *DingtalkLogDao) OmitEmpty() *DingtalkLogDao {
+	return &DingtalkLogDao{M: d.M.OmitEmpty()}
+}
+
+// Filter marks filtering the fields which does not exist in the fields of the operated table.
+func (d *DingtalkLogDao) Filter() *DingtalkLogDao {
+	return &DingtalkLogDao{M: d.M.Filter()}
+}
+
+// Where sets the condition statement for the model. The parameter <where> can be type of
+// string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
+// multiple conditions will be joined into where statement using "AND".
+// Eg:
+// Where("uid=10000")
+// Where("uid", 10000)
+// Where("money>? AND name like ?", 99999, "vip_%")
+// Where("uid", 1).Where("name", "john")
+// Where("status IN (?)", g.Slice{1,2,3})
+// Where("age IN(?,?)", 18, 50)
+// Where(User{ Id : 1, UserName : "john"})
+func (d *DingtalkLogDao) Where(where interface{}, args ...interface{}) *DingtalkLogDao {
+	return &DingtalkLogDao{M: d.M.Where(where, args...)}
+}
+
+// WherePri does the same logic as M.Where except that if the parameter <where>
+// is a single condition like int/string/float/slice, it treats the condition as the primary
+// key value. That is, if primary key is "id" and given <where> parameter as "123", the
+// WherePri function treats the condition as "id=123", but M.Where treats the condition
+// as string "123".
+func (d *DingtalkLogDao) WherePri(where interface{}, args ...interface{}) *DingtalkLogDao {
+	return &DingtalkLogDao{M: d.M.WherePri(where, args...)}
+}
+
+// And adds "AND" condition to the where statement.
+func (d *DingtalkLogDao) And(where interface{}, args ...interface{}) *DingtalkLogDao {
+	return &DingtalkLogDao{M: d.M.And(where, args...)}
+}
+
+// Or adds "OR" condition to the where statement.
+func (d *DingtalkLogDao) Or(where interface{}, args ...interface{}) *DingtalkLogDao {
+	return &DingtalkLogDao{M: d.M.Or(where, args...)}
+}
+
+// Group sets the "GROUP BY" statement for the model.
+func (d *DingtalkLogDao) Group(groupBy string) *DingtalkLogDao {
+	return &DingtalkLogDao{M: d.M.Group(groupBy)}
+}
+
+// Order sets the "ORDER BY" statement for the model.
+func (d *DingtalkLogDao) Order(orderBy ...string) *DingtalkLogDao {
+	return &DingtalkLogDao{M: d.M.Order(orderBy...)}
+}
+
+// Limit sets the "LIMIT" statement for the model.
+// The parameter <limit> can be either one or two number, if passed two number is passed,
+// it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
+// statement.
+func (d *DingtalkLogDao) Limit(limit ...int) *DingtalkLogDao {
+	return &DingtalkLogDao{M: d.M.Limit(limit...)}
+}
+
+// Offset sets the "OFFSET" statement for the model.
+// It only makes sense for some databases like SQLServer, PostgreSQL, etc.
+func (d *DingtalkLogDao) Offset(offset int) *DingtalkLogDao {
+	return &DingtalkLogDao{M: d.M.Offset(offset)}
+}
+
+// Page sets the paging number for the model.
+// The parameter <page> is started from 1 for paging.
+// Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
+func (d *DingtalkLogDao) Page(page, limit int) *DingtalkLogDao {
+	return &DingtalkLogDao{M: d.M.Page(page, limit)}
+}
+
+// Batch sets the batch operation number for the model.
+func (d *DingtalkLogDao) Batch(batch int) *DingtalkLogDao {
+	return &DingtalkLogDao{M: d.M.Batch(batch)}
+}
+
+// Cache sets the cache feature for the model. It caches the result of the sql, which means
+// if there's another same sql request, it just reads and returns the result from cache, it
+// but not committed and executed into the database.
+//
+// If the parameter <duration> < 0, which means it clear the cache with given <name>.
+// If the parameter <duration> = 0, which means it never expires.
+// If the parameter <duration> > 0, which means it expires after <duration>.
+//
+// The optional parameter <name> is used to bind a name to the cache, which means you can later
+// control the cache like changing the <duration> or clearing the cache with specified <name>.
+//
+// Note that, the cache feature is disabled if the model is operating on a transaction.
+func (d *DingtalkLogDao) Cache(duration time.Duration, name ...string) *DingtalkLogDao {
+	return &DingtalkLogDao{M: d.M.Cache(duration, name...)}
+}
+
+// Data sets the operation data for the model.
+// The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
+// Eg:
+// Data("uid=10000")
+// Data("uid", 10000)
+// Data(g.Map{"uid": 10000, "name":"john"})
+// Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
+func (d *DingtalkLogDao) Data(data ...interface{}) *DingtalkLogDao {
+	return &DingtalkLogDao{M: d.M.Data(data...)}
+}
+
+// All does "SELECT FROM ..." statement for the model.
+// It retrieves the records from table and returns the result as []*model.DingtalkLog.
+// It returns nil if there's no record retrieved with the given conditions from table.
+//
+// The optional parameter <where> is the same as the parameter of M.Where function,
+// see M.Where.
+func (d *DingtalkLogDao) All(where ...interface{}) ([]*dingtalk_log.DingtalkLog, error) {
+	all, err := d.M.All(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entities []*dingtalk_log.DingtalkLog
+	if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entities, nil
+}
+
+// One retrieves one record from table and returns the result as *model.DingtalkLog.
+// It returns nil if there's no record retrieved with the given conditions from table.
+//
+// The optional parameter <where> is the same as the parameter of M.Where function,
+// see M.Where.
+func (d *DingtalkLogDao) One(where ...interface{}) (*dingtalk_log.DingtalkLog, error) {
+	one, err := d.M.One(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entity *dingtalk_log.DingtalkLog
+	if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entity, nil
+}
+
+// FindOne retrieves and returns a single Record by M.WherePri and M.One.
+// Also see M.WherePri and M.One.
+func (d *DingtalkLogDao) FindOne(where ...interface{}) (*dingtalk_log.DingtalkLog, error) {
+	one, err := d.M.FindOne(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entity *dingtalk_log.DingtalkLog
+	if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entity, nil
+}
+
+// FindAll retrieves and returns Result by by M.WherePri and M.All.
+// Also see M.WherePri and M.All.
+func (d *DingtalkLogDao) FindAll(where ...interface{}) ([]*dingtalk_log.DingtalkLog, error) {
+	all, err := d.M.FindAll(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entities []*dingtalk_log.DingtalkLog
+	if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entities, nil
+}
+
+// Struct retrieves one record from table and converts it into given struct.
+// The parameter <pointer> should be type of *struct/**struct. If type **struct is given,
+// it can create the struct internally during converting.
+//
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+//
+// Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
+// from table and <pointer> is not nil.
+//
+// Eg:
+// user := new(User)
+// err  := dao.User.Where("id", 1).Struct(user)
+//
+// user := (*User)(nil)
+// err  := dao.User.Where("id", 1).Struct(&user)
+func (d *DingtalkLogDao) Struct(pointer interface{}, where ...interface{}) error {
+	return d.M.Struct(pointer, where...)
+}
+
+// Structs retrieves records from table and converts them into given struct slice.
+// The parameter <pointer> should be type of *[]struct/*[]*struct. It can create and fill the struct
+// slice internally during converting.
+//
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+//
+// Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
+// from table and <pointer> is not empty.
+//
+// Eg:
+// users := ([]User)(nil)
+// err   := dao.User.Structs(&users)
+//
+// users := ([]*User)(nil)
+// err   := dao.User.Structs(&users)
+func (d *DingtalkLogDao) Structs(pointer interface{}, where ...interface{}) error {
+	return d.M.Structs(pointer, where...)
+}
+
+// Scan automatically calls Struct or Structs function according to the type of parameter <pointer>.
+// It calls function Struct if <pointer> is type of *struct/**struct.
+// It calls function Structs if <pointer> is type of *[]struct/*[]*struct.
+//
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+//
+// Note that it returns sql.ErrNoRows if there's no record retrieved and given pointer is not empty or nil.
+//
+// Eg:
+// user  := new(User)
+// err   := dao.User.Where("id", 1).Scan(user)
+//
+// user  := (*User)(nil)
+// err   := dao.User.Where("id", 1).Scan(&user)
+//
+// users := ([]User)(nil)
+// err   := dao.User.Scan(&users)
+//
+// users := ([]*User)(nil)
+// err   := dao.User.Scan(&users)
+func (d *DingtalkLogDao) Scan(pointer interface{}, where ...interface{}) error {
+	return d.M.Scan(pointer, where...)
+}
+
+// Chunk iterates the table with given size and callback function.
+func (d *DingtalkLogDao) Chunk(limit int, callback func(entities []*dingtalk_log.DingtalkLog, err error) bool) {
+	d.M.Chunk(limit, func(result gdb.Result, err error) bool {
+		var entities []*dingtalk_log.DingtalkLog
+		err = result.Structs(&entities)
+		if err == sql.ErrNoRows {
+			return false
+		}
+		return callback(entities, err)
+	})
+}
+
+// LockUpdate sets the lock for update for current operation.
+func (d *DingtalkLogDao) LockUpdate() *DingtalkLogDao {
+	return &DingtalkLogDao{M: d.M.LockUpdate()}
+}
+
+// LockShared sets the lock in share mode for current operation.
+func (d *DingtalkLogDao) LockShared() *DingtalkLogDao {
+	return &DingtalkLogDao{M: d.M.LockShared()}
+}
+
+// Unscoped enables/disables the soft deleting feature.
+func (d *DingtalkLogDao) Unscoped() *DingtalkLogDao {
+	return &DingtalkLogDao{M: d.M.Unscoped()}
+}

+ 23 - 0
opms_parent/app/handler/dingtalk/ding_event.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	model "dashoo.cn/micro/app/model/workflow"
 	custServer "dashoo.cn/micro/app/service/cust"
+	"dashoo.cn/micro/app/service/dingtalk_log"
 	platServer "dashoo.cn/micro/app/service/plat"
 	workflowServer "dashoo.cn/micro/app/service/workflow"
 	"dashoo.cn/opms_libary/plugin/dingtalk"
@@ -12,6 +13,7 @@ import (
 	"database/sql"
 	"fmt"
 	"github.com/gogf/gf/os/glog"
+	"github.com/gogf/gf/util/gconv"
 )
 
 type DingHandler struct{}
@@ -24,6 +26,9 @@ func (h *DingHandler) CallBack(ctx context.Context, req *message.SubsMessage, rs
 	handler := dingtalk.Client.GetDingTalkHandler(req)
 	//设置接收消息的处理方法
 	handler.SetHandleMessageFunc(func(msg *message.MixMessage) string {
+		// 记录日志
+		dingtalk_log.Create(handler.Context.SubsMessage.Ctx, "20", gconv.String(msg))
+
 		switch msg.EventType {
 		case message.EventCheckUrl:
 			return h.handleCheckUrl(msg)
@@ -86,6 +91,9 @@ func (h *DingHandler) handleBpmsInstanceChange(msg *message.MixMessage, ctx *din
 		glog.Error(err)
 		return err.Error()
 	}
+	if instance == nil {
+		return "无匹配的审批实例"
+	}
 	// 处理实例数据(不需要钉钉审批实例参数)
 	switch instance.BizType {
 	case model.CustomerReceive:
@@ -101,16 +109,31 @@ func (h *DingHandler) handleBpmsInstanceChange(msg *message.MixMessage, ctx *din
 				return err.Error()
 			}
 		}
+		err = s.Update(instance, msg)
+		if err != nil {
+			glog.Error(err)
+			return err.Error()
+		}
 		return "success"
 	case model.ProjectCreate:
 		if msg.ProcessType == "finish" || msg.ProcessType == "terminate" {
 			//srv.Handle(instance, msg)
 		}
+		err = s.Update(instance, msg)
+		if err != nil {
+			glog.Error(err)
+			return err.Error()
+		}
 		return "success"
 	case model.ContractCreate:
 		if msg.ProcessType == "finish" || msg.ProcessType == "terminate" {
 			//srv.Handle(instance, msg)
 		}
+		err = s.Update(instance, msg)
+		if err != nil {
+			glog.Error(err)
+			return err.Error()
+		}
 		return "success"
 	}
 

+ 14 - 0
opms_parent/app/model/dingtalk_log/dingtalk_log.go

@@ -0,0 +1,14 @@
+// ==========================================================================
+// This is auto-generated by gf cli tool. Fill this file as you wish.
+// ==========================================================================
+
+package dingtalk_log
+
+import (
+	"dashoo.cn/micro/app/model/dingtalk_log/internal"
+)
+
+// DingtalkLog is the golang structure for table dingtalk_log.
+type DingtalkLog internal.DingtalkLog
+
+// Fill with you ideas below.

+ 24 - 0
opms_parent/app/model/dingtalk_log/internal/dingtalk_log.go

@@ -0,0 +1,24 @@
+// ==========================================================================
+// This is auto-generated by gf cli tool. DO NOT EDIT THIS FILE MANUALLY.
+// ==========================================================================
+
+package internal
+
+import (
+	"github.com/gogf/gf/os/gtime"
+)
+
+// DingtalkLog is the golang structure for table dingtalk_log.
+type DingtalkLog struct {
+	Id          int         `orm:"id,primary"   json:"id"`          // 主键
+	Type        string      `orm:"type"         json:"type"`        // 类型:10 调用钉钉接口;20 钉钉事件回调
+	Content     string      `orm:"content"      json:"content"`     // 请求或响应参数
+	Remark      string      `orm:"remark"       json:"remark"`      // 备注
+	CreatedBy   int         `orm:"created_by"   json:"createdBy"`   // 创建者
+	CreatedName string      `orm:"created_name" json:"createdName"` // 创建人
+	CreatedTime *gtime.Time `orm:"created_time" json:"createdTime"` // 创建时间
+	UpdatedBy   int         `orm:"updated_by"   json:"updatedBy"`   // 更新者
+	UpdatedName string      `orm:"updated_name" json:"updatedName"` // 更新人
+	UpdatedTime *gtime.Time `orm:"updated_time" json:"updatedTime"` // 更新时间
+	DeletedTime *gtime.Time `orm:"deleted_time" json:"deletedTime"` // 删除时间
+}

+ 43 - 0
opms_parent/app/service/dingtalk_log/dingtalk_log.go

@@ -0,0 +1,43 @@
+package dingtalk_log
+
+import (
+	"context"
+	"dashoo.cn/micro/app/dao/dingtalk_log"
+	model "dashoo.cn/micro/app/model/dingtalk_log"
+	"dashoo.cn/micro/app/service"
+	"github.com/gogf/gf/os/glog"
+)
+
+type taskService struct {
+	*service.ContextService
+
+	Dao *dingtalk_log.DingtalkLogDao
+}
+
+func newService(ctx context.Context) (svc *taskService, err error) {
+	svc = new(taskService)
+	if svc.ContextService, err = svc.Init(ctx); err != nil {
+		return nil, err
+	}
+	svc.Dao = dingtalk_log.NewDingtalkLogDao(svc.Tenant)
+	return svc, nil
+}
+
+func Create(ctx context.Context, logType, content string) {
+	srv, err := newService(ctx)
+	if err != nil {
+		glog.Error(err)
+		return
+	}
+	// 构造日志数据
+	var entity model.DingtalkLog
+	entity.Type = logType
+	entity.Content = content
+	service.SetCreatedInfo(&entity, srv.GetCxtUserId(), srv.GetCxtUserName())
+
+	_, err = srv.Dao.Save()
+	if err != nil {
+		glog.Error(err)
+		return
+	}
+}

+ 25 - 5
opms_parent/app/service/plat/plat_schedule.go

@@ -2,6 +2,7 @@ package plat
 
 import (
 	"context"
+	"dashoo.cn/micro/app/service/dingtalk_log"
 	"dashoo.cn/opms_libary/myerrors"
 	"database/sql"
 	"fmt"
@@ -91,6 +92,9 @@ func (s *scheduleService) GetUserBusyStatus(req *model.UserBusyStatusReq) (UserB
 
 	param.UserId = s.GetCxtUserDingtalkId()
 
+	// 记录日志
+	dingtalk_log.Create(s.Ctx, "10", gconv.String(&param))
+
 	// 调用钉钉接口
 	client := libary_dingtalk.NewClient()
 	cal := client.GetCalendar()
@@ -123,6 +127,9 @@ func (s *scheduleService) Create(req *model.AddScheduleSeq) (insertId int64, err
 
 	param.UserId = s.GetCxtUserDingtalkId()
 
+	// 记录日志
+	dingtalk_log.Create(s.Ctx, "10", gconv.String(&param))
+
 	// 调用钉钉接口
 	client := libary_dingtalk.NewClient()
 	cal := client.GetCalendar()
@@ -167,6 +174,9 @@ func (s *scheduleService) SaveByDingEvent(msg *message.MixMessage) (err error) {
 		param.EventId = msg.CalendarEventId
 		param.UserId = msg.UnionIdList[0]
 
+		// 记录日志
+		dingtalk_log.Create(s.Ctx, "10", gconv.String(&param))
+
 		// 获取日程详情
 		// 调用钉钉接口
 		client := libary_dingtalk.NewClient()
@@ -277,9 +287,15 @@ func (s *scheduleService) addScheduleByDing(rsp *calendar.GetEventResponse) erro
 		schedule.SchDateEnd = gtime.NewFromStr(*rsp.End.DateTime)
 	}
 	schedule.UserId = 0 // TODO 获取系统的用户Id
-	schedule.UserUnionId = *rsp.Organizer.Id
-	schedule.UserName = *rsp.Organizer.DisplayName
-	schedule.DingScheduleId = *rsp.Id
+	if rsp.Organizer != nil && rsp.Organizer.Id != nil {
+		schedule.UserUnionId = *rsp.Organizer.Id
+	}
+	if rsp.Organizer != nil && rsp.Organizer.DisplayName != nil {
+		schedule.UserName = *rsp.Organizer.DisplayName
+	}
+	if rsp.Id != nil {
+		schedule.DingScheduleId = *rsp.Id
+	}
 
 	insertId, err := s.Dao.InsertAndGetId(schedule)
 	if err != nil {
@@ -320,6 +336,10 @@ func updateScheduleByDing(rsp *calendar.GetEventResponse, schedule *model.PlatSc
 		schedule.SchDateEnd = gtime.NewFromStr(*rsp.End.DateTime)
 	}
 	schedule.UserId = 0 // TODO 获取系统的用户Id
-	schedule.UserUnionId = *rsp.Organizer.Id
-	schedule.UserName = *rsp.Organizer.DisplayName
+	if rsp.Organizer != nil && rsp.Organizer.Id != nil {
+		schedule.UserUnionId = *rsp.Organizer.Id
+	}
+	if rsp.Organizer != nil && rsp.Organizer.DisplayName != nil {
+		schedule.UserName = *rsp.Organizer.DisplayName
+	}
 }

+ 14 - 1
opms_parent/app/service/workflow/work_flow.go

@@ -7,10 +7,13 @@ import (
 	"dashoo.cn/micro/app/service"
 	"dashoo.cn/opms_libary/myerrors"
 	"dashoo.cn/opms_libary/plugin/dingtalk"
+	"dashoo.cn/opms_libary/plugin/dingtalk/message"
 	"dashoo.cn/opms_libary/plugin/dingtalk/workflow"
 	"dashoo.cn/opms_libary/utils"
 	"github.com/gogf/gf/frame/g"
 	"github.com/gogf/gf/os/gtime"
+	"github.com/gogf/gf/util/gconv"
+	"time"
 )
 
 type workflowService struct {
@@ -87,7 +90,7 @@ func (s *workflowService) saveWorkflowInstance(bizCode, bizType, instanceId stri
 	var instance model.PlatWorkflow
 	instance.BizCode = bizCode
 	instance.BizType = bizType
-	instance.CurrentNode = "新建"
+	instance.CurrentNode = "create"
 	instance.CurrentNodeTime = now.Format("Y-m-d H:i:s")
 	instance.ProcessInstId = instanceId
 	// 填充创建信息
@@ -103,6 +106,16 @@ func (s *workflowService) GetWorkflowInstance(instanceId string) (*model.PlatWor
 	return s.Dao.Where("process_inst_id", instanceId).FindOne()
 }
 
+// Update 更新(本地数据)
+func (s *workflowService) Update(instance *model.PlatWorkflow, msg *message.MixMessage) (err error) {
+	// 保存实例
+	instance.CurrentNode = msg.ProcessType
+	instance.CurrentNodeTime = time.Unix(gconv.Int64(msg.FinishTime), 0).Format("2006-01-02 15:04:05")
+	instance.ApprovalResult = msg.Result
+	_, err = s.Dao.Save(instance)
+	return
+}
+
 // GetList 任务信息列表(本地数据)
 func (s *workflowService) GetList(req *model.SearchWorkflowReq) (total int, flowList []*model.PlatWorkflow, err error) {
 	flowModel := s.Dao.M