作者 yangfu

1.修改机会变更详情

... ... @@ -558,9 +558,9 @@ type Speech struct {
//图片
type Picture struct {
Path string `json:"path"`
W int `json:"-"` //w
H int `json:"-"` //h
ImageId string `json:"imageId"` //imageId
W int `json:"-"` //w
H int `json:"-"` //h
ImageId string `json:"imageId,omitempty"` //imageId
PathBak string `json:"-"`
//JobId string `json:"job_id"`
}
... ... @@ -728,7 +728,11 @@ type ChanceReviseLog struct {
}
type ReviseContent struct {
Content string `json:"content"`
InputType string `json:"inputType"`
Label string `json:"label"`
Content string `json:"content"`
Data []*FormDataItem `json:"data"`
RemoveAllPhotoVideo bool `json:"removeAllPhotoVideo"` //是否移除所有媒体数据
}
/*ChanceReviseDetail 机会补充详情*/
... ...
... ... @@ -50,6 +50,8 @@ const (
InputFiles = "files"
InputCheckbox = "checkbox"
InputText = "text"
InputImage = "image"
InputVideo = "video"
)
var MapStaticName map[int64]string
... ...
... ... @@ -249,16 +249,96 @@ func GetIncrementSqlBatch(table string, column string, incre int, ids ...int64)
}
}
//清楚未填写的表单数据
func ClearEmptyForm(inputFormList []*protocol.Form) (FormList []*protocol.Form) {
type Filters func(inputFormList []*protocol.Form) (forms []*protocol.Form)
//清除未填写的表单数据
func ClearEmptyForm(inputFormList []*protocol.Form) (forms []*protocol.Form) {
if len(inputFormList) == 0 {
return
}
for i := range inputFormList {
item := inputFormList[i]
if len(item.Data) == 0 {
item.Data = make([]*protocol.FormDataItem, 0)
}
if len(item.ValueList) == 0 {
item.ValueList = make([]*protocol.ValueListItem, 0)
}
if len(item.Value) > 0 {
FormList = append(FormList, item)
forms = append(forms, item)
}
}
return
}
//清楚文件表单数据
func ClearFilesForm(inputFormList []*protocol.Form) (forms []*protocol.Form) {
if len(inputFormList) == 0 {
return
}
for i := range inputFormList {
item := inputFormList[i]
if strings.EqualFold(strings.TrimSpace(item.InputType), protocol.InputFiles) {
continue
}
forms = append(forms, item)
}
return
}
func FormFilter(inputFormList []*protocol.Form, fiters ...Filters) (forms []*protocol.Form) {
for i := range fiters {
forms = fiters[i](inputFormList)
}
return
}
//表单所有媒体文件
func FormsAllFiles(inputFormList []*protocol.Form) ([]protocol.Picture, []protocol.Video) {
var (
pictures []protocol.Picture = make([]protocol.Picture, 0)
videos []protocol.Video = make([]protocol.Video, 0)
)
for i := range inputFormList {
item := inputFormList[i]
if !strings.EqualFold(strings.TrimSpace(item.InputType), protocol.InputFiles) {
continue
}
for j := range item.Data {
var (
path string = item.Data[j].Path
cover *protocol.Cover = &protocol.Cover{}
duration int = item.Data[j].Duration
)
if len(strings.TrimSpace(item.Data[j].Path)) == 0 {
continue
}
switch item.Data[j].Type {
case protocol.InputImage:
pictures = append(pictures, protocol.Picture{
Path: path,
})
break
case protocol.InputVideo:
if item.Data[j].Cover == nil {
continue
}
cover = item.Data[j].Cover
videos = append(videos, protocol.Video{
Path: path,
Duration: duration,
Cover: *cover,
})
break
}
}
}
return pictures, videos
}
func CombineAllFiles(inputFormList []*protocol.Form, pics []protocol.Picture, vids []protocol.Video) ([]protocol.Picture, []protocol.Video) {
formPics, formVids := FormsAllFiles(inputFormList)
formPics = append(formPics, pics...)
formVids = append(formVids, vids...)
return formPics, formVids
}
... ...
... ... @@ -240,10 +240,11 @@ func SetChanceItem(header *protocol.RequestHeader, chance protocol.CommChanceIte
item.UpdateTime = 0
}
utils.JsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = ClearEmptyForm(item.FormList)
utils.JsonUnmarshal(chance.Images, &item.Pictures)
utils.JsonUnmarshal(chance.Voices, &item.Speechs)
utils.JsonUnmarshal(chance.Videos, &item.Videos)
item.Pictures, item.Videos = CombineAllFiles(item.FormList, item.Pictures, item.Videos)
item.FormList = FormFilter(item.FormList, ClearEmptyForm, ClearFilesForm)
return item, chanceStatus
}
func SetMsgItem(header *protocol.RequestHeader, msg protocol.MsgItemOrm, commItem *protocol.MsgCommonListItem) {
... ...
... ... @@ -654,7 +654,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)
... ... @@ -797,11 +797,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)
... ... @@ -813,49 +808,76 @@ func CheckChanceDifferent(header *protocol.RequestHeader, chance *models.Chance,
if chance.ReviewStatus != protocol.ReviewStatusPass {
return
}
var modifyLog = protocol.ChanceReviseLog{
RemoveAllPhotoVideo: false,
RemoveAllSpeech: false,
}
checkIsSaveLog := func() {
var (
isSaveLog bool = false
modifyLog = protocol.ChanceReviseLog{
RemoveAllPhotoVideo: false,
RemoveAllSpeech: false,
}
)
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 {
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
... ... @@ -866,12 +888,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
}
... ... @@ -888,16 +910,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)
}
... ... @@ -911,49 +930,61 @@ func CheckChanceDifferent(header *protocol.RequestHeader, chance *models.Chance,
modifyLog.DiffContents = make([]protocol.ReviseContent, 0)
}
}
checkModifyLog()
if isSaveLog { //&& changeCount > 0
orm := orm.NewOrm()
orm.Begin()
var logId int64
//发送日志
if id, err := agg.SaveApproveLogResult(orm, 10, header.UserId, chance.Id); err != nil {
log.Error(err)
orm.Rollback()
return
} else {
logId = id
}
//保存修改详情
chanceReviseLog = &models.ChanceReviseLog{
Id: idgen.Next(),
ChanceId: chance.Id,
UserCompanyId: header.UserId,
Data: common.AssertJson(modifyLog),
CreateAt: time.Now(),
AuditFlowLogId: logId,
}
if _, e := orm.Insert(chanceReviseLog); e != nil {
log.Error(e)
orm.Rollback()
return
}
if chanceType, err := models.GetChanceTypeById(chance.ChanceTypeId); err != nil {
log.Error(err)
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 {
log.Error(err)
orm.Rollback()
return
}
orm.Commit()
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
//发送日志
if id, err := agg.SaveApproveLogResult(orm, 10, header.UserId, chance.Id); err != nil {
log.Error(err)
orm.Rollback()
return
} else {
logId = id
}
//保存修改详情
chanceReviseLog = &models.ChanceReviseLog{
Id: idgen.Next(),
ChanceId: chance.Id,
UserCompanyId: header.UserId,
Data: common.AssertJson(modifyLog),
CreateAt: time.Now(),
AuditFlowLogId: logId,
}
if _, e := orm.Insert(chanceReviseLog); e != nil {
log.Error(e)
orm.Rollback()
return
}
if chanceType, err := models.GetChanceTypeById(chance.ChanceTypeId); err != nil {
log.Error(err)
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 {
log.Error(err)
orm.Rollback()
return
}
orm.Commit()
return
}
//修改公开状态
... ... @@ -1627,6 +1658,8 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ
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
//点赞评论数据
... ...