ctr_contract.go 37 KB

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