ctr_contract.go 18 KB

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