修正项目
This commit is contained in:
111
xlcs-parent/service/pom.xml
Normal file
111
xlcs-parent/service/pom.xml
Normal file
@@ -0,0 +1,111 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.yovinchen</groupId>
|
||||
<artifactId>xlcs-parent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>service</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>service-acl</module>
|
||||
<module>service-sys</module>
|
||||
<module>service-product</module>
|
||||
<module>service-search</module>
|
||||
<module>service-activity</module>
|
||||
<module>service-user</module>
|
||||
<module>service-home</module>
|
||||
<module>service-cart</module>
|
||||
<module>service-order</module>
|
||||
<module>service-payment</module>
|
||||
</modules>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>p6spy</groupId>
|
||||
<artifactId>p6spy</artifactId>
|
||||
<version>3.9.1</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!--依赖服务的工具类-->
|
||||
<dependency>
|
||||
<groupId>com.yovinchen</groupId>
|
||||
<artifactId>service-util</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!--数据载体-->
|
||||
<dependency>
|
||||
<groupId>com.yovinchen</groupId>
|
||||
<artifactId>model</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!--web 需要启动项目-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--mybatis-plus-->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--mysql-->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 服务注册 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
<!-- 配置中心来做配置管理-->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
<!-- 服务调用feign -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 流量控制 -->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.alibaba.cloud</groupId>-->
|
||||
<!-- <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<!--开发者工具-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
5
xlcs-parent/service/service-acl/Dockerfile
Normal file
5
xlcs-parent/service/service-acl/Dockerfile
Normal file
@@ -0,0 +1,5 @@
|
||||
FROM openjdk:8-jdk-alpine
|
||||
LABEL authors="yovinchen"
|
||||
VOLUME /tmp
|
||||
ADD ./target/service-acl.jar service-acl.jar
|
||||
ENTRYPOINT ["java","-jar","/service-acl.jar", "&"]
|
20
xlcs-parent/service/service-acl/pom.xml
Normal file
20
xlcs-parent/service/service-acl/pom.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.yovinchen</groupId>
|
||||
<artifactId>service</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>service-acl</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
@@ -0,0 +1,23 @@
|
||||
package com.yovinchen.xlcs;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
|
||||
/**
|
||||
* ClassName: ServiceAclApplication
|
||||
* Package: com.yovinchen.xlcs
|
||||
* 权限管理模块启动类
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/9/13 17:38
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableDiscoveryClient
|
||||
public class ServiceAclApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ServiceAclApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,134 @@
|
||||
package com.yovinchen.xlcs.acl.controller;
|
||||
|
||||
|
||||
import com.yovinchen.xlcs.acl.service.AdminService;
|
||||
import com.yovinchen.xlcs.acl.service.RoleService;
|
||||
import com.yovinchen.xlcs.common.result.Result;
|
||||
import com.yovinchen.xlcs.common.utils.MD5;
|
||||
import com.yovinchen.xlcs.model.acl.Admin;
|
||||
import com.yovinchen.xlcs.vo.acl.AdminQueryVo;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ClassName: AdminController
|
||||
* Package: com.yovinchen.xlcs.acl.controller
|
||||
* 用户管理 前端控制器
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/9/14 10:38
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/admin/acl/user")
|
||||
@Api(tags = "用户管理")
|
||||
public class AdminController {
|
||||
|
||||
@Autowired
|
||||
private AdminService adminService;
|
||||
|
||||
@Autowired
|
||||
private RoleService roleService;
|
||||
|
||||
@ApiOperation(value = "获取管理用户分页列表")
|
||||
@GetMapping("{page}/{limit}")
|
||||
public Result index(@ApiParam(name = "page", value = "当前页码", required = true) @PathVariable Long page,
|
||||
@ApiParam(name = "limit", value = "每页记录数", required = true) @PathVariable Long limit,
|
||||
@ApiParam(name = "userQueryVo", value = "查询对象", required = false) AdminQueryVo userQueryVo) {
|
||||
try {
|
||||
Page<Admin> pageParam = new Page<>(page, limit);
|
||||
IPage<Admin> pageModel = adminService.selectPage(pageParam, userQueryVo);
|
||||
return Result.ok(pageModel);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("获取管理用户分页列表异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取管理用户")
|
||||
@GetMapping("get/{id}")
|
||||
public Result get(@PathVariable Long id) {
|
||||
try {
|
||||
Admin user = adminService.getById(id);
|
||||
return Result.ok(user);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("获取管理用户异常", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ApiOperation(value = "新增管理用户")
|
||||
@PostMapping("save")
|
||||
public Result save(@RequestBody Admin user) {
|
||||
try {
|
||||
//对密码进行MD5处理
|
||||
user.setPassword(MD5.encrypt(user.getPassword()));
|
||||
boolean result = adminService.save(user);
|
||||
return result ? Result.ok(null) : Result.fail(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("新增管理用户异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "修改管理用户")
|
||||
@PutMapping("update")
|
||||
public Result updateById(@RequestBody Admin user) {
|
||||
try {
|
||||
boolean result = adminService.updateById(user);
|
||||
return result ? Result.ok(null) : Result.fail(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("修改管理用户异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "删除管理用户")
|
||||
@DeleteMapping("remove/{id}")
|
||||
public Result remove(@PathVariable Long id) {
|
||||
try {
|
||||
boolean result = adminService.removeById(id);
|
||||
return result ? Result.ok(null) : Result.fail(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("删除管理用户异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "根据id列表删除管理用户")
|
||||
@DeleteMapping("batchRemove")
|
||||
public Result batchRemove(@RequestBody List<Long> idList) {
|
||||
try {
|
||||
boolean result = adminService.removeByIds(idList);
|
||||
return result ? Result.ok(null) : Result.fail(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("根据id列表删除管理用户异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "根据用户获取角色数据")
|
||||
@GetMapping("/toAssign/{adminId}")
|
||||
public Result toAssign(@PathVariable Long adminId) {
|
||||
try {
|
||||
Map<String, Object> roleMap = roleService.findRoleByUserId(adminId);
|
||||
return StringUtils.isNotEmpty(roleMap.toString()) ? Result.ok(roleMap) : Result.fail(roleMap);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("根据用户获取角色数据异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "根据用户分配角色")
|
||||
@PostMapping("/doAssign")
|
||||
public Result doAssign(@RequestParam Long adminId, @RequestParam Long[] roleId) {
|
||||
try {
|
||||
roleService.saveUserRoleRealtionShip(adminId, roleId);
|
||||
return Result.ok(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("根据用户分配角色异常", e);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
package com.yovinchen.xlcs.acl.controller;
|
||||
|
||||
import com.yovinchen.xlcs.common.result.Result;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ClassName: IndexController
|
||||
* Package: com.yovinchen.xlcs.acl.controller
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/9/13 18:00
|
||||
*/
|
||||
|
||||
@Api(tags = "登录接口")
|
||||
@RestController
|
||||
@RequestMapping("/admin/acl/index")
|
||||
public class IndexController {
|
||||
|
||||
/**
|
||||
* 1、请求登陆的login
|
||||
*/
|
||||
@PostMapping("login")
|
||||
public Result login() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("token", "admin-token");
|
||||
return Result.ok(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 2 获取用户信息
|
||||
*/
|
||||
@GetMapping("info")
|
||||
public Result info() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("name", "yovinchen");
|
||||
map.put("avatar", "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
|
||||
return Result.ok(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 3 退出
|
||||
*/
|
||||
@PostMapping("logout")
|
||||
public Result logout() {
|
||||
return Result.ok(null);
|
||||
}
|
||||
}
|
@@ -0,0 +1,74 @@
|
||||
package com.yovinchen.xlcs.acl.controller;
|
||||
|
||||
import com.yovinchen.xlcs.acl.service.PermissionService;
|
||||
import com.yovinchen.xlcs.common.result.Result;
|
||||
import com.yovinchen.xlcs.model.acl.Permission;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ClassName: PermissionController
|
||||
* Package: com.yovinchen.xlcs.acl.controller
|
||||
* 菜单服务
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/9/14 14:03
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/admin/acl/permission")
|
||||
@Api(tags = "菜单服务")
|
||||
|
||||
public class PermissionController {
|
||||
|
||||
@Autowired
|
||||
private PermissionService permissionService;
|
||||
|
||||
@ApiOperation(value = "获取菜单")
|
||||
@GetMapping
|
||||
public Result index() {
|
||||
try {
|
||||
List<Permission> list = permissionService.queryAllMenu();
|
||||
return StringUtils.isNotEmpty(list.toString()) ? Result.ok(list) : Result.fail(list);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("获取菜单异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "新增菜单")
|
||||
@PostMapping("save")
|
||||
public Result save(@RequestBody Permission permission) {
|
||||
try {
|
||||
boolean result = permissionService.save(permission);
|
||||
return result ? Result.ok(null) : Result.fail(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("新增菜单异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "修改菜单")
|
||||
@PutMapping("update")
|
||||
public Result updateById(@RequestBody Permission permission) {
|
||||
try {
|
||||
boolean result = permissionService.updateById(permission);
|
||||
return result ? Result.ok(null) : Result.fail(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("修改菜单异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "递归删除菜单")
|
||||
@DeleteMapping("remove/{id}")
|
||||
public Result remove(@PathVariable Long id) {
|
||||
try {
|
||||
boolean result = permissionService.removeChildById(id);
|
||||
return result ? Result.ok(null) : Result.fail(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("递归删除菜单异常", e);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,128 @@
|
||||
package com.yovinchen.xlcs.acl.controller;
|
||||
|
||||
import com.yovinchen.xlcs.acl.service.PermissionService;
|
||||
import com.yovinchen.xlcs.acl.service.RoleService;
|
||||
import com.yovinchen.xlcs.common.result.Result;
|
||||
import com.yovinchen.xlcs.model.acl.Role;
|
||||
import com.yovinchen.xlcs.vo.acl.RoleQueryVo;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ClassName: RoleController
|
||||
* Package: com.yovinchen.xlcs.acl.controller
|
||||
* 角色管理 前端控制器
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/9/14 09:09
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/admin/acl/role")
|
||||
@Api(tags = "角色管理")
|
||||
|
||||
@Slf4j
|
||||
public class RoleController {
|
||||
|
||||
@Autowired
|
||||
private RoleService roleService;
|
||||
@Autowired
|
||||
private PermissionService permissionService;
|
||||
|
||||
@ApiOperation(value = "获取角色分页列表")
|
||||
@GetMapping("{page}/{limit}")
|
||||
public Result index(@ApiParam(name = "page", value = "当前页码", required = true)
|
||||
@PathVariable Long page, @ApiParam(name = "limit", value = "每页记录数", required = true)
|
||||
@PathVariable Long limit, @ApiParam(name = "roleQueryVo", value = "查询对象", required = false)
|
||||
RoleQueryVo roleQueryVo) {
|
||||
try {
|
||||
Page<Role> pageParam = new Page<>(page, limit);
|
||||
IPage<Role> pageModel = roleService.selectPage(pageParam, roleQueryVo);
|
||||
return Result.ok(pageModel);
|
||||
} catch (Exception e) {
|
||||
// 处理异常,例如记录日志或者抛出自定义异常
|
||||
throw new RuntimeException("获取角色分页列表异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取角色")
|
||||
@GetMapping("get/{id}")
|
||||
public Result get(@PathVariable Long id) {
|
||||
try {
|
||||
Role role = roleService.getById(id);
|
||||
return Result.ok(role);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("获取角色异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "新增角色")
|
||||
@PostMapping("save")
|
||||
public Result save(@RequestBody Role role) {
|
||||
try {
|
||||
boolean result = roleService.save(role);
|
||||
return result ? Result.ok(null) : Result.fail(null);
|
||||
} catch (Exception e) {
|
||||
// 处理异常,例如记录日志或者抛出自定义异常
|
||||
throw new RuntimeException("新增角色异常" + role.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "修改角色")
|
||||
@PutMapping("update")
|
||||
public Result updateById(@RequestBody Role role) {
|
||||
try {
|
||||
boolean result = roleService.updateById(role);
|
||||
return result ? Result.ok(null) : Result.fail(null);
|
||||
} catch (Exception e) {
|
||||
// 处理异常,例如记录日志或者抛出自定义异常
|
||||
throw new RuntimeException("修改角色异常" + role.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "删除角色")
|
||||
@DeleteMapping("remove/{id}")
|
||||
public Result remove(@PathVariable Long id) {
|
||||
try {
|
||||
boolean result = roleService.removeById(id);
|
||||
return result ? Result.ok(null) : Result.fail(null);
|
||||
} catch (Exception e) {
|
||||
// 处理异常,例如记录日志或者抛出自定义异常
|
||||
throw new RuntimeException("删除角色异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "根据id列表删除角色")
|
||||
@DeleteMapping("batchRemove")
|
||||
public Result batchRemove(@RequestBody List<Long> idList) {
|
||||
// TODO
|
||||
try {
|
||||
boolean result = roleService.removeByIds(idList);
|
||||
return result ? Result.ok(null) : Result.fail(null);
|
||||
} catch (Exception e) {
|
||||
// 处理异常,例如记录日志或者抛出自定义异常
|
||||
throw new RuntimeException("根据id列表删除角色异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取一个角色的所有权限列表")
|
||||
@GetMapping("toAssign/{id}")
|
||||
public Result toAssign(@PathVariable Long id) {
|
||||
// TODO
|
||||
try {
|
||||
Map<String, Object> result = permissionService.getPermissionById(id);
|
||||
return Result.ok(result);
|
||||
} catch (Exception e) {
|
||||
// 处理异常,例如记录日志或者抛出自定义异常
|
||||
throw new RuntimeException("获取一个角色的所有权限列表异常", e);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
package com.yovinchen.xlcs.acl.mapper;
|
||||
|
||||
import com.yovinchen.xlcs.model.acl.Admin;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* ClassName: AdminMapper
|
||||
* Package: com.yovinchen.xlcs.acl.mapper
|
||||
* 用户管理
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/9/14 10:45
|
||||
*/
|
||||
@Repository
|
||||
public interface AdminMapper extends BaseMapper<Admin> {
|
||||
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package com.yovinchen.xlcs.acl.mapper;
|
||||
|
||||
import com.yovinchen.xlcs.model.acl.AdminRole;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* ClassName: AdminRoleMapper
|
||||
* Package: com.yovinchen.xlcs.acl.mapper
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/9/14 11:15
|
||||
*/
|
||||
@Repository
|
||||
public interface AdminRoleMapper extends BaseMapper<AdminRole> {
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
package com.yovinchen.xlcs.acl.mapper;
|
||||
|
||||
import com.yovinchen.xlcs.model.acl.Permission;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* ClassName: PermissionMapper
|
||||
* Package: com.yovinchen.xlcs.acl.mapper
|
||||
* 菜单Mapper接口
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/9/14 13:59
|
||||
*/
|
||||
@Repository
|
||||
public interface PermissionMapper extends BaseMapper<Permission> {
|
||||
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
package com.yovinchen.xlcs.acl.mapper;
|
||||
|
||||
import com.yovinchen.xlcs.model.acl.Role;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* ClassName: RoleMapper
|
||||
* Package: com.yovinchen.xlcs.acl.mapper
|
||||
* 角色管理
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/9/14 09:11
|
||||
*/
|
||||
@Repository
|
||||
public interface RoleMapper extends BaseMapper<Role> {
|
||||
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
package com.yovinchen.xlcs.acl.mapper;
|
||||
|
||||
import com.yovinchen.xlcs.model.acl.RolePermission;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* ClassName: RolePermissionMapper
|
||||
* Package: com.yovinchen.xlcs.acl.mapper
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/9/14 15:07
|
||||
*/
|
||||
public interface RolePermissionMapper extends BaseMapper<RolePermission> {
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
package com.yovinchen.xlcs.acl.service;
|
||||
|
||||
import com.yovinchen.xlcs.model.acl.AdminRole;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* ClassName: AdminRoleService
|
||||
* Package: com.yovinchen.xlcs.acl.service
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/9/14 11:15
|
||||
*/
|
||||
public interface AdminRoleService extends IService<AdminRole> {
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
package com.yovinchen.xlcs.acl.service;
|
||||
|
||||
import com.yovinchen.xlcs.model.acl.Admin;
|
||||
import com.yovinchen.xlcs.vo.acl.AdminQueryVo;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* ClassName: AdminService
|
||||
* Package: com.yovinchen.xlcs.acl.service
|
||||
* 用户管理
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/9/14 10:44
|
||||
*/
|
||||
public interface AdminService extends IService<Admin> {
|
||||
|
||||
/**
|
||||
* 用户分页列表
|
||||
*
|
||||
* @param pageParam
|
||||
* @param userQueryVo
|
||||
* @return
|
||||
*/
|
||||
IPage<Admin> selectPage(Page<Admin> pageParam, AdminQueryVo userQueryVo);
|
||||
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
package com.yovinchen.xlcs.acl.service;
|
||||
|
||||
import com.yovinchen.xlcs.model.acl.Permission;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ClassName: PermissionService
|
||||
* Package: com.yovinchen.xlcs.acl.service
|
||||
* 权限服务
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/9/14 14:01
|
||||
*/
|
||||
public interface PermissionService extends IService<Permission> {
|
||||
|
||||
//获取所有菜单列表
|
||||
List<Permission> queryAllMenu();
|
||||
|
||||
//递归删除
|
||||
boolean removeChildById(Long id);
|
||||
|
||||
Map<String, Object> getPermissionById(Long id);
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
package com.yovinchen.xlcs.acl.service;
|
||||
|
||||
import com.yovinchen.xlcs.model.acl.Role;
|
||||
import com.yovinchen.xlcs.vo.acl.RoleQueryVo;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ClassName: RoleService
|
||||
* Package: com.yovinchen.xlcs.acl.service
|
||||
* 用户管理
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/9/14 09:10
|
||||
*/
|
||||
public interface RoleService extends IService<Role> {
|
||||
|
||||
//角色分页列表
|
||||
IPage<Role> selectPage(Page<Role> pageParam, RoleQueryVo roleQueryVo);
|
||||
|
||||
Map<String, Object> findRoleByUserId(Long adminId);
|
||||
|
||||
void saveUserRoleRealtionShip(Long adminId, Long[] roleId);
|
||||
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package com.yovinchen.xlcs.acl.service.impl;
|
||||
|
||||
import com.yovinchen.xlcs.acl.mapper.AdminRoleMapper;
|
||||
import com.yovinchen.xlcs.acl.service.AdminRoleService;
|
||||
import com.yovinchen.xlcs.model.acl.AdminRole;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* ClassName: AdminRoleServiceImpl
|
||||
* Package: com.yovinchen.xlcs.acl.service.impl
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/9/14 11:15
|
||||
*/
|
||||
@Service
|
||||
public class AdminRoleServiceImpl extends ServiceImpl<AdminRoleMapper, AdminRole>
|
||||
implements AdminRoleService {
|
||||
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
package com.yovinchen.xlcs.acl.service.impl;
|
||||
|
||||
import com.yovinchen.xlcs.acl.mapper.AdminMapper;
|
||||
import com.yovinchen.xlcs.acl.service.AdminService;
|
||||
import com.yovinchen.xlcs.acl.service.RoleService;
|
||||
import com.yovinchen.xlcs.model.acl.Admin;
|
||||
import com.yovinchen.xlcs.vo.acl.AdminQueryVo;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* ClassName: AdminServiceImpl
|
||||
* Package: com.yovinchen.xlcs.acl.service.impl
|
||||
* 用户管理
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/9/14 10:44
|
||||
*/
|
||||
@Service
|
||||
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {
|
||||
|
||||
@Autowired
|
||||
private AdminMapper userMapper;
|
||||
|
||||
@Autowired
|
||||
private RoleService roleService;
|
||||
|
||||
@Override
|
||||
public IPage<Admin> selectPage(Page<Admin> pageParam, AdminQueryVo userQueryVo) {
|
||||
//获取用户名称条件值
|
||||
String name = userQueryVo.getName();
|
||||
//创建条件构造器
|
||||
LambdaQueryWrapper<Admin> wrapper = new LambdaQueryWrapper<>();
|
||||
if (!StringUtils.isEmpty(name)) {
|
||||
//封装条件
|
||||
wrapper.like(Admin::getName, name);
|
||||
}
|
||||
//调用mapper方法
|
||||
IPage<Admin> pageModel = baseMapper.selectPage(pageParam, wrapper);
|
||||
return pageModel;
|
||||
}
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
package com.yovinchen.xlcs.acl.service.impl;
|
||||
|
||||
import com.yovinchen.xlcs.acl.mapper.PermissionMapper;
|
||||
import com.yovinchen.xlcs.acl.service.PermissionService;
|
||||
import com.yovinchen.xlcs.acl.utils.PermissionHelper;
|
||||
import com.yovinchen.xlcs.model.acl.Permission;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ClassName: PermissionServiceImpl
|
||||
* Package: com.yovinchen.xlcs.acl.service.impl
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/9/14 14:02
|
||||
*/
|
||||
@Service
|
||||
public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permission> implements PermissionService {
|
||||
|
||||
|
||||
/**
|
||||
* 获取所有菜单
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<Permission> queryAllMenu() {
|
||||
//获取全部权限数据
|
||||
List<Permission> allPermissionList = baseMapper.selectList(new QueryWrapper<Permission>().orderByAsc("CAST(id AS SIGNED)"));
|
||||
|
||||
//把权限数据构建成树形结构数据
|
||||
return PermissionHelper.bulid(allPermissionList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归删除菜单
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean removeChildById(Long id) {
|
||||
List<Long> idList = new ArrayList<>();
|
||||
this.selectChildListById(id, idList);
|
||||
idList.add(id);
|
||||
baseMapper.deleteBatchIds(idList);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getPermissionById(Long id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归获取子节点
|
||||
*
|
||||
* @param id
|
||||
* @param idList
|
||||
*/
|
||||
private void selectChildListById(Long id, List<Long> idList) {
|
||||
List<Permission> childList = baseMapper.selectList(new QueryWrapper<Permission>()
|
||||
.eq("pid", id)
|
||||
.select("id"));
|
||||
childList.forEach(item -> {
|
||||
idList.add(item.getId());
|
||||
this.selectChildListById(item.getId(), idList);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,114 @@
|
||||
package com.yovinchen.xlcs.acl.service.impl;
|
||||
|
||||
import com.yovinchen.xlcs.acl.mapper.RoleMapper;
|
||||
import com.yovinchen.xlcs.acl.service.AdminRoleService;
|
||||
import com.yovinchen.xlcs.acl.service.RoleService;
|
||||
import com.yovinchen.xlcs.model.acl.AdminRole;
|
||||
import com.yovinchen.xlcs.model.acl.Role;
|
||||
import com.yovinchen.xlcs.vo.acl.RoleQueryVo;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* ClassName: RoleServiceImpl
|
||||
* Package: com.yovinchen.xlcs.acl.service.impl
|
||||
* 角色管理
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/9/14 09:11
|
||||
*/
|
||||
@Service
|
||||
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
|
||||
|
||||
@Autowired
|
||||
private AdminRoleService adminRoleService;
|
||||
|
||||
//角色分页列表
|
||||
@Override
|
||||
public IPage<Role> selectPage(Page<Role> pageParam, RoleQueryVo roleQueryVo) {
|
||||
//获取条件值:角色名称
|
||||
String roleName = roleQueryVo.getRoleName();
|
||||
//创建条件构造器对象
|
||||
LambdaQueryWrapper<Role> wrapper = new LambdaQueryWrapper<>();
|
||||
//判断条件值是否为空
|
||||
if (!StringUtils.isEmpty(roleName)) {
|
||||
//封装条件
|
||||
wrapper.like(Role::getRoleName, roleName);
|
||||
}
|
||||
//调用mapper方法实现条件分页查询
|
||||
IPage<Role> pageModel = baseMapper.selectPage(pageParam, wrapper);
|
||||
return pageModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分配角色
|
||||
*
|
||||
* @param adminId
|
||||
* @param roleIds
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveUserRoleRealtionShip(Long adminId, Long[] roleIds) {
|
||||
//删除用户分配的角色数据
|
||||
adminRoleService.remove(new QueryWrapper<AdminRole>().eq("admin_id", adminId));
|
||||
|
||||
//分配新的角色
|
||||
List<AdminRole> userRoleList = new ArrayList<>();
|
||||
for (Long roleId : roleIds) {
|
||||
if (StringUtils.isEmpty(roleId)) continue;
|
||||
AdminRole userRole = new AdminRole();
|
||||
userRole.setAdminId(adminId);
|
||||
userRole.setRoleId(roleId);
|
||||
userRoleList.add(userRole);
|
||||
}
|
||||
adminRoleService.saveBatch(userRoleList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户获取角色数据
|
||||
*
|
||||
* @param adminId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> findRoleByUserId(Long adminId) {
|
||||
//查询所有的角色
|
||||
List<Role> allRolesList = baseMapper.selectList(null);
|
||||
|
||||
//拥有的角色id
|
||||
List<AdminRole> existUserRoleList = adminRoleService.list(new QueryWrapper<AdminRole>()
|
||||
.eq("admin_id", adminId)
|
||||
.select("role_id"));
|
||||
List<Long> existRoleList = existUserRoleList
|
||||
.stream()
|
||||
.map(AdminRole::getRoleId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
//对角色进行分类
|
||||
List<Role> assignRoles = new ArrayList<Role>();
|
||||
for (Role role : allRolesList) {
|
||||
//已分配
|
||||
if (existRoleList.contains(role.getId())) {
|
||||
assignRoles.add(role);
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Object> roleMap = new HashMap<>();
|
||||
roleMap.put("assignRoles", assignRoles);
|
||||
roleMap.put("allRolesList", allRolesList);
|
||||
return roleMap;
|
||||
}
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
package com.yovinchen.xlcs.acl.utils;
|
||||
|
||||
import com.yovinchen.xlcs.model.acl.Permission;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ClassName: PermissionHelper
|
||||
* Package: com.yovinchen.xlcs.acl.utils
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/9/14 14:23
|
||||
*/
|
||||
public class PermissionHelper {
|
||||
|
||||
/**
|
||||
* 使用递归方法建菜单
|
||||
*
|
||||
* @param treeNodes
|
||||
* @return
|
||||
*/
|
||||
public static List<Permission> bulid(List<Permission> treeNodes) {
|
||||
List<Permission> trees = new ArrayList<>();
|
||||
for (Permission treeNode : treeNodes) {
|
||||
if (treeNode.getPid() == 0) {
|
||||
treeNode.setLevel(1);
|
||||
trees.add(findChildren(treeNode, treeNodes));
|
||||
}
|
||||
}
|
||||
return trees;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归查找子节点
|
||||
*
|
||||
* @param treeNodes
|
||||
* @return
|
||||
*/
|
||||
public static Permission findChildren(Permission treeNode, List<Permission> treeNodes) {
|
||||
treeNode.setChildren(new ArrayList<Permission>());
|
||||
|
||||
for (Permission it : treeNodes) {
|
||||
if (treeNode
|
||||
.getId()
|
||||
.longValue() == it
|
||||
.getPid()
|
||||
.longValue()) {
|
||||
int level = treeNode.getLevel() + 1;
|
||||
it.setLevel(level);
|
||||
if (treeNode.getChildren() == null) {
|
||||
treeNode.setChildren(new ArrayList<>());
|
||||
}
|
||||
treeNode
|
||||
.getChildren()
|
||||
.add(findChildren(it, treeNodes));
|
||||
}
|
||||
}
|
||||
return treeNode;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,11 @@
|
||||
server:
|
||||
port: 8201
|
||||
spring:
|
||||
application:
|
||||
name: service-acl
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 82.157.68.223:8848
|
||||
username: nacos
|
||||
password: nacos
|
@@ -0,0 +1,18 @@
|
||||
spring:
|
||||
cloud:
|
||||
nacos:
|
||||
config:
|
||||
namespace: dd5265c5-8290-45bc-9d07-395c14c977d3
|
||||
server-addr: 82.157.68.223:8848
|
||||
group: service
|
||||
username: nacos
|
||||
password: nacos
|
||||
enabled: true
|
||||
file-extension: yml
|
||||
extension-configs:
|
||||
- data-id: common.yml
|
||||
group: common
|
||||
refresh: true
|
||||
- data-id: service-redis.yml
|
||||
group: common
|
||||
refresh: true
|
@@ -0,0 +1,19 @@
|
||||
module.log=com.p6spy.engine.logging.P6LogFactory,com.p6spy.engine.outage.P6OutageFactory
|
||||
# \u81EA\u5B9A\u4E49\u65E5\u5FD7\u6253\u5370
|
||||
#logMessageFormat=com.p6spy.engine.spy.appender.SingleLineFormat
|
||||
logMessageFormat=com.p6spy.engine.spy.appender.CustomLineFormat
|
||||
customLogMessageFormat=%(currentTime) | SQL\u8017\u65F6\uFF1A %(executionTime) ms | \u8FDE\u63A5\u4FE1\u606F\uFF1A %(category)-%(connectionId) | \u6267\u884C\u8BED\u53E5\uFF1A %(sql)
|
||||
# \u4F7F\u7528\u63A7\u5236\u53F0\u8BB0\u5F55sql
|
||||
appender=com.p6spy.engine.spy.appender.StdoutLogger
|
||||
## \u914D\u7F6E\u8BB0\u5F55Log\u4F8B\u5916
|
||||
excludecategories=info,debug,result,batc,resultset
|
||||
# \u8BBE\u7F6E\u4F7F\u7528p6spy driver\u6765\u505A\u4EE3\u7406
|
||||
deregisterdrivers=true
|
||||
# \u65E5\u671F\u683C\u5F0F
|
||||
dateformat=yyyy-MM-dd HH:mm:ss
|
||||
# \u5B9E\u9645\u9A71\u52A8
|
||||
driverlist=com.mysql.jdbc.Driver
|
||||
# \u662F\u5426\u5F00\u542F\u6162SQL\u8BB0\u5F55
|
||||
outagedetection=true
|
||||
# \u6162SQL\u8BB0\u5F55\u6807\u51C6 \u79D2
|
||||
outagedetectioninterval=2
|
5
xlcs-parent/service/service-activity/Dockerfile
Normal file
5
xlcs-parent/service/service-activity/Dockerfile
Normal file
@@ -0,0 +1,5 @@
|
||||
FROM openjdk:8-jdk-alpine
|
||||
LABEL authors="yovinchen"
|
||||
VOLUME /tmp
|
||||
ADD ./target/service-activity.jar service-activity.jar
|
||||
ENTRYPOINT ["java","-jar","/service-activity.jar", "&"]
|
28
xlcs-parent/service/service-activity/pom.xml
Normal file
28
xlcs-parent/service/service-activity/pom.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.yovinchen</groupId>
|
||||
<artifactId>service</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>service-activity</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.yovinchen</groupId>
|
||||
<artifactId>service-product-client</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
@@ -0,0 +1,23 @@
|
||||
package com.yovinchen.xlcs;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
/**
|
||||
* ClassName: ServiceActivityApplication
|
||||
* Package: com.yovinchen.xlcs
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/9/17 12:08
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableDiscoveryClient
|
||||
@EnableFeignClients
|
||||
public class ServiceActivityApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ServiceActivityApplication.class, args);
|
||||
}
|
||||
}
|
@@ -0,0 +1,79 @@
|
||||
package com.yovinchen.xlcs.activity.api;
|
||||
|
||||
import com.yovinchen.xlcs.activity.service.ActivityInfoService;
|
||||
import com.yovinchen.xlcs.activity.service.CouponInfoService;
|
||||
import com.yovinchen.xlcs.model.activity.CouponInfo;
|
||||
import com.yovinchen.xlcs.model.order.CartInfo;
|
||||
import com.yovinchen.xlcs.vo.order.CartInfoVo;
|
||||
import com.yovinchen.xlcs.vo.order.OrderConfirmVo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ClassName: ActivityInfoController
|
||||
* Package: com.yovinchen.xlcs.activity.api
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/9/26 14:12
|
||||
*/
|
||||
@Api(tags = "促销与优惠券接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/activity")
|
||||
@Slf4j
|
||||
public class ActivityApiController {
|
||||
|
||||
@Resource
|
||||
private ActivityInfoService activityInfoService;
|
||||
|
||||
@Autowired
|
||||
private CouponInfoService couponInfoService;
|
||||
|
||||
@ApiOperation("获取购物车中满足条件优惠券和活动")
|
||||
@PostMapping("inner/findCartActivityAndCoupon/{userId}")
|
||||
public OrderConfirmVo findCartActivityAndCoupon(
|
||||
@RequestBody List<CartInfo> cartInfoList, @PathVariable("userId") Long userId) {
|
||||
return activityInfoService.findCartActivityAndCoupon(cartInfoList, userId);
|
||||
|
||||
}
|
||||
|
||||
@ApiOperation(value = "根据skuId列表获取促销信息")
|
||||
@PostMapping("inner/findActivity")
|
||||
public Map<Long, List<String>> findActivity(@RequestBody List<Long> skuIdList) {
|
||||
return activityInfoService.findActivity(skuIdList);
|
||||
}
|
||||
|
||||
@ApiOperation("根据skuID获取营销数据和优惠卷")
|
||||
@GetMapping("inner/findActivityAndCoupon/{skuId}/{userId}")
|
||||
public Map<String, Object> findActivityAndCoupon(
|
||||
@PathVariable("skuId") Long skuId, @PathVariable("userId") Long userId) {
|
||||
return activityInfoService.findActivityAndCoupon(skuId, userId);
|
||||
}
|
||||
|
||||
@ApiOperation("获取购物车对应规则数据")
|
||||
@PostMapping("inner/findCartActivityList")
|
||||
public List<CartInfoVo> findCartActivityList(@RequestBody List<CartInfo> cartInfoList) {
|
||||
return activityInfoService.findCartActivityList(cartInfoList);
|
||||
}
|
||||
|
||||
@ApiOperation("获取购物车对应优惠券数据")
|
||||
@PostMapping("inner/findRangeSkuIdList")
|
||||
public CouponInfo findRangeSkuIdList(@RequestBody List<CartInfo> cartInfoList, @PathVariable("couponId") Long couponId) {
|
||||
return couponInfoService.findRangeSkuIdList(cartInfoList, couponId);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "更新优惠卷使用状态")
|
||||
@GetMapping("inner/updateCouponInfoUseStatus/{couponId}/{userId}/{orderId}")
|
||||
public Boolean updateCouponInfoUseStatus(@PathVariable("couponId") Long couponId,
|
||||
@PathVariable("userId") Long userId,
|
||||
@PathVariable("orderId") Long orderId) {
|
||||
couponInfoService.updateCouponInfoUseStatus(couponId, userId, orderId);
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,101 @@
|
||||
package com.yovinchen.xlcs.activity.controller;
|
||||
|
||||
|
||||
import com.yovinchen.xlcs.activity.service.ActivityInfoService;
|
||||
import com.yovinchen.xlcs.common.result.Result;
|
||||
import com.yovinchen.xlcs.model.activity.ActivityInfo;
|
||||
import com.yovinchen.xlcs.vo.activity.ActivityRuleVo;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 活动表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@Api(value = "ActivityInfo管理", tags = "活动管理")
|
||||
@RestController
|
||||
|
||||
@RequestMapping("/admin/activity/activityInfo")
|
||||
public class ActivityInfoController {
|
||||
|
||||
@Autowired
|
||||
private ActivityInfoService activityInfoService;
|
||||
|
||||
@ApiOperation(value = "获取分页列表")
|
||||
@GetMapping("{page}/{limit}")
|
||||
public Result index(
|
||||
@ApiParam(name = "page", value = "当前页码", required = true) @PathVariable Long page,
|
||||
@ApiParam(name = "limit", value = "每页记录数", required = true) @PathVariable Long limit) {
|
||||
Page<ActivityInfo> pageParam = new Page<>(page, limit);
|
||||
IPage<ActivityInfo> pageModel = activityInfoService.selectPage(pageParam);
|
||||
return Result.ok(pageModel);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取活动")
|
||||
@GetMapping("get/{id}")
|
||||
public Result get(@PathVariable Long id) {
|
||||
ActivityInfo activityInfo = activityInfoService.getById(id);
|
||||
activityInfo.setActivityTypeString(activityInfo.getActivityType()
|
||||
.getComment());
|
||||
return Result.ok(activityInfo);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "新增活动")
|
||||
@PostMapping("save")
|
||||
public Result save(@RequestBody ActivityInfo activityInfo) {
|
||||
activityInfoService.save(activityInfo);
|
||||
return Result.ok(null);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "修改活动")
|
||||
@PutMapping("update")
|
||||
public Result updateById(@RequestBody ActivityInfo activityInfo) {
|
||||
activityInfoService.updateById(activityInfo);
|
||||
return Result.ok(null);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "删除活动")
|
||||
@DeleteMapping("remove/{id}")
|
||||
public Result remove(@PathVariable Long id) {
|
||||
activityInfoService.removeById(id);
|
||||
return Result.ok(null);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "根据id列表删除活动")
|
||||
@DeleteMapping("batchRemove")
|
||||
public Result batchRemove(@RequestBody List<String> idList) {
|
||||
activityInfoService.removeByIds(idList);
|
||||
return Result.ok(null);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取活动规则")
|
||||
@GetMapping("findActivityRuleList/{id}")
|
||||
public Result findActivityRuleList(@PathVariable Long id) {
|
||||
return Result.ok(activityInfoService.findActivityRuleList(id));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "新增活动规则")
|
||||
@PostMapping("saveActivityRule")
|
||||
public Result saveActivityRule(@RequestBody ActivityRuleVo activityRuleVo) {
|
||||
activityInfoService.saveActivityRule(activityRuleVo);
|
||||
return Result.ok(null);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "根据关键字获取sku列表,活动使用")
|
||||
@GetMapping("findSkuInfoByKeyword/{keyword}")
|
||||
public Result findSkuInfoByKeyword(@PathVariable("keyword") String keyword) {
|
||||
return Result.ok(activityInfoService.findSkuInfoByKeyword(keyword));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,20 @@
|
||||
package com.yovinchen.xlcs.activity.controller;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 优惠规则 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/activity/activity-rule")
|
||||
public class ActivityRuleController {
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,20 @@
|
||||
package com.yovinchen.xlcs.activity.controller;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 活动参与商品 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/activity/activity-sku")
|
||||
public class ActivitySkuController {
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,100 @@
|
||||
package com.yovinchen.xlcs.activity.controller;
|
||||
|
||||
|
||||
import com.yovinchen.xlcs.activity.service.CouponInfoService;
|
||||
import com.yovinchen.xlcs.common.result.Result;
|
||||
import com.yovinchen.xlcs.model.activity.CouponInfo;
|
||||
import com.yovinchen.xlcs.vo.activity.CouponRuleVo;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 优惠券信息 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@RestController
|
||||
|
||||
@RequestMapping("/admin/activity/couponInfo")
|
||||
public class CouponInfoController {
|
||||
|
||||
@Autowired
|
||||
private CouponInfoService couponInfoService;
|
||||
|
||||
@ApiOperation(value = "获取分页列表")
|
||||
@GetMapping("{page}/{limit}")
|
||||
public Result index(
|
||||
@ApiParam(name = "page", value = "当前页码", required = true) @PathVariable Long page,
|
||||
@ApiParam(name = "limit", value = "每页记录数", required = true) @PathVariable Long limit) {
|
||||
IPage<CouponInfo> pageModel = couponInfoService.selectPage(page, limit);
|
||||
return Result.ok(pageModel);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "根据ID查询优惠券")
|
||||
@GetMapping("get/{id}")
|
||||
public Result get(@PathVariable Long id) {
|
||||
CouponInfo couponInfo = couponInfoService.getCouponInfo(id);
|
||||
return Result.ok(couponInfo);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "新增优惠券")
|
||||
@PostMapping("save")
|
||||
public Result save(@RequestBody CouponInfo couponInfo) {
|
||||
couponInfoService.save(couponInfo);
|
||||
return Result.ok(null);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "修改优惠券")
|
||||
@PutMapping("update")
|
||||
public Result updateById(@RequestBody CouponInfo couponInfo) {
|
||||
couponInfoService.updateById(couponInfo);
|
||||
return Result.ok(null);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "删除优惠券")
|
||||
@DeleteMapping("remove/{id}")
|
||||
public Result remove(@PathVariable String id) {
|
||||
couponInfoService.removeById(id);
|
||||
return Result.ok(null);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "根据id列表删除优惠券")
|
||||
@DeleteMapping("batchRemove")
|
||||
public Result batchRemove(@RequestBody List<String> idList) {
|
||||
couponInfoService.removeByIds(idList);
|
||||
return Result.ok(null);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取优惠券信息")
|
||||
@GetMapping("findCouponRuleList/{id}")
|
||||
public Result findActivityRuleList(@PathVariable Long id) {
|
||||
return Result.ok(couponInfoService.findCouponRuleList(id));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "新增优惠券")
|
||||
@PostMapping("saveCouponRule")
|
||||
public Result saveCouponRule(@RequestBody CouponRuleVo couponRuleVo) {
|
||||
couponInfoService.saveCouponRule(couponRuleVo);
|
||||
return Result.ok(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据关键字获取sku列表,活动使用
|
||||
*
|
||||
* @param keyword
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("findCouponByKeyword/{keyword}")
|
||||
public Result findCouponByKeyword(@PathVariable("keyword") String keyword) {
|
||||
return Result.ok(couponInfoService.findCouponByKeyword(keyword));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,20 @@
|
||||
package com.yovinchen.xlcs.activity.controller;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 优惠券范围表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/activity/coupon-range")
|
||||
public class CouponRangeController {
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,20 @@
|
||||
package com.yovinchen.xlcs.activity.controller;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 优惠券领用表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/activity/coupon-use")
|
||||
public class CouponUseController {
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,20 @@
|
||||
package com.yovinchen.xlcs.activity.controller;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 首页专题表【jd首页下面很多专题,每个专题链接新的页面,展示专题商品信息】 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/activity/home-subject")
|
||||
public class HomeSubjectController {
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,20 @@
|
||||
package com.yovinchen.xlcs.activity.controller;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 专题商品 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/activity/home-subject-sku")
|
||||
public class HomeSubjectSkuController {
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,20 @@
|
||||
package com.yovinchen.xlcs.activity.controller;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 秒杀活动 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/activity/seckill")
|
||||
public class SeckillController {
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,20 @@
|
||||
package com.yovinchen.xlcs.activity.controller;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 秒杀活动商品关联 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/activity/seckill-sku")
|
||||
public class SeckillSkuController {
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,20 @@
|
||||
package com.yovinchen.xlcs.activity.controller;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 秒杀商品通知订阅 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/activity/seckill-sku-notice")
|
||||
public class SeckillSkuNoticeController {
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,20 @@
|
||||
package com.yovinchen.xlcs.activity.controller;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 秒杀活动场次 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/activity/seckill-time")
|
||||
public class SeckillTimeController {
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,20 @@
|
||||
package com.yovinchen.xlcs.activity.controller;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* sku信息 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/activity/sku-info")
|
||||
public class SkuInfoController {
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,46 @@
|
||||
package com.yovinchen.xlcs.activity.mapper;
|
||||
|
||||
import com.yovinchen.xlcs.model.activity.ActivityInfo;
|
||||
import com.yovinchen.xlcs.model.activity.ActivityRule;
|
||||
import com.yovinchen.xlcs.model.activity.ActivitySku;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import feign.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 活动表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@Repository
|
||||
public interface ActivityInfoMapper extends BaseMapper<ActivityInfo> {
|
||||
|
||||
/**
|
||||
* 查询两张表判断 activity_info 和 activity_sku,编写SQL语句实现
|
||||
*
|
||||
* @param skuIdList
|
||||
* @return
|
||||
*/
|
||||
List<Long> selectSkuIdListExist(@Param("skuIdList") List<Long> skuIdList);
|
||||
|
||||
/**
|
||||
* 根据skuId进行查询,查询sku对应活动里面规则列表
|
||||
*
|
||||
* @param skuId
|
||||
* @return
|
||||
*/
|
||||
List<ActivityRule> findActivityRule(@Param("skuId") Long skuId);
|
||||
|
||||
/**
|
||||
* 根据所有skuId列表获取参与活动
|
||||
*
|
||||
* @param skuIdList
|
||||
* @return
|
||||
*/
|
||||
List<ActivitySku> selectCartActivity(@Param("skuIdList") List<Long> skuIdList);
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
package com.yovinchen.xlcs.activity.mapper;
|
||||
|
||||
import com.yovinchen.xlcs.model.activity.ActivityRule;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 优惠规则 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@Repository
|
||||
public interface ActivityRuleMapper extends BaseMapper<ActivityRule> {
|
||||
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
package com.yovinchen.xlcs.activity.mapper;
|
||||
|
||||
import com.yovinchen.xlcs.model.activity.ActivitySku;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 活动参与商品 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@Repository
|
||||
public interface ActivitySkuMapper extends BaseMapper<ActivitySku> {
|
||||
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
package com.yovinchen.xlcs.activity.mapper;
|
||||
|
||||
import com.yovinchen.xlcs.model.activity.CouponInfo;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 优惠券信息 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
public interface CouponInfoMapper extends BaseMapper<CouponInfo> {
|
||||
|
||||
/**
|
||||
* 根据条件查询:skuId + 分类id + userId
|
||||
*
|
||||
* @param id
|
||||
* @param categoryId
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<CouponInfo> selectCouponInfoList(
|
||||
@Param("skuId") Long id, @Param("categoryId") Long categoryId, @Param("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 根据userId获取用户全部优惠卷
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<CouponInfo> selectCartCouponInfoList(@Param("userId") Long userId);
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
package com.yovinchen.xlcs.activity.mapper;
|
||||
|
||||
import com.yovinchen.xlcs.model.activity.CouponRange;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 优惠券范围表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@Repository
|
||||
public interface CouponRangeMapper extends BaseMapper<CouponRange> {
|
||||
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
package com.yovinchen.xlcs.activity.mapper;
|
||||
|
||||
import com.yovinchen.xlcs.model.activity.CouponUse;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 优惠券领用表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@Repository
|
||||
public interface CouponUseMapper extends BaseMapper<CouponUse> {
|
||||
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package com.yovinchen.xlcs.activity.mapper;
|
||||
|
||||
import com.yovinchen.xlcs.model.activity.HomeSubject;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 首页专题表【jd首页下面很多专题,每个专题链接新的页面,展示专题商品信息】 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
public interface HomeSubjectMapper extends BaseMapper<HomeSubject> {
|
||||
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package com.yovinchen.xlcs.activity.mapper;
|
||||
|
||||
import com.yovinchen.xlcs.model.activity.HomeSubjectSku;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 专题商品 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
public interface HomeSubjectSkuMapper extends BaseMapper<HomeSubjectSku> {
|
||||
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package com.yovinchen.xlcs.activity.mapper;
|
||||
|
||||
import com.yovinchen.xlcs.model.activity.Seckill;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 秒杀活动 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
public interface SeckillMapper extends BaseMapper<Seckill> {
|
||||
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package com.yovinchen.xlcs.activity.mapper;
|
||||
|
||||
import com.yovinchen.xlcs.model.activity.SeckillSku;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 秒杀活动商品关联 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
public interface SeckillSkuMapper extends BaseMapper<SeckillSku> {
|
||||
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package com.yovinchen.xlcs.activity.mapper;
|
||||
|
||||
import com.yovinchen.xlcs.model.activity.SeckillSkuNotice;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 秒杀商品通知订阅 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
public interface SeckillSkuNoticeMapper extends BaseMapper<SeckillSkuNotice> {
|
||||
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package com.yovinchen.xlcs.activity.mapper;
|
||||
|
||||
import com.yovinchen.xlcs.model.activity.SeckillTime;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 秒杀活动场次 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
public interface SeckillTimeMapper extends BaseMapper<SeckillTime> {
|
||||
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package com.yovinchen.xlcs.activity.mapper;
|
||||
|
||||
import com.yovinchen.xlcs.model.product.SkuInfo;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* sku信息 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
public interface SkuInfoMapper extends BaseMapper<SkuInfo> {
|
||||
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.yovinchen.xlcs.activity.mapper.ActivityRuleMapper">
|
||||
|
||||
</mapper>
|
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.yovinchen.xlcs.activity.mapper.ActivitySkuMapper">
|
||||
|
||||
</mapper>
|
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.yovinchen.xlcs.activity.mapper.CouponRangeMapper">
|
||||
|
||||
</mapper>
|
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.yovinchen.xlcs.activity.mapper.CouponUseMapper">
|
||||
|
||||
</mapper>
|
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.yovinchen.xlcs.activity.mapper.HomeSubjectMapper">
|
||||
|
||||
</mapper>
|
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.yovinchen.xlcs.activity.mapper.HomeSubjectSkuMapper">
|
||||
|
||||
</mapper>
|
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.yovinchen.xlcs.activity.mapper.SeckillMapper">
|
||||
|
||||
</mapper>
|
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.yovinchen.xlcs.activity.mapper.SeckillSkuMapper">
|
||||
|
||||
</mapper>
|
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.yovinchen.xlcs.activity.mapper.SeckillSkuNoticeMapper">
|
||||
|
||||
</mapper>
|
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.yovinchen.xlcs.activity.mapper.SeckillTimeMapper">
|
||||
|
||||
</mapper>
|
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.yovinchen.xlcs.activity.mapper.SkuInfoMapper">
|
||||
|
||||
</mapper>
|
@@ -0,0 +1,92 @@
|
||||
package com.yovinchen.xlcs.activity.service;
|
||||
|
||||
|
||||
import com.yovinchen.xlcs.model.activity.ActivityInfo;
|
||||
import com.yovinchen.xlcs.model.order.CartInfo;
|
||||
import com.yovinchen.xlcs.model.product.SkuInfo;
|
||||
import com.yovinchen.xlcs.vo.activity.ActivityRuleVo;
|
||||
import com.yovinchen.xlcs.vo.order.CartInfoVo;
|
||||
import com.yovinchen.xlcs.vo.order.OrderConfirmVo;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 活动表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
public interface ActivityInfoService extends IService<ActivityInfo> {
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param pageParam
|
||||
* @return
|
||||
*/
|
||||
IPage<ActivityInfo> selectPage(Page<ActivityInfo> pageParam);
|
||||
|
||||
/**
|
||||
* 获取活动规则id
|
||||
*
|
||||
* @param activityId
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> findActivityRuleList(Long activityId);
|
||||
|
||||
/**
|
||||
* 保存活动规则信息
|
||||
*
|
||||
* @param activityRuleVo
|
||||
*/
|
||||
void saveActivityRule(ActivityRuleVo activityRuleVo);
|
||||
|
||||
/**
|
||||
* 根据关键字获取sku信息列表
|
||||
*
|
||||
* @param keyword
|
||||
* @return
|
||||
*/
|
||||
List<SkuInfo> findSkuInfoByKeyword(String keyword);
|
||||
|
||||
/**
|
||||
* 根据skuId列表获取促销信息
|
||||
*
|
||||
* @param skuIdList
|
||||
* @return
|
||||
*/
|
||||
Map<Long, List<String>> findActivity(List<Long> skuIdList);
|
||||
|
||||
/**
|
||||
* 根据skuID获取营销数据和优惠卷
|
||||
*
|
||||
* @param skuId
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> findActivityAndCoupon(Long skuId, Long userId);
|
||||
|
||||
/**
|
||||
* 获取购物车中满足条件优惠券和活动
|
||||
*
|
||||
* @param cartInfoList
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
OrderConfirmVo findCartActivityAndCoupon(List<CartInfo> cartInfoList, Long userId);
|
||||
|
||||
/**
|
||||
* 获取购物车对应规则数据
|
||||
*
|
||||
* @param cartInfoList
|
||||
* @return
|
||||
*/
|
||||
List<CartInfoVo> findCartActivityList(List<CartInfo> cartInfoList);
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package com.yovinchen.xlcs.activity.service;
|
||||
|
||||
import com.yovinchen.xlcs.model.activity.ActivityRule;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 优惠规则 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
public interface ActivityRuleService extends IService<ActivityRule> {
|
||||
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package com.yovinchen.xlcs.activity.service;
|
||||
|
||||
import com.yovinchen.xlcs.model.activity.ActivitySku;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 活动参与商品 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
public interface ActivitySkuService extends IService<ActivitySku> {
|
||||
|
||||
}
|
@@ -0,0 +1,99 @@
|
||||
package com.yovinchen.xlcs.activity.service;
|
||||
|
||||
import com.yovinchen.xlcs.model.activity.CouponInfo;
|
||||
import com.yovinchen.xlcs.model.order.CartInfo;
|
||||
import com.yovinchen.xlcs.vo.activity.CouponRuleVo;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 优惠券信息 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
public interface CouponInfoService extends IService<CouponInfo> {
|
||||
|
||||
|
||||
/**
|
||||
* 获取分页列表
|
||||
*
|
||||
* @param page
|
||||
* @param limit
|
||||
* @return
|
||||
*/
|
||||
IPage<CouponInfo> selectPage(Long page, Long limit);
|
||||
|
||||
/**
|
||||
* 根据ID查询优惠券
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
CouponInfo getCouponInfo(Long id);
|
||||
|
||||
/**
|
||||
* 根据优惠卷id获取优惠券规则列表
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> findCouponRuleList(Long id);
|
||||
|
||||
/**
|
||||
* 新增优惠券规则
|
||||
*
|
||||
* @param couponRuleVo
|
||||
*/
|
||||
void saveCouponRule(CouponRuleVo couponRuleVo);
|
||||
|
||||
/**
|
||||
* 根据关键字获取sku列表,活动使用
|
||||
*
|
||||
* @param keyword
|
||||
* @return
|
||||
*/
|
||||
List<CouponInfo> findCouponByKeyword(String keyword);
|
||||
|
||||
/**
|
||||
* 根据skuId+userId查询优惠卷信息
|
||||
*
|
||||
* @param skuId
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
|
||||
List<CouponInfo> findCouponInfoList(Long skuId, Long userId);
|
||||
|
||||
/**
|
||||
* 获取购物车可以使用优惠卷列表
|
||||
*
|
||||
* @param cartInfoList
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<CouponInfo> findCartCouponInfo(List<CartInfo> cartInfoList, Long userId);
|
||||
|
||||
/**
|
||||
* 获取购物车对应优惠券数据
|
||||
*
|
||||
* @param cartInfoList
|
||||
* @param couponId
|
||||
* @return
|
||||
*/
|
||||
CouponInfo findRangeSkuIdList(List<CartInfo> cartInfoList, Long couponId);
|
||||
|
||||
/**
|
||||
* 更新优惠卷使用状态
|
||||
*
|
||||
* @param couponId
|
||||
* @param userId
|
||||
* @param orderId
|
||||
*/
|
||||
void updateCouponInfoUseStatus(Long couponId, Long userId, Long orderId);
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package com.yovinchen.xlcs.activity.service;
|
||||
|
||||
import com.yovinchen.xlcs.model.activity.CouponRange;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 优惠券范围表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
public interface CouponRangeService extends IService<CouponRange> {
|
||||
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package com.yovinchen.xlcs.activity.service;
|
||||
|
||||
import com.yovinchen.xlcs.model.activity.CouponUse;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 优惠券领用表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
public interface CouponUseService extends IService<CouponUse> {
|
||||
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package com.yovinchen.xlcs.activity.service;
|
||||
|
||||
import com.yovinchen.xlcs.model.activity.HomeSubject;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 首页专题表【jd首页下面很多专题,每个专题链接新的页面,展示专题商品信息】 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
public interface HomeSubjectService extends IService<HomeSubject> {
|
||||
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package com.yovinchen.xlcs.activity.service;
|
||||
|
||||
import com.yovinchen.xlcs.model.activity.HomeSubjectSku;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 专题商品 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
public interface HomeSubjectSkuService extends IService<HomeSubjectSku> {
|
||||
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package com.yovinchen.xlcs.activity.service;
|
||||
|
||||
import com.yovinchen.xlcs.model.activity.Seckill;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 秒杀活动 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
public interface SeckillService extends IService<Seckill> {
|
||||
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package com.yovinchen.xlcs.activity.service;
|
||||
|
||||
import com.yovinchen.xlcs.model.activity.SeckillSkuNotice;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 秒杀商品通知订阅 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
public interface SeckillSkuNoticeService extends IService<SeckillSkuNotice> {
|
||||
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package com.yovinchen.xlcs.activity.service;
|
||||
|
||||
import com.yovinchen.xlcs.model.activity.SeckillSku;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 秒杀活动商品关联 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
public interface SeckillSkuService extends IService<SeckillSku> {
|
||||
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package com.yovinchen.xlcs.activity.service;
|
||||
|
||||
import com.yovinchen.xlcs.model.activity.SeckillTime;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 秒杀活动场次 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
public interface SeckillTimeService extends IService<SeckillTime> {
|
||||
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package com.yovinchen.xlcs.activity.service;
|
||||
|
||||
import com.yovinchen.xlcs.model.product.SkuInfo;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* sku信息 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
public interface SkuInfoService extends IService<SkuInfo> {
|
||||
|
||||
}
|
@@ -0,0 +1,546 @@
|
||||
package com.yovinchen.xlcs.activity.service.impl;
|
||||
|
||||
import com.yovinchen.xlcs.activity.mapper.ActivityInfoMapper;
|
||||
import com.yovinchen.xlcs.activity.mapper.ActivityRuleMapper;
|
||||
import com.yovinchen.xlcs.activity.mapper.ActivitySkuMapper;
|
||||
import com.yovinchen.xlcs.activity.service.ActivityInfoService;
|
||||
import com.yovinchen.xlcs.activity.service.CouponInfoService;
|
||||
import com.yovinchen.xlcs.client.product.ProductFeignClient;
|
||||
import com.yovinchen.xlcs.enums.ActivityType;
|
||||
import com.yovinchen.xlcs.model.activity.ActivityInfo;
|
||||
import com.yovinchen.xlcs.model.activity.ActivityRule;
|
||||
import com.yovinchen.xlcs.model.activity.ActivitySku;
|
||||
import com.yovinchen.xlcs.model.activity.CouponInfo;
|
||||
import com.yovinchen.xlcs.model.order.CartInfo;
|
||||
import com.yovinchen.xlcs.model.product.SkuInfo;
|
||||
import com.yovinchen.xlcs.vo.activity.ActivityRuleVo;
|
||||
import com.yovinchen.xlcs.vo.order.CartInfoVo;
|
||||
import com.yovinchen.xlcs.vo.order.OrderConfirmVo;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 活动表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@Service
|
||||
public class ActivityInfoServiceImpl extends ServiceImpl<ActivityInfoMapper, ActivityInfo> implements ActivityInfoService {
|
||||
|
||||
|
||||
@Autowired
|
||||
private ActivityInfoMapper activityInfoMapper;
|
||||
|
||||
@Autowired
|
||||
private ActivityRuleMapper activityRuleMapper;
|
||||
|
||||
@Autowired
|
||||
private ActivitySkuMapper activitySkuMapper;
|
||||
|
||||
@Autowired
|
||||
private ProductFeignClient productFeignClient;
|
||||
|
||||
@Autowired
|
||||
private CouponInfoService couponInfoService;
|
||||
|
||||
/**
|
||||
* 优惠活动列表方法
|
||||
*
|
||||
* @param pageParam
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public IPage<ActivityInfo> selectPage(Page<ActivityInfo> pageParam) {
|
||||
QueryWrapper<ActivityInfo> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.orderByDesc("id");
|
||||
|
||||
IPage<ActivityInfo> page = activityInfoMapper.selectPage(pageParam, queryWrapper);
|
||||
page.getRecords()
|
||||
.forEach(item -> {
|
||||
item.setActivityTypeString(item.getActivityType()
|
||||
.getComment());
|
||||
});
|
||||
return page;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据活动Id查询活动规则列表方法
|
||||
*
|
||||
* @param activityId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> findActivityRuleList(Long activityId) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
LambdaQueryWrapper<ActivityRule> queryWrapper = new LambdaQueryWrapper<ActivityRule>();
|
||||
queryWrapper.eq(ActivityRule::getActivityId, activityId);
|
||||
List<ActivityRule> activityRuleList = activityRuleMapper.selectList(queryWrapper);
|
||||
result.put("activityRuleList", activityRuleList);
|
||||
|
||||
LambdaQueryWrapper<ActivitySku> activitySkuQueryWrapper = new LambdaQueryWrapper<ActivitySku>();
|
||||
activitySkuQueryWrapper.eq(ActivitySku::getActivityId, activityId);
|
||||
List<ActivitySku> activitySkuList = activitySkuMapper.selectList(activitySkuQueryWrapper);
|
||||
List<Long> skuIdList = activitySkuList.stream()
|
||||
.map(ActivitySku::getSkuId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<SkuInfo> skuInfoList = null;
|
||||
if (!skuIdList.isEmpty()) {
|
||||
skuInfoList = productFeignClient.findSkuInfoList(skuIdList);
|
||||
}
|
||||
|
||||
result.put("skuInfoList", skuInfoList);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存活动规则
|
||||
*
|
||||
* @param activityRuleVo
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void saveActivityRule(ActivityRuleVo activityRuleVo) {
|
||||
//第一步 根据活动id删除之前规则数据
|
||||
//ActivityRule数据删除
|
||||
Long activityId = activityRuleVo.getActivityId();
|
||||
activityRuleMapper.delete(new LambdaQueryWrapper<ActivityRule>().eq(ActivityRule::getActivityId, activityId));
|
||||
//ActivitySku数据删除
|
||||
activitySkuMapper.delete(new LambdaQueryWrapper<ActivitySku>().eq(ActivitySku::getActivityId, activityId));
|
||||
|
||||
//第二步 获取规则列表数据
|
||||
List<ActivityRule> activityRuleList = activityRuleVo.getActivityRuleList();
|
||||
ActivityInfo activityInfo = baseMapper.selectById(activityId);
|
||||
for (ActivityRule activityRule : activityRuleList) {
|
||||
activityRule.setActivityId(activityId);//活动id
|
||||
activityRule.setActivityType(activityInfo.getActivityType());//类型
|
||||
activityRuleMapper.insert(activityRule);
|
||||
}
|
||||
|
||||
//第三步 获取规则范围数据
|
||||
List<ActivitySku> activitySkuList = activityRuleVo.getActivitySkuList();
|
||||
for (ActivitySku activitySku : activitySkuList) {
|
||||
activitySku.setActivityId(activityId);
|
||||
activitySkuMapper.insert(activitySku);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据关键字查询sku信息列表
|
||||
*
|
||||
* @param keyword
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<SkuInfo> findSkuInfoByKeyword(String keyword) {
|
||||
//第一步 根据关键字查询sku匹配内容列表
|
||||
//// (1) service-product模块创建接口 据关键字查询sku匹配内容列表
|
||||
//// (2) service-activity远程调用得到sku内容列表
|
||||
List<SkuInfo> skuInfoList = productFeignClient.findSkuInfoByKeyword(keyword);
|
||||
//判断:如果根据关键字查询不到匹配内容,直接返回空集合
|
||||
if (skuInfoList.isEmpty()) {
|
||||
return skuInfoList;
|
||||
}
|
||||
|
||||
//从skuInfoList集合获取所有skuId
|
||||
List<Long> skuIdList = skuInfoList.stream()
|
||||
.map(SkuInfo::getId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
//第二步 判断添加商品之前是否参加过活动,
|
||||
// 如果之前参加过,活动正在进行中,排除商品
|
||||
//// (1) 查询两张表判断 activity_info 和 activity_sku,编写SQL语句实现
|
||||
List<Long> existSkuIdList = baseMapper.selectSkuIdListExist(skuIdList);
|
||||
|
||||
//// (2) 判断逻辑处理:排除已经参加活动商品
|
||||
List<SkuInfo> findSkuList = new ArrayList<>();
|
||||
//遍历全部sku列表
|
||||
for (SkuInfo skuInfo : skuInfoList) {
|
||||
if (!existSkuIdList.contains(skuInfo.getId())) {
|
||||
findSkuList.add(skuInfo);
|
||||
}
|
||||
}
|
||||
return findSkuList;
|
||||
}
|
||||
|
||||
//拼接文字
|
||||
private String getRuleDesc(ActivityRule activityRule) {
|
||||
ActivityType activityType = activityRule.getActivityType();
|
||||
StringBuffer ruleDesc = new StringBuffer();
|
||||
if (activityType == ActivityType.FULL_REDUCTION) {
|
||||
ruleDesc.append("满")
|
||||
.append(activityRule.getConditionAmount())
|
||||
.append("元减")
|
||||
.append(activityRule.getBenefitAmount())
|
||||
.append("元");
|
||||
} else {
|
||||
ruleDesc.append("满")
|
||||
.append(activityRule.getConditionNum())
|
||||
.append("元打")
|
||||
.append(activityRule.getBenefitDiscount())
|
||||
.append("折");
|
||||
}
|
||||
return ruleDesc.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据skuId列表获取促销信息
|
||||
*
|
||||
* @param skuIdList
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<Long, List<String>> findActivity(List<Long> skuIdList) {
|
||||
Map<Long, List<String>> result = new HashMap<>();
|
||||
//skuIdList遍历,得到每个skuId
|
||||
skuIdList.forEach(skuId -> {
|
||||
//根据skuId进行查询,查询sku对应活动里面规则列表
|
||||
List<ActivityRule> activityRuleList = baseMapper.findActivityRule(skuId);
|
||||
//数据封装,规则名称
|
||||
if (!CollectionUtils.isEmpty(activityRuleList)) {
|
||||
List<String> ruleList = new ArrayList<>();
|
||||
//把规则名称处理
|
||||
for (ActivityRule activityRule : activityRuleList) {
|
||||
ruleList.add(this.getRuleDesc(activityRule));
|
||||
}
|
||||
result.put(skuId, ruleList);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据skuID获取营销数据和优惠卷
|
||||
*
|
||||
* @param skuId
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> findActivityAndCoupon(Long skuId, Long userId) {
|
||||
//1 根据skuId获取sku营销活动,一个活动有多个规则
|
||||
List<ActivityRule> activityRuleList = this.findActivityRuleBySkuId(skuId);
|
||||
|
||||
//2 根据skuId+userId查询优惠卷信息
|
||||
List<CouponInfo> couponInfoList = couponInfoService.findCouponInfoList(skuId, userId);
|
||||
|
||||
//3 封装到map集合,返回
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("couponInfoList", couponInfoList);
|
||||
map.put("activityRuleList", activityRuleList);
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取购物车中满足条件优惠券和活动
|
||||
*
|
||||
* @param cartInfoList
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public OrderConfirmVo findCartActivityAndCoupon(List<CartInfo> cartInfoList, Long userId) {
|
||||
//1 获取购物车,每个购物项参与活动,根据活动规则分组,
|
||||
//一个规则对应多个商品
|
||||
List<CartInfoVo> cartInfoVoList = this.findCartActivityList(cartInfoList);
|
||||
|
||||
//2 计算参与活动之后金额
|
||||
BigDecimal activityReduceAmount = cartInfoVoList.stream()
|
||||
.filter(cartInfoVo -> cartInfoVo.getActivityRule() != null)
|
||||
.map(cartInfoVo -> cartInfoVo.getActivityRule()
|
||||
.getReduceAmount())
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
//3 获取购物车可以使用优惠卷列表
|
||||
List<CouponInfo> couponInfoList = couponInfoService.findCartCouponInfo(cartInfoList, userId);
|
||||
|
||||
//4 计算商品使用优惠卷之后金额,一次只能使用一张优惠卷
|
||||
BigDecimal couponReduceAmount = new BigDecimal(0);
|
||||
if (!CollectionUtils.isEmpty(couponInfoList)) {
|
||||
couponReduceAmount = couponInfoList.stream()
|
||||
.filter(couponInfo -> couponInfo.getIsOptimal()
|
||||
.intValue() == 1)
|
||||
.map(couponInfo -> couponInfo.getAmount())
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
}
|
||||
|
||||
//5 计算没有参与活动,没有使用优惠卷原始金额
|
||||
BigDecimal originalTotalAmount = cartInfoList.stream()
|
||||
.filter(cartInfo -> cartInfo.getIsChecked() == 1)
|
||||
.map(cartInfo -> cartInfo.getCartPrice()
|
||||
.multiply(new BigDecimal(cartInfo.getSkuNum())))
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
//6 最终金额
|
||||
BigDecimal totalAmount = originalTotalAmount.subtract(activityReduceAmount)
|
||||
.subtract(couponReduceAmount);
|
||||
|
||||
//7 封装需要数据到OrderConfirmVo,返回
|
||||
OrderConfirmVo orderTradeVo = new OrderConfirmVo();
|
||||
orderTradeVo.setCarInfoVoList(cartInfoVoList);
|
||||
orderTradeVo.setActivityReduceAmount(activityReduceAmount);
|
||||
orderTradeVo.setCouponInfoList(couponInfoList);
|
||||
orderTradeVo.setCouponReduceAmount(couponReduceAmount);
|
||||
orderTradeVo.setOriginalTotalAmount(originalTotalAmount);
|
||||
orderTradeVo.setTotalAmount(totalAmount);
|
||||
return orderTradeVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取购物车对应规则数据
|
||||
*
|
||||
* @param cartInfoList
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<CartInfoVo> findCartActivityList(List<CartInfo> cartInfoList) {
|
||||
//创建最终返回集合
|
||||
List<CartInfoVo> cartInfoVoList = new ArrayList<>();
|
||||
//获取所有skuId
|
||||
List<Long> skuIdList = cartInfoList.stream()
|
||||
.map(CartInfo::getSkuId)
|
||||
.collect(Collectors.toList());
|
||||
//根据所有skuId列表获取参与活动
|
||||
List<ActivitySku> activitySkuList = baseMapper.selectCartActivity(skuIdList);
|
||||
//根据活动进行分组,每个活动里面有哪些skuId信息
|
||||
//map里面key是分组字段 活动id
|
||||
// value是每组里面sku列表数据,set集合
|
||||
Map<Long, Set<Long>> activityIdToSkuIdListMap = activitySkuList.stream()
|
||||
.collect(Collectors.groupingBy(ActivitySku::getActivityId, Collectors.mapping(ActivitySku::getSkuId, Collectors.toSet())));
|
||||
|
||||
//获取活动里面规则数据
|
||||
//key是活动id value是活动里面规则列表数据
|
||||
Map<Long, List<ActivityRule>> activityIdToActivityRuleListMap = new HashMap<>();
|
||||
//所有活动id
|
||||
Set<Long> activityIdSet = activitySkuList.stream()
|
||||
.map(ActivitySku::getActivityId)
|
||||
.collect(Collectors.toSet());
|
||||
if (!CollectionUtils.isEmpty(activityIdSet)) {
|
||||
//activity_rule表
|
||||
LambdaQueryWrapper<ActivityRule> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.orderByDesc(ActivityRule::getConditionAmount, ActivityRule::getConditionNum);
|
||||
wrapper.in(ActivityRule::getActivityId, activityIdSet);
|
||||
List<ActivityRule> activityRuleList = activityRuleMapper.selectList(wrapper);
|
||||
|
||||
//封装到activityIdToActivityRuleListMap里面
|
||||
//根据活动id进行分组
|
||||
activityIdToActivityRuleListMap = activityRuleList.stream()
|
||||
.collect(Collectors.groupingBy(activityRule -> activityRule.getActivityId()));
|
||||
}
|
||||
|
||||
//有活动的购物项skuId
|
||||
Set<Long> activitySkuIdSet = new HashSet<>();
|
||||
if (!CollectionUtils.isEmpty(activityIdToSkuIdListMap)) {
|
||||
//遍历activityIdToSkuIdListMap集合
|
||||
Iterator<Map.Entry<Long, Set<Long>>> iterator = activityIdToSkuIdListMap.entrySet()
|
||||
.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<Long, Set<Long>> entry = iterator.next();
|
||||
//活动id
|
||||
Long activityId = entry.getKey();
|
||||
//每个活动对应skuId列表
|
||||
Set<Long> currentActivitySkuIdSet = entry.getValue();
|
||||
//获取当前活动对应的购物项列表
|
||||
List<CartInfo> currentActivityCartInfoList = cartInfoList.stream()
|
||||
.filter(cartInfo -> currentActivitySkuIdSet.contains(cartInfo.getSkuId()))
|
||||
.collect(Collectors.toList());
|
||||
//计数购物项总金额和总数量
|
||||
BigDecimal activityTotalAmount = this.computeTotalAmount(currentActivityCartInfoList);
|
||||
int activityTotalNum = this.computeCartNum(currentActivityCartInfoList);
|
||||
|
||||
//计算活动对应规则
|
||||
//根据activityId获取活动对应规则
|
||||
List<ActivityRule> currentActivityRuleList = activityIdToActivityRuleListMap.get(activityId);
|
||||
ActivityType activityType = currentActivityRuleList.get(0)
|
||||
.getActivityType();
|
||||
//判断活动类型:满减和打折
|
||||
ActivityRule activityRule = null;
|
||||
if (activityType == ActivityType.FULL_REDUCTION) {//满减"
|
||||
activityRule = this.computeFullReduction(activityTotalAmount, currentActivityRuleList);
|
||||
} else {//满量
|
||||
activityRule = this.computeFullDiscount(activityTotalNum, activityTotalAmount, currentActivityRuleList);
|
||||
}
|
||||
|
||||
//CartInfoVo封装
|
||||
CartInfoVo cartInfoVo = new CartInfoVo();
|
||||
cartInfoVo.setActivityRule(activityRule);
|
||||
cartInfoVo.setCartInfoList(currentActivityCartInfoList);
|
||||
cartInfoVoList.add(cartInfoVo);
|
||||
|
||||
//记录哪些购物项参与活动
|
||||
activitySkuIdSet.addAll(currentActivitySkuIdSet);
|
||||
}
|
||||
}
|
||||
|
||||
//没有活动购物项skuId
|
||||
//获取哪些skuId没有参加活动
|
||||
skuIdList.removeAll(activitySkuIdSet);
|
||||
if (!CollectionUtils.isEmpty(skuIdList)) {
|
||||
//skuId对应购物项
|
||||
Map<Long, CartInfo> skuIdCartInfoMap = cartInfoList.stream()
|
||||
.collect(Collectors.toMap(CartInfo::getSkuId, CartInfo -> CartInfo));
|
||||
for (Long skuId : skuIdList) {
|
||||
CartInfoVo cartInfoVo = new CartInfoVo();
|
||||
cartInfoVo.setActivityRule(null);//没有活动
|
||||
|
||||
List<CartInfo> cartInfos = new ArrayList<>();
|
||||
cartInfos.add(skuIdCartInfoMap.get(skuId));
|
||||
cartInfoVo.setCartInfoList(cartInfos);
|
||||
|
||||
cartInfoVoList.add(cartInfoVo);
|
||||
}
|
||||
}
|
||||
|
||||
return cartInfoVoList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算满量打折最优规则
|
||||
* 该活动规则skuActivityRuleList数据,已经按照优惠折扣从大到小排序了
|
||||
*
|
||||
* @param totalNum
|
||||
* @param activityRuleList
|
||||
*/
|
||||
private ActivityRule computeFullDiscount(Integer totalNum, BigDecimal totalAmount, List<ActivityRule> activityRuleList) {
|
||||
ActivityRule optimalActivityRule = null;
|
||||
//该活动规则skuActivityRuleList数据,已经按照优惠金额从大到小排序了
|
||||
for (ActivityRule activityRule : activityRuleList) {
|
||||
//如果订单项购买个数大于等于满减件数,则优化打折
|
||||
if (totalNum.intValue() >= activityRule.getConditionNum()) {
|
||||
BigDecimal skuDiscountTotalAmount = totalAmount.multiply(activityRule.getBenefitDiscount()
|
||||
.divide(new BigDecimal("10")));
|
||||
BigDecimal reduceAmount = totalAmount.subtract(skuDiscountTotalAmount);
|
||||
activityRule.setReduceAmount(reduceAmount);
|
||||
optimalActivityRule = activityRule;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (null == optimalActivityRule) {
|
||||
//如果没有满足条件的取最小满足条件的一项
|
||||
optimalActivityRule = activityRuleList.get(activityRuleList.size() - 1);
|
||||
optimalActivityRule.setReduceAmount(new BigDecimal("0"));
|
||||
optimalActivityRule.setSelectType(1);
|
||||
|
||||
String ruleDesc = "满" +
|
||||
optimalActivityRule.getConditionNum() +
|
||||
"元打" +
|
||||
optimalActivityRule.getBenefitDiscount() +
|
||||
"折,还差" +
|
||||
(totalNum - optimalActivityRule.getConditionNum()) +
|
||||
"件";
|
||||
optimalActivityRule.setRuleDesc(ruleDesc);
|
||||
} else {
|
||||
String ruleDesc = "满" +
|
||||
optimalActivityRule.getConditionNum() +
|
||||
"元打" +
|
||||
optimalActivityRule.getBenefitDiscount() +
|
||||
"折,已减" +
|
||||
optimalActivityRule.getReduceAmount() +
|
||||
"元";
|
||||
optimalActivityRule.setRuleDesc(ruleDesc);
|
||||
optimalActivityRule.setSelectType(2);
|
||||
}
|
||||
return optimalActivityRule;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算满减最优规则
|
||||
* 该活动规则skuActivityRuleList数据,已经按照优惠金额从大到小排序了
|
||||
*
|
||||
* @param totalAmount
|
||||
* @param activityRuleList
|
||||
*/
|
||||
private ActivityRule computeFullReduction(BigDecimal totalAmount, List<ActivityRule> activityRuleList) {
|
||||
ActivityRule optimalActivityRule = null;
|
||||
//该活动规则skuActivityRuleList数据,已经按照优惠金额从大到小排序了
|
||||
for (ActivityRule activityRule : activityRuleList) {
|
||||
//如果订单项金额大于等于满减金额,则优惠金额
|
||||
if (totalAmount.compareTo(activityRule.getConditionAmount()) > -1) {
|
||||
//优惠后减少金额
|
||||
activityRule.setReduceAmount(activityRule.getBenefitAmount());
|
||||
optimalActivityRule = activityRule;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (null == optimalActivityRule) {
|
||||
//如果没有满足条件的取最小满足条件的一项
|
||||
optimalActivityRule = activityRuleList.get(activityRuleList.size() - 1);
|
||||
optimalActivityRule.setReduceAmount(new BigDecimal("0"));
|
||||
optimalActivityRule.setSelectType(1);
|
||||
|
||||
String ruleDesc = "满" +
|
||||
optimalActivityRule.getConditionAmount() +
|
||||
"元减" +
|
||||
optimalActivityRule.getBenefitAmount() +
|
||||
"元,还差" +
|
||||
totalAmount.subtract(optimalActivityRule.getConditionAmount()) +
|
||||
"元";
|
||||
optimalActivityRule.setRuleDesc(ruleDesc);
|
||||
} else {
|
||||
String ruleDesc = "满" +
|
||||
optimalActivityRule.getConditionAmount() +
|
||||
"元减" +
|
||||
optimalActivityRule.getBenefitAmount() +
|
||||
"元,已减" +
|
||||
optimalActivityRule.getReduceAmount() +
|
||||
"元";
|
||||
optimalActivityRule.setRuleDesc(ruleDesc);
|
||||
optimalActivityRule.setSelectType(2);
|
||||
}
|
||||
return optimalActivityRule;
|
||||
}
|
||||
|
||||
//根据skuId获取活动规则数据
|
||||
public List<ActivityRule> findActivityRuleBySkuId(Long skuId) {
|
||||
List<ActivityRule> activityRuleList = baseMapper.findActivityRule(skuId);
|
||||
|
||||
for (ActivityRule activityRule : activityRuleList) {
|
||||
String ruleDesc = this.getRuleDesc(activityRule);
|
||||
activityRule.setRuleDesc(ruleDesc);
|
||||
}
|
||||
return activityRuleList;
|
||||
}
|
||||
|
||||
//计算购物车中金额
|
||||
private BigDecimal computeTotalAmount(List<CartInfo> cartInfoList) {
|
||||
BigDecimal total = new BigDecimal("0");
|
||||
for (CartInfo cartInfo : cartInfoList) {
|
||||
//是否选中
|
||||
if (cartInfo.getIsChecked()
|
||||
.intValue() == 1) {
|
||||
BigDecimal itemTotal = cartInfo.getCartPrice()
|
||||
.multiply(new BigDecimal(cartInfo.getSkuNum()));
|
||||
total = total.add(itemTotal);
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
//计算购物车中总数量
|
||||
private int computeCartNum(List<CartInfo> cartInfoList) {
|
||||
int total = 0;
|
||||
for (CartInfo cartInfo : cartInfoList) {
|
||||
//是否选中
|
||||
if (cartInfo.getIsChecked()
|
||||
.intValue() == 1) {
|
||||
total += cartInfo.getSkuNum();
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package com.yovinchen.xlcs.activity.service.impl;
|
||||
|
||||
import com.yovinchen.xlcs.activity.mapper.ActivityRuleMapper;
|
||||
import com.yovinchen.xlcs.activity.service.ActivityRuleService;
|
||||
import com.yovinchen.xlcs.model.activity.ActivityRule;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 优惠规则 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@Service
|
||||
public class ActivityRuleServiceImpl extends ServiceImpl<ActivityRuleMapper, ActivityRule> implements ActivityRuleService {
|
||||
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package com.yovinchen.xlcs.activity.service.impl;
|
||||
|
||||
import com.yovinchen.xlcs.activity.mapper.ActivitySkuMapper;
|
||||
import com.yovinchen.xlcs.activity.service.ActivitySkuService;
|
||||
import com.yovinchen.xlcs.model.activity.ActivitySku;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 活动参与商品 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@Service
|
||||
public class ActivitySkuServiceImpl extends ServiceImpl<ActivitySkuMapper, ActivitySku> implements ActivitySkuService {
|
||||
|
||||
}
|
@@ -0,0 +1,361 @@
|
||||
package com.yovinchen.xlcs.activity.service.impl;
|
||||
|
||||
import com.yovinchen.xlcs.activity.mapper.CouponInfoMapper;
|
||||
import com.yovinchen.xlcs.activity.mapper.CouponRangeMapper;
|
||||
import com.yovinchen.xlcs.activity.mapper.CouponUseMapper;
|
||||
import com.yovinchen.xlcs.activity.service.CouponInfoService;
|
||||
import com.yovinchen.xlcs.client.product.ProductFeignClient;
|
||||
import com.yovinchen.xlcs.enums.CouponRangeType;
|
||||
import com.yovinchen.xlcs.enums.CouponStatus;
|
||||
import com.yovinchen.xlcs.model.activity.CouponInfo;
|
||||
import com.yovinchen.xlcs.model.activity.CouponRange;
|
||||
import com.yovinchen.xlcs.model.activity.CouponUse;
|
||||
import com.yovinchen.xlcs.model.base.BaseEntity;
|
||||
import com.yovinchen.xlcs.model.order.CartInfo;
|
||||
import com.yovinchen.xlcs.model.product.Category;
|
||||
import com.yovinchen.xlcs.model.product.SkuInfo;
|
||||
import com.yovinchen.xlcs.vo.activity.CouponRuleVo;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 优惠券信息 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@Service
|
||||
public class CouponInfoServiceImpl extends ServiceImpl<CouponInfoMapper, CouponInfo> implements CouponInfoService {
|
||||
|
||||
@Autowired
|
||||
CouponRangeMapper couponRangeMapper;
|
||||
@Autowired
|
||||
ProductFeignClient productFeignClient;
|
||||
@Autowired
|
||||
private CouponUseMapper couponUseMapper;
|
||||
|
||||
/**
|
||||
* 获取分页列表
|
||||
*
|
||||
* @param page
|
||||
* @param limit
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public IPage<CouponInfo> selectPage(Long page, Long limit) {
|
||||
Page<CouponInfo> pageParam = new Page<>(page, limit);
|
||||
Page<CouponInfo> couponInfoPage = baseMapper.selectPage(pageParam, null);
|
||||
List<CouponInfo> couponInfoList = couponInfoPage.getRecords();
|
||||
couponInfoList.forEach(item -> {
|
||||
item.setCouponTypeString(item.getCouponType()
|
||||
.getComment());
|
||||
CouponRangeType rangeType = item.getRangeType();
|
||||
if (rangeType != null) {
|
||||
item.setRangeTypeString(rangeType.getComment());
|
||||
}
|
||||
});
|
||||
return couponInfoPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询优惠券
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public CouponInfo getCouponInfo(Long id) {
|
||||
CouponInfo couponInfo = baseMapper.selectById(id);
|
||||
couponInfo.setCouponTypeString(couponInfo.getCouponType()
|
||||
.getComment());
|
||||
if (couponInfo.getRangeType() != null) {
|
||||
couponInfo.setRangeTypeString(couponInfo.getRangeType()
|
||||
.getComment());
|
||||
}
|
||||
return couponInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据优惠卷id获取优惠券规则列表
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> findCouponRuleList(Long id) {
|
||||
//第一步 根据优惠卷id查询优惠卷基本信息 coupon_info表
|
||||
CouponInfo couponInfo = baseMapper.selectById(id);
|
||||
|
||||
//第二步 根据优惠卷id查询coupon_range 查询里面对应range_id
|
||||
List<CouponRange> couponRangeList = couponRangeMapper.selectList(new LambdaQueryWrapper<CouponRange>().eq(CouponRange::getCouponId, id));
|
||||
//couponRangeList获取所有range_id
|
||||
//// 如果规则类型 SKU range_id就是skuId值
|
||||
//// 如果规则类型 CATEGORY range_id就是分类Id值
|
||||
List<Long> randIdList = couponRangeList.stream()
|
||||
.map(CouponRange::getRangeId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
//第三步 分别判断封装不同数据
|
||||
if (!CollectionUtils.isEmpty(randIdList)) {
|
||||
if (couponInfo.getRangeType() == CouponRangeType.SKU) {
|
||||
//// 如果规则类型是SKU ,得到skuId,
|
||||
// 远程调用根据多个skuId值获取对应sku信息
|
||||
List<SkuInfo> skuInfoList = productFeignClient.findSkuInfoList(randIdList);
|
||||
result.put("skuInfoList", skuInfoList);
|
||||
|
||||
} else if (couponInfo.getRangeType() == CouponRangeType.CATEGORY) {
|
||||
//// 如果规则类型是分类,得到分类Id,远程调用根据多个分类Id值获取对应分类信息
|
||||
List<Category> categoryList = productFeignClient.findCategoryList(randIdList);
|
||||
result.put("categoryList", categoryList);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增优惠券规则
|
||||
*
|
||||
* @param couponRuleVo
|
||||
*/
|
||||
@Override
|
||||
public void saveCouponRule(CouponRuleVo couponRuleVo) {
|
||||
//优惠券couponInfo 与 couponRange 要一起操作:先删除couponRange ,更新couponInfo ,再新增couponRange !
|
||||
|
||||
couponRangeMapper.delete(new LambdaQueryWrapper<CouponRange>().eq(CouponRange::getCouponId, couponRuleVo.getCouponId()));
|
||||
|
||||
//更新优惠卷基本信息
|
||||
CouponInfo couponInfo = baseMapper.selectById(couponRuleVo.getCouponId());
|
||||
couponInfo.setRangeType(couponRuleVo.getRangeType());
|
||||
couponInfo.setConditionAmount(couponRuleVo.getConditionAmount());
|
||||
couponInfo.setAmount(couponRuleVo.getAmount());
|
||||
couponInfo.setConditionAmount(couponRuleVo.getConditionAmount());
|
||||
couponInfo.setRangeDesc(couponRuleVo.getRangeDesc());
|
||||
baseMapper.updateById(couponInfo);
|
||||
|
||||
//添加优惠卷新规则数据
|
||||
List<CouponRange> couponRangeList = couponRuleVo.getCouponRangeList();
|
||||
for (CouponRange couponRange : couponRangeList) {
|
||||
//设置优惠卷id
|
||||
couponRange.setCouponId(couponRuleVo.getCouponId());
|
||||
//添加
|
||||
couponRangeMapper.insert(couponRange);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CouponInfo> findCouponByKeyword(String keyword) {
|
||||
return baseMapper.selectList(new LambdaQueryWrapper<CouponInfo>().like(CouponInfo::getCouponName, keyword));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据skuId+userId查询优惠卷信息
|
||||
*
|
||||
* @param skuId
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<CouponInfo> findCouponInfoList(Long skuId, Long userId) {
|
||||
//远程调用:根据skuId获取skuInfo
|
||||
SkuInfo skuInfo = productFeignClient.getSkuInfo(skuId);
|
||||
|
||||
//根据条件查询:skuId + 分类id + userId
|
||||
List<CouponInfo> couponInfoList = baseMapper.selectCouponInfoList(skuInfo.getId(), skuInfo.getCategoryId(), userId);
|
||||
|
||||
return couponInfoList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取购物车可以使用优惠卷列表
|
||||
*
|
||||
* @param cartInfoList
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<CouponInfo> findCartCouponInfo(List<CartInfo> cartInfoList, Long userId) {
|
||||
//1 根据userId获取用户全部优惠卷
|
||||
//coupon_use coupon_info
|
||||
List<CouponInfo> userAllCouponInfoList = baseMapper.selectCartCouponInfoList(userId);
|
||||
if (CollectionUtils.isEmpty(userAllCouponInfoList)) {
|
||||
return new ArrayList<CouponInfo>();
|
||||
}
|
||||
|
||||
//2 从第一步返回list集合中,获取所有优惠卷id列表
|
||||
List<Long> couponIdList = userAllCouponInfoList.stream()
|
||||
.map(BaseEntity::getId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
//3 查询优惠卷对应的范围 coupon_range
|
||||
//couponRangeList
|
||||
LambdaQueryWrapper<CouponRange> wrapper = new LambdaQueryWrapper<>();
|
||||
// id in (1,2,3)
|
||||
wrapper.in(CouponRange::getCouponId, couponIdList);
|
||||
List<CouponRange> couponRangeList = couponRangeMapper.selectList(wrapper);
|
||||
|
||||
//4 获取优惠卷id 对应skuId列表
|
||||
//优惠卷id进行分组,得到map集合
|
||||
// Map<Long,List<Long>>
|
||||
Map<Long, List<Long>> couponIdToSkuIdMap = this.findCouponIdToSkuIdMap(cartInfoList, couponRangeList);
|
||||
|
||||
//5 遍历全部优惠卷集合,判断优惠卷类型
|
||||
//全场通用 sku和分类
|
||||
BigDecimal reduceAmount = new BigDecimal(0);
|
||||
CouponInfo optimalCouponInfo = null;
|
||||
for (CouponInfo couponInfo : userAllCouponInfoList) {
|
||||
//全场通用
|
||||
if (CouponRangeType.ALL == couponInfo.getRangeType()) {
|
||||
//全场通用
|
||||
//判断是否满足优惠使用门槛
|
||||
//计算购物车商品的总价
|
||||
BigDecimal totalAmount = computeTotalAmount(cartInfoList);
|
||||
if (totalAmount.subtract(couponInfo.getConditionAmount())
|
||||
.doubleValue() >= 0) {
|
||||
couponInfo.setIsSelect(1);
|
||||
}
|
||||
} else {
|
||||
//优惠卷id获取对应skuId列表
|
||||
List<Long> skuIdList = couponIdToSkuIdMap.get(couponInfo.getId());
|
||||
//满足使用范围购物项
|
||||
List<CartInfo> currentCartInfoList = cartInfoList.stream()
|
||||
.filter(cartInfo -> skuIdList.contains(cartInfo.getSkuId()))
|
||||
.collect(Collectors.toList());
|
||||
BigDecimal totalAmount = computeTotalAmount(currentCartInfoList);
|
||||
if (totalAmount.subtract(couponInfo.getConditionAmount())
|
||||
.doubleValue() >= 0) {
|
||||
couponInfo.setIsSelect(1);
|
||||
}
|
||||
}
|
||||
if (couponInfo.getIsSelect()
|
||||
.intValue() == 1 && couponInfo.getAmount()
|
||||
.subtract(reduceAmount)
|
||||
.doubleValue() > 0) {
|
||||
reduceAmount = couponInfo.getAmount();
|
||||
optimalCouponInfo = couponInfo;
|
||||
}
|
||||
|
||||
}
|
||||
//6 返回List<CouponInfo>
|
||||
if (null != optimalCouponInfo) {
|
||||
optimalCouponInfo.setIsOptimal(1);
|
||||
}
|
||||
return userAllCouponInfoList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取购物车对应优惠券数据
|
||||
*
|
||||
* @param cartInfoList
|
||||
* @param couponId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public CouponInfo findRangeSkuIdList(List<CartInfo> cartInfoList, Long couponId) {
|
||||
//根据优惠卷id基本信息查询
|
||||
CouponInfo couponInfo = baseMapper.selectById(couponId);
|
||||
if (couponInfo == null) {
|
||||
return null;
|
||||
}
|
||||
//根据couponId查询对应CouponRange数据
|
||||
List<CouponRange> couponRangeList = couponRangeMapper.selectList(new LambdaQueryWrapper<CouponRange>().eq(CouponRange::getCouponId, couponId));
|
||||
//对应sku信息
|
||||
Map<Long, List<Long>> couponIdToSkuIdMap = this.findCouponIdToSkuIdMap(cartInfoList, couponRangeList);
|
||||
//遍历map,得到value值,封装到couponInfo对象
|
||||
List<Long> skuIdList = couponIdToSkuIdMap.entrySet()
|
||||
.iterator()
|
||||
.next()
|
||||
.getValue();
|
||||
couponInfo.setSkuIdList(skuIdList);
|
||||
return couponInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新优惠卷使用状态
|
||||
*
|
||||
* @param couponId
|
||||
* @param userId
|
||||
* @param orderId
|
||||
*/
|
||||
@Override
|
||||
public void updateCouponInfoUseStatus(Long couponId, Long userId, Long orderId) {
|
||||
//根据couponId查询优惠卷信息
|
||||
CouponUse couponUse = couponUseMapper.selectOne(
|
||||
new LambdaQueryWrapper<CouponUse>()
|
||||
.eq(CouponUse::getCouponId, couponId)
|
||||
.eq(CouponUse::getUserId, userId)
|
||||
.eq(CouponUse::getOrderId, orderId)
|
||||
);
|
||||
|
||||
//设置修改值
|
||||
couponUse.setCouponStatus(CouponStatus.USED);
|
||||
|
||||
//调用方法修改
|
||||
couponUseMapper.updateById(couponUse);
|
||||
}
|
||||
|
||||
//获取优惠卷id 对应skuId列表
|
||||
private Map<Long, List<Long>> findCouponIdToSkuIdMap(List<CartInfo> cartInfoList, List<CouponRange> couponRangeList) {
|
||||
Map<Long, List<Long>> couponIdToSkuIdMap = new HashMap<>();
|
||||
|
||||
//couponRangeList数据处理,根据优惠卷id分组
|
||||
Map<Long, List<CouponRange>> couponRangeToRangeListMap = couponRangeList.stream()
|
||||
.collect(Collectors.groupingBy(CouponRange::getCouponId));
|
||||
|
||||
//遍历map集合
|
||||
Iterator<Map.Entry<Long, List<CouponRange>>> iterator = couponRangeToRangeListMap.entrySet()
|
||||
.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<Long, List<CouponRange>> entry = iterator.next();
|
||||
Long couponId = entry.getKey();
|
||||
List<CouponRange> rangeList = entry.getValue();
|
||||
|
||||
//创建集合 set
|
||||
Set<Long> skuIdSet = new HashSet<>();
|
||||
for (CartInfo cartInfo : cartInfoList) {
|
||||
for (CouponRange couponRange : rangeList) {
|
||||
//判断
|
||||
if (couponRange.getRangeType() == CouponRangeType.SKU && couponRange.getRangeId()
|
||||
.longValue() == cartInfo.getSkuId()
|
||||
.longValue()) {
|
||||
skuIdSet.add(cartInfo.getSkuId());
|
||||
} else if (couponRange.getRangeType() == CouponRangeType.CATEGORY && couponRange.getRangeId()
|
||||
.longValue() == cartInfo.getCategoryId()
|
||||
.longValue()) {
|
||||
skuIdSet.add(cartInfo.getSkuId());
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
couponIdToSkuIdMap.put(couponId, new ArrayList<>(skuIdSet));
|
||||
}
|
||||
return couponIdToSkuIdMap;
|
||||
}
|
||||
|
||||
//计算购物车商品的总价
|
||||
private BigDecimal computeTotalAmount(List<CartInfo> cartInfoList) {
|
||||
BigDecimal total = new BigDecimal("0");
|
||||
for (CartInfo cartInfo : cartInfoList) {
|
||||
//是否选中
|
||||
if (cartInfo.getIsChecked()
|
||||
.intValue() == 1) {
|
||||
BigDecimal itemTotal = cartInfo.getCartPrice()
|
||||
.multiply(new BigDecimal(cartInfo.getSkuNum()));
|
||||
total = total.add(itemTotal);
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package com.yovinchen.xlcs.activity.service.impl;
|
||||
|
||||
import com.yovinchen.xlcs.activity.mapper.CouponRangeMapper;
|
||||
import com.yovinchen.xlcs.activity.service.CouponRangeService;
|
||||
import com.yovinchen.xlcs.model.activity.CouponRange;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 优惠券范围表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@Service
|
||||
public class CouponRangeServiceImpl extends ServiceImpl<CouponRangeMapper, CouponRange> implements CouponRangeService {
|
||||
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package com.yovinchen.xlcs.activity.service.impl;
|
||||
|
||||
import com.yovinchen.xlcs.activity.mapper.CouponUseMapper;
|
||||
import com.yovinchen.xlcs.activity.service.CouponUseService;
|
||||
import com.yovinchen.xlcs.model.activity.CouponUse;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 优惠券领用表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@Service
|
||||
public class CouponUseServiceImpl extends ServiceImpl<CouponUseMapper, CouponUse> implements CouponUseService {
|
||||
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package com.yovinchen.xlcs.activity.service.impl;
|
||||
|
||||
import com.yovinchen.xlcs.activity.mapper.HomeSubjectMapper;
|
||||
import com.yovinchen.xlcs.activity.service.HomeSubjectService;
|
||||
import com.yovinchen.xlcs.model.activity.HomeSubject;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 首页专题表【jd首页下面很多专题,每个专题链接新的页面,展示专题商品信息】 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@Service
|
||||
public class HomeSubjectServiceImpl extends ServiceImpl<HomeSubjectMapper, HomeSubject> implements HomeSubjectService {
|
||||
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package com.yovinchen.xlcs.activity.service.impl;
|
||||
|
||||
import com.yovinchen.xlcs.activity.mapper.HomeSubjectSkuMapper;
|
||||
import com.yovinchen.xlcs.activity.service.HomeSubjectSkuService;
|
||||
import com.yovinchen.xlcs.model.activity.HomeSubjectSku;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 专题商品 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@Service
|
||||
public class HomeSubjectSkuServiceImpl extends ServiceImpl<HomeSubjectSkuMapper, HomeSubjectSku> implements HomeSubjectSkuService {
|
||||
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package com.yovinchen.xlcs.activity.service.impl;
|
||||
|
||||
import com.yovinchen.xlcs.activity.mapper.SeckillMapper;
|
||||
import com.yovinchen.xlcs.activity.service.SeckillService;
|
||||
import com.yovinchen.xlcs.model.activity.Seckill;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 秒杀活动 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@Service
|
||||
public class SeckillServiceImpl extends ServiceImpl<SeckillMapper, Seckill> implements SeckillService {
|
||||
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package com.yovinchen.xlcs.activity.service.impl;
|
||||
|
||||
import com.yovinchen.xlcs.activity.mapper.SeckillSkuNoticeMapper;
|
||||
import com.yovinchen.xlcs.activity.service.SeckillSkuNoticeService;
|
||||
import com.yovinchen.xlcs.model.activity.SeckillSkuNotice;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 秒杀商品通知订阅 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@Service
|
||||
public class SeckillSkuNoticeServiceImpl extends ServiceImpl<SeckillSkuNoticeMapper, SeckillSkuNotice> implements SeckillSkuNoticeService {
|
||||
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package com.yovinchen.xlcs.activity.service.impl;
|
||||
|
||||
import com.yovinchen.xlcs.activity.mapper.SeckillSkuMapper;
|
||||
import com.yovinchen.xlcs.activity.service.SeckillSkuService;
|
||||
import com.yovinchen.xlcs.model.activity.SeckillSku;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 秒杀活动商品关联 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@Service
|
||||
public class SeckillSkuServiceImpl extends ServiceImpl<SeckillSkuMapper, SeckillSku> implements SeckillSkuService {
|
||||
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package com.yovinchen.xlcs.activity.service.impl;
|
||||
|
||||
import com.yovinchen.xlcs.activity.mapper.SeckillTimeMapper;
|
||||
import com.yovinchen.xlcs.activity.service.SeckillTimeService;
|
||||
import com.yovinchen.xlcs.model.activity.SeckillTime;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 秒杀活动场次 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@Service
|
||||
public class SeckillTimeServiceImpl extends ServiceImpl<SeckillTimeMapper, SeckillTime> implements SeckillTimeService {
|
||||
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package com.yovinchen.xlcs.activity.service.impl;
|
||||
|
||||
import com.yovinchen.xlcs.activity.mapper.SkuInfoMapper;
|
||||
import com.yovinchen.xlcs.activity.service.SkuInfoService;
|
||||
import com.yovinchen.xlcs.model.product.SkuInfo;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* sku信息 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-09-17
|
||||
*/
|
||||
@Service
|
||||
public class SkuInfoServiceImpl extends ServiceImpl<SkuInfoMapper, SkuInfo> implements SkuInfoService {
|
||||
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
server:
|
||||
port: 8205
|
||||
spring:
|
||||
application:
|
||||
name: service-activity
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 82.157.68.223:8848
|
||||
username: nacos
|
||||
password: nacos
|
@@ -0,0 +1,18 @@
|
||||
spring:
|
||||
cloud:
|
||||
nacos:
|
||||
config:
|
||||
namespace: dd5265c5-8290-45bc-9d07-395c14c977d3
|
||||
server-addr: 82.157.68.223:8848
|
||||
group: service
|
||||
username: nacos
|
||||
password: nacos
|
||||
enabled: true
|
||||
file-extension: yml
|
||||
extension-configs:
|
||||
- data-id: common.yml
|
||||
group: common
|
||||
refresh: true
|
||||
- data-id: service-redis.yml
|
||||
group: common
|
||||
refresh: true
|
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.yovinchen.xlcs.activity.mapper.ActivityInfoMapper">
|
||||
|
||||
<resultMap id="ActivityRuleMap" type="com.yovinchen.xlcs.model.activity.ActivityRule" autoMapping="true"></resultMap>
|
||||
<resultMap id="CouponInfoMap" type="com.yovinchen.xlcs.model.activity.CouponInfo" autoMapping="true"></resultMap>
|
||||
<resultMap id="ActivitySkuMap" type="com.yovinchen.xlcs.model.activity.ActivitySku" autoMapping="true"></resultMap>
|
||||
|
||||
<!-- //根据所有skuId列表获取参与活动-->
|
||||
<select id="selectCartActivity" resultMap="ActivitySkuMap">
|
||||
select
|
||||
info.id as activityId,
|
||||
sku.sku_id as skuId
|
||||
from activity_info info
|
||||
inner join activity_sku sku on info.id = sku.activity_id
|
||||
<where>
|
||||
and sku.sku_id in
|
||||
<foreach collection="skuIdList" item="item" open="(" close=")" separator=",">
|
||||
#{item}
|
||||
</foreach>
|
||||
</where>
|
||||
and now() between info.start_time and info.end_time
|
||||
</select>
|
||||
<!--//根据skuId进行查询,查询sku对应活动里面规则列表-->
|
||||
<select id="findActivityRule" resultMap="ActivityRuleMap">
|
||||
select rule.id,
|
||||
info.activity_type as activityType,
|
||||
rule.activity_id,
|
||||
rule.condition_amount,
|
||||
rule.condition_num,
|
||||
rule.benefit_amount,
|
||||
rule.benefit_discount
|
||||
from activity_info info
|
||||
inner join activity_sku sku on info.id = sku.activity_id
|
||||
inner join activity_rule rule on info.id = rule.activity_id
|
||||
where sku.sku_id = #{skuId}
|
||||
and now() between info.start_time and info.end_time
|
||||
and sku.is_deleted = 0
|
||||
and info.is_deleted = 0
|
||||
and rule.is_deleted = 0
|
||||
order by rule.condition_amount desc
|
||||
</select>
|
||||
|
||||
<!--// 如果之前参加过,活动正在进行中,排除商品-->
|
||||
<select id="selectSkuIdListExist" resultType="Long">
|
||||
select sku.sku_id
|
||||
from activity_info info
|
||||
inner join activity_sku sku on info.id = sku.activity_id
|
||||
<where>
|
||||
<if test="skuIdList != null">
|
||||
and sku.sku_id in
|
||||
<foreach collection="skuIdList" item="item"
|
||||
index="index" open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
and now() between info.start_time and info.end_time
|
||||
</select>
|
||||
</mapper>
|
@@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.yovinchen.xlcs.activity.mapper.CouponInfoMapper">
|
||||
|
||||
<resultMap id="CouponInfoMap" type="com.yovinchen.xlcs.model.activity.CouponInfo" autoMapping="true"></resultMap>
|
||||
|
||||
<!--//1 根据userId获取用户全部优惠卷-->
|
||||
<select id="selectCartCouponInfoList" resultMap="CouponInfoMap">
|
||||
select info.id,
|
||||
info.coupon_type,
|
||||
info.coupon_name,
|
||||
info.amount,
|
||||
info.condition_amount,
|
||||
info.start_time,
|
||||
info.end_time,
|
||||
info.range_type,
|
||||
info.range_desc,
|
||||
info.publish_count,
|
||||
info.per_limit,
|
||||
info.use_count,
|
||||
info.receive_count,
|
||||
info.expire_time,
|
||||
info.publish_status,
|
||||
info.create_time,
|
||||
info.update_time,
|
||||
info.is_deleted,
|
||||
cuse.coupon_status
|
||||
from coupon_use cuse
|
||||
inner join coupon_info info on cuse.coupon_id = info.id
|
||||
<where>
|
||||
and cuse.user_id = #{userId}
|
||||
and info.expire_time >= now()
|
||||
</where>
|
||||
order by info.amount desc
|
||||
</select>
|
||||
<!--//2 根据skuId+分类id+userId查询优惠卷信息-->
|
||||
<select id="selectCouponInfoList" resultMap="CouponInfoMap">
|
||||
select info.id,
|
||||
info.coupon_type,
|
||||
info.coupon_name,
|
||||
info.amount,
|
||||
info.condition_amount,
|
||||
info.start_time,
|
||||
info.end_time,
|
||||
info.range_type,
|
||||
info.range_desc,
|
||||
info.publish_count,
|
||||
info.per_limit,
|
||||
info.use_count,
|
||||
info.receive_count,
|
||||
info.expire_time,
|
||||
info.publish_status,
|
||||
info.create_time,
|
||||
info.update_time,
|
||||
info.is_deleted,
|
||||
cuse.coupon_status
|
||||
from coupon_info info
|
||||
left join coupon_range crange on info.id = crange.coupon_id
|
||||
left join coupon_use cuse on info.id = cuse.coupon_id and cuse.user_id = #{userId}
|
||||
where (info.range_type = 1 or (info.range_type = 2 and crange.range_id = #{skuId})
|
||||
or (info.range_type = 3 and crange.range_id = #{categoryId})
|
||||
)
|
||||
and info.is_deleted = 0
|
||||
and crange.is_deleted = 0
|
||||
and cuse.is_deleted = 0
|
||||
and now() between info.start_time and info.end_time
|
||||
order by info.amount desc
|
||||
</select>
|
||||
</mapper>
|
5
xlcs-parent/service/service-cart/Dockerfile
Normal file
5
xlcs-parent/service/service-cart/Dockerfile
Normal file
@@ -0,0 +1,5 @@
|
||||
FROM openjdk:8-jdk-alpine
|
||||
LABEL authors="yovinchen"
|
||||
VOLUME /tmp
|
||||
ADD ./target/service-cart.jar service-cart.jar
|
||||
ENTRYPOINT ["java","-jar","/service-cart.jar", "&"]
|
46
xlcs-parent/service/service-cart/pom.xml
Normal file
46
xlcs-parent/service/service-cart/pom.xml
Normal file
@@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.yovinchen</groupId>
|
||||
<artifactId>service</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>service-cart</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.yovinchen</groupId>
|
||||
<artifactId>service-product-client</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.yovinchen</groupId>
|
||||
<artifactId>service-product-client</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.yovinchen</groupId>
|
||||
<artifactId>service-activity-client</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.yovinchen</groupId>
|
||||
<artifactId>rabbit_util</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@@ -0,0 +1,23 @@
|
||||
package com.yovinchen.xlcs;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
/**
|
||||
* ClassName: ServiceCartApplication
|
||||
* Package: com.yovinchen.xlcs
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/10/8 22:26
|
||||
*/
|
||||
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)//取消数据源自动配置
|
||||
@EnableDiscoveryClient
|
||||
@EnableFeignClients
|
||||
public class ServiceCartApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ServiceCartApplication.class, args);
|
||||
}
|
||||
}
|
@@ -0,0 +1,117 @@
|
||||
package com.yovinchen.xlcs.cart.controller;
|
||||
|
||||
import com.yovinchen.xlcs.cart.service.CartInfoService;
|
||||
import com.yovinchen.xlcs.client.activity.ActivityFeignClient;
|
||||
import com.yovinchen.xlcs.common.auth.AuthContextHolder;
|
||||
import com.yovinchen.xlcs.common.result.Result;
|
||||
import com.yovinchen.xlcs.model.order.CartInfo;
|
||||
import com.yovinchen.xlcs.vo.order.OrderConfirmVo;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ClassName: CartApiController
|
||||
* Package: com.yovinchen.xlcs.cart.cart.controller
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/10/8 22:32
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/cart")
|
||||
public class CartApiController {
|
||||
|
||||
@Autowired
|
||||
private CartInfoService cartInfoService;
|
||||
|
||||
@Autowired
|
||||
private ActivityFeignClient activityFeignClient;
|
||||
|
||||
//添加内容:当前登录用户id,skuId,商品数量
|
||||
@ApiOperation(value = "添加商品到购物车")
|
||||
@GetMapping("addToCart/{skuId}/{skuNum}")
|
||||
public Result addToCart(@PathVariable("skuId") Long skuId, @PathVariable("skuNum") Integer skuNum) {
|
||||
//获取当前登录用户Id
|
||||
Long userId = AuthContextHolder.getUserId();
|
||||
cartInfoService.addToCart(userId, skuId, skuNum);
|
||||
return Result.ok(null);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "根据skuId删除购物车")
|
||||
@DeleteMapping("deleteCart/{skuId}")
|
||||
public Result deleteCart(@PathVariable("skuId") Long skuId) {
|
||||
Long userId = AuthContextHolder.getUserId();
|
||||
cartInfoService.deleteCart(skuId, userId);
|
||||
return Result.ok(null);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "清空购物车")
|
||||
@DeleteMapping("deleteAllCart")
|
||||
public Result deleteAllCart() {
|
||||
Long userId = AuthContextHolder.getUserId();
|
||||
cartInfoService.deleteAllCart(userId);
|
||||
return Result.ok(null);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "批量删除购物车 多个skuId")
|
||||
@DeleteMapping("batchDeleteCart")
|
||||
public Result batchDeleteCart(@RequestBody List<Long> skuIdList) {
|
||||
Long userId = AuthContextHolder.getUserId();
|
||||
cartInfoService.batchDeleteCart(skuIdList, userId);
|
||||
return Result.ok(null);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "购物车列表")
|
||||
@GetMapping("cartList")
|
||||
public Result cartList() {
|
||||
//获取userId
|
||||
Long userId = AuthContextHolder.getUserId();
|
||||
List<CartInfo> cartInfoList = cartInfoService.getCartList(userId);
|
||||
return Result.ok(cartInfoList);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "查询带优惠卷的购物车")
|
||||
@GetMapping("activityCartList")
|
||||
public Result activityCartList() {
|
||||
// 获取用户Id
|
||||
Long userId = AuthContextHolder.getUserId();
|
||||
List<CartInfo> cartInfoList = cartInfoService.getCartList(userId);
|
||||
|
||||
OrderConfirmVo orderTradeVo = activityFeignClient.findCartActivityAndCoupon(cartInfoList, userId);
|
||||
return Result.ok(orderTradeVo);
|
||||
}
|
||||
|
||||
@ApiOperation("根据skuId选中")
|
||||
@GetMapping("checkCart/{skuId}/{isChecked}")
|
||||
public Result checkCart(@PathVariable("skuId") Long skuId, @PathVariable("isChecked") Integer isChecked) {
|
||||
//获取userId
|
||||
Long userId = AuthContextHolder.getUserId();
|
||||
//调用方法
|
||||
cartInfoService.checkCart(userId, skuId, isChecked);
|
||||
return Result.ok(null);
|
||||
}
|
||||
|
||||
@ApiOperation("全选")
|
||||
@GetMapping("checkAllCart/{isChecked}")
|
||||
public Result checkAllCart(@PathVariable("isChecked") Integer isChecked) {
|
||||
Long userId = AuthContextHolder.getUserId();
|
||||
cartInfoService.checkAllCart(userId, isChecked);
|
||||
return Result.ok(null);
|
||||
}
|
||||
|
||||
@ApiOperation("批量选中")
|
||||
@PostMapping("batchCheckCart/{isChecked}")
|
||||
public Result batchCheckCart(@RequestBody List<Long> skuIdList, @PathVariable("isChecked") Integer isChecked) {
|
||||
Long userId = AuthContextHolder.getUserId();
|
||||
cartInfoService.batchCheckCart(skuIdList, userId, isChecked);
|
||||
return Result.ok(null);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "根据用户Id查询购物车列表")
|
||||
@PostMapping("inner/getCartCheckedList/{userId}")
|
||||
public List<CartInfo> getCartCheckedList(@PathVariable("userId") Long userId) {
|
||||
return cartInfoService.getCartCheckedList(userId);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user