ctr_contract.go 30 KB

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