黄远 5 年 前
コミット
125ca1bf42

+ 39 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/entity/UserAccount.java

@@ -0,0 +1,39 @@
+package cn.com.ty.lift.system.entity;
+
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * 实体类 - 表:user_account
+ * @since 2019-11-29 17:15:02
+ */
+@Data
+public class UserAccount {
+	private Long userId;
+
+	private int type;
+
+	private String account;
+
+	private String password;
+
+	private String salt;
+
+	private String mobile;
+
+	private String wechatOpenId;
+
+	private String email;
+
+	private String otherAccount;
+
+	private String otherAccount2;
+
+	private int status;
+
+	private String remarks;
+
+	private Date createDate;
+
+}

+ 15 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/entity/model/UserRequest.java

@@ -0,0 +1,15 @@
+package cn.com.ty.lift.system.entity.model;
+
+import lombok.Data;
+
+/**
+ * @author huangyuan
+ * @date 2019-11-29
+ * @description 用户请求类
+ */
+@Data
+public class UserRequest {
+    private String mobile;//手机号
+    private String password;//密码
+    private String name;//用户真实姓名
+}

+ 23 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/mapper/UserAccountMapper.java

@@ -0,0 +1,23 @@
+package cn.com.ty.lift.system.mapper;
+
+import cn.com.ty.lift.system.entity.UserAccount;
+import cn.com.xwy.boot.mybatis.MyBatisMapper;
+
+/**
+ * MyBatis Mapper 接口 - 表:user_account
+ * @since 2019-11-29 17:15:02
+ */
+@MyBatisMapper
+public interface UserAccountMapper {
+	int deleteByPrimaryKey(Long userId);
+
+	int insert(UserAccount record);
+
+	int insertSelective(UserAccount record);
+
+	UserAccount selectByPrimaryKey(Long userId);
+
+	int updateByPrimaryKeySelective(UserAccount record);
+
+	int updateByPrimaryKey(UserAccount record);
+}

+ 14 - 3
lift-system-service/src/main/java/cn/com/ty/lift/system/user/controller/LoginController.java

@@ -1,7 +1,9 @@
 package cn.com.ty.lift.system.user.controller;
 
