run_model.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. // ==========================================================================
  2. // This is auto-generated by gf cli tool. You may not really want to edit it.
  3. // ==========================================================================
  4. package wf_run
  5. import (
  6. "database/sql"
  7. "github.com/gogf/gf/database/gdb"
  8. "github.com/gogf/gf/frame/g"
  9. "github.com/gogf/gf/frame/gmvc"
  10. "time"
  11. )
  12. // arModel is a active record design model for table wf_run operations.
  13. type arModel struct {
  14. gmvc.M
  15. }
  16. var (
  17. // Table is the table name of wf_run.
  18. Table = "wf_run"
  19. // Model is the model object of wf_run.
  20. Model = &arModel{g.DB("default").Table(Table).Safe()}
  21. // Columns defines and stores column names for table wf_run.
  22. Columns = struct {
  23. Id string //
  24. Pid string // work_run父流转公文ID 值大于0则这个是子流程,完成后或者要返回父流程
  25. FromTable string // 单据表,不带前缀
  26. FromId string //
  27. FromTitle string //业务表审批状态字段
  28. FromStatus string //业务表审批状态字段
  29. PidFlowStep string // 父pid的flow_id中的第几步骤进入的,取回这个work_flow_step的child_over决定结束子流程的动作
  30. CacheRunId string // 多个子流程时pid无法识别cache所以加这个字段pid>0
  31. Uid string //
  32. FlowId string // 流程id 正常流程
  33. CatId string // 流程分类ID即公文分类ID
  34. RunName string // 公文名称
  35. RunFlowId string // 流转到什么流程 最新流程,查询优化,进入子流程时将简化查询,子流程与父流程同步
  36. RunFlowProcess string // 流转到第几步
  37. AttIds string // 公文附件ids
  38. Endtime string // 结束时间
  39. Status string // 状态,0流程中,1通过,2回退
  40. IsDel string //
  41. Updatetime string //
  42. Dateline string //
  43. IsSing string //
  44. SingId string //
  45. }{
  46. Id: "id",
  47. Pid: "pid",
  48. FromTable: "from_table",
  49. FromId: "from_id",
  50. FromTitle: "from_title",
  51. FromStatus: "from_status",
  52. PidFlowStep: "pid_flow_step",
  53. CacheRunId: "cache_run_id",
  54. Uid: "uid",
  55. FlowId: "flow_id",
  56. CatId: "cat_id",
  57. RunName: "run_name",
  58. RunFlowId: "run_flow_id",
  59. RunFlowProcess: "run_flow_process",
  60. AttIds: "att_ids",
  61. Endtime: "endtime",
  62. Status: "status",
  63. IsDel: "is_del",
  64. Updatetime: "updatetime",
  65. Dateline: "dateline",
  66. IsSing: "is_sing",
  67. SingId: "sing_id",
  68. }
  69. )
  70. // FindOne is a convenience method for Model.FindOne.
  71. // See Model.FindOne.
  72. func FindOne(where ...interface{}) (*Entity, error) {
  73. return Model.FindOne(where...)
  74. }
  75. // FindAll is a convenience method for Model.FindAll.
  76. // See Model.FindAll.
  77. func FindAll(where ...interface{}) ([]*Entity, error) {
  78. return Model.FindAll(where...)
  79. }
  80. // FindValue is a convenience method for Model.FindValue.
  81. // See Model.FindValue.
  82. func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
  83. return Model.FindValue(fieldsAndWhere...)
  84. }
  85. // FindArray is a convenience method for Model.FindArray.
  86. // See Model.FindArray.
  87. func FindArray(fieldsAndWhere ...interface{}) ([]gdb.Value, error) {
  88. return Model.FindArray(fieldsAndWhere...)
  89. }
  90. // FindCount is a convenience method for Model.FindCount.
  91. // See Model.FindCount.
  92. func FindCount(where ...interface{}) (int, error) {
  93. return Model.FindCount(where...)
  94. }
  95. // Insert is a convenience method for Model.Insert.
  96. func Insert(data ...interface{}) (result sql.Result, err error) {
  97. return Model.Insert(data...)
  98. }
  99. // InsertIgnore is a convenience method for Model.InsertIgnore.
  100. func InsertIgnore(data ...interface{}) (result sql.Result, err error) {
  101. return Model.InsertIgnore(data...)
  102. }
  103. // Replace is a convenience method for Model.Replace.
  104. func Replace(data ...interface{}) (result sql.Result, err error) {
  105. return Model.Replace(data...)
  106. }
  107. // Save is a convenience method for Model.Save.
  108. func Save(data ...interface{}) (result sql.Result, err error) {
  109. return Model.Save(data...)
  110. }
  111. // Update is a convenience method for Model.Update.
  112. func Update(dataAndWhere ...interface{}) (result sql.Result, err error) {
  113. return Model.Update(dataAndWhere...)
  114. }
  115. // Delete is a convenience method for Model.Delete.
  116. func Delete(where ...interface{}) (result sql.Result, err error) {
  117. return Model.Delete(where...)
  118. }
  119. // As sets an alias name for current table.
  120. func (m *arModel) As(as string) *arModel {
  121. return &arModel{m.M.As(as)}
  122. }
  123. // TX sets the transaction for current operation.
  124. func (m *arModel) TX(tx *gdb.TX) *arModel {
  125. return &arModel{m.M.TX(tx)}
  126. }
  127. // Master marks the following operation on master node.
  128. func (m *arModel) Master() *arModel {
  129. return &arModel{m.M.Master()}
  130. }
  131. // Slave marks the following operation on slave node.
  132. // Note that it makes sense only if there's any slave node configured.
  133. func (m *arModel) Slave() *arModel {
  134. return &arModel{m.M.Slave()}
  135. }
  136. // LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
  137. // The parameter <table> can be joined table and its joined condition,
  138. // and also with its alias name, like:
  139. // Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
  140. // Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
  141. func (m *arModel) LeftJoin(table ...string) *arModel {
  142. return &arModel{m.M.LeftJoin(table...)}
  143. }
  144. // RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
  145. // The parameter <table> can be joined table and its joined condition,
  146. // and also with its alias name, like:
  147. // Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
  148. // Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
  149. func (m *arModel) RightJoin(table ...string) *arModel {
  150. return &arModel{m.M.RightJoin(table...)}
  151. }
  152. // InnerJoin does "INNER JOIN ... ON ..." statement on the model.
  153. // The parameter <table> can be joined table and its joined condition,
  154. // and also with its alias name, like:
  155. // Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
  156. // Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
  157. func (m *arModel) InnerJoin(table ...string) *arModel {
  158. return &arModel{m.M.InnerJoin(table...)}
  159. }
  160. // Fields sets the operation fields of the model, multiple fields joined using char ','.
  161. func (m *arModel) Fields(fields string) *arModel {
  162. return &arModel{m.M.Fields(fields)}
  163. }
  164. // FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
  165. func (m *arModel) FieldsEx(fields string) *arModel {
  166. return &arModel{m.M.FieldsEx(fields)}
  167. }
  168. // Option sets the extra operation option for the model.
  169. func (m *arModel) Option(option int) *arModel {
  170. return &arModel{m.M.Option(option)}
  171. }
  172. // OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
  173. // the data and where attributes for empty values.
  174. func (m *arModel) OmitEmpty() *arModel {
  175. return &arModel{m.M.OmitEmpty()}
  176. }
  177. // Filter marks filtering the fields which does not exist in the fields of the operated table.
  178. func (m *arModel) Filter() *arModel {
  179. return &arModel{m.M.Filter()}
  180. }
  181. // Where sets the condition statement for the model. The parameter <where> can be type of
  182. // string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
  183. // multiple conditions will be joined into where statement using "AND".
  184. // Eg:
  185. // Where("uid=10000")
  186. // Where("uid", 10000)
  187. // Where("money>? AND name like ?", 99999, "vip_%")
  188. // Where("uid", 1).Where("name", "john")
  189. // Where("status IN (?)", g.Slice{1,2,3})
  190. // Where("age IN(?,?)", 18, 50)
  191. // Where(User{ Id : 1, UserName : "john"})
  192. func (m *arModel) Where(where interface{}, args ...interface{}) *arModel {
  193. return &arModel{m.M.Where(where, args...)}
  194. }
  195. // And adds "AND" condition to the where statement.
  196. func (m *arModel) And(where interface{}, args ...interface{}) *arModel {
  197. return &arModel{m.M.And(where, args...)}
  198. }
  199. // Or adds "OR" condition to the where statement.
  200. func (m *arModel) Or(where interface{}, args ...interface{}) *arModel {
  201. return &arModel{m.M.Or(where, args...)}
  202. }
  203. // Group sets the "GROUP BY" statement for the model.
  204. func (m *arModel) Group(groupBy string) *arModel {
  205. return &arModel{m.M.Group(groupBy)}
  206. }
  207. // Order sets the "ORDER BY" statement for the model.
  208. func (m *arModel) Order(orderBy ...string) *arModel {
  209. return &arModel{m.M.Order(orderBy...)}
  210. }
  211. // Limit sets the "LIMIT" statement for the model.
  212. // The parameter <limit> can be either one or two number, if passed two number is passed,
  213. // it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
  214. // statement.
  215. func (m *arModel) Limit(limit ...int) *arModel {
  216. return &arModel{m.M.Limit(limit...)}
  217. }
  218. // Offset sets the "OFFSET" statement for the model.
  219. // It only makes sense for some databases like SQLServer, PostgreSQL, etc.
  220. func (m *arModel) Offset(offset int) *arModel {
  221. return &arModel{m.M.Offset(offset)}
  222. }
  223. // Page sets the paging number for the model.
  224. // The parameter <page> is started from 1 for paging.
  225. // Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
  226. func (m *arModel) Page(page, limit int) *arModel {
  227. return &arModel{m.M.Page(page, limit)}
  228. }
  229. // Batch sets the batch operation number for the model.
  230. func (m *arModel) Batch(batch int) *arModel {
  231. return &arModel{m.M.Batch(batch)}
  232. }
  233. // Cache sets the cache feature for the model. It caches the result of the sql, which means
  234. // if there's another same sql request, it just reads and returns the result from cache, it
  235. // but not committed and executed into the database.
  236. //
  237. // If the parameter <duration> < 0, which means it clear the cache with given <name>.
  238. // If the parameter <duration> = 0, which means it never expires.
  239. // If the parameter <duration> > 0, which means it expires after <duration>.
  240. //
  241. // The optional parameter <name> is used to bind a name to the cache, which means you can later
  242. // control the cache like changing the <duration> or clearing the cache with specified <name>.
  243. //
  244. // Note that, the cache feature is disabled if the model is operating on a transaction.
  245. func (m *arModel) Cache(duration time.Duration, name ...string) *arModel {
  246. return &arModel{m.M.Cache(duration, name...)}
  247. }
  248. // Data sets the operation data for the model.
  249. // The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
  250. // Eg:
  251. // Data("uid=10000")
  252. // Data("uid", 10000)
  253. // Data(g.Map{"uid": 10000, "name":"john"})
  254. // Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
  255. func (m *arModel) Data(data ...interface{}) *arModel {
  256. return &arModel{m.M.Data(data...)}
  257. }
  258. // All does "SELECT FROM ..." statement for the model.
  259. // It retrieves the records from table and returns the result as []*Entity.
  260. // It returns nil if there's no record retrieved with the given conditions from table.
  261. //
  262. // The optional parameter <where> is the same as the parameter of Model.Where function,
  263. // see Model.Where.
  264. func (m *arModel) All(where ...interface{}) ([]*Entity, error) {
  265. all, err := m.M.All(where...)
  266. if err != nil {
  267. return nil, err
  268. }
  269. var entities []*Entity
  270. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  271. return nil, err
  272. }
  273. return entities, nil
  274. }
  275. // One retrieves one record from table and returns the result as *Entity.
  276. // It returns nil if there's no record retrieved with the given conditions from table.
  277. //
  278. // The optional parameter <where> is the same as the parameter of Model.Where function,
  279. // see Model.Where.
  280. func (m *arModel) One(where ...interface{}) (*Entity, error) {
  281. one, err := m.M.One(where...)
  282. if err != nil {
  283. return nil, err
  284. }
  285. var entity *Entity
  286. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  287. return nil, err
  288. }
  289. return entity, nil
  290. }
  291. // FindOne retrieves and returns a single Record by Model.WherePri and Model.One.
  292. // Also see Model.WherePri and Model.One.
  293. func (m *arModel) FindOne(where ...interface{}) (*Entity, error) {
  294. one, err := m.M.FindOne(where...)
  295. if err != nil {
  296. return nil, err
  297. }
  298. var entity *Entity
  299. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  300. return nil, err
  301. }
  302. return entity, nil
  303. }
  304. // FindAll retrieves and returns Result by by Model.WherePri and Model.All.
  305. // Also see Model.WherePri and Model.All.
  306. func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) {
  307. all, err := m.M.FindAll(where...)
  308. if err != nil {
  309. return nil, err
  310. }
  311. var entities []*Entity
  312. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  313. return nil, err
  314. }
  315. return entities, nil
  316. }
  317. // Chunk iterates the table with given size and callback function.
  318. func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) {
  319. m.M.Chunk(limit, func(result gdb.Result, err error) bool {
  320. var entities []*Entity
  321. err = result.Structs(&entities)
  322. if err == sql.ErrNoRows {
  323. return false
  324. }
  325. return callback(entities, err)
  326. })
  327. }
  328. // LockUpdate sets the lock for update for current operation.
  329. func (m *arModel) LockUpdate() *arModel {
  330. return &arModel{m.M.LockUpdate()}
  331. }
  332. // LockShared sets the lock in share mode for current operation.
  333. func (m *arModel) LockShared() *arModel {
  334. return &arModel{m.M.LockShared()}
  335. }
  336. // Unscoped enables/disables the soft deleting feature.
  337. func (m *arModel) Unscoped() *arModel {
  338. return &arModel{m.M.Unscoped()}
  339. }