ctr_contract.go 34 KB

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