// 模块模型操作接口-公司
// 秒寻科技
// zt 2024-02-01

package companyapi

import (
	"errors"
	"ipsomc/core/company/companymodel"
	"ipsomc/core/dao/mysql/mysqlapi"
)

type CompanyApi struct {
	MySqlApi mysqlapi.MySqlApi
}

// 查重
func (obj *CompanyApi) CheckCompany(dataModel *companymodel.Company) error {
	var count uint

	//查重
	if err := obj.MySqlApi.GetDb().Model(dataModel).Where("name=?", dataModel.Name).Count(&count).Error; err != nil {
		return err
	}
	if count > 0 {
		return errors.New("该公司已注册")
	}

	return nil
}

// 查询公司记录
func (obj *CompanyApi) GetCompanyById(dataModel *companymodel.Company) error {
	//根据域名获得项目ID
	if err := obj.MySqlApi.GetItemByID(dataModel); err != nil {
		return err
	}
	return nil
}
