|
@@ -8,6 +8,7 @@ import com.izouma.dingdong.domain.backstage.Email;
|
|
|
import com.izouma.dingdong.domain.merchant.*;
|
|
import com.izouma.dingdong.domain.merchant.*;
|
|
|
import com.izouma.dingdong.dto.AppraisalMerDTO;
|
|
import com.izouma.dingdong.dto.AppraisalMerDTO;
|
|
|
import com.izouma.dingdong.enums.ApplyStatus;
|
|
import com.izouma.dingdong.enums.ApplyStatus;
|
|
|
|
|
+import com.izouma.dingdong.enums.GoodType;
|
|
|
import com.izouma.dingdong.exception.BusinessException;
|
|
import com.izouma.dingdong.exception.BusinessException;
|
|
|
import com.izouma.dingdong.repo.backstage.EmailRepo;
|
|
import com.izouma.dingdong.repo.backstage.EmailRepo;
|
|
|
import com.izouma.dingdong.repo.merchant.*;
|
|
import com.izouma.dingdong.repo.merchant.*;
|
|
@@ -17,9 +18,11 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -34,6 +37,7 @@ public class GoodsService {
|
|
|
private MerchantRepo merchantRepo;
|
|
private MerchantRepo merchantRepo;
|
|
|
private AppraisalService appraisalService;
|
|
private AppraisalService appraisalService;
|
|
|
private GoodsSpecificationRepo goodsSpecificationRepo;
|
|
private GoodsSpecificationRepo goodsSpecificationRepo;
|
|
|
|
|
+ private SalesRepo salesRepo;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 添加修改商品
|
|
* 添加修改商品
|
|
@@ -83,6 +87,12 @@ public class GoodsService {
|
|
|
goods.setEnabled(true);
|
|
goods.setEnabled(true);
|
|
|
//审核
|
|
//审核
|
|
|
goods.setIsPass(false);
|
|
goods.setIsPass(false);
|
|
|
|
|
+ //优先级
|
|
|
|
|
+ goods.setPriority(1);
|
|
|
|
|
+ //好评
|
|
|
|
|
+ goods.setPopularity(false);
|
|
|
|
|
+ //人气
|
|
|
|
|
+ goods.setPraise(false);
|
|
|
goods.setStatus(ApplyStatus.PENDING);
|
|
goods.setStatus(ApplyStatus.PENDING);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -224,17 +234,63 @@ public class GoodsService {
|
|
|
/*
|
|
/*
|
|
|
显示商品所有信息
|
|
显示商品所有信息
|
|
|
*/
|
|
*/
|
|
|
- public Map<String,Object> goodsAllInfo(Long goodsId){
|
|
|
|
|
|
|
+ public Map<String, Object> goodsAllInfo(Long goodsId) {
|
|
|
HashMap<String, Object> map = new HashMap<>();
|
|
HashMap<String, Object> map = new HashMap<>();
|
|
|
Goods goods = goodsRepo.findById(goodsId).orElseThrow(new BusinessException("无记录"));
|
|
Goods goods = goodsRepo.findById(goodsId).orElseThrow(new BusinessException("无记录"));
|
|
|
- map.put("goods",goods);
|
|
|
|
|
|
|
+ map.put("goods", goods);
|
|
|
|
|
|
|
|
List<AppraisalMerDTO> appraisals = appraisalService.goodsAppraisals(goodsId);
|
|
List<AppraisalMerDTO> appraisals = appraisalService.goodsAppraisals(goodsId);
|
|
|
- map.put("appraisal",appraisals);
|
|
|
|
|
|
|
+ map.put("appraisal", appraisals);
|
|
|
|
|
|
|
|
List<GoodsSpecification> specifications = goodsSpecificationRepo.findAllByGoodsId(goodsId);
|
|
List<GoodsSpecification> specifications = goodsSpecificationRepo.findAllByGoodsId(goodsId);
|
|
|
- map.put("specification",specifications);
|
|
|
|
|
|
|
+ map.put("specification", specifications);
|
|
|
|
|
|
|
|
return map;
|
|
return map;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /*
|
|
|
|
|
+ 商品列表
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<Goods> showAll(GoodType type) {
|
|
|
|
|
+
|
|
|
|
|
+ //用户3km以内的商品 3km以内的商户
|
|
|
|
|
+
|
|
|
|
|
+ List<Goods> goodsList = goodsRepo.findAll();
|
|
|
|
|
+
|
|
|
|
|
+ List<Goods> all = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ //(1000-距离)/1000*0.5 + 月销/10000*0.5 (月销大于10000按照10000计算)
|
|
|
|
|
+ switch (type) {
|
|
|
|
|
+ case PRAISE_FOOD:
|
|
|
|
|
+ all.addAll(goodsList.stream().filter(Goods::getSignboard)
|
|
|
|
|
+ .sorted((a, b) -> b.getPriority().compareTo(a.getPriority())).collect(Collectors.toList()));
|
|
|
|
|
+ case POPULAR_FOOD:
|
|
|
|
|
+ all.addAll(goodsList.stream().filter(Goods::getPopularity).collect(Collectors.toList()));
|
|
|
|
|
+ case SIGNBOARD_FOOD:
|
|
|
|
|
+ all.addAll(goodsList.stream().filter(Goods::getPraise).collect(Collectors.toList()));
|
|
|
|
|
+ }
|
|
|
|
|
+ for (Goods a : all) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ return all;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //更新商品优先级,每月1日更新
|
|
|
|
|
+ public void priority(Long goodsId) {
|
|
|
|
|
+ Goods goods = goodsRepo.findById(goodsId).orElseThrow(new BusinessException("无商品"));
|
|
|
|
|
+
|
|
|
|
|
+ LocalDate now = LocalDate.now();
|
|
|
|
|
+ //上个月日期
|
|
|
|
|
+ LocalDate lastMonth = now.minusMonths(1);
|
|
|
|
|
+ List<Sales> sales = salesRepo.findAllByGoodsIdAndDayBetween(goodsId, lastMonth, now);
|
|
|
|
|
+
|
|
|
|
|
+ //点赞数
|
|
|
|
|
+ Integer likes = 0;
|
|
|
|
|
+ //差评数
|
|
|
|
|
+ Integer badReview = 0;
|
|
|
|
|
+ for (Sales s : sales) {
|
|
|
|
|
+ likes += s.getDayLikes();
|
|
|
|
|
+ badReview += s.getDayBad();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|