problem_info.go 13 KB

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