6
0

instrument.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  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. model2 "lims_adapter/model"
  12. "time"
  13. )
  14. // InstrumentDao is the manager for logic model data accessing
  15. // and custom defined data operations functions management.
  16. type InstrumentDao struct {
  17. gmvc.M
  18. DB gdb.DB
  19. Table string
  20. Columns instrumentColumns
  21. }
  22. // InstrumentColumns defines and stores column names for table instrument.
  23. type instrumentColumns struct {
  24. Id string //
  25. RoomId string // 所属房间id
  26. Code string // 设备编码
  27. Name string // 设备名称
  28. InstrImgId string // 设备图片id
  29. InstrImgUrl string // 设备图片Url
  30. SupplierId string // 供应商
  31. FactoryNum string // 出厂编号
  32. Model string // 型号
  33. Brand string // 设备品牌
  34. InstrType string // 设备类别
  35. Status string // 设备状态
  36. Location string // 设备所在位置
  37. Remark string // 备注
  38. IsFixedPoint string // 参与点检:
  39. CalibrationAt string // 校准时间
  40. CalibrationDeadline string // 校准使用期限
  41. CalibrationDeadlineType string // 期限类型
  42. MaintenCycle string // 维护周期数
  43. CycleType string // 期限类型
  44. HeartbeatAt string // 心跳时间
  45. Spec string // 规格
  46. CreatedAt string // 创建时间
  47. CreatedBy string // 创建人
  48. UpdatedAt string // 更新时间
  49. UpdatedBy string // 更新人
  50. TimeNotification string // 有效期提醒
  51. Sharable string // 是否共享(可预约)
  52. EndTime string // 截止日期
  53. Responsible string // 责任人
  54. MaintenTime string // 最后维护时间
  55. PurchaseTime string // 采购日期
  56. JoinPlan string // 计划
  57. IsAppoint string // 是否需要预约
  58. DeletedAt string // 删除时间
  59. Weekday string // 每周可预约日
  60. BeginAt string // 预约开始时段
  61. EndAt string // 预约结束时间
  62. MediaIds string // 文件ID
  63. IsOpen string // 是否开启预约 1开启 2未开启
  64. Instructions string // 使用说明
  65. Terminal string // 信息终端
  66. RoleId string // 自动审批角色
  67. Sort string // 排序
  68. }
  69. var (
  70. // Instrument is globally public accessible object for table instrument operations.
  71. Instrument = InstrumentDao{
  72. M: g.DB("default").Model("instrument").Safe(),
  73. DB: g.DB("default"),
  74. Table: "instrument",
  75. Columns: instrumentColumns{
  76. Id: "Id",
  77. RoomId: "RoomId",
  78. Code: "Code",
  79. Name: "Name",
  80. InstrImgId: "InstrImgId",
  81. InstrImgUrl: "InstrImgUrl",
  82. SupplierId: "SupplierId",
  83. FactoryNum: "FactoryNum",
  84. Model: "Model",
  85. Brand: "Brand",
  86. InstrType: "InstrType",
  87. Status: "Status",
  88. Location: "Location",
  89. Remark: "Remark",
  90. IsFixedPoint: "IsFixedPoint",
  91. CalibrationAt: "CalibrationAt",
  92. CalibrationDeadline: "CalibrationDeadline",
  93. CalibrationDeadlineType: "CalibrationDeadlineType",
  94. MaintenCycle: "MaintenCycle",
  95. CycleType: "CycleType",
  96. HeartbeatAt: "HeartbeatAt",
  97. Spec: "Spec",
  98. CreatedAt: "CreatedAt",
  99. CreatedBy: "CreatedBy",
  100. UpdatedAt: "UpdatedAt",
  101. UpdatedBy: "UpdatedBy",
  102. TimeNotification: "TimeNotification",
  103. Sharable: "Sharable",
  104. EndTime: "EndTime",
  105. Responsible: "Responsible",
  106. MaintenTime: "MaintenTime",
  107. PurchaseTime: "PurchaseTime",
  108. JoinPlan: "JoinPlan",
  109. IsAppoint: "IsAppoint",
  110. DeletedAt: "DeletedAt",
  111. Weekday: "Weekday",
  112. BeginAt: "BeginAt",
  113. EndAt: "EndAt",
  114. MediaIds: "MediaIds",
  115. IsOpen: "IsOpen",
  116. Instructions: "Instructions",
  117. Terminal: "Terminal",
  118. RoleId: "RoleId",
  119. Sort: "Sort",
  120. },
  121. }
  122. )
  123. func NewInstrumentDao(tenant string) InstrumentDao {
  124. var dao InstrumentDao
  125. dao = InstrumentDao{
  126. M: g.DB(tenant).Model("instrument").Safe(),
  127. DB: g.DB(tenant),
  128. Table: "instrument",
  129. Columns: instrumentColumns{
  130. Id: "Id",
  131. RoomId: "RoomId",
  132. Code: "Code",
  133. Name: "Name",
  134. InstrImgId: "InstrImgId",
  135. InstrImgUrl: "InstrImgUrl",
  136. SupplierId: "SupplierId",
  137. FactoryNum: "FactoryNum",
  138. Model: "Model",
  139. Brand: "Brand",
  140. InstrType: "InstrType",
  141. Status: "Status",
  142. Location: "Location",
  143. Remark: "Remark",
  144. IsFixedPoint: "IsFixedPoint",
  145. CalibrationAt: "CalibrationAt",
  146. CalibrationDeadline: "CalibrationDeadline",
  147. CalibrationDeadlineType: "CalibrationDeadlineType",
  148. MaintenCycle: "MaintenCycle",
  149. CycleType: "CycleType",
  150. HeartbeatAt: "HeartbeatAt",
  151. Spec: "Spec",
  152. CreatedAt: "CreatedAt",
  153. CreatedBy: "CreatedBy",
  154. UpdatedAt: "UpdatedAt",
  155. UpdatedBy: "UpdatedBy",
  156. TimeNotification: "TimeNotification",
  157. Sharable: "Sharable",
  158. EndTime: "EndTime",
  159. Responsible: "Responsible",
  160. MaintenTime: "MaintenTime",
  161. PurchaseTime: "PurchaseTime",
  162. JoinPlan: "JoinPlan",
  163. IsAppoint: "IsAppoint",
  164. DeletedAt: "DeletedAt",
  165. Weekday: "Weekday",
  166. BeginAt: "BeginAt",
  167. EndAt: "EndAt",
  168. MediaIds: "MediaIds",
  169. IsOpen: "IsOpen",
  170. Instructions: "Instructions",
  171. Terminal: "Terminal",
  172. RoleId: "RoleId",
  173. Sort: "Sort",
  174. },
  175. }
  176. return dao
  177. }
  178. // Ctx is a chaining function, which creates and returns a new DB that is a shallow copy
  179. // of current DB object and with given context in it.
  180. // Note that this returned DB object can be used only once, so do not assign it to
  181. // a global or package variable for long using.
  182. func (d *InstrumentDao) Ctx(ctx context.Context) *InstrumentDao {
  183. return &InstrumentDao{M: d.M.Ctx(ctx)}
  184. }
  185. // As sets an alias name for current table.
  186. func (d *InstrumentDao) As(as string) *InstrumentDao {
  187. return &InstrumentDao{M: d.M.As(as)}
  188. }
  189. // TX sets the transaction for current operation.
  190. func (d *InstrumentDao) TX(tx *gdb.TX) *InstrumentDao {
  191. return &InstrumentDao{M: d.M.TX(tx)}
  192. }
  193. // Master marks the following operation on master node.
  194. func (d *InstrumentDao) Master() *InstrumentDao {
  195. return &InstrumentDao{M: d.M.Master()}
  196. }
  197. // Slave marks the following operation on slave node.
  198. // Note that it makes sense only if there's any slave node configured.
  199. func (d *InstrumentDao) Slave() *InstrumentDao {
  200. return &InstrumentDao{M: d.M.Slave()}
  201. }
  202. // Args sets custom arguments for model operation.
  203. func (d *InstrumentDao) Args(args ...interface{}) *InstrumentDao {
  204. return &InstrumentDao{M: d.M.Args(args...)}
  205. }
  206. // LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
  207. // The parameter <table> can be joined table and its joined condition,
  208. // and also with its alias name, like:
  209. // Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
  210. // Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
  211. func (d *InstrumentDao) LeftJoin(table ...string) *InstrumentDao {
  212. return &InstrumentDao{M: d.M.LeftJoin(table...)}
  213. }
  214. // RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
  215. // The parameter <table> can be joined table and its joined condition,
  216. // and also with its alias name, like:
  217. // Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
  218. // Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
  219. func (d *InstrumentDao) RightJoin(table ...string) *InstrumentDao {
  220. return &InstrumentDao{M: d.M.RightJoin(table...)}
  221. }
  222. // InnerJoin does "INNER JOIN ... ON ..." statement on the model.
  223. // The parameter <table> can be joined table and its joined condition,
  224. // and also with its alias name, like:
  225. // Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
  226. // Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
  227. func (d *InstrumentDao) InnerJoin(table ...string) *InstrumentDao {
  228. return &InstrumentDao{M: d.M.InnerJoin(table...)}
  229. }
  230. // Fields sets the operation fields of the model, multiple fields joined using char ','.
  231. // The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
  232. func (d *InstrumentDao) Fields(fieldNamesOrMapStruct ...interface{}) *InstrumentDao {
  233. return &InstrumentDao{M: d.M.Fields(fieldNamesOrMapStruct...)}
  234. }
  235. // FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
  236. // The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
  237. func (d *InstrumentDao) FieldsEx(fieldNamesOrMapStruct ...interface{}) *InstrumentDao {
  238. return &InstrumentDao{M: d.M.FieldsEx(fieldNamesOrMapStruct...)}
  239. }
  240. // Option sets the extra operation option for the model.
  241. func (d *InstrumentDao) Option(option int) *InstrumentDao {
  242. return &InstrumentDao{M: d.M.Option(option)}
  243. }
  244. // OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
  245. // the data and where attributes for empty values.
  246. func (d *InstrumentDao) OmitEmpty() *InstrumentDao {
  247. return &InstrumentDao{M: d.M.OmitEmpty()}
  248. }
  249. // Filter marks filtering the fields which does not exist in the fields of the operated table.
  250. func (d *InstrumentDao) Filter() *InstrumentDao {
  251. return &InstrumentDao{M: d.M.Filter()}
  252. }
  253. // Where sets the condition statement for the model. The parameter <where> can be type of
  254. // string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
  255. // multiple conditions will be joined into where statement using "AND".
  256. // Eg:
  257. // Where("uid=10000")
  258. // Where("uid", 10000)
  259. // Where("money>? AND name like ?", 99999, "vip_%")
  260. // Where("uid", 1).Where("name", "john")
  261. // Where("status IN (?)", g.Slice{1,2,3})
  262. // Where("age IN(?,?)", 18, 50)
  263. // Where(User{ Id : 1, UserName : "john"})
  264. func (d *InstrumentDao) Where(where interface{}, args ...interface{}) *InstrumentDao {
  265. return &InstrumentDao{M: d.M.Where(where, args...)}
  266. }
  267. // WherePri does the same logic as M.Where except that if the parameter <where>
  268. // is a single condition like int/string/float/slice, it treats the condition as the primary
  269. // key value. That is, if primary key is "id" and given <where> parameter as "123", the
  270. // WherePri function treats the condition as "id=123", but M.Where treats the condition
  271. // as string "123".
  272. func (d *InstrumentDao) WherePri(where interface{}, args ...interface{}) *InstrumentDao {
  273. return &InstrumentDao{M: d.M.WherePri(where, args...)}
  274. }
  275. // And adds "AND" condition to the where statement.
  276. func (d *InstrumentDao) And(where interface{}, args ...interface{}) *InstrumentDao {
  277. return &InstrumentDao{M: d.M.And(where, args...)}
  278. }
  279. // Or adds "OR" condition to the where statement.
  280. func (d *InstrumentDao) Or(where interface{}, args ...interface{}) *InstrumentDao {
  281. return &InstrumentDao{M: d.M.Or(where, args...)}
  282. }
  283. // Group sets the "GROUP BY" statement for the model.
  284. func (d *InstrumentDao) Group(groupBy string) *InstrumentDao {
  285. return &InstrumentDao{M: d.M.Group(groupBy)}
  286. }
  287. // Order sets the "ORDER BY" statement for the model.
  288. func (d *InstrumentDao) Order(orderBy ...string) *InstrumentDao {
  289. return &InstrumentDao{M: d.M.Order(orderBy...)}
  290. }
  291. // Limit sets the "LIMIT" statement for the model.
  292. // The parameter <limit> can be either one or two number, if passed two number is passed,
  293. // it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
  294. // statement.
  295. func (d *InstrumentDao) Limit(limit ...int) *InstrumentDao {
  296. return &InstrumentDao{M: d.M.Limit(limit...)}
  297. }
  298. // Offset sets the "OFFSET" statement for the model.
  299. // It only makes sense for some databases like SQLServer, PostgreSQL, etc.
  300. func (d *InstrumentDao) Offset(offset int) *InstrumentDao {
  301. return &InstrumentDao{M: d.M.Offset(offset)}
  302. }
  303. // Page sets the paging number for the model.
  304. // The parameter <page> is started from 1 for paging.
  305. // Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
  306. func (d *InstrumentDao) Page(page, limit int) *InstrumentDao {
  307. return &InstrumentDao{M: d.M.Page(page, limit)}
  308. }
  309. // Batch sets the batch operation number for the model.
  310. func (d *InstrumentDao) Batch(batch int) *InstrumentDao {
  311. return &InstrumentDao{M: d.M.Batch(batch)}
  312. }
  313. // Cache sets the cache feature for the model. It caches the result of the sql, which means
  314. // if there's another same sql request, it just reads and returns the result from cache, it
  315. // but not committed and executed into the database.
  316. //
  317. // If the parameter <duration> < 0, which means it clear the cache with given <name>.
  318. // If the parameter <duration> = 0, which means it never expires.
  319. // If the parameter <duration> > 0, which means it expires after <duration>.
  320. //
  321. // The optional parameter <name> is used to bind a name to the cache, which means you can later
  322. // control the cache like changing the <duration> or clearing the cache with specified <name>.
  323. //
  324. // Note that, the cache feature is disabled if the model is operating on a transaction.
  325. func (d *InstrumentDao) Cache(duration time.Duration, name ...string) *InstrumentDao {
  326. return &InstrumentDao{M: d.M.Cache(duration, name...)}
  327. }
  328. // Data sets the operation data for the model.
  329. // The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
  330. // Eg:
  331. // Data("uid=10000")
  332. // Data("uid", 10000)
  333. // Data(g.Map{"uid": 10000, "name":"john"})
  334. // Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
  335. func (d *InstrumentDao) Data(data ...interface{}) *InstrumentDao {
  336. return &InstrumentDao{M: d.M.Data(data...)}
  337. }
  338. // All does "SELECT FROM ..." statement for the model.
  339. // It retrieves the records from table and returns the result as []*model.Instrument.
  340. // It returns nil if there's no record retrieved with the given conditions from table.
  341. //
  342. // The optional parameter <where> is the same as the parameter of M.Where function,
  343. // see M.Where.
  344. func (d *InstrumentDao) All(where ...interface{}) ([]*model2.Instrument, error) {
  345. all, err := d.M.All(where...)
  346. if err != nil {
  347. return nil, err
  348. }
  349. var entities []*model2.Instrument
  350. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  351. return nil, err
  352. }
  353. return entities, nil
  354. }
  355. // One retrieves one record from table and returns the result as *model.Instrument.
  356. // It returns nil if there's no record retrieved with the given conditions from table.
  357. //
  358. // The optional parameter <where> is the same as the parameter of M.Where function,
  359. // see M.Where.
  360. func (d *InstrumentDao) One(where ...interface{}) (*model2.Instrument, error) {
  361. one, err := d.M.One(where...)
  362. if err != nil {
  363. return nil, err
  364. }
  365. var entity *model2.Instrument
  366. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  367. return nil, err
  368. }
  369. return entity, nil
  370. }
  371. // FindOne retrieves and returns a single Record by M.WherePri and M.One.
  372. // Also see M.WherePri and M.One.
  373. func (d *InstrumentDao) FindOne(where ...interface{}) (*model2.Instrument, error) {
  374. one, err := d.M.FindOne(where...)
  375. if err != nil {
  376. return nil, err
  377. }
  378. var entity *model2.Instrument
  379. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  380. return nil, err
  381. }
  382. return entity, nil
  383. }
  384. // FindAll retrieves and returns Result by by M.WherePri and M.All.
  385. // Also see M.WherePri and M.All.
  386. func (d *InstrumentDao) FindAll(where ...interface{}) ([]*model2.Instrument, error) {
  387. all, err := d.M.FindAll(where...)
  388. if err != nil {
  389. return nil, err
  390. }
  391. var entities []*model2.Instrument
  392. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  393. return nil, err
  394. }
  395. return entities, nil
  396. }
  397. // Struct retrieves one record from table and converts it into given struct.
  398. // The parameter <pointer> should be type of *struct/**struct. If type **struct is given,
  399. // it can create the struct internally during converting.
  400. //
  401. // The optional parameter <where> is the same as the parameter of Model.Where function,
  402. // see Model.Where.
  403. //
  404. // Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
  405. // from table and <pointer> is not nil.
  406. //
  407. // Eg:
  408. // user := new(User)
  409. // err := dao.User.Where("id", 1).Struct(user)
  410. //
  411. // user := (*User)(nil)
  412. // err := dao.User.Where("id", 1).Struct(&user)
  413. func (d *InstrumentDao) Struct(pointer interface{}, where ...interface{}) error {
  414. return d.M.Struct(pointer, where...)
  415. }
  416. // Structs retrieves records from table and converts them into given struct slice.
  417. // The parameter <pointer> should be type of *[]struct/*[]*struct. It can create and fill the struct
  418. // slice internally during converting.
  419. //
  420. // The optional parameter <where> is the same as the parameter of Model.Where function,
  421. // see Model.Where.
  422. //
  423. // Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
  424. // from table and <pointer> is not empty.
  425. //
  426. // Eg:
  427. // users := ([]User)(nil)
  428. // err := dao.User.Structs(&users)
  429. //
  430. // users := ([]*User)(nil)
  431. // err := dao.User.Structs(&users)
  432. func (d *InstrumentDao) Structs(pointer interface{}, where ...interface{}) error {
  433. return d.M.Structs(pointer, where...)
  434. }
  435. // Scan automatically calls Struct or Structs function according to the type of parameter <pointer>.
  436. // It calls function Struct if <pointer> is type of *struct/**struct.
  437. // It calls function Structs if <pointer> is type of *[]struct/*[]*struct.
  438. //
  439. // The optional parameter <where> is the same as the parameter of Model.Where function,
  440. // see Model.Where.
  441. //
  442. // Note that it returns sql.ErrNoRows if there's no record retrieved and given pointer is not empty or nil.
  443. //
  444. // Eg:
  445. // user := new(User)
  446. // err := dao.User.Where("id", 1).Scan(user)
  447. //
  448. // user := (*User)(nil)
  449. // err := dao.User.Where("id", 1).Scan(&user)
  450. //
  451. // users := ([]User)(nil)
  452. // err := dao.User.Scan(&users)
  453. //
  454. // users := ([]*User)(nil)
  455. // err := dao.User.Scan(&users)
  456. func (d *InstrumentDao) Scan(pointer interface{}, where ...interface{}) error {
  457. return d.M.Scan(pointer, where...)
  458. }
  459. // Chunk iterates the table with given size and callback function.
  460. func (d *InstrumentDao) Chunk(limit int, callback func(entities []*model2.Instrument, err error) bool) {
  461. d.M.Chunk(limit, func(result gdb.Result, err error) bool {
  462. var entities []*model2.Instrument
  463. err = result.Structs(&entities)
  464. if err == sql.ErrNoRows {
  465. return false
  466. }
  467. return callback(entities, err)
  468. })
  469. }
  470. // LockUpdate sets the lock for update for current operation.
  471. func (d *InstrumentDao) LockUpdate() *InstrumentDao {
  472. return &InstrumentDao{M: d.M.LockUpdate()}
  473. }
  474. // LockShared sets the lock in share mode for current operation.
  475. func (d *InstrumentDao) LockShared() *InstrumentDao {
  476. return &InstrumentDao{M: d.M.LockShared()}
  477. }
  478. // Unscoped enables/disables the soft deleting feature.
  479. func (d *InstrumentDao) Unscoped() *InstrumentDao {
  480. return &InstrumentDao{M: d.M.Unscoped()}
  481. }