question.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. package http
  2. import (
  3. "go-common/app/service/openplatform/anti-fraud/model"
  4. "go-common/library/ecode"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/net/http/blademaster/binding"
  8. )
  9. // qusBankInfo 题库信息
  10. func qusBankInfo(c *bm.Context) {
  11. params := new(model.ArgGetQusBank)
  12. if err := c.Bind(params); err != nil {
  13. return
  14. }
  15. c.JSON(svc.GetQusBankInfo(c, params.QsBId))
  16. }
  17. // qusBankList 题库列表
  18. func qusBankList(c *bm.Context) {
  19. params := new(model.ArgBankList)
  20. if err := c.Bind(params); err != nil {
  21. return
  22. }
  23. result := model.RespList{}
  24. list, err := svc.GetQusBanklist(c, params.PageNo, params.PageSize, params.Name)
  25. if err != nil {
  26. c.JSON(nil, err)
  27. return
  28. }
  29. total, err := svc.GetQusBankTotal(c, params.Name)
  30. if err != nil {
  31. c.JSON(nil, err)
  32. return
  33. }
  34. result.Items = list
  35. result.PageSize = params.PageSize
  36. result.PageNo = params.PageNo
  37. result.Total = total
  38. c.JSON(result, nil)
  39. }
  40. // qusBankAdd 添加题库
  41. func qusBankAdd(c *bm.Context) {
  42. params := new(model.ArgAddQusBank)
  43. if err := c.BindWith(params, binding.JSON); err != nil {
  44. return
  45. }
  46. c.JSON(svc.AddQusBank(c, params))
  47. }
  48. // qusBankEdit 更新题库
  49. func qusBankEdit(c *bm.Context) {
  50. params := new(model.ArgUpdateQusBank)
  51. if err := c.BindWith(params, binding.JSON); err != nil {
  52. return
  53. }
  54. c.JSON(svc.UpdataQusBank(c, params.QsBId, params.QBName, params.MaxRetryTime, params.CdTime))
  55. }
  56. // qusBankDel 删除题库
  57. func qusBankDel(c *bm.Context) {
  58. params := new(model.ArgBaseBank)
  59. if err := c.BindWith(params, binding.JSON); err != nil {
  60. return
  61. }
  62. c.JSON(svc.DelQusBank(c, params.QsBId, model.DeledStatus))
  63. }
  64. // qusInfo 题目详情
  65. func qusInfo(c *bm.Context) {
  66. params := new(model.ArgGetQus)
  67. if err := c.Bind(params); err != nil {
  68. return
  69. }
  70. data := &model.QuestionAll{}
  71. answers, err := svc.GetAnswerList(c, params.QsID)
  72. if err != nil {
  73. c.JSON(nil, ecode.QusIDInvalid)
  74. return
  75. }
  76. info, err := svc.GetQusInfo(c, params.QsID)
  77. if err != nil || info == nil {
  78. c.JSON(nil, ecode.QusIDInvalid)
  79. return
  80. }
  81. data.Question = *info
  82. data.AnswersList = answers
  83. c.JSON(data, err)
  84. }
  85. // qusList 题目列表
  86. func qusList(c *bm.Context) {
  87. params := new(model.ArgQusList)
  88. if err := c.Bind(params); err != nil {
  89. return
  90. }
  91. result := model.RespList{}
  92. list, err := svc.GetQuslist(c, params.PageNo, params.PageSize, params.QsBId)
  93. if err != nil {
  94. c.JSON(nil, err)
  95. return
  96. }
  97. total, err := svc.GetQusTotal(c, params.QsBId)
  98. if err != nil {
  99. c.JSON(nil, err)
  100. return
  101. }
  102. result.Items = list
  103. result.PageSize = params.PageSize
  104. result.PageNo = params.PageNo
  105. result.Total = total
  106. c.JSON(result, nil)
  107. }
  108. // qusAdd 题目添加
  109. func qusAdd(c *bm.Context) {
  110. params := new(model.ArgAddQus)
  111. if err := c.BindWith(params, binding.JSON); err != nil {
  112. return
  113. }
  114. anlist := params.Answer
  115. msg, err := svc.CheckAnswer(c, 0, params.Type, anlist)
  116. if err != nil {
  117. c.JSON(msg, err)
  118. return
  119. }
  120. addQus := &model.AddQus{
  121. BId: params.BId,
  122. Type: params.Type,
  123. Name: params.Name,
  124. Dif: params.Dif,
  125. AnType: params.AnType,
  126. Answers: anlist,
  127. QsID: 0,
  128. }
  129. c.JSON(svc.AddQus(c, addQus, anlist))
  130. }
  131. // qusUpdate 题目更新
  132. func qusUpdate(c *bm.Context) {
  133. params := new(model.ArgUpdateQus)
  134. if err := c.BindWith(params, binding.JSON); err != nil {
  135. return
  136. }
  137. answers := params.Answer
  138. msg, err := svc.CheckAnswer(c, params.QsID, params.Type, answers)
  139. if err != nil {
  140. c.JSON(msg, err)
  141. return
  142. }
  143. c.JSON(svc.UpdateQus(c, params, answers))
  144. }
  145. // questionBankBind 项目关联题库
  146. func questionBankBind(c *bm.Context) {
  147. params := &model.ArgQuestionBankBinds{}
  148. if err := c.BindWith(params, binding.JSON); err != nil {
  149. return
  150. }
  151. err := svc.QuestionBankBind(c, params)
  152. if err != nil {
  153. log.Error("questionBankBind(%v) error(%v)", params, err)
  154. }
  155. c.JSON(nil, err)
  156. }
  157. // questionBankUnbind 解绑
  158. func questionBankUnbind(c *bm.Context) {
  159. params := &model.ArgQuestionBankUnbind{}
  160. if err := c.BindWith(params, binding.JSON); err != nil {
  161. return
  162. }
  163. c.JSON(nil, svc.QuestionBankUnbind(c, params))
  164. }
  165. // qusDel 删除题目
  166. func qusDel(c *bm.Context) {
  167. params := new(model.ArgGetQus)
  168. if err := c.BindWith(params, binding.JSON); err != nil {
  169. return
  170. }
  171. c.JSON(svc.DelQus(c, params.QsID))
  172. }
  173. // getBankBind 绑定关系
  174. func getBankBind(c *bm.Context) {
  175. params := &model.ArgGetBankBind{}
  176. if err := c.BindWith(params, binding.JSON); err != nil {
  177. return
  178. }
  179. c.JSON(svc.GetQuestionBankBind(c, params))
  180. }
  181. // getBindItems 查询绑定到题库的
  182. func getBindItems(c *bm.Context) {
  183. params := &model.ArgGetBindItems{}
  184. if err := c.Bind(params); err != nil {
  185. return
  186. }
  187. c.JSON(svc.GetBindItem(c, params))
  188. }
  189. // getQuestion 随机获取一个问题
  190. func getQuestion(c *bm.Context) {
  191. params := &model.ArgGetQuestion{}
  192. if err := c.Bind(params); err != nil {
  193. return
  194. }
  195. c.JSON(svc.GetQuestion(c, params))
  196. }
  197. // answerQuestion 答题
  198. func answerQuestion(c *bm.Context) {
  199. // 判断是否可答 返回冷却时间
  200. params := &model.ArgCheckAnswer{}
  201. if err := c.BindWith(params, binding.JSON); err != nil {
  202. return
  203. }
  204. c.JSON(svc.UserAnswer(c, params))
  205. }
  206. // qusBankCheck 题库检查
  207. func qusBankCheck(c *bm.Context) {
  208. // 判断是否可答 返回冷却时间
  209. params := &model.ArgCheckQus{}
  210. if err := c.BindWith(params, binding.JSON); err != nil {
  211. return
  212. }
  213. c.JSON(svc.QusBankCheck(c, params))
  214. }