作者 yangfu

自查修改

@@ -12,7 +12,6 @@ import ( @@ -12,7 +12,6 @@ import (
12 /*机会-自查内容*/ 12 /*机会-自查内容*/
13 var CheckOptionsCommit = []CheckOption{{Item: "是", NeedOther: false}, {Item: "否", NeedOther: false}, {Item: "不清楚", NeedOther: false}} 13 var CheckOptionsCommit = []CheckOption{{Item: "是", NeedOther: false}, {Item: "否", NeedOther: false}, {Item: "不清楚", NeedOther: false}}
14 14
15 -//var CheckOptionsApprove = []CheckOption{{Item: "是",NeedOther:false},{Item: "否",NeedOther:true},{Item: "不清楚",NeedOther:false}}  
16 //自查结果列表 15 //自查结果列表
17 type SelfCheckResults []selfCheckResult 16 type SelfCheckResults []selfCheckResult
18 type selfCheckResult struct { 17 type selfCheckResult struct {
@@ -21,7 +20,19 @@ type selfCheckResult struct { @@ -21,7 +20,19 @@ type selfCheckResult struct {
21 } 20 }
22 21
23 //自查项列表 22 //自查项列表
  23 +func NewSelfChecks(data string) (rsp SelfChecks) {
  24 + if len(data) == 0 {
  25 + return
  26 + }
  27 + e := json.Unmarshal([]byte(data), &rsp)
  28 + if e != nil {
  29 + log.Error(e)
  30 + }
  31 + return
  32 +}
  33 +
24 type SelfChecks []SelfCheck 34 type SelfChecks []SelfCheck
  35 +
25 type SelfCheck struct { 36 type SelfCheck struct {
26 CheckItem string `json:"checkItem"` 37 CheckItem string `json:"checkItem"`
27 GroupId int64 `json:"groupId"` //分组 38 GroupId int64 `json:"groupId"` //分组
@@ -33,17 +44,6 @@ func (c SelfCheck) Key() string { @@ -33,17 +44,6 @@ func (c SelfCheck) Key() string {
33 return fmt.Sprintf("%v-%v", c.GroupId, c.CheckItem) 44 return fmt.Sprintf("%v-%v", c.GroupId, c.CheckItem)
34 } 45 }
35 46
36 -func NewSelfChecks(data string) (rsp SelfChecks) {  
37 - if len(data) == 0 {  
38 - return  
39 - }  
40 - e := json.Unmarshal([]byte(data), &rsp)  
41 - if e != nil {  
42 - log.Error(e)  
43 - }  
44 - return  
45 -}  
46 -  
47 //统计自查结果 47 //统计自查结果
48 func (s SelfChecks) Static() SelfCheckResults { 48 func (s SelfChecks) Static() SelfCheckResults {
49 if len(s) == 0 { 49 if len(s) == 0 {
@@ -91,9 +91,9 @@ func (s SelfChecks) String() string { @@ -91,9 +91,9 @@ func (s SelfChecks) String() string {
91 for i := range s { 91 for i := range s {
92 c := s[i] 92 c := s[i]
93 if len(c.Reason) == 0 { 93 if len(c.Reason) == 0 {
94 - buf.WriteString(fmt.Sprintf("%v:%v;\n", c.CheckItem, c.Answer)) 94 + buf.WriteString(fmt.Sprintf("\n%v:%v;", c.CheckItem, c.Answer))
95 } else { 95 } else {
96 - buf.WriteString(fmt.Sprintf("%v:%v,理由:%v;\n", c.CheckItem, c.Answer, c.Reason)) 96 + buf.WriteString(fmt.Sprintf("\n%v:%v,理由:%v;", c.CheckItem, c.Answer, c.Reason))
97 } 97 }
98 } 98 }
99 return buf.String() 99 return buf.String()
@@ -135,6 +135,15 @@ func (s SelfChecks) Compare(dst string) (rspChecks SelfChecks, err error) { @@ -135,6 +135,15 @@ func (s SelfChecks) Compare(dst string) (rspChecks SelfChecks, err error) {
135 } 135 }
136 136
137 //自查问题 137 //自查问题
  138 +func NewCheckQuestion(checkItem, title string, groupId int64, ops []CheckOption) *CheckQuestion {
  139 + return &CheckQuestion{
  140 + CheckItem: checkItem,
  141 + Title: title,
  142 + GroupId: groupId,
  143 + CheckOptions: ops,
  144 + }
  145 +}
  146 +
138 type CheckQuestion struct { 147 type CheckQuestion struct {
139 CheckItem string `json:"checkItem"` 148 CheckItem string `json:"checkItem"`
140 Title string `json:"title"` 149 Title string `json:"title"`
@@ -143,16 +152,7 @@ type CheckQuestion struct { @@ -143,16 +152,7 @@ type CheckQuestion struct {
143 } 152 }
144 type CheckOption struct { 153 type CheckOption struct {
145 Item string `json:"item"` 154 Item string `json:"item"`
146 - NeedOther bool `json:"needOther"` //是否需填写其他的内容【1:需要】【2:不需要】  
147 -}  
148 -  
149 -func NewCheckQuestion(checkItem, title string, groupId int64, ops []CheckOption) *CheckQuestion {  
150 - return &CheckQuestion{  
151 - CheckItem: checkItem,  
152 - Title: title,  
153 - GroupId: groupId,  
154 - CheckOptions: ops,  
155 - } 155 + NeedOther bool `json:"-"` //是否需填写其他的内容【1:需要】【2:不需要】
156 } 156 }
157 157
158 /*CheckQuestions 自查问题列表*/ 158 /*CheckQuestions 自查问题列表*/
@@ -61,9 +61,9 @@ func init() { @@ -61,9 +61,9 @@ func init() {
61 var ApproveLog = map[int]string{ 61 var ApproveLog = map[int]string{
62 1: "提交了机会", //提交人提交机会 62 1: "提交了机会", //提交人提交机会
63 2: "删除了机会", //提交人删除机会 63 2: "删除了机会", //提交人删除机会
64 - 3: "退回了机会;\n%v", //审批人退回机会  
65 - 4: "通过了机会;\n%v\n基础评分:%v分,附加评分:%v分,价值评分:%v分,公开状态:公司公开", //审批人通过机会(公司公开)  
66 - 5: "通过了机会;\n%v\n基础评分:%v分,附加评分:%v分,价值评分:%v分,公开状态:%v", //审批人通过机会(部门公开) 测试部、销售部 64 + 3: "退回了机会;%v", //审批人退回机会
  65 + 4: "通过了机会;%v\n基础评分:%v分,附加评分:%v分,价值评分:%v分,公开状态:公司公开", //审批人通过机会(公司公开)
  66 + 5: "通过了机会;%v\n基础评分:%v分,附加评分:%v分,价值评分:%v分,公开状态:%v", //审批人通过机会(部门公开) 测试部、销售部
67 6: "系统 自动通过了机会;基础评分:%v分,附加评分:%v分,价值评分:%v分,公开状态:公司公开", //审批人通过了机会(系统自动通过) 67 6: "系统 自动通过了机会;基础评分:%v分,附加评分:%v分,价值评分:%v分,公开状态:公司公开", //审批人通过了机会(系统自动通过)
68 7: "修改了公开状态:公司公开", //审批通过后修改公开状态(公司公开) 68 7: "修改了公开状态:公司公开", //审批通过后修改公开状态(公司公开)
69 8: "修改了公开状态:%v", //审批通过后修改公开状态(部门公开) 69 8: "修改了公开状态:%v", //审批通过后修改公开状态(部门公开)
@@ -4,10 +4,12 @@ import ( @@ -4,10 +4,12 @@ import (
4 "encoding/json" 4 "encoding/json"
5 "fmt" 5 "fmt"
6 "github.com/astaxie/beego/orm" 6 "github.com/astaxie/beego/orm"
  7 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/idgen"
7 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" 8 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
8 "opp/internal/utils" 9 "opp/internal/utils"
9 "opp/models" 10 "opp/models"
10 "opp/protocol" 11 "opp/protocol"
  12 + "time"
11 ) 13 )
12 14
13 //机会池 15 //机会池
@@ -227,7 +229,6 @@ func SetChanceItem(header *protocol.RequestHeader, chance protocol.CommChanceIte @@ -227,7 +229,6 @@ func SetChanceItem(header *protocol.RequestHeader, chance protocol.CommChanceIte
227 utils.JsonUnmarshal(chance.Videos, &item.Videos) 229 utils.JsonUnmarshal(chance.Videos, &item.Videos)
228 return item, chanceStatus 230 return item, chanceStatus
229 } 231 }
230 -  
231 func SetMsgItem(header *protocol.RequestHeader, msg protocol.MsgItemOrm, commItem *protocol.MsgCommonListItem) { 232 func SetMsgItem(header *protocol.RequestHeader, msg protocol.MsgItemOrm, commItem *protocol.MsgCommonListItem) {
232 commItem.MsgId = msg.MsgId 233 commItem.MsgId = msg.MsgId
233 commItem.MsgTime = msg.MsgTime.Unix() * 1000 234 commItem.MsgTime = msg.MsgTime.Unix() * 1000
@@ -304,10 +305,62 @@ func GetCheckQuestionsByChanceId(id int64) (rsp []*protocol.CheckQuestion, err e @@ -304,10 +305,62 @@ func GetCheckQuestionsByChanceId(id int64) (rsp []*protocol.CheckQuestion, err e
304 } 305 }
305 return 306 return
306 } 307 }
307 -  
308 func getQuestionTitle(groupIdx int, idx int, title string) string { 308 func getQuestionTitle(groupIdx int, idx int, title string) string {
309 if idx == 0 { 309 if idx == 0 {
310 return fmt.Sprintf("%v、%v?", groupIdx, title) 310 return fmt.Sprintf("%v、%v?", groupIdx, title)
311 } 311 }
312 return fmt.Sprintf("%v.%v、%v?", groupIdx, idx, title) 312 return fmt.Sprintf("%v.%v、%v?", groupIdx, idx, title)
313 } 313 }
  314 +
  315 +//自查问题回答批量入库
  316 +func BulkInsertSelfChecks(header *protocol.RequestHeader, relateId, chanceId int64, selfChecks protocol.SelfChecks) {
  317 + defer func() {
  318 + if p := recover(); p != nil {
  319 + log.Warn(p)
  320 + }
  321 + }()
  322 + var (
  323 + count int
  324 + err error
  325 + Exists = `select count(0) from chance_self_check where chanceId=? and relateId=?`
  326 + DeleteExistedRow = `update chance_self_check set enable=0 where chanceId=? and relateId=?`
  327 + )
  328 + if len(selfChecks) == 0 {
  329 + return
  330 + }
  331 + o := orm.NewOrm()
  332 + o.Begin()
  333 + if err = utils.ExecuteQueryOneWithOrmer(o, &count, Exists, relateId, chanceId); err != nil {
  334 + log.Error(err)
  335 + o.Rollback()
  336 + return
  337 + }
  338 + if count > 0 {
  339 + if err = utils.ExecuteSQLWithOrmer(o, DeleteExistedRow, relateId, chanceId); err != nil {
  340 + log.Error(err)
  341 + o.Rollback()
  342 + return
  343 + }
  344 + }
  345 + for i := range selfChecks {
  346 + check := selfChecks[i]
  347 + m := models.ChanceSelfCheck{
  348 + Id: idgen.Next(),
  349 + UserCompanyId: header.UserId,
  350 + ChanceId: chanceId,
  351 + RelateId: relateId,
  352 + CheckItem: check.CheckItem,
  353 + GroupId: check.GroupId,
  354 + Answer: check.Answer,
  355 + Reason: check.Reason,
  356 + CreateAt: time.Now(),
  357 + }
  358 + if _, err = o.Insert(m); err != nil {
  359 + log.Error(err)
  360 + o.Rollback()
  361 + return
  362 + }
  363 + }
  364 +
  365 + o.Commit()
  366 +}