-import cn.com.ty.lift.common.Constants.ApiConstants;
+import cn.com.ty.lift.system.entity.model.UserRequest;
+import cn.com.ty.lift.system.user.service.impl.LoginService;
 import cn.com.xwy.boot.web.dto.RestResponse;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -14,9 +16,18 @@ import org.springframework.web.bind.annotation.RestController;
 @RequestMapping("/login")
 public class LoginController {
 
+    @Autowired
+    private LoginService loginService;
+
+    /**
+     * @description 用户注册
+     * @date 2019/11/27 10:03 AM
+     * @param userRequest 用户参数对象
+     * @return
+     */
     @RequestMapping("/register")
-    public RestResponse register(){
-        return RestResponse.ok(null, ApiConstants.RESULT_SUCCESS, "注册成功");
+    public RestResponse register(UserRequest userRequest){
+        return loginService.register(userRequest);
     }
 
 

+ 0 - 25
lift-system-service/src/main/java/cn/com/ty/lift/system/user/controller/UserController.java

@@ -1,13 +1,8 @@
 package cn.com.ty.lift.system.user.controller;
 
-import cn.com.ty.lift.system.entity.User;
-import cn.com.ty.lift.system.entity.UserInfo;
 import cn.com.ty.lift.system.user.service.impl.UserService;
-import cn.com.xwy.boot.web.dto.RestResponse;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.bind.annotation.RestController;
 
 @RestController
@@ -17,24 +12,4 @@ public class UserController {
     @Autowired
     private UserService userService;
 
-    @RequestMapping("/login")
-    @ResponseBody
-    public User getUser(String userId){
-        User user = userService.getUserById(userId);
-        return user;
-    }
-
-    /**
-     * @description
-     * @date 2019/11/27 10:03 AM
-     * @param
-     * @return
-     */
-    @PostMapping("/addUser")
-    @ResponseBody
-    public Object addUserInfo(UserInfo userInfo){
-        userService.saveUserInfo(userInfo);
-        return RestResponse.ok(UserInfo.class, "success");
-    }
-
 }

+ 15 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/ILoginService.java

@@ -0,0 +1,15 @@
+package cn.com.ty.lift.system.user.service;
+
+import cn.com.ty.lift.system.entity.model.UserRequest;
+import cn.com.xwy.boot.web.dto.RestResponse;
+
+public interface ILoginService {
+
+    /**
+     * @description 用户注册
+     * @date 2019/11/27 10:03 AM
+     * @param userRequest  用户请求参数
+     * @return
+     */
+    RestResponse register(UserRequest userRequest);
+}

+ 20 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/IUserAccountService.java

@@ -0,0 +1,20 @@
+package cn.com.ty.lift.system.user.service;
+
+import cn.com.ty.lift.system.entity.UserAccount;
+
+/**
+ * @author huangyuan
+ * @date 2019-11-29
+ * @description 用户账户接口
+ */
+public interface IUserAccountService {
+
+    /**
+     * @description 保存用户账户
+     * @date 2019/11/27 10:03 AM
+     * @param userAccount 用户账户
+     * @return
+     */
+    int add(UserAccount userAccount);
+
+}

+ 20 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/IUserInfoService.java

@@ -0,0 +1,20 @@
+package cn.com.ty.lift.system.user.service;
+
+import cn.com.ty.lift.system.entity.UserInfo;
+
+/**
+ * @author huangyuan
+ * @date 2019-11-29
+ * @description
+ */
+public interface IUserInfoService {
+
+    /**
+     * @description 新增用户信息
+     * @date 2019/11/27 10:03 AM
+     * @param userInfo 用户信息
+     * @return 插入条数
+     */
+    int add(UserInfo userInfo);
+
+}

+ 9 - 12
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/IUserService.java

@@ -1,6 +1,6 @@
 package cn.com.ty.lift.system.user.service;
 
-import cn.com.ty.lift.system.entity.User;
+import cn.com.ty.lift.system.entity.UserAccount;
 import cn.com.ty.lift.system.entity.UserInfo;
 
 /**
@@ -8,15 +8,12 @@ import cn.com.ty.lift.system.entity.UserInfo;
  * @author huangyuan - 2019-11-25 18:36:53
  */
 public interface IUserService{
-
-    /*
-     *@Author huangyuan
-     *@Description 通过用户id获取用户信息
-     *@Date 15:57 2019-11-26
-     *@Param [userId]
-     *@return cn.com.ty.lift.system.entity.User
-     **/
-    User getUserById(String userId);
-
-    void saveUserInfo(UserInfo userInfo);
+    /**
+     * @description  用户注册
+     * @date 2019/11/27 10:03 AM
+     * @param userInfo 用户信息
+     * @param userAccount 用户账户
+     * @return
+     */
+    boolean register(UserInfo userInfo, UserAccount userAccount);
 }

+ 41 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/impl/LoginService.java

@@ -0,0 +1,41 @@
+package cn.com.ty.lift.system.user.service.impl;
+
+import cn.com.ty.lift.common.Constants.ApiConstants;
+import cn.com.ty.lift.system.entity.UserAccount;
+import cn.com.ty.lift.system.entity.UserInfo;
+import cn.com.ty.lift.system.entity.model.UserRequest;
+import cn.com.ty.lift.system.user.service.ILoginService;
+import cn.com.xwy.boot.web.dto.RestResponse;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Date;
+
+/**
+ * @author huangyuan
+ * @date 2019-11-29
+ * @description 用户登录接口
+ */
+@Service
+public class LoginService implements ILoginService {
+
+    @Autowired
+    private UserService userService;
+
+    @Override
+    public RestResponse register(UserRequest userRequest) {
+        UserAccount userAccount = new UserAccount();
+        userAccount.setMobile(userRequest.getMobile());
+        userAccount.setCreateDate(new Date());
+        UserInfo userInfo = new UserInfo();
+        userInfo.setName(userRequest.getName());
+        //密码加密
+
+        //保存用户信息
+        boolean registerFlag = userService.register(userInfo, userAccount);
+        if(registerFlag){
+            return RestResponse.ok(null, ApiConstants.RESULT_SUCCESS, "注册成功");
+        }
+        return RestResponse.error(ApiConstants.RESULT_ERROR, "注册失败");
+    }
+}

+ 26 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/impl/UserAccountService.java

@@ -0,0 +1,26 @@
+package cn.com.ty.lift.system.user.service.impl;
+
+import cn.com.ty.lift.system.entity.UserAccount;
+import cn.com.ty.lift.system.mapper.UserAccountMapper;
+import cn.com.ty.lift.system.user.service.IUserAccountService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * @author huangyuan
+ * @date 2019-11-29
+ * @description 用户账户
+ */
+@Service
+public class UserAccountService implements IUserAccountService {
+
+    @Autowired
+    private UserAccountMapper userAccountMapper;
+
+    @Override
+    @Transactional
+    public int add(UserAccount userAccount) {
+        return userAccountMapper.insert(userAccount);
+    }
+}

+ 26 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/impl/UserInfoService.java

@@ -0,0 +1,26 @@
+package cn.com.ty.lift.system.user.service.impl;
+
+import cn.com.ty.lift.system.entity.UserInfo;
+import cn.com.ty.lift.system.mapper.UserInfoMapper;
+import cn.com.ty.lift.system.user.service.IUserInfoService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * @author huangyuan
+ * @date 2019-11-29
+ * @description 用户信息
+ */
+@Service
+public class UserInfoService implements IUserInfoService {
+
+    @Autowired
+    private UserInfoMapper userInfoMapper;
+
+    @Override
+    @Transactional
+    public int add(UserInfo userInfo) {
+        return userInfoMapper.insert(userInfo);
+    }
+}

+ 21 - 17
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/impl/UserService.java

@@ -1,35 +1,39 @@
 package cn.com.ty.lift.system.user.service.impl;
 
-import cn.com.ty.lift.system.entity.User;
+import cn.com.ty.lift.system.entity.UserAccount;
 import cn.com.ty.lift.system.entity.UserInfo;
-import cn.com.ty.lift.system.mapper.UserInfoMapper;
+import cn.com.ty.lift.system.user.service.IUserAccountService;
+import cn.com.ty.lift.system.user.service.IUserInfoService;
 import cn.com.ty.lift.system.user.service.IUserService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
- * <h1>.</h1><BR>
- * @author huangyuan - 2019-11-25 18:36:53
+ * @author huangyuan
+ * @date 2019-11-29
+ * @description 用户接口
  */
-@Service("IUserService")
-@Transactional
+@Service
 public class UserService implements IUserService {
 
     @Autowired
-    private UserInfoMapper userInfoMapper;
+    private IUserAccountService userAccountService;
 
-    public User getUserById(String userId) {
-        User user = new User();
-        user.setId(1L);
-        user.setAccount("huangyuan");
-        user.setName("黄远");
-        user.setPassword("123456");
-        return user;
-    }
+    @Autowired
+    private IUserInfoService userInfoService;
 
     @Override
-    public void saveUserInfo(UserInfo userInfo) {
-        userInfoMapper.insert(userInfo);
+    @Transactional
+    public boolean register(UserInfo userInfo, UserAccount userAccount) {
+        //保存用户账户
+        int insertAccountCount = userAccountService.add(userAccount);
+        userInfo.setUserId(userAccount.getUserId());
+        //保存用户信息
+        int insertInfoCount = userInfoService.add(userInfo);
+        if(insertAccountCount == 0 || insertInfoCount == 0){
+            return false;
+        }
+        return true;
     }
 }

+ 196 - 0
lift-system-service/src/main/resources/mapper/UserAccountMapper.xml

@@ -0,0 +1,196 @@
+<?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="cn.com.ty.lift.system.mapper.UserAccountMapper" >
+	<resultMap id="BaseResultMap" type="cn.com.ty.lift.system.entity.UserAccount" >
+		<id column="user_id" property="userId" jdbcType="BIGINT" />
+		<result column="type" property="type" jdbcType="TINYINT" />
+		<result column="account" property="account" jdbcType="VARCHAR" />
+		<result column="password" property="password" jdbcType="VARCHAR" />
+		<result column="salt" property="salt" jdbcType="VARCHAR" />
+		<result column="mobile" property="mobile" jdbcType="CHAR" />
+		<result column="wechat_open_id" property="wechatOpenId" jdbcType="VARCHAR" />
+		<result column="email" property="email" jdbcType="VARCHAR" />
+		<result column="other_account" property="otherAccount" jdbcType="VARCHAR" />
+		<result column="other_account2" property="otherAccount2" jdbcType="VARCHAR" />
+		<result column="status" property="status" jdbcType="TINYINT" />
+		<result column="remarks" property="remarks" jdbcType="VARCHAR" />
+		<result column="create_date" property="createDate" jdbcType="TIMESTAMP" />
+	</resultMap>
+
+	<sql id="Base_Column_List" >
+		user_id, type, account, password, salt, mobile, wechat_open_id, email, other_account, 
+		other_account2, status, remarks, create_date
+	</sql>
+
+	<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
+		select 
+		<include refid="Base_Column_List" />
+		from user_account
+		where user_id = #{userId,jdbcType=BIGINT}
+	</select>
+
+	<delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
+		delete from user_account
+		where user_id = #{userId,jdbcType=BIGINT}
+	</delete>
+
+	<insert id="insert" parameterType="cn.com.ty.lift.system.entity.UserAccount" >
+		insert into user_account (user_id, type, account, 
+			password, salt, mobile, 
+			wechat_open_id, email, other_account, 
+			other_account2, status, remarks, 
+			create_date)
+		values (#{userId,jdbcType=BIGINT}, #{type,jdbcType=TINYINT}, #{account,jdbcType=VARCHAR}, 
+			#{password,jdbcType=VARCHAR}, #{salt,jdbcType=VARCHAR}, #{mobile,jdbcType=CHAR}, 
+			#{wechatOpenId,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{otherAccount,jdbcType=VARCHAR}, 
+			#{otherAccount2,jdbcType=VARCHAR}, #{status,jdbcType=TINYINT}, #{remarks,jdbcType=VARCHAR}, 
+			#{createDate,jdbcType=TIMESTAMP})
+	</insert>
+
+	<insert id="insertSelective" parameterType="cn.com.ty.lift.system.entity.UserAccount" >
+		insert into user_account
+		<trim prefix="(" suffix=")" suffixOverrides="," >
+			<if test="userId != null" >
+				user_id,
+			</if>
+			<if test="type != null" >
+				type,
+			</if>
+			<if test="account != null" >
+				account,
+			</if>
+			<if test="password != null" >
+				password,
+			</if>
+			<if test="salt != null" >
+				salt,
+			</if>
+			<if test="mobile != null" >
+				mobile,
+			</if>
+			<if test="wechatOpenId != null" >
+				wechat_open_id,
+			</if>
+			<if test="email != null" >
+				email,
+			</if>
+			<if test="otherAccount != null" >
+				other_account,
+			</if>
+			<if test="otherAccount2 != null" >
+				other_account2,
+			</if>
+			<if test="status != null" >
+				status,
+			</if>
+			<if test="remarks != null" >
+				remarks,
+			</if>
+			<if test="createDate != null" >
+				create_date,
+			</if>
+		</trim>
+		<trim prefix="values (" suffix=")" suffixOverrides="," >
+			<if test="userId != null" >
+				#{userId,jdbcType=BIGINT},
+			</if>
+			<if test="type != null" >
+				#{type,jdbcType=TINYINT},
+			</if>
+			<if test="account != null" >
+				#{account,jdbcType=VARCHAR},
+			</if>
+			<if test="password != null" >
+				#{password,jdbcType=VARCHAR},
+			</if>
+			<if test="salt != null" >
+				#{salt,jdbcType=VARCHAR},
+			</if>
+			<if test="mobile != null" >
+				#{mobile,jdbcType=CHAR},
+			</if>
+			<if test="wechatOpenId != null" >
+				#{wechatOpenId,jdbcType=VARCHAR},
+			</if>
+			<if test="email != null" >
+				#{email,jdbcType=VARCHAR},
+			</if>
+			<if test="otherAccount != null" >
+				#{otherAccount,jdbcType=VARCHAR},
+			</if>
+			<if test="otherAccount2 != null" >
+				#{otherAccount2,jdbcType=VARCHAR},
+			</if>
+			<if test="status != null" >
+				#{status,jdbcType=TINYINT},
+			</if>
+			<if test="remarks != null" >
+				#{remarks,jdbcType=VARCHAR},
+			</if>
+			<if test="createDate != null" >
+				#{createDate,jdbcType=TIMESTAMP},
+			</if>
+		</trim>
+	</insert>
+
+	<update id="updateByPrimaryKeySelective" parameterType="cn.com.ty.lift.system.entity.UserAccount" >
+		update user_account
+		<set >
+			<if test="type != null" >
+				type = #{type,jdbcType=TINYINT},
+			</if>
+			<if test="account != null" >
+				account = #{account,jdbcType=VARCHAR},
+			</if>
+			<if test="password != null" >
+				password = #{password,jdbcType=VARCHAR},
+			</if>
+			<if test="salt != null" >
+				salt = #{salt,jdbcType=VARCHAR},
+			</if>
+			<if test="mobile != null" >
+				mobile = #{mobile,jdbcType=CHAR},
+			</if>
+			<if test="wechatOpenId != null" >
+				wechat_open_id = #{wechatOpenId,jdbcType=VARCHAR},
+			</if>
+			<if test="email != null" >
+				email = #{email,jdbcType=VARCHAR},
+			</if>
+			<if test="otherAccount != null" >
+				other_account = #{otherAccount,jdbcType=VARCHAR},
+			</if>
+			<if test="otherAccount2 != null" >
+				other_account2 = #{otherAccount2,jdbcType=VARCHAR},
+			</if>
+			<if test="status != null" >
+				status = #{status,jdbcType=TINYINT},
+			</if>
+			<if test="remarks != null" >
+				remarks = #{remarks,jdbcType=VARCHAR},
+			</if>
+			<if test="createDate != null" >
+				create_date = #{createDate,jdbcType=TIMESTAMP},
+			</if>
+		</set>
+		where user_id = #{userId,jdbcType=BIGINT}
+	</update>
+
+	<update id="updateByPrimaryKey" parameterType="cn.com.ty.lift.system.entity.UserAccount" >
+		update user_account
+		set type = #{type,jdbcType=TINYINT},
+			account = #{account,jdbcType=VARCHAR},
+			password = #{password,jdbcType=VARCHAR},
+			salt = #{salt,jdbcType=VARCHAR},
+			mobile = #{mobile,jdbcType=CHAR},
+			wechat_open_id = #{wechatOpenId,jdbcType=VARCHAR},
+			email = #{email,jdbcType=VARCHAR},
+			other_account = #{otherAccount,jdbcType=VARCHAR},
+			other_account2 = #{otherAccount2,jdbcType=VARCHAR},
+			status = #{status,jdbcType=TINYINT},
+			remarks = #{remarks,jdbcType=VARCHAR},
+			create_date = #{createDate,jdbcType=TIMESTAMP}
+		where user_id = #{userId,jdbcType=BIGINT}
+	</update>
+
+</mapper>