query.go 657 B

123456789101112131415161718192021222324
  1. package company
  2. import (
  3. "errors"
  4. "hongze/hongze_yb/global"
  5. "hongze/hongze_yb/utils"
  6. )
  7. // GetByCompanyId 根据客户id获取信息
  8. func GetByCompanyId(companyId int64) (item *Company, err error) {
  9. err = global.DEFAULT_MYSQL.Where("company_id = ? ", companyId).First(&item).Error
  10. return
  11. }
  12. // GetByWhereMap 根据查询条件map获取信息
  13. func GetByWhereMap(where map[string]interface{}) (item *Company, err error) {
  14. cond, whereVal, buildErr := utils.WhereBuild(where)
  15. if buildErr != nil {
  16. err = errors.New("系统异常,生成查询语句失败")
  17. return
  18. }
  19. err = global.DEFAULT_MYSQL.Where(cond, whereVal...).First(&item).Error
  20. return
  21. }