info.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. package blocked
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "strconv"
  6. "go-common/app/admin/main/credit/model"
  7. "go-common/library/log"
  8. xtime "go-common/library/time"
  9. )
  10. // const info
  11. const (
  12. // info publish_status
  13. StatusClose = int8(0) // 案件关闭状态
  14. StatusOpen = int8(1) // 案件公开状态
  15. // info block_type
  16. PunishBlock = 0 // 系统封禁
  17. PunishJury = 1 // 风纪仲裁
  18. // punish type.
  19. PunishTypeMoral = int8(1) // 节操
  20. PunishTypeBlockTime = int8(2) // 封禁
  21. PunishTypeBlockForever = int8(3) // 永久封禁
  22. // info status.
  23. BlockStateOpen = int8(0) // 未解禁
  24. BlockStateClose = int8(1) // 已解禁
  25. )
  26. // var info
  27. var (
  28. PStatusDesc = map[int8]string{
  29. StatusClose: "不公开",
  30. StatusOpen: "公开",
  31. }
  32. BTypeDesc = map[int8]string{
  33. PunishBlock: "系统封禁",
  34. PunishJury: "风纪仲裁",
  35. }
  36. )
  37. // Info is blocked_info model.
  38. type Info struct {
  39. ID int64 `gorm:"column:id" json:"id"`
  40. UID int64 `gorm:"column:uid" json:"uid"`
  41. UName string `gorm:"column:uname" json:"uname"`
  42. Status int8 `gorm:"column:status" json:"status"`
  43. OriginTitle string `gorm:"column:origin_title" json:"origin_title"`
  44. OriginURL string `gorm:"column:origin_url" json:"origin_url"`
  45. OriginContent string `gorm:"column:origin_content" json:"origin_content"`
  46. OriginContentModify string `gorm:"column:origin_content_modify" json:"origin_content_modify"`
  47. OriginType int8 `gorm:"column:origin_type" json:"origin_type"`
  48. BlockedDays int `gorm:"column:blocked_days" json:"blocked_days"`
  49. BlockedForever int8 `gorm:"column:blocked_forever" json:"blocked_forever"`
  50. BlockedType int8 `gorm:"column:blocked_type" json:"blocked_type"`
  51. BlockedRemark string `gorm:"column:blocked_remark" json:"blocked_remark"`
  52. CaseID int64 `gorm:"column:case_id" json:"case_id"`
  53. MoralNum int `gorm:"column:moral_num" json:"moral_num"`
  54. ReasonType int8 `gorm:"column:reason_type" json:"reason_type"`
  55. PublishStatus int8 `gorm:"column:publish_status" json:"publish_status"`
  56. PunishType int8 `gorm:"column:punish_type" json:"punish_type"`
  57. PunishTime xtime.Time `gorm:"column:punish_time" json:"punish_time"`
  58. PublishTime xtime.Time `gorm:"column:publish_time" json:"publish_time"`
  59. OperID int64 `gorm:"column:oper_id" json:"oper_id"`
  60. CTime xtime.Time `gorm:"column:ctime" json:"ctime"`
  61. MTime xtime.Time `gorm:"column:mtime" json:"mtime"`
  62. PublishStatusDesc string `gorm:"-" json:"publish_status_desc"`
  63. OriginTypeDesc string `gorm:"-" json:"origin_type_desc"`
  64. BlockedTypeDesc string `gorm:"-" json:"blocked_type_desc"`
  65. BlockedDaysDesc string `gorm:"-" json:"blocked_days_desc"`
  66. ReasonTypeDesc string `gorm:"-" json:"reason_type_desc"`
  67. OPName string `gorm:"-" json:"oname"`
  68. OOPName string `gorm:"column:operator_name" json:"-"`
  69. }
  70. // InfoList is info list.
  71. type InfoList struct {
  72. IDs []int64
  73. List []*Info
  74. }
  75. // InfoDesc is Info_desc model.
  76. type InfoDesc struct {
  77. ID string `json:"id"`
  78. PunishTime string `json:"punish_time"`
  79. OriginTypeDesc string `json:"origin_type_desc"`
  80. ReasonTypeDesc string `json:"reason_type_desc"`
  81. PublishStatusDesc string `json:"publish_status_desc"`
  82. BlockedTypeDesc string `json:"blocked_type_desc"`
  83. OriginContent string `json:"origin_content"`
  84. BlockedDaysDesc string `json:"blocked_days_desc"`
  85. UName string `json:"uname"`
  86. UID string `json:"uid"`
  87. OPName string `json:"oname"`
  88. }
  89. // TableName Info tablename
  90. func (*Info) TableName() string {
  91. return "blocked_info"
  92. }
  93. // DealInfo deal with info data.
  94. func DealInfo(infos []*Info) (data [][]string, err error) {
  95. var infoDescs []*InfoDesc
  96. for _, v := range infos {
  97. infoDesc := &InfoDesc{
  98. ID: strconv.FormatInt(v.ID, 10),
  99. PunishTime: v.PunishTime.Time().Format(model.TimeFormatSec),
  100. OriginTypeDesc: v.OriginTypeDesc,
  101. PublishStatusDesc: v.PublishStatusDesc,
  102. BlockedTypeDesc: v.BlockedTypeDesc,
  103. ReasonTypeDesc: v.ReasonTypeDesc,
  104. OriginContent: v.OriginContent,
  105. BlockedDaysDesc: v.BlockedDaysDesc,
  106. UName: v.UName,
  107. UID: strconv.FormatInt(v.UID, 10),
  108. OPName: v.OPName,
  109. }
  110. infoDescs = append(infoDescs, infoDesc)
  111. }
  112. infoMap, _ := json.Marshal(infoDescs)
  113. var objmap []map[string]string
  114. if err = json.Unmarshal(infoMap, &objmap); err != nil {
  115. log.Error("Unmarshal(%s) error(%v)", string(infoMap), err)
  116. return
  117. }
  118. data = append(data, []string{"ID", "惩罚时间", "类型", "状态", "封禁类型", "理由类型", "原文概要", "处罚结果", "用户", "用户ID", "操作者"})
  119. for _, v := range objmap {
  120. var fields []string
  121. fields = append(fields, v["id"])
  122. fields = append(fields, v["punish_time"])
  123. fields = append(fields, v["origin_type_desc"])
  124. fields = append(fields, v["publish_status_desc"])
  125. fields = append(fields, v["blocked_type_desc"])
  126. fields = append(fields, v["reason_type_desc"])
  127. fields = append(fields, v["origin_content"])
  128. fields = append(fields, v["blocked_days_desc"])
  129. fields = append(fields, v["uname"])
  130. fields = append(fields, v["uid"])
  131. fields = append(fields, v["oname"])
  132. data = append(data, fields)
  133. }
  134. return
  135. }
  136. // BDaysDesc is blocked_days_desc.
  137. func BDaysDesc(bDays, moralNum int, pType, bForever int8) string {
  138. switch {
  139. case pType == PunishTypeMoral:
  140. return fmt.Sprintf(blockedDesc[BlockMoralNum], moralNum)
  141. case bDays == BlockForever && bForever == OnBlockedForever:
  142. return blockedDesc[BlockForever]
  143. case pType == PunishTypeBlockTime:
  144. if bDays == BlockThree || bDays == BlockSeven || bDays == BlockFifteen {
  145. return blockedDesc[bDays]
  146. }
  147. return strconv.Itoa(bDays) + blockedDesc[BlockCustom]
  148. }
  149. return ""
  150. }