eta_version_update_log.go 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hz_crm_api/models"
  7. "hongze/hz_crm_api/utils"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. // EtaVersionUpdateLogController ETA版本更新日志
  13. type EtaVersionUpdateLogController struct {
  14. BaseAuthController
  15. }
  16. // PageList
  17. // @Title 更新日志列表-分页
  18. // @Description 更新日志列表-分页
  19. // @Param Keyword query string false "关键词"
  20. // @Param SortType query string false "排序方式, 1-ASC; 2-DESC"
  21. // @Success 200 Ret=200 获取成功
  22. // @router /page_list [get]
  23. func (this *EtaVersionUpdateLogController) PageList() {
  24. br := new(models.BaseResponse).Init()
  25. defer func() {
  26. if br.ErrMsg == "" {
  27. br.IsSendEmail = false
  28. }
  29. this.Data["json"] = br
  30. this.ServeJSON()
  31. }()
  32. sysUser := this.SysUser
  33. if sysUser == nil {
  34. br.Msg = "请登录"
  35. br.ErrMsg = "请登录,SysUser Is Empty"
  36. br.Ret = 408
  37. return
  38. }
  39. // 分页
  40. pageSize, _ := this.GetInt("PageSize")
  41. currentIndex, _ := this.GetInt("CurrentIndex")
  42. var startSize int
  43. if pageSize <= 0 {
  44. pageSize = utils.PageSize20
  45. }
  46. if currentIndex <= 0 {
  47. currentIndex = 1
  48. }
  49. startSize = utils.StartIndex(currentIndex, pageSize)
  50. cond := ``
  51. pars := make([]interface{}, 0)
  52. // 关键词
  53. keyword := this.GetString("Keyword", "")
  54. keyword = strings.TrimSpace(keyword)
  55. if keyword != "" {
  56. kw := fmt.Sprint("%", keyword, "%")
  57. cond += ` AND content LIKE ?`
  58. pars = append(pars, kw)
  59. }
  60. sortType, _ := this.GetInt("SortType", 0)
  61. orderMap := map[int]string{0: "", 1: "update_date ASC", 2: "update_date DESC"}
  62. order := orderMap[sortType]
  63. // 获取列表
  64. businessOb := new(models.EtaVersionUpdateLog)
  65. total, e := businessOb.GetCountByCondition(cond, pars)
  66. if e != nil {
  67. br.Msg = "获取失败"
  68. br.ErrMsg = "获取更新日志总数失败, Err: " + e.Error()
  69. return
  70. }
  71. list, e := businessOb.GetPageItemsByCondition(cond, pars, []string{}, order, startSize, pageSize)
  72. if e != nil {
  73. br.Msg = "获取失败"
  74. br.ErrMsg = "获取更新日志列表失败, Err: " + e.Error()
  75. return
  76. }
  77. items := make([]*models.EtaVersionUpdateLogItem, 0)
  78. for _, v := range list {
  79. b := new(models.EtaVersionUpdateLogItem)
  80. b.Id = v.Id
  81. b.Version = v.Version
  82. b.Content = v.Content
  83. b.UpdateDate = v.UpdateDate.Format(utils.FormatDate)
  84. b.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
  85. b.ModifyTime = v.ModifyTime.Format(utils.FormatDateTime)
  86. items = append(items, b)
  87. }
  88. resp := new(models.EtaVersionUpdateLogListResp)
  89. resp.List = items
  90. resp.Paging = paging.GetPaging(currentIndex, pageSize, total)
  91. br.Data = resp
  92. br.Ret = 200
  93. br.Success = true
  94. br.Msg = "获取成功"
  95. }
  96. // Add
  97. // @Title 新增
  98. // @Description 新增
  99. // @Param request body models.EtaVersionUpdateLogAddReq true "type json string"
  100. // @Success 200 Ret=200 操作成功
  101. // @router /add [post]
  102. func (this *EtaVersionUpdateLogController) Add() {
  103. br := new(models.BaseResponse).Init()
  104. defer func() {
  105. if br.ErrMsg == "" {
  106. br.IsSendEmail = false
  107. }
  108. this.Data["json"] = br
  109. this.ServeJSON()
  110. }()
  111. sysUser := this.SysUser
  112. if sysUser == nil {
  113. br.Msg = "请登录"
  114. br.ErrMsg = "请登录,SysUser Is Empty"
  115. br.Ret = 408
  116. return
  117. }
  118. // 参数校验
  119. var req models.EtaVersionUpdateLogAddReq
  120. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  121. br.Msg = "参数解析异常!"
  122. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  123. return
  124. }
  125. req.Version = strings.TrimSpace(req.Version)
  126. if req.Version == "" {
  127. br.Msg = "版本号不可为空"
  128. return
  129. }
  130. // 版本号格式: X.X.X
  131. versionArr := strings.Split(req.Version, ".")
  132. if len(versionArr) != 3 {
  133. br.Msg = "请输入正确格式的版本号"
  134. return
  135. }
  136. for _, n := range versionArr {
  137. if _, e := strconv.Atoi(n); e != nil {
  138. br.Msg = "请输入正确格式的版本号"
  139. return
  140. }
  141. }
  142. req.Content = strings.TrimSpace(req.Content)
  143. if req.Content == "" {
  144. br.Msg = "更新内容不可为空"
  145. return
  146. }
  147. updateDate, e := time.ParseInLocation(utils.FormatDate, req.UpdateDate, time.Local)
  148. if e != nil {
  149. br.Msg = "更新日期格式有误"
  150. br.ErrMsg = "更新日期格式有误, Err: " + e.Error()
  151. return
  152. }
  153. // 版本号重复校验
  154. {
  155. item := new(models.EtaVersionUpdateLog)
  156. cond := ` AND version = ?`
  157. pars := make([]interface{}, 0)
  158. pars = append(pars, req.Version)
  159. exist, e := item.GetItemByCondition(cond, pars)
  160. if e != nil && e.Error() != utils.ErrNoRow() {
  161. br.Msg = "操作失败"
  162. br.ErrMsg = "获取更新日志重复版本号失败, Err: " + e.Error()
  163. return
  164. }
  165. if exist != nil {
  166. br.Msg = "该版本号已有更新日志, 请重新输入"
  167. return
  168. }
  169. }
  170. // 更新日期重复校验
  171. {
  172. item := new(models.EtaVersionUpdateLog)
  173. cond := ` AND update_date = ?`
  174. pars := make([]interface{}, 0)
  175. pars = append(pars, req.UpdateDate)
  176. exist, e := item.GetItemByCondition(cond, pars)
  177. if e != nil && e.Error() != utils.ErrNoRow() {
  178. br.Msg = "操作失败"
  179. br.ErrMsg = "获取更新日志重复日期失败, Err: " + e.Error()
  180. return
  181. }
  182. if exist != nil {
  183. br.Msg = "该日期已有更新日志, 请重新选择"
  184. return
  185. }
  186. }
  187. // 新增
  188. item := new(models.EtaVersionUpdateLog)
  189. item.Version = req.Version
  190. item.UpdateDate = updateDate
  191. item.Content = req.Content
  192. item.CreateTime = time.Now().Local()
  193. item.ModifyTime = time.Now().Local()
  194. if e = item.Create(); e != nil {
  195. br.Msg = "操作失败"
  196. br.ErrMsg = "新增更新日志失败, Err: " + e.Error()
  197. return
  198. }
  199. br.Ret = 200
  200. br.Success = true
  201. br.Msg = "操作成功"
  202. }
  203. // Edit
  204. // @Title 编辑
  205. // @Description 编辑
  206. // @Param request body models.EtaVersionUpdateLogEditReq true "type json string"
  207. // @Success 200 Ret=200 操作成功
  208. // @router /edit [post]
  209. func (this *EtaVersionUpdateLogController) Edit() {
  210. br := new(models.BaseResponse).Init()
  211. defer func() {
  212. if br.ErrMsg == "" {
  213. br.IsSendEmail = false
  214. }
  215. this.Data["json"] = br
  216. this.ServeJSON()
  217. }()
  218. sysUser := this.SysUser
  219. if sysUser == nil {
  220. br.Msg = "请登录"
  221. br.ErrMsg = "请登录,SysUser Is Empty"
  222. br.Ret = 408
  223. return
  224. }
  225. // 参数校验
  226. var req models.EtaVersionUpdateLogEditReq
  227. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  228. br.Msg = "参数解析异常!"
  229. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  230. return
  231. }
  232. if req.Id <= 0 {
  233. br.Msg = "参数有误"
  234. return
  235. }
  236. req.Version = strings.TrimSpace(req.Version)
  237. if req.Version == "" {
  238. br.Msg = "版本号不可为空"
  239. return
  240. }
  241. // 版本号格式: X.X.X
  242. versionArr := strings.Split(req.Version, ".")
  243. if len(versionArr) != 3 {
  244. br.Msg = "请输入正确格式的版本号"
  245. return
  246. }
  247. for _, n := range versionArr {
  248. if _, e := strconv.Atoi(n); e != nil {
  249. br.Msg = "请输入正确格式的版本号"
  250. return
  251. }
  252. }
  253. req.Content = strings.TrimSpace(req.Content)
  254. if req.Content == "" {
  255. br.Msg = "更新内容不可为空"
  256. return
  257. }
  258. updateDate, e := time.ParseInLocation(utils.FormatDate, req.UpdateDate, time.Local)
  259. if e != nil {
  260. br.Msg = "更新日期格式有误"
  261. br.ErrMsg = "更新日期格式有误, Err: " + e.Error()
  262. return
  263. }
  264. // 版本号重复校验
  265. {
  266. item := new(models.EtaVersionUpdateLog)
  267. cond := ` AND version = ?`
  268. pars := make([]interface{}, 0)
  269. pars = append(pars, req.Version)
  270. exist, e := item.GetItemByCondition(cond, pars)
  271. if e != nil && e.Error() != utils.ErrNoRow() {
  272. br.Msg = "操作失败"
  273. br.ErrMsg = "获取更新日志重复版本号失败, Err: " + e.Error()
  274. return
  275. }
  276. if exist != nil && exist.Id != req.Id {
  277. br.Msg = "该版本号已有更新日志, 请重新输入"
  278. return
  279. }
  280. }
  281. // 更新日期重复校验
  282. {
  283. item := new(models.EtaVersionUpdateLog)
  284. cond := ` AND update_date = ?`
  285. pars := make([]interface{}, 0)
  286. pars = append(pars, req.UpdateDate)
  287. exist, e := item.GetItemByCondition(cond, pars)
  288. if e != nil && e.Error() != utils.ErrNoRow() {
  289. br.Msg = "操作失败"
  290. br.ErrMsg = "获取更新日志重复日期失败, Err: " + e.Error()
  291. return
  292. }
  293. if exist != nil && exist.Id != req.Id {
  294. br.Msg = "该日期已有更新日志, 请重新选择"
  295. return
  296. }
  297. }
  298. ob := new(models.EtaVersionUpdateLog)
  299. item, e := ob.GetItemById(req.Id)
  300. if e != nil {
  301. if e.Error() == utils.ErrNoRow() {
  302. br.Msg = "更新日志不存在, 请刷新页面"
  303. return
  304. }
  305. br.Msg = "操作失败"
  306. br.ErrMsg = "获取更新日志信息失败, Err: " + e.Error()
  307. return
  308. }
  309. item.Version = req.Version
  310. item.Content = req.Content
  311. item.UpdateDate = updateDate
  312. item.ModifyTime = time.Now().Local()
  313. cols := []string{"Version", "Content", "UpdateDate", "ModifyTime"}
  314. if e := item.Update(cols); e != nil {
  315. br.Msg = "操作失败"
  316. br.ErrMsg = "编辑更新日志失败, Err: " + e.Error()
  317. return
  318. }
  319. br.Ret = 200
  320. br.Success = true
  321. br.Msg = "操作成功"
  322. }
  323. // Del
  324. // @Title 删除
  325. // @Description 删除
  326. // @Param request body models.EtaVersionUpdateLogDelReq true "type json string"
  327. // @Success 200 Ret=200 操作成功
  328. // @router /del [post]
  329. func (this *EtaVersionUpdateLogController) Del() {
  330. br := new(models.BaseResponse).Init()
  331. defer func() {
  332. if br.ErrMsg == "" {
  333. br.IsSendEmail = false
  334. }
  335. this.Data["json"] = br
  336. this.ServeJSON()
  337. }()
  338. sysUser := this.SysUser
  339. if sysUser == nil {
  340. br.Msg = "请登录"
  341. br.ErrMsg = "请登录,SysUser Is Empty"
  342. br.Ret = 408
  343. return
  344. }
  345. // 参数校验
  346. var req models.EtaVersionUpdateLogDelReq
  347. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  348. br.Msg = "参数解析异常!"
  349. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  350. return
  351. }
  352. if req.Id <= 0 {
  353. br.Msg = "参数有误"
  354. return
  355. }
  356. ob := new(models.EtaVersionUpdateLog)
  357. item, e := ob.GetItemById(req.Id)
  358. if e != nil {
  359. if e.Error() == utils.ErrNoRow() {
  360. br.Msg = "更新日志不存在, 请刷新页面"
  361. return
  362. }
  363. br.Msg = "操作失败"
  364. br.ErrMsg = "获取更新日志信息失败, Err: " + e.Error()
  365. return
  366. }
  367. if e := item.Del(); e != nil {
  368. br.Msg = "操作失败"
  369. br.ErrMsg = "删除更新日志失败, Err: " + e.Error()
  370. return
  371. }
  372. br.Ret = 200
  373. br.Success = true
  374. br.Msg = "操作成功"
  375. }