system.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package system
  2. import (
  3. "lims_adapter/dao"
  4. "lims_adapter/model"
  5. "strconv"
  6. )
  7. type Service struct {
  8. Dao *dao.BaseItemdetailsDao
  9. Tenant string
  10. }
  11. // NewSrv 服务初始化
  12. func NewSrv(tenant string) Service {
  13. return Service{Dao: dao.NewBaseItemdetailsDao(tenant), Tenant: tenant}
  14. }
  15. // DictInfo 获取字典数据
  16. func(s Service) DictInfo(req *model.DictReq) (dictInfo []model.BaseItemdetails, err error) {
  17. where := "DictCode = '" + req.DictCode + "' and Enabled = 1"
  18. if req.ItemName != "" {
  19. where += " and ItemName = '" + req.ItemName + "'"
  20. }
  21. if req.ItemValue != "" {
  22. where += " and ItemValue = '" + req.ItemValue + "'"
  23. }
  24. if req.SortCode != "" {
  25. where += " and SortCode = '" + req.SortCode + "'"
  26. }
  27. err = s.Dao.M.Where(where).Scan(&dictInfo)
  28. if err != nil {
  29. return dictInfo, err
  30. }
  31. return dictInfo, nil
  32. }
  33. // UserList 获取用户信息
  34. func (s Service) UserList(req *model.UserInfoReq) (userInfos model.UserInfoRsp,err error) {
  35. where := "Enabled = 1"
  36. departmentId := strconv.Itoa(req.DepartmentId)
  37. instrumentId := strconv.Itoa(req.InstrumentId)
  38. current:= req.PageNun
  39. size:= req.PageSize
  40. count := 0
  41. model := s.Dao.DB.Model("base_user a")
  42. if departmentId != "" && departmentId != "0"{
  43. where += " and DepartmentId = " + departmentId
  44. }
  45. if req.ReqType == 1 { // 预约资格
  46. count, err = model.Where(where).Count()
  47. }else if req.ReqType == 2 { // 优先预约权
  48. where += " and Id not in(select UserId from base_equipment_qualification where EquipmentId = "+
  49. instrumentId +" and Qualification in (0,3))"
  50. count, err = model.Where(where).Count()
  51. }
  52. if err != nil {
  53. return userInfos, err
  54. }
  55. userInfos.Total = count
  56. model.Page(current, size).Scan(&userInfos.Records)
  57. return userInfos, nil
  58. }