|
@@ -1,11 +1,14 @@
|
|
|
package com.caimei.modules.groupbuy.service;
|
|
|
|
|
|
|
|
|
+import com.caimei.modules.club.entity.CmUser;
|
|
|
import com.caimei.modules.club.entity.Page;
|
|
|
import com.caimei.modules.groupbuy.dao.ProcureRepository;
|
|
|
import com.caimei.modules.groupbuy.entity.AdditionalPo;
|
|
|
import com.caimei.modules.groupbuy.entity.BuyerDto;
|
|
|
import com.caimei.modules.groupbuy.entity.ProcurePo;
|
|
|
+import com.caimei.modules.shiro.dao.UserDao;
|
|
|
+import com.caimei.utils.ResponseJson;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.data.domain.PageImpl;
|
|
@@ -16,12 +19,12 @@ import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.data.mongodb.core.query.Query;
|
|
|
+import sun.util.calendar.BaseCalendar;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import javax.xml.ws.Response;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
@Service
|
|
@@ -33,6 +36,9 @@ public class ProcureService {
|
|
|
private MongoTemplate mongoTemplate;
|
|
|
@Resource
|
|
|
private AdditionalService additionalService;
|
|
|
+ @Resource
|
|
|
+ private UserDao userDao;
|
|
|
+
|
|
|
/**
|
|
|
* 保存
|
|
|
*
|
|
@@ -134,16 +140,27 @@ public class ProcureService {
|
|
|
}
|
|
|
|
|
|
public Page<BuyerDto> findBuyListByPro(BuyerDto dto, Integer pageNum, Integer pageSize) {
|
|
|
- Pageable pageable = PageRequest.of(pageNum, pageSize);
|
|
|
+ Pageable pageable = PageRequest.of(pageNum - 1, pageSize);
|
|
|
Query query = new Query();
|
|
|
- Criteria criteria = setCriteriaVal(dto);
|
|
|
- query.addCriteria(criteria).with(Sort.by(Sort.Direction.DESC, "saveTime")).with(pageable);
|
|
|
+ setCriteriaVal(query, dto);
|
|
|
+ query.with(Sort.by(Sort.Direction.DESC, "saveTime")).with(pageable);
|
|
|
List<ProcurePo> procurePos = mongoTemplate.find(query, ProcurePo.class);
|
|
|
List<BuyerDto> buyerDtos = new ArrayList<>();
|
|
|
+ // 定义格式化字符串
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
procurePos.forEach(p -> {
|
|
|
BuyerDto buyerDto = new BuyerDto();
|
|
|
+ Date date = new Date(Long.parseLong(p.getSaveTime()));
|
|
|
+ p.setSaveTime(dateFormat.format(date));
|
|
|
int count = (int) mongoTemplate.count(Query.query(Criteria.where("procureId").is(p.getId())), AdditionalPo.class);
|
|
|
+ CmUser linkMan = userDao.findLinkMan(p.getUserId());
|
|
|
+ buyerDto.setLinkMan(linkMan.getLinkMan());
|
|
|
+ buyerDto.setMobile(linkMan.getMobile());
|
|
|
buyerDto.setClubCount(count);
|
|
|
+ // 1未完成 2已完成 3已删除
|
|
|
+ Integer status = "0".equals(p.getIsAchieve()) ? 1 : 2;
|
|
|
+ status = !"0".equals(p.getDelFlag()) ? 3 : status;
|
|
|
+ buyerDto.setStatus(status);
|
|
|
BeanUtils.copyProperties(p, buyerDto);
|
|
|
buyerDtos.add(buyerDto);
|
|
|
});
|
|
@@ -165,30 +182,31 @@ public class ProcureService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public Criteria setCriteriaVal(BuyerDto dto) {
|
|
|
- Criteria criteria = new Criteria();
|
|
|
+ public Query setCriteriaVal(Query query, BuyerDto dto) {
|
|
|
+ // 发布者有创建者id
|
|
|
+ query.addCriteria(Criteria.where("createUserId").ne(null));
|
|
|
if (StringUtils.isNotBlank(dto.getClubName())) {
|
|
|
Pattern pattern = Pattern.compile("^.*" + dto.getClubName() + ".*$", Pattern.CASE_INSENSITIVE);
|
|
|
- criteria.andOperator(Criteria.where("clubName").regex(pattern));
|
|
|
+ query.addCriteria(Criteria.where("clubName").regex(pattern));
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(dto.getProductName())) {
|
|
|
Pattern pattern = Pattern.compile("^.*" + dto.getProductName() + ".*$", Pattern.CASE_INSENSITIVE);
|
|
|
- criteria.andOperator(Criteria.where("productName").regex(pattern));
|
|
|
+ query.addCriteria(Criteria.where("productName").regex(pattern));
|
|
|
}
|
|
|
if (null != dto.getStatus()) {
|
|
|
if (3 == dto.getStatus()) {
|
|
|
- criteria.andOperator(Criteria.where("delFlag").is("1"));
|
|
|
+ query.addCriteria(Criteria.where("delFlag").is("1"));
|
|
|
} else {
|
|
|
- criteria.andOperator(Criteria.where("isAchieve").is(dto.getStatus().toString()));
|
|
|
+ query.addCriteria(Criteria.where("isAchieve").is(dto.getStatus().toString()));
|
|
|
}
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(dto.getStartSaveTime())) {
|
|
|
- criteria.andOperator(Criteria.where("saveTime").gte(dto.getStartSaveTime()));
|
|
|
+ query.addCriteria(Criteria.where("saveTime").gte(dto.getStartSaveTime()));
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(dto.getEndSaveTime())) {
|
|
|
- criteria.andOperator(Criteria.where("saveTime")).lte(dto.getEndSaveTime());
|
|
|
+ query.addCriteria(Criteria.where("saveTime").lte(dto.getEndSaveTime()));
|
|
|
}
|
|
|
- return criteria;
|
|
|
+ return query;
|
|
|
}
|
|
|
|
|
|
public Map<String, Object> findDetail(String id) {
|
|
@@ -197,13 +215,20 @@ public class ProcureService {
|
|
|
// 参与者
|
|
|
List<AdditionalPo> procureById = additionalService.findProcureById(byId.getId());
|
|
|
List<ProcurePo> procurePos = new ArrayList<>();
|
|
|
- procureById.forEach(p->{
|
|
|
+ procureById.forEach(p -> {
|
|
|
ProcurePo byId1 = findById(p.getProcureId());
|
|
|
procurePos.add(byId1);
|
|
|
});
|
|
|
Map<String, Object> map = new HashMap<>(2);
|
|
|
- map.put("publishMan",byId);
|
|
|
- map.put("followMan",procurePos);
|
|
|
+ map.put("publishMan", byId);
|
|
|
+ map.put("followMan", procurePos);
|
|
|
return map;
|
|
|
}
|
|
|
+
|
|
|
+ public ResponseJson checkDone(String id) {
|
|
|
+ ProcurePo byId = findById(id);
|
|
|
+ byId.setIsAchieve("1");
|
|
|
+ update(byId);
|
|
|
+ return ResponseJson.success();
|
|
|
+ }
|
|
|
}
|