problem_info.go 14 KB

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