diff --git a/src/main/java/com/service/FoodsMaterialInfoService.java b/src/main/java/com/service/FoodsMaterialInfoService.java new file mode 100644 index 0000000..08d9175 --- /dev/null +++ b/src/main/java/com/service/FoodsMaterialInfoService.java @@ -0,0 +1,50 @@ +package com.example.service; + +import cn.hutool.core.collection.CollectionUtil; +import com.example.dao.FoodsMaterialInfoDao; +import com.example.entity.FoodsMaterialInfo; +import com.example.vo.FoodsMaterialInfoVo; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +@Service +public class FoodsMaterialInfoService { + + @Resource + private FoodsMaterialInfoDao foodsMaterialInfoDao; + + public FoodsMaterialInfo add(FoodsMaterialInfo info) { + foodsMaterialInfoDao.insertSelective(info); + return info; + } + + public void delete(Long id) { + foodsMaterialInfoDao.deleteByPrimaryKey(id); + } + + public void update(FoodsMaterialInfo info) { + foodsMaterialInfoDao.updateByPrimaryKeySelective(info); + } + + public FoodsMaterialInfoVo findById(Long id) { + List list = foodsMaterialInfoDao.findByNameAndId(null, id); + if (!CollectionUtil.isEmpty(list)) { + return list.get(0); + } + return new FoodsMaterialInfoVo(); + } + + public List findAll() { + return foodsMaterialInfoDao.findByNameAndId("all", null); + } + + public PageInfo findPage(String name, Integer pageNum, Integer pageSize) { + PageHelper.startPage(pageNum, pageSize); + List info = foodsMaterialInfoDao.findByNameAndId(name, null); + return PageInfo.of(info); + } +}