ctr_contract.go 34 KB

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