|
|
@@ -18,8 +18,9 @@ func NewSrv(tenant string) Service {
|
|
|
return Service{ConsequentDao: dao.NewConsequentDao(tenant), ConsequentDetailDao: dao.NewConsequentDetailDao(tenant), Tenant: tenant}
|
|
|
}
|
|
|
|
|
|
-func (s Service) BatchInsertPapers(insertList []result_def.BatchInsertPapersReq, userInfo request.UserInfo) (int, int, []interface{}, error) {
|
|
|
+func (s Service) BatchInsertPapers(insertList []result_def.BatchInsertPapersReq, userInfo request.UserInfo) (int, int, int, []interface{}, error) {
|
|
|
failCount := 0
|
|
|
+ duplicatedCount := 0
|
|
|
failList := []interface{}{}
|
|
|
successCount := 0
|
|
|
|
|
|
@@ -35,12 +36,19 @@ func (s Service) BatchInsertPapers(insertList []result_def.BatchInsertPapersReq,
|
|
|
p.Entity.PublishTime = nil
|
|
|
}
|
|
|
|
|
|
- // FIXME 防止重复插入论文
|
|
|
+ // TODO 查询优化
|
|
|
+ // 防止重复插入论文
|
|
|
+ r, _ := s.ConsequentDetailDao.M.Where("PaperTopic=? or PaperPage=?", p.Detail.PaperTopic, p.Detail.PaperPage).Where("PaperPage!=''").One()
|
|
|
+ if len(r) > 0 {
|
|
|
+ duplicatedCount += 1
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
InsertId, err := s.ConsequentDao.M.InsertAndGetId(p.Entity)
|
|
|
if err == nil {
|
|
|
p.Detail.ConsequentId = int(InsertId)
|
|
|
_, err = s.ConsequentDetailDao.M.Insert(p.Detail)
|
|
|
- // 如果Detail插入失败则删除成果
|
|
|
+ // 如果Detail插入失败则删除成果主表记录
|
|
|
if err != nil {
|
|
|
s.ConsequentDao.Where("id=?", InsertId).Delete()
|
|
|
failCount += 1
|
|
|
@@ -59,5 +67,5 @@ func (s Service) BatchInsertPapers(insertList []result_def.BatchInsertPapersReq,
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
- return failCount, successCount, failList, nil
|
|
|
+ return failCount, successCount, duplicatedCount, failList, nil
|
|
|
}
|