12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- package financial_analyst
- import (
- logger "eta/eta_mini_ht_api/common/component/log"
- "eta/eta_mini_ht_api/common/utils/page"
- financialAnalystDao "eta/eta_mini_ht_api/models/financial_analyst"
- )
- type FinancialAnalystDTO struct {
- Id int
- ETAId int
- Name string
- Position string
- InvestmentCertificate string
- ProfessionalCertificate string
- HeadImgUrl string
- HeadOriginImgUrl string
- Introduction string
- Status bool
- Deleted bool
- }
- func GetAnalystList(pageInfo page.PageInfo) (analystsDTO []FinancialAnalystDTO, err error) {
- offset := page.StartIndex(pageInfo.Current, pageInfo.PageSize)
- analystList, err := financialAnalystDao.GetAnalystList(pageInfo.LatestId, offset, pageInfo.PageSize)
- for _, analyst := range analystList {
- analystsDTO = append(analystsDTO, convertToBaseDTO(analyst))
- }
- return
- }
- func GetAnalystById(id int) (financialAnalyst FinancialAnalystDTO, err error) {
- analyst, err := financialAnalystDao.GetAnalystById(id)
- if err != nil {
- logger.Error("获取研究员失败: %v", err)
- return
- }
- financialAnalyst = convertToBaseDTO(analyst)
- return
- }
- func GetCount() (total int64, latestId int64) {
- return financialAnalystDao.GetCount()
- }
- func GetAnalystByName(name string) (financialAnalyst FinancialAnalystDTO, err error) {
- analyst, err := financialAnalystDao.GetAnalystByName(name)
- if err != nil {
- logger.Error("获取研究员失败: %v", err)
- return
- }
- financialAnalyst = convertToBaseDTO(analyst)
- return
- }
- func SyncAnalyst(list []FinancialAnalystDTO) (err error) {
- var financialAnalystList []financialAnalystDao.CrmFinancialAnalyst
- for _, dto := range list {
- financialAnalyst := convert(dto)
- financialAnalystList = append(financialAnalystList, financialAnalyst)
- }
- return financialAnalystDao.BatchInsertOrUpdate(financialAnalystList)
- }
- func convert(dto FinancialAnalystDTO) (financialAnalyst financialAnalystDao.CrmFinancialAnalyst) {
- var status financialAnalystDao.AnalystStatus
- if dto.Status {
- status = financialAnalystDao.AnalystStatusEnabled
- } else {
- status = financialAnalystDao.AnalystStatusDisabled
- }
- return financialAnalystDao.CrmFinancialAnalyst{
- ETAId: dto.ETAId,
- Name: dto.Name,
- Status: status,
- Deleted: dto.Deleted,
- }
- }
- func convertToBaseDTO(financialAnalyst financialAnalystDao.CrmFinancialAnalyst) (dto FinancialAnalystDTO) {
- return FinancialAnalystDTO{
- Id: financialAnalyst.Id,
- ETAId: financialAnalyst.ETAId,
- HeadImgUrl: financialAnalyst.HeadImgURL,
- HeadOriginImgUrl: financialAnalyst.HeadOriginImgUrl,
- Name: financialAnalyst.Name,
- Introduction: financialAnalyst.Introduction,
- ProfessionalCertificate: financialAnalyst.ProfessionalCertificate,
- InvestmentCertificate: financialAnalyst.InvestmentCertificate,
- Position: financialAnalyst.Position,
- }
- }
|