作者 yangfu

增加 筛选历史,筛选历史详情

@@ -739,3 +739,45 @@ func (this *ChanceController) SubmitChecks() { @@ -739,3 +739,45 @@ func (this *ChanceController) SubmitChecks() {
739 header := controllers.GetRequestHeader(this.Ctx) 739 header := controllers.GetRequestHeader(this.Ctx)
740 msg = protocol.NewReturnResponse(chance.SubmitChecks(header, request)) 740 msg = protocol.NewReturnResponse(chance.SubmitChecks(header, request))
741 } 741 }
  742 +
  743 +//SiftingResultsItemHistory 筛选历史
  744 +//@router /siftingResults/itemHistory [post]
  745 +func (this *ChanceController) SiftingResultsItemHistory() {
  746 + var msg *protocol.ResponseMessage
  747 + defer func() {
  748 + this.Resp(msg)
  749 + }()
  750 + var request *protocol.SiftingResultsItemHistoryRequest
  751 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  752 + log.Error(err)
  753 + msg = protocol.BadRequestParam(1)
  754 + return
  755 + }
  756 + if b, m := this.Valid(request); !b {
  757 + msg = m
  758 + return
  759 + }
  760 + header := controllers.GetRequestHeader(this.Ctx)
  761 + msg = protocol.NewReturnResponse(chance.SiftingResultsItemHistory(header, request))
  762 +}
  763 +
  764 +//SiftingResultsItemDetail 筛选历史详情
  765 +//@router /siftingResults/itemDetail [post]
  766 +func (this *ChanceController) SiftingResultsItemDetail() {
  767 + var msg *protocol.ResponseMessage
  768 + defer func() {
  769 + this.Resp(msg)
  770 + }()
  771 + var request *protocol.SiftingResultsItemDetailRequest
  772 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  773 + log.Error(err)
  774 + msg = protocol.BadRequestParam(1)
  775 + return
  776 + }
  777 + if b, m := this.Valid(request); !b {
  778 + msg = m
  779 + return
  780 + }
  781 + header := controllers.GetRequestHeader(this.Ctx)
  782 + msg = protocol.NewReturnResponse(chance.SiftingResultsItemDetail(header, request))
  783 +}
@@ -91,3 +91,22 @@ func GetCheckResultAllSubmitters(chanceId int64) (v []int64, err error) { @@ -91,3 +91,22 @@ func GetCheckResultAllSubmitters(chanceId int64) (v []int64, err error) {
91 } 91 }
92 return 92 return
93 } 93 }
  94 +
  95 +//获取机会所有筛选结果
  96 +func GetCheckResultsByChanceId(chanceId int64) (v []*ChanceCheckResult, err error) {
  97 + o := orm.NewOrm()
  98 + sql := "select * from chance_check_result where chance_id =? order by check_pid,check_id"
  99 + if err = utils.ExecuteQueryAllWithOrmer(o, &v, sql, chanceId); err != nil {
  100 + return
  101 + }
  102 + return
  103 +}
  104 +
  105 +func GetCheckResultsByCheckId(chanceId int64, checkId int) (v []*ChanceCheckResult, err error) {
  106 + o := orm.NewOrm()
  107 + sql := "select * from chance_check_result where chance_id =? and check_id=? order by id"
  108 + if err = utils.ExecuteQueryAllWithOrmer(o, &v, sql, chanceId, checkId); err != nil {
  109 + return
  110 + }
  111 + return
  112 +}
@@ -28,6 +28,12 @@ const ( @@ -28,6 +28,12 @@ const (
28 Pass //通过 28 Pass //通过
29 ) 29 )
30 30
  31 +const (
  32 + OptionYes = "是"
  33 + OptionNo = "否"
  34 + OptionNoCertain = "不清楚"
  35 +)
  36 +
