From ecfa5126c2d894003163429f12e87bc46775866a Mon Sep 17 00:00:00 2001 From: pqyt64hnf <2543568107@qq.com> Date: Sun, 30 Apr 2023 01:17:16 +0800 Subject: [PATCH] ADD file via upload --- .../com/service/FoodsMenuInfoService.java | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/main/java/com/service/FoodsMenuInfoService.java diff --git a/src/main/java/com/service/FoodsMenuInfoService.java b/src/main/java/com/service/FoodsMenuInfoService.java new file mode 100644 index 0000000..8122935 --- /dev/null +++ b/src/main/java/com/service/FoodsMenuInfoService.java @@ -0,0 +1,80 @@ +package com.example.service; + +import cn.hutool.core.collection.CollectionUtil; +import com.example.dao.CollectInfoDao; +import com.example.dao.FoodsMenuInfoDao; +import com.example.dao.PraiseInfoDao; +import com.example.entity.FoodsMenuInfo; +import com.example.vo.FoodsMenuInfoVo; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +@Service +public class FoodsMenuInfoService { + + @Resource + private FoodsMenuInfoDao foodsMenuInfoDao; + @Resource + private PraiseInfoDao praiseInfoDao; + @Resource + private CollectInfoDao collectInfoDao; + + public FoodsMenuInfo add(FoodsMenuInfo info) { + foodsMenuInfoDao.insertSelective(info); + return info; + } + + public void delete(Long id) { + foodsMenuInfoDao.deleteByPrimaryKey(id); + } + + public void update(FoodsMenuInfo info) { + foodsMenuInfoDao.updateByPrimaryKeySelective(info); + } + + public FoodsMenuInfoVo findById(Long id) { + List list = foodsMenuInfoDao.findByNameAndId(null, id, null); + if (!CollectionUtil.isEmpty(list)) { + FoodsMenuInfoVo foodsMenuInfoVo = list.get(0); + Integer count = praiseInfoDao.count(null, id); + foodsMenuInfoVo.setPraiseCount(count); + + Integer collectCount = collectInfoDao.count(null, id); + foodsMenuInfoVo.setCollectCount(collectCount); + return foodsMenuInfoVo; + } + return new FoodsMenuInfoVo(); + } + + public List findAll() { + return foodsMenuInfoDao.findByNameAndId("all", null, null); + } + + public PageInfo findPage(String name, Long classifyId, Integer pageNum, Integer pageSize) { + PageHelper.startPage(pageNum, pageSize); + List info = foodsMenuInfoDao.findByNameAndId(name, null, classifyId); + for (FoodsMenuInfoVo foodsMenuInfoVo : info) { + Long id = foodsMenuInfoVo.getId(); + Integer count = praiseInfoDao.count(null, id); + foodsMenuInfoVo.setPraiseCount(count); + + Integer collectCount = collectInfoDao.count(null, id); + foodsMenuInfoVo.setCollectCount(collectCount); + } + // 按点赞数排序 + info = info.stream().sorted(Comparator.comparing(FoodsMenuInfoVo::getPraiseCount).reversed()).collect(Collectors.toList()); + return PageInfo.of(info); + } + + public PageInfo findPageByUser(String name, String username, Integer level, Integer pageNum, Integer pageSize) { + PageHelper.startPage(pageNum, pageSize); + List info = foodsMenuInfoDao.findByNameAndUser(name, username, level); + return PageInfo.of(info); + } +}