|
@@ -2,15 +2,16 @@ package com.caimei365.commodity.service.impl;
|
|
|
|
|
|
import com.caimei365.commodity.mapper.ProcureRepository;
|
|
|
import com.caimei365.commodity.model.po.ProcurePo;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.PageImpl;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
-import org.springframework.data.mongodb.core.aggregation.Aggregation;
|
|
|
-import org.springframework.data.mongodb.core.aggregation.LookupOperation;
|
|
|
import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
import org.springframework.data.mongodb.core.query.Query;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -22,15 +23,18 @@ import java.util.List;
|
|
|
@Service
|
|
|
public class ProcureService {
|
|
|
|
|
|
- @Autowired private ProcureRepository procureRepository;
|
|
|
- @Autowired private MongoTemplate mongoTemplate;
|
|
|
+ @Resource
|
|
|
+ private ProcureRepository procureRepository;
|
|
|
+ @Resource
|
|
|
+ private MongoTemplate mongoTemplate;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 保存
|
|
|
+ *
|
|
|
* @param procure
|
|
|
*/
|
|
|
- public void save(ProcurePo procure){
|
|
|
+ public void save(ProcurePo procure) {
|
|
|
//如果需要自定义主键,可以在这里指定主键;如果不指定主键,MongoDB会自动生成主键
|
|
|
//设置一些默认初始值。。。
|
|
|
//调用dao
|
|
@@ -39,47 +43,55 @@ public class ProcureService {
|
|
|
|
|
|
/**
|
|
|
* 修改
|
|
|
+ *
|
|
|
* @param procure
|
|
|
*/
|
|
|
- public void update(ProcurePo procure){
|
|
|
+ public void update(ProcurePo procure) {
|
|
|
//调用dao
|
|
|
procureRepository.save(procure);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据id删除
|
|
|
+ *
|
|
|
* @param id
|
|
|
*/
|
|
|
- public void deleteById(String id){
|
|
|
+ public void deleteById(String id) {
|
|
|
//调用dao
|
|
|
procureRepository.deleteById(id);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询所有集采
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<ProcurePo> findList(int pageNo, int pageSize){
|
|
|
+ public List<ProcurePo> findList(int pageNo, int pageSize) {
|
|
|
//调用dao
|
|
|
+ Pageable pageable = PageRequest.of(pageNo, pageSize);
|
|
|
Query query = new Query();
|
|
|
query.addCriteria(Criteria.where("delFlag").is("0"));
|
|
|
query.with(Sort.by(Sort.Direction.DESC, "saveTime"));
|
|
|
- query.limit(pageSize);
|
|
|
- query.skip(pageSize * (pageNo - 1));
|
|
|
- return mongoTemplate.find(query, ProcurePo.class);
|
|
|
+ List<ProcurePo> procurePos = mongoTemplate.find(query.with(pageable), ProcurePo.class);
|
|
|
+// long count1 = mongoTemplate.count(query, ProcurePo.class);
|
|
|
+// PageImpl<ProcurePo> procurePos1 = new PageImpl<>(procurePos, pageable, count1);
|
|
|
+ return procurePos;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 根据id查询
|
|
|
+ *
|
|
|
* @param id
|
|
|
* @return
|
|
|
*/
|
|
|
- public ProcurePo findById(String id){
|
|
|
+ public ProcurePo findById(String id) {
|
|
|
//调用dao
|
|
|
return procureRepository.findById(id).get();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 我参与的集采
|
|
|
+ *
|
|
|
* @param userId
|
|
|
* @return
|
|
|
*/
|
|
@@ -98,6 +110,7 @@ public class ProcureService {
|
|
|
|
|
|
/**
|
|
|
* 我发起的集采
|
|
|
+ *
|
|
|
* @param userId
|
|
|
* @return
|
|
|
*/
|