31 /*机会-自查内容*/ 37 /*机会-自查内容*/
32 var CheckOptionsCommit = []CheckOption{{Item: "是", NeedOther: false}, {Item: "否", NeedOther: false}, {Item: "不清楚", NeedOther: false}} 38 var CheckOptionsCommit = []CheckOption{{Item: "是", NeedOther: false}, {Item: "否", NeedOther: false}, {Item: "不清楚", NeedOther: false}}
33 var CheckOptionsApprove = []CheckOption{{Item: "是", NeedOther: false}, {Item: "否", NeedOther: true}, {Item: "不清楚", NeedOther: false}} 39 var CheckOptionsApprove = []CheckOption{{Item: "是", NeedOther: false}, {Item: "否", NeedOther: true}, {Item: "不清楚", NeedOther: false}}
@@ -157,6 +163,61 @@ func (s SelfChecks) Compare(dst string) (rspChecks SelfChecks, err error) { @@ -157,6 +163,61 @@ func (s SelfChecks) Compare(dst string) (rspChecks SelfChecks, err error) {
157 return 163 return
158 } 164 }
159 165
  166 +//按规则设置自查 一级自查
  167 +func (s SelfChecks) SetSelfChecksLevel1ByRule() (err error) {
  168 + if len(s) == 0 {
  169 + return
  170 + }
  171 + var gIdx = -1
  172 + for i := 0; i < len(s); i++ {
  173 + if gIdx < 0 || s[gIdx].GroupId != s[i].GroupId {
  174 + gIdx = i
  175 + } else {
  176 + continue
  177 + }
  178 + hasSub := false
  179 + var (
  180 + cntYes = 0 //是
  181 + cntNo = 0 //否
  182 + cntUncertain = 0 //不确定
  183 + )
  184 + for j := i + 1; j < len(s); j++ {
  185 + if s[i].GroupId == s[j].GroupId {
  186 + if !hasSub {
  187 + hasSub = true
  188 + }
  189 + } else {
  190 + break
  191 + }
  192 + answer := s[j].Answer
  193 + if strings.EqualFold(strings.TrimSpace(answer), OptionYes) {
  194 + cntYes++
  195 + } else if strings.EqualFold(strings.TrimSpace(answer), OptionNo) {
  196 + cntNo++
  197 + } else if strings.EqualFold(strings.TrimSpace(answer), OptionNoCertain) {
  198 + cntUncertain++
  199 + }
  200 + }
  201 + //只有一级维度的必须填写
  202 + if hasSub {
  203 + if cntYes > 0 {
  204 + s[gIdx].Answer = OptionYes
  205 + } else if cntNo > 0 {
  206 + s[gIdx].Answer = OptionNo
  207 + } else if cntUncertain > 0 {
  208 + s[gIdx].Answer = OptionNoCertain
  209 + }
  210 + }
  211 + if hasSub && cntYes == 0 && cntNo == 0 && cntUncertain == 0 {
  212 + err = NewCustomMessage(2, fmt.Sprintf("未填写自查项:%v,二级维度至少需要填写一项", s[gIdx].CheckItem))
  213 + }
  214 + if !hasSub && len(s[gIdx].Answer) == 0 {
  215 + err = NewCustomMessage(2, fmt.Sprintf("未填写自查项:%v", s[gIdx].CheckItem))
  216 + }
  217 + }
  218 + return
  219 +}
  220 +
