From 8839fbbe73d2fc3e5f0dbf25044b1ee9c48e064b Mon Sep 17 00:00:00 2001 From: pqyt64hnf <2543568107@qq.com> Date: Sun, 30 Apr 2023 01:19:07 +0800 Subject: [PATCH] ADD file via upload --- .../java/com/service/PraiseInfoService.java | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/main/java/com/service/PraiseInfoService.java diff --git a/src/main/java/com/service/PraiseInfoService.java b/src/main/java/com/service/PraiseInfoService.java new file mode 100644 index 0000000..92ce979 --- /dev/null +++ b/src/main/java/com/service/PraiseInfoService.java @@ -0,0 +1,68 @@ +package com.example.service; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.json.JSONUtil; +import com.example.dao.PraiseInfoDao; +import com.example.exception.CustomException; +import org.springframework.stereotype.Service; +import com.example.entity.PraiseInfo; +import com.example.entity.AuthorityInfo; +import com.example.entity.Account; +import com.example.vo.PraiseInfoVo; + +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; +import java.util.Date; +import java.util.List; + +@Service +public class PraiseInfoService { + + @Resource + private PraiseInfoDao praiseInfoDao; + + public PraiseInfo add(PraiseInfo praiseInfo, HttpServletRequest request) { + HttpSession session = request.getSession(); + Account user = (Account) session.getAttribute("user"); + PraiseInfoVo praiseInfoVo = praiseInfoDao.findByUser(user, praiseInfo); + if (praiseInfoVo != null) { + return null; + } + praiseInfo.setUserId(user.getId()); + praiseInfo.setLevel(user.getLevel()); + praiseInfo.setTime(DateUtil.now()); + praiseInfoDao.insertSelective(praiseInfo); + return praiseInfo; + } + + public void delete(Long id) { + praiseInfoDao.deleteByPrimaryKey(id); + } + + public void update(PraiseInfo praiseInfo) { + praiseInfoDao.updateByPrimaryKeySelective(praiseInfo); + } + + public PraiseInfo findById(Long id) { + return praiseInfoDao.selectByPrimaryKey(id); + } + + public List findAll() { + return praiseInfoDao.findByName("all"); + } + + public PageInfo findPage(String name, Integer pageNum, Integer pageSize, HttpServletRequest request) { + PageHelper.startPage(pageNum, pageSize); + List all = findAllPage(request, name); + return PageInfo.of(all); + } + + public List findAllPage(HttpServletRequest request, String name) { + return praiseInfoDao.findByName(name); + } + +}