|
|
@@ -2,30 +2,33 @@ package workflow
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
- "dashoo.cn/micro/app/dao/plat"
|
|
|
+ dao "dashoo.cn/micro/app/dao/workflow"
|
|
|
+ model "dashoo.cn/micro/app/model/workflow"
|
|
|
"dashoo.cn/micro/app/service"
|
|
|
+ "dashoo.cn/opms_libary/myerrors"
|
|
|
"dashoo.cn/opms_libary/plugin/dingtalk"
|
|
|
"dashoo.cn/opms_libary/plugin/dingtalk/workflow"
|
|
|
"dashoo.cn/opms_libary/utils"
|
|
|
"github.com/gogf/gf/frame/g"
|
|
|
+ "github.com/gogf/gf/os/gtime"
|
|
|
)
|
|
|
|
|
|
type workflowService struct {
|
|
|
*service.ContextService
|
|
|
|
|
|
- Dao *plat.PlatTaskDao
|
|
|
+ Dao *dao.PlatWorkflowDao
|
|
|
}
|
|
|
|
|
|
-func NewTaskService(ctx context.Context) (svc *workflowService, err error) {
|
|
|
+func NewFlowService(ctx context.Context) (svc *workflowService, err error) {
|
|
|
svc = new(workflowService)
|
|
|
if svc.ContextService, err = svc.Init(ctx); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
- svc.Dao = plat.NewPlatTaskDao(svc.Tenant)
|
|
|
+ svc.Dao = dao.NewPlatWorkflowDao(svc.Tenant)
|
|
|
return svc, nil
|
|
|
}
|
|
|
|
|
|
-// GetProcessInstanceDetail 获取审批实例详情
|
|
|
+// GetProcessInstanceDetail 获取审批实例详情(钉钉接口)
|
|
|
func (s *workflowService) GetProcessInstanceDetail(instId string) (*workflow.QueryProcessInstanceResponse, error) {
|
|
|
g.Log().Info("搜索值", instId)
|
|
|
// 调用钉钉接口
|
|
|
@@ -38,7 +41,7 @@ func (s *workflowService) GetProcessInstanceDetail(instId string) (*workflow.Que
|
|
|
return &resp, nil
|
|
|
}
|
|
|
|
|
|
-// StartProcessInstance 发起一个新的审批流
|
|
|
+// StartProcessInstance 发起一个新的审批流(钉钉接口,并回填到本地系统)
|
|
|
// OriginatorUserId = utils.String("当前用户的钉钉中的Id")
|
|
|
// ProcessCode = utils.String("每种审批对应固定的code")
|
|
|
// bizType:业务类型(10领用20项目创建30合同创建
|
|
|
@@ -47,8 +50,8 @@ func (s *workflowService) StartProcessInstance(bizCode, bizType string, flow *wo
|
|
|
g.Log().Info("搜索值", flow)
|
|
|
// 参数调整
|
|
|
if flow.OriginatorUserId == nil {
|
|
|
- // TODO s.GetCxtDingId()
|
|
|
- flow.OriginatorUserId = utils.String("s.GetCxtDingId()")
|
|
|
+ // TODO s.GetCxtDingId() 目前写死
|
|
|
+ flow.OriginatorUserId = utils.String("2710120955840801")
|
|
|
}
|
|
|
// 调用钉钉接口
|
|
|
client := dingtalk.NewClient()
|
|
|
@@ -58,10 +61,10 @@ func (s *workflowService) StartProcessInstance(bizCode, bizType string, flow *wo
|
|
|
return 0, err
|
|
|
}
|
|
|
|
|
|
- return s.saveWorkflowInstance(bizCode, bizType, resp.InstanceId, flow)
|
|
|
+ return s.saveWorkflowInstance(bizCode, bizType, resp.InstanceId)
|
|
|
}
|
|
|
|
|
|
-// RevokeProcessInstance 撤销审批实例
|
|
|
+// RevokeProcessInstance 撤销审批实例(钉钉接口)
|
|
|
func (s *workflowService) RevokeProcessInstance(instId, remark string) (string, error) {
|
|
|
g.Log().Info("搜索值instId, remark:", instId, remark)
|
|
|
// 调用钉钉接口
|
|
|
@@ -76,6 +79,49 @@ func (s *workflowService) RevokeProcessInstance(instId, remark string) (string,
|
|
|
}
|
|
|
|
|
|
// 将审批实例同步到数据库中
|
|
|
-func (s *workflowService) saveWorkflowInstance(bizCode, bizType, instanceId string, flow *workflow.StartProcessInstanceRequest) (insertId int64, err error) {
|
|
|
- return 0, nil
|
|
|
+func (s *workflowService) saveWorkflowInstance(bizCode, bizType, instanceId string) (insertId int64, err error) {
|
|
|
+ now := gtime.Now()
|
|
|
+
|
|
|
+ // 构造基础数据
|
|
|
+ var instance model.PlatWorkflow
|
|
|
+ instance.BizCode = bizCode
|
|
|
+ instance.BizType = bizType
|
|
|
+ instance.CurrentNode = "新建"
|
|
|
+ instance.CurrentNodeTime = now.Format("Y-m-d H:i:s")
|
|
|
+ instance.ProcessInstId = instanceId
|
|
|
+ // 填充创建信息
|
|
|
+ service.SetCreatedInfo(&instance, s.GetCxtUserId(), s.GetCxtUserName())
|
|
|
+
|
|
|
+ // 保存数据并返回
|
|
|
+ return s.Dao.InsertAndGetId(instance)
|
|
|
+}
|
|
|
+
|
|
|
+// GetWorkflowInstance 获取实例(本地数据)
|
|
|
+func (s *workflowService) GetWorkflowInstance(instanceId string) (*model.PlatWorkflow, error) {
|
|
|
+ // 查询日程实例
|
|
|
+ return s.Dao.Where("process_inst_id", instanceId).FindOne()
|
|
|
+}
|
|
|
+
|
|
|
+// GetList 任务信息列表(本地数据)
|
|
|
+func (s *workflowService) GetList(req *model.SearchWorkflowReq) (total int, flowList []*model.PlatWorkflow, err error) {
|
|
|
+ flowModel := s.Dao.M
|
|
|
+ if req.BizCode != "" {
|
|
|
+ flowModel = flowModel.Where("biz_code", req.BizCode)
|
|
|
+ }
|
|
|
+ if req.BizType != "" {
|
|
|
+ flowModel = flowModel.Where("biz_type", req.BizType)
|
|
|
+ }
|
|
|
+ if req.MySelf != "0" {
|
|
|
+ flowModel = flowModel.Where("created_by", s.GetCxtUserId())
|
|
|
+ }
|
|
|
+
|
|
|
+ total, err = flowModel.Count()
|
|
|
+ if err != nil {
|
|
|
+ g.Log().Error(err)
|
|
|
+ err = myerrors.DbError("获取总行数失败。")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ err = flowModel.Page(req.GetPage()).Order("plat_task.created_time DESC").Scan(&flowList)
|
|
|
+ return
|
|
|
}
|