unit.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. package autocode
  2. import (
  3. "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/gin-gonic/gin"
  10. "go.uber.org/zap"
  11. )
  12. type UnitApi struct {
  13. }
  14. var unitService = service.ServiceGroupApp.AutoCodeServiceGroup.UnitService
  15. // CreateUnit 创建Unit
  16. // @Tags Unit
  17. // @Summary 创建Unit
  18. // @Security ApiKeyAuth
  19. // @accept application/json
  20. // @Produce application/json
  21. // @Param data body autocode.Unit true "创建Unit"
  22. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  23. // @Router /unit/createUnit [post]
  24. func (unitApi *UnitApi) CreateUnit(c *gin.Context) {
  25. var unit autocode.Unit
  26. _ = c.ShouldBindJSON(&unit)
  27. //if err, nowUnit := unitService.GetUnitTop(); err != nil {
  28. //新建期数
  29. //unit.Period = time.Now().Format("20060102150405")
  30. integral := 0
  31. unit.UnitIntegral = &integral
  32. unit.UnitMaxIntegral = &integral
  33. unitService.CreateUnit(unit)
  34. response.OkWithMessage("创建成功", c)
  35. //} else {
  36. // unit.UnitIntegral = nowUnit.UnitMaxIntegral
  37. // unit.UnitMaxIntegral = nowUnit.UnitMaxIntegral
  38. // unit.Period = nowUnit.Period
  39. // if err := unitService.CreateUnit(unit); err != nil {
  40. // global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
  41. // response.FailWithMessage("创建失败", c)
  42. // } else {
  43. // response.OkWithMessage("创建成功", c)
  44. // }
  45. //}
  46. }
  47. // DeleteUnit 删除Unit
  48. // @Tags Unit
  49. // @Summary 删除Unit
  50. // @Security ApiKeyAuth
  51. // @accept application/json
  52. // @Produce application/json
  53. // @Param data body autocode.Unit true "删除Unit"
  54. // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
  55. // @Router /unit/deleteUnit [delete]
  56. func (unitApi *UnitApi) DeleteUnit(c *gin.Context) {
  57. var unit autocode.Unit
  58. _ = c.ShouldBindJSON(&unit)
  59. if err := unitService.DeleteUnit(unit); err != nil {
  60. global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
  61. response.FailWithMessage("删除失败", c)
  62. } else {
  63. response.OkWithMessage("删除成功", c)
  64. }
  65. }
  66. // DeleteUnitByIds 批量删除Unit
  67. // @Tags Unit
  68. // @Summary 批量删除Unit
  69. // @Security ApiKeyAuth
  70. // @accept application/json
  71. // @Produce application/json
  72. // @Param data body request.IdsReq true "批量删除Unit"
  73. // @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
  74. // @Router /unit/deleteUnitByIds [delete]
  75. func (unitApi *UnitApi) DeleteUnitByIds(c *gin.Context) {
  76. var IDS request.IdsReq
  77. _ = c.ShouldBindJSON(&IDS)
  78. if err := unitService.DeleteUnitByIds(IDS); err != nil {
  79. global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err))
  80. response.FailWithMessage("批量删除失败", c)
  81. } else {
  82. response.OkWithMessage("批量删除成功", c)
  83. }
  84. }
  85. // UpdateUnit 更新Unit
  86. // @Tags Unit
  87. // @Summary 更新Unit
  88. // @Security ApiKeyAuth
  89. // @accept application/json
  90. // @Produce application/json
  91. // @Param data body autocode.Unit true "更新Unit"
  92. // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
  93. // @Router /unit/updateUnit [put]
  94. func (unitApi *UnitApi) UpdateUnit(c *gin.Context) {
  95. var unit autocode.Unit
  96. _ = c.ShouldBindJSON(&unit)
  97. if err := unitService.UpdateUnit(unit); err != nil {
  98. global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
  99. response.FailWithMessage("更新失败", c)
  100. } else {
  101. response.OkWithMessage("更新成功", c)
  102. }
  103. }
  104. func (unitApi *UnitApi) UpdateUnitIntergral(c *gin.Context) {
  105. unitService.UpdateUnitIntergral()
  106. response.OkWithMessage("更新成功", c)
  107. }
  108. func (unitApi *UnitApi) GetUnitIntergralRate(c *gin.Context) {
  109. remark, _ := c.GetQuery("remark")
  110. if err, list := unitService.GetUnitIntergralRate(remark); err != nil {
  111. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  112. response.FailWithMessage("获取失败", c)
  113. } else {
  114. response.OkWithDetailed(response.PageResult{
  115. List: list,
  116. }, "获取成功", c)
  117. }
  118. }
  119. func (unitApi *UnitApi) GetUnitDesc(c *gin.Context) {
  120. remark, _ := c.GetQuery("remark")
  121. if err, list := unitService.GetUnitDesc(remark); err != nil {
  122. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  123. response.FailWithMessage("获取失败", c)
  124. } else {
  125. response.OkWithDetailed(response.PageResult{
  126. List: list,
  127. }, "获取成功", c)
  128. }
  129. }
  130. // FindUnit 用id查询Unit
  131. // @Tags Unit
  132. // @Summary 用id查询Unit
  133. // @Security ApiKeyAuth
  134. // @accept application/json
  135. // @Produce application/json
  136. // @Param data query autocode.Unit true "用id查询Unit"
  137. // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
  138. // @Router /unit/findUnit [get]
  139. func (unitApi *UnitApi) FindUnit(c *gin.Context) {
  140. var unit autocode.Unit
  141. _ = c.ShouldBindQuery(&unit)
  142. if err, reunit := unitService.GetUnit(unit.ID); err != nil {
  143. global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
  144. response.FailWithMessage("查询失败", c)
  145. } else {
  146. response.OkWithData(gin.H{"reunit": reunit}, c)
  147. }
  148. }
  149. // GetUnitList 分页获取Unit列表
  150. // @Tags Unit
  151. // @Summary 分页获取Unit列表
  152. // @Security ApiKeyAuth
  153. // @accept application/json
  154. // @Produce application/json
  155. // @Param data query autocodeReq.UnitSearch true "分页获取Unit列表"
  156. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  157. // @Router /unit/getUnitList [get]
  158. func (unitApi *UnitApi) GetUnitList(c *gin.Context) {
  159. var pageInfo autocodeReq.UnitSearch
  160. _ = c.ShouldBindQuery(&pageInfo)
  161. if err, list, total := unitService.GetUnitInfoList(pageInfo); err != nil {
  162. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  163. response.FailWithMessage("获取失败", c)
  164. } else {
  165. response.OkWithDetailed(response.PageResult{
  166. List: list,
  167. Total: total,
  168. Page: pageInfo.Page,
  169. PageSize: pageInfo.PageSize,
  170. }, "获取成功", c)
  171. }
  172. }