xgl 8 months ago
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,90 @@
package com.example.service;
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.Cart;
import com.example.exception.CustomException;
import com.example.mapper.CartMapper;
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 CartService {
@Resource
private CartMapper cartMapper;
/**
*
*/
public void add(Cart cart) {
// 判断该用户对该商品有没有加入过购物车如果加入过那么只要更新一下该条记录的num+1
Cart dbCart = cartMapper.selectByUserIdAndGoodsId(cart.getUserId(), cart.getGoodsId());
if (ObjectUtil.isNotEmpty(dbCart)) {
dbCart.setNum(dbCart.getNum() + 1);
cartMapper.updateById(dbCart);
} else {
cartMapper.insert(cart);
}
}
/**
*
*/
public void deleteById(Integer id) {
cartMapper.deleteById(id);
}
/**
*
*/
public void deleteBatch(List<Integer> ids) {
for (Integer id : ids) {
cartMapper.deleteById(id);
}
}
/**
*
*/
public void updateById(Cart cart) {
cartMapper.updateById(cart);
}
/**
* ID
*/
public Cart selectById(Integer id) {
return cartMapper.selectById(id);
}
/**
*
*/
public List<Cart> selectAll(Cart cart) {
return cartMapper.selectAll(cart);
}
/**
*
*/
public PageInfo<Cart> selectPage(Cart cart, Integer pageNum, Integer pageSize) {
Account currentUser = TokenUtils.getCurrentUser();
if (RoleEnum.USER.name().equals(currentUser.getRole())) {
cart.setUserId(currentUser.getId());
}
PageHelper.startPage(pageNum, pageSize);
List<Cart> list = cartMapper.selectAll(cart);
return PageInfo.of(list);
}
}

@ -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…
Cancel
Save