You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
SRuml/GoodsService.java

101 lines
2.3 KiB

package com.example.service;
import com.example.common.enums.RoleEnum;
import com.example.entity.Account;
import com.example.entity.Goods;
import com.example.mapper.GoodsMapper;
import com.example.utils.TokenUtils;
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 GoodsService {
@Resource
private GoodsMapper goodsMapper;
/**
* 新增
*/
public void add(Goods goods) {
Account currentUser = TokenUtils.getCurrentUser();
if (RoleEnum.BUSINESS.name().equals(currentUser.getRole())) {
goods.setBusinessId(currentUser.getId());
}
goodsMapper.insert(goods);
}
/**
* 删除
*/
public void deleteById(Integer id) {
goodsMapper.deleteById(id);
}
/**
* 批量删除
*/
public void deleteBatch(List<Integer> ids) {
for (Integer id : ids) {
goodsMapper.deleteById(id);
}
}
/**
* 修改
*/
public void updateById(Goods goods) {
goodsMapper.updateById(goods);
}
/**
* 根据ID查询
*/
public Goods selectById(Integer id) {
return goodsMapper.selectById(id);
}
/**
* 查询所有
*/
public List<Goods> selectAll(Goods goods) {
return goodsMapper.selectAll(goods);
}
/**
* 分页查询
*/
public PageInfo<Goods> selectPage(Goods goods, Integer pageNum, Integer pageSize) {
Account currentUser = TokenUtils.getCurrentUser();
if (RoleEnum.BUSINESS.name().equals(currentUser.getRole())) {
goods.setBusinessId(currentUser.getId());
}
PageHelper.startPage(pageNum, pageSize);
List<Goods> list = goodsMapper.selectAll(goods);
return PageInfo.of(list);
}
public List<Goods> selectTop15() {
return goodsMapper.selectTop15();
}
public List<Goods> selectByTypeId(Integer id) {
return goodsMapper.selectByTypeId(id);
}
public List<Goods> selectByBusinessId(Integer id) {
return goodsMapper.selectByBusinessId(id);
}
public List<Goods> selectByName(String name) {
return goodsMapper.selectByName(name);
}
}