ctr_contract.go 18 KB

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