正在显示
9 个修改的文件
包含
463 行增加
和
2 行删除
@@ -459,6 +459,11 @@ func (this *ChanceController) ChanceApprove() { | @@ -459,6 +459,11 @@ func (this *ChanceController) ChanceApprove() { | ||
459 | msg = protocol.NewReturnResponse(nil, e) | 459 | msg = protocol.NewReturnResponse(nil, e) |
460 | return | 460 | return |
461 | } | 461 | } |
462 | + if !(request.Type == 0 || request.Type == 1) { | ||
463 | + msg = protocol.BadRequestParamWithMessage(2, "机会类型错误 (0,1)") | ||
464 | + log.Error(msg) | ||
465 | + return | ||
466 | + } | ||
462 | if len([]rune(request.Reason)) > 100 { | 467 | if len([]rune(request.Reason)) > 100 { |
463 | msg = protocol.BadRequestParamWithMessage(2, "填写理由长度有误,最多输入100个字符") | 468 | msg = protocol.BadRequestParamWithMessage(2, "填写理由长度有误,最多输入100个字符") |
464 | log.Error(msg) | 469 | log.Error(msg) |
@@ -788,3 +793,66 @@ func (this *ChanceController) SiftingResultsItemDetail() { | @@ -788,3 +793,66 @@ func (this *ChanceController) SiftingResultsItemDetail() { | ||
788 | header := controllers.GetRequestHeader(this.Ctx) | 793 | header := controllers.GetRequestHeader(this.Ctx) |
789 | msg = protocol.NewReturnResponse(chance.SiftingResultsItemDetail(header, request)) | 794 | msg = protocol.NewReturnResponse(chance.SiftingResultsItemDetail(header, request)) |
790 | } | 795 | } |
796 | + | ||
797 | +//DraftSaveChance 机会保存到草稿箱 | ||
798 | +//@router /draftSaveChance [post] | ||
799 | +func (this *ChanceController) DraftSaveChance() { | ||
800 | + var msg *protocol.ResponseMessage | ||
801 | + defer func() { | ||
802 | + this.Resp(msg) | ||
803 | + }() | ||
804 | + var request *protocol.DraftSaveChanceRequest | ||
805 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
806 | + log.Error(err) | ||
807 | + msg = protocol.BadRequestParam(1) | ||
808 | + return | ||
809 | + } | ||
810 | + if b, m := this.Valid(request); !b { | ||
811 | + msg = m | ||
812 | + return | ||
813 | + } | ||
814 | + header := controllers.GetRequestHeader(this.Ctx) | ||
815 | + msg = protocol.NewReturnResponse(chance.DraftSaveChance(header, request)) | ||
816 | +} | ||
817 | + | ||
818 | +//DraftDelete 草稿删除(清空) | ||
819 | +//@router /draftDelete [post] | ||
820 | +func (this *ChanceController) DraftDelete() { | ||
821 | + var msg *protocol.ResponseMessage | ||
822 | + defer func() { | ||
823 | + this.Resp(msg) | ||
824 | + }() | ||
825 | + var request *protocol.DraftDeleteRequest | ||
826 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
827 | + log.Error(err) | ||
828 | + msg = protocol.BadRequestParam(1) | ||
829 | + return | ||
830 | + } | ||
831 | + if b, m := this.Valid(request); !b { | ||
832 | + msg = m | ||
833 | + return | ||
834 | + } | ||
835 | + header := controllers.GetRequestHeader(this.Ctx) | ||
836 | + msg = protocol.NewReturnResponse(chance.DraftDelete(header, request)) | ||
837 | +} | ||
838 | + | ||
839 | +//DraftByChance 草稿箱-机会列表 | ||
840 | +//@router /draftByChance [post] | ||
841 | +func (this *ChanceController) DraftByChance() { | ||
842 | + var msg *protocol.ResponseMessage | ||
843 | + defer func() { | ||
844 | + this.Resp(msg) | ||
845 | + }() | ||
846 | + var request *protocol.DraftByChanceRequest | ||
847 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
848 | + log.Error(err) | ||
849 | + msg = protocol.BadRequestParam(1) | ||
850 | + return | ||
851 | + } | ||
852 | + if b, m := this.Valid(request); !b { | ||
853 | + msg = m | ||
854 | + return | ||
855 | + } | ||
856 | + header := controllers.GetRequestHeader(this.Ctx) | ||
857 | + msg = protocol.NewReturnResponse(chance.DraftByChance(header, request)) | ||
858 | +} |
models/chance_draft.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "opp/internal/utils" | ||
6 | + "time" | ||
7 | + | ||
8 | + "github.com/astaxie/beego/orm" | ||
9 | +) | ||
10 | + | ||
11 | +type ChanceDraft struct { | ||
12 | + Id int64 `orm:"column(id);pk" description:"id 主键"` | ||
13 | + UserId int64 `orm:"column(user_id)" description:"表user_company.id id"` | ||
14 | + DepartmentId int64 `orm:"column(department_id)" description:"表department.id 部门id (提交机会指定的部门)"` | ||
15 | + ChanceTypeId int `orm:"column(chance_type_id)" description:"表chance_type.id 机会类型 "` | ||
16 | + CompanyId int64 `orm:"column(company_id)" description:"表company.id 公司编号"` | ||
17 | + AuditTemplateId int64 `orm:"column(audit_template_id)" description:"表audit_template.id 所属审批模板编号"` | ||
18 | + AuditTemplateConfig string `orm:"column(audit_template_config);size(255);null" description:"模板配置 (存旧的配置信息,对新改动的不影响)"` | ||
19 | + SourceContent string `orm:"column(source_content)" description:"原始表单内容 json"` | ||
20 | + EnableStatus int8 `orm:"column(enable_status)" description:"有效状态 0:无效 1:有效 "` | ||
21 | + UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"` | ||
22 | + CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"` | ||
23 | +} | ||
24 | + | ||
25 | +func (t *ChanceDraft) TableName() string { | ||
26 | + return "chance_draft" | ||
27 | +} | ||
28 | + | ||
29 | +func init() { | ||
30 | + orm.RegisterModel(new(ChanceDraft)) | ||
31 | +} | ||
32 | + | ||
33 | +var ( | ||
34 | + DeleteAllChanceDraft = "update chance_draft set enable_status=0 where user_id=%v and enable_status=1" | ||
35 | + DeleteChanceDraft = "update chance_draft set enable_status=0 where user_id=%v and id=%v and enable_status=1" | ||
36 | +) | ||
37 | + | ||
38 | +// AddChanceDraft insert a new ChanceDraft into database and returns | ||
39 | +// last inserted Id on success. | ||
40 | +func AddChanceDraft(m *ChanceDraft) (id int64, err error) { | ||
41 | + o := orm.NewOrm() | ||
42 | + id, err = o.Insert(m) | ||
43 | + return | ||
44 | +} | ||
45 | + | ||
46 | +// GetChanceDraftById retrieves ChanceDraft by Id. Returns error if | ||
47 | +// Id doesn't exist | ||
48 | +func GetChanceDraftById(id int64) (v *ChanceDraft, err error) { | ||
49 | + o := orm.NewOrm() | ||
50 | + v = &ChanceDraft{Id: id} | ||
51 | + if err = o.Read(v); err == nil { | ||
52 | + return v, nil | ||
53 | + } | ||
54 | + return nil, err | ||
55 | +} | ||
56 | + | ||
57 | +// UpdateChanceDraft updates ChanceDraft by Id and returns error if | ||
58 | +// the record to be updated doesn't exist | ||
59 | +func UpdateChanceDraftById(m *ChanceDraft) (err error) { | ||
60 | + o := orm.NewOrm() | ||
61 | + v := ChanceDraft{Id: m.Id} | ||
62 | + // ascertain id exists in the database | ||
63 | + if err = o.Read(&v); err == nil { | ||
64 | + var num int64 | ||
65 | + if num, err = o.Update(m); err == nil { | ||
66 | + fmt.Println("Number of records updated in database:", num) | ||
67 | + } | ||
68 | + } | ||
69 | + return | ||
70 | +} | ||
71 | + | ||
72 | +//草稿项机会列表 | ||
73 | +func GetDraftByChance(uid int64, offset int, pageSize int, v interface{}) (total int, err error) { | ||
74 | + sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos | ||
75 | +from ( | ||
76 | + select b.id chance_id,b.user_id chance_user_id,b.source_content,b.enable_status,b.audit_template_id, | ||
77 | +b.chance_type_id,b.create_at,b.update_at,b.department_id | ||
78 | + from chance_draft b | ||
79 | + where b.user_id=%v and enable_status=1 | ||
80 | +)a left outer join chance_data b on a.chance_id =b.chance_id | ||
81 | +order by a.update_at desc | ||
82 | +limit %v,%v`, uid, offset, pageSize) | ||
83 | + | ||
84 | + sqlCount := fmt.Sprintf(`select count(0) | ||
85 | + from chance_draft b | ||
86 | + where b.user_id=%v and enable_status=1 | ||
87 | +`, uid) | ||
88 | + if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil { | ||
89 | + return | ||
90 | + } | ||
91 | + if v != nil { | ||
92 | + if err = utils.ExecuteQueryAll(v, sql); err != nil { | ||
93 | + return | ||
94 | + } | ||
95 | + } | ||
96 | + return | ||
97 | +} |
models/chance_reserve_type.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "time" | ||
5 | + | ||
6 | + "github.com/astaxie/beego/orm" | ||
7 | +) | ||
8 | + | ||
9 | +type ChanceReserveType struct { | ||
10 | + Id int `orm:"column(id);auto"` | ||
11 | + Name string `orm:"column(name);size(50)" description:"储备类型名称"` | ||
12 | + CompanyId int `orm:"column(company_id)" description:"表company.id 公司编号"` | ||
13 | + SortNum int `orm:"column(sort_num);null" description:"序号 "` | ||
14 | + CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间 "` | ||
15 | + UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间 "` | ||
16 | +} | ||
17 | + | ||
18 | +func (t *ChanceReserveType) TableName() string { | ||
19 | + return "chance_reserve_type" | ||
20 | +} | ||
21 | + | ||
22 | +func init() { | ||
23 | + orm.RegisterModel(new(ChanceReserveType)) | ||
24 | +} | ||
25 | + | ||
26 | +// GetChanceReserveTypeById retrieves ChanceReserveType by Id. Returns error if | ||
27 | +// Id doesn't exist | ||
28 | +func GetChanceReserveTypeById(id int) (v *ChanceReserveType, err error) { | ||
29 | + o := orm.NewOrm() | ||
30 | + v = &ChanceReserveType{Id: id} | ||
31 | + if err = o.Read(v); err == nil { | ||
32 | + return v, nil | ||
33 | + } | ||
34 | + return nil, err | ||
35 | +} |
@@ -609,6 +609,7 @@ type ChanceItem struct { | @@ -609,6 +609,7 @@ type ChanceItem struct { | ||
609 | Videos []Video `json:"videos"` | 609 | Videos []Video `json:"videos"` |
610 | 610 | ||
611 | PublicStatus int `json:"-"` //publicStatus | 611 | PublicStatus int `json:"-"` //publicStatus |
612 | + RelatedDepartmentInfo *Dep `json:"relatedDepartment,omitempty"` | ||
612 | } | 613 | } |
613 | type ChanceData struct { | 614 | type ChanceData struct { |
614 | ThumbsUpTotal int `json:"thumbsupTotal"` //点赞总数 | 615 | ThumbsUpTotal int `json:"thumbsupTotal"` //点赞总数 |
@@ -687,3 +688,40 @@ type ChanceSiftResultOrm struct { | @@ -687,3 +688,40 @@ type ChanceSiftResultOrm struct { | ||
687 | 688 | ||
688 | CheckTime time.Time `orm:"column(check_time)"` //通过时间时间 | 689 | CheckTime time.Time `orm:"column(check_time)"` //通过时间时间 |
689 | } | 690 | } |
691 | + | ||
692 | +/*DraftSaveChance 机会保存到草稿箱*/ | ||
693 | +type DraftSaveChanceRequest struct { | ||
694 | + Id int64 `json:"id"` // = 0添加 >0 编辑 | ||
695 | + AuditTemplateId int64 `json:"auditTemplateId" valid:"Required"` | ||
696 | + FormList []*Form `json:"formList" valid:"Required"` | ||
697 | + SelfChecks SelfChecks `json:"selfChecks"` | ||
698 | + Speechs []Speech `json:"speechs"` | ||
699 | + Pictures []Picture `json:"pictures"` | ||
700 | + Videos []Video `json:"videos"` | ||
701 | + RelatedDepartment int64 `json:"relatedDepartments" valid:"Required"` | ||
702 | +} | ||
703 | +type DraftSaveChanceResponse struct { | ||
704 | +} | ||
705 | + | ||
706 | +/*DraftDelete 草稿删除(清空)*/ | ||
707 | +type DraftDeleteRequest struct { | ||
708 | + Id int `json:"id" valid:"Required"` //-1清空 >1:指定草稿 | ||
709 | +} | ||
710 | +type DraftDeleteResponse struct { | ||
711 | +} | ||
712 | + | ||
713 | +/*DraftByChance 草稿箱-机会列表*/ | ||
714 | +type DraftByChanceRequest struct { | ||
715 | + PageInfo | ||
716 | +} | ||
717 | +type DraftByChanceResponse struct{ ChancePoolResponse } | ||
718 | + | ||
719 | +//机会池筛选项 | ||
720 | +type DraftChanceItemOrm struct { | ||
721 | + CommChanceItemOrm | ||
722 | + | ||
723 | + //ApproveData string `json:"approveData"` //审核数据 | ||
724 | + TemplateId int `orm:"column(audit_template_id)"` | ||
725 | + ChanceTypeId int `orm:"column(chance_type_id)"` | ||
726 | + DepartmentId int `orm:"column(department_id)"` | ||
727 | +} |
@@ -193,6 +193,30 @@ func init() { | @@ -193,6 +193,30 @@ func init() { | ||
193 | 193 | ||
194 | beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"], | 194 | beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"], |
195 | beego.ControllerComments{ | 195 | beego.ControllerComments{ |
196 | + Method: "DraftByChance", | ||
197 | + Router: `/draftByChance`, | ||
198 | + AllowHTTPMethods: []string{"post"}, | ||
199 | + MethodParams: param.Make(), | ||
200 | + Params: nil}) | ||
201 | + | ||
202 | + beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"], | ||
203 | + beego.ControllerComments{ | ||
204 | + Method: "DraftDelete", | ||
205 | + Router: `/draftDelete`, | ||
206 | + AllowHTTPMethods: []string{"post"}, | ||
207 | + MethodParams: param.Make(), | ||
208 | + Params: nil}) | ||
209 | + | ||
210 | + beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"], | ||
211 | + beego.ControllerComments{ | ||
212 | + Method: "DraftSaveChance", | ||
213 | + Router: `/draftSaveChance`, | ||
214 | + AllowHTTPMethods: []string{"post"}, | ||
215 | + MethodParams: param.Make(), | ||
216 | + Params: nil}) | ||
217 | + | ||
218 | + beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"], | ||
219 | + beego.ControllerComments{ | ||
196 | Method: "Favorite", | 220 | Method: "Favorite", |
197 | Router: `/favorite`, | 221 | Router: `/favorite`, |
198 | AllowHTTPMethods: []string{"post"}, | 222 | AllowHTTPMethods: []string{"post"}, |
@@ -154,6 +154,16 @@ func GetTopPosition(positions []*protocol.Position) *protocol.Position { | @@ -154,6 +154,16 @@ func GetTopPosition(positions []*protocol.Position) *protocol.Position { | ||
154 | return top | 154 | return top |
155 | } | 155 | } |
156 | 156 | ||
157 | +func GetDepartment(dId int) *protocol.Dep { | ||
158 | + if d, e := models.GetDepartmentById(int64(dId)); e == nil { | ||
159 | + return &protocol.Dep{ | ||
160 | + Id: int(d.Id), | ||
161 | + Name: d.Name, | ||
162 | + } | ||
163 | + } | ||
164 | + return nil | ||
165 | +} | ||
166 | + | ||
157 | //获取机会 | 167 | //获取机会 |
158 | func GetChance(chanceId int64, companyId int64) (v *protocol.ChanceDetail, err error) { | 168 | func GetChance(chanceId int64, companyId int64) (v *protocol.ChanceDetail, err error) { |
159 | var ( | 169 | var ( |
services/agg/chance_code.go
0 → 100644
1 | +package agg | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/astaxie/beego/orm" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | ||
7 | + "sync" | ||
8 | + "sync/atomic" | ||
9 | + "time" | ||
10 | +) | ||
11 | + | ||
12 | +var rwCC sync.RWMutex | ||
13 | +var currentSN int32 | ||
14 | + | ||
15 | +func GetChanceCode(chanceId int64, chanceTypeId int, templateId int64) (rsp string, err error) { | ||
16 | + rwCC.RLock() | ||
17 | + defer rwCC.RUnlock() | ||
18 | + var ( | ||
19 | + ChanceTypeCode, TemplateCode string | ||
20 | + Num int32 | ||
21 | + loopTime int | ||
22 | + sql = fmt.Sprintf(`select a.code chance_type_code,b.code template_code,c.num+1 num from | ||
23 | +(select code from chance_type where id =%v) a , | ||
24 | +(select code from audit_template where id=%v) b, | ||
25 | +(select count(0) num from chance where review_status=3) c`, chanceTypeId, templateId) | ||
26 | + ) | ||
27 | + o := orm.NewOrm() | ||
28 | + for { | ||
29 | + if err = o.Raw(sql).QueryRow(&ChanceTypeCode, &TemplateCode, &Num); err != nil { | ||
30 | + log.Error(err) | ||
31 | + return | ||
32 | + } | ||
33 | + if currentSN != Num { | ||
34 | + atomic.StoreInt32(¤tSN, Num) | ||
35 | + break | ||
36 | + } | ||
37 | + if loopTime > 5 { //重试5次 | ||
38 | + break | ||
39 | + } | ||
40 | + log.Warn(fmt.Sprintf("get chance code retry(%v): cursn:%v cid:%v cc:%v tc:%v", | ||
41 | + loopTime, currentSN, chanceId, ChanceTypeCode, TemplateCode)) | ||
42 | + time.Sleep(time.Millisecond * 500) | ||
43 | + loopTime++ | ||
44 | + } | ||
45 | + | ||
46 | + rsp = fmt.Sprintf("%v%v%v", ChanceTypeCode, TemplateCode, Num) | ||
47 | + return | ||
48 | +} |
@@ -304,6 +304,16 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro | @@ -304,6 +304,16 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro | ||
304 | err = protocol.NewErrWithMessage(5206) | 304 | err = protocol.NewErrWithMessage(5206) |
305 | return | 305 | return |
306 | } | 306 | } |
307 | + if request.ReserveTypeId > 0 { | ||
308 | + if _, err = models.GetChanceReserveTypeById(request.ReserveTypeId); err != nil { | ||
309 | + if err == orm.ErrNoRows { | ||
310 | + err = protocol.NewCustomMessage(1, "储备类型不存在,请重新选择") | ||
311 | + return | ||
312 | + } | ||
313 | + log.Error(err) | ||
314 | + return | ||
315 | + } | ||
316 | + } | ||
307 | if chance.ReviewStatus != protocol.ReviewStatusAuditging { | 317 | if chance.ReviewStatus != protocol.ReviewStatusAuditging { |
308 | log.Error(fmt.Sprintf("机会已经被审核 chance_id:%v review_status:%v", chance.Id, chance.ReviewStatus)) | 318 | log.Error(fmt.Sprintf("机会已经被审核 chance_id:%v review_status:%v", chance.Id, chance.ReviewStatus)) |
309 | err = protocol.NewErrWithMessage(5202) | 319 | err = protocol.NewErrWithMessage(5202) |
@@ -345,6 +355,8 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro | @@ -345,6 +355,8 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro | ||
345 | mapProcess["DiscoveryScore"] = request.ApproveData.Score.DiscoveryScore | 355 | mapProcess["DiscoveryScore"] = request.ApproveData.Score.DiscoveryScore |
346 | mapProcess["ApproveData"] = common.AssertJson(request.ApproveData) | 356 | mapProcess["ApproveData"] = common.AssertJson(request.ApproveData) |
347 | mapProcess["EnableStatus"] = int8(1) | 357 | mapProcess["EnableStatus"] = int8(1) |
358 | + mapChance["Type"] = request.Type | ||
359 | + mapChance["ReserveTypeId"] = request.ReserveTypeId | ||
348 | mapChance["SelfChecks"] = common.AssertJson(request.SelfChecks) | 360 | mapChance["SelfChecks"] = common.AssertJson(request.SelfChecks) |
349 | } | 361 | } |
350 | } | 362 | } |
@@ -379,8 +391,9 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro | @@ -379,8 +391,9 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro | ||
379 | } | 391 | } |
380 | if approveItemResponse.IsOver == 1 { | 392 | if approveItemResponse.IsOver == 1 { |
381 | //结束审批 | 393 | //结束审批 |
382 | - { | ||
383 | mapChance["ReviewStatus"] = int8(request.ReviewStatus) | 394 | mapChance["ReviewStatus"] = int8(request.ReviewStatus) |
395 | + if request.ReviewStatus == protocol.ReviewStatusPass { | ||
396 | + mapChance["Code"], _ = agg.GetChanceCode(chance.Id, chance.ChanceTypeId, chance.AuditTemplateId) | ||
384 | } | 397 | } |
385 | } else { | 398 | } else { |
386 | //发送下一个消息给下一流程的审核人 | 399 | //发送下一个消息给下一流程的审核人 |
@@ -408,7 +408,7 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit | @@ -408,7 +408,7 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit | ||
408 | AuditLevel: 1, | 408 | AuditLevel: 1, |
409 | ReviewStatus: protocol.ReviewStatusAuditging, | 409 | ReviewStatus: protocol.ReviewStatusAuditging, |
410 | DepartmentId: request.RelatedDepartment, | 410 | DepartmentId: request.RelatedDepartment, |
411 | - Code: fmt.Sprintf("%v%v", chanceType.Code, template.Code), | 411 | + //Code: fmt.Sprintf("%v%v", chanceType.Code, template.Code), |
412 | Status: models.ChanceStatusOpen, | 412 | Status: models.ChanceStatusOpen, |
413 | SelfChecks: common.AssertJson(request.SelfChecks), | 413 | SelfChecks: common.AssertJson(request.SelfChecks), |
414 | } | 414 | } |
@@ -2253,3 +2253,131 @@ func CheckQuestions(header *protocol.RequestHeader, request *protocol.CheckQuest | @@ -2253,3 +2253,131 @@ func CheckQuestions(header *protocol.RequestHeader, request *protocol.CheckQuest | ||
2253 | } | 2253 | } |
2254 | return | 2254 | return |
2255 | } | 2255 | } |
2256 | + | ||
2257 | +//机会保存到草稿箱 | ||
2258 | +func DraftSaveChance(header *protocol.RequestHeader, request *protocol.DraftSaveChanceRequest) (rsp *protocol.DraftSaveChanceResponse, err error) { | ||
2259 | + var ( | ||
2260 | + template *models.AuditTemplate | ||
2261 | + chanceData *models.ChanceData | ||
2262 | + chance *models.ChanceDraft | ||
2263 | + ) | ||
2264 | + rsp = &protocol.DraftSaveChanceResponse{} | ||
2265 | + | ||
2266 | + //1.模板是否存在 | ||
2267 | + if template, err = models.GetAuditTemplateById(request.AuditTemplateId); err != nil { | ||
2268 | + log.Error("模板不存在:", request.AuditTemplateId, err) | ||
2269 | + return | ||
2270 | + } | ||
2271 | + if _, err = models.GetChanceTypeById(template.ChanceTypeId); err != nil { | ||
2272 | + log.Error("一级分类不存在:", request.AuditTemplateId, err) | ||
2273 | + return | ||
2274 | + } | ||
2275 | + //2.检查模板是否有权限 | ||
2276 | + if request.Id > 0 { | ||
2277 | + //更新机会 | ||
2278 | + if chance, err = models.GetChanceDraftById(request.Id); err != nil { | ||
2279 | + err = protocol.NewCustomMessage(1, "该机会已不存在") | ||
2280 | + return | ||
2281 | + } | ||
2282 | + chance.SourceContent = common.AssertJson(request.FormList) | ||
2283 | + chance.UpdateAt = time.Now() | ||
2284 | + chance.DepartmentId = request.RelatedDepartment | ||
2285 | + if err = models.UpdateChanceDraftById(chance); err != nil { | ||
2286 | + err = protocol.NewCustomMessage(1, "该机会已不存在") | ||
2287 | + return | ||
2288 | + } | ||
2289 | + | ||
2290 | + //更新机会数据 | ||
2291 | + if chanceData, err = models.GetChanceDataByChanceId(request.Id); err != nil { | ||
2292 | + err = protocol.NewCustomMessage(1, "该机会已不存在") | ||
2293 | + return | ||
2294 | + } | ||
2295 | + chanceDataMap := map[string]interface{}{ | ||
2296 | + "Speechs": common.AssertJson(request.Speechs), | ||
2297 | + "Images": common.AssertJson(request.Pictures), | ||
2298 | + "Videos": common.AssertJson(request.Videos), | ||
2299 | + "UpdateAt": time.Now(), | ||
2300 | + } | ||
2301 | + if err = utils.UpdateTableByMap(chanceData, chanceDataMap); err != nil { | ||
2302 | + log.Error(err) | ||
2303 | + return | ||
2304 | + } | ||
2305 | + return | ||
2306 | + } | ||
2307 | + //3.添加机会 添加文件 | ||
2308 | + chance = &models.ChanceDraft{ | ||
2309 | + Id: idgen.Next(), | ||
2310 | + UserId: header.UserId, | ||
2311 | + CompanyId: header.CompanyId, | ||
2312 | + ChanceTypeId: template.ChanceTypeId, | ||
2313 | + AuditTemplateId: template.Id, | ||
2314 | + SourceContent: common.AssertJson(request.FormList), | ||
2315 | + EnableStatus: 1, | ||
2316 | + CreateAt: time.Now(), | ||
2317 | + UpdateAt: time.Now(), | ||
2318 | + DepartmentId: request.RelatedDepartment, | ||
2319 | + } | ||
2320 | + if _, err = models.AddChanceDraft(chance); err != nil { | ||
2321 | + log.Error(err) | ||
2322 | + return | ||
2323 | + } | ||
2324 | + data := &models.ChanceData{ | ||
2325 | + Id: idgen.Next(), | ||
2326 | + ChanceId: chance.Id, | ||
2327 | + Speechs: common.AssertJson(request.Speechs), | ||
2328 | + Images: common.AssertJson(request.Pictures), | ||
2329 | + Videos: common.AssertJson(request.Videos), | ||
2330 | + CreateAt: time.Now(), | ||
2331 | + UpdateAt: time.Now(), | ||
2332 | + } | ||
2333 | + if _, err = models.AddChanceData(data); err != nil { | ||
2334 | + log.Error(err) | ||
2335 | + return | ||
2336 | + } | ||
2337 | + return | ||
2338 | +} | ||
2339 | + | ||
2340 | +//草稿删除(清空) | ||
2341 | +func DraftDelete(header *protocol.RequestHeader, request *protocol.DraftDeleteRequest) (rsp *protocol.DraftDeleteResponse, err error) { | ||
2342 | + var ( | ||
2343 | + sql string | ||
2344 | + ) | ||
2345 | + rsp = &protocol.DraftDeleteResponse{} | ||
2346 | + sql = fmt.Sprintf(models.DeleteChanceDraft, header.UserId, request.Id) | ||
2347 | + if request.Id < 0 { | ||
2348 | + sql = fmt.Sprintf(models.DeleteAllChanceDraft, header.UserId) | ||
2349 | + } | ||
2350 | + o := orm.NewOrm() | ||
2351 | + if err = utils.ExecuteSQLWithOrmer(o, sql); err != nil { | ||
2352 | + log.Error(err) | ||
2353 | + return | ||
2354 | + } | ||
2355 | + return | ||
2356 | +} | ||
2357 | + | ||
2358 | +//草稿箱-机会列表 | ||
2359 | +func DraftByChance(header *protocol.RequestHeader, request *protocol.DraftByChanceRequest) (rsp *protocol.DraftByChanceResponse, err error) { | ||
2360 | + var ( | ||
2361 | + ormItems []protocol.DraftChanceItemOrm | ||
2362 | + ) | ||
2363 | + rsp = &protocol.DraftByChanceResponse{} | ||
2364 | + rsp.List = make([]protocol.CommonListItem, 0) | ||
2365 | + if rsp.Total, err = models.GetDraftByChance(header.UserId, request.Offset(), request.PageSize, &ormItems); err != nil { | ||
2366 | + if err == orm.ErrNoRows { | ||
2367 | + err = nil | ||
2368 | + return | ||
2369 | + } | ||
2370 | + log.Error(err) | ||
2371 | + return | ||
2372 | + } | ||
2373 | + for i := 0; i < len(ormItems); i++ { | ||
2374 | + ormItem := ormItems[i] | ||
2375 | + commItem := agg.NewCommonListItem(header, ormItem.CommChanceItemOrm) | ||
2376 | + commItem.Chance.CreateTime = ormItem.UpdateTime.Unix() * 1000 | ||
2377 | + commItem.Chance.RelatedDepartmentInfo = agg.GetDepartment(ormItem.DepartmentId) | ||
2378 | + commItem.Chance.ApproveTime = 0 | ||
2379 | + | ||
2380 | + rsp.List = append(rsp.List, commItem) | ||
2381 | + } | ||
2382 | + return | ||
2383 | +} |
-
请 注册 或 登录 后发表评论