ctr_contract.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. // ==========================================================================
  2. // This is auto-generated by gf cli tool. DO NOT EDIT THIS FILE MANUALLY.
  3. // ==========================================================================
  4. package internal
  5. import (
  6. "context"
  7. "database/sql"
  8. "github.com/gogf/gf/database/gdb"
  9. "github.com/gogf/gf/frame/g"
  10. "github.com/gogf/gf/frame/gmvc"
  11. "time"
  12. model "dashoo.cn/micro/app/model/contract"
  13. )
  14. // CtrContractDao is the manager for logic model data accessing
  15. // and custom defined data operations functions management.
  16. type CtrContractDao struct {
  17. gmvc.M
  18. DB gdb.DB
  19. Table string
  20. Columns ctrContractColumns
  21. }
  22. // CtrContractColumns defines and stores column names for table ctr_contract.
  23. type ctrContractColumns struct {
  24. Id string // 主键
  25. ContractCode string // 合同编号
  26. ContractName string // 合同名称
  27. CustId string // 关联客户
  28. CustName string // 客户名称
  29. NboId string // 关联项目
  30. NboName string // 项目名称
  31. ApproStatus string // 审批状态
  32. ContractType string // 合同类型
  33. ContractAmount string // 合同金额
  34. InvoiceAmount string // 已开票金额
  35. CollectedAmount string // 已回款金额
  36. ContractStartTime string // 合同开始时间
  37. ContractEndTime string // 合同结束时间
  38. InchargeId string // 负责人ID
  39. InchargeName string // 负责人(销售工程师)
  40. SignatoryId string // 公司签约人ID
  41. SignatoryName string // 公司签约人
  42. SignatoryType string // 签订单位类型 10 终端用户 20 经销商 30 代理商
  43. CustSignatoryId string // 客户签约人ID
  44. CustSignatoryName string // 客户签约人
  45. DistributorId string // 经销商ID
  46. DistributorName string // 经销商
  47. Remark string // 备注
  48. CreatedBy string // 创建者
  49. CreatedName string // 创建人
  50. CreatedTime string // 创建时间
  51. UpdatedBy string // 更新者
  52. UpdatedName string // 更新人
  53. UpdatedTime string // 更新时间
  54. DeletedTime string // 删除时间
  55. }
  56. var (
  57. // CtrContract is globally public accessible object for table ctr_contract operations.
  58. CtrContract = CtrContractDao{
  59. M: g.DB("default").Model("ctr_contract").Safe(),
  60. DB: g.DB("default"),
  61. Table: "ctr_contract",
  62. Columns: ctrContractColumns{
  63. Id: "id",
  64. ContractCode: "contract_code",
  65. ContractName: "contract_name",
  66. CustId: "cust_id",
  67. CustName: "cust_name",
  68. NboId: "nbo_id",
  69. NboName: "nbo_name",
  70. ApproStatus: "appro_status",
  71. ContractType: "contract_type",
  72. ContractAmount: "contract_amount",
  73. InvoiceAmount: "invoice_amount",
  74. CollectedAmount: "collected_amount",
  75. ContractStartTime: "contract_start_time",
  76. ContractEndTime: "contract_end_time",
  77. InchargeId: "incharge_id",
  78. InchargeName: "incharge_name",
  79. SignatoryId: "signatory_id",
  80. SignatoryName: "signatory_name",
  81. SignatoryType: "signatory_type",
  82. CustSignatoryId: "cust_signatory_id",
  83. CustSignatoryName: "cust_signatory_name",
  84. DistributorId: "distributor_id",
  85. DistributorName: "distributor_name",
  86. Remark: "remark",
  87. CreatedBy: "created_by",
  88. CreatedName: "created_name",
  89. CreatedTime: "created_time",
  90. UpdatedBy: "updated_by",
  91. UpdatedName: "updated_name",
  92. UpdatedTime: "updated_time",
  93. DeletedTime: "deleted_time",
  94. },
  95. }
  96. )
  97. func NewCtrContractDao(tenant string) CtrContractDao {
  98. var dao CtrContractDao
  99. dao = CtrContractDao{
  100. M: g.DB(tenant).Model("ctr_contract").Safe(),
  101. DB: g.DB(tenant),
  102. Table: "ctr_contract",
  103. Columns: ctrContractColumns{
  104. Id: "id",
  105. ContractCode: "contract_code",
  106. ContractName: "contract_name",
  107. CustId: "cust_id",
  108. CustName: "cust_name",
  109. NboId: "nbo_id",
  110. NboName: "nbo_name",
  111. ApproStatus: "appro_status",
  112. ContractType: "contract_type",
  113. ContractAmount: "contract_amount",
  114. InvoiceAmount: "invoice_amount",
  115. CollectedAmount: "collected_amount",
  116. ContractStartTime: "contract_start_time",
  117. ContractEndTime: "contract_end_time",
  118. InchargeId: "incharge_id",
  119. InchargeName: "incharge_name",
  120. SignatoryId: "signatory_id",
  121. SignatoryName: "signatory_name",
  122. SignatoryType: "signatory_type",
  123. CustSignatoryId: "cust_signatory_id",
  124. CustSignatoryName: "cust_signatory_name",
  125. DistributorId: "distributor_id",
  126. DistributorName: "distributor_name",
  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. return dao
  138. }
  139. // Ctx is a chaining function, which creates and returns a new DB that is a shallow copy
  140. // of current DB object and with given context in it.
  141. // Note that this returned DB object can be used only once, so do not assign it to
  142. // a global or package variable for long using.
  143. func (d *CtrContractDao) Ctx(ctx context.Context) *CtrContractDao {
  144. return &CtrContractDao{M: d.M.Ctx(ctx)}
  145. }
  146. // As sets an alias name for current table.
  147. func (d *CtrContractDao) As(as string) *CtrContractDao {
  148. return &CtrContractDao{M: d.M.As(as)}
  149. }
  150. // TX sets the transaction for current operation.
  151. func (d *CtrContractDao) TX(tx *gdb.TX) *CtrContractDao {
  152. return &CtrContractDao{M: d.M.TX(tx)}
  153. }
  154. // Master marks the following operation on master node.
  155. func (d *CtrContractDao) Master() *CtrContractDao {
  156. return &CtrContractDao{M: d.M.Master()}
  157. }
  158. // Slave marks the following operation on slave node.
  159. // Note that it makes sense only if there's any slave node configured.
  160. func (d *CtrContractDao) Slave() *CtrContractDao {
  161. return &CtrContractDao{M: d.M.Slave()}
  162. }
  163. // Args sets custom arguments for model operation.
  164. func (d *CtrContractDao) Args(args ...interface{}) *CtrContractDao {
  165. return &CtrContractDao{M: d.M.Args(args...)}
  166. }
  167. // LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
  168. // The parameter <table> can be joined table and its joined condition,
  169. // and also with its alias name, like:
  170. // Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
  171. // Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
  172. func (d *CtrContractDao) LeftJoin(table ...string) *CtrContractDao {
  173. return &CtrContractDao{M: d.M.LeftJoin(table...)}
  174. }
  175. // RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
  176. // The parameter <table> can be joined table and its joined condition,
  177. // and also with its alias name, like:
  178. // Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
  179. // Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
  180. func (d *CtrContractDao) RightJoin(table ...string) *CtrContractDao {
  181. return &CtrContractDao{M: d.M.RightJoin(table...)}
  182. }
  183. // InnerJoin does "INNER JOIN ... ON ..." statement on the model.
  184. // The parameter <table> can be joined table and its joined condition,
  185. // and also with its alias name, like:
  186. // Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
  187. // Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
  188. func (d *CtrContractDao) InnerJoin(table ...string) *CtrContractDao {
  189. return &CtrContractDao{M: d.M.InnerJoin(table...)}
  190. }
  191. // Fields sets the operation fields of the model, multiple fields joined using char ','.
  192. // The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
  193. func (d *CtrContractDao) Fields(fieldNamesOrMapStruct ...interface{}) *CtrContractDao {
  194. return &CtrContractDao{M: d.M.Fields(fieldNamesOrMapStruct...)}
  195. }
  196. // FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
  197. // The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
  198. func (d *CtrContractDao) FieldsEx(fieldNamesOrMapStruct ...interface{}) *CtrContractDao {
  199. return &CtrContractDao{M: d.M.FieldsEx(fieldNamesOrMapStruct...)}
  200. }
  201. // Option sets the extra operation option for the model.
  202. func (d *CtrContractDao) Option(option int) *CtrContractDao {
  203. return &CtrContractDao{M: d.M.Option(option)}
  204. }
  205. // OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
  206. // the data and where attributes for empty values.
  207. func (d *CtrContractDao) OmitEmpty() *CtrContractDao {
  208. return &CtrContractDao{M: d.M.OmitEmpty()}
  209. }
  210. // Filter marks filtering the fields which does not exist in the fields of the operated table.
  211. func (d *CtrContractDao) Filter() *CtrContractDao {
  212. return &CtrContractDao{M: d.M.Filter()}
  213. }
  214. // Where sets the condition statement for the model. The parameter <where> can be type of
  215. // string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
  216. // multiple conditions will be joined into where statement using "AND".
  217. // Eg:
  218. // Where("uid=10000")
  219. // Where("uid", 10000)
  220. // Where("money>? AND name like ?", 99999, "vip_%")
  221. // Where("uid", 1).Where("name", "john")
  222. // Where("status IN (?)", g.Slice{1,2,3})
  223. // Where("age IN(?,?)", 18, 50)
  224. // Where(User{ Id : 1, UserName : "john"})
  225. func (d *CtrContractDao) Where(where interface{}, args ...interface{}) *CtrContractDao {
  226. return &CtrContractDao{M: d.M.Where(where, args...)}
  227. }
  228. // WherePri does the same logic as M.Where except that if the parameter <where>
  229. // is a single condition like int/string/float/slice, it treats the condition as the primary
  230. // key value. That is, if primary key is "id" and given <where> parameter as "123", the
  231. // WherePri function treats the condition as "id=123", but M.Where treats the condition
  232. // as string "123".
  233. func (d *CtrContractDao) WherePri(where interface{}, args ...interface{}) *CtrContractDao {
  234. return &CtrContractDao{M: d.M.WherePri(where, args...)}
  235. }
  236. // And adds "AND" condition to the where statement.
  237. func (d *CtrContractDao) And(where interface{}, args ...interface{}) *CtrContractDao {
  238. return &CtrContractDao{M: d.M.And(where, args...)}
  239. }
  240. // Or adds "OR" condition to the where statement.
  241. func (d *CtrContractDao) Or(where interface{}, args ...interface{}) *CtrContractDao {
  242. return &CtrContractDao{M: d.M.Or(where, args...)}
  243. }
  244. // Group sets the "GROUP BY" statement for the model.
  245. func (d *CtrContractDao) Group(groupBy string) *CtrContractDao {
  246. return &CtrContractDao{M: d.M.Group(groupBy)}
  247. }
  248. // Order sets the "ORDER BY" statement for the model.
  249. func (d *CtrContractDao) Order(orderBy ...string) *CtrContractDao {
  250. return &CtrContractDao{M: d.M.Order(orderBy...)}
  251. }
  252. // Limit sets the "LIMIT" statement for the model.
  253. // The parameter <limit> can be either one or two number, if passed two number is passed,
  254. // it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
  255. // statement.
  256. func (d *CtrContractDao) Limit(limit ...int) *CtrContractDao {
  257. return &CtrContractDao{M: d.M.Limit(limit...)}
  258. }
  259. // Offset sets the "OFFSET" statement for the model.
  260. // It only makes sense for some databases like SQLServer, PostgreSQL, etc.
  261. func (d *CtrContractDao) Offset(offset int) *CtrContractDao {
  262. return &CtrContractDao{M: d.M.Offset(offset)}
  263. }
  264. // Page sets the paging number for the model.
  265. // The parameter <page> is started from 1 for paging.
  266. // Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
  267. func (d *CtrContractDao) Page(page, limit int) *CtrContractDao {
  268. return &CtrContractDao{M: d.M.Page(page, limit)}
  269. }
  270. // Batch sets the batch operation number for the model.
  271. func (d *CtrContractDao) Batch(batch int) *CtrContractDao {
  272. return &CtrContractDao{M: d.M.Batch(batch)}
  273. }
  274. // Cache sets the cache feature for the model. It caches the result of the sql, which means
  275. // if there's another same sql request, it just reads and returns the result from cache, it
  276. // but not committed and executed into the database.
  277. //
  278. // If the parameter <duration> < 0, which means it clear the cache with given <name>.
  279. // If the parameter <duration> = 0, which means it never expires.
  280. // If the parameter <duration> > 0, which means it expires after <duration>.
  281. //
  282. // The optional parameter <name> is used to bind a name to the cache, which means you can later
  283. // control the cache like changing the <duration> or clearing the cache with specified <name>.
  284. //
  285. // Note that, the cache feature is disabled if the model is operating on a transaction.
  286. func (d *CtrContractDao) Cache(duration time.Duration, name ...string) *CtrContractDao {
  287. return &CtrContractDao{M: d.M.Cache(duration, name...)}
  288. }
  289. // Data sets the operation data for the model.
  290. // The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
  291. // Eg:
  292. // Data("uid=10000")
  293. // Data("uid", 10000)
  294. // Data(g.Map{"uid": 10000, "name":"john"})
  295. // Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
  296. func (d *CtrContractDao) Data(data ...interface{}) *CtrContractDao {
  297. return &CtrContractDao{M: d.M.Data(data...)}
  298. }
  299. // All does "SELECT FROM ..." statement for the model.
  300. // It retrieves the records from table and returns the result as []*model.CtrContract.
  301. // It returns nil if there's no record retrieved with the given conditions from table.
  302. //
  303. // The optional parameter <where> is the same as the parameter of M.Where function,
  304. // see M.Where.
  305. func (d *CtrContractDao) All(where ...interface{}) ([]*model.CtrContract, error) {
  306. all, err := d.M.All(where...)
  307. if err != nil {
  308. return nil, err
  309. }
  310. var entities []*model.CtrContract
  311. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  312. return nil, err
  313. }
  314. return entities, nil
  315. }
  316. // One retrieves one record from table and returns the result as *model.CtrContract.
  317. // It returns nil if there's no record retrieved with the given conditions from table.
  318. //
  319. // The optional parameter <where> is the same as the parameter of M.Where function,
  320. // see M.Where.
  321. func (d *CtrContractDao) One(where ...interface{}) (*model.CtrContract, error) {
  322. one, err := d.M.One(where...)
  323. if err != nil {
  324. return nil, err
  325. }
  326. var entity *model.CtrContract
  327. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  328. return nil, err
  329. }
  330. return entity, nil
  331. }
  332. // FindOne retrieves and returns a single Record by M.WherePri and M.One.
  333. // Also see M.WherePri and M.One.
  334. func (d *CtrContractDao) FindOne(where ...interface{}) (*model.CtrContract, error) {
  335. one, err := d.M.FindOne(where...)
  336. if err != nil {
  337. return nil, err
  338. }
  339. var entity *model.CtrContract
  340. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  341. return nil, err
  342. }
  343. return entity, nil
  344. }
  345. // FindAll retrieves and returns Result by by M.WherePri and M.All.
  346. // Also see M.WherePri and M.All.
  347. func (d *CtrContractDao) FindAll(where ...interface{}) ([]*model.CtrContract, error) {
  348. all, err := d.M.FindAll(where...)
  349. if err != nil {
  350. return nil, err
  351. }
  352. var entities []*model.CtrContract
  353. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  354. return nil, err
  355. }
  356. return entities, nil
  357. }
  358. // Struct retrieves one record from table and converts it into given struct.
  359. // The parameter <pointer> should be type of *struct/**struct. If type **struct is given,
  360. // it can create the struct internally during converting.
  361. //
  362. // The optional parameter <where> is the same as the parameter of Model.Where function,
  363. // see Model.Where.
  364. //
  365. // Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
  366. // from table and <pointer> is not nil.
  367. //
  368. // Eg:
  369. // user := new(User)
  370. // err := dao.User.Where("id", 1).Struct(user)
  371. //
  372. // user := (*User)(nil)
  373. // err := dao.User.Where("id", 1).Struct(&user)
  374. func (d *CtrContractDao) Struct(pointer interface{}, where ...interface{}) error {
  375. return d.M.Struct(pointer, where...)
  376. }
  377. // Structs retrieves records from table and converts them into given struct slice.
  378. // The parameter <pointer> should be type of *[]struct/*[]*struct. It can create and fill the struct
  379. // slice internally during converting.
  380. //
  381. // The optional parameter <where> is the same as the parameter of Model.Where function,
  382. // see Model.Where.
  383. //
  384. // Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
  385. // from table and <pointer> is not empty.
  386. //
  387. // Eg:
  388. // users := ([]User)(nil)
  389. // err := dao.User.Structs(&users)
  390. //
  391. // users := ([]*User)(nil)
  392. // err := dao.User.Structs(&users)
  393. func (d *CtrContractDao) Structs(pointer interface{}, where ...interface{}) error {
  394. return d.M.Structs(pointer, where...)
  395. }
  396. // Scan automatically calls Struct or Structs function according to the type of parameter <pointer>.
  397. // It calls function Struct if <pointer> is type of *struct/**struct.
  398. // It calls function Structs if <pointer> is type of *[]struct/*[]*struct.
  399. //
  400. // The optional parameter <where> is the same as the parameter of Model.Where function,
  401. // see Model.Where.
  402. //
  403. // Note that it returns sql.ErrNoRows if there's no record retrieved and given pointer is not empty or nil.
  404. //
  405. // Eg:
  406. // user := new(User)
  407. // err := dao.User.Where("id", 1).Scan(user)
  408. //
  409. // user := (*User)(nil)
  410. // err := dao.User.Where("id", 1).Scan(&user)
  411. //
  412. // users := ([]User)(nil)
  413. // err := dao.User.Scan(&users)
  414. //
  415. // users := ([]*User)(nil)
  416. // err := dao.User.Scan(&users)
  417. func (d *CtrContractDao) Scan(pointer interface{}, where ...interface{}) error {
  418. return d.M.Scan(pointer, where...)
  419. }
  420. // Chunk iterates the table with given size and callback function.
  421. func (d *CtrContractDao) Chunk(limit int, callback func(entities []*model.CtrContract, err error) bool) {
  422. d.M.Chunk(limit, func(result gdb.Result, err error) bool {
  423. var entities []*model.CtrContract
  424. err = result.Structs(&entities)
  425. if err == sql.ErrNoRows {
  426. return false
  427. }
  428. return callback(entities, err)
  429. })
  430. }
  431. // LockUpdate sets the lock for update for current operation.
  432. func (d *CtrContractDao) LockUpdate() *CtrContractDao {
  433. return &CtrContractDao{M: d.M.LockUpdate()}
  434. }
  435. // LockShared sets the lock in share mode for current operation.
  436. func (d *CtrContractDao) LockShared() *CtrContractDao {
  437. return &CtrContractDao{M: d.M.LockShared()}
  438. }
  439. // Unscoped enables/disables the soft deleting feature.
  440. func (d *CtrContractDao) Unscoped() *CtrContractDao {
  441. return &CtrContractDao{M: d.M.Unscoped()}
  442. }