engine.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. package model
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "reflect"
  6. "go-common/app/admin/main/aegis/model/common"
  7. "go-common/app/admin/main/aegis/model/net"
  8. "go-common/app/admin/main/aegis/model/resource"
  9. "go-common/app/admin/main/aegis/model/task"
  10. member "go-common/app/service/main/account/api"
  11. "go-common/library/log"
  12. )
  13. const (
  14. // DefaultZeroInt form default zero
  15. DefaultZeroInt = int64(-12345)
  16. )
  17. // EngineOption .
  18. type EngineOption struct {
  19. common.BaseOptions
  20. TaskID int64 `json:"task_id" form:"task_id"`
  21. Result *resource.Result `json:"resource_result" form:"resource_result" submit:"object"` // 资源的修改内容,要传就全传,否则传空
  22. Forbid *Forbid `json:"forbid_params" submit:"json"`
  23. ExtraData map[string]interface{} `json:"extra_data" submit:"map"`
  24. }
  25. // Forbid 封禁参数
  26. type Forbid struct {
  27. Notify int `json:"notify"`
  28. Reason string `json:"reason"`
  29. Duration int64 `json:"duration"`
  30. Comment string `json:"comment"`
  31. Img string `json:"img"`
  32. }
  33. // InfoResOption .
  34. type InfoResOption struct {
  35. common.BaseOptions
  36. }
  37. // ListResOption .
  38. type ListResOption struct {
  39. common.Pager
  40. common.BaseOptions
  41. BusinessID int64 `form:"business_id"`
  42. FlowID int64 `form:"flow_id"`
  43. }
  44. // SubmitOptions 审核结果提交参数
  45. type SubmitOptions struct {
  46. EngineOption
  47. NewFlowID int64 `json:"newflow_id"`
  48. BindStr string `json:"binds"`
  49. Binds []int64 `json:"-"`
  50. }
  51. // BatchOption 批量提交
  52. type BatchOption struct {
  53. BusinessID int64 `form:"business_id" json:"business_id" validate:"required"`
  54. NetID int64 `form:"net_id" json:"net_id"`
  55. UID int64 `form:"uid" json:"uid"`
  56. Debug int8 `form:"debug" json:"debug"`
  57. Uname string `form:"uname" json:"uname"`
  58. RIDs []int64 `form:"rids,split" json:"rids" validate:"gt=0,dive,gt=0"`
  59. Binds []int64 `form:"binds,split" json:"binds" validate:"gt=0,dive,gt=0"`
  60. RejectReason string `form:"reject_reason"`
  61. ReasonID int64 `form:"reason_id" default:"0"`
  62. Notify int8 `form:"notify"`
  63. }
  64. // Tip 批量提交的错误提示
  65. type Tip struct {
  66. Success []int64 `json:"success"`
  67. Async []int64 `json:"async"`
  68. Fail map[int64]string `json:"fail"`
  69. }
  70. // AddOption add option
  71. type AddOption struct {
  72. resource.Resource
  73. State int `form:"state" json:"state"`
  74. NetID int64 `form:"net_id" json:"net_id" validate:"required"`
  75. }
  76. // UpdateKeys 可更新的资源字段
  77. var UpdateKeys = map[string]struct{}{
  78. "mid": {},
  79. "content": {},
  80. "extra1": {},
  81. "extra2": {},
  82. "extra3": {},
  83. "extra4": {},
  84. "extra5": {},
  85. "extra6": {},
  86. "extra1s": {},
  87. "extra2s": {},
  88. "extra3s": {},
  89. "extra4s": {},
  90. "extratime1": {},
  91. "octime": {},
  92. "ptime": {},
  93. "metadata": {},
  94. }
  95. // UpdateOption update option
  96. type UpdateOption struct {
  97. BusinessID int64 `form:"business_id" json:"business_id" validate:"required"`
  98. NetID int64 `form:"net_id" json:"net_id" validate:"required"`
  99. OID string `form:"oid" json:"oid" validate:"required"`
  100. Update map[string]interface{} `json:"update"`
  101. }
  102. // AuditInfo 审核详情页
  103. type AuditInfo struct {
  104. UnDoStat *task.UnDOStat `json:"undo_stat"`
  105. Task *task.Task `json:"task"`
  106. Flow *net.TransitionInfo `json:"flow"`
  107. Resource *resource.Res `json:"resource"`
  108. OperHistorys []string `json:"historys"`
  109. IFrame string `json:"iframe_url,omitempty"`
  110. UserInfo *UserInfo `json:"user_info"`
  111. UserGroup map[int64]*common.Group `json:"user_group"`
  112. Hit []string `json:"hit"`
  113. Actions []*Action `json:"actions"`
  114. }
  115. // UserInfo .
  116. type UserInfo struct {
  117. Mid int64 `json:"mid"`
  118. Name string `json:"name"`
  119. Official member.OfficialInfo `json:"official"`
  120. Follower int64 `json:"follower"`
  121. }
  122. // SyncMessage .
  123. type SyncMessage struct {
  124. URL string
  125. Uname string `json:"auditor"`
  126. MID int64 `json:"uid"`
  127. OID string `json:"oid"`
  128. RejectReason string `json:"reason"`
  129. FlowData map[string]interface{} `json:"flow_data"`
  130. ExtraData map[string]interface{} `json:"extra_data"`
  131. ForbidParams map[string]interface{} `json:"forbid_params"`
  132. Attribute map[string]int8 `json:"attribute"`
  133. }
  134. // GetEmptyInfo empty info for debug
  135. func GetEmptyInfo() *AuditInfo {
  136. info := &AuditInfo{
  137. UnDoStat: &task.UnDOStat{},
  138. Task: &task.Task{},
  139. Flow: &net.TransitionInfo{
  140. Operations: []*net.TranOperation{{}},
  141. },
  142. UserInfo: &UserInfo{},
  143. Resource: &resource.Res{},
  144. OperHistorys: []string{
  145. "wulalalal",
  146. },
  147. IFrame: "iframe",
  148. }
  149. return info
  150. }
  151. // SearchParams ..
  152. type SearchParams struct {
  153. common.Pager
  154. Debug int8 `form:"debug" reflect:"ignore"`
  155. FilterOff bool `form:"state_filter_off" reflect:"ignore"`
  156. BusinessID int64 `form:"business_id" validate:"required" reflect:"business_id"`
  157. OID []string `form:"oid,split" reflect:"oid"`
  158. FlowID int64 `form:"flow_id" default:"-12345" reflect:"flow_id,omitdefault"`
  159. State int64 `form:"state" default:"-12345" reflect:"state,omitdefault"`
  160. Mid int64 `form:"mid" default:"-12345" reflect:"mid,omitdefault"`
  161. CtimeFrom string `form:"ctime_from" reflect:"ctime,from"`
  162. CtimeTo string `form:"ctime_to" reflect:"ctime,to"`
  163. Extra1 string `form:"extra1" reflect:"extra1" parse:"[]int"`
  164. Extra2 string `form:"extra2" reflect:"extra2" parse:"int"`
  165. Extra3 string `form:"extra3" reflect:"extra3" parse:"int"`
  166. Extra4 string `form:"extra4" reflect:"extra4" parse:"int"`
  167. Extra5 string `form:"extra4" reflect:"extra5" parse:"int"`
  168. Extra6 string `form:"extra4" reflect:"extra6" parse:"int"`
  169. Extra1s string `form:"extra1s" reflect:"extra1s" `
  170. Extra2s string `form:"extra2s" reflect:"extra2s" `
  171. Extra3s string `form:"extra3s" reflect:"extra3s" `
  172. Extra4s string `form:"extra4s" reflect:"extra4s" `
  173. ExtraTime1 string `form:"extratime1" reflect:"extratime1" ` //TODO 具体用到了再看怎么解析
  174. KeyWord string `form:"keyWords" reflect:"ignore"`
  175. CtimeOrder string `form:"ctime_order" reflect:"ignore"` //TODO 等octime导入后要按照octime筛选
  176. }
  177. // SearchRes search list.
  178. type SearchRes struct {
  179. Resources []*ListRscItem `json:"result"`
  180. Page struct {
  181. Num int `json:"num"`
  182. Size int `json:"size"`
  183. Total int `json:"total"`
  184. } `json:"page"`
  185. }
  186. //Column .
  187. type Column struct {
  188. Name string `json:"name"`
  189. ChName string `json:"chname"`
  190. Enum map[int64]string `json:"enum,omitempty"`
  191. }
  192. // ListRscItem .
  193. type ListRscItem struct {
  194. resource.Res
  195. FlowID int64 `json:"flow_id"`
  196. UserInfo *UserInfo `json:"user_info"`
  197. UserGroup map[int64]*common.Group `json:"user_group"`
  198. Hit []string `json:"hit"`
  199. }
  200. // ListTaskItem .
  201. type ListTaskItem struct {
  202. ListTask
  203. WaitTime string `json:"wait_time"`
  204. OID string `json:"oid"`
  205. Content string `json:"content"`
  206. UserInfo *UserInfo `json:"user_info"`
  207. UserGroup map[int64]*common.Group `json:"user_group"`
  208. Metas map[string]interface{} `json:"metas"`
  209. }
  210. // ListTask 转化gtime
  211. type ListTask struct {
  212. *task.Task
  213. GTstr string `json:"gtime"`
  214. CTstr string `json:"ctime"`
  215. MTstr string `json:"mtime"`
  216. UserName string `json:"uid"`
  217. MidStr string `json:"mid"`
  218. }
  219. // EmptyListItem .
  220. func EmptyListItem() *ListRscItem {
  221. return &ListRscItem{
  222. UserInfo: &UserInfo{},
  223. }
  224. }
  225. // IsImgType file type is image
  226. func IsImgType(fileType string) bool {
  227. return fileType != "image/jpeg" && fileType != "image/png" && fileType != "image/webp"
  228. }
  229. //Action 下发到前端的组件
  230. type Action struct {
  231. Name string `json:"name"`
  232. URL string `json:"url"`
  233. Method string `json:"method"`
  234. Response string `json:"response"`
  235. Extra string `json:"extra,omitempty"`
  236. Params map[string]*ActionParam `json:"params"`
  237. }
  238. //ActionParam 烦人啊,动态的打回理由是必传参数
  239. type ActionParam struct {
  240. Value string `json:"value"`
  241. Default string `json:"default"`
  242. }
  243. //SubReflect .
  244. func SubReflect(ot reflect.Type, ov reflect.Value, key string, vals []string, defaultval string, params map[string]interface{}) {
  245. var result string
  246. boommsg := fmt.Sprintf("key:%s vals:%v ot:%+v vt:%+v", key, vals, ot, reflect.TypeOf(ov).Kind())
  247. if len(vals) == 0 {
  248. return
  249. }
  250. val := vals[0]
  251. tfield, ok := ot.FieldByName(val)
  252. if !ok {
  253. log.Error("SubReflect1:" + boommsg)
  254. return
  255. }
  256. vfield := ov.FieldByName(val)
  257. if !vfield.IsValid() {
  258. log.Error("SubReflect7:" + boommsg)
  259. return
  260. }
  261. switch tfield.Tag.Get("submit") {
  262. case "object":
  263. vals = vals[1:]
  264. tt := tfield.Type
  265. vv := reflect.ValueOf(vfield)
  266. if tfield.Type.Kind() == reflect.Ptr {
  267. tt = tfield.Type.Elem()
  268. vv = vfield.Elem()
  269. }
  270. SubReflect(tt, vv, key, vals, defaultval, params)
  271. return
  272. case "map":
  273. if len(vals) != 2 || tfield.Type.Kind() != reflect.Map {
  274. log.Error("SubReflect2:" + boommsg)
  275. }
  276. v := vfield.MapIndex(reflect.ValueOf(vals[1]))
  277. if !v.IsValid() { //批量操作,可能会没有map的参数
  278. log.Warn("SubReflect4:" + boommsg)
  279. return
  280. }
  281. result = fmt.Sprint(v.Interface())
  282. case "json":
  283. bs, err := json.Marshal(vfield.Interface())
  284. if err != nil {
  285. log.Error("SubReflect5:" + boommsg)
  286. return
  287. }
  288. result = string(bs)
  289. case "int", "string":
  290. result = fmt.Sprint(vfield.Interface())
  291. default:
  292. log.Error("SubReflect6:" + boommsg)
  293. }
  294. if result == "" {
  295. result = defaultval
  296. }
  297. params[key] = result
  298. }
  299. //Auth auth
  300. type Auth struct {
  301. OK bool `json:"ok"`
  302. Admin bool `json:"admin"`
  303. Business map[int64]int64 `json:"business"`
  304. }
  305. //UpsertItem 更新搜索的items
  306. type UpsertItem struct {
  307. ID int64 `json:"id"`
  308. State int `json:"state"`
  309. Extra1 int64 `json:"extra1"`
  310. Extra2 int64 `json:"extra2"`
  311. Extra3 int64 `json:"extra3"`
  312. Extra4 int64 `json:"extra4"`
  313. }
  314. //CancelOption .
  315. type CancelOption struct {
  316. BusinessID int64 `form:"business_id" validate:"required" json:"business_id"`
  317. Oids []string `form:"oids,split" validate:"required" json:"oids"`
  318. Reason string `form:"reason" json:"reason"`
  319. }