ctr_contract.go 39 KB

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