160 //自查问题 221 //自查问题
161 func NewCheckQuestion(checkItem, title string, groupId int64, ops []CheckOption) *CheckQuestion { 222 func NewCheckQuestion(checkItem, title string, groupId int64, ops []CheckOption) *CheckQuestion {
162 return &CheckQuestion{ 223 return &CheckQuestion{
@@ -224,3 +285,93 @@ type SubmitChecksRequest struct { @@ -224,3 +285,93 @@ type SubmitChecksRequest struct {
224 } 285 }
225 type SubmitChecksResponse struct { 286 type SubmitChecksResponse struct {
226 } 287 }
  288 +
  289 +/*SiftingResultsItemHistory 筛选历史*/
  290 +type SiftingResultsItemHistoryRequest struct {
  291 + ChanceId int64 `json:"chanceId" valid:"Required"`
  292 +}
  293 +type SiftingResultsItemHistoryResponse struct {
  294 + SiftingResults SiftingResults `json:"siftingResults"`
  295 + TotalSubmitters int `json:"totalSubmitters"`
  296 +}
  297 +
  298 +type SiftingResult struct {
  299 + CheckId int `json:"checkId"` //检查项id
  300 + CheckParentId int64 `json:"parentId"` //项父id
  301 + //GroupId int `json:"json:groupId"`//项分组id
  302 + Title string `json:"title"` //标题
  303 + CheckItem string `json:"checkItem"` //自查项
  304 +
  305 + TotalYes int `json:"totalYes"` //选择是的人数
  306 + TotalNo int `json:"totalNo"` //选择否的人数
  307 + TotalUncertain int `json:"totalUncertain"` //选择不清楚的人数
  308 + TotalSubmitters int `json:"totalSubmitters"` //总提交人数
  309 +
  310 + SubSiftingResults SiftingResults `json:"subSiftingResults"`
  311 +}
  312 +
  313 +type SiftingResults []SiftingResult
  314 +
  315 +func (s SiftingResults) AddStatic(checkId int, answer string) {
  316 + s.addStatic(checkId, answer)
  317 +}
  318 +
  319 +//清空统计结果
  320 +func (s SiftingResults) ClearStatic() {
  321 + for i := range s {
  322 + s[i].TotalYes = 0
  323 + s[i].TotalNo = 0
  324 + s[i].TotalUncertain = 0
  325 + s[i].TotalSubmitters = 0
  326 + s[i].SubSiftingResults.ClearStatic()
  327 + }
  328 +}
  329 +
  330 +//添加统计
  331 +func (s SiftingResults) addStatic(checkId int, answer string) {
  332 + for i := range s {
  333 + if s[i].CheckId == checkId {
  334 + var isAnswer = true
  335 + switch answer {
  336 + case OptionYes:
  337 + s[i].TotalYes++
  338 + break
  339 + case OptionNo:
  340 + s[i].TotalNo++
  341 + break
  342 + case OptionNoCertain:
  343 + s[i].TotalUncertain++
  344 + break
  345 + default:
  346 + isAnswer = false
  347 + break
  348 + }
  349 + if isAnswer {
  350 + s[i].TotalSubmitters++
  351 + }
  352 + }
  353 + s[i].SubSiftingResults.AddStatic(checkId, answer)
  354 + }
  355 +}
  356 +
  357 +/*SiftingResultsItemDetail 筛选历史详情*/
  358 +type SiftingResultsItemDetailRequest struct {
  359 + ChanceId int64 `json:"chanceId" valid:"Required"`
  360 + CheckId int `json:"checkId" valid:"Required"` //检查项id
  361 +}
  362 +type SiftingResultsItemDetailResponse struct {
  363 + SiftingResultDetails []SiftingResultDetail `json:"siftingResultDetails"`
  364 +}
  365 +
  366 +//筛选结果详情
  367 +type SiftingResultDetail struct {
  368 + Option string `json:"option"` //选项:是 否 不清楚
  369 + Items SiftingCommitItems `json:"items"`
  370 +}
  371 +
  372 +//筛选结果提交人项
  373 +type SiftingCommitItems []SiftingCommitItem
  374 +type SiftingCommitItem struct {
  375 + Provider *BaseUserInfo `json:"provider"`
  376 + Reason string `json:"reason"` //理由
  377 +}
@@ -273,6 +273,22 @@ func init() { @@ -273,6 +273,22 @@ func init() {
273 273
274 beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"], 274 beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
275 beego.ControllerComments{ 275 beego.ControllerComments{
  276 + Method: "SiftingResultsItemDetail",
  277 + Router: `/siftingResults/itemDetail`,
  278 + AllowHTTPMethods: []string{"post"},
  279 + MethodParams: param.Make(),
  280 + Params: nil})
  281 +
  282 + beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
  283 + beego.ControllerComments{
  284 + Method: "SiftingResultsItemHistory",
  285 + Router: `/siftingResults/itemHistory`,
  286 + AllowHTTPMethods: []string{"post"},
  287 + MethodParams: param.Make(),
  288 + Params: nil})
  289 +
  290 + beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
  291 + beego.ControllerComments{
276 Method: "ChanceStatistics", 292 Method: "ChanceStatistics",
277 Router: `/statistics`, 293 Router: `/statistics`,
278 AllowHTTPMethods: []string{"post"}, 294 AllowHTTPMethods: []string{"post"},
@@ -2235,6 +2235,9 @@ func CheckQuestions(header *protocol.RequestHeader, request *protocol.CheckQuest @@ -2235,6 +2235,9 @@ func CheckQuestions(header *protocol.RequestHeader, request *protocol.CheckQuest
2235 } 2235 }
2236 for i := range rsp.Questions { 2236 for i := range rsp.Questions {
2237 rsp.Questions[i].CheckOptions = protocol.CheckOptionsApprove 2237 rsp.Questions[i].CheckOptions = protocol.CheckOptionsApprove
  2238 + //if rsp.Questions[i].ParentId!=0{
  2239 + // rsp.Questions[i].Title= rsp.Questions[i].CheckItem
  2240 + //}
2238 } 2241 }
2239 } 2242 }
2240 return 2243 return
1 package chance 1 package chance
2 2
3 import ( 3 import (
  4 + "fmt"
4 "github.com/astaxie/beego/orm" 5 "github.com/astaxie/beego/orm"
5 "gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/idgen" 6 "gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/idgen"
6 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" 7 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
@@ -8,6 +9,7 @@ import ( @@ -8,6 +9,7 @@ import (
8 "opp/models" 9 "opp/models"
9 "opp/protocol" 10 "opp/protocol"
10 "opp/services/agg" 11 "opp/services/agg"
  12 + "strings"
11 "time" 13 "time"
12 ) 14 )
13 15
@@ -80,6 +82,10 @@ func SubmitChecks(header *protocol.RequestHeader, request *protocol.SubmitChecks @@ -80,6 +82,10 @@ func SubmitChecks(header *protocol.RequestHeader, request *protocol.SubmitChecks
80 if request.Uid != 0 { 82 if request.Uid != 0 {
81 header.UserId = request.Uid 83 header.UserId = request.Uid
82 } 84 }
  85 + if err = request.SelfChecks.SetSelfChecksLevel1ByRule(); err != nil {
  86 + log.Error(err)
  87 + return
  88 + }
83 if p, err = models.GetAuditorLatestAuditFlowProcess(request.ChanceId, header.UserId); err != nil { 89 if p, err = models.GetAuditorLatestAuditFlowProcess(request.ChanceId, header.UserId); err != nil {
84 log.Error(request.ChanceId, header.UserId, err) 90 log.Error(request.ChanceId, header.UserId, err)
85 if err == orm.ErrNoRows { 91 if err == orm.ErrNoRows {
@@ -179,3 +185,121 @@ func CheckIsCommitAllCheck(chanceId int64) (err error, result bool) { @@ -179,3 +185,121 @@ func CheckIsCommitAllCheck(chanceId int64) (err error, result bool) {
179 } 185 }
180 return 186 return
181 } 187 }
  188 +
  189 +//筛选历史
  190 +func SiftingResultsItemHistory(header *protocol.RequestHeader, request *protocol.SiftingResultsItemHistoryRequest) (rsp *protocol.SiftingResultsItemHistoryResponse, err error) {
  191 + var (
  192 + checkResults []*models.ChanceCheckResult
  193 + ids []int64
  194 + )
  195 + rsp = &protocol.SiftingResultsItemHistoryResponse{}
  196 + if checkResults, err = models.GetCheckResultsByChanceId(request.ChanceId); err != nil {
  197 + if err == orm.ErrNoRows {
  198 + err = nil
  199 + return
  200 + }
  201 + log.Error(err)
  202 + return
  203 + }
  204 + rsp.SiftingResults = NewSiftingResults(checkResults)
  205 + if ids, err = models.GetCheckResultAllSubmitters(request.ChanceId); err == nil {
  206 + rsp.TotalSubmitters = len(ids)
  207 + }
  208 + for i := range checkResults {
  209 + item := checkResults[i]
  210 + rsp.SiftingResults.AddStatic(item.CheckId, item.Answer)
  211 + }
  212 + return
  213 +}
  214 +
  215 +//新建筛选结果列表
  216 +func NewSiftingResults(checkResults []*models.ChanceCheckResult) protocol.SiftingResults {
  217 + var rsp []protocol.SiftingResult
  218 + var maps = make(map[int]*protocol.SiftingResult, 0)
  219 + var ids []int
  220 + for i := range checkResults {
  221 + r := checkResults[i]
  222 + var tmp *protocol.SiftingResult
  223 + var ok bool
  224 + new := &protocol.SiftingResult{
  225 + CheckId: r.CheckId,
  226 + CheckParentId: r.CheckPid,
  227 + CheckItem: r.CheckItem,
  228 + Title: r.CheckItem,
  229 + SubSiftingResults: make([]protocol.SiftingResult, 0),
  230 + }
  231 + if tmp, ok = maps[new.CheckId]; !ok && new.CheckParentId == 0 {
  232 + new.Title = fmt.Sprintf("%v、%v", len(ids)+1, new.CheckItem) //父级标题 1、素食为主 子级标题:素食为主
  233 + maps[new.CheckId] = new
  234 + ids = append(ids, new.CheckId)
  235 + }
  236 + //已存在的向子级增加一条记录
  237 + if tmp, ok = maps[int(new.CheckParentId)]; ok {
  238 + var exists bool = false
  239 + for i := range tmp.SubSiftingResults {
  240 + if tmp.SubSiftingResults[i].CheckId == new.CheckId {
  241 + exists = true
  242 + break
  243 + }
  244 + }
  245 + if !exists {
  246 + tmp.SubSiftingResults = append(tmp.SubSiftingResults, *new)
  247 + }
  248 + }
  249 + }
  250 + for i := range ids {
  251 + if v, ok := maps[ids[i]]; ok {
  252 + rsp = append(rsp, *v)
  253 + }
  254 + }
  255 + return rsp
  256 +}
  257 +
  258 +//筛选历史详情
  259 +func SiftingResultsItemDetail(header *protocol.RequestHeader, request *protocol.SiftingResultsItemDetailRequest) (rsp *protocol.SiftingResultsItemDetailResponse, err error) {
  260 + var (
  261 + checkResults []*models.ChanceCheckResult
  262 + sortList []string = []string{protocol.OptionYes, protocol.OptionNo, protocol.OptionNoCertain}
  263 + )
  264 + rsp = &protocol.SiftingResultsItemDetailResponse{}
  265 + if checkResults, err = models.GetCheckResultsByCheckId(request.ChanceId, request.CheckId); err != nil {
  266 + if err == orm.ErrNoRows {
  267 + err = nil
  268 + return
  269 + }
  270 + log.Error(err)
  271 + return
  272 + }
  273 + var tmpMap = make(map[string]protocol.SiftingResultDetail)
  274 + for i := range checkResults {
  275 + checkResult := checkResults[i]
  276 + key := strings.TrimSpace(checkResult.Answer)
  277 + if len(key) == 0 {
  278 + continue
  279 + }
  280 + var provider *protocol.BaseUserInfo
  281 + if provider, err = agg.GetUserBaseInfo(checkResult.UserCompanyId, header.CompanyId); err != nil {
  282 + log.Error(err)
  283 + return
  284 + }
  285 + commitItem := protocol.SiftingCommitItem{
  286 + Provider: provider,
  287 + Reason: checkResult.Reason,
  288 + }
  289 + if v, ok := tmpMap[key]; ok {
  290 + v.Items = append(v.Items, commitItem)
  291 + tmpMap[key] = v
  292 + } else {
  293 + tmpMap[key] = protocol.SiftingResultDetail{
  294 + Option: key,
  295 + Items: []protocol.SiftingCommitItem{commitItem},
  296 + }
  297 + }
  298 + }
  299 + for i := range sortList {
  300 + if v, ok := tmpMap[sortList[i]]; ok {
  301 + rsp.SiftingResultDetails = append(rsp.SiftingResultDetails, v)
  302 + }
  303 + }
  304 + return
  305 +}