作者 yangfu

1.修改机会变更详情

@@ -558,9 +558,9 @@ type Speech struct { @@ -558,9 +558,9 @@ type Speech struct {
558 //图片 558 //图片
559 type Picture struct { 559 type Picture struct {
560 Path string `json:"path"` 560 Path string `json:"path"`
561 - W int `json:"-"` //w  
562 - H int `json:"-"` //h  
563 - ImageId string `json:"imageId"` //imageId 561 + W int `json:"-"` //w
  562 + H int `json:"-"` //h
  563 + ImageId string `json:"imageId,omitempty"` //imageId
564 PathBak string `json:"-"` 564 PathBak string `json:"-"`
565 //JobId string `json:"job_id"` 565 //JobId string `json:"job_id"`
566 } 566 }
@@ -728,7 +728,11 @@ type ChanceReviseLog struct { @@ -728,7 +728,11 @@ type ChanceReviseLog struct {
728 } 728 }
729 729
730 type ReviseContent struct { 730 type ReviseContent struct {
731 - Content string `json:"content"` 731 + InputType string `json:"inputType"`
  732 + Label string `json:"label"`
  733 + Content string `json:"content"`
  734 + Data []*FormDataItem `json:"data"`
  735 + RemoveAllPhotoVideo bool `json:"removeAllPhotoVideo"` //是否移除所有媒体数据
732 } 736 }
733 737
734 /*ChanceReviseDetail 机会补充详情*/ 738 /*ChanceReviseDetail 机会补充详情*/
@@ -50,6 +50,8 @@ const ( @@ -50,6 +50,8 @@ const (
50 InputFiles = "files" 50 InputFiles = "files"
51 InputCheckbox = "checkbox" 51 InputCheckbox = "checkbox"
52 InputText = "text" 52 InputText = "text"
  53 + InputImage = "image"
  54 + InputVideo = "video"
53 ) 55 )
54 56
55 var MapStaticName map[int64]string 57 var MapStaticName map[int64]string
@@ -249,16 +249,96 @@ func GetIncrementSqlBatch(table string, column string, incre int, ids ...int64) @@ -249,16 +249,96 @@ func GetIncrementSqlBatch(table string, column string, incre int, ids ...int64)
249 } 249 }
250 } 250 }
251 251
252 -//清楚未填写的表单数据  
253 -func ClearEmptyForm(inputFormList []*protocol.Form) (FormList []*protocol.Form) { 252 +type Filters func(inputFormList []*protocol.Form) (forms []*protocol.Form)
  253 +
  254 +//清除未填写的表单数据
  255 +func ClearEmptyForm(inputFormList []*protocol.Form) (forms []*protocol.Form) {
254 if len(inputFormList) == 0 { 256 if len(inputFormList) == 0 {
255 return 257 return
256 } 258 }
257 for i := range inputFormList { 259 for i := range inputFormList {
258 item := inputFormList[i] 260 item := inputFormList[i]
  261 + if len(item.Data) == 0 {
  262 + item.Data = make([]*protocol.FormDataItem, 0)
  263 + }
  264 + if len(item.ValueList) == 0 {
  265 + item.ValueList = make([]*protocol.ValueListItem, 0)
  266 + }
259 if len(item.Value) > 0 { 267 if len(item.Value) > 0 {
260 - FormList = append(FormList, item) 268 + forms = append(forms, item)
261 } 269 }
262 } 270 }
263 return 271 return
264 } 272 }
  273 +
  274 +//清楚文件表单数据
  275 +func ClearFilesForm(inputFormList []*protocol.Form) (forms []*protocol.Form) {
  276 + if len(inputFormList) == 0 {
  277 + return
  278 + }
  279 + for i := range inputFormList {
  280 + item := inputFormList[i]
  281 + if strings.EqualFold(strings.TrimSpace(item.InputType), protocol.InputFiles) {
  282 + continue
  283 + }
  284 + forms = append(forms, item)
  285 + }
  286 + return
  287 +}
  288 +
  289 +func FormFilter(inputFormList []*protocol.Form, fiters ...Filters) (forms []*protocol.Form) {
  290 + for i := range fiters {
  291 + forms = fiters[i](inputFormList)
  292 + }
  293 + return
  294 +}
  295 +
  296 +//表单所有媒体文件
  297 +func FormsAllFiles(inputFormList []*protocol.Form) ([]protocol.Picture, []protocol.Video) {
  298 + var (
  299 + pictures []protocol.Picture = make([]protocol.Picture, 0)
  300 + videos []protocol.Video = make([]protocol.Video, 0)
  301 + )
  302 + for i := range inputFormList {
  303 + item := inputFormList[i]
  304 + if !strings.EqualFold(strings.TrimSpace(item.InputType), protocol.InputFiles) {
  305 + continue
  306 + }
  307 + for j := range item.Data {
  308 + var (
  309 + path string = item.Data[j].Path
  310 + cover *protocol.Cover = &protocol.Cover{}
  311 + duration int = item.Data[j].Duration
  312 + )
  313 + if len(strings.TrimSpace(item.Data[j].Path)) == 0 {
  314 + continue
  315 + }
  316 + switch item.Data[j].Type {
  317 + case protocol.InputImage:
  318 + pictures = append(pictures, protocol.Picture{
  319 + Path: path,
  320 + })
  321 + break
  322 + case protocol.InputVideo:
  323 + if item.Data[j].Cover == nil {
  324 + continue
  325 + }
  326 + cover = item.Data[j].Cover
  327 + videos = append(videos, protocol.Video{
  328 + Path: path,
  329 + Duration: duration,
  330 + Cover: *cover,
  331 + })
  332 + break
  333 + }
  334 + }
  335 + }
  336 + return pictures, videos
  337 +}
  338 +
  339 +func CombineAllFiles(inputFormList []*protocol.Form, pics []protocol.Picture, vids []protocol.Video) ([]protocol.Picture, []protocol.Video) {
  340 + formPics, formVids := FormsAllFiles(inputFormList)
  341 + formPics = append(formPics, pics...)
  342 + formVids = append(formVids, vids...)
  343 + return formPics, formVids
  344 +}
