commit
7323ba8817
@ -0,0 +1,122 @@
|
||||
package com.example.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 商家
|
||||
*/
|
||||
public class Business extends Account implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** ID */
|
||||
private Integer id;
|
||||
/** 用户名 */
|
||||
private String username;
|
||||
/** 密码 */
|
||||
private String password;
|
||||
/** 姓名 */
|
||||
private String name;
|
||||
/** 电话 */
|
||||
private String phone;
|
||||
/** 邮箱 */
|
||||
private String email;
|
||||
/** 头像 */
|
||||
private String avatar;
|
||||
/** 角色标识 */
|
||||
private String role;
|
||||
|
||||
private String description;
|
||||
|
||||
private String status;
|
||||
@Override
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getPhone() {
|
||||
return phone;
|
||||
}
|
||||
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAvatar() {
|
||||
return avatar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAvatar(String avatar) {
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRole(String role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
package com.example.controller;
|
||||
|
||||
import com.example.common.Result;
|
||||
import com.example.entity.Admin;
|
||||
import com.example.entity.Business;
|
||||
import com.example.service.AdminService;
|
||||
import com.example.service.BusinessService;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商家前端操作接口
|
||||
**/
|
||||
@RestController
|
||||
@RequestMapping("/business")
|
||||
public class BusinessController {
|
||||
|
||||
@Resource
|
||||
private BusinessService businessService;
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public Result add(@RequestBody Business business) {
|
||||
businessService.add(business);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public Result deleteById(@PathVariable Integer id) {
|
||||
businessService.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*/
|
||||
@DeleteMapping("/delete/batch")
|
||||
public Result deleteBatch(@RequestBody List<Integer> ids) {
|
||||
businessService.deleteBatch(ids);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
public Result updateById(@RequestBody Business business) {
|
||||
businessService.updateById(business);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
*/
|
||||
@GetMapping("/selectById/{id}")
|
||||
public Result selectById(@PathVariable Integer id) {
|
||||
Business business = businessService.selectById(id);
|
||||
return Result.success(business);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
*/
|
||||
@GetMapping("/selectAll")
|
||||
public Result selectAll(Business business ) {
|
||||
List<Business> list = businessService.selectAll(business);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@GetMapping("/selectPage")
|
||||
public Result selectPage(Business business,
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||
PageInfo<Business> page = businessService.selectPage(business, pageNum, pageSize);
|
||||
return Result.success(page);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package com.example.mapper;
|
||||
|
||||
import com.example.entity.Business;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 操作business相关数据接口
|
||||
*/
|
||||
public interface BusinessMapper {
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
int insert(Business business);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
int deleteById(Integer id);
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
int updateById(Business business);
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
*/
|
||||
Business selectById(Integer id);
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
*/
|
||||
List<Business> selectAll(Business business);
|
||||
|
||||
@Select("select * from business where username = #{username}")
|
||||
Business selectByUsername(String username);
|
||||
}
|
@ -0,0 +1,139 @@
|
||||
package com.example.service;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.example.common.Constants;
|
||||
import com.example.common.enums.ResultCodeEnum;
|
||||
import com.example.common.enums.RoleEnum;
|
||||
import com.example.common.enums.StatusEnum;
|
||||
import com.example.entity.Account;
|
||||
import com.example.entity.Business;
|
||||
import com.example.exception.CustomException;
|
||||
import com.example.mapper.BusinessMapper;
|
||||
import com.example.utils.TokenUtils;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商家业务处理
|
||||
**/
|
||||
@Service
|
||||
public class BusinessService {
|
||||
|
||||
@Resource
|
||||
private BusinessMapper businessMapper;
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public void add(Business business) {
|
||||
Business dbBusiness = businessMapper.selectByUsername(business.getUsername());
|
||||
if (ObjectUtil.isNotNull(dbBusiness)) {
|
||||
throw new CustomException(ResultCodeEnum.USER_EXIST_ERROR);
|
||||
}
|
||||
if (ObjectUtil.isEmpty(business.getPassword())) {
|
||||
business.setPassword(Constants.USER_DEFAULT_PASSWORD);
|
||||
}
|
||||
if (ObjectUtil.isEmpty(business.getName())) {
|
||||
business.setName(business.getUsername());
|
||||
}
|
||||
if (ObjectUtil.isEmpty(business.getStatus())) {
|
||||
business.setStatus(StatusEnum.CHECKEING.status);
|
||||
}
|
||||
business.setRole(RoleEnum.BUSINESS.name());
|
||||
businessMapper.insert(business);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public void deleteById(Integer id) {
|
||||
businessMapper.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*/
|
||||
public void deleteBatch(List<Integer> ids) {
|
||||
for (Integer id : ids) {
|
||||
businessMapper.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
public void updateById(Business business) {
|
||||
businessMapper.updateById(business);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
*/
|
||||
public Business selectById(Integer id) {
|
||||
return businessMapper.selectById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
*/
|
||||
public List<Business> selectAll(Business business) {
|
||||
return businessMapper.selectAll(business);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
public PageInfo<Business> selectPage(Business business, Integer pageNum, Integer pageSize) {
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
List<Business> list = businessMapper.selectAll(business);
|
||||
return PageInfo.of(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
public Account login(Account account) {
|
||||
Account dbBusiness = businessMapper.selectByUsername(account.getUsername());
|
||||
if (ObjectUtil.isNull(dbBusiness)) {
|
||||
throw new CustomException(ResultCodeEnum.USER_NOT_EXIST_ERROR);
|
||||
}
|
||||
if (!account.getPassword().equals(dbBusiness.getPassword())) {
|
||||
throw new CustomException(ResultCodeEnum.USER_ACCOUNT_ERROR);
|
||||
}
|
||||
// 生成token
|
||||
String tokenData = dbBusiness.getId() + "-" + RoleEnum.BUSINESS.name();
|
||||
String token = TokenUtils.createToken(tokenData, dbBusiness.getPassword());
|
||||
dbBusiness.setToken(token);
|
||||
return dbBusiness;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册
|
||||
*/
|
||||
public void register(Account account) {
|
||||
Business business = new Business();
|
||||
BeanUtils.copyProperties(account, business);
|
||||
add(business);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
*/
|
||||
public void updatePassword(Account account) {
|
||||
Business dbBusiness = businessMapper.selectByUsername(account.getUsername());
|
||||
if (ObjectUtil.isNull(dbBusiness)) {
|
||||
throw new CustomException(ResultCodeEnum.USER_NOT_EXIST_ERROR);
|
||||
}
|
||||
if (!account.getPassword().equals(dbBusiness.getPassword())) {
|
||||
throw new CustomException(ResultCodeEnum.PARAM_PASSWORD_ERROR);
|
||||
}
|
||||
dbBusiness.setPassword(account.getNewPassword());
|
||||
businessMapper.updateById(dbBusiness);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
package com.example.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 购物车信息表
|
||||
*/
|
||||
public class Cart implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Integer id;
|
||||
private Integer userId;
|
||||
private Integer businessId;
|
||||
private Integer goodsId;
|
||||
private Integer num;
|
||||
|
||||
private String businessName;
|
||||
private String goodsName;
|
||||
private String goodsImg;
|
||||
private String goodUnit;
|
||||
private Double goodsPrice;
|
||||
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Integer userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public Integer getBusinessId() {
|
||||
return businessId;
|
||||
}
|
||||
|
||||
public void setBusinessId(Integer businessId) {
|
||||
this.businessId = businessId;
|
||||
}
|
||||
|
||||
public Integer getGoodsId() {
|
||||
return goodsId;
|
||||
}
|
||||
|
||||
public void setGoodsId(Integer goodsId) {
|
||||
this.goodsId = goodsId;
|
||||
}
|
||||
|
||||
public String getBusinessName() {
|
||||
return businessName;
|
||||
}
|
||||
|
||||
public void setBusinessName(String businessName) {
|
||||
this.businessName = businessName;
|
||||
}
|
||||
|
||||
public String getGoodsName() {
|
||||
return goodsName;
|
||||
}
|
||||
|
||||
public void setGoodsName(String goodsName) {
|
||||
this.goodsName = goodsName;
|
||||
}
|
||||
|
||||
public String getGoodsImg() {
|
||||
return goodsImg;
|
||||
}
|
||||
|
||||
public void setGoodsImg(String goodsImg) {
|
||||
this.goodsImg = goodsImg;
|
||||
}
|
||||
|
||||
public String getGoodUnit() {
|
||||
return goodUnit;
|
||||
}
|
||||
|
||||
public void setGoodUnit(String goodUnit) {
|
||||
this.goodUnit = goodUnit;
|
||||
}
|
||||
|
||||
public Double getGoodsPrice() {
|
||||
return goodsPrice;
|
||||
}
|
||||
|
||||
public void setGoodsPrice(Double goodsPrice) {
|
||||
this.goodsPrice = goodsPrice;
|
||||
}
|
||||
|
||||
public Integer getNum() {
|
||||
return num;
|
||||
}
|
||||
|
||||
public void setNum(Integer num) {
|
||||
this.num = num;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,87 @@
|
||||
package com.example.controller;
|
||||
|
||||
import com.example.common.Result;
|
||||
import com.example.entity.Cart;
|
||||
import com.example.service.CartService;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 购物车前端操作接口
|
||||
**/
|
||||
@RestController
|
||||
@RequestMapping("/cart")
|
||||
public class CartController {
|
||||
|
||||
@Resource
|
||||
private CartService cartService;
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public Result add(@RequestBody Cart cart) {
|
||||
cartService.add(cart);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public Result deleteById(@PathVariable Integer id) {
|
||||
cartService.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*/
|
||||
@DeleteMapping("/delete/batch")
|
||||
public Result deleteBatch(@RequestBody List<Integer> ids) {
|
||||
cartService.deleteBatch(ids);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
public Result updateById(@RequestBody Cart cart) {
|
||||
cartService.updateById(cart);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
*/
|
||||
@GetMapping("/selectById/{id}")
|
||||
public Result selectById(@PathVariable Integer id) {
|
||||
Cart cart = cartService.selectById(id);
|
||||
return Result.success(cart);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
*/
|
||||
@GetMapping("/selectAll")
|
||||
public Result selectAll(Cart cart ) {
|
||||
List<Cart> list = cartService.selectAll(cart);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@GetMapping("/selectPage")
|
||||
public Result selectPage(Cart cart,
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||
PageInfo<Cart> page = cartService.selectPage(cart, pageNum, pageSize);
|
||||
return Result.success(page);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.example.mapper;
|
||||
|
||||
import com.example.entity.Cart;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 操作cart相关数据接口
|
||||
*/
|
||||
public interface CartMapper {
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
int insert(Cart cart);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
int deleteById(Integer id);
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
int updateById(Cart cart);
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
*/
|
||||
Cart selectById(Integer id);
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
*/
|
||||
List<Cart> selectAll(Cart cart);
|
||||
|
||||
@Select("select * from cart where user_id = #{userId} and goods_id = #{goodsId}")
|
||||
Cart selectByUserIdAndGoodsId(@Param("userId") Integer userId, @Param("goodsId") Integer goodsId);
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
package com.example.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 评论信息表
|
||||
*/
|
||||
public class Comment implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** ID */
|
||||
private Integer id;
|
||||
private Integer userId;
|
||||
private Integer businessId;
|
||||
private Integer goodsId;
|
||||
|
||||
private String businessName;
|
||||
private String goodsName;
|
||||
|
||||
private String time;
|
||||
private String content;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Integer userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public Integer getBusinessId() {
|
||||
return businessId;
|
||||
}
|
||||
|
||||
public void setBusinessId(Integer businessId) {
|
||||
this.businessId = businessId;
|
||||
}
|
||||
|
||||
public Integer getGoodsId() {
|
||||
return goodsId;
|
||||
}
|
||||
|
||||
public void setGoodsId(Integer goodsId) {
|
||||
this.goodsId = goodsId;
|
||||
}
|
||||
|
||||
public String getBusinessName() {
|
||||
return businessName;
|
||||
}
|
||||
|
||||
public void setBusinessName(String businessName) {
|
||||
this.businessName = businessName;
|
||||
}
|
||||
|
||||
public String getGoodsName() {
|
||||
return goodsName;
|
||||
}
|
||||
|
||||
public void setGoodsName(String goodsName) {
|
||||
this.goodsName = goodsName;
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(String time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
package com.example.controller;
|
||||
|
||||
import com.example.common.Result;
|
||||
import com.example.entity.Comment;
|
||||
import com.example.service.CommentService;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 评论前端操作接口
|
||||
**/
|
||||
@RestController
|
||||
@RequestMapping("/comment")
|
||||
public class CommentController {
|
||||
|
||||
@Resource
|
||||
private CommentService commentService;
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public Result add(@RequestBody Comment comment) {
|
||||
commentService.add(comment);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public Result deleteById(@PathVariable Integer id) {
|
||||
commentService.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*/
|
||||
@DeleteMapping("/delete/batch")
|
||||
public Result deleteBatch(@RequestBody List<Integer> ids) {
|
||||
commentService.deleteBatch(ids);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
public Result updateById(@RequestBody Comment comment) {
|
||||
commentService.updateById(comment);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
*/
|
||||
@GetMapping("/selectById/{id}")
|
||||
public Result selectById(@PathVariable Integer id) {
|
||||
Comment comment = commentService.selectById(id);
|
||||
return Result.success(comment);
|
||||
}
|
||||
|
||||
@GetMapping("/selectByGoodsId")
|
||||
public Result selectByGoodsId(@RequestParam Integer id) {
|
||||
List<Comment> list = commentService.selectByGoodsId(id);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
*/
|
||||
@GetMapping("/selectAll")
|
||||
public Result selectAll(Comment comment ) {
|
||||
List<Comment> list = commentService.selectAll(comment);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@GetMapping("/selectPage")
|
||||
public Result selectPage(Comment comment,
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||
PageInfo<Comment> page = commentService.selectPage(comment, pageNum, pageSize);
|
||||
return Result.success(page);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.example.mapper;
|
||||
|
||||
import com.example.entity.Comment;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 操作comment相关数据接口
|
||||
*/
|
||||
public interface CommentMapper {
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
int insert(Comment comment);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
int deleteById(Integer id);
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
int updateById(Comment comment);
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
*/
|
||||
Comment selectById(Integer id);
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
*/
|
||||
List<Comment> selectAll(Comment comment);
|
||||
|
||||
@Select("select comment.*, user.avatar as userAvatar, user.name as userName from comment left join user on comment.user_id = user.id where comment.goods_id = #{id}")
|
||||
List<Comment> selectByGoodsId(Integer id);
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
package com.example.service;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.example.common.enums.ResultCodeEnum;
|
||||
import com.example.common.enums.RoleEnum;
|
||||
import com.example.entity.Account;
|
||||
import com.example.entity.Comment;
|
||||
import com.example.exception.CustomException;
|
||||
import com.example.mapper.CommentMapper;
|
||||
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 CommentService {
|
||||
|
||||
@Resource
|
||||
private CommentMapper commentMapper;
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public void add(Comment comment) {
|
||||
comment.setTime(DateUtil.now());
|
||||
commentMapper.insert(comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public void deleteById(Integer id) {
|
||||
commentMapper.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*/
|
||||
public void deleteBatch(List<Integer> ids) {
|
||||
for (Integer id : ids) {
|
||||
commentMapper.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
public void updateById(Comment comment) {
|
||||
commentMapper.updateById(comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
*/
|
||||
public Comment selectById(Integer id) {
|
||||
return commentMapper.selectById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
*/
|
||||
public List<Comment> selectAll(Comment comment) {
|
||||
return commentMapper.selectAll(comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
public PageInfo<Comment> selectPage(Comment comment, Integer pageNum, Integer pageSize) {
|
||||
Account currentUser = TokenUtils.getCurrentUser();
|
||||
if (RoleEnum.USER.name().equals(currentUser.getRole())) {
|
||||
comment.setUserId(currentUser.getId());
|
||||
}
|
||||
if (RoleEnum.BUSINESS.name().equals(currentUser.getRole())) {
|
||||
comment.setBusinessId(currentUser.getId());
|
||||
}
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
List<Comment> list = commentMapper.selectAll(comment);
|
||||
return PageInfo.of(list);
|
||||
}
|
||||
|
||||
public List<Comment> selectByGoodsId(Integer id) {
|
||||
return commentMapper.selectByGoodsId(id);
|
||||
}
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
package com.example.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 商品信息表
|
||||
*/
|
||||
public class Goods implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** ID */
|
||||
private Integer id;
|
||||
/** 分类名称 */
|
||||
private String name;
|
||||
/** 分类描述 */
|
||||
private String description;
|
||||
/** 分类图标 */
|
||||
private String img;
|
||||
private Double price;
|
||||
private String unit;
|
||||
private Integer count;
|
||||
private Integer typeId;
|
||||
private Integer businessId;
|
||||
private String typeName;
|
||||
private String businessName;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getImg() {
|
||||
return img;
|
||||
}
|
||||
|
||||
public void setImg(String img) {
|
||||
this.img = img;
|
||||
}
|
||||
|
||||
public Double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(Double price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public String getUnit() {
|
||||
return unit;
|
||||
}
|
||||
|
||||
public void setUnit(String unit) {
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
public Integer getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public void setCount(Integer count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public Integer getTypeId() {
|
||||
return typeId;
|
||||
}
|
||||
|
||||
public void setTypeId(Integer typeId) {
|
||||
this.typeId = typeId;
|
||||
}
|
||||
|
||||
public Integer getBusinessId() {
|
||||
return businessId;
|
||||
}
|
||||
|
||||
public void setBusinessId(Integer businessId) {
|
||||
this.businessId = businessId;
|
||||
}
|
||||
|
||||
public String getTypeName() {
|
||||
return typeName;
|
||||
}
|
||||
|
||||
public void setTypeName(String typeName) {
|
||||
this.typeName = typeName;
|
||||
}
|
||||
|
||||
public String getBusinessName() {
|
||||
return businessName;
|
||||
}
|
||||
|
||||
public void setBusinessName(String businessName) {
|
||||
this.businessName = businessName;
|
||||
}
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
package com.example.controller;
|
||||
|
||||
import com.example.common.Result;
|
||||
import com.example.entity.Goods;
|
||||
import com.example.service.GoodsService;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品信息表前端操作接口
|
||||
**/
|
||||
@RestController
|
||||
@RequestMapping("/goods")
|
||||
public class GoodsController {
|
||||
|
||||
@Resource
|
||||
private GoodsService goodsService;
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public Result add(@RequestBody Goods goods) {
|
||||
goodsService.add(goods);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public Result deleteById(@PathVariable Integer id) {
|
||||
goodsService.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*/
|
||||
@DeleteMapping("/delete/batch")
|
||||
public Result deleteBatch(@RequestBody List<Integer> ids) {
|
||||
goodsService.deleteBatch(ids);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
public Result updateById(@RequestBody Goods goods) {
|
||||
goodsService.updateById(goods);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
*/
|
||||
@GetMapping("/selectById")
|
||||
public Result selectById(@RequestParam Integer id) {
|
||||
Goods goods = goodsService.selectById(id);
|
||||
return Result.success(goods);
|
||||
}
|
||||
@GetMapping("/selectTop15")
|
||||
public Result selectTop15() {
|
||||
List<Goods> list = goodsService.selectTop15();
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
*/
|
||||
@GetMapping("/selectAll")
|
||||
public Result selectAll(Goods goods ) {
|
||||
List<Goods> list = goodsService.selectAll(goods);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
@GetMapping("/selectByTypeId")
|
||||
public Result selectByTypeId(@RequestParam Integer id) {
|
||||
List<Goods> list = goodsService.selectByTypeId(id);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
@GetMapping("/selectByName")
|
||||
public Result selectByName(@RequestParam String name) {
|
||||
List<Goods> list = goodsService.selectByName(name);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
@GetMapping("/selectByBusinessId")
|
||||
public Result selectByBusinessId(@RequestParam Integer id) {
|
||||
List<Goods> list = goodsService.selectByBusinessId(id);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@GetMapping("/selectPage")
|
||||
public Result selectPage(Goods goods,
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||
PageInfo<Goods> page = goodsService.selectPage(goods, pageNum, pageSize);
|
||||
return Result.success(page);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package com.example.mapper;
|
||||
|
||||
import com.example.entity.Goods;
|
||||
import com.example.entity.Type;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 操作goods相关数据接口
|
||||
*/
|
||||
public interface GoodsMapper {
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
int insert(Goods goods);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
int deleteById(Integer id);
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
int updateById(Goods goods);
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
*/
|
||||
Goods selectById(Integer id);
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
*/
|
||||
List<Goods> selectAll(Goods goods);
|
||||
|
||||
@Select("select * from goods order by count desc limit 15")
|
||||
List<Goods> selectTop15();
|
||||
|
||||
@Select("select * from goods where type_id = #{id}")
|
||||
List<Goods> selectByTypeId(Integer id);
|
||||
|
||||
@Select("select * from goods where business_id = #{id}")
|
||||
List<Goods> selectByBusinessId(Integer id);
|
||||
|
||||
@Select("select * from goods where name like concat('%', #{name}, '%')")
|
||||
List<Goods> selectByName(String name);
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -0,0 +1,180 @@
|
||||
package com.example.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 购物车信息表
|
||||
*/
|
||||
public class Orders implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** ID */
|
||||
private Integer id;
|
||||
private Integer userId;
|
||||
private Integer businessId;
|
||||
private Integer goodsId;
|
||||
private String orderId;
|
||||
private Integer addressId;
|
||||
private Integer num;
|
||||
private Double price;
|
||||
private String status;
|
||||
|
||||
private List<Cart> cartData;
|
||||
|
||||
|
||||
private String businessName;
|
||||
private String goodsName;
|
||||
private String goodsImg;
|
||||
private String goodsUnit;
|
||||
private Double goodsPrice;
|
||||
private String username;
|
||||
private String useraddress;
|
||||
private String phone;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Integer userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public Integer getBusinessId() {
|
||||
return businessId;
|
||||
}
|
||||
|
||||
public void setBusinessId(Integer businessId) {
|
||||
this.businessId = businessId;
|
||||
}
|
||||
|
||||
public Integer getGoodsId() {
|
||||
return goodsId;
|
||||
}
|
||||
|
||||
public void setGoodsId(Integer goodsId) {
|
||||
this.goodsId = goodsId;
|
||||
}
|
||||
|
||||
public String getOrderId() {
|
||||
return orderId;
|
||||
}
|
||||
|
||||
public void setOrderId(String orderId) {
|
||||
this.orderId = orderId;
|
||||
}
|
||||
|
||||
public Integer getAddressId() {
|
||||
return addressId;
|
||||
}
|
||||
|
||||
public void setAddressId(Integer addressId) {
|
||||
this.addressId = addressId;
|
||||
}
|
||||
|
||||
public Integer getNum() {
|
||||
return num;
|
||||
}
|
||||
|
||||
public void setNum(Integer num) {
|
||||
this.num = num;
|
||||
}
|
||||
|
||||
public Double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(Double price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public List<Cart> getCartData() {
|
||||
return cartData;
|
||||
}
|
||||
|
||||
public void setCartData(List<Cart> cartData) {
|
||||
this.cartData = cartData;
|
||||
}
|
||||
|
||||
public String getBusinessName() {
|
||||
return businessName;
|
||||
}
|
||||
|
||||
public void setBusinessName(String businessName) {
|
||||
this.businessName = businessName;
|
||||
}
|
||||
|
||||
public String getGoodsName() {
|
||||
return goodsName;
|
||||
}
|
||||
|
||||
public void setGoodsName(String goodsName) {
|
||||
this.goodsName = goodsName;
|
||||
}
|
||||
|
||||
public String getGoodsImg() {
|
||||
return goodsImg;
|
||||
}
|
||||
|
||||
public void setGoodsImg(String goodsImg) {
|
||||
this.goodsImg = goodsImg;
|
||||
}
|
||||
|
||||
public String getGoodsUnit() {
|
||||
return goodsUnit;
|
||||
}
|
||||
|
||||
public void setGoodsUnit(String goodsUnit) {
|
||||
this.goodsUnit = goodsUnit;
|
||||
}
|
||||
|
||||
public Double getGoodsPrice() {
|
||||
return goodsPrice;
|
||||
}
|
||||
|
||||
public void setGoodsPrice(Double goodsPrice) {
|
||||
this.goodsPrice = goodsPrice;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getUseraddress() {
|
||||
return useraddress;
|
||||
}
|
||||
|
||||
public void setUseraddress(String useraddress) {
|
||||
this.useraddress = useraddress;
|
||||
}
|
||||
|
||||
public String getPhone() {
|
||||
return phone;
|
||||
}
|
||||
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,87 @@
|
||||
package com.example.controller;
|
||||
|
||||
import com.example.common.Result;
|
||||
import com.example.entity.Orders;
|
||||
import com.example.service.OrdersService;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 订单前端操作接口
|
||||
**/
|
||||
@RestController
|
||||
@RequestMapping("/orders")
|
||||
public class OrdersController {
|
||||
|
||||
@Resource
|
||||
private OrdersService ordersService;
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public Result add(@RequestBody Orders orders) {
|
||||
ordersService.add(orders);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public Result deleteById(@PathVariable Integer id) {
|
||||
ordersService.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*/
|
||||
@DeleteMapping("/delete/batch")
|
||||
public Result deleteBatch(@RequestBody List<Integer> ids) {
|
||||
ordersService.deleteBatch(ids);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
public Result updateById(@RequestBody Orders orders) {
|
||||
ordersService.updateById(orders);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
*/
|
||||
@GetMapping("/selectById/{id}")
|
||||
public Result selectById(@PathVariable Integer id) {
|
||||
Orders orders = ordersService.selectById(id);
|
||||
return Result.success(orders);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
*/
|
||||
@GetMapping("/selectAll")
|
||||
public Result selectAll(Orders orders ) {
|
||||
List<Orders> list = ordersService.selectAll(orders);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@GetMapping("/selectPage")
|
||||
public Result selectPage(Orders orders,
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||
PageInfo<Orders> page = ordersService.selectPage(orders, pageNum, pageSize);
|
||||
return Result.success(page);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.example.mapper;
|
||||
|
||||
import com.example.entity.Orders;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 操作orders相关数据接口
|
||||
*/
|
||||
public interface OrdersMapper {
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
int insert(Orders orders);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
int deleteById(Integer id);
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
int updateById(Orders orders);
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
*/
|
||||
Orders selectById(Integer id);
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
*/
|
||||
List<Orders> selectAll(Orders orders);
|
||||
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
package com.example.service;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.example.common.enums.RoleEnum;
|
||||
import com.example.entity.Account;
|
||||
import com.example.entity.Cart;
|
||||
import com.example.entity.Orders;
|
||||
import com.example.mapper.CartMapper;
|
||||
import com.example.mapper.OrdersMapper;
|
||||
import com.example.utils.TokenUtils;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 订单业务处理
|
||||
**/
|
||||
@Service
|
||||
public class OrdersService {
|
||||
|
||||
@Resource
|
||||
private OrdersMapper ordersMapper;
|
||||
@Resource
|
||||
private CartMapper cartMapper;
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public void add(Orders orders) {
|
||||
orders.setOrderId(DateUtil.format(new Date(), "yyyyMMddHHmmss"));
|
||||
for (Cart cart : orders.getCartData()) {
|
||||
Orders dbOrders = new Orders();
|
||||
BeanUtils.copyProperties(orders, dbOrders);
|
||||
dbOrders.setGoodsId(cart.getGoodsId());
|
||||
dbOrders.setBusinessId(cart.getBusinessId());
|
||||
dbOrders.setNum(cart.getNum());
|
||||
dbOrders.setPrice(cart.getNum() * cart.getGoodsPrice());
|
||||
ordersMapper.insert(dbOrders);
|
||||
|
||||
// 把购物车里对应的商品删掉
|
||||
cartMapper.deleteById(cart.getId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public void deleteById(Integer id) {
|
||||
ordersMapper.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*/
|
||||
public void deleteBatch(List<Integer> ids) {
|
||||
for (Integer id : ids) {
|
||||
ordersMapper.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
public void updateById(Orders orders) {
|
||||
ordersMapper.updateById(orders);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
*/
|
||||
public Orders selectById(Integer id) {
|
||||
return ordersMapper.selectById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
*/
|
||||
public List<Orders> selectAll(Orders orders) {
|
||||
return ordersMapper.selectAll(orders);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
public PageInfo<Orders> selectPage(Orders orders, Integer pageNum, Integer pageSize) {
|
||||
Account currentUser = TokenUtils.getCurrentUser();
|
||||
if (RoleEnum.USER.name().equals(currentUser.getRole())) {
|
||||
orders.setUserId(currentUser.getId());
|
||||
}
|
||||
if (RoleEnum.BUSINESS.name().equals(currentUser.getRole())) {
|
||||
orders.setBusinessId(currentUser.getId());
|
||||
}
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
List<Orders> list = ordersMapper.selectAll(orders);
|
||||
return PageInfo.of(list);
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package com.example.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 商品分类信息表
|
||||
*/
|
||||
public class Type implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** ID */
|
||||
private Integer id;
|
||||
/** 分类名称 */
|
||||
private String name;
|
||||
/** 分类描述 */
|
||||
private String description;
|
||||
/** 分类图标 */
|
||||
private String img;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getImg() {
|
||||
return img;
|
||||
}
|
||||
|
||||
public void setImg(String img) {
|
||||
this.img = img;
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package com.example.controller;
|
||||
|
||||
import com.example.common.Result;
|
||||
import com.example.entity.Type;
|
||||
import com.example.service.TypeService;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 公告信息表前端操作接口
|
||||
**/
|
||||
@RestController
|
||||
@RequestMapping("/type")
|
||||
public class TypeController {
|
||||
|
||||
@Resource
|
||||
private TypeService typeService;
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public Result add(@RequestBody Type type) {
|
||||
typeService.add(type);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public Result deleteById(@PathVariable Integer id) {
|
||||
typeService.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*/
|
||||
@DeleteMapping("/delete/batch")
|
||||
public Result deleteBatch(@RequestBody List<Integer> ids) {
|
||||
typeService.deleteBatch(ids);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
public Result updateById(@RequestBody Type type) {
|
||||
typeService.updateById(type);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
*/
|
||||
@GetMapping("/selectById/{id}")
|
||||
public Result selectById(@PathVariable Integer id) {
|
||||
Type type = typeService.selectById(id);
|
||||
return Result.success(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
*/
|
||||
@GetMapping("/selectAll")
|
||||
public Result selectAll(Type type ) {
|
||||
List<Type> list = typeService.selectAll(type);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@GetMapping("/selectPage")
|
||||
public Result selectPage(Type type,
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||
PageInfo<Type> page = typeService.selectPage(type, pageNum, pageSize);
|
||||
return Result.success(page);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.example.mapper;
|
||||
|
||||
import com.example.entity.Type;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 操作type相关数据接口
|
||||
*/
|
||||
public interface TypeMapper {
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
int insert(Type type);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
int deleteById(Integer id);
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
int updateById(Type type);
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
*/
|
||||
Type selectById(Integer id);
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
*/
|
||||
List<Type> selectAll(Type type);
|
||||
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
package com.example.service;
|
||||
|
||||
|
||||
import com.example.entity.Type;
|
||||
import com.example.mapper.TypeMapper;
|
||||
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 TypeService {
|
||||
|
||||
@Resource
|
||||
private TypeMapper typeMapper;
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public void add(Type type) {
|
||||
typeMapper.insert(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public void deleteById(Integer id) {
|
||||
typeMapper.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*/
|
||||
public void deleteBatch(List<Integer> ids) {
|
||||
for (Integer id : ids) {
|
||||
typeMapper.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
public void updateById(Type type) {
|
||||
typeMapper.updateById(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
*/
|
||||
public Type selectById(Integer id) {
|
||||
return typeMapper.selectById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
*/
|
||||
public List<Type> selectAll(Type type) {
|
||||
return typeMapper.selectAll(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
public PageInfo<Type> selectPage(Type type, Integer pageNum, Integer pageSize) {
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
List<Type> list = typeMapper.selectAll(type);
|
||||
return PageInfo.of(list);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue