DingXiaoYu 2 gadi atpakaļ
vecāks
revīzija
67ad282edf

+ 0 - 38
src/main/java/com/seecoder/BlueWhale/controller/ProductController.java

@@ -1,38 +0,0 @@
-package com.seecoder.BlueWhale.controller;
-
-import com.seecoder.BlueWhale.service.ProductService;
-import com.seecoder.BlueWhale.vo.ProductVO;
-import com.seecoder.BlueWhale.vo.ResultVO;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
-
-import java.util.List;
-
-@RestController
-@RequestMapping("/api/products")
-public class ProductController {
-
-    @Autowired
-    ProductService productService;
-
-    @PostMapping
-    public ResultVO<Boolean> create(@RequestBody ProductVO productVO){
-        return ResultVO.buildSuccess(productService.create(productVO));
-    }
-
-    @PostMapping("/{id}/stock")
-    public ResultVO<Boolean> addStock(@PathVariable(value = "id") Integer id,@RequestParam("number") Integer number){
-        return ResultVO.buildSuccess(productService.addStock(id,number));
-    }
-
-    @GetMapping
-    public ResultVO<List<ProductVO>> getAllProducts(@RequestParam("storeId") Integer storeId){
-        return ResultVO.buildSuccess(productService.getAllProducts(storeId));
-    }
-
-    @GetMapping("/{id}")
-    public ResultVO<ProductVO> getProduct(@PathVariable(value = "id") Integer id){
-        return ResultVO.buildSuccess(productService.getProduct(id));
-    }
-
-}

+ 0 - 33
src/main/java/com/seecoder/BlueWhale/controller/StoreController.java

@@ -1,33 +0,0 @@
-package com.seecoder.BlueWhale.controller;
-
-import java.util.List;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
-
-import com.seecoder.BlueWhale.service.StoreService;
-import com.seecoder.BlueWhale.vo.ResultVO;
-import com.seecoder.BlueWhale.vo.StoreVO;
-
-@RestController
-@RequestMapping("/api/stores")
-public class StoreController {
-    
-    @Autowired
-    StoreService storeService;
-
-    @PostMapping
-    public ResultVO<Boolean> create(@RequestBody StoreVO storeVO){
-        return ResultVO.buildSuccess(storeService.create(storeVO));
-    }
-
-    @GetMapping("/{id}")
-    public ResultVO<StoreVO> getStore(@PathVariable(value = "id") Integer id){
-        return ResultVO.buildSuccess(storeService.getStore(id));
-    }
-
-    @GetMapping
-    public ResultVO<List<StoreVO>> getAllStores(){
-        return ResultVO.buildSuccess(storeService.getAllStores());
-    }
-
-}

+ 0 - 5
src/main/java/com/seecoder/BlueWhale/enums/CategoryEnum.java

@@ -1,5 +0,0 @@
-package com.seecoder.BlueWhale.enums;
-
-public enum CategoryEnum {
-    FOOD,CLOTHES,FURNITURE,ELECTRONICS,ENTERTAINMENT,SPORTS,LUXURY;
-}

+ 0 - 12
src/main/java/com/seecoder/BlueWhale/exception/BlueWhaleException.java

@@ -26,16 +26,4 @@ public class BlueWhaleException extends RuntimeException{
         return new BlueWhaleException("文件上传失败!");
     }
 
-    public static BlueWhaleException nameAlreadyExists(){
-        return new BlueWhaleException("名称已经存在!");
-    }
-
-    public static BlueWhaleException storeNotExists(){
-        return new BlueWhaleException("店铺不存在!");
-    }
-
-    public static BlueWhaleException productNotExists(){
-        return new BlueWhaleException("商品不存在!");
-    }
-
 }

+ 0 - 73
src/main/java/com/seecoder/BlueWhale/po/Product.java

@@ -1,73 +0,0 @@
-package com.seecoder.BlueWhale.po;
-
-import com.seecoder.BlueWhale.enums.CategoryEnum;
-import com.seecoder.BlueWhale.vo.ProductVO;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
-
-import javax.persistence.*;
-import java.util.List;
-
-@Getter
-@Setter
-@NoArgsConstructor
-@Entity
-public class Product {
-
-    @GeneratedValue(strategy = GenerationType.IDENTITY)
-    @Id
-    @Column(name = "id")
-    private Integer id;
-
-    @Basic
-    @Column(name = "store_id")
-    private Integer storeId;
-
-    @Basic
-    @Column(name = "rating")
-    private Double rating;
-
-    @Basic
-    @Column(name = "number")
-    private Integer number;
-
-    @ElementCollection(fetch = FetchType.EAGER)
-    private List<String> photoUrlList;
-
-    @Basic
-    @Column(name = "name")
-    private String name;
-
-    @Basic
-    @Column(name = "sales_amount")
-    private Integer salesAmount;
-
-    @Basic
-    @Column(name = "stock")
-    private Integer stock;
-
-    @Basic
-    @Column(name = "price")
-    private Double price;
-
-    @Basic
-    @Column(name = "category")
-    @Enumerated(EnumType.STRING)
-    private CategoryEnum category;
-
-    public ProductVO toVO(){
-        ProductVO productVO=new ProductVO();
-        productVO.setCategory(this.category);
-        productVO.setName(this.name);
-        productVO.setId(this.id);
-        productVO.setPrice(this.price);
-        productVO.setNumber(this.number);
-        productVO.setRating(this.rating);
-        productVO.setStock(this.stock);
-        productVO.setStoreId(this.storeId);
-        productVO.setSalesAmount(this.salesAmount);
-        productVO.setPhotoUrlList(this.photoUrlList);
-        return productVO;
-    }
-}

+ 0 - 52
src/main/java/com/seecoder/BlueWhale/po/Store.java

@@ -1,52 +0,0 @@
-package com.seecoder.BlueWhale.po;
-
-import javax.persistence.*;
-
-import com.seecoder.BlueWhale.vo.StoreVO;
-
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
-
-@Getter
-@Setter
-@NoArgsConstructor
-@Entity
-public class Store {
-    
-    @GeneratedValue(strategy = GenerationType.IDENTITY)
-    @Id
-    @Column(name = "id")
-    private Integer id;
-
-    @Basic
-    @Column(name = "name")
-    private String name;
-
-    @Basic
-    @Column(name = "logo_url")
-    private String logoUrl;
-
-    @Basic
-    @Column(name = "rating")
-    private Double rating;
-
-    @Basic
-    @Column(name = "number")
-    private Integer number;
-
-    @Basic
-    @Column(name = "location")
-    private String location;
-
-    public StoreVO toVO(){
-        StoreVO storeVO=new StoreVO();
-        storeVO.setId(this.id);
-        storeVO.setLocation(this.location);
-        storeVO.setLogoUrl(this.logoUrl);
-        storeVO.setName(this.name);
-        storeVO.setNumber(this.number);
-        storeVO.setRating(this.rating);
-        return storeVO;
-    }
-}

+ 0 - 12
src/main/java/com/seecoder/BlueWhale/repository/ProductRepository.java

@@ -1,12 +0,0 @@
-package com.seecoder.BlueWhale.repository;
-
-import com.seecoder.BlueWhale.po.Product;
-import org.springframework.data.jpa.repository.JpaRepository;
-
-import java.util.List;
-
-public interface ProductRepository extends JpaRepository<Product, Integer> {
-    List<Product> findAllByStoreId(Integer storeId);
-
-    Product findByStoreIdAndName(Integer storeId,String name);
-}

+ 0 - 10
src/main/java/com/seecoder/BlueWhale/repository/StoreRepository.java

@@ -1,10 +0,0 @@
-package com.seecoder.BlueWhale.repository;
-
-import org.springframework.data.jpa.repository.JpaRepository;
-
-import com.seecoder.BlueWhale.po.Store;
-
-public interface StoreRepository extends JpaRepository<Store, Integer> {
-    Store findByName(String name);
-
-}

+ 0 - 16
src/main/java/com/seecoder/BlueWhale/service/ProductService.java

@@ -1,16 +0,0 @@
-package com.seecoder.BlueWhale.service;
-
-import java.util.List;
-
-import com.seecoder.BlueWhale.vo.ProductVO;
-
-public interface ProductService {
-    Boolean create(ProductVO productVO);
-
-    Boolean addStock(Integer id, Integer number);
-
-    List<ProductVO> getAllProducts(Integer storeId);
-
-    ProductVO getProduct(Integer id);
-
-}

+ 0 - 14
src/main/java/com/seecoder/BlueWhale/service/StoreService.java

@@ -1,14 +0,0 @@
-package com.seecoder.BlueWhale.service;
-
-import java.util.List;
-
-import com.seecoder.BlueWhale.vo.StoreVO;
-
-public interface StoreService {
-    Boolean create(StoreVO storeVO);
-
-    StoreVO getStore(Integer id);
-
-    List<StoreVO> getAllStores();
-
-}

+ 0 - 67
src/main/java/com/seecoder/BlueWhale/serviceImpl/ProductServiceImpl.java

@@ -1,67 +0,0 @@
-package com.seecoder.BlueWhale.serviceImpl;
-
-import com.seecoder.BlueWhale.exception.BlueWhaleException;
-import com.seecoder.BlueWhale.po.Product;
-import com.seecoder.BlueWhale.po.Store;
-import com.seecoder.BlueWhale.repository.ProductRepository;
-import com.seecoder.BlueWhale.repository.StoreRepository;
-import com.seecoder.BlueWhale.service.ProductService;
-import com.seecoder.BlueWhale.vo.ProductVO;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import java.util.List;
-import java.util.stream.Collectors;
-
-@Service
-public class ProductServiceImpl implements ProductService {
-
-    @Autowired
-    ProductRepository productRepository;
-
-    @Autowired
-    StoreRepository storeRepository;
-
-    @Override
-    public Boolean create(ProductVO productVO) {
-        if (productRepository.findByStoreIdAndName(productVO.getStoreId(),productVO.getName())!=null){
-            throw BlueWhaleException.nameAlreadyExists();
-        }
-        Product product=productVO.toPO();
-        product.setSalesAmount(0);
-        product.setStock(0);
-        product.setNumber(0);
-        product.setRating(0.0);
-        productRepository.save(product);
-        return true;
-    }
-
-    @Override
-    public Boolean addStock(Integer id, Integer number) {
-        Product product=productRepository.findById(id).orElse(null);
-        if(product==null){
-            throw BlueWhaleException.productNotExists();
-        }
-        product.setStock(product.getStock()+number);
-        productRepository.save(product);
-        return true;
-    }
-
-    @Override
-    public List<ProductVO> getAllProducts(Integer storeId) {
-        Store store = storeRepository.findById(storeId).orElse(null);
-        if (store == null) {
-            throw BlueWhaleException.storeNotExists();
-        }
-        return productRepository.findAllByStoreId(storeId).stream().map(Product::toVO).collect(Collectors.toList());
-    }
-
-    @Override
-    public ProductVO getProduct(Integer id) {
-        Product product=productRepository.findById(id).orElse(null);
-        if(product==null){
-            throw BlueWhaleException.productNotExists();
-        }
-        return product.toVO();
-    }
-}

+ 0 - 47
src/main/java/com/seecoder/BlueWhale/serviceImpl/StoreServiceImpl.java

@@ -1,47 +0,0 @@
-package com.seecoder.BlueWhale.serviceImpl;
-
-import com.seecoder.BlueWhale.exception.BlueWhaleException;
-import com.seecoder.BlueWhale.po.Store;
-import com.seecoder.BlueWhale.repository.StoreRepository;
-import com.seecoder.BlueWhale.service.StoreService;
-import com.seecoder.BlueWhale.vo.StoreVO;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import java.util.List;
-import java.util.stream.Collectors;
-
-@Service
-public class StoreServiceImpl implements StoreService {
-
-    @Autowired
-    StoreRepository storeRepository;
-
-    @Override
-    public Boolean create(StoreVO storeVO) {
-        Store store = storeRepository.findByName(storeVO.getName());
-        if (store != null) {
-            throw BlueWhaleException.nameAlreadyExists();
-        }
-        Store newStore = storeVO.toPO();
-        newStore.setRating(0.0);
-        newStore.setNumber(0);
-        storeRepository.save(newStore);
-        return true;
-    }
-
-    @Override
-    public StoreVO getStore(Integer id) {
-        Store store = storeRepository.findById(id).orElse(null);
-        if (store == null) {
-            throw BlueWhaleException.storeNotExists();
-        }
-        return store.toVO();
-    }
-
-    @Override
-    public List<StoreVO> getAllStores() {
-        return storeRepository.findAll().stream().map(Store::toVO).collect(Collectors.toList());
-    }
-
-}

+ 3 - 21
src/main/java/com/seecoder/BlueWhale/serviceImpl/UserServiceImpl.java

@@ -1,21 +1,17 @@
 package com.seecoder.BlueWhale.serviceImpl;
 
-import com.seecoder.BlueWhale.enums.RoleEnum;
 import com.seecoder.BlueWhale.exception.BlueWhaleException;
-import com.seecoder.BlueWhale.repository.StoreRepository;
-import com.seecoder.BlueWhale.repository.UserRepository;
-import com.seecoder.BlueWhale.po.Store;
 import com.seecoder.BlueWhale.po.User;
+import com.seecoder.BlueWhale.repository.UserRepository;
 import com.seecoder.BlueWhale.service.UserService;
 import com.seecoder.BlueWhale.util.SecurityUtil;
 import com.seecoder.BlueWhale.util.TokenUtil;
 import com.seecoder.BlueWhale.vo.UserVO;
-
-import java.util.Date;
-
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.Date;
+
 /**
  * @Author: GaoZhaolong
  * @Date: 14:46 2023/11/26
@@ -34,8 +30,6 @@ public class UserServiceImpl implements UserService {
     @Autowired
     SecurityUtil securityUtil;
 
-    @Autowired
-    StoreRepository storeRepository;
 
     @Override
     public Boolean register(UserVO userVO) {
@@ -61,9 +55,6 @@ public class UserServiceImpl implements UserService {
     @Override
     public UserVO getInformation() {
         User user=securityUtil.getCurrentUser();
-        if (user.getRole()==RoleEnum.STAFF) {
-            return wrapWithStoreName(user.toVO());
-        }
         return user.toVO();
     }
 
@@ -83,13 +74,4 @@ public class UserServiceImpl implements UserService {
         return true;
     }
 
-    private UserVO wrapWithStoreName(UserVO userVO){
-        Integer storeId = userVO.getStoreId();
-        if (storeId==null){
-            return userVO;
-        }
-        Store store = storeRepository.findById(storeId).get();
-        userVO.setStoreName(store.getName());
-        return userVO;
-    }
 }

+ 0 - 50
src/main/java/com/seecoder/BlueWhale/vo/ProductVO.java

@@ -1,50 +0,0 @@
-package com.seecoder.BlueWhale.vo;
-
-import com.seecoder.BlueWhale.enums.CategoryEnum;
-import com.seecoder.BlueWhale.po.Product;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
-
-import java.util.List;
-
-@Getter
-@Setter
-@NoArgsConstructor
-public class ProductVO {
-
-    private Integer id;
-
-    private Integer storeId;
-
-    private Double rating;
-
-    private Integer number;
-
-    private List<String> photoUrlList;
-
-    private String name;
-
-    private Integer salesAmount;
-
-    private Integer stock;
-
-    private Double price;
-
-    private CategoryEnum category;
-
-    public Product toPO(){
-        Product product=new Product();
-        product.setCategory(this.category);
-        product.setId(this.id);
-        product.setPrice(this.price);
-        product.setName(this.name);
-        product.setNumber(this.number);
-        product.setRating(this.rating);
-        product.setStock(this.stock);
-        product.setStoreId(this.storeId);
-        product.setSalesAmount(this.salesAmount);
-        product.setPhotoUrlList(this.photoUrlList);
-        return product;
-    }
-}

+ 0 - 36
src/main/java/com/seecoder/BlueWhale/vo/StoreVO.java

@@ -1,36 +0,0 @@
-package com.seecoder.BlueWhale.vo;
-
-import com.seecoder.BlueWhale.po.Store;
-
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
-
-@Getter
-@Setter
-@NoArgsConstructor
-public class StoreVO {
-
-    private Integer id;
-    
-    private String name;
-
-    private String logoUrl;
-
-    private Double rating;
-
-    private Integer number;
-
-    private String location;
-
-    public Store toPO(){
-        Store store=new Store();
-        store.setId(this.id);
-        store.setLocation(this.location);
-        store.setLogoUrl(this.logoUrl);
-        store.setName(this.name);
-        store.setNumber(this.number);
-        store.setRating(this.rating);
-        return store;
-    }
-}