...
|
...
|
@@ -2311,6 +2311,7 @@ func DraftSaveChance(header *protocol.RequestHeader, request *protocol.DraftSave |
|
|
chance.SourceContent = common.AssertJson(request.FormList)
|
|
|
chance.UpdateAt = time.Now()
|
|
|
chance.DepartmentId = request.RelatedDepartment
|
|
|
chance.SelfChecks = common.AssertJson(request.SelfChecks)
|
|
|
if err = models.UpdateChanceDraftById(chance); err != nil {
|
|
|
err = protocol.NewCustomMessage(1, "该机会已不存在")
|
|
|
return
|
...
|
...
|
@@ -2345,6 +2346,7 @@ func DraftSaveChance(header *protocol.RequestHeader, request *protocol.DraftSave |
|
|
CreateAt: time.Now(),
|
|
|
UpdateAt: time.Now(),
|
|
|
DepartmentId: request.RelatedDepartment,
|
|
|
SelfChecks: common.AssertJson(request.SelfChecks),
|
|
|
}
|
|
|
if _, err = models.AddChanceDraft(chance); err != nil {
|
|
|
log.Error(err)
|
...
|
...
|
@@ -2406,7 +2408,79 @@ func DraftByChance(header *protocol.RequestHeader, request *protocol.DraftByChan |
|
|
commItem.Chance.RelatedDepartmentInfo = agg.GetDepartment(ormItem.DepartmentId)
|
|
|
commItem.Chance.ApproveTime = 0
|
|
|
|
|
|
commItem.Chance.FormList = GetNewestFormList(header, ormItem.ChanceTypeId, ormItem.TemplateId, commItem.Chance.FormList)
|
|
|
if len(ormItem.SelfChecks) > 0 {
|
|
|
utils.JsonUnmarshal(ormItem.SelfChecks, &commItem.Chance.SelfChecks)
|
|
|
}
|
|
|
commItem.Chance.SelfChecks = GetNewestSelfChecks(int64(ormItem.TemplateId), commItem.Chance.SelfChecks)
|
|
|
rsp.List = append(rsp.List, commItem)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//获取最新的表单列表
|
|
|
func GetNewestFormList(header *protocol.RequestHeader, chanceType, tpId int, old []*protocol.Form) []*protocol.Form {
|
|
|
var (
|
|
|
new []*protocol.Form
|
|
|
)
|
|
|
if forms, err := Template(header, &protocol.TemplateRequest{ChanceTypeId: int(chanceType), TemplateId: int(tpId)}); err != nil {
|
|
|
return old
|
|
|
} else {
|
|
|
new = forms.Template.FormList
|
|
|
}
|
|
|
return getNewestFormList(new, old)
|
|
|
}
|
|
|
func getNewestFormList(new []*protocol.Form, old []*protocol.Form) []*protocol.Form {
|
|
|
for i := 0; i < len(new); i++ {
|
|
|
itemNew := new[i]
|
|
|
for j := 0; j < len(old); j++ {
|
|
|
itemOld := old[j]
|
|
|
if itemNew.Id == itemOld.Id && itemNew.Label == itemOld.Label {
|
|
|
new[i].Value = itemOld.Value
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return new
|
|
|
}
|
|
|
|
|
|
//获取最新的自查列表
|
|
|
func GetNewestSelfChecks(tpId int64, old []protocol.SelfCheck) protocol.SelfChecks {
|
|
|
var new []protocol.SelfCheck = make([]protocol.SelfCheck, 0)
|
|
|
if questions, err := agg.GetCheckQuestionsByTemplateId(tpId); err != nil {
|
|
|
log.Error(err)
|
|
|
return old
|
|
|
} else {
|
|
|
for i := range questions {
|
|
|
q := questions[i]
|
|
|
new = append(new, protocol.SelfCheck{
|
|
|
Id: q.Id,
|
|
|
ParentId: q.ParentId,
|
|
|
CheckItem: q.CheckItem,
|
|
|
GroupId: q.GroupId,
|
|
|
Answer: q.Answer,
|
|
|
Reason: q.Reason,
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
new = getNewestSelfChecks(new, old)
|
|
|
protocol.SelfChecks(new).SetSelfChecksLevel1ByRule()
|
|
|
return new
|
|
|
}
|
|
|
func getNewestSelfChecks(new []protocol.SelfCheck, old []protocol.SelfCheck) []protocol.SelfCheck {
|
|
|
if len(new) == 0 {
|
|
|
return old
|
|
|
}
|
|
|
for i := 0; i < len(new); i++ {
|
|
|
itemNew := new[i]
|
|
|
for j := 0; j < len(old); j++ {
|
|
|
itemOld := old[j]
|
|
|
if itemNew.GroupId == itemOld.GroupId && itemNew.CheckItem == itemOld.CheckItem {
|
|
|
new[i].Answer = itemOld.Answer
|
|
|
new[i].Reason = itemOld.Reason
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return new
|
|
|
} |
...
|
...
|
|