...
|
...
|
@@ -287,16 +287,17 @@ func Templates(header *protocol.RequestHeader, request *protocol.TemplatesReques |
|
|
//模板详情
|
|
|
func Template(header *protocol.RequestHeader, request *protocol.TemplateRequest) (rsp *protocol.TemplateResponse, err error) {
|
|
|
var (
|
|
|
templates *models.AuditTemplate
|
|
|
forms []*models.AuditForm
|
|
|
chance *models.Chance
|
|
|
templates *models.AuditTemplate
|
|
|
forms []*models.AuditForm
|
|
|
chance *models.Chance
|
|
|
chanceDraft *models.ChanceDraft
|
|
|
)
|
|
|
rsp = &protocol.TemplateResponse{}
|
|
|
if templates, err = models.GetAuditTemplate(header.CompanyId, request.ChanceTypeId, request.TemplateId); err != nil {
|
|
|
log.Error(fmt.Sprintf("公司:%v chance_type_id:%v id:%v无模板 ", header.CompanyId, request.ChanceTypeId, request.TemplateId), err)
|
|
|
return
|
|
|
}
|
|
|
if request.ChanceId > 0 {
|
|
|
if request.ChanceId > 0 && !request.IsDraft {
|
|
|
if chance, err = models.GetChanceById(request.ChanceId); err == nil {
|
|
|
if chance.EnableStatus == 0 {
|
|
|
err = protocol.NewErrWithMessage(5101)
|
...
|
...
|
@@ -326,9 +327,17 @@ func Template(header *protocol.RequestHeader, request *protocol.TemplateRequest) |
|
|
template.Link = fmt.Sprintf("%v/#/ability/opportunity?id=%v", beego.AppConfig.String("h5_host"), item.Id)
|
|
|
}
|
|
|
if request.ChanceId > 0 {
|
|
|
if template.Questions, err = agg.GetCheckQuestionsByChanceId(header, request.ChanceId); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
if request.IsDraft { //是否是机会草稿
|
|
|
if chanceDraft, err = models.GetChanceDraftById(request.ChanceId); err == nil {
|
|
|
var old []protocol.SelfCheck
|
|
|
utils.JsonUnmarshal(chanceDraft.SelfChecks, &old)
|
|
|
template.Questions = GetNewestCheckQuestions(chanceDraft.AuditTemplateId, old)
|
|
|
}
|
|
|
} else { //正常机会
|
|
|
if template.Questions, err = agg.GetCheckQuestionsByChanceId(header, request.ChanceId); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
if template.Questions, err = agg.GetCheckQuestionsByTemplateId(templates.Id); err != nil {
|
...
|
...
|
@@ -2043,6 +2052,60 @@ func ChanceDetail(header *protocol.RequestHeader, request *protocol.ChanceDetail |
|
|
return
|
|
|
}
|
|
|
|
|
|
func ChanceDraftDetail(header *protocol.RequestHeader, request *protocol.ChanceDetailRequest) (rsp *protocol.ChanceDetailResponse, err error) {
|
|
|
var (
|
|
|
chance *models.ChanceDraft
|
|
|
chanceData *models.ChanceData
|
|
|
provider *protocol.BaseUserInfo
|
|
|
)
|
|
|
rsp = &protocol.ChanceDetailResponse{}
|
|
|
if chance, err = models.GetChanceDraftById(request.Id); err != nil {
|
|
|
if err == orm.ErrNoRows {
|
|
|
err = protocol.NewErrWithMessage(5101)
|
|
|
return
|
|
|
}
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
//用户信息
|
|
|
if provider, err = agg.GetUserBaseInfo(chance.UserId, header.CompanyId); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if template, e := models.GetAuditTemplateById(chance.AuditTemplateId); e == nil {
|
|
|
rsp.ChanceTemplate = protocol.NameItem{
|
|
|
Id: int(template.Id),
|
|
|
Name: template.Name,
|
|
|
}
|
|
|
}
|
|
|
if chanceType, e := models.GetChanceTypeById(chance.ChanceTypeId); e == nil {
|
|
|
rsp.ChanceType = protocol.NameItem{
|
|
|
Id: int(chanceType.Id),
|
|
|
Name: chanceType.Name,
|
|
|
}
|
|
|
}
|
|
|
item := protocol.ChanceItem{
|
|
|
Id: chance.Id,
|
|
|
Provider: provider,
|
|
|
CreateTime: chance.CreateAt.Unix() * 1000,
|
|
|
UpdateTime: chance.UpdateAt.Unix() * 1000,
|
|
|
}
|
|
|
jsonUnmarshal(chance.SourceContent, &item.FormList)
|
|
|
jsonUnmarshal(chance.SelfChecks, &item.SelfChecks)
|
|
|
item.FormList = clearEmptyForm(item.FormList)
|
|
|
|
|
|
if chanceData, err = models.GetChanceDataByChanceId(chance.Id); err == nil {
|
|
|
if len(chanceData.Videos) > 0 {
|
|
|
chanceData.Videos = strings.ReplaceAll(chanceData.Videos, "https", "http")
|
|
|
}
|
|
|
jsonUnmarshal(chanceData.Images, &item.Pictures)
|
|
|
jsonUnmarshal(chanceData.Speechs, &item.Speechs)
|
|
|
jsonUnmarshal(chanceData.Videos, &item.Videos)
|
|
|
}
|
|
|
rsp.ChanceDetail = item
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//机会删除
|
|
|
func ChanceDelete(header *protocol.RequestHeader, request *protocol.ChanceDeleteRequest) (rsp *protocol.ChanceDeleteResponse, err error) {
|
|
|
var (
|
...
|
...
|
@@ -2408,11 +2471,11 @@ 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)
|
|
|
//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)
|
|
|
//commItem.Questions = GetNewestCheckQuestions(int64(ormItem.TemplateId), commItem.Chance.SelfChecks)
|
|
|
rsp.List = append(rsp.List, commItem)
|
|
|
}
|
|
|
return
|
...
|
...
|
@@ -2445,31 +2508,20 @@ func getNewestFormList(new []*protocol.Form, old []*protocol.Form) []*protocol.F |
|
|
}
|
|
|
|
|
|
//获取最新的自查列表
|
|
|
func GetNewestSelfChecks(tpId int64, old []protocol.SelfCheck) protocol.SelfChecks {
|
|
|
var new []protocol.SelfCheck = make([]protocol.SelfCheck, 0)
|
|
|
func GetNewestCheckQuestions(tpId int64, old []protocol.SelfCheck) []*protocol.CheckQuestion {
|
|
|
var rsp = []*protocol.CheckQuestion{}
|
|
|
if questions, err := agg.GetCheckQuestionsByTemplateId(tpId); err != nil {
|
|
|
log.Error(err)
|
|
|
return old
|
|
|
return rsp
|
|
|
} 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
|
|
|
getNewestSelfChecks(questions, old)
|
|
|
rsp = questions
|
|
|
}
|
|
|
return rsp
|
|
|
}
|
|
|
func getNewestSelfChecks(new []protocol.SelfCheck, old []protocol.SelfCheck) []protocol.SelfCheck {
|
|
|
func getNewestSelfChecks(new []*protocol.CheckQuestion, old []protocol.SelfCheck) {
|
|
|
if len(new) == 0 {
|
|
|
return old
|
|
|
return
|
|
|
}
|
|
|
for i := 0; i < len(new); i++ {
|
|
|
itemNew := new[i]
|
...
|
...
|
@@ -2482,5 +2534,5 @@ func getNewestSelfChecks(new []protocol.SelfCheck, old []protocol.SelfCheck) []p |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return new
|
|
|
return
|
|
|
} |
...
|
...
|
|