log.go 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. package model
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "go-common/app/admin/main/aegis/model/net"
  6. )
  7. //..
  8. const (
  9. LogBusinessAudit = int(231)
  10. LogTypeAuditSubmit = int(1)
  11. LogTypeAuditJump = int(2)
  12. LogTypeAuditAdd = int(3)
  13. LogTypeAuditCancel = int(4)
  14. LogBusinessTask = int(232)
  15. LogTypeTaskDispatch = int(1)
  16. LogTypeTaskConsumer = int(2)
  17. LogTYpeTaskWeight = int(3)
  18. LogBusinessResource = int(233)
  19. LogTypeFormAuditor = int(1) // 审核员提交变更
  20. LogTypeFromAdd = int(2) // 业务添加资源
  21. LogTypeFromCancle = int(3) // 业务注销资源
  22. LogBusinessNet = int(234) //流程流转
  23. LogTypeNetTrigger = int(1) //流程流转
  24. LogFromBatch = "批量提交"
  25. LogFromSingle = "单个提交"
  26. LogFromStart = "启动"
  27. LogFromJump = "跳流程"
  28. LogFromCancle = "取消流程"
  29. LogBusinessNetConf = int(235) //流程配置
  30. LogTypeNetConf = int(1) //流程网配置
  31. LogTypeTokenConf = int(2) //令牌配置
  32. LogTypeFlowConf = int(3) //节点配置
  33. LogTypeTranConf = int(4) //变迁配置
  34. LogTypeTokenBindConf = int(5) //令牌绑定配置
  35. LogTypeDirConf = int(6) //有向线配置
  36. //流程配置的操作
  37. LogNetActionNew = "创建"
  38. LogNetActionUpdate = "更新"
  39. LogNetActionDisable = "禁用"
  40. LogNetActionAvailable = "启用"
  41. //流程配置的更新字段
  42. LogFieldPID = "pid"
  43. LogFieldChName = "ch_name"
  44. LogFieldName = "name"
  45. LogFieldTokenID = "token_id"
  46. LogFieldStartFlow = "start_flow"
  47. LogFieldTrigger = "trigger"
  48. LogFieldLimit = "limit"
  49. LogFieldDirection = "direction"
  50. LogFieldOrder = "order"
  51. LogFieldGuard = "guard"
  52. LogFieldOutput = "output"
  53. )
  54. //LogFieldDesc 日志中的变更字段描述
  55. var LogFieldDesc = map[string]string{
  56. LogFieldPID: "父网",
  57. LogFieldChName: "中文名",
  58. LogFieldName: "英文名",
  59. LogFieldTokenID: "令牌",
  60. LogFieldStartFlow: "初始节点",
  61. LogFieldTrigger: "触发类型",
  62. LogFieldLimit: "限制",
  63. LogFieldDirection: "指向",
  64. LogFieldOrder: "顺序",
  65. LogFieldGuard: "通行条件",
  66. LogFieldOutput: "输出规则",
  67. }
  68. //LogFieldTemp 指定模板和字段,组建变更日志字段
  69. func LogFieldTemp(field string, nw interface{}, old interface{}, diffTemp bool) (s string) {
  70. var (
  71. desc string
  72. exist bool
  73. temp string
  74. )
  75. if desc, exist = LogFieldDesc[field]; !exist {
  76. desc = field
  77. }
  78. if diffTemp {
  79. temp = "[%s]从[%v]变成[%v]"
  80. s = fmt.Sprintf(temp, desc, old, nw)
  81. } else {
  82. temp = "[%s]为[%v]"
  83. s = fmt.Sprintf(temp, desc, nw)
  84. }
  85. return
  86. }
  87. //NetConfOper 流程配置日志
  88. type NetConfOper struct {
  89. OID int64 `json:"oid"`
  90. Action string `json:"action"`
  91. UID int64 `json:"uid"`
  92. Uname string `json:"uname"`
  93. NetID int64 `json:"net_id"`
  94. ChName string `json:"ch_name"`
  95. FlowID int64 `json:"flow_id"`
  96. TranID int64 `json:"tran_id"`
  97. Diff []string `json:"diff"`
  98. }
  99. //SearchAuditLogParam 搜索行为日志参数
  100. type SearchAuditLogParam struct {
  101. RID []int64
  102. OID []string `form:"oid,split" validate:"omitempty,max=30,dive,gt=0"`
  103. Username []string `form:"username,split"`
  104. CtimeFrom string `form:"ctime_from"`
  105. CtimeTo string `form:"ctime_to"`
  106. Ps int `form:"ps" validate:"gt=0,max=50" default:"10"`
  107. Pn int `form:"pn" validate:"gt=0" default:"1"`
  108. TaskID []int64 `form:"task_id,split" validate:"omitempty,max=30"`
  109. State string `form:"state"`
  110. BusinessID int64 `form:"business_id" validate:"required,gt=0"`
  111. }
  112. //SearchAuditLog 审核日志记录
  113. type SearchAuditLog struct {
  114. RID int64 `json:"rid"`
  115. OID string `json:"oid"`
  116. TaskID int64 `json:"task_id"`
  117. State string `json:"state"`
  118. Stime string `json:"stime"`
  119. UID int64 `json:"uid"`
  120. Uname string `json:"uname"`
  121. Department string `json:"department"`
  122. Extra string `json:"extra"`
  123. }
  124. type SearchLogResult struct {
  125. Result []struct {
  126. UID int64 `json:"uid"`
  127. Uname string `json:"uname"`
  128. OID int64 `json:"oid"`
  129. Type int8 `json:"type"`
  130. Action string `json:"action"`
  131. Str0 string `json:"str_0"`
  132. Str1 string `json:"str_1"`
  133. Str2 string `json:"str_2"`
  134. Int0 int64 `json:"int_0"`
  135. Int1 int64 `json:"int_1"`
  136. Int2 int64 `json:"int_2"`
  137. Ctime string `json:"ctime"`
  138. Extra string `json:"extra_data"`
  139. } `json:"result"`
  140. Page struct {
  141. Num int `json:"num"`
  142. Size int `json:"size"`
  143. Total int `json:"total"`
  144. } `json:"page"`
  145. }
  146. // Change for log
  147. type Change struct {
  148. Opt *SubmitOptions `json:"opt"`
  149. Flow *Flow `json:"flow"`
  150. }
  151. //GetSubmitOper .
  152. func (change *Change) GetSubmitOper() (flowaction, submitopt string) {
  153. if change.Flow != nil && change.Flow.ResultToken != nil {
  154. flowaction = change.Flow.ResultToken.ChName
  155. }
  156. if change.Opt != nil {
  157. if change.Opt.Result != nil {
  158. if change.Opt.Result.ReasonID != 0 {
  159. submitopt += fmt.Sprintf(" 理由ID:%d ", change.Opt.Result.ReasonID)
  160. }
  161. if change.Opt.Result.RejectReason != "" && change.Opt.Result.RejectReason != "null" {
  162. submitopt += fmt.Sprintf(" 打回理由:%s ", change.Opt.Result.RejectReason)
  163. }
  164. if change.Opt.Result.Note != "" && change.Opt.Result.Note != "null" {
  165. submitopt += fmt.Sprintf(" 备注:%s ", change.Opt.Result.Note)
  166. }
  167. }
  168. if change.Opt.Forbid != nil {
  169. if change.Opt.Forbid.Reason != "" && change.Opt.Forbid.Reason != "null" {
  170. submitopt += fmt.Sprintf(" 封禁理由:%s ", change.Opt.Forbid.Reason)
  171. if du := change.Opt.Forbid.Duration; du == -1 {
  172. submitopt += " 封禁时长:永久 "
  173. } else {
  174. submitopt += fmt.Sprintf(" 封禁时长:%d天 ", du/86400)
  175. }
  176. }
  177. if change.Opt.Forbid.Comment != "" && change.Opt.Forbid.Comment != "null" {
  178. submitopt += fmt.Sprintf(" 备注:%s ", change.Opt.Forbid.Comment)
  179. }
  180. }
  181. }
  182. return
  183. }
  184. // Flow for log
  185. type Flow struct {
  186. SubmitToken *net.TokenPackage `json:"submit_token"`
  187. ResultToken *net.TokenPackage `json:"result_token"`
  188. NewFlowID int64 `json:"new_flow_id"`
  189. OldFlowID json.Number `json:"old_flow_id"`
  190. }
  191. // WeightLog task log
  192. type WeightLog struct {
  193. UPtime string `json:"uptime"`
  194. Mid int64 `json:"mid"`
  195. MemName string `json:"member_name"` // up主名称
  196. Fans int64 `json:"fans"`
  197. FansWeight int64 `json:"fans_weight"`
  198. Group string `json:"group"`
  199. GroupWeight int64 `json:"group_weight"`
  200. WaitTime string `json:"wait_time"`
  201. WaitWeight int64 `json:"wait_weight"`
  202. EqualWeight int64 `json:"config_weight"`
  203. ConfigItems []*ConfigItem `json:"config_items"`
  204. Weight int64 `json:"weight"`
  205. }
  206. // ConfigItem .
  207. type ConfigItem struct {
  208. Name string `json:"name"`
  209. Desc string `json:"desc"`
  210. Username string `json:"uname"`
  211. }
  212. //TrackRsc 资源信息追踪
  213. type TrackRsc struct {
  214. Ctime string `json:"ctime"`
  215. Content string `json:"content"`
  216. Detail map[string]interface{} `json:"detail"`
  217. }
  218. //TrackAudit 操作日志信息追踪
  219. type TrackAudit struct {
  220. Ctime string `json:"ctime"`
  221. FlowID []int64 `json:"flow_id"`
  222. FlowName string `json:"flow_name"`
  223. State string `json:"state"`
  224. Uname string `json:"uname"`
  225. }
  226. //TrackInfo 信息追踪汇总
  227. type TrackInfo struct {
  228. Add []*TrackRsc `json:"add"`
  229. Audit []*TrackAudit `json:"audit"`
  230. Relation [][]int `json:"relation"`
  231. }
  232. //TrackParam 信息追踪参数
  233. type TrackParam struct {
  234. BusinessID int64 `form:"business_id" validate:"required,gt=0"`
  235. OID string `form:"oid" validate:"required,gt=0"`
  236. Pn int `form:"pn" validate:"gt=0" default:"1"`
  237. Ps int `form:"ps" validate:"gt=0,max=30" default:"10"`
  238. LastPageTime string `form:"last_page_time"`
  239. }
  240. //ParamsQueryLog .
  241. type ParamsQueryLog struct {
  242. Business int `reflect:"business"`
  243. Type int `default:"0" reflect:"type,omitdefault"`
  244. Uname []string `reflect:"uname"`
  245. UID []int64 `reflect:"uid"`
  246. Oid []int64 `reflect:"oid"`
  247. Action []string `reflect:"action"`
  248. CtimeFrom string `reflect:"ctime,from"`
  249. CtimeTo string `reflect:"ctime,to"`
  250. Int0 []int64 `reflect:"int_0"`
  251. Int0From string `reflect:"int_0,from"`
  252. Int0To string `reflect:"int_0,to"`
  253. Int1 []int64 `reflect:"int_1"`
  254. Int1From string `reflect:"int_1,from"`
  255. Int1To string `reflect:"int_1,to"`
  256. Int2 []int64 `reflect:"int_2"`
  257. Int2From string `reflect:"int_2,from"`
  258. Int3To string `reflect:"int_2,to"`
  259. Str0 []string `reflect:"str_0"`
  260. Str1 []string `reflect:"str_1"`
  261. Str2 []string `reflect:"str_2"`
  262. }
  263. //EsCommon .
  264. type EsCommon struct {
  265. Pn int
  266. Ps int
  267. Order string
  268. Sort string
  269. Group string
  270. }