作者 tangxvhui

Merge branch 'dev' into test

... ... @@ -195,36 +195,123 @@ func addSelfCheckData(templateId int64, data []protocol.TemplateSelfCheck, om or
}
//editSelfCheckData 机会模板设置-自查内容设置
// func editSelfCheckData(templateId int64, data []protocol.TemplateSelfCheck, om orm2.Ormer) error {
// if len(data) == 0 {
// return nil
// }
// 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
// }
//editSelfCheckData2 编辑自查内容
func editSelfCheckData(templateId int64, data []protocol.TemplateSelfCheck, om orm2.Ormer) error {
if len(data) == 0 {
return nil
}
var (
err error
deleteId []int64
updateSelfCheck []models.AuditCheck
newSelfCheckData []models.AuditCheck
oldSelfCheckMap = make(map[int64]*models.AuditCheck)
)
/**简单做法**/
err = models.DeleteAuditCheckByTempelate(templateId, om)
oldSelfCheck, err := models.GetAuditCheckByTemplate(templateId)
if err != nil {
log.Error("软删除audit_check数据失败,err;%s", err)
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
for i := range oldSelfCheck {
oldSelfCheckMap[oldSelfCheck[i].Id] = &oldSelfCheck[i]
}
nowTime := time.Now()
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)
for k, v := range data {
m := models.AuditCheck{
Id: v.Id,
Pid: v.Pid,
Title: v.Title,
CreateTime: nowTime,
Items: string(defaultItemJson),
Enable: models.AUDITCHECK_ENABLE_YES,
TemplateId: templateId,
}
if m.Id == 0 {
m.Id = idworker.NextId()
newSelfCheckData = append(newSelfCheckData, m)
} else if _, ok := oldSelfCheckMap[m.Id]; ok {
updateSelfCheck = append(updateSelfCheck, m)
delete(oldSelfCheckMap, m.Id)
}
for _, vv := range data[k].Child {
mm := models.AuditCheck{
Id: vv.Id,
Pid: m.Id,
Title: vv.Title,
CreateTime: nowTime,
Items: string(defaultItemJson),
Enable: models.AUDITCHECK_ENABLE_YES,
TemplateId: templateId,
}
if mm.Id == 0 {
mm.Id = idworker.NextId()
newSelfCheckData = append(newSelfCheckData, mm)
} else if _, ok := oldSelfCheckMap[m.Id]; ok {
updateSelfCheck = append(updateSelfCheck, mm)
delete(oldSelfCheckMap, mm.Id)
}
}
}
for i := range oldSelfCheckMap {
deleteId = append(deleteId, oldSelfCheckMap[i].Id)
}
return nil
}
//editSelfCheckData2 编辑自查内容
func editSelfCheckData2(templateId int64, data []protocol.TemplateSelfCheck, om orm2.Ormer) error {
// var (
// updateId []int64
// deleteId []int64
// updateSelfCheck []models.AuditCheck
// newSelfCheckData []models.AuditCheck
// )
//删除废弃项
if len(deleteId) > 0 {
_, err = om.QueryTable(&models.AuditCheck{}).
Filter("id__in", deleteId).
Update(orm2.Params{
"enable": models.AUDITCHECK_ENABLE_NO,
})
if err != nil {
log.Error("删除audit_check旧数据失败,err:%s", err)
return err
}
}
//添加新的项
if len(newSelfCheckData) > 0 {
if _, err = om.InsertMulti(10, newSelfCheckData); err != nil {
log.Error("添加audit_check数据失败:%s", err)
return err
}
}
//更新项
for i := range updateSelfCheck {
_, err = om.QueryTable(&models.AuditCheck{}).
Filter("id", updateSelfCheck[i].Id).
Update(orm2.Params{
"title": updateSelfCheck[i].Title,
})
if err != nil {
log.Error("更新audit_check数据失败:%s", err)
return err
}
}
return nil
}
... ...