problem_info.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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: "创城办"},
  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/question?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().Unix() > problemInfoNow.HandAt.Unix() {
  231. //超时扣分
  232. probIds := strings.Split(problemInfoNow.Matter, "|")
  233. //问题关联的部门
  234. unitIds := strings.Split(problemInfoNow.Department, "|")
  235. if err, probTypes := problemTypeService.GetProblemTypeIds(probIds); err == nil {
  236. //扣部门分数
  237. for _, unitId := range unitIds {
  238. if unitId == "" {
  239. continue
  240. }
  241. integral := 0
  242. for _, probType := range probTypes {
  243. if strings.Index(probType.UnitIds, unitId) != -1 {
  244. integral = integral + *probType.Integral
  245. }
  246. }
  247. if integral != 0 {
  248. id, _ := strconv.Atoi(unitId)
  249. global.GVA_LOG.Error("id!", zap.Any("unitId", unitId), zap.Any("id", id))
  250. _, unit := unitService.GetUnit(uint(id))
  251. oldIntegral := *unit.UnitIntegral
  252. nowIntegral := oldIntegral + integral
  253. unit.UnitIntegral = &nowIntegral
  254. unitService.UpdateUnitA(unit)
  255. }
  256. }
  257. }
  258. } else {
  259. temp := 0
  260. problemInfo.Integral = &temp
  261. // 未超时,不处理
  262. }
  263. }
  264. if err := problemInfoService.UpdateProblemInfo(problemInfoNow); err != nil {
  265. global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
  266. response.FailWithMessage("更新失败", c)
  267. } else {
  268. response.OkWithMessage("更新成功", c)
  269. }
  270. }
  271. // FindProblemInfo 用id查询ProblemInfo
  272. // @Tags ProblemInfo
  273. // @Summary 用id查询ProblemInfo
  274. // @Security ApiKeyAuth
  275. // @accept application/json
  276. // @Produce application/json
  277. // @Param data query autocode.ProblemInfo true "用id查询ProblemInfo"
  278. // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
  279. // @Router /problemInfo/findProblemInfo [get]
  280. func (problemInfoApi *ProblemInfoApi) FindProblemInfo(c *gin.Context) {
  281. var problemInfo autocode.ProblemInfo
  282. _ = c.ShouldBindQuery(&problemInfo)
  283. if err, reproblemInfo := problemInfoService.GetProblemInfo(problemInfo.ID); err != nil {
  284. global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
  285. response.FailWithMessage("查询失败", c)
  286. } else {
  287. //param := reqMode.SysDictionarySearch{, request.PageInfo{PageSize: 9999, Page: 0}}
  288. _, reproblemInfo.MatterList, _ = service.ServiceGroupApp.AutoCodeServiceGroup.GetProblemTypeInfoListBySiteType(reproblemInfo.SiteType)
  289. response.OkWithData(gin.H{"reproblemInfo": reproblemInfo}, c)
  290. }
  291. }
  292. func (problemInfoApi *ProblemInfoApi) FindProblemPInfo(c *gin.Context) {
  293. var problemInfo autocode.ProblemInfo
  294. _ = c.ShouldBindQuery(&problemInfo)
  295. if err, reproblemInfo := problemInfoService.GetProblemInfo(problemInfo.ID); err != nil {
  296. global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
  297. response.FailWithMessage("查询失败", c)
  298. } else {
  299. userId := utils.GetUserID(c)
  300. //记录查看记录
  301. if err, readCount := service.ServiceGroupApp.AutoCodeServiceGroup.ReadCountService.GetReadCountByUserId(int(userId), int(problemInfo.ID)); err != nil {
  302. //新增
  303. service.ServiceGroupApp.AutoCodeServiceGroup.ReadCountService.CreateReadCount(autocode.ReadCount{ProblemId: problemInfo.ID, UserId: userId, UserName: utils.GetUserInfo(c).Username})
  304. } else {
  305. service.ServiceGroupApp.AutoCodeServiceGroup.ReadCountService.UpdateReadCountBy(readCount.ID)
  306. }
  307. //累加总阅读量
  308. problemInfoService.UpdateProblemInfoCount(problemInfo.ID)
  309. //param := reqMode.SysDictionarySearch{, request.PageInfo{PageSize: 9999, Page: 0}}
  310. _, reproblemInfo.MatterList, _ = service.ServiceGroupApp.AutoCodeServiceGroup.GetProblemTypeInfoListBySiteType(reproblemInfo.SiteType)
  311. response.OkWithData(gin.H{"reproblemInfo": reproblemInfo}, c)
  312. }
  313. }
  314. // GetProblemInfoList 分页获取ProblemInfo列表
  315. // @Tags ProblemInfo
  316. // @Summary 分页获取ProblemInfo列表
  317. // @Security ApiKeyAuth
  318. // @accept application/json
  319. // @Produce application/json
  320. // @Param data query autocodeReq.ProblemInfoSearch true "分页获取ProblemInfo列表"
  321. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  322. // @Router /problemInfo/getProblemInfoList [get]
  323. func (problemInfoApi *ProblemInfoApi) GetProblemInfoList(c *gin.Context) {
  324. var pageInfo autocodeReq.ProblemInfoSearch
  325. _ = c.ShouldBindQuery(&pageInfo)
  326. if err, list, total := problemInfoService.GetProblemInfoInfoList(pageInfo); err != nil {
  327. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  328. response.FailWithMessage("获取失败", c)
  329. } else {
  330. response.OkWithDetailed(response.PageResult{
  331. List: list,
  332. Total: total,
  333. Page: pageInfo.Page,
  334. PageSize: pageInfo.PageSize,
  335. }, "获取成功", c)
  336. }
  337. }