...
|
...
|
@@ -8,6 +8,7 @@ import ( |
|
|
"oppmg/models"
|
|
|
"oppmg/protocol"
|
|
|
"oppmg/utils"
|
|
|
"oppmg/utils/idworker"
|
|
|
"strings"
|
|
|
"time"
|
|
|
|
...
|
...
|
@@ -129,11 +130,82 @@ func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rs |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//添加自查内容
|
|
|
err = addSelfCheckData(templateId, request.SelfCheck, orm)
|
|
|
if err != nil {
|
|
|
log.Error("模板设置,添加自查内容失败,err:%s", err)
|
|
|
orm.Rollback()
|
|
|
return nil, protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
orm.Commit()
|
|
|
rsp = &protocol.TemplateAddResponse{}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//SetSelfCheckData 机会模板设置-自查内容设置
|
|
|
func addSelfCheckData(templateId int64, data []protocol.TemplateSelfCheck, om orm2.Ormer) error {
|
|
|
var (
|
|
|
addSelfCheck []models.AuditCheck
|
|
|
err error
|
|
|
)
|
|
|
defaultItem := models.AuditCheckItems{
|
|
|
Items: []models.AuditCheckItem{
|
|
|
models.AuditCheckItem{Item: "是", NeedOther: 0},
|
|
|
models.AuditCheckItem{Item: "否", NeedOther: 1},
|
|
|
models.AuditCheckItem{Item: "不清楚", NeedOther: 0},
|
|
|
},
|
|
|
}
|
|
|
defaultItemJson, _ := json.Marshal(defaultItem)
|
|
|
nowTime := time.Now()
|
|
|
for _, v := range data {
|
|
|
mId := idworker.NextId()
|
|
|
m := models.AuditCheck{
|
|
|
Id: mId,
|
|
|
Pid: 0,
|
|
|
TemplateId: templateId,
|
|
|
Title: v.Title,
|
|
|
Enable: models.AUDITCHECK_ENABLE_YES,
|
|
|
CreateTime: nowTime,
|
|
|
Items: string(defaultItemJson),
|
|
|
}
|
|
|
addSelfCheck = append(addSelfCheck, m)
|
|
|
if len(v.Child) > 0 {
|
|
|
for _, vv := range v.Child {
|
|
|
childId := idworker.NextId()
|
|
|
childDdata := models.AuditCheck{
|
|
|
Id: childId,
|
|
|
Pid: mId,
|
|
|
TemplateId: templateId,
|
|
|
Title: vv.Title,
|
|
|
Enable: models.AUDITCHECK_ENABLE_YES,
|
|
|
CreateTime: nowTime,
|
|
|
Items: string(defaultItemJson),
|
|
|
}
|
|
|
addSelfCheck = append(addSelfCheck, childDdata)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
_, err = om.InsertMulti(10, addSelfCheck)
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
func editSelfCheckData(templateId int64, data []protocol.TemplateSelfCheck, om orm2.Ormer) error {
|
|
|
var (
|
|
|
err error
|
|
|
)
|
|
|
err = models.DeleteAuditCheckByTempelate(templateId, om)
|
|
|
if err != nil {
|
|
|
log.Error("软删除audit_check数据失败,err;%s", err)
|
|
|
return err
|
|
|
}
|
|
|
err = addSelfCheckData(templateId, data, om)
|
|
|
if err != nil {
|
|
|
log.Error("添加audit_check数据失败,err:%s", err)
|
|
|
return err
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func jsonAssertMarsh(v interface{}) string {
|
|
|
if data, e := json.Marshal(v); e != nil {
|
|
|
log.Error(fmt.Sprintf("%v %v", e.Error(), v))
|
...
|
...
|
@@ -255,7 +327,12 @@ func TemplateUpdate(uid, companyId int64, request *protocol.TemplateUpdateReques |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
err = editSelfCheckData(template.Id, request.SelfCheck, orm)
|
|
|
if err != nil {
|
|
|
log.Error("更新audit_check数据失败:err:%s", err)
|
|
|
orm.Rollback()
|
|
|
return rsp, protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
orm.Commit()
|
|
|
rsp = &protocol.TemplateUpdateResponse{}
|
|
|
return
|
...
|
...
|
|