@@ -240,10 +240,11 @@ func SetChanceItem(header *protocol.RequestHeader, chance protocol.CommChanceIte @@ -240,10 +240,11 @@ func SetChanceItem(header *protocol.RequestHeader, chance protocol.CommChanceIte
240 item.UpdateTime = 0 240 item.UpdateTime = 0
241 } 241 }
242 utils.JsonUnmarshal(chance.SourceContent, &item.FormList) 242 utils.JsonUnmarshal(chance.SourceContent, &item.FormList)
243 - item.FormList = ClearEmptyForm(item.FormList)  
244 utils.JsonUnmarshal(chance.Images, &item.Pictures) 243 utils.JsonUnmarshal(chance.Images, &item.Pictures)
245 utils.JsonUnmarshal(chance.Voices, &item.Speechs) 244 utils.JsonUnmarshal(chance.Voices, &item.Speechs)
246 utils.JsonUnmarshal(chance.Videos, &item.Videos) 245 utils.JsonUnmarshal(chance.Videos, &item.Videos)
  246 + item.Pictures, item.Videos = CombineAllFiles(item.FormList, item.Pictures, item.Videos)
  247 + item.FormList = FormFilter(item.FormList, ClearEmptyForm, ClearFilesForm)
247 return item, chanceStatus 248 return item, chanceStatus
248 } 249 }
249 func SetMsgItem(header *protocol.RequestHeader, msg protocol.MsgItemOrm, commItem *protocol.MsgCommonListItem) { 250 func SetMsgItem(header *protocol.RequestHeader, msg protocol.MsgItemOrm, commItem *protocol.MsgCommonListItem) {
@@ -654,7 +654,7 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate @@ -654,7 +654,7 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate
654 err = protocol.NewErrWithMessage(5301) 654 err = protocol.NewErrWithMessage(5301)
655 return 655 return
656 } 656 }
657 - auditConfig = &protocol.AuditConfig{NoApprover: template.NoApprover} 657 + auditConfig = &protocol.AuditConfig{NoApprover: template.NoApprover, SelfCheckNeed: template.SelfCheckNeed}
658 658
659 CheckChanceDifferent(header, chance, request) 659 CheckChanceDifferent(header, chance, request)
660 660
@@ -797,11 +797,6 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate @@ -797,11 +797,6 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate
797 797
798 //检查机会更新 798 //检查机会更新
799 func CheckChanceDifferent(header *protocol.RequestHeader, chance *models.Chance, request *protocol.ChanceUpdateRequest) { 799 func CheckChanceDifferent(header *protocol.RequestHeader, chance *models.Chance, request *protocol.ChanceUpdateRequest) {
800 - var (  
801 - isSaveLog bool = false  
802 - chanceReviseLog *models.ChanceReviseLog  
803 - message string  
804 - )  
805 defer func() { 800 defer func() {
806 if p := recover(); p != nil { 801 if p := recover(); p != nil {
807 log.Error(p) 802 log.Error(p)
@@ -813,49 +808,76 @@ func CheckChanceDifferent(header *protocol.RequestHeader, chance *models.Chance, @@ -813,49 +808,76 @@ func CheckChanceDifferent(header *protocol.RequestHeader, chance *models.Chance,
813 if chance.ReviewStatus != protocol.ReviewStatusPass { 808 if chance.ReviewStatus != protocol.ReviewStatusPass {
814 return 809 return
815 } 810 }
816 - var modifyLog = protocol.ChanceReviseLog{  
817 - RemoveAllPhotoVideo: false,  
818 - RemoveAllSpeech: false,  
819 - }  
820 - checkIsSaveLog := func() { 811 +
  812 + var (
  813 + isSaveLog bool = false
  814 + modifyLog = protocol.ChanceReviseLog{
  815 + RemoveAllPhotoVideo: false,
  816 + RemoveAllSpeech: false,
  817 + }
  818 + )
  819 + funcCheckSave := func() {
821 if !isSaveLog { 820 if !isSaveLog {
822 isSaveLog = true 821 isSaveLog = true
823 } 822 }
824 } 823 }
825 -  
826 - diffFormList := func(source string, dis []*protocol.Form) { 824 + funcDiffForms := func(source string, src []*protocol.Form) {
827 var ( 825 var (
828 - src []*protocol.Form  
829 - mapForm map[string]*protocol.Form = make(map[string]*protocol.Form) 826 + dst []*protocol.Form
  827 + mapForm = make(map[string]*protocol.Form)
830 reviseContents []protocol.ReviseContent 828 reviseContents []protocol.ReviseContent
831 ) 829 )
832 - jsonUnmarshal(source, &src)  
833 - keyFunc := func(form *protocol.Form) string { 830 + utils.JsonUnmarshal(source, &dst)
  831 + funcKey := func(form *protocol.Form) string {
834 return fmt.Sprintf("%v_%v", form.Label, form.SectionType) 832 return fmt.Sprintf("%v_%v", form.Label, form.SectionType)
835 } 833 }
836 - for i := range src {  
837 - mapForm[keyFunc(src[i])] = src[i] 834 + for i := range dst {
  835 + mapForm[funcKey(dst[i])] = dst[i]
838 } 836 }
839 - for i := range dis {  
840 - isDiff := false  
841 - srcValue := ""  
842 - if v, ok := mapForm[keyFunc(dis[i])]; ok { 837 + for i := range src {
  838 + var (
  839 + isDiff = false
  840 + oldForm *protocol.Form
  841 + srcValue = ""
  842 + )
  843 +
  844 + if v, ok := mapForm[funcKey(src[i])]; ok {
843 srcValue = v.Value 845 srcValue = v.Value
844 - if dis[i].Value != v.Value { 846 + if src[i].Value != v.Value {
845 isDiff = true 847 isDiff = true
846 } 848 }
  849 + if len(src[i].Data) > 0 {
  850 + if !reflect.DeepEqual(src[i].Data, v.Data) {
  851 + isDiff = true
  852 + }
  853 + }
  854 + oldForm = v
847 } else { 855 } else {
848 isDiff = true 856 isDiff = true
849 } 857 }
  858 +
850 if isDiff { 859 if isDiff {
851 - reviseContents = append(reviseContents, protocol.ReviseContent{  
852 - Content: fmt.Sprintf("将“%v”由“%v”改为 “%v”", dis[i].Label, srcValue, dis[i].Value)})  
853 - checkIsSaveLog() 860 + c := protocol.ReviseContent{
  861 + Content: fmt.Sprintf("将“%v”由“%v”改为 “%v”", src[i].Label, srcValue, src[i].Value),
  862 + Label: src[i].Label,
  863 + InputType: src[i].InputType,
  864 + Data: src[i].Data,
  865 + }
  866 +
  867 + //文件表单
  868 + if src[i].InputType == protocol.InputFiles {
  869 + if oldForm != nil && len(oldForm.Data) > 0 && len(src[i].Data) == 0 {
  870 + c.RemoveAllPhotoVideo = true
  871 + }
  872 + c.Content = fmt.Sprintf("将%v修改为:", src[i].Label)
  873 + }
  874 + reviseContents = append(reviseContents, c)
  875 + funcCheckSave()
854 } 876 }
855 } 877 }
856 modifyLog.DiffContents = reviseContents 878 modifyLog.DiffContents = reviseContents
857 } 879 }
858 - diffChanceData := func() { 880 + funcDiffChanceData := func() {
859 var ( 881 var (
860 speechs []protocol.Speech 882 speechs []protocol.Speech
861 pictures []protocol.Picture 883 pictures []protocol.Picture
@@ -866,12 +888,12 @@ func CheckChanceDifferent(header *protocol.RequestHeader, chance *models.Chance, @@ -866,12 +888,12 @@ func CheckChanceDifferent(header *protocol.RequestHeader, chance *models.Chance,
866 jsonUnmarshal(chanceData.Images, &pictures) 888 jsonUnmarshal(chanceData.Images, &pictures)
867 jsonUnmarshal(chanceData.Videos, &videos) 889 jsonUnmarshal(chanceData.Videos, &videos)
868 if !reflect.DeepEqual(request.Videos, videos) || !reflect.DeepEqual(request.Pictures, pictures) { 890 if !reflect.DeepEqual(request.Videos, videos) || !reflect.DeepEqual(request.Pictures, pictures) {
869 - checkIsSaveLog() 891 + funcCheckSave()
870 modifyLog.Videos = request.Videos 892 modifyLog.Videos = request.Videos
871 modifyLog.Pictures = request.Pictures 893 modifyLog.Pictures = request.Pictures
872 } 894 }
873 if !reflect.DeepEqual(request.Speechs, speechs) { 895 if !reflect.DeepEqual(request.Speechs, speechs) {
874 - checkIsSaveLog() 896 + funcCheckSave()
875 modifyLog.Speechs = request.Speechs 897 modifyLog.Speechs = request.Speechs
876 } 898 }
877 899
@@ -888,16 +910,13 @@ func CheckChanceDifferent(header *protocol.RequestHeader, chance *models.Chance, @@ -888,16 +910,13 @@ func CheckChanceDifferent(header *protocol.RequestHeader, chance *models.Chance,
888 modifyLog.RemoveAllSpeech = true 910 modifyLog.RemoveAllSpeech = true
889 } 911 }
890 } else { 912 } else {
891 - checkIsSaveLog() 913 + funcCheckSave()
892 modifyLog.Speechs = request.Speechs 914 modifyLog.Speechs = request.Speechs
893 modifyLog.Videos = request.Videos 915 modifyLog.Videos = request.Videos
894 modifyLog.Speechs = request.Speechs 916 modifyLog.Speechs = request.Speechs
895 } 917 }
896 } 918 }
897 -  
898 - diffFormList(chance.SourceContent, request.FormList)  
899 - diffChanceData()  
900 - checkModifyLog := func() { 919 + funcFormatEmpty := func() {
901 if len(modifyLog.Speechs) == 0 { 920 if len(modifyLog.Speechs) == 0 {
902 modifyLog.Speechs = make([]protocol.Speech, 0) 921 modifyLog.Speechs = make([]protocol.Speech, 0)
903 } 922 }
@@ -911,49 +930,61 @@ func CheckChanceDifferent(header *protocol.RequestHeader, chance *models.Chance, @@ -911,49 +930,61 @@ func CheckChanceDifferent(header *protocol.RequestHeader, chance *models.Chance,
911 modifyLog.DiffContents = make([]protocol.ReviseContent, 0) 930 modifyLog.DiffContents = make([]protocol.ReviseContent, 0)
912 } 931 }
913 } 932 }
914 - checkModifyLog()  
915 - if isSaveLog { //&& changeCount > 0  
916 - orm := orm.NewOrm()  
917 - orm.Begin()  
918 - var logId int64  
919 - //发送日志  
920 - if id, err := agg.SaveApproveLogResult(orm, 10, header.UserId, chance.Id); err != nil {  
921 - log.Error(err)  
922 - orm.Rollback()  
923 - return  
924 - } else {  
925 - logId = id  
926 - }  
927 - //保存修改详情  
928 - chanceReviseLog = &models.ChanceReviseLog{  
929 - Id: idgen.Next(),  
930 - ChanceId: chance.Id,  
931 - UserCompanyId: header.UserId,  
932 - Data: common.AssertJson(modifyLog),  
933 - CreateAt: time.Now(),  
934 - AuditFlowLogId: logId,  
935 - }  
936 - if _, e := orm.Insert(chanceReviseLog); e != nil {  
937 - log.Error(e)  
938 - orm.Rollback()  
939 - return  
940 - }  
941 - if chanceType, err := models.GetChanceTypeById(chance.ChanceTypeId); err != nil {  
942 - log.Error(err)  
943 - orm.Rollback()  
944 - return  
945 - } else {  
946 - message = fmt.Sprintf(protocol.MessageChanceRevise, chanceType.Name)  
947 - }  
948 - //发送修改机会消息  
949 - if err := agg.SendMsgWithHeader(header, chance.UserId, "", chanceReviseLog.Id, protocol.SourceTypeChanceReviseLog, message, protocol.MsgTypeChanceRevise, chance.Id); err != nil {  
950 - log.Error(err)  
951 - orm.Rollback()  
952 - return  
953 - }  
954 933
955 - orm.Commit() 934 + funcDiffForms(chance.SourceContent, request.FormList) //比对表单
  935 + funcDiffChanceData() //比对机会数据
  936 + funcFormatEmpty() //格式化变更日志
  937 + if isSaveLog {
  938 + _ = SaveChanceReviseLog(header, chance, modifyLog)
  939 + }
  940 +}
  941 +
  942 +//保存机会变更日志
  943 +func SaveChanceReviseLog(header *protocol.RequestHeader, chance *models.Chance, modifyLog protocol.ChanceReviseLog) (err error) {
  944 + var (
  945 + chanceReviseLog *models.ChanceReviseLog
  946 + message string
  947 + )
  948 + orm := orm.NewOrm()
  949 + orm.Begin()
  950 + var logId int64
  951 + //发送日志
  952 + if id, err := agg.SaveApproveLogResult(orm, 10, header.UserId, chance.Id); err != nil {
  953 + log.Error(err)
  954 + orm.Rollback()
  955 + return
  956 + } else {
  957 + logId = id
  958 + }
  959 + //保存修改详情
  960 + chanceReviseLog = &models.ChanceReviseLog{
  961 + Id: idgen.Next(),
  962 + ChanceId: chance.Id,
  963 + UserCompanyId: header.UserId,
  964 + Data: common.AssertJson(modifyLog),
  965 + CreateAt: time.Now(),
  966 + AuditFlowLogId: logId,
  967 + }
  968 + if _, e := orm.Insert(chanceReviseLog); e != nil {
  969 + log.Error(e)
  970 + orm.Rollback()
  971 + return
  972 + }
  973 + if chanceType, err := models.GetChanceTypeById(chance.ChanceTypeId); err != nil {
  974 + log.Error(err)
  975 + orm.Rollback()
  976 + return
  977 + } else {
  978 + message = fmt.Sprintf(protocol.MessageChanceRevise, chanceType.Name)
  979 + }
  980 + //发送修改机会消息
  981 + if err := agg.SendMsgWithHeader(header, chance.UserId, "", chanceReviseLog.Id, protocol.SourceTypeChanceReviseLog, message, protocol.MsgTypeChanceRevise, chance.Id); err != nil {
  982 + log.Error(err)
  983 + orm.Rollback()
  984 + return
956 } 985 }
  986 + orm.Commit()
  987 + return
957 } 988 }
958 989
959 //修改公开状态 990 //修改公开状态
@@ -1627,6 +1658,8 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ @@ -1627,6 +1658,8 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ
1627 jsonUnmarshal(chance.Images, &item.Pictures) 1658 jsonUnmarshal(chance.Images, &item.Pictures)
1628 jsonUnmarshal(chance.Voices, &item.Speechs) 1659 jsonUnmarshal(chance.Voices, &item.Speechs)
1629 jsonUnmarshal(chance.Videos, &item.Videos) 1660 jsonUnmarshal(chance.Videos, &item.Videos)
  1661 + item.Pictures, item.Videos = agg.CombineAllFiles(item.FormList, item.Pictures, item.Videos)
  1662 + item.FormList = agg.FormFilter(item.FormList, agg.ClearEmptyForm, agg.ClearFilesForm)
1630 commItem.Chance = item 1663 commItem.Chance = item
1631 1664
1632 //点赞评论数据 1665 //点赞评论数据