ctr_contract_share.go 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  1. // ==========================================================================
  2. // This is auto-generated by gf cli tool. DO NOT EDIT THIS FILE MANUALLY.
  3. // ==========================================================================
  4. package internal
  5. import (
  6. "context"
  7. "database/sql"
  8. "fmt"
  9. "github.com/gogf/gf/container/garray"
  10. "github.com/gogf/gf/database/gdb"
  11. "github.com/gogf/gf/frame/g"
  12. "github.com/gogf/gf/frame/gmvc"
  13. "github.com/gogf/gf/util/gconv"
  14. "strings"
  15. "time"
  16. model "dashoo.cn/micro/app/model/contract"
  17. )
  18. // CtrContractShareDao is the manager for logic model data accessing and custom defined data operations functions management.
  19. type CtrContractShareDao struct {
  20. gmvc.M // M is the core and embedded struct that inherits all chaining operations from gdb.Model.
  21. C ctrContractShareColumns // C is the short type for Columns, which contains all the column names of Table for convenient usage.
  22. DB gdb.DB // DB is the raw underlying database management object.
  23. Table string // Table is the underlying table name of the DAO.
  24. TableAs string // TableAs is the underlying table alias name of the DAO.
  25. }
  26. // CtrContractShareColumns defines and stores column names for table ctr_contract_share.
  27. type ctrContractShareColumns struct {
  28. Id string // 主键
  29. ContractId string // 关联合同
  30. ContractCode string // 合同编号
  31. ContractAmount string // 合同金额
  32. ContractSignTime string // 合同签订时间(提高统计效率,此处没有连表查询)
  33. SaleId string // 归属销售
  34. SaleName string // 销售姓名
  35. ShareRatio string // 销售分成比例
  36. ShareAmount string // 销售分成金额
  37. Remark string // 备注
  38. CreatedBy string // 创建者
  39. CreatedName string // 创建人
  40. CreatedTime string // 创建时间
  41. UpdatedBy string // 更新者
  42. UpdatedName string // 更新人
  43. UpdatedTime string // 更新时间
  44. DeletedTime string // 删除时间
  45. }
  46. var (
  47. // CtrContractShare is globally public accessible object for table ctr_contract_share operations.
  48. CtrContractShare = CtrContractShareDao{
  49. M: g.DB("default").Model("ctr_contract_share").Safe(),
  50. DB: g.DB("default"),
  51. Table: "ctr_contract_share",
  52. C: ctrContractShareColumns{
  53. Id: "id",
  54. ContractId: "contract_id",
  55. ContractCode: "contract_code",
  56. ContractAmount: "contract_amount",
  57. ContractSignTime: "contract_sign_time",
  58. SaleId: "sale_id",
  59. SaleName: "sale_name",
  60. ShareRatio: "share_ratio",
  61. ShareAmount: "share_amount",
  62. Remark: "remark",
  63. CreatedBy: "created_by",
  64. CreatedName: "created_name",
  65. CreatedTime: "created_time",
  66. UpdatedBy: "updated_by",
  67. UpdatedName: "updated_name",
  68. UpdatedTime: "updated_time",
  69. DeletedTime: "deleted_time",
  70. },
  71. }
  72. )
  73. func NewCtrContractShareDao(tenant string) CtrContractShareDao {
  74. var dao CtrContractShareDao
  75. dao = CtrContractShareDao{
  76. M: g.DB(tenant).Model("ctr_contract_share").Safe(),
  77. DB: g.DB(tenant),
  78. Table: "ctr_contract_share",
  79. C: ctrContractShareColumns{
  80. Id: "id",
  81. ContractId: "contract_id",
  82. ContractCode: "contract_code",
  83. ContractAmount: "contract_amount",
  84. ContractSignTime: "contract_sign_time",
  85. SaleId: "sale_id",
  86. SaleName: "sale_name",
  87. ShareRatio: "share_ratio",
  88. ShareAmount: "share_amount",
  89. Remark: "remark",
  90. CreatedBy: "created_by",
  91. CreatedName: "created_name",
  92. CreatedTime: "created_time",
  93. UpdatedBy: "updated_by",
  94. UpdatedName: "updated_name",
  95. UpdatedTime: "updated_time",
  96. DeletedTime: "deleted_time",
  97. },
  98. }
  99. return dao
  100. }
  101. // Ctx is a chaining function, which creates and returns a new DB that is a shallow copy
  102. // of current DB object and with given context in it.
  103. // Note that this returned DB object can be used only once, so do not assign it to
  104. // a global or package variable for long using.
  105. func (d *CtrContractShareDao) Ctx(ctx context.Context) *CtrContractShareDao {
  106. return &CtrContractShareDao{M: d.M.Ctx(ctx), Table: d.Table, TableAs: d.TableAs}
  107. }
  108. // GetCtx returns the context for current Model.
  109. // It returns "context.Background() i"s there's no context previously set.
  110. func (d *CtrContractShareDao) GetCtx() context.Context {
  111. return d.M.GetCtx()
  112. }
  113. // As sets an alias name for current table.
  114. func (d *CtrContractShareDao) As(as string) *CtrContractShareDao {
  115. return &CtrContractShareDao{M: d.M.As(as), Table: d.Table, TableAs: as}
  116. }
  117. // TX sets the transaction for current operation.
  118. func (d *CtrContractShareDao) TX(tx *gdb.TX) *CtrContractShareDao {
  119. return &CtrContractShareDao{M: d.M.TX(tx), Table: d.Table, TableAs: d.TableAs}
  120. }
  121. // Master marks the following operation on master node.
  122. func (d *CtrContractShareDao) Master() *CtrContractShareDao {
  123. return &CtrContractShareDao{M: d.M.Master(), Table: d.Table, TableAs: d.TableAs}
  124. }
  125. // Slave marks the following operation on slave node.
  126. // Note that it makes sense only if there's any slave node configured.
  127. func (d *CtrContractShareDao) Slave() *CtrContractShareDao {
  128. return &CtrContractShareDao{M: d.M.Slave(), Table: d.Table, TableAs: d.TableAs}
  129. }
  130. // Args sets custom arguments for model operation.
  131. func (d *CtrContractShareDao) Args(args ...interface{}) *CtrContractShareDao {
  132. return &CtrContractShareDao{M: d.M.Args(args...), Table: d.Table, TableAs: d.TableAs}
  133. }
  134. // Handler calls each of "handlers" on current Model and returns a new Model.
  135. // ModelHandler is a function that handles given Model and returns a new Model that is custom modified.
  136. func (d *CtrContractShareDao) Handler(handlers ...gdb.ModelHandler) *CtrContractShareDao {
  137. return &CtrContractShareDao{M: d.M.Handler(handlers...), Table: d.Table, TableAs: d.TableAs}
  138. }
  139. // LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
  140. // The parameter <table> can be joined table and its joined condition,
  141. // and also with its alias name, like:
  142. // Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
  143. // Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
  144. func (d *CtrContractShareDao) LeftJoin(table ...string) *CtrContractShareDao {
  145. return &CtrContractShareDao{M: d.M.LeftJoin(table...), Table: d.Table, TableAs: d.TableAs}
  146. }
  147. // RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
  148. // The parameter <table> can be joined table and its joined condition,
  149. // and also with its alias name, like:
  150. // Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
  151. // Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
  152. func (d *CtrContractShareDao) RightJoin(table ...string) *CtrContractShareDao {
  153. return &CtrContractShareDao{M: d.M.RightJoin(table...), Table: d.Table, TableAs: d.TableAs}
  154. }
  155. // InnerJoin does "INNER JOIN ... ON ..." statement on the model.
  156. // The parameter <table> can be joined table and its joined condition,
  157. // and also with its alias name, like:
  158. // Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
  159. // Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
  160. func (d *CtrContractShareDao) InnerJoin(table ...string) *CtrContractShareDao {
  161. return &CtrContractShareDao{M: d.M.InnerJoin(table...), Table: d.Table, TableAs: d.TableAs}
  162. }
  163. // Fields sets the operation fields of the model, multiple fields joined using char ','.
  164. // The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
  165. func (d *CtrContractShareDao) Fields(fieldNamesOrMapStruct ...interface{}) *CtrContractShareDao {
  166. return &CtrContractShareDao{M: d.M.Fields(fieldNamesOrMapStruct...), Table: d.Table, TableAs: d.TableAs}
  167. }
  168. // FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
  169. // The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
  170. func (d *CtrContractShareDao) FieldsEx(fieldNamesOrMapStruct ...interface{}) *CtrContractShareDao {
  171. return &CtrContractShareDao{M: d.M.FieldsEx(fieldNamesOrMapStruct...), Table: d.Table, TableAs: d.TableAs}
  172. }
  173. // FieldCount formats and appends commonly used field "COUNT(column)" to the select fields of model.
  174. func (d *CtrContractShareDao) FieldCount(column string, as ...string) *CtrContractShareDao {
  175. return &CtrContractShareDao{M: d.M.FieldCount(column, as...), Table: d.Table, TableAs: d.TableAs}
  176. }
  177. // FieldSum formats and appends commonly used field "SUM(column)" to the select fields of model.
  178. func (d *CtrContractShareDao) FieldSum(column string, as ...string) *CtrContractShareDao {
  179. return &CtrContractShareDao{M: d.M.FieldSum(column, as...), Table: d.Table, TableAs: d.TableAs}
  180. }
  181. // FieldMin formats and appends commonly used field "MIN(column)" to the select fields of model.
  182. func (d *CtrContractShareDao) FieldMin(column string, as ...string) *CtrContractShareDao {
  183. return &CtrContractShareDao{M: d.M.FieldMin(column, as...), Table: d.Table, TableAs: d.TableAs}
  184. }
  185. // FieldMax formats and appends commonly used field "MAX(column)" to the select fields of model.
  186. func (d *CtrContractShareDao) FieldMax(column string, as ...string) *CtrContractShareDao {
  187. return &CtrContractShareDao{M: d.M.FieldMax(column, as...), Table: d.Table, TableAs: d.TableAs}
  188. }
  189. // FieldAvg formats and appends commonly used field "AVG(column)" to the select fields of model.
  190. func (d *CtrContractShareDao) FieldAvg(column string, as ...string) *CtrContractShareDao {
  191. return &CtrContractShareDao{M: d.M.FieldAvg(column, as...), Table: d.Table, TableAs: d.TableAs}
  192. }
  193. // Option adds extra operation option for the model.
  194. // Deprecated, use separate operations instead.
  195. func (d *CtrContractShareDao) Option(option int) *CtrContractShareDao {
  196. return &CtrContractShareDao{M: d.M.Option(option), Table: d.Table, TableAs: d.TableAs}
  197. }
  198. // OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
  199. // the data and where attributes for empty values.
  200. func (d *CtrContractShareDao) OmitEmpty() *CtrContractShareDao {
  201. return &CtrContractShareDao{M: d.M.OmitEmpty(), Table: d.Table, TableAs: d.TableAs}
  202. }
  203. // OmitEmptyWhere sets optionOmitEmptyWhere option for the model, which automatically filers
  204. // the Where/Having parameters for "empty" values.
  205. func (d *CtrContractShareDao) OmitEmptyWhere() *CtrContractShareDao {
  206. return &CtrContractShareDao{M: d.M.OmitEmptyWhere(), Table: d.Table, TableAs: d.TableAs}
  207. }
  208. // OmitEmptyData sets optionOmitEmptyData option for the model, which automatically filers
  209. // the Data parameters for "empty" values.
  210. func (d *CtrContractShareDao) OmitEmptyData() *CtrContractShareDao {
  211. return &CtrContractShareDao{M: d.M.OmitEmptyData(), Table: d.Table, TableAs: d.TableAs}
  212. }
  213. // OmitNil sets optionOmitNil option for the model, which automatically filers
  214. // the data and where parameters for "nil" values.
  215. func (d *CtrContractShareDao) OmitNil() *CtrContractShareDao {
  216. return &CtrContractShareDao{M: d.M.OmitNil(), Table: d.Table, TableAs: d.TableAs}
  217. }
  218. // OmitNilWhere sets optionOmitNilWhere option for the model, which automatically filers
  219. // the Where/Having parameters for "nil" values.
  220. func (d *CtrContractShareDao) OmitNilWhere() *CtrContractShareDao {
  221. return &CtrContractShareDao{M: d.M.OmitNilWhere(), Table: d.Table, TableAs: d.TableAs}
  222. }
  223. // OmitNilData sets optionOmitNilData option for the model, which automatically filers
  224. // the Data parameters for "nil" values.
  225. func (d *CtrContractShareDao) OmitNilData() *CtrContractShareDao {
  226. return &CtrContractShareDao{M: d.M.OmitNilData(), Table: d.Table, TableAs: d.TableAs}
  227. }
  228. // Filter marks filtering the fields which does not exist in the fields of the operated table.
  229. // Note that this function supports only single table operations.
  230. // Deprecated, filter feature is automatically enabled from GoFrame v1.16.0, it is so no longer used.
  231. func (d *CtrContractShareDao) Filter() *CtrContractShareDao {
  232. return &CtrContractShareDao{M: d.M.Filter(), Table: d.Table, TableAs: d.TableAs}
  233. }
  234. // Where sets the condition statement for the model. The parameter <where> can be type of
  235. // string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
  236. // multiple conditions will be joined into where statement using "AND".
  237. // Eg:
  238. // Where("uid=10000")
  239. // Where("uid", 10000)
  240. // Where("money>? AND name like ?", 99999, "vip_%")
  241. // Where("uid", 1).Where("name", "john")
  242. // Where("status IN (?)", g.Slice{1,2,3})
  243. // Where("age IN(?,?)", 18, 50)
  244. // Where(User{ Id : 1, UserName : "john"})
  245. func (d *CtrContractShareDao) Where(where interface{}, args ...interface{}) *CtrContractShareDao {
  246. return &CtrContractShareDao{M: d.M.Where(where, args...), Table: d.Table, TableAs: d.TableAs}
  247. }
  248. // WherePri does the same logic as M.Where except that if the parameter <where>
  249. // is a single condition like int/string/float/slice, it treats the condition as the primary
  250. // key value. That is, if primary key is "id" and given <where> parameter as "123", the
  251. // WherePri function treats the condition as "id=123", but M.Where treats the condition
  252. // as string "123".
  253. func (d *CtrContractShareDao) WherePri(where interface{}, args ...interface{}) *CtrContractShareDao {
  254. return &CtrContractShareDao{M: d.M.WherePri(where, args...), Table: d.Table, TableAs: d.TableAs}
  255. }
  256. // Having sets the having statement for the model.
  257. // The parameters of this function usage are as the same as function Where.
  258. // See Where.
  259. func (d *CtrContractShareDao) Having(having interface{}, args ...interface{}) *CtrContractShareDao {
  260. return &CtrContractShareDao{M: d.M.Having(having, args...), Table: d.Table, TableAs: d.TableAs}
  261. }
  262. // Wheref builds condition string using fmt.Sprintf and arguments.
  263. // Note that if the number of "args" is more than the place holder in "format",
  264. // the extra "args" will be used as the where condition arguments of the Model.
  265. func (d *CtrContractShareDao) Wheref(format string, args ...interface{}) *CtrContractShareDao {
  266. return &CtrContractShareDao{M: d.M.Wheref(format, args...), Table: d.Table, TableAs: d.TableAs}
  267. }
  268. // WhereLT builds "column < value" statement.
  269. func (d *CtrContractShareDao) WhereLT(column string, value interface{}) *CtrContractShareDao {
  270. return &CtrContractShareDao{M: d.M.WhereLT(column, value), Table: d.Table, TableAs: d.TableAs}
  271. }
  272. // WhereLTE builds "column <= value" statement.
  273. func (d *CtrContractShareDao) WhereLTE(column string, value interface{}) *CtrContractShareDao {
  274. return &CtrContractShareDao{M: d.M.WhereLTE(column, value), Table: d.Table, TableAs: d.TableAs}
  275. }
  276. // WhereGT builds "column > value" statement.
  277. func (d *CtrContractShareDao) WhereGT(column string, value interface{}) *CtrContractShareDao {
  278. return &CtrContractShareDao{M: d.M.WhereGT(column, value), Table: d.Table, TableAs: d.TableAs}
  279. }
  280. // WhereGTE builds "column >= value" statement.
  281. func (d *CtrContractShareDao) WhereGTE(column string, value interface{}) *CtrContractShareDao {
  282. return &CtrContractShareDao{M: d.M.WhereGTE(column, value), Table: d.Table, TableAs: d.TableAs}
  283. }
  284. // WhereBetween builds "column BETWEEN min AND max" statement.
  285. func (d *CtrContractShareDao) WhereBetween(column string, min, max interface{}) *CtrContractShareDao {
  286. return &CtrContractShareDao{M: d.M.WhereBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
  287. }
  288. // WhereLike builds "column LIKE like" statement.
  289. func (d *CtrContractShareDao) WhereLike(column string, like interface{}) *CtrContractShareDao {
  290. return &CtrContractShareDao{M: d.M.WhereLike(column, like), Table: d.Table, TableAs: d.TableAs}
  291. }
  292. // WhereIn builds "column IN (in)" statement.
  293. func (d *CtrContractShareDao) WhereIn(column string, in interface{}) *CtrContractShareDao {
  294. return &CtrContractShareDao{M: d.M.WhereIn(column, in), Table: d.Table, TableAs: d.TableAs}
  295. }
  296. // WhereNull builds "columns[0] IS NULL AND columns[1] IS NULL ..." statement.
  297. func (d *CtrContractShareDao) WhereNull(columns ...string) *CtrContractShareDao {
  298. return &CtrContractShareDao{M: d.M.WhereNull(columns...), Table: d.Table, TableAs: d.TableAs}
  299. }
  300. // WhereNotBetween builds "column NOT BETWEEN min AND max" statement.
  301. func (d *CtrContractShareDao) WhereNotBetween(column string, min, max interface{}) *CtrContractShareDao {
  302. return &CtrContractShareDao{M: d.M.WhereNotBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
  303. }
  304. // WhereNotLike builds "column NOT LIKE like" statement.
  305. func (d *CtrContractShareDao) WhereNotLike(column string, like interface{}) *CtrContractShareDao {
  306. return &CtrContractShareDao{M: d.M.WhereNotLike(column, like), Table: d.Table, TableAs: d.TableAs}
  307. }
  308. // WhereNot builds "column != value" statement.
  309. func (d *CtrContractShareDao) WhereNot(column string, value interface{}) *CtrContractShareDao {
  310. return &CtrContractShareDao{M: d.M.WhereNot(column, value), Table: d.Table, TableAs: d.TableAs}
  311. }
  312. // WhereNotIn builds "column NOT IN (in)" statement.
  313. func (d *CtrContractShareDao) WhereNotIn(column string, in interface{}) *CtrContractShareDao {
  314. return &CtrContractShareDao{M: d.M.WhereNotIn(column, in), Table: d.Table, TableAs: d.TableAs}
  315. }
  316. // WhereNotNull builds "columns[0] IS NOT NULL AND columns[1] IS NOT NULL ..." statement.
  317. func (d *CtrContractShareDao) WhereNotNull(columns ...string) *CtrContractShareDao {
  318. return &CtrContractShareDao{M: d.M.WhereNotNull(columns...), Table: d.Table, TableAs: d.TableAs}
  319. }
  320. // WhereOr adds "OR" condition to the where statement.
  321. func (d *CtrContractShareDao) WhereOr(where interface{}, args ...interface{}) *CtrContractShareDao {
  322. return &CtrContractShareDao{M: d.M.WhereOr(where, args...), Table: d.Table, TableAs: d.TableAs}
  323. }
  324. // WhereOrf builds "OR" condition string using fmt.Sprintf and arguments.
  325. func (d *CtrContractShareDao) WhereOrf(format string, args ...interface{}) *CtrContractShareDao {
  326. return &CtrContractShareDao{M: d.M.WhereOrf(format, args...), Table: d.Table, TableAs: d.TableAs}
  327. }
  328. // WhereOrLT builds "column < value" statement in "OR" conditions..
  329. func (d *CtrContractShareDao) WhereOrLT(column string, value interface{}) *CtrContractShareDao {
  330. return &CtrContractShareDao{M: d.M.WhereOrLT(column, value), Table: d.Table, TableAs: d.TableAs}
  331. }
  332. // WhereOrLTE builds "column <= value" statement in "OR" conditions..
  333. func (d *CtrContractShareDao) WhereOrLTE(column string, value interface{}) *CtrContractShareDao {
  334. return &CtrContractShareDao{M: d.M.WhereOrLTE(column, value), Table: d.Table, TableAs: d.TableAs}
  335. }
  336. // WhereOrGT builds "column > value" statement in "OR" conditions..
  337. func (d *CtrContractShareDao) WhereOrGT(column string, value interface{}) *CtrContractShareDao {
  338. return &CtrContractShareDao{M: d.M.WhereOrGT(column, value), Table: d.Table, TableAs: d.TableAs}
  339. }
  340. // WhereOrGTE builds "column >= value" statement in "OR" conditions..
  341. func (d *CtrContractShareDao) WhereOrGTE(column string, value interface{}) *CtrContractShareDao {
  342. return &CtrContractShareDao{M: d.M.WhereOrGTE(column, value), Table: d.Table, TableAs: d.TableAs}
  343. }
  344. // WhereOrBetween builds "column BETWEEN min AND max" statement in "OR" conditions.
  345. func (d *CtrContractShareDao) WhereOrBetween(column string, min, max interface{}) *CtrContractShareDao {
  346. return &CtrContractShareDao{M: d.M.WhereOrBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
  347. }
  348. // WhereOrLike builds "column LIKE like" statement in "OR" conditions.
  349. func (d *CtrContractShareDao) WhereOrLike(column string, like interface{}) *CtrContractShareDao {
  350. return &CtrContractShareDao{M: d.M.WhereOrLike(column, like), Table: d.Table, TableAs: d.TableAs}
  351. }
  352. // WhereOrIn builds "column IN (in)" statement in "OR" conditions.
  353. func (d *CtrContractShareDao) WhereOrIn(column string, in interface{}) *CtrContractShareDao {
  354. return &CtrContractShareDao{M: d.M.WhereOrIn(column, in), Table: d.Table, TableAs: d.TableAs}
  355. }
  356. // WhereOrNull builds "columns[0] IS NULL OR columns[1] IS NULL ..." statement in "OR" conditions.
  357. func (d *CtrContractShareDao) WhereOrNull(columns ...string) *CtrContractShareDao {
  358. return &CtrContractShareDao{M: d.M.WhereOrNull(columns...), Table: d.Table, TableAs: d.TableAs}
  359. }
  360. // WhereOrNotBetween builds "column NOT BETWEEN min AND max" statement in "OR" conditions.
  361. func (d *CtrContractShareDao) WhereOrNotBetween(column string, min, max interface{}) *CtrContractShareDao {
  362. return &CtrContractShareDao{M: d.M.WhereOrNotBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
  363. }
  364. // WhereOrNotLike builds "column NOT LIKE like" statement in "OR" conditions.
  365. func (d *CtrContractShareDao) WhereOrNotLike(column string, like interface{}) *CtrContractShareDao {
  366. return &CtrContractShareDao{M: d.M.WhereOrNotLike(column, like), Table: d.Table, TableAs: d.TableAs}
  367. }
  368. // WhereOrNotIn builds "column NOT IN (in)" statement.
  369. func (d *CtrContractShareDao) WhereOrNotIn(column string, in interface{}) *CtrContractShareDao {
  370. return &CtrContractShareDao{M: d.M.WhereOrNotIn(column, in), Table: d.Table, TableAs: d.TableAs}
  371. }
  372. // WhereOrNotNull builds "columns[0] IS NOT NULL OR columns[1] IS NOT NULL ..." statement in "OR" conditions.
  373. func (d *CtrContractShareDao) WhereOrNotNull(columns ...string) *CtrContractShareDao {
  374. return &CtrContractShareDao{M: d.M.WhereOrNotNull(columns...), Table: d.Table, TableAs: d.TableAs}
  375. }
  376. // Group sets the "GROUP BY" statement for the model.
  377. func (d *CtrContractShareDao) Group(groupBy ...string) *CtrContractShareDao {
  378. return &CtrContractShareDao{M: d.M.Group(groupBy...), Table: d.Table, TableAs: d.TableAs}
  379. }
  380. // And adds "AND" condition to the where statement.
  381. // Deprecated, use Where instead.
  382. func (d *CtrContractShareDao) And(where interface{}, args ...interface{}) *CtrContractShareDao {
  383. return &CtrContractShareDao{M: d.M.And(where, args...), Table: d.Table, TableAs: d.TableAs}
  384. }
  385. // Or adds "OR" condition to the where statement.
  386. // Deprecated, use WhereOr instead.
  387. func (d *CtrContractShareDao) Or(where interface{}, args ...interface{}) *CtrContractShareDao {
  388. return &CtrContractShareDao{M: d.M.Or(where, args...), Table: d.Table, TableAs: d.TableAs}
  389. }
  390. // GroupBy sets the "GROUP BY" statement for the model.
  391. func (d *CtrContractShareDao) GroupBy(groupBy string) *CtrContractShareDao {
  392. return &CtrContractShareDao{M: d.M.Group(groupBy), Table: d.Table, TableAs: d.TableAs}
  393. }
  394. // Order sets the "ORDER BY" statement for the model.
  395. func (d *CtrContractShareDao) Order(orderBy ...string) *CtrContractShareDao {
  396. return &CtrContractShareDao{M: d.M.Order(orderBy...), Table: d.Table, TableAs: d.TableAs}
  397. }
  398. // OrderAsc sets the "ORDER BY xxx ASC" statement for the model.
  399. func (d *CtrContractShareDao) OrderAsc(column string) *CtrContractShareDao {
  400. return &CtrContractShareDao{M: d.M.OrderAsc(column), Table: d.Table, TableAs: d.TableAs}
  401. }
  402. // OrderDesc sets the "ORDER BY xxx DESC" statement for the model.
  403. func (d *CtrContractShareDao) OrderDesc(column string) *CtrContractShareDao {
  404. return &CtrContractShareDao{M: d.M.OrderDesc(column), Table: d.Table, TableAs: d.TableAs}
  405. }
  406. // OrderRandom sets the "ORDER BY RANDOM()" statement for the model.
  407. func (d *CtrContractShareDao) OrderRandom() *CtrContractShareDao {
  408. return &CtrContractShareDao{M: d.M.OrderRandom(), Table: d.Table, TableAs: d.TableAs}
  409. }
  410. // OrderBy is alias of Model.Order.
  411. // See Model.Order.
  412. // Deprecated, use Order instead.
  413. func (d *CtrContractShareDao) OrderBy(orderBy string) *CtrContractShareDao {
  414. return &CtrContractShareDao{M: d.M.Order(orderBy), Table: d.Table, TableAs: d.TableAs}
  415. }
  416. // Limit sets the "LIMIT" statement for the model.
  417. // The parameter <limit> can be either one or two number, if passed two number is passed,
  418. // it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
  419. // statement.
  420. func (d *CtrContractShareDao) Limit(limit ...int) *CtrContractShareDao {
  421. return &CtrContractShareDao{M: d.M.Limit(limit...), Table: d.Table, TableAs: d.TableAs}
  422. }
  423. // Offset sets the "OFFSET" statement for the model.
  424. // It only makes sense for some databases like SQLServer, PostgreSQL, etc.
  425. func (d *CtrContractShareDao) Offset(offset int) *CtrContractShareDao {
  426. return &CtrContractShareDao{M: d.M.Offset(offset), Table: d.Table, TableAs: d.TableAs}
  427. }
  428. // Distinct forces the query to only return distinct results.
  429. func (d *CtrContractShareDao) Distinct() *CtrContractShareDao {
  430. return &CtrContractShareDao{M: d.M.Distinct(), Table: d.Table, TableAs: d.TableAs}
  431. }
  432. // Page sets the paging number for the model.
  433. // The parameter <page> is started from 1 for paging.
  434. // Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
  435. func (d *CtrContractShareDao) Page(page, limit int) *CtrContractShareDao {
  436. return &CtrContractShareDao{M: d.M.Page(page, limit), Table: d.Table, TableAs: d.TableAs}
  437. }
  438. // Batch sets the batch operation number for the model.
  439. func (d *CtrContractShareDao) Batch(batch int) *CtrContractShareDao {
  440. return &CtrContractShareDao{M: d.M.Batch(batch), Table: d.Table, TableAs: d.TableAs}
  441. }
  442. // Cache sets the cache feature for the model. It caches the result of the sql, which means
  443. // if there's another same sql request, it just reads and returns the result from cache, it
  444. // but not committed and executed into the database.
  445. //
  446. // If the parameter <duration> < 0, which means it clear the cache with given <name>.
  447. // If the parameter <duration> = 0, which means it never expires.
  448. // If the parameter <duration> > 0, which means it expires after <duration>.
  449. //
  450. // The optional parameter <name> is used to bind a name to the cache, which means you can later
  451. // control the cache like changing the <duration> or clearing the cache with specified <name>.
  452. //
  453. // Note that, the cache feature is disabled if the model is operating on a transaction.
  454. func (d *CtrContractShareDao) Cache(duration time.Duration, name ...string) *CtrContractShareDao {
  455. return &CtrContractShareDao{M: d.M.Cache(duration, name...), Table: d.Table, TableAs: d.TableAs}
  456. }
  457. // Data sets the operation data for the model.
  458. // The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
  459. // Eg:
  460. // Data("uid=10000")
  461. // Data("uid", 10000)
  462. // Data(g.Map{"uid": 10000, "name":"john"})
  463. // Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
  464. func (d *CtrContractShareDao) Data(data ...interface{}) *CtrContractShareDao {
  465. return &CtrContractShareDao{M: d.M.Data(data...), Table: d.Table, TableAs: d.TableAs}
  466. }
  467. // All does "SELECT FROM ..." statement for the model.
  468. // It retrieves the records from table and returns the result as []*model.CtrContractShare.
  469. // It returns nil if there's no record retrieved with the given conditions from table.
  470. //
  471. // The optional parameter <where> is the same as the parameter of M.Where function,
  472. // see M.Where.
  473. func (d *CtrContractShareDao) All(where ...interface{}) ([]*model.CtrContractShare, error) {
  474. all, err := d.M.All(where...)
  475. if err != nil {
  476. return nil, err
  477. }
  478. var entities []*model.CtrContractShare
  479. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  480. return nil, err
  481. }
  482. return entities, nil
  483. }
  484. // One retrieves one record from table and returns the result as *model.CtrContractShare.
  485. // It returns nil if there's no record retrieved with the given conditions from table.
  486. //
  487. // The optional parameter <where> is the same as the parameter of M.Where function,
  488. // see M.Where.
  489. func (d *CtrContractShareDao) One(where ...interface{}) (*model.CtrContractShare, error) {
  490. one, err := d.M.One(where...)
  491. if err != nil {
  492. return nil, err
  493. }
  494. var entity *model.CtrContractShare
  495. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  496. return nil, err
  497. }
  498. return entity, nil
  499. }
  500. // FindOne retrieves and returns a single Record by M.WherePri and M.One.
  501. // Also see M.WherePri and M.One.
  502. func (d *CtrContractShareDao) FindOne(where ...interface{}) (*model.CtrContractShare, error) {
  503. one, err := d.M.FindOne(where...)
  504. if err != nil {
  505. return nil, err
  506. }
  507. var entity *model.CtrContractShare
  508. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  509. return nil, err
  510. }
  511. return entity, nil
  512. }
  513. // FindAll retrieves and returns Result by by M.WherePri and M.All.
  514. // Also see M.WherePri and M.All.
  515. func (d *CtrContractShareDao) FindAll(where ...interface{}) ([]*model.CtrContractShare, error) {
  516. all, err := d.M.FindAll(where...)
  517. if err != nil {
  518. return nil, err
  519. }
  520. var entities []*model.CtrContractShare
  521. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  522. return nil, err
  523. }
  524. return entities, nil
  525. }
  526. // Struct retrieves one record from table and converts it into given struct.
  527. // The parameter <pointer> should be type of *struct/**struct. If type **struct is given,
  528. // it can create the struct internally during converting.
  529. //
  530. // The optional parameter <where> is the same as the parameter of Model.Where function,
  531. // see Model.Where.
  532. //
  533. // Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
  534. // from table and <pointer> is not nil.
  535. //
  536. // Eg:
  537. // user := new(User)
  538. // err := dao.User.Where("id", 1).Struct(user)
  539. //
  540. // user := (*User)(nil)
  541. // err := dao.User.Where("id", 1).Struct(&user)
  542. func (d *CtrContractShareDao) Struct(pointer interface{}, where ...interface{}) error {
  543. return d.M.Struct(pointer, where...)
  544. }
  545. // Structs retrieves records from table and converts them into given struct slice.
  546. // The parameter <pointer> should be type of *[]struct/*[]*struct. It can create and fill the struct
  547. // slice internally during converting.
  548. //
  549. // The optional parameter <where> is the same as the parameter of Model.Where function,
  550. // see Model.Where.
  551. //
  552. // Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
  553. // from table and <pointer> is not empty.
  554. //
  555. // Eg:
  556. // users := ([]User)(nil)
  557. // err := dao.User.Structs(&users)
  558. //
  559. // users := ([]*User)(nil)
  560. // err := dao.User.Structs(&users)
  561. func (d *CtrContractShareDao) Structs(pointer interface{}, where ...interface{}) error {
  562. return d.M.Structs(pointer, where...)
  563. }
  564. // Scan automatically calls Struct or Structs function according to the type of parameter <pointer>.
  565. // It calls function Struct if <pointer> is type of *struct/**struct.
  566. // It calls function Structs if <pointer> is type of *[]struct/*[]*struct.
  567. //
  568. // The optional parameter <where> is the same as the parameter of Model.Where function,
  569. // see Model.Where.
  570. //
  571. // Note that it returns sql.ErrNoRows if there's no record retrieved and given pointer is not empty or nil.
  572. //
  573. // Eg:
  574. // user := new(User)
  575. // err := dao.User.Where("id", 1).Scan(user)
  576. //
  577. // user := (*User)(nil)
  578. // err := dao.User.Where("id", 1).Scan(&user)
  579. //
  580. // users := ([]User)(nil)
  581. // err := dao.User.Scan(&users)
  582. //
  583. // users := ([]*User)(nil)
  584. // err := dao.User.Scan(&users)
  585. func (d *CtrContractShareDao) Scan(pointer interface{}, where ...interface{}) error {
  586. return d.M.Scan(pointer, where...)
  587. }
  588. // Chunk iterates the table with given size and callback function.
  589. func (d *CtrContractShareDao) Chunk(limit int, callback func(entities []*model.CtrContractShare, err error) bool) {
  590. d.M.Chunk(limit, func(result gdb.Result, err error) bool {
  591. var entities []*model.CtrContractShare
  592. err = result.Structs(&entities)
  593. if err == sql.ErrNoRows {
  594. return false
  595. }
  596. return callback(entities, err)
  597. })
  598. }
  599. // LockUpdate sets the lock for update for current operation.
  600. func (d *CtrContractShareDao) LockUpdate() *CtrContractShareDao {
  601. return &CtrContractShareDao{M: d.M.LockUpdate(), Table: d.Table, TableAs: d.TableAs}
  602. }
  603. // LockShared sets the lock in share mode for current operation.
  604. func (d *CtrContractShareDao) LockShared() *CtrContractShareDao {
  605. return &CtrContractShareDao{M: d.M.LockShared(), Table: d.Table, TableAs: d.TableAs}
  606. }
  607. // Unscoped enables/disables the soft deleting feature.
  608. func (d *CtrContractShareDao) Unscoped() *CtrContractShareDao {
  609. return &CtrContractShareDao{M: d.M.Unscoped(), Table: d.Table, TableAs: d.TableAs}
  610. }
  611. // DataScope enables the DataScope feature.
  612. func (d *CtrContractShareDao) DataScope(ctx context.Context, args ...interface{}) *CtrContractShareDao {
  613. cs := ctx.Value("contextService")
  614. dataScope := gconv.Map(gconv.String(gconv.Map(cs)["dataScope"]))
  615. if dataScope != nil {
  616. // 销售工程师判断
  617. var salesEngineerFlag bool
  618. if roles, ok := dataScope["roles"]; ok {
  619. arr := garray.NewArrayFrom(roles.([]interface{}), true)
  620. if arr.Len() == 1 && arr.Contains("SalesEngineer") {
  621. salesEngineerFlag = true
  622. }
  623. }
  624. userIds, ok := dataScope["userIds"]
  625. specialFlag, userCols, orColsMap := d.checkColumnsName(dataScope, args...)
  626. var orColumns []string
  627. var orValues []interface{}
  628. if ok && userIds != "-1" {
  629. for _, column := range userCols {
  630. if ok, _ := d.M.HasField(column); ok || specialFlag {
  631. orColumns = append(orColumns, column+" IN (?) ")
  632. orValues = append(orValues, userIds)
  633. }
  634. }
  635. }
  636. for col, params := range orColsMap {
  637. if ok, _ := d.M.HasField(col); ok || specialFlag {
  638. orColumns = append(orColumns, fmt.Sprintf(" ( %s IN (?) )", col))
  639. orValues = append(orValues, params)
  640. }
  641. }
  642. // 销售工程师权限加成
  643. if !salesEngineerFlag {
  644. var andColumns []string
  645. var andValues []interface{}
  646. for col, params := range dataScope {
  647. if ok, _ := d.M.HasField(col); ok || specialFlag {
  648. andColumns = append(andColumns, fmt.Sprintf(" ( %s IN (?) )", col))
  649. andValues = append(andValues, params)
  650. }
  651. }
  652. if len(andColumns) > 0 {
  653. andWhereSql := strings.Join(andColumns, " AND ")
  654. orColumns = append(orColumns, "("+andWhereSql+")")
  655. orValues = append(orValues, andValues...)
  656. }
  657. }
  658. whereSql := strings.Join(orColumns, " OR ")
  659. return &CtrContractShareDao{M: d.M.Where(whereSql, orValues...).Ctx(ctx), Table: d.Table, TableAs: d.TableAs}
  660. }
  661. return d
  662. }
  663. // args 1、字段
  664. // args 2、字段、表名
  665. // args 3、字段对应关系
  666. func (d *CtrContractShareDao) checkColumnsName(dataScope map[string]interface{}, args ...interface{}) (bool, []string, map[string]interface{}) {
  667. var userCols []string
  668. tableAs, specialFlag := "", false
  669. orColsMap, colsContrast := map[string]interface{}{}, map[string]interface{}{}
  670. if d.TableAs != "" && len(args) <= 1 {
  671. tableAs = d.TableAs + "."
  672. }
  673. if len(args) > 1 {
  674. specialFlag = true
  675. if val, ok := args[1].(string); ok {
  676. tableAs = val + "."
  677. }
  678. }
  679. if len(args) > 0 {
  680. userCols = []string{tableAs + "created_by"}
  681. if column, ok := args[0].(string); ok {
  682. userCols = []string{tableAs + column}
  683. }
  684. if cols, ok := args[0].([]string); ok {
  685. for _, v := range cols {
  686. userCols = append(userCols, tableAs+v)
  687. }
  688. }
  689. if val, ok := args[0].(map[string]interface{}); ok {
  690. specialFlag = true
  691. colsContrast = val
  692. if orcols, ok := val["orcols"]; ok {
  693. if col, ok := orcols.(string); ok && gconv.String(val[col]) != "" {
  694. orColsMap[col] = val[col]
  695. delete(colsContrast, col)
  696. }
  697. if cols, ok := orcols.([]string); ok {
  698. for _, col := range cols {
  699. if gconv.String(val[col]) == "" {
  700. continue
  701. }
  702. orColsMap[col] = val[col]
  703. delete(colsContrast, col)
  704. }
  705. }
  706. }
  707. delete(colsContrast, "orcols")
  708. }
  709. }
  710. delete(dataScope, "userIds")
  711. delete(dataScope, "roles")
  712. delete(dataScope, "posts")
  713. if len(colsContrast) > 0 {
  714. for k, v := range dataScope {
  715. if data, ok := colsContrast[k]; ok {
  716. dataScope[data.(string)] = v
  717. }
  718. delete(dataScope, k)
  719. delete(colsContrast, k)
  720. }
  721. for k, v := range colsContrast {
  722. dataScope[k] = v
  723. }
  724. }
  725. return specialFlag, userCols, orColsMap
  726. }