ctr_contract.go 37 KB

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