|
package service
|
|
import (
|
"aps_crm/model"
|
"aps_crm/model/request"
|
"aps_crm/pkg/ecode"
|
)
|
|
type ReportSourceService struct{}
|
|
func (ReportSourceService) AddReportSource(reportSource *model.ReportSource) int {
|
err := model.NewReportSourceSearch().Create(reportSource)
|
if err != nil {
|
return ecode.ReportSourceExist
|
}
|
|
return ecode.OK
|
}
|
|
func (ReportSourceService) DeleteReportSource(id int) int {
|
_, err := model.NewReportSourceSearch().SetId(id).Find()
|
if err != nil {
|
return ecode.ReportSourceNotExist
|
}
|
|
err = model.NewReportSourceSearch().SetId(id).Delete()
|
if err != nil {
|
return ecode.ReportSourceNotExist
|
}
|
return ecode.OK
|
}
|
|
func (ReportSourceService) GetReportSourceList() ([]*model.ReportSource, int) {
|
list, err := model.NewReportSourceSearch().FindAll()
|
if err != nil {
|
return nil, ecode.ReportSourceListErr
|
}
|
|
return list, ecode.OK
|
}
|
|
func (ReportSourceService) UpdateReportSource(reportSources []*request.UpdateReportSource) int {
|
for _, v := range reportSources {
|
// check reportSource exist
|
_, err := model.NewReportSourceSearch().SetId(v.Id).Find()
|
if err != nil {
|
return ecode.ReportSourceNotExist
|
}
|
|
err = model.NewReportSourceSearch().SetId(v.Id).Updates(map[string]interface{}{
|
"name": v.Name,
|
})
|
if err != nil {
|
return ecode.ReportSourceSetErr
|
}
|
}
|
|
return ecode.OK
|
}
|
|
func (ReportSourceService) GetReportSourceDetail(id int) (*model.ReportSource, int) {
|
reportSource, err := model.NewReportSourceSearch().SetId(id).Find()
|
if err != nil {
|
return nil, ecode.ReportSourceNotExist
|
}
|
|
return reportSource, ecode.OK
|
}
|