problem_info.go 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. package autocode
  2. import (
  3. global "github.com/flipped-aurora/gin-vue-admin/server/global"
  4. "github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
  5. autocodeReq "github.com/flipped-aurora/gin-vue-admin/server/model/autocode/request"
  6. "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
  7. "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
  8. "github.com/flipped-aurora/gin-vue-admin/server/service"
  9. "github.com/flipped-aurora/gin-vue-admin/server/utils"
  10. "github.com/gin-gonic/gin"
  11. "github.com/silenceper/wechat/v2/officialaccount/message"
  12. "go.uber.org/zap"
  13. "strconv"
  14. "time"
  15. )
  16. type ProblemInfoApi struct {
  17. }
  18. var problemInfoService = service.ServiceGroupApp.AutoCodeServiceGroup.ProblemInfoService
  19. // CreateProblemInfo 创建ProblemInfo
  20. // @Tags ProblemInfo
  21. // @Summary 创建ProblemInfo
  22. // @Security ApiKeyAuth
  23. // @accept application/json
  24. // @Produce application/json
  25. // @Param data body autocode.ProblemInfo true "创建ProblemInfo"
  26. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  27. // @Router /problemInfo/createProblemInfo [post]
  28. func (problemInfoApi *ProblemInfoApi) CreateProblemInfo(c *gin.Context) {
  29. userId := utils.GetUserID(c)
  30. var problemInfo autocode.ProblemInfo
  31. _ = c.ShouldBindJSON(&problemInfo)
  32. problemInfo.Status = "Untreated"
  33. if err, place := service.ServiceGroupApp.AutoCodeServiceGroup.PlaceService.GetPlace(problemInfo.SiteId); err != nil {
  34. response.FailWithMessage("创建失败,选择站点错误", c)
  35. } else {
  36. problemInfo.Oper = userId
  37. problemInfo.SiteType = place.Type
  38. problemInfo.Position = place.Position
  39. problemInfo.SiteName = place.Name
  40. problemInfo.Region = place.Region
  41. }
  42. if err := problemInfoService.CreateProblemInfo(problemInfo); err != nil {
  43. global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
  44. response.FailWithMessage("发布失败", c)
  45. } else {
  46. response.OkWithMessage("发布成功", c)
  47. }
  48. }
  49. func (problemInfoApi *ProblemInfoApi) ExportExcel(c *gin.Context) {
  50. var problemInfo autocodeReq.ProblemInfoSearch
  51. _ = c.ShouldBindJSON(&problemInfo)
  52. filePath := global.GVA_CONFIG.Excel.Dir + strconv.FormatInt(time.Now().Unix(), 10) + ".xlsx"
  53. if err, list, _ := problemInfoService.GetProblemInfoInfoList(problemInfo); err != nil {
  54. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  55. response.FailWithMessage("获取失败", c)
  56. } else {
  57. _, dictList := service.ServiceGroupApp.SystemServiceGroup.DictionaryService.GetSysDictionaryDetailList()
  58. err := service.ServiceGroupApp.ExampleServiceGroup.ExcelService.ProblemInfoList2Excel(list, filePath, dictList)
  59. if err != nil {
  60. global.GVA_LOG.Error("转换Excel失败!", zap.Any("err", err))
  61. response.FailWithMessage("转换Excel失败", c)
  62. return
  63. }
  64. c.Writer.Header().Add("success", "true")
  65. c.File(filePath)
  66. }
  67. }
  68. func (problemInfoApi *ProblemInfoApi) SendUser(c *gin.Context) {
  69. var sendUser autocodeReq.SendUser
  70. _ = c.ShouldBindJSON(&sendUser)
  71. _, problem := problemInfoService.GetProblemInfo(sendUser.ProblemID)
  72. _, oper := service.ServiceGroupApp.SystemServiceGroup.FindUserById(int(problem.Oper))
  73. appid := global.GVA_CONFIG.Wxxcx.Appid
  74. for _, id := range sendUser.ID {
  75. userId, _ := strconv.Atoi(id)
  76. _, user := service.ServiceGroupApp.SystemServiceGroup.FindUserById(userId)
  77. if user.WechatId == "" {
  78. continue
  79. }
  80. msg := &message.TemplateMessage{
  81. ToUser: user.WechatId,
  82. TemplateID: "DAyIWY0UUaqGxMG13MUtNCkNFKEe719sp75P0tT7FS4",
  83. Data: map[string]*message.TemplateDataItem{
  84. "first": {Value: "有新的站点问题"},
  85. "keyword1": {Value: oper.Username},
  86. "keyword2": {Value: problem.SiteName},
  87. "keyword3": {Value: problem.Department},
  88. "keyword4": {Value: problem.CreatedAt.Format("2006-01-02 15:04:05")},
  89. "remark": {Value: "点击查看问题"},
  90. },
  91. MiniProgram: struct {
  92. AppID string `json:"appid"`
  93. PagePath string `json:"pagepath"`
  94. }{AppID: appid, PagePath: "/pages/public-details?id=" + strconv.Itoa(int(sendUser.ProblemID))},
  95. }
  96. if _, err := global.GVA_WECHAT.GetTemplate().Send(msg); err != nil {
  97. global.GVA_LOG.Error("微信模板通知失败!", zap.Any("err", err))
  98. }
  99. }
  100. response.OkWithMessage("发送成功", c)
  101. }
  102. // DeleteProblemInfo 删除ProblemInfo
  103. // @Tags ProblemInfo
  104. // @Summary 删除ProblemInfo
  105. // @Security ApiKeyAuth
  106. // @accept application/json
  107. // @Produce application/json
  108. // @Param data body autocode.ProblemInfo true "删除ProblemInfo"
  109. // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
  110. // @Router /problemInfo/deleteProblemInfo [delete]
  111. func (problemInfoApi *ProblemInfoApi) DeleteProblemInfo(c *gin.Context) {
  112. var problemInfo autocode.ProblemInfo
  113. _ = c.ShouldBindJSON(&problemInfo)
  114. if err := problemInfoService.DeleteProblemInfo(problemInfo); err != nil {
  115. global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
  116. response.FailWithMessage("删除失败", c)
  117. } else {
  118. response.OkWithMessage("删除成功", c)
  119. }
  120. }
  121. // DeleteProblemInfoByIds 批量删除ProblemInfo
  122. // @Tags ProblemInfo
  123. // @Summary 批量删除ProblemInfo
  124. // @Security ApiKeyAuth
  125. // @accept application/json
  126. // @Produce application/json
  127. // @Param data body request.IdsReq true "批量删除ProblemInfo"
  128. // @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
  129. // @Router /problemInfo/deleteProblemInfoByIds [delete]
  130. func (problemInfoApi *ProblemInfoApi) DeleteProblemInfoByIds(c *gin.Context) {
  131. var IDS request.IdsReq
  132. _ = c.ShouldBindJSON(&IDS)
  133. if err := problemInfoService.DeleteProblemInfoByIds(IDS); err != nil {
  134. global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err))
  135. response.FailWithMessage("批量删除失败", c)
  136. } else {
  137. response.OkWithMessage("批量删除成功", c)
  138. }
  139. }
  140. // UpdateProblemInfo 更新ProblemInfo
  141. // @Tags ProblemInfo
  142. // @Summary 更新ProblemInfo
  143. // @Security ApiKeyAuth
  144. // @accept application/json
  145. // @Produce application/json
  146. // @Param data body autocode.ProblemInfo true "更新ProblemInfo"
  147. // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
  148. // @Router /problemInfo/updateProblemInfo [put]
  149. func (problemInfoApi *ProblemInfoApi) UpdateProblemInfo(c *gin.Context) {
  150. var problemInfo autocode.ProblemInfo
  151. _ = c.ShouldBindJSON(&problemInfo)
  152. _, problemInfoNow := problemInfoService.GetProblemInfo(problemInfo.ID)
  153. problemInfoNow.Handler = problemInfo.Handler
  154. problemInfoNow.HandImgs = problemInfo.HandImgs
  155. problemInfoNow.HandText = problemInfo.HandText
  156. problemInfoNow.Status = "Processed"
  157. if err := problemInfoService.UpdateProblemInfo(problemInfoNow); err != nil {
  158. global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
  159. response.FailWithMessage("更新失败", c)
  160. } else {
  161. response.OkWithMessage("更新成功", c)
  162. }
  163. }
  164. // FindProblemInfo 用id查询ProblemInfo
  165. // @Tags ProblemInfo
  166. // @Summary 用id查询ProblemInfo
  167. // @Security ApiKeyAuth
  168. // @accept application/json
  169. // @Produce application/json
  170. // @Param data query autocode.ProblemInfo true "用id查询ProblemInfo"
  171. // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
  172. // @Router /problemInfo/findProblemInfo [get]
  173. func (problemInfoApi *ProblemInfoApi) FindProblemInfo(c *gin.Context) {
  174. var problemInfo autocode.ProblemInfo
  175. _ = c.ShouldBindQuery(&problemInfo)
  176. if err, reproblemInfo := problemInfoService.GetProblemInfo(problemInfo.ID); err != nil {
  177. global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
  178. response.FailWithMessage("查询失败", c)
  179. } else {
  180. //param := reqMode.SysDictionarySearch{, request.PageInfo{PageSize: 9999, Page: 0}}
  181. _, reproblemInfo.MatterList = service.ServiceGroupApp.SystemServiceGroup.DictionaryService.GetSysDictionaryDetail(reproblemInfo.SiteType)
  182. response.OkWithData(gin.H{"reproblemInfo": reproblemInfo}, c)
  183. }
  184. }
  185. func (problemInfoApi *ProblemInfoApi) FindProblemPInfo(c *gin.Context) {
  186. var problemInfo autocode.ProblemInfo
  187. _ = c.ShouldBindQuery(&problemInfo)
  188. if err, reproblemInfo := problemInfoService.GetProblemInfo(problemInfo.ID); err != nil {
  189. global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
  190. response.FailWithMessage("查询失败", c)
  191. } else {
  192. userId := utils.GetUserID(c)
  193. //记录查看记录
  194. if err, readCount := service.ServiceGroupApp.AutoCodeServiceGroup.ReadCountService.GetReadCountByUserId(int(userId), int(problemInfo.ID)); err != nil {
  195. //新增
  196. service.ServiceGroupApp.AutoCodeServiceGroup.ReadCountService.CreateReadCount(autocode.ReadCount{ProblemId: problemInfo.ID, UserId: userId, UserName: utils.GetUserInfo(c).Username})
  197. } else {
  198. service.ServiceGroupApp.AutoCodeServiceGroup.ReadCountService.UpdateReadCountBy(readCount.ID)
  199. }
  200. //累加总阅读量
  201. problemInfoService.UpdateProblemInfoCount(problemInfo.ID)
  202. //param := reqMode.SysDictionarySearch{, request.PageInfo{PageSize: 9999, Page: 0}}
  203. _, reproblemInfo.MatterList = service.ServiceGroupApp.SystemServiceGroup.DictionaryService.GetSysDictionaryDetail(reproblemInfo.SiteType)
  204. response.OkWithData(gin.H{"reproblemInfo": reproblemInfo}, c)
  205. }
  206. }
  207. // GetProblemInfoList 分页获取ProblemInfo列表
  208. // @Tags ProblemInfo
  209. // @Summary 分页获取ProblemInfo列表
  210. // @Security ApiKeyAuth
  211. // @accept application/json
  212. // @Produce application/json
  213. // @Param data query autocodeReq.ProblemInfoSearch true "分页获取ProblemInfo列表"
  214. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  215. // @Router /problemInfo/getProblemInfoList [get]
  216. func (problemInfoApi *ProblemInfoApi) GetProblemInfoList(c *gin.Context) {
  217. var pageInfo autocodeReq.ProblemInfoSearch
  218. _ = c.ShouldBindQuery(&pageInfo)
  219. if err, list, total := problemInfoService.GetProblemInfoInfoList(pageInfo); err != nil {
  220. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  221. response.FailWithMessage("获取失败", c)
  222. } else {
  223. response.OkWithDetailed(response.PageResult{
  224. List: list,
  225. Total: total,
  226. Page: pageInfo.Page,
  227. PageSize: pageInfo.PageSize,
  228. }, "获取成功", c)
  229. }
  230. }