From e0efbea83a0e1bd9b4fd1cdb722bf382b77769ac Mon Sep 17 00:00:00 2001
From: Bunny <1319900154@qq.com>
Date: Tue, 26 Dec 2023 16:18:31 +0800
Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=B3=A8=E5=86=8C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.idea/workspace.xml | 52 +++++++++--------
.../product/controller/BrandController.java | 4 +-
.../controller/CategoryController.java | 8 +--
.../product/controller/ProductController.java | 2 +
.../bunny/user/controller/SmsController.java | 2 +
.../user/controller/UserinfoController.java | 28 ++++++++++
.../cn/bunny/user/mapper/UserinfoMapper.java | 15 +++++
.../bunny/user/service/UserinfoService.java | 9 +++
.../service/impl/UserinfoServiceImpl.java | 53 ++++++++++++++++++
.../src/main/resources/application-dev.yml | 6 +-
.../src/main/resources/logback-spring.xml | 56 +++++++++++++++++++
.../main/resources/mapper/UserinfoMapper.xml | 55 ++++++++++++++++++
.../src/main/resources/mybatis-config.xml | 16 ++++++
13 files changed, 276 insertions(+), 30 deletions(-)
create mode 100644 spzx-service/service-user/src/main/java/cn/bunny/user/controller/UserinfoController.java
create mode 100644 spzx-service/service-user/src/main/java/cn/bunny/user/mapper/UserinfoMapper.java
create mode 100644 spzx-service/service-user/src/main/java/cn/bunny/user/service/UserinfoService.java
create mode 100644 spzx-service/service-user/src/main/java/cn/bunny/user/service/impl/UserinfoServiceImpl.java
create mode 100644 spzx-service/service-user/src/main/resources/logback-spring.xml
create mode 100644 spzx-service/service-user/src/main/resources/mapper/UserinfoMapper.xml
create mode 100644 spzx-service/service-user/src/main/resources/mybatis-config.xml
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 0b455dc..cfed013 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,25 +4,20 @@
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
@@ -32,9 +27,9 @@
@@ -86,7 +81,7 @@
"code.cleanup.on.save": "true",
"git-widget-placeholder": "master",
"jdk.selected.JAVA_MODULE": "21",
- "last_opened_file_path": "F:/File/Java/spzx-parent/spzx-service/service-user/src/main/java/cn/bunny/user",
+ "last_opened_file_path": "F:/File/Java/spzx-parent/spzx-service/service-user/src/main/resources",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
@@ -110,8 +105,8 @@
-
+
@@ -201,7 +196,7 @@
1703487755445
-
+
@@ -267,7 +262,15 @@
1703567148967
-
+
+
+ 1703574739774
+
+
+
+ 1703574739774
+
+
@@ -281,7 +284,8 @@
-
+
+
diff --git a/spzx-service/service-product/src/main/java/cn/bunny/web/product/controller/BrandController.java b/spzx-service/service-product/src/main/java/cn/bunny/web/product/controller/BrandController.java
index d93afff..e7c11ce 100644
--- a/spzx-service/service-product/src/main/java/cn/bunny/web/product/controller/BrandController.java
+++ b/spzx-service/service-product/src/main/java/cn/bunny/web/product/controller/BrandController.java
@@ -5,6 +5,7 @@ import cn.bunny.common.spzx.model.vo.common.Result;
import cn.bunny.common.spzx.model.vo.common.ResultCodeEnum;
import cn.bunny.web.product.service.BrandService;
import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -12,8 +13,9 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.List;
+@Tag(name = "品牌接口")
@RestController
-@RequestMapping(value="/api/product/brand")
+@RequestMapping(value = "/api/product/brand")
public class BrandController {
@Resource
private BrandService brandService;
diff --git a/spzx-service/service-product/src/main/java/cn/bunny/web/product/controller/CategoryController.java b/spzx-service/service-product/src/main/java/cn/bunny/web/product/controller/CategoryController.java
index 10a224f..5e78370 100644
--- a/spzx-service/service-product/src/main/java/cn/bunny/web/product/controller/CategoryController.java
+++ b/spzx-service/service-product/src/main/java/cn/bunny/web/product/controller/CategoryController.java
@@ -13,18 +13,18 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.List;
-@RestController
@Tag(name = "分类接口管理")
-@RequestMapping(value="/api/product/category")
+@RestController
+@RequestMapping(value = "/api/product/category")
// @CrossOrigin
public class CategoryController {
@Resource
private CategoryService categoryService;
- @Operation(summary = "获取分类树形数据",description = "按照树型方式进行封装")
+ @Operation(summary = "获取分类树形数据", description = "按照树型方式进行封装")
@GetMapping("findCategoryTree")
public Result findCategoryTree() {
- List categoryList= categoryService.findCategoryTree();
+ List categoryList = categoryService.findCategoryTree();
return Result.build(categoryList, ResultCodeEnum.SUCCESS);
}
}
diff --git a/spzx-service/service-product/src/main/java/cn/bunny/web/product/controller/ProductController.java b/spzx-service/service-product/src/main/java/cn/bunny/web/product/controller/ProductController.java
index 952bacb..a61a146 100644
--- a/spzx-service/service-product/src/main/java/cn/bunny/web/product/controller/ProductController.java
+++ b/spzx-service/service-product/src/main/java/cn/bunny/web/product/controller/ProductController.java
@@ -9,12 +9,14 @@ import cn.bunny.web.product.service.ProductService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
+@Tag(name = "商品接口")
@RestController
@RequestMapping("/api/product")
public class ProductController {
diff --git a/spzx-service/service-user/src/main/java/cn/bunny/user/controller/SmsController.java b/spzx-service/service-user/src/main/java/cn/bunny/user/controller/SmsController.java
index 5a85a8f..7ad1b5f 100644
--- a/spzx-service/service-user/src/main/java/cn/bunny/user/controller/SmsController.java
+++ b/spzx-service/service-user/src/main/java/cn/bunny/user/controller/SmsController.java
@@ -4,12 +4,14 @@ import cn.bunny.common.spzx.model.vo.common.Result;
import cn.bunny.common.spzx.model.vo.common.ResultCodeEnum;
import cn.bunny.user.service.SmsService;
import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
+@Tag(name = "发送验证码")
@RestController
@RequestMapping("/api/user/sms")
public class SmsController {
diff --git a/spzx-service/service-user/src/main/java/cn/bunny/user/controller/UserinfoController.java b/spzx-service/service-user/src/main/java/cn/bunny/user/controller/UserinfoController.java
new file mode 100644
index 0000000..d27134e
--- /dev/null
+++ b/spzx-service/service-user/src/main/java/cn/bunny/user/controller/UserinfoController.java
@@ -0,0 +1,28 @@
+package cn.bunny.user.controller;
+
+import cn.bunny.common.spzx.model.dto.h5.UserRegisterDto;
+import cn.bunny.common.spzx.model.vo.common.Result;
+import cn.bunny.common.spzx.model.vo.common.ResultCodeEnum;
+import cn.bunny.user.service.UserinfoService;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.annotation.Resource;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@Tag(name = "会员用户接口")
+@RestController
+@RequestMapping("api/user/userInfo")
+public class UserinfoController {
+ @Resource
+ private UserinfoService userinfoService;
+
+ @Operation(summary = "会员注册")
+ @PostMapping("register")
+ public Result register(@RequestBody UserRegisterDto userRegisterDto) {
+ userinfoService.register(userRegisterDto);
+ return Result.build(null, ResultCodeEnum.SUCCESS);
+ }
+}
diff --git a/spzx-service/service-user/src/main/java/cn/bunny/user/mapper/UserinfoMapper.java b/spzx-service/service-user/src/main/java/cn/bunny/user/mapper/UserinfoMapper.java
new file mode 100644
index 0000000..eb3e240
--- /dev/null
+++ b/spzx-service/service-user/src/main/java/cn/bunny/user/mapper/UserinfoMapper.java
@@ -0,0 +1,15 @@
+package cn.bunny.user.mapper;
+
+import cn.bunny.common.spzx.model.entity.user.UserInfo;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+@Mapper
+public interface UserinfoMapper {
+
+ // 校验用户名不重复
+ UserInfo getByUsername(@Param("username") String username);
+
+ // 封装添加数据,调用方法调用添加数据
+ void save(UserInfo userInfo);
+}
diff --git a/spzx-service/service-user/src/main/java/cn/bunny/user/service/UserinfoService.java b/spzx-service/service-user/src/main/java/cn/bunny/user/service/UserinfoService.java
new file mode 100644
index 0000000..542b70f
--- /dev/null
+++ b/spzx-service/service-user/src/main/java/cn/bunny/user/service/UserinfoService.java
@@ -0,0 +1,9 @@
+package cn.bunny.user.service;
+
+import cn.bunny.common.spzx.model.dto.h5.UserRegisterDto;
+
+public interface UserinfoService {
+ // 会员注册
+ void register(UserRegisterDto userLoginDto);
+
+}
diff --git a/spzx-service/service-user/src/main/java/cn/bunny/user/service/impl/UserinfoServiceImpl.java b/spzx-service/service-user/src/main/java/cn/bunny/user/service/impl/UserinfoServiceImpl.java
new file mode 100644
index 0000000..baa919c
--- /dev/null
+++ b/spzx-service/service-user/src/main/java/cn/bunny/user/service/impl/UserinfoServiceImpl.java
@@ -0,0 +1,53 @@
+package cn.bunny.user.service.impl;
+
+import cn.bunny.common.exception.BunnyException;
+import cn.bunny.common.spzx.model.dto.h5.UserRegisterDto;
+import cn.bunny.common.spzx.model.entity.user.UserInfo;
+import cn.bunny.common.spzx.model.vo.common.ResultCodeEnum;
+import cn.bunny.user.mapper.UserinfoMapper;
+import cn.bunny.user.service.UserinfoService;
+import jakarta.annotation.Resource;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.stereotype.Service;
+import org.springframework.util.DigestUtils;
+
+@Service
+public class UserinfoServiceImpl implements UserinfoService {
+ @Resource
+ private RedisTemplate redisTemplate;
+ @Resource
+ private UserinfoMapper userinfoMapper;
+
+ // 会员注册
+ @Override
+ public void register(UserRegisterDto userRegisterDto) {
+ // 1. userLoginDto获取数据
+ String username = userRegisterDto.getUsername();
+ String password = userRegisterDto.getPassword();
+ String nickName = userRegisterDto.getNickName();
+ String code = userRegisterDto.getCode();
+ // 2. 从Redis获取发送验证码
+ String redisCode = (String) redisTemplate.opsForValue().get(username);
+ // 3. 获取输入验证码,进行对比
+ if (!redisCode.equals(code)) {
+ throw new BunnyException(ResultCodeEnum.VALIDATECODE_ERROR);
+ }
+ // 4. 校验用户名不重复
+ UserInfo userInfo = userinfoMapper.getByUsername(username);
+ if (userInfo != null) {
+ throw new BunnyException(ResultCodeEnum.USER_NAME_IS_EXISTS);
+ }
+ // 5. 封装添加数据,调用方法调用添加数据
+ userInfo = new UserInfo();
+ userInfo.setUsername(username);
+ userInfo.setNickName(nickName);
+ userInfo.setPassword(DigestUtils.md5DigestAsHex(password.getBytes()));
+ userInfo.setPhone(username);
+ userInfo.setStatus(1);
+ userInfo.setSex(0);
+ userInfo.setAvatar("http://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83eoj0hHXhgJNOTSOFsS4uZs8x1ConecaVOB8eIl115xmJZcT4oCicvia7wMEufibKtTLqiaJeanU2Lpg3w/132");
+ userinfoMapper.save(userInfo);
+ // 6. 从Redis中删除发送验证码
+ redisTemplate.delete(username);
+ }
+}
diff --git a/spzx-service/service-user/src/main/resources/application-dev.yml b/spzx-service/service-user/src/main/resources/application-dev.yml
index 626b340..176744e 100644
--- a/spzx-service/service-user/src/main/resources/application-dev.yml
+++ b/spzx-service/service-user/src/main/resources/application-dev.yml
@@ -19,4 +19,8 @@ spring:
data:
redis:
port: 6379
- host: 192.168.2.156
\ No newline at end of file
+ host: 192.168.2.156
+
+mybatis:
+ config-location: classpath:mybatis-config.xml
+ mapper-locations: classpath:/mapper/*.xml
\ No newline at end of file
diff --git a/spzx-service/service-user/src/main/resources/logback-spring.xml b/spzx-service/service-user/src/main/resources/logback-spring.xml
new file mode 100644
index 0000000..09148d5
--- /dev/null
+++ b/spzx-service/service-user/src/main/resources/logback-spring.xml
@@ -0,0 +1,56 @@
+
+
+
+ logback
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ INFO
+
+
+ ${CONSOLE_LOG_PATTERN}
+ ${ENCODING}
+
+
+
+
+
+ ${log.path}//log.log
+ true
+
+ %date{yyyy-MM-dd HH:mm:ss} %msg%n
+ ${ENCODING}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spzx-service/service-user/src/main/resources/mapper/UserinfoMapper.xml b/spzx-service/service-user/src/main/resources/mapper/UserinfoMapper.xml
new file mode 100644
index 0000000..126b5fc
--- /dev/null
+++ b/spzx-service/service-user/src/main/resources/mapper/UserinfoMapper.xml
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+ id,username,password,nick_name,avatar,sex,phone,memo,open_id,union_id,last_login_ip,last_login_time,status,create_time,update_time,is_deleted
+
+
+
+
+
+
+
+
+ insert into user_info (id,
+ username,
+ password,
+ nick_name,
+ avatar,
+ sex,
+ phone,
+ memo,
+ open_id,
+ union_id,
+ last_login_ip,
+ last_login_time,
+ status)
+ values (#{id},
+ #{username},
+ #{password},
+ #{nickName},
+ #{avatar},
+ #{sex},
+ #{phone},
+ #{memo},
+ #{openId},
+ #{unionId},
+ #{lastLoginIp},
+ #{lastLoginTime},
+ #{status})
+
+
+
diff --git a/spzx-service/service-user/src/main/resources/mybatis-config.xml b/spzx-service/service-user/src/main/resources/mybatis-config.xml
new file mode 100644
index 0000000..89898c2
--- /dev/null
+++ b/spzx-service/service-user/src/main/resources/mybatis-config.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+