problem_info.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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/model/system"
  9. "github.com/flipped-aurora/gin-vue-admin/server/service"
  10. "github.com/flipped-aurora/gin-vue-admin/server/utils"
  11. "github.com/gin-gonic/gin"
  12. "github.com/silenceper/wechat/v2/officialaccount/message"
  13. "go.uber.org/zap"
  14. "strconv"
  15. "strings"
  16. "time"
  17. )
  18. type ProblemInfoApi struct {
  19. }
  20. var problemInfoService = service.ServiceGroupApp.AutoCodeServiceGroup.ProblemInfoService
  21. // CreateProblemInfo 创建ProblemInfo
  22. // @Tags ProblemInfo
  23. // @Summary 创建ProblemInfo
  24. // @Security ApiKeyAuth
  25. // @accept application/json
  26. // @Produce application/json
  27. // @Param data body autocode.ProblemInfo true "创建ProblemInfo"
  28. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  29. // @Router /problemInfo/createProblemInfo [post]
  30. func (problemInfoApi *ProblemInfoApi) CreateProblemInfo(c *gin.Context) {
  31. userId := utils.GetUserID(c)
  32. var problemInfo autocode.ProblemInfo
  33. _ = c.ShouldBindJSON(&problemInfo)
  34. problemInfo.Status = "Untreated"
  35. if err, place := service.ServiceGroupApp.AutoCodeServiceGroup.PlaceService.GetPlace(problemInfo.SiteId); err != nil {
  36. response.FailWithMessage("创建失败,选择站点错误", c)
  37. } else {
  38. problemInfo.Oper = userId
  39. problemInfo.SiteType = place.Type
  40. problemInfo.Position = place.Position
  41. problemInfo.SiteName = place.Name
  42. problemInfo.Region = place.Region
  43. }
  44. if problemInfo.UnitId != nil && *problemInfo.UnitId != 0 {
  45. probleTypeIds := strings.Split(problemInfo.Matter, "|")
  46. if len(probleTypeIds) > 0 {
  47. _, proTypes := problemTypeService.GetProblemTypeIds(probleTypeIds)
  48. var integral int
  49. for _, proType := range proTypes {
  50. inter := *proType.Integral
  51. integral = integral + inter
  52. }
  53. problemInfo.Integral = &integral
  54. }
  55. // 发送问题到负责人
  56. if err, unituser := unitUserService.GetUnitUsers(problemInfo.UnitId); err != nil {
  57. source := make([]string, 0)
  58. for _, item := range unituser {
  59. source = append(source, item.UUID)
  60. }
  61. SendMsg(autocodeReq.SendUser{ProblemID: problemInfo.ID, ID: source}, true)
  62. }
  63. }
  64. if err := problemInfoService.CreateProblemInfo(problemInfo); err != nil {
  65. global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
  66. response.FailWithMessage("发布失败", c)
  67. } else {
  68. response.OkWithMessage("发布成功", c)
  69. }
  70. }
  71. func (problemInfoApi *ProblemInfoApi) ExportExcel(c *gin.Context) {
  72. var problemInfo autocodeReq.ProblemInfoSearch
  73. _ = c.ShouldBindJSON(&problemInfo)
  74. filePath := global.GVA_CONFIG.Excel.Dir + strconv.FormatInt(time.Now().Unix(), 10) + ".xlsx"
  75. if err, list, _ := problemInfoService.GetProblemInfoInfoList(problemInfo); err != nil {
  76. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  77. response.FailWithMessage("获取失败", c)
  78. } else {
  79. _, siteType := service.ServiceGroupApp.SystemServiceGroup.DictionaryService.GetSysDictionary("site_type", 0)
  80. _, proList := problemTypeService.GetProblemTypeInfoListAll()
  81. err := service.ServiceGroupApp.ExampleServiceGroup.ExcelService.ProblemInfoList2Excel(list, filePath, siteType, proList)
  82. if err != nil {
  83. global.GVA_LOG.Error("转换Excel失败!", zap.Any("err", err))
  84. response.FailWithMessage("转换Excel失败", c)
  85. return
  86. }
  87. c.Writer.Header().Add("success", "true")
  88. c.File(filePath)
  89. }
  90. }
  91. func (problemInfoApi *ProblemInfoApi) SendUser(c *gin.Context) {
  92. var sendUser autocodeReq.SendUser
  93. _ = c.ShouldBindJSON(&sendUser)
  94. SendMsg(sendUser, false)
  95. response.OkWithMessage("发送成功", c)
  96. }
  97. func SendMsg(sendUser autocodeReq.SendUser, isUuid bool) {
  98. _, problem := problemInfoService.GetProblemInfo(sendUser.ProblemID)
  99. _, opera := service.ServiceGroupApp.SystemServiceGroup.FindUserById(int(problem.Oper))
  100. appid := global.GVA_CONFIG.Wxxcx.Appid
  101. for _, id := range sendUser.ID {
  102. var user *system.SysUser
  103. if isUuid {
  104. _, user = service.ServiceGroupApp.SystemServiceGroup.FindUserByUuid(id)
  105. } else {
  106. userId, _ := strconv.Atoi(id)
  107. _, user = service.ServiceGroupApp.SystemServiceGroup.FindUserById(userId)
  108. }
  109. if user.WechatId == "" {
  110. continue
  111. }
  112. msg := &message.TemplateMessage{
  113. ToUser: user.WechatId,
  114. TemplateID: global.GVA_CONFIG.Wxxcx.Msgid,
  115. Data: map[string]*message.TemplateDataItem{
  116. "first": {Value: "有新的站点问题"},
  117. "keyword1": {Value: opera.Username},
  118. "keyword2": {Value: problem.SiteName},
  119. "keyword3": {Value: problem.Department},
  120. "keyword4": {Value: problem.CreatedAt.Format("2006-01-02 15:04:05")},
  121. "remark": {Value: "点击查看问题"},
  122. },
  123. MiniProgram: struct {
  124. AppID string `json:"appid"`
  125. PagePath string `json:"pagepath"`
  126. }{AppID: appid, PagePath: "/pages/public-details?id=" + strconv.Itoa(int(sendUser.ProblemID))},
  127. }
  128. if _, err := global.GVA_WECHAT.GetTemplate().Send(msg); err != nil {
  129. global.GVA_LOG.Error("微信模板通知失败!", zap.Any("err", err))
  130. }
  131. }
  132. }
  133. // DeleteProblemInfo 删除ProblemInfo
  134. // @Tags ProblemInfo
  135. // @Summary 删除ProblemInfo
  136. // @Security ApiKeyAuth
  137. // @accept application/json
  138. // @Produce application/json
  139. // @Param data body autocode.ProblemInfo true "删除ProblemInfo"
  140. // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
  141. // @Router /problemInfo/deleteProblemInfo [delete]
  142. func (problemInfoApi *ProblemInfoApi) DeleteProblemInfo(c *gin.Context) {
  143. var problemInfo autocode.ProblemInfo
  144. _ = c.ShouldBindJSON(&problemInfo)
  145. if err := problemInfoService.DeleteProblemInfo(problemInfo); err != nil {
  146. global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
  147. response.FailWithMessage("删除失败", c)
  148. } else {
  149. response.OkWithMessage("删除成功", c)
  150. }
  151. }
  152. // DeleteProblemInfoByIds 批量删除ProblemInfo
  153. // @Tags ProblemInfo
  154. // @Summary 批量删除ProblemInfo
  155. // @Security ApiKeyAuth
  156. // @accept application/json
  157. // @Produce application/json
  158. // @Param data body request.IdsReq true "批量删除ProblemInfo"
  159. // @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
  160. // @Router /problemInfo/deleteProblemInfoByIds [delete]
  161. func (problemInfoApi *ProblemInfoApi) DeleteProblemInfoByIds(c *gin.Context) {
  162. var IDS request.IdsReq
  163. _ = c.ShouldBindJSON(&IDS)
  164. if err := problemInfoService.DeleteProblemInfoByIds(IDS); err != nil {
  165. global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err))
  166. response.FailWithMessage("批量删除失败", c)
  167. } else {
  168. response.OkWithMessage("批量删除成功", c)
  169. }
  170. }
  171. // UpdateProblemInfo 更新ProblemInfo
  172. // @Tags ProblemInfo
  173. // @Summary 更新ProblemInfo
  174. // @Security ApiKeyAuth
  175. // @accept application/json
  176. // @Produce application/json
  177. // @Param data body autocode.ProblemInfo true "更新ProblemInfo"
  178. // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
  179. // @Router /problemInfo/updateProblemInfo [put]
  180. func (problemInfoApi *ProblemInfoApi) UpdateProblemInfo(c *gin.Context) {
  181. var problemInfo autocode.ProblemInfo
  182. _ = c.ShouldBindJSON(&problemInfo)
  183. _, problemInfoNow := problemInfoService.GetProblemInfo(problemInfo.ID)
  184. problemInfoNow.Handler = problemInfo.Handler
  185. problemInfoNow.HandImgs = problemInfo.HandImgs
  186. problemInfoNow.HandText = problemInfo.HandText
  187. problemInfoNow.Status = "Processed"
  188. if err := problemInfoService.UpdateProblemInfo(problemInfoNow); err != nil {
  189. global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
  190. response.FailWithMessage("更新失败", c)
  191. } else {
  192. response.OkWithMessage("更新成功", c)
  193. }
  194. }
  195. func (problemInfoApi *ProblemInfoApi) UpdateProblemInfoStatus(c *gin.Context) {
  196. var problemInfo autocode.ProblemInfo
  197. _ = c.ShouldBindJSON(&problemInfo)
  198. _, problemInfoNow := problemInfoService.GetProblemInfo(problemInfo.ID)
  199. problemInfoNow.Status = problemInfo.Status
  200. problemInfoNow.Audit = problemInfo.Audit
  201. if problemInfo.Status == "Success" {
  202. if time.Now().Before(problemInfoNow.HandAt) {
  203. //超时扣分
  204. //todo 扣站点分数
  205. //todo 扣单位分数
  206. _, unit := unitService.GetUnit(uint(*problemInfo.UnitId))
  207. oldIntegral := *unit.UnitIntegral
  208. nowIntegral := oldIntegral - *problemInfoNow.Integral
  209. unit.UnitIntegral = &nowIntegral
  210. unitService.UpdateUnitA(unit)
  211. } else {
  212. temp := 0
  213. problemInfo.Integral = &temp
  214. // 未超时,不处理
  215. }
  216. }
  217. if err := problemInfoService.UpdateProblemInfo(problemInfoNow); err != nil {
  218. global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
  219. response.FailWithMessage("更新失败", c)
  220. } else {
  221. response.OkWithMessage("更新成功", c)
  222. }
  223. }
  224. // FindProblemInfo 用id查询ProblemInfo
  225. // @Tags ProblemInfo
  226. // @Summary 用id查询ProblemInfo
  227. // @Security ApiKeyAuth
  228. // @accept application/json
  229. // @Produce application/json
  230. // @Param data query autocode.ProblemInfo true "用id查询ProblemInfo"
  231. // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
  232. // @Router /problemInfo/findProblemInfo [get]
  233. func (problemInfoApi *ProblemInfoApi) FindProblemInfo(c *gin.Context) {
  234. var problemInfo autocode.ProblemInfo
  235. _ = c.ShouldBindQuery(&problemInfo)
  236. if err, reproblemInfo := problemInfoService.GetProblemInfo(problemInfo.ID); err != nil {
  237. global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
  238. response.FailWithMessage("查询失败", c)
  239. } else {
  240. //param := reqMode.SysDictionarySearch{, request.PageInfo{PageSize: 9999, Page: 0}}
  241. _, reproblemInfo.MatterList, _ = service.ServiceGroupApp.AutoCodeServiceGroup.GetProblemTypeInfoListBySiteType(reproblemInfo.SiteType)
  242. response.OkWithData(gin.H{"reproblemInfo": reproblemInfo}, c)
  243. }
  244. }
  245. func (problemInfoApi *ProblemInfoApi) FindProblemPInfo(c *gin.Context) {
  246. var problemInfo autocode.ProblemInfo
  247. _ = c.ShouldBindQuery(&problemInfo)
  248. if err, reproblemInfo := problemInfoService.GetProblemInfo(problemInfo.ID); err != nil {
  249. global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
  250. response.FailWithMessage("查询失败", c)
  251. } else {
  252. userId := utils.GetUserID(c)
  253. //记录查看记录
  254. if err, readCount := service.ServiceGroupApp.AutoCodeServiceGroup.ReadCountService.GetReadCountByUserId(int(userId), int(problemInfo.ID)); err != nil {
  255. //新增
  256. service.ServiceGroupApp.AutoCodeServiceGroup.ReadCountService.CreateReadCount(autocode.ReadCount{ProblemId: problemInfo.ID, UserId: userId, UserName: utils.GetUserInfo(c).Username})
  257. } else {
  258. service.ServiceGroupApp.AutoCodeServiceGroup.ReadCountService.UpdateReadCountBy(readCount.ID)
  259. }
  260. //累加总阅读量
  261. problemInfoService.UpdateProblemInfoCount(problemInfo.ID)
  262. //param := reqMode.SysDictionarySearch{, request.PageInfo{PageSize: 9999, Page: 0}}
  263. _, reproblemInfo.MatterList, _ = service.ServiceGroupApp.AutoCodeServiceGroup.GetProblemTypeInfoListBySiteType(reproblemInfo.SiteType)
  264. response.OkWithData(gin.H{"reproblemInfo": reproblemInfo}, c)
  265. }
  266. }
  267. // GetProblemInfoList 分页获取ProblemInfo列表
  268. // @Tags ProblemInfo
  269. // @Summary 分页获取ProblemInfo列表
  270. // @Security ApiKeyAuth
  271. // @accept application/json
  272. // @Produce application/json
  273. // @Param data query autocodeReq.ProblemInfoSearch true "分页获取ProblemInfo列表"
  274. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  275. // @Router /problemInfo/getProblemInfoList [get]
  276. func (problemInfoApi *ProblemInfoApi) GetProblemInfoList(c *gin.Context) {
  277. var pageInfo autocodeReq.ProblemInfoSearch
  278. _ = c.ShouldBindQuery(&pageInfo)
  279. if err, list, total := problemInfoService.GetProblemInfoInfoList(pageInfo); err != nil {
  280. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  281. response.FailWithMessage("获取失败", c)
  282. } else {
  283. response.OkWithDetailed(response.PageResult{
  284. List: list,
  285. Total: total,
  286. Page: pageInfo.Page,
  287. PageSize: pageInfo.PageSize,
  288. }, "获取成功", c)
  289. }
  290. }