sys_sign_config.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package system
  2. import (
  3. "fmt"
  4. "github.com/gin-gonic/gin"
  5. "go_server/model/common/response"
  6. "go_server/model/system"
  7. "go_server/service/base"
  8. )
  9. type SignService struct {
  10. base.SysCommonService
  11. }
  12. func (s *SignService) Find(c *gin.Context) {
  13. db := s.DB()
  14. items, err := base.GetMore[system.SysSignConfig](db)
  15. if err != nil {
  16. response.Resp(c, err.Error())
  17. return
  18. }
  19. type SignInfo struct {
  20. ID int64 `json:"id" gorm:"primarykey;comment:id"`
  21. IsSystemSign bool `json:"isSystemSign" gorm:"comment:'是否本系统密钥信息'"`
  22. SignName string `json:"signName" gorm:"type:varchar(45);unique;comment:'签名系统名称-前缀:FOMO-PRO'"`
  23. SignAddress string `json:"signAddress" gorm:"type:varchar(42);comment:'系统地址'"`
  24. SignExpSec int64 `json:"signExpSec" gorm:"comment:'超时时间S'"`
  25. SysUrl string `json:"sysUrl" gorm:"type:varchar(512);comment:外部系统请求链接"`
  26. }
  27. list := make([]*SignInfo, 0)
  28. for _, item := range items {
  29. list = append(list, &SignInfo{
  30. ID: item.ID,
  31. IsSystemSign: item.IsSystemSign,
  32. SignName: item.SignName,
  33. SignAddress: item.SignAddress,
  34. SignExpSec: item.SignExpSec,
  35. SysUrl: item.SysUrl,
  36. })
  37. }
  38. response.Resp(c, map[string]interface{}{
  39. "list": list,
  40. })
  41. }
  42. func (s *SignService) Set(c *gin.Context) {
  43. // 限制用户增加必须管理员才可以操作
  44. userId := c.GetInt64("userId")
  45. if userId != system.AdminId {
  46. response.Resp(c, "不允许操作")
  47. return
  48. }
  49. type request struct {
  50. Id interface{} `json:"id"`
  51. SignName string `json:"signName" gorm:"type:varchar(45);unique;comment:'签名系统名称-前缀:FOMO-PRO'"`
  52. SignAddress string `json:"signAddress" gorm:"type:varchar(42);comment:'系统地址'"`
  53. SignExpSec int64 `json:"signExpSec" gorm:"comment:'超时时间S'"`
  54. SysUrl string `json:"sysUrl" gorm:"type:varchar(512);comment:外部系统请求链接"`
  55. }
  56. req := new(request)
  57. if err := c.BindJSON(req); err != nil {
  58. response.Resp(c, err.Error())
  59. return
  60. }
  61. row, ok := base.GetOne[system.SysSignConfig](s.DB(), "id", req.Id)
  62. if !ok {
  63. response.Resp(c, fmt.Sprintf("配置ID:%d不存在", req.Id))
  64. return
  65. }
  66. if row.IsSystemSign {
  67. response.Resp(c, fmt.Sprintf("本系统地址不允许修改"))
  68. return
  69. }
  70. row.SignAddress = req.SignAddress
  71. row.SignExpSec = req.SignExpSec
  72. row.SysUrl = req.SysUrl
  73. if err := s.DB().Save(&row).Error; err != nil {
  74. response.Resp(c, fmt.Sprintf("修改失败:%s", err.Error()))
  75. return
  76. }
  77. response.Resp(c, nil)
  78. }