...
|
...
|
@@ -270,14 +270,20 @@ func Templates(header *protocol.RequestHeader, request *protocol.TemplatesReques |
|
|
}
|
|
|
for j := range forms {
|
|
|
form := forms[j]
|
|
|
template.FormList[j] = &protocol.Form{
|
|
|
formItem := &protocol.Form{
|
|
|
Id: form.Id,
|
|
|
Label: form.Label,
|
|
|
Value: "",
|
|
|
InputType: form.InputType,
|
|
|
SectionType: form.Section,
|
|
|
Required: form.Required,
|
|
|
Data: make([]*protocol.FormDataItem, 0),
|
|
|
ValueList: make([]*protocol.ValueListItem, 0),
|
|
|
}
|
|
|
if len(form.ValueList) > 0 && form.InputType == protocol.InputRadio {
|
|
|
utils.JsonUnmarshal(form.ValueList, &formItem.ValueList)
|
|
|
}
|
|
|
template.FormList[j] = formItem
|
|
|
}
|
|
|
rsp.Templates = append(rsp.Templates, template)
|
|
|
}
|
...
|
...
|
@@ -291,6 +297,7 @@ func Template(header *protocol.RequestHeader, request *protocol.TemplateRequest) |
|
|
forms []*models.AuditForm
|
|
|
chance *models.Chance
|
|
|
chanceDraft *models.ChanceDraft
|
|
|
formData []*protocol.Form
|
|
|
)
|
|
|
rsp = &protocol.TemplateResponse{}
|
|
|
if templates, err = models.GetAuditTemplate(header.CompanyId, request.ChanceTypeId, request.TemplateId); err != nil {
|
...
|
...
|
@@ -331,9 +338,11 @@ func Template(header *protocol.RequestHeader, request *protocol.TemplateRequest) |
|
|
if chanceDraft, err = models.GetChanceDraftById(request.ChanceId); err == nil {
|
|
|
var old []protocol.SelfCheck
|
|
|
utils.JsonUnmarshal(chanceDraft.SelfChecks, &old)
|
|
|
utils.JsonUnmarshal(chanceDraft.SourceContent, &formData)
|
|
|
template.Questions = GetNewestCheckQuestions(chanceDraft.AuditTemplateId, old)
|
|
|
}
|
|
|
} else { //正常机会
|
|
|
utils.JsonUnmarshal(chance.SourceContent, &formData)
|
|
|
if template.Questions, err = agg.GetCheckQuestionsByChanceId(header, request.ChanceId); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
...
|
...
|
@@ -347,14 +356,33 @@ func Template(header *protocol.RequestHeader, request *protocol.TemplateRequest) |
|
|
}
|
|
|
for j := range forms {
|
|
|
form := forms[j]
|
|
|
template.FormList[j] = &protocol.Form{
|
|
|
formItem := &protocol.Form{
|
|
|
Id: form.Id,
|
|
|
Label: form.Label,
|
|
|
Value: "",
|
|
|
InputType: form.InputType,
|
|
|
SectionType: form.Section,
|
|
|
Required: form.Required,
|
|
|
Data: make([]*protocol.FormDataItem, 0),
|
|
|
ValueList: make([]*protocol.ValueListItem, 0),
|
|
|
}
|
|
|
if len(form.ValueList) > 0 && form.InputType == protocol.InputRadio {
|
|
|
utils.JsonUnmarshal(form.ValueList, &formItem.ValueList)
|
|
|
}
|
|
|
//填充旧的表单数据
|
|
|
setOldForm := func() {
|
|
|
for i := range formData {
|
|
|
data := formData[i]
|
|
|
if data.Id == formItem.Id && strings.EqualFold(data.Label, data.Label) {
|
|
|
formItem.Value = data.Value
|
|
|
formItem.Data = data.Data
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if request.ChanceId > 0 {
|
|
|
setOldForm()
|
|
|
}
|
|
|
template.FormList[j] = formItem
|
|
|
}
|
|
|
rsp.Template = template
|
|
|
return
|
...
|
...
|
@@ -432,7 +460,7 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit |
|
|
err = protocol.NewErrWithMessage(5302)
|
|
|
return
|
|
|
}
|
|
|
auditConfig = &protocol.AuditConfig{NoApprover: template.NoApprover}
|
|
|
auditConfig = &protocol.AuditConfig{NoApprover: template.NoApprover, SelfCheckNeed: template.SelfCheckNeed}
|
|
|
orm := orm.NewOrm()
|
|
|
orm.Begin()
|
|
|
//2.检查模板是否有权限
|
...
|
...
|
@@ -648,7 +676,7 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate |
|
|
err = protocol.NewErrWithMessage(5301)
|
|
|
return
|
|
|
}
|
|
|
auditConfig = &protocol.AuditConfig{NoApprover: template.NoApprover}
|
|
|
auditConfig = &protocol.AuditConfig{NoApprover: template.NoApprover, SelfCheckNeed: template.SelfCheckNeed}
|
|
|
|
|
|
CheckChanceDifferent(header, chance, request)
|
|
|
|
...
|
...
|
@@ -791,11 +819,6 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate |
|
|
|
|
|
//检查机会更新
|
|
|
func CheckChanceDifferent(header *protocol.RequestHeader, chance *models.Chance, request *protocol.ChanceUpdateRequest) {
|
|
|
var (
|
|
|
isSaveLog bool = false
|
|
|
chanceReviseLog *models.ChanceReviseLog
|
|
|
message string
|
|
|
)
|
|
|
defer func() {
|
|
|
if p := recover(); p != nil {
|
|
|
log.Error(p)
|
...
|
...
|
@@ -804,52 +827,80 @@ func CheckChanceDifferent(header *protocol.RequestHeader, chance *models.Chance, |
|
|
if header.UserId == chance.UserId {
|
|
|
return
|
|
|
}
|
|
|
//机会是审核通过的才有编辑记录!!
|
|
|
if chance.ReviewStatus != protocol.ReviewStatusPass {
|
|
|
return
|
|
|
}
|
|
|
var modifyLog = protocol.ChanceReviseLog{
|
|
|
|
|
|
var (
|
|
|
isSaveLog bool = false
|
|
|
modifyLog = protocol.ChanceReviseLog{
|
|
|
RemoveAllPhotoVideo: false,
|
|
|
RemoveAllSpeech: false,
|
|
|
}
|
|
|
checkIsSaveLog := func() {
|
|
|
)
|
|
|
funcCheckSave := func() {
|
|
|
if !isSaveLog {
|
|
|
isSaveLog = true
|
|
|
}
|
|
|
}
|
|
|
|
|
|
diffFormList := func(source string, dis []*protocol.Form) {
|
|
|
funcDiffForms := func(source string, src []*protocol.Form) {
|
|
|
var (
|
|
|
src []*protocol.Form
|
|
|
mapForm map[string]*protocol.Form = make(map[string]*protocol.Form)
|
|
|
dst []*protocol.Form
|
|
|
mapForm = make(map[string]*protocol.Form)
|
|
|
reviseContents []protocol.ReviseContent
|
|
|
)
|
|
|
jsonUnmarshal(source, &src)
|
|
|
keyFunc := func(form *protocol.Form) string {
|
|
|
utils.JsonUnmarshal(source, &dst)
|
|
|
funcKey := func(form *protocol.Form) string {
|
|
|
return fmt.Sprintf("%v_%v", form.Label, form.SectionType)
|
|
|
}
|
|
|
for i := range src {
|
|
|
mapForm[keyFunc(src[i])] = src[i]
|
|
|
for i := range dst {
|
|
|
mapForm[funcKey(dst[i])] = dst[i]
|
|
|
}
|
|
|
for i := range dis {
|
|
|
isDiff := false
|
|
|
srcValue := ""
|
|
|
if v, ok := mapForm[keyFunc(dis[i])]; ok {
|
|
|
for i := range src {
|
|
|
var (
|
|
|
isDiff = false
|
|
|
oldForm *protocol.Form
|
|
|
srcValue = ""
|
|
|
)
|
|
|
|
|
|
if v, ok := mapForm[funcKey(src[i])]; ok {
|
|
|
srcValue = v.Value
|
|
|
if dis[i].Value != v.Value {
|
|
|
if src[i].Value != v.Value {
|
|
|
isDiff = true
|
|
|
}
|
|
|
if len(src[i].Data) > 0 || len(v.Data) > 0 {
|
|
|
if !reflect.DeepEqual(src[i].Data, v.Data) {
|
|
|
isDiff = true
|
|
|
}
|
|
|
}
|
|
|
oldForm = v
|
|
|
} else {
|
|
|
isDiff = true
|
|
|
}
|
|
|
|
|
|
if isDiff {
|
|
|
reviseContents = append(reviseContents, protocol.ReviseContent{
|
|
|
Content: fmt.Sprintf("将“%v”由“%v”改为 “%v”", dis[i].Label, srcValue, dis[i].Value)})
|
|
|
checkIsSaveLog()
|
|
|
c := protocol.ReviseContent{
|
|
|
Content: fmt.Sprintf("将“%v”由“%v”改为“%v”", src[i].Label, srcValue, src[i].Value),
|
|
|
Label: src[i].Label,
|
|
|
InputType: src[i].InputType,
|
|
|
Data: src[i].Data,
|
|
|
}
|
|
|
|
|
|
//文件表单
|
|
|
if src[i].InputType == protocol.InputFiles {
|
|
|
if oldForm != nil && len(oldForm.Data) > 0 && len(src[i].Data) == 0 {
|
|
|
c.RemoveAllPhotoVideo = true
|
|
|
}
|
|
|
c.Content = fmt.Sprintf("将%v修改为:", src[i].Label)
|
|
|
}
|
|
|
reviseContents = append(reviseContents, c)
|
|
|
funcCheckSave()
|
|
|
}
|
|
|
}
|
|
|
modifyLog.DiffContents = reviseContents
|
|
|
}
|
|
|
diffChanceData := func() {
|
|
|
funcDiffChanceData := func() {
|
|
|
var (
|
|
|
speechs []protocol.Speech
|
|
|
pictures []protocol.Picture
|
...
|
...
|
@@ -860,12 +911,12 @@ func CheckChanceDifferent(header *protocol.RequestHeader, chance *models.Chance, |
|
|
jsonUnmarshal(chanceData.Images, &pictures)
|
|
|
jsonUnmarshal(chanceData.Videos, &videos)
|
|
|
if !reflect.DeepEqual(request.Videos, videos) || !reflect.DeepEqual(request.Pictures, pictures) {
|
|
|
checkIsSaveLog()
|
|
|
funcCheckSave()
|
|
|
modifyLog.Videos = request.Videos
|
|
|
modifyLog.Pictures = request.Pictures
|
|
|
}
|
|
|
if !reflect.DeepEqual(request.Speechs, speechs) {
|
|
|
checkIsSaveLog()
|
|
|
funcCheckSave()
|
|
|
modifyLog.Speechs = request.Speechs
|
|
|
}
|
|
|
|
...
|
...
|
@@ -882,16 +933,13 @@ func CheckChanceDifferent(header *protocol.RequestHeader, chance *models.Chance, |
|
|
modifyLog.RemoveAllSpeech = true
|
|
|
}
|
|
|
} else {
|
|
|
checkIsSaveLog()
|
|
|
funcCheckSave()
|
|
|
modifyLog.Speechs = request.Speechs
|
|
|
modifyLog.Videos = request.Videos
|
|
|
modifyLog.Speechs = request.Speechs
|
|
|
}
|
|
|
}
|
|
|
|
|
|
diffFormList(chance.SourceContent, request.FormList)
|
|
|
diffChanceData()
|
|
|
checkModifyLog := func() {
|
|
|
funcFormatEmpty := func() {
|
|
|
if len(modifyLog.Speechs) == 0 {
|
|
|
modifyLog.Speechs = make([]protocol.Speech, 0)
|
|
|
}
|
...
|
...
|
@@ -905,13 +953,26 @@ func CheckChanceDifferent(header *protocol.RequestHeader, chance *models.Chance, |
|
|
modifyLog.DiffContents = make([]protocol.ReviseContent, 0)
|
|
|
}
|
|
|
}
|
|
|
checkModifyLog()
|
|
|
if isSaveLog { //&& changeCount > 0
|
|
|
|
|
|
funcDiffForms(chance.SourceContent, request.FormList) //比对表单
|
|
|
funcDiffChanceData() //比对机会数据
|
|
|
funcFormatEmpty() //格式化变更日志
|
|
|
if isSaveLog {
|
|
|
_ = SaveChanceReviseLog(header, chance, modifyLog)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//保存机会变更日志
|
|
|
func SaveChanceReviseLog(header *protocol.RequestHeader, chance *models.Chance, modifyLog protocol.ChanceReviseLog) (err error) {
|
|
|
var (
|
|
|
chanceReviseLog *models.ChanceReviseLog
|
|
|
message string
|
|
|
)
|
|
|
orm := orm.NewOrm()
|
|
|
orm.Begin()
|
|
|
var logId int64
|
|
|
var logId, id int64
|
|
|
//发送日志
|
|
|
if id, err := agg.SaveApproveLogResult(orm, 10, header.UserId, chance.Id); err != nil {
|
|
|
if id, err = agg.SaveApproveLogResult(orm, 10, header.UserId, chance.Id); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
...
|
...
|
@@ -932,22 +993,22 @@ func CheckChanceDifferent(header *protocol.RequestHeader, chance *models.Chance, |
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
if chanceType, err := models.GetChanceTypeById(chance.ChanceTypeId); err != nil {
|
|
|
log.Error(err)
|
|
|
if chanceType, e := models.GetChanceTypeById(chance.ChanceTypeId); e != nil {
|
|
|
log.Error(e)
|
|
|
err = e
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
} else {
|
|
|
message = fmt.Sprintf(protocol.MessageChanceRevise, chanceType.Name)
|
|
|
}
|
|
|
//发送修改机会消息
|
|
|
if err := agg.SendMsgWithHeader(header, chance.UserId, "", chanceReviseLog.Id, protocol.SourceTypeChanceReviseLog, message, protocol.MsgTypeChanceRevise, chance.Id); err != nil {
|
|
|
if err = agg.SendMsgWithHeader(header, chance.UserId, "", chanceReviseLog.Id, protocol.SourceTypeChanceReviseLog, message, protocol.MsgTypeChanceRevise, chance.Id); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
orm.Commit()
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//修改公开状态
|
...
|
...
|
@@ -1590,7 +1651,9 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ |
|
|
provider *protocol.BaseUserInfo
|
|
|
flag int
|
|
|
)
|
|
|
if total, err = agg.GetChancePool(header.UserId, header.CompanyId, models.NewChancePoolOption(request.ChanceTypeId, []int{}, request.Type, request.ReserveTypeId), request.DepartmentId, request.IncludeSubDepartment, request.LastId, request.PageSize, &chanceItems); err != nil {
|
|
|
options := models.NewChancePoolOption(request.ChanceTypeId, []int{}, request.Type, request.ReserveTypeId)
|
|
|
options.SetKeyWord(request.KeyWord)
|
|
|
if total, err = agg.GetChancePool(header.UserId, header.CompanyId, options, request.DepartmentId, request.IncludeSubDepartment, request.LastId, request.PageSize, &chanceItems); err != nil {
|
|
|
if err == orm.ErrNoRows {
|
|
|
err = nil
|
|
|
return
|
...
|
...
|
@@ -1615,10 +1678,11 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ |
|
|
CreateTime: chance.CreateTime.Unix() * 1000,
|
|
|
}
|
|
|
jsonUnmarshal(chance.SourceContent, &item.FormList)
|
|
|
item.FormList = clearEmptyForm(item.FormList)
|
|
|
jsonUnmarshal(chance.Images, &item.Pictures)
|
|
|
jsonUnmarshal(chance.Voices, &item.Speechs)
|
|
|
jsonUnmarshal(chance.Videos, &item.Videos)
|
|
|
item.Pictures, item.Videos = agg.CombineAllFiles(item.FormList, item.Pictures, item.Videos)
|
|
|
item.FormList = agg.FormFilter(item.FormList, agg.ClearEmptyForm, agg.ClearFilesForm)
|
|
|
commItem.Chance = item
|
|
|
|
|
|
//点赞评论数据
|
...
|
...
|
@@ -1953,7 +2017,7 @@ func clearEmptyForm(inputFormList []*protocol.Form) (FormList []*protocol.Form) |
|
|
}
|
|
|
for i := range inputFormList {
|
|
|
item := inputFormList[i]
|
|
|
if len(item.Value) > 0 {
|
|
|
if len(item.Value) > 0 || len(item.Data) > 0 {
|
|
|
FormList = append(FormList, item)
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -2018,7 +2082,6 @@ func ChanceDetail(header *protocol.RequestHeader, request *protocol.ChanceDetail |
|
|
UpdateTime: chance.UpdateAt.Unix() * 1000,
|
|
|
}
|
|
|
jsonUnmarshal(chance.SourceContent, &item.FormList)
|
|
|
//jsonUnmarshal(chance.SelfChecks, &item.SelfChecks)
|
|
|
item.SelfChecks = agg.GetChanceSelfChecks(chance)
|
|
|
item.FormList = clearEmptyForm(item.FormList)
|
|
|
item.RelatedDepartmentId = chance.DepartmentId
|
...
|
...
|
@@ -2102,7 +2165,6 @@ func ChanceDraftDetail(header *protocol.RequestHeader, request *protocol.ChanceD |
|
|
item.RelatedDepartmentInfo = agg.GetDepartment(int(chance.DepartmentId))
|
|
|
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 {
|
...
|
...
|
|