作者 tangxvhui

添加 自查内容 筛选功能

@@ -186,29 +186,59 @@ func (c *AuditController) GetChanceCheckResultList() { @@ -186,29 +186,59 @@ func (c *AuditController) GetChanceCheckResultList() {
186 } 186 }
187 companyId := c.GetCompanyId() 187 companyId := c.GetCompanyId()
188 rspData := serveaudit.GetChanceCheckResultList(param.PageIndex, param.PageSize, companyId, param.CheckResultStatus) 188 rspData := serveaudit.GetChanceCheckResultList(param.PageIndex, param.PageSize, companyId, param.CheckResultStatus)
189 - msg = protocol.NewReturnResponse(rspData, nil) 189 + msg = protocol.NewPageDataResponse(rspData, nil)
190 return 190 return
191 } 191 }
192 192
193 //GetChanceCheckResultInfo 获取机会的自查内容的筛选结果详情 193 //GetChanceCheckResultInfo 获取机会的自查内容的筛选结果详情
194 //@router /v1/audit/check_result/info 194 //@router /v1/audit/check_result/info
195 func (c *AuditController) GetChanceCheckResultInfo() { 195 func (c *AuditController) GetChanceCheckResultInfo() {
196 - // var msg *protocol.ResponseMessage  
197 - // defer func() {  
198 - // c.ResposeJson(msg)  
199 - // }()  
200 - // type Parameter struct {  
201 - // protocol.RequestPageInfo  
202 - // CheckResultStatus int8 `json:"check_result_status"`  
203 - // }  
204 - // var param Parameter  
205 - // if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {  
206 - // log.Error("json 解析失败", err)  
207 - // msg = protocol.BadRequestParam("1")  
208 - // return  
209 - // }  
210 - // companyId := c.GetCompanyId()  
211 - // rspData := serveaudit.GetChanceCheckResultList(param.PageIndex, param.PageSize, companyId, param.CheckResultStatus)  
212 - // msg = protocol.NewReturnResponse(rspData, nil) 196 + var msg *protocol.ResponseMessage
  197 + defer func() {
  198 + c.ResposeJson(msg)
  199 + }()
  200 + type Parameter struct {
  201 + ChanceId string `json:"chance_id"`
  202 + }
  203 + var param Parameter
  204 + if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
  205 + log.Error("json 解析失败", err)
  206 + msg = protocol.BadRequestParam("1")
  207 + return
  208 + }
  209 + chanceId, _ := strconv.ParseInt(param.ChanceId, 10, 64)
  210 + companyId := c.GetCompanyId()
  211 + rspData, err := serveaudit.GetChanceCheckResultInfo(chanceId, companyId)
  212 + msg = protocol.NewReturnResponse(rspData, err)
  213 + return
  214 +}
  215 +
  216 +//GetChanceCheckResultInfo 获取机会的自查内容的筛选结果详情
  217 +//@router /v1/audit/check_result/pass_or_no
  218 +func (c *AuditController) ChanceCheckResultPassOrNo() {
  219 + var msg *protocol.ResponseMessage
  220 + defer func() {
  221 + c.ResposeJson(msg)
  222 + }()
  223 + type Parameter struct {
  224 + ChanceId string `json:"chance_id"`
  225 + Status int `json:"status"`
  226 + }
  227 + var param Parameter
  228 + if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
  229 + log.Error("json 解析失败", err)
  230 + msg = protocol.BadRequestParam("1")
  231 + return
  232 + }
  233 + chanceId, _ := strconv.ParseInt(param.ChanceId, 10, 64)
  234 + companyId := c.GetCompanyId()
  235 + var err error
  236 + switch param.Status {
  237 + case 1:
  238 + err = serveaudit.ChanceCheckResultPass(chanceId, companyId)
  239 + case 2:
  240 + err = serveaudit.ChanceCheckResultNoPass(chanceId, companyId)
  241 + }
  242 + msg = protocol.NewReturnResponse(nil, err)
213 return 243 return
214 } 244 }
@@ -108,6 +108,8 @@ func init() { @@ -108,6 +108,8 @@ func init() {
108 beego.NSRouter("/allow_forbid", &controllers.AuditController{}, "post:AllowForbidAudit"), 108 beego.NSRouter("/allow_forbid", &controllers.AuditController{}, "post:AllowForbidAudit"),
109 beego.NSRouter("/revise/info", &controllers.AuditController{}, "post:GetChanceReviseLog"), 109 beego.NSRouter("/revise/info", &controllers.AuditController{}, "post:GetChanceReviseLog"),
110 beego.NSRouter("/check_result/list", &controllers.AuditController{}, "post:GetChanceCheckResultList"), 110 beego.NSRouter("/check_result/list", &controllers.AuditController{}, "post:GetChanceCheckResultList"),
  111 + beego.NSRouter("/check_result/info", &controllers.AuditController{}, "post:GetChanceCheckResultInfo"),
  112 + beego.NSRouter("/check_result/pass_or_no", &controllers.AuditController{}, "post:ChanceCheckResultPassOrNo"),
111 ), 113 ),
112 beego.NSNamespace("/rank", 114 beego.NSNamespace("/rank",
113 beego.NSRouter("/type/list", &controllers.RankController{}, "post:GetRankType"), 115 beego.NSRouter("/type/list", &controllers.RankController{}, "post:GetRankType"),
@@ -8,7 +8,7 @@ import ( @@ -8,7 +8,7 @@ import (
8 "oppmg/utils" 8 "oppmg/utils"
9 ) 9 )
10 10
11 -//GetChanceCheckResultInfo 获取机会详情 11 +//GetChanceCheckResultInfo 获取机会自查内容筛选详情
12 func GetChanceCheckResultInfo(chanceId int64, companyid int64) (protocol.ReponseChanceCheckResult, error) { 12 func GetChanceCheckResultInfo(chanceId int64, companyid int64) (protocol.ReponseChanceCheckResult, error) {
13 var ( 13 var (
14 chanceData *models.Chance 14 chanceData *models.Chance
@@ -31,23 +31,82 @@ func GetChanceCheckResultInfo(chanceId int64, companyid int64) (protocol.Reponse @@ -31,23 +31,82 @@ func GetChanceCheckResultInfo(chanceId int64, companyid int64) (protocol.Reponse
31 log.Error("机会的自查内容筛选状态错误") 31 log.Error("机会的自查内容筛选状态错误")
32 return rsp, protocol.NewErrWithMessage("1") 32 return rsp, protocol.NewErrWithMessage("1")
33 } 33 }
  34 + rsp, err = getChanceCheckResultData(chanceId)
  35 + return rsp, err
  36 +}
  37 +
  38 +//getChanceCheckResultData 机会自查内容筛选详情数据输出
  39 +func getChanceCheckResultData(chanceId int64) (protocol.ReponseChanceCheckResult, error) {
34 var ( 40 var (
35 checkResultData []models.ChanceCheckResult 41 checkResultData []models.ChanceCheckResult
  42 + err error
36 ) 43 )
  44 + rsp := protocol.ReponseChanceCheckResult{}
37 checkResultData, err = models.GetChanceCheckResultByChancce(chanceId) 45 checkResultData, err = models.GetChanceCheckResultByChancce(chanceId)
38 if err != nil { 46 if err != nil {
39 log.Error("未获得指定的机会自查内容筛选结果,err;%s", err) 47 log.Error("未获得指定的机会自查内容筛选结果,err;%s", err)
40 return rsp, nil 48 return rsp, nil
41 } 49 }
42 //组装响应数据 50 //组装响应数据
43 - //定义动态数据列  
44 - customItems := utils.NewArraySetString() 51 + //自查内容中的用户id
  52 + userIds := utils.NewArraySetInt64()
45 //自查内容项 53 //自查内容项
46 checkItems := utils.NewArraySetString() 54 checkItems := utils.NewArraySetString()
47 - _ = checkResultData  
48 - _ = customItems  
49 - _ = checkItems  
50 - return rsp, err 55 + checkResultMap := make(map[string]*protocol.ChanceCheckResultData)
  56 + for _, v := range checkResultData {
  57 + userIds.Add(v.UserCompanyId)
  58 + checkItems.Add(v.CheckItem)
  59 + if _, ok := checkResultMap[v.CheckItem]; ok {
  60 + checkResultMap[v.CheckItem].CustomItemData[fmt.Sprint(v.UserCompanyId)] = v.Answer
  61 + continue
  62 + }
  63 + userAnswer := map[string]string{
  64 + fmt.Sprint(v.UserCompanyId): v.Answer,
  65 + }
  66 + checkResultMap[v.CheckItem] = &protocol.ChanceCheckResultData{
  67 + CheckItem: v.CheckItem,
  68 + CustomItemData: userAnswer,
  69 + }
  70 +
  71 + }
  72 + usernameMap := make(map[string]string)
  73 + for _, v := range userIds.ToSlice() {
  74 + idString := fmt.Sprint(v)
  75 + u, err := models.GetUserCompanyById(v)
  76 + if err == nil {
  77 + usernameMap[idString] = u.NickName
  78 + } else {
  79 + usernameMap[idString] = idString
  80 + }
  81 + rsp.CustomItem = append(rsp.CustomItem, usernameMap[idString])
  82 + }
  83 + for _, v := range checkItems.ToSlice() {
  84 + newCustomItemData := map[string]string{}
  85 + for kk, vv := range usernameMap {
  86 + if answer, ok := checkResultMap[v].CustomItemData[kk]; ok {
  87 + newCustomItemData[vv] = answer
  88 + } else {
  89 + newCustomItemData[vv] = ""
  90 + }
  91 + }
  92 + answerYes := 0 //回答:是
  93 + answerNo := 0 //回答:否
  94 + answerAny := 0 //回答:不清楚
  95 + checkResultMap[v].CustomItemData = newCustomItemData
  96 + for _, answerData := range checkResultMap[v].CustomItemData {
  97 + switch answerData {
  98 + case "是":
  99 + answerYes++
  100 + case "否":
  101 + answerNo++
  102 + case "不清楚":
  103 + answerAny++
  104 + }
  105 + }
  106 + checkResultMap[v].Total = fmt.Sprintf("是:%d 否:%d 不清楚:%d", answerYes, answerNo, answerAny)
  107 + rsp.CheckData = append(rsp.CheckData, *checkResultMap[v])
  108 + }
  109 + return rsp, nil
51 } 110 }
52 111
53 func GetChanceCheckResultList(pageIndex int, pageSize int, companyId int64, checkResultStatus int8) protocol.ResponseChanceCheckResultList { 112 func GetChanceCheckResultList(pageIndex int, pageSize int, companyId int64, checkResultStatus int8) protocol.ResponseChanceCheckResultList {
@@ -145,3 +204,47 @@ func GetChanceCheckResultList(pageIndex int, pageSize int, companyId int64, chec @@ -145,3 +204,47 @@ func GetChanceCheckResultList(pageIndex int, pageSize int, companyId int64, chec
145 returnData.CurrentPage = pageIndex 204 returnData.CurrentPage = pageIndex
146 return returnData 205 return returnData
147 } 206 }
  207 +
  208 +func ChanceCheckResultPass(chanceId int64, companyId int64) error {
  209 + var (
  210 + err error
  211 + chanceData *models.Chance
  212 + )
  213 + chanceData, err = models.GetChanceById(chanceId)
  214 + if err != nil {
  215 + log.Error("未找到指定机会id=%d,err:%s", chanceId, err)
  216 + return protocol.NewErrWithMessage("1")
  217 + }
  218 + if chanceData.CompanyId != companyId {
  219 + log.Error("机会对应的公司不匹配")
  220 + return protocol.NewErrWithMessage("1")
  221 + }
  222 + chanceData.CheckResultStatus = models.CheckResultStatusPass
  223 + err = models.UpdateChanceById(chanceData, []string{"CheckResultStatus"})
  224 + if err != nil {
  225 + log.Error("更新chance数据失败,err;%s", err)
  226 + }
  227 + return nil
  228 +}
  229 +
  230 +func ChanceCheckResultNoPass(chanceId int64, companyId int64) error {
  231 + var (
  232 + err error
  233 + chanceData *models.Chance
  234 + )
  235 + chanceData, err = models.GetChanceById(chanceId)
  236 + if err != nil {
  237 + log.Error("未找到指定机会id=%d,err:%s", chanceId, err)
  238 + return protocol.NewErrWithMessage("1")
  239 + }
  240 + if chanceData.CompanyId != companyId {
  241 + log.Error("机会对应的公司不匹配")
  242 + return protocol.NewErrWithMessage("1")
  243 + }
  244 + chanceData.CheckResultStatus = models.CheckResultStatusNOPass
  245 + err = models.UpdateChanceById(chanceData, []string{"CheckResultStatus"})
  246 + if err != nil {
  247 + log.Error("更新chance数据失败,err;%s", err)
  248 + }
  249 + return nil
  250 +}
@@ -121,3 +121,49 @@ func (set *ArraySetString) ToSlice() []string { @@ -121,3 +121,49 @@ func (set *ArraySetString) ToSlice() []string {
121 } 121 }
122 return newSlice 122 return newSlice
123 } 123 }
  124 +
  125 +//ArraySetString 构建元素不重复的数组
  126 +//可按需扩展
  127 +type ArraySetInt64 struct {
  128 + m map[int64]int
  129 +}
  130 +
  131 +func NewArraySetInt64() ArraySetInt64 {
  132 + return ArraySetInt64{
  133 + m: make(map[int64]int),
  134 + }
  135 +}
  136 +func (set *ArraySetInt64) Has(str int64) bool {
  137 + if _, ok := set.m[str]; ok {
  138 + return true
  139 + }
  140 + return false
  141 +}
  142 +
  143 +//Add 追加元素
  144 +func (set *ArraySetInt64) Add(str int64) {
  145 + if _, ok := set.m[str]; ok {
  146 + return
  147 + }
  148 + l := len(set.m)
  149 + set.m[str] = l
  150 +}
  151 +
  152 +//Remove 移除指定元素
  153 +func (set *ArraySetInt64) Remove(str int64) {
  154 + delete(set.m, str)
  155 +}
  156 +
  157 +//Len 元素长度
  158 +func (set *ArraySetInt64) Len() int {
  159 + return len(set.m)
  160 +}
  161 +
  162 +//ToSlice 转换为切片输出
  163 +func (set *ArraySetInt64) ToSlice() []int64 {
  164 + newSlice := make([]int64, len(set.m))
  165 + for k, v := range set.m {
  166 + newSlice[v] = k
  167 + }
  168 + return newSlice
  169 +}