...
|
...
|
@@ -45,7 +45,7 @@ func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rs |
|
|
Doc: request.Template.Doc,
|
|
|
Icon: request.Template.Icon,
|
|
|
Code: request.Template.Code,
|
|
|
NoApprover: 1, //TODO:配置
|
|
|
NoApprover: int8(request.AuditFlowConfig.NoApprover), //TODO:配置
|
|
|
SortNum: 0,
|
|
|
VisibleType: int8(0),
|
|
|
EnableStatus: 1,
|
...
|
...
|
@@ -82,11 +82,61 @@ func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rs |
|
|
}
|
|
|
}
|
|
|
//审核配置
|
|
|
{
|
|
|
//删除旧的配置
|
|
|
if err = utils.ExecuteSQLWithOrmer(orm, models.DeleteAuditFlowConfigSql, template.Id); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
//插入新的审批配置
|
|
|
var normalLevel int = 1
|
|
|
for i := range request.AuditFlowConfig.ProcessConfig {
|
|
|
config := request.AuditFlowConfig.ProcessConfig[i]
|
|
|
flowConfig := &models.AuditFlowConfig{
|
|
|
AuditFlowType: config.ProcessType,
|
|
|
}
|
|
|
if config.ProcessType == models.FlowTypeNormal {
|
|
|
flowConfig.Level = normalLevel
|
|
|
normalLevel++
|
|
|
} else {
|
|
|
flowConfig.Level = 1
|
|
|
flowConfig.FromSpecialUser = jsonAssertMarsh(getIdsFrom(config.FromSpecialUser))
|
|
|
}
|
|
|
flowConfig.AuditTemplateId = templateId
|
|
|
flowConfig.ToRole = jsonAssertMarsh(getIdsFrom(config.ToRole))
|
|
|
flowConfig.ToUser = jsonAssertMarsh(getIdsFrom(config.ToUser))
|
|
|
flowConfig.ActionType = config.AcitonType
|
|
|
flowConfig.CreateAt = time.Now()
|
|
|
flowConfig.AuditGroupId = int64(config.GroupId)
|
|
|
flowConfig.ConfigData = jsonAssertMarsh(config)
|
|
|
if _, err = orm.Insert(flowConfig); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
orm.Commit()
|
|
|
rsp = &protocol.TemplateAddResponse{}
|
|
|
return
|
|
|
}
|
|
|
func jsonAssertMarsh(v interface{}) string {
|
|
|
if data, e := json.Marshal(v); e != nil {
|
|
|
log.Error(fmt.Sprintf("%v %v", e.Error(), v))
|
|
|
return ""
|
|
|
} else {
|
|
|
return string(data)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func getIdsFrom(v []protocol.VisibleObject) (ids []int) {
|
|
|
for i := range v {
|
|
|
ids = append(ids, v[i].Id)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//模板更新
|
|
|
func TemplateUpdate(uid, companyId int64, request *protocol.TemplateUpdateRequest) (rsp *protocol.TemplateUpdateResponse, err error) {
|
...
|
...
|
@@ -144,6 +194,42 @@ func TemplateUpdate(uid, companyId int64, request *protocol.TemplateUpdateReques |
|
|
}
|
|
|
}
|
|
|
//审核配置
|
|
|
//审核配置
|
|
|
{
|
|
|
//删除旧的配置
|
|
|
if err = utils.ExecuteSQLWithOrmer(orm, models.DeleteAuditFlowConfigSql, template.Id); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
//插入新的审批配置
|
|
|
var normalLevel int = 1
|
|
|
for i := range request.AuditFlowConfig.ProcessConfig {
|
|
|
config := request.AuditFlowConfig.ProcessConfig[i]
|
|
|
flowConfig := &models.AuditFlowConfig{
|
|
|
AuditFlowType: config.ProcessType,
|
|
|
}
|
|
|
if config.ProcessType == models.FlowTypeNormal {
|
|
|
flowConfig.Level = normalLevel
|
|
|
normalLevel++
|
|
|
} else {
|
|
|
flowConfig.Level = 1
|
|
|
flowConfig.FromSpecialUser = jsonAssertMarsh(getIdsFrom(config.FromSpecialUser))
|
|
|
}
|
|
|
flowConfig.AuditTemplateId = template.Id
|
|
|
flowConfig.ToRole = jsonAssertMarsh(getIdsFrom(config.ToRole))
|
|
|
flowConfig.ToUser = jsonAssertMarsh(getIdsFrom(config.ToUser))
|
|
|
flowConfig.ActionType = config.AcitonType
|
|
|
flowConfig.CreateAt = time.Now()
|
|
|
flowConfig.AuditGroupId = int64(config.GroupId)
|
|
|
flowConfig.ConfigData = jsonAssertMarsh(config)
|
|
|
if _, err = orm.Insert(flowConfig); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
orm.Commit()
|
|
|
rsp = &protocol.TemplateUpdateResponse{}
|
...
|
...
|
@@ -323,6 +409,7 @@ func TemplateGet(uid, companyId int64, request *protocol.TemplateGetRequest) (rs |
|
|
var (
|
|
|
template *models.AuditTemplate
|
|
|
auditForm []*models.AuditForm
|
|
|
configs []*models.AuditFlowConfig
|
|
|
)
|
|
|
rsp = &protocol.TemplateGetResponse{}
|
|
|
if template, err = models.GetAuditTemplateById(int64(request.Id)); err != nil {
|
...
|
...
|
@@ -357,6 +444,23 @@ func TemplateGet(uid, companyId int64, request *protocol.TemplateGetRequest) (rs |
|
|
SectionType: input.Section,
|
|
|
})
|
|
|
}
|
|
|
if configs, err = models.GetAuditFlowConfig(template.Id); err != nil {
|
|
|
log.Error("template:%v %v", template.Id, err.Error())
|
|
|
err = nil
|
|
|
return
|
|
|
}
|
|
|
rsp.AuditFlowConfig = protocol.AuditFlowConfig{
|
|
|
NoApprover: int(template.NoApprover),
|
|
|
}
|
|
|
for i := range configs {
|
|
|
config := configs[i]
|
|
|
var configItem protocol.ProcessConfig
|
|
|
if e := json.Unmarshal([]byte(config.ConfigData), &configItem); e != nil {
|
|
|
log.Error(e.Error())
|
|
|
continue
|
|
|
}
|
|
|
rsp.AuditFlowConfig.ProcessConfig = append(rsp.AuditFlowConfig.ProcessConfig, configItem)
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
}
|
...
|
...
|
|