ctr_contract.go 40 KB

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