初始化美若彩妆销售平台项目
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package com.meiruo.cosmetics;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
@MapperScan("com.meiruo.cosmetics.mapper")
|
||||
public class MeiruoCosmeticsApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(MeiruoCosmeticsApplication.class, args);
|
||||
System.out.println("====================================");
|
||||
System.out.println(" 美若彩妆销售平台启动成功!");
|
||||
System.out.println("====================================");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.meiruo.cosmetics.config;
|
||||
|
||||
import cn.dev33.satoken.interceptor.SaInterceptor;
|
||||
import cn.dev33.satoken.jwt.SaJwtManager;
|
||||
import cn.dev33.satoken.jwt.StpLogicJwtForSimple;
|
||||
import cn.dev33.satoken.stp.StpInterface;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
public class SaTokenConfig implements WebMvcConfigurer {
|
||||
|
||||
@Bean
|
||||
public StpLogicJwtForSimple stpLogicJwtForSimple() {
|
||||
return new StpLogicJwtForSimple();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public StpInterface stpInterface() {
|
||||
return new StpInterface() {
|
||||
@Override
|
||||
public List<String> getPermissionList(Object loginId, String loginType) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRoleList(Object loginId, String loginType) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(new SaInterceptor()).addPathPatterns("/api/**").excludePathPatterns("/api/user/login", "/api/user/register");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.meiruo.cosmetics.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/upload/**")
|
||||
.addResourceLocations("file:src/main/resources/static/upload/")
|
||||
.addResourceLocations("classpath:/static/upload/");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.meiruo.cosmetics.controller;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Banner;
|
||||
import com.meiruo.cosmetics.service.BannerService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/banner")
|
||||
public class BannerController {
|
||||
|
||||
@Autowired
|
||||
private BannerService bannerService;
|
||||
|
||||
@GetMapping("/list")
|
||||
public Map<String, Object> getList(@RequestParam(required = false) Integer status) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
List<Banner> list = bannerService.getList(status);
|
||||
result.put("code", 200);
|
||||
result.put("data", list);
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public Map<String, Object> getById(@PathVariable Long id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("code", 200);
|
||||
result.put("data", bannerService.getById(id));
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public Map<String, Object> add(@RequestBody Banner banner) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
bannerService.add(banner);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "添加成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
public Map<String, Object> update(@RequestBody Banner banner) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
bannerService.update(banner);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "修改成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public Map<String, Object> delete(@PathVariable Long id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
bannerService.delete(id);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "删除成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
@PutMapping("/sort/{id}")
|
||||
public Map<String, Object> updateSort(@PathVariable Long id, @RequestParam Integer sort) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
bannerService.updateSort(id, sort);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "修改成功");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.meiruo.cosmetics.controller;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.meiruo.cosmetics.service.CartService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/cart")
|
||||
public class CartController {
|
||||
|
||||
@Autowired
|
||||
private CartService cartService;
|
||||
|
||||
@GetMapping("/list")
|
||||
public Map<String, Object> getList() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Long userId = StpUtil.getLoginIdAsLong();
|
||||
result.put("code", 200);
|
||||
result.put("data", cartService.getCartList(userId));
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("/add")
|
||||
public Map<String, Object> add(@RequestParam Long productId, @RequestParam Integer quantity) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Long userId = StpUtil.getLoginIdAsLong();
|
||||
cartService.add(userId, productId, quantity);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "添加成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
@PutMapping("/quantity/{id}")
|
||||
public Map<String, Object> updateQuantity(@PathVariable Long id, @RequestParam Integer quantity) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
cartService.updateQuantity(id, quantity);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "修改成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public Map<String, Object> delete(@PathVariable Long id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
cartService.delete(id);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "删除成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
@DeleteMapping("/clear")
|
||||
public Map<String, Object> clear() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Long userId = StpUtil.getLoginIdAsLong();
|
||||
cartService.clear(userId);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "清空成功");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.meiruo.cosmetics.controller;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Category;
|
||||
import com.meiruo.cosmetics.service.CategoryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/category")
|
||||
public class CategoryController {
|
||||
|
||||
@Autowired
|
||||
private CategoryService categoryService;
|
||||
|
||||
@GetMapping("/list")
|
||||
public Map<String, Object> getList(@RequestParam(required = false) Integer status) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
List<Category> list = categoryService.getList(status);
|
||||
result.put("code", 200);
|
||||
result.put("data", list);
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public Map<String, Object> getById(@PathVariable Long id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("code", 200);
|
||||
result.put("data", categoryService.getById(id));
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public Map<String, Object> add(@RequestBody Category category) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
categoryService.add(category);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "添加成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
public Map<String, Object> update(@RequestBody Category category) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
categoryService.update(category);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "修改成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public Map<String, Object> delete(@PathVariable Long id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
categoryService.delete(id);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "删除成功");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.meiruo.cosmetics.controller;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.meiruo.cosmetics.entity.Order;
|
||||
import com.meiruo.cosmetics.service.OrderService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/order")
|
||||
public class OrderController {
|
||||
|
||||
@Autowired
|
||||
private OrderService orderService;
|
||||
|
||||
@PostMapping("/create")
|
||||
public Map<String, Object> create(
|
||||
@RequestBody Map<String, Object> params) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Long userId = StpUtil.getLoginIdAsLong();
|
||||
List<Long> cartIds = (List<Long>) params.get("cartIds");
|
||||
String receiverName = (String) params.get("receiverName");
|
||||
String receiverPhone = (String) params.get("receiverPhone");
|
||||
String receiverAddress = (String) params.get("receiverAddress");
|
||||
String remark = (String) params.get("remark");
|
||||
|
||||
Order order = orderService.create(userId, cartIds, receiverName, receiverPhone, receiverAddress, remark);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "下单成功");
|
||||
result.put("data", order);
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
public Map<String, Object> getList(@RequestParam(required = false) Integer status) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Long userId = StpUtil.getLoginIdAsLong();
|
||||
List<Order> list = orderService.getByUserId(userId, status);
|
||||
result.put("code", 200);
|
||||
result.put("data", list);
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("/admin/list")
|
||||
public Map<String, Object> adminList(@RequestParam(required = false) String keyword, @RequestParam(required = false) Integer status) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
List<Order> list = orderService.getList(keyword, status);
|
||||
result.put("code", 200);
|
||||
result.put("data", list);
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public Map<String, Object> getById(@PathVariable Long id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Order order = orderService.getById(id);
|
||||
result.put("code", 200);
|
||||
result.put("data", order);
|
||||
return result;
|
||||
}
|
||||
|
||||
@PutMapping("/status/{id}")
|
||||
public Map<String, Object> updateStatus(@PathVariable Long id, @RequestParam Integer status) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
orderService.updateStatus(id, status);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "操作成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("/revenue/{type}")
|
||||
public Map<String, Object> getRevenueStatistics(@PathVariable String type) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("code", 200);
|
||||
result.put("data", orderService.getRevenueStatistics(type));
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("/top/{limit}")
|
||||
public Map<String, Object> getTopProducts(@PathVariable Integer limit) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("code", 200);
|
||||
result.put("data", orderService.getTopProducts(limit));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.meiruo.cosmetics.controller;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Product;
|
||||
import com.meiruo.cosmetics.service.ProductService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/product")
|
||||
public class ProductController {
|
||||
|
||||
@Autowired
|
||||
private ProductService productService;
|
||||
|
||||
@GetMapping("/list")
|
||||
public Map<String, Object> getList(
|
||||
@RequestParam(required = false) Long categoryId,
|
||||
@RequestParam(required = false) String keyword) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
List<Product> list = productService.getList(categoryId, keyword);
|
||||
result.put("code", 200);
|
||||
result.put("data", list);
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("/recommend")
|
||||
public Map<String, Object> getRecommend() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("code", 200);
|
||||
result.put("data", productService.getRecommend());
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public Map<String, Object> getById(@PathVariable Long id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Product product = productService.getById(id);
|
||||
result.put("code", 200);
|
||||
result.put("data", product);
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public Map<String, Object> add(@RequestBody Product product) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
productService.add(product);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "添加成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
public Map<String, Object> update(@RequestBody Product product) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
productService.update(product);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "修改成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public Map<String, Object> delete(@PathVariable Long id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
productService.delete(id);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "删除成功");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.meiruo.cosmetics.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/upload")
|
||||
@CrossOrigin
|
||||
public class UploadController {
|
||||
|
||||
private static final String UPLOAD_PATH = "src/main/resources/static/upload/";
|
||||
|
||||
@PostMapping("/image")
|
||||
public Map<String, Object> uploadImage(@RequestParam("file") MultipartFile file) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
if (file.isEmpty()) {
|
||||
result.put("code", 500);
|
||||
result.put("msg", "请选择要上传的文件");
|
||||
return result;
|
||||
}
|
||||
|
||||
try {
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
String ext = originalFilename.substring(originalFilename.lastIndexOf("."));
|
||||
|
||||
String dateDir = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
||||
String fileName = System.currentTimeMillis() + ext;
|
||||
|
||||
Path uploadDir = Paths.get(UPLOAD_PATH + dateDir);
|
||||
if (!Files.exists(uploadDir)) {
|
||||
Files.createDirectories(uploadDir);
|
||||
}
|
||||
|
||||
Path filePath = uploadDir.resolve(fileName);
|
||||
Files.copy(file.getInputStream(), filePath, StandardCopyOption.REPLACE_EXISTING);
|
||||
|
||||
String url = "/upload/" + dateDir + "/" + fileName;
|
||||
|
||||
result.put("code", 200);
|
||||
result.put("msg", "上传成功");
|
||||
result.put("url", url);
|
||||
return result;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
result.put("code", 500);
|
||||
result.put("msg", "文件上传失败");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package com.meiruo.cosmetics.controller;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.meiruo.cosmetics.entity.User;
|
||||
import com.meiruo.cosmetics.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/user")
|
||||
public class UserController {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@PostMapping("/login")
|
||||
public Map<String, Object> login(@RequestBody User user) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
User loginUser = userService.login(user.getUsername(), user.getPassword());
|
||||
if (loginUser == null) {
|
||||
result.put("code", 500);
|
||||
result.put("msg", "用户名或密码错误");
|
||||
return result;
|
||||
}
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("id", loginUser.getId());
|
||||
data.put("username", loginUser.getUsername());
|
||||
data.put("nickname", loginUser.getNickname());
|
||||
data.put("avatar", loginUser.getAvatar());
|
||||
data.put("role", loginUser.getRole());
|
||||
result.put("code", 200);
|
||||
result.put("msg", "登录成功");
|
||||
result.put("data", data);
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("/register")
|
||||
public Map<String, Object> register(@RequestBody User user) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
User registerUser = userService.register(user);
|
||||
if (registerUser == null) {
|
||||
result.put("code", 500);
|
||||
result.put("msg", "用户名已存在");
|
||||
return result;
|
||||
}
|
||||
result.put("code", 200);
|
||||
result.put("msg", "注册成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("/info")
|
||||
public Map<String, Object> getInfo() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Long userId = StpUtil.getLoginIdAsLong();
|
||||
User user = userService.getById(userId);
|
||||
if (user == null) {
|
||||
result.put("code", 500);
|
||||
result.put("msg", "用户不存在");
|
||||
return result;
|
||||
}
|
||||
result.put("code", 200);
|
||||
result.put("data", user);
|
||||
return result;
|
||||
}
|
||||
|
||||
@PutMapping("/info")
|
||||
public Map<String, Object> updateInfo(@RequestBody User user) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Long userId = StpUtil.getLoginIdAsLong();
|
||||
user.setId(userId);
|
||||
userService.update(user);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "修改成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("/logout")
|
||||
public Map<String, Object> logout() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
StpUtil.logout();
|
||||
result.put("code", 200);
|
||||
result.put("msg", "退出成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
public Map<String, Object> getList(@RequestParam(required = false) String query) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("code", 200);
|
||||
result.put("data", userService.getList(query));
|
||||
return result;
|
||||
}
|
||||
|
||||
@PutMapping("/status/{id}")
|
||||
public Map<String, Object> updateStatus(@PathVariable Long id, @RequestParam Integer status) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
userService.updateStatus(id, status);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "操作成功");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.meiruo.cosmetics.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class Banner {
|
||||
private Long id;
|
||||
private String title;
|
||||
private String image;
|
||||
private String link;
|
||||
private Integer sort;
|
||||
private Integer status;
|
||||
private LocalDateTime createTime;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.meiruo.cosmetics.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class Cart {
|
||||
private Long id;
|
||||
private Long userId;
|
||||
private Long productId;
|
||||
private Integer quantity;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.meiruo.cosmetics.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class Category {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String description;
|
||||
private Integer sort;
|
||||
private Integer status;
|
||||
private LocalDateTime createTime;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.meiruo.cosmetics.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class Order {
|
||||
private Long id;
|
||||
private String orderNo;
|
||||
private Long userId;
|
||||
private BigDecimal totalAmount;
|
||||
private Integer status;
|
||||
private String receiverName;
|
||||
private String receiverPhone;
|
||||
private String receiverAddress;
|
||||
private String remark;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime payTime;
|
||||
private LocalDateTime shipTime;
|
||||
private LocalDateTime receiveTime;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.meiruo.cosmetics.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class OrderItem {
|
||||
private Long id;
|
||||
private Long orderId;
|
||||
private Long productId;
|
||||
private String productName;
|
||||
private String productImage;
|
||||
private BigDecimal price;
|
||||
private Integer quantity;
|
||||
private LocalDateTime createTime;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.meiruo.cosmetics.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class Product {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String description;
|
||||
private BigDecimal price;
|
||||
private Integer stock;
|
||||
private Long categoryId;
|
||||
private String image;
|
||||
private String images;
|
||||
private Integer status;
|
||||
private Integer sales;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.meiruo.cosmetics.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class User {
|
||||
private Long id;
|
||||
private String username;
|
||||
private String password;
|
||||
private String nickname;
|
||||
private String phone;
|
||||
private String email;
|
||||
private String avatar;
|
||||
private Integer role;
|
||||
private Integer status;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.meiruo.cosmetics.mapper;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Banner;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface BannerMapper {
|
||||
|
||||
List<Banner> selectList(@Param("status") Integer status);
|
||||
|
||||
Banner selectById(@Param("id") Long id);
|
||||
|
||||
int insert(Banner banner);
|
||||
|
||||
int update(Banner banner);
|
||||
|
||||
int delete(@Param("id") Long id);
|
||||
|
||||
int updateSort(@Param("id") Long id, @Param("sort") Integer sort);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.meiruo.cosmetics.mapper;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Cart;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface CartMapper {
|
||||
|
||||
Cart selectByUserAndProduct(@Param("userId") Long userId, @Param("productId") Long productId);
|
||||
|
||||
List<Cart> selectByUserId(@Param("userId") Long userId);
|
||||
|
||||
int insert(Cart cart);
|
||||
|
||||
int update(Cart cart);
|
||||
|
||||
int delete(@Param("id") Long id);
|
||||
|
||||
int deleteByUserId(@Param("userId") Long userId);
|
||||
|
||||
int updateQuantity(@Param("id") Long id, @Param("quantity") Integer quantity);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.meiruo.cosmetics.mapper;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Category;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface CategoryMapper {
|
||||
|
||||
Category selectById(@Param("id") Long id);
|
||||
|
||||
List<Category> selectList(@Param("status") Integer status);
|
||||
|
||||
int insert(Category category);
|
||||
|
||||
int update(Category category);
|
||||
|
||||
int delete(@Param("id") Long id);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.meiruo.cosmetics.mapper;
|
||||
|
||||
import com.meiruo.cosmetics.entity.OrderItem;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface OrderItemMapper {
|
||||
|
||||
List<OrderItem> selectByOrderId(@Param("orderId") Long orderId);
|
||||
|
||||
int insert(OrderItem orderItem);
|
||||
|
||||
int insertBatch(@Param("items") List<OrderItem> items);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.meiruo.cosmetics.mapper;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Order;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface OrderMapper {
|
||||
|
||||
Order selectById(@Param("id") Long id);
|
||||
|
||||
Order selectByOrderNo(@Param("orderNo") String orderNo);
|
||||
|
||||
List<Order> selectByUserId(@Param("userId") Long userId, @Param("status") Integer status);
|
||||
|
||||
List<Order> selectList(@Param("keyword") String keyword, @Param("status") Integer status);
|
||||
|
||||
int insert(Order order);
|
||||
|
||||
int update(Order order);
|
||||
|
||||
int updateStatus(@Param("id") Long id, @Param("status") Integer status);
|
||||
|
||||
List<Map<String, Object>> selectRevenueStatistics(@Param("type") String type);
|
||||
|
||||
List<Map<String, Object>> selectTopProducts(@Param("limit") Integer limit);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.meiruo.cosmetics.mapper;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Product;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ProductMapper {
|
||||
|
||||
Product selectById(@Param("id") Long id);
|
||||
|
||||
List<Product> selectList(@Param("categoryId") Long categoryId, @Param("keyword") String keyword);
|
||||
|
||||
List<Product> selectRecommend();
|
||||
|
||||
List<Product> selectByIds(@Param("ids") List<Long> ids);
|
||||
|
||||
int insert(Product product);
|
||||
|
||||
int update(Product product);
|
||||
|
||||
int delete(@Param("id") Long id);
|
||||
|
||||
int updateStock(@Param("id") Long id, @Param("count") Integer count);
|
||||
|
||||
int incrementSales(@Param("id") Long id, @Param("count") Integer count);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.meiruo.cosmetics.mapper;
|
||||
|
||||
import com.meiruo.cosmetics.entity.User;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface UserMapper {
|
||||
|
||||
User selectById(@Param("id") Long id);
|
||||
|
||||
User selectByUsername(@Param("username") String username);
|
||||
|
||||
User selectByPhone(@Param("phone") String phone);
|
||||
|
||||
List<User> selectList(@Param("query") String query);
|
||||
|
||||
int insert(User user);
|
||||
|
||||
int update(User user);
|
||||
|
||||
int delete(@Param("id") Long id);
|
||||
|
||||
int updateStatus(@Param("id") Long id, @Param("status") Integer status);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.meiruo.cosmetics.service;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Banner;
|
||||
import java.util.List;
|
||||
|
||||
public interface BannerService {
|
||||
|
||||
List<Banner> getList(Integer status);
|
||||
|
||||
Banner getById(Long id);
|
||||
|
||||
void add(Banner banner);
|
||||
|
||||
void update(Banner banner);
|
||||
|
||||
void delete(Long id);
|
||||
|
||||
void updateSort(Long id, Integer sort);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.meiruo.cosmetics.service;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Cart;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface CartService {
|
||||
|
||||
List<Map<String, Object>> getCartList(Long userId);
|
||||
|
||||
void add(Long userId, Long productId, Integer quantity);
|
||||
|
||||
void updateQuantity(Long id, Integer quantity);
|
||||
|
||||
void delete(Long id);
|
||||
|
||||
void clear(Long userId);
|
||||
|
||||
void mergeFromCookie(Long userId);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.meiruo.cosmetics.service;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Category;
|
||||
import java.util.List;
|
||||
|
||||
public interface CategoryService {
|
||||
|
||||
Category getById(Long id);
|
||||
|
||||
List<Category> getList(Integer status);
|
||||
|
||||
void add(Category category);
|
||||
|
||||
void update(Category category);
|
||||
|
||||
void delete(Long id);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.meiruo.cosmetics.service;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Order;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface OrderService {
|
||||
|
||||
Order create(Long userId, List<Long> cartIds, String receiverName, String receiverPhone, String receiverAddress, String remark);
|
||||
|
||||
Order getById(Long id);
|
||||
|
||||
Order getByOrderNo(String orderNo);
|
||||
|
||||
List<Order> getByUserId(Long userId, Integer status);
|
||||
|
||||
List<Order> getList(String keyword, Integer status);
|
||||
|
||||
void updateStatus(Long id, Integer status);
|
||||
|
||||
Map<String, Object> getRevenueStatistics(String type);
|
||||
|
||||
List<Map<String, Object>> getTopProducts(Integer limit);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.meiruo.cosmetics.service;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Product;
|
||||
import java.util.List;
|
||||
|
||||
public interface ProductService {
|
||||
|
||||
Product getById(Long id);
|
||||
|
||||
List<Product> getList(Long categoryId, String keyword);
|
||||
|
||||
List<Product> getRecommend();
|
||||
|
||||
List<Product> getByIds(List<Long> ids);
|
||||
|
||||
void add(Product product);
|
||||
|
||||
void update(Product product);
|
||||
|
||||
void delete(Long id);
|
||||
|
||||
void updateStock(Long id, Integer count);
|
||||
|
||||
void incrementSales(Long id, Integer count);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.meiruo.cosmetics.service;
|
||||
|
||||
import com.meiruo.cosmetics.entity.User;
|
||||
import java.util.List;
|
||||
|
||||
public interface UserService {
|
||||
|
||||
User login(String username, String password);
|
||||
|
||||
User register(User user);
|
||||
|
||||
User getById(Long id);
|
||||
|
||||
User getByUsername(String username);
|
||||
|
||||
List<User> getList(String query);
|
||||
|
||||
void update(User user);
|
||||
|
||||
void delete(Long id);
|
||||
|
||||
void updateStatus(Long id, Integer status);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.meiruo.cosmetics.service.impl;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Banner;
|
||||
import com.meiruo.cosmetics.mapper.BannerMapper;
|
||||
import com.meiruo.cosmetics.service.BannerService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class BannerServiceImpl implements BannerService {
|
||||
|
||||
@Autowired
|
||||
private BannerMapper bannerMapper;
|
||||
|
||||
@Override
|
||||
public List<Banner> getList(Integer status) {
|
||||
return bannerMapper.selectList(status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Banner getById(Long id) {
|
||||
return bannerMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Banner banner) {
|
||||
banner.setStatus(1);
|
||||
bannerMapper.insert(banner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Banner banner) {
|
||||
bannerMapper.update(banner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
bannerMapper.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSort(Long id, Integer sort) {
|
||||
bannerMapper.updateSort(id, sort);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.meiruo.cosmetics.service.impl;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Cart;
|
||||
import com.meiruo.cosmetics.entity.Product;
|
||||
import com.meiruo.cosmetics.mapper.CartMapper;
|
||||
import com.meiruo.cosmetics.mapper.ProductMapper;
|
||||
import com.meiruo.cosmetics.service.CartService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class CartServiceImpl implements CartService {
|
||||
|
||||
@Autowired
|
||||
private CartMapper cartMapper;
|
||||
@Autowired
|
||||
private ProductMapper productMapper;
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> getCartList(Long userId) {
|
||||
return cartMapper.selectByUserId(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Long userId, Long productId, Integer quantity) {
|
||||
Cart existCart = cartMapper.selectByUserAndProduct(userId, productId);
|
||||
if (existCart != null) {
|
||||
cartMapper.updateQuantity(existCart.getId(), existCart.getQuantity() + quantity);
|
||||
} else {
|
||||
Cart cart = new Cart();
|
||||
cart.setUserId(userId);
|
||||
cart.setProductId(productId);
|
||||
cart.setQuantity(quantity);
|
||||
cartMapper.insert(cart);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateQuantity(Long id, Integer quantity) {
|
||||
cartMapper.updateQuantity(id, quantity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
cartMapper.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear(Long userId) {
|
||||
cartMapper.deleteByUserId(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void mergeFromCookie(Long userId) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.meiruo.cosmetics.service.impl;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Category;
|
||||
import com.meiruo.cosmetics.mapper.CategoryMapper;
|
||||
import com.meiruo.cosmetics.service.CategoryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class CategoryServiceImpl implements CategoryService {
|
||||
|
||||
@Autowired
|
||||
private CategoryMapper categoryMapper;
|
||||
|
||||
@Override
|
||||
public Category getById(Long id) {
|
||||
return categoryMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Category> getList(Integer status) {
|
||||
return categoryMapper.selectList(status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Category category) {
|
||||
category.setStatus(1);
|
||||
categoryMapper.insert(category);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Category category) {
|
||||
categoryMapper.update(category);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
categoryMapper.delete(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.meiruo.cosmetics.service.impl;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Order;
|
||||
import com.meiruo.cosmetics.entity.OrderItem;
|
||||
import com.meiruo.cosmetics.mapper.OrderItemMapper;
|
||||
import com.meiruo.cosmetics.mapper.OrderMapper;
|
||||
import com.meiruo.cosmetics.mapper.ProductMapper;
|
||||
import com.meiruo.cosmetics.service.OrderService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
public class OrderServiceImpl implements OrderService {
|
||||
|
||||
@Autowired
|
||||
private OrderMapper orderMapper;
|
||||
@Autowired
|
||||
private OrderItemMapper orderItemMapper;
|
||||
@Autowired
|
||||
private ProductMapper productMapper;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Order create(Long userId, List<Long> cartIds, String receiverName, String receiverPhone, String receiverAddress, String remark) {
|
||||
Order order = new Order();
|
||||
order.setOrderNo(UUID.randomUUID().toString().replace("-", ""));
|
||||
order.setUserId(userId);
|
||||
order.setReceiverName(receiverName);
|
||||
order.setReceiverPhone(receiverPhone);
|
||||
order.setReceiverAddress(receiverAddress);
|
||||
order.setRemark(remark);
|
||||
order.setStatus(1);
|
||||
|
||||
List<OrderItem> orderItems = new ArrayList<>();
|
||||
BigDecimal totalAmount = BigDecimal.ZERO;
|
||||
|
||||
for (Long cartId : cartIds) {
|
||||
}
|
||||
|
||||
order.setTotalAmount(totalAmount);
|
||||
orderMapper.insert(order);
|
||||
|
||||
for (OrderItem item : orderItems) {
|
||||
item.setOrderId(order.getId());
|
||||
orderItemMapper.insert(item);
|
||||
productMapper.updateStock(item.getProductId(), item.getQuantity());
|
||||
productMapper.incrementSales(item.getProductId(), item.getQuantity());
|
||||
}
|
||||
|
||||
return order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Order getById(Long id) {
|
||||
return orderMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Order getByOrderNo(String orderNo) {
|
||||
return orderMapper.selectByOrderNo(orderNo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Order> getByUserId(Long userId, Integer status) {
|
||||
return orderMapper.selectByUserId(userId, status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Order> getList(String keyword, Integer status) {
|
||||
return orderMapper.selectList(keyword, status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStatus(Long id, Integer status) {
|
||||
orderMapper.updateStatus(id, status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getRevenueStatistics(String type) {
|
||||
List<Map<String, Object>> statistics = orderMapper.selectRevenueStatistics(type);
|
||||
BigDecimal total = BigDecimal.ZERO;
|
||||
for (Map<String, Object> stat : statistics) {
|
||||
total = total.add(new BigDecimal(stat.get("amount").toString()));
|
||||
}
|
||||
return Map.of("list", statistics, "total", total);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> getTopProducts(Integer limit) {
|
||||
return orderMapper.selectTopProducts(limit);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.meiruo.cosmetics.service.impl;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Product;
|
||||
import com.meiruo.cosmetics.mapper.ProductMapper;
|
||||
import com.meiruo.cosmetics.service.ProductService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class ProductServiceImpl implements ProductService {
|
||||
|
||||
@Autowired
|
||||
private ProductMapper productMapper;
|
||||
|
||||
@Override
|
||||
public Product getById(Long id) {
|
||||
return productMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Product> getList(Long categoryId, String keyword) {
|
||||
return productMapper.selectList(categoryId, keyword);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Product> getRecommend() {
|
||||
return productMapper.selectRecommend();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Product> getByIds(List<Long> ids) {
|
||||
return productMapper.selectByIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Product product) {
|
||||
product.setStatus(1);
|
||||
product.setSales(0);
|
||||
productMapper.insert(product);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Product product) {
|
||||
productMapper.update(product);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
productMapper.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStock(Long id, Integer count) {
|
||||
productMapper.updateStock(id, count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incrementSales(Long id, Integer count) {
|
||||
productMapper.incrementSales(id, count);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.meiruo.cosmetics.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.dev33.satoken.util.SaResult;
|
||||
import com.meiruo.cosmetics.entity.User;
|
||||
import com.meiruo.cosmetics.mapper.UserMapper;
|
||||
import com.meiruo.cosmetics.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.DigestUtils;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class UserServiceImpl implements UserService {
|
||||
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
@Override
|
||||
public User login(String username, String password) {
|
||||
User user = userMapper.selectByUsername(username);
|
||||
if (user == null) {
|
||||
return null;
|
||||
}
|
||||
String md5Password = DigestUtils.md5DigestAsHex(password.getBytes(StandardCharsets.UTF_8));
|
||||
if (!md5Password.equals(user.getPassword())) {
|
||||
return null;
|
||||
}
|
||||
if (user.getStatus() != 1) {
|
||||
return null;
|
||||
}
|
||||
StpUtil.login(user.getId());
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User register(User user) {
|
||||
User existUser = userMapper.selectByUsername(user.getUsername());
|
||||
if (existUser != null) {
|
||||
return null;
|
||||
}
|
||||
user.setPassword(DigestUtils.md5DigestAsHex(user.getPassword().getBytes(StandardCharsets.UTF_8)));
|
||||
user.setRole(0);
|
||||
user.setStatus(1);
|
||||
userMapper.insert(user);
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getById(Long id) {
|
||||
return userMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getByUsername(String username) {
|
||||
return userMapper.selectByUsername(username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<User> getList(String query) {
|
||||
return userMapper.selectList(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(User user) {
|
||||
userMapper.update(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
userMapper.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStatus(Long id, Integer status) {
|
||||
userMapper.updateStatus(id, status);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user