Quellcode durchsuchen

Merge branch 'huangyuan-user' of lift-manager/lift-server into develop

huangyuan vor 5 Jahren
Ursprung
Commit
f65660c590

+ 5 - 0
lift-common/pom.xml

@@ -31,6 +31,11 @@
             <artifactId>aliyun-sdk-oss</artifactId>
             <version>3.5.0</version>
         </dependency>
+        <dependency>
+            <groupId>com.aliyun</groupId>
+            <artifactId>aliyun-java-sdk-core</artifactId>
+            <version>4.0.3</version>
+        </dependency>
         <dependency>
             <groupId>commons-logging</groupId>
             <artifactId>commons-logging</artifactId>

+ 9 - 0
lift-common/src/main/java/cn.com.ty.lift.common/aliservice/alipay/AlipayUtil.java

@@ -0,0 +1,9 @@
+package cn.com.ty.lift.common.aliservice.alipay;
+
+/**
+ * @author huangyuan
+ * @date 2019-12-05
+ * @description 阿里支付工具
+ */
+public class AlipayUtil {
+}

+ 76 - 0
lift-common/src/main/java/cn.com.ty.lift.common/aliservice/aliyunsms/AliyunSmsUtil.java

@@ -0,0 +1,76 @@
+package cn.com.ty.lift.common.aliservice.aliyunsms;
+
+import cn.com.ty.lift.common.aliservice.constants.AliConstants;
+import cn.hutool.json.JSONUtil;
+import com.aliyuncs.CommonRequest;
+import com.aliyuncs.CommonResponse;
+import com.aliyuncs.DefaultAcsClient;
+import com.aliyuncs.IAcsClient;
+import com.aliyuncs.exceptions.ClientException;
+import com.aliyuncs.exceptions.ServerException;
+import com.aliyuncs.http.MethodType;
+import com.aliyuncs.profile.DefaultProfile;
+
+import java.util.Random;
+
+/**
+ * @author huangyuan
+ * @date 2019-12-05
+ * @description 阿里云短信接口
+ */
+public class AliyunSmsUtil {
+
+
+    public static String sendSmsCode(String phoneNumbers, String templateCode){
+        String smsCode = GenerateSMSCode();
+        DefaultProfile profile = DefaultProfile.getProfile(AliConstants.REGION_ID, AliConstants.SmsConstants.ACCESS_KEY_ID,
+                AliConstants.SmsConstants.ACCESS_SECRET);
+        IAcsClient client = new DefaultAcsClient(profile);
+        CommonRequest request = new CommonRequest();
+        request.setMethod(MethodType.POST);
+        request.setDomain(AliConstants.SmsConstants.DOMAIN);
+        request.setVersion(AliConstants.SmsConstants.VERSION);
+        request.setAction(AliConstants.SmsConstants.ACTION_SEND_SMS);
+        //设置区域
+        request.putQueryParameter("RegionId", AliConstants.REGION_ID);
+        //设置手机号
+        request.putQueryParameter("PhoneNumbers", phoneNumbers);
+        //设置模板签名
+        request.putQueryParameter("SignName", AliConstants.SmsConstants.SIGN_NAME);
+        //设置模板编码
+        request.putQueryParameter("TemplateCode", templateCode);
+        //设置验证码
+        String templateParam = "{\"code\":\"" + smsCode + "\"}";
+        request.putQueryParameter("TemplateParam", templateParam);
+
+        try {
+            CommonResponse response = client.getCommonResponse(request);
+            String returnMessage = response.getData();
+            SmsResponse smsResponse = JSONUtil.toBean(returnMessage, SmsResponse.class);
+            if(!AliConstants.STATUS_CODE_OK.equals(smsResponse.getCode())){
+               return null;
+            }
+        } catch (ServerException e) {
+            e.printStackTrace();
+        } catch (ClientException e) {
+            e.printStackTrace();
+        }
+        return smsCode;
+    }
+
+    /**
+     * 生成6位随机码
+     *@author huangy
+     *@return String
+     *@throws
+     */
+    public static String GenerateSMSCode() {
+        String smsVerifyCode = "";
+        Random random = new Random();
+        for(int i = 0; i < 6; i++) {
+            smsVerifyCode = smsVerifyCode + random.nextInt(10);//生成0-10(不包括10)之间的随机数
+        }
+        return smsVerifyCode;
+    }
+
+}

+ 16 - 0
lift-common/src/main/java/cn.com.ty.lift.common/aliservice/aliyunsms/SmsResponse.java

@@ -0,0 +1,16 @@
+package cn.com.ty.lift.common.aliservice.aliyunsms;
+
+import lombok.Data;
+
+/**
+ * @author huangyuan
+ * @date 2019-12-05
+ * @description
+ */
+@Data
+public class SmsResponse {
+    private String Message;
+    private String RequestId;
+    private String BizId;
+    private String Code;//ok表示成功
+}

+ 65 - 0
lift-common/src/main/java/cn.com.ty.lift.common/aliservice/constants/AliConstants.java

@@ -0,0 +1,65 @@
+package cn.com.ty.lift.common.aliservice.constants;
+
+/**
+ * @author huangyuan
+ * @date 2019-12-05
+ * @description 阿里常量
+ */
+public class AliConstants {
+
+    /**
+     * 区域id
+     */
+    public static final String REGION_ID = "cn-hangzhou";
+
+    /**
+     * 接口状态码 ok
+     */
+    public static String STATUS_CODE_OK = "OK";
+
+    /**
+     * 短接口常量
+     */
+    public interface SmsConstants {
+        /**
+         * 密钥id
+         */
+        String ACCESS_KEY_ID = "LTAI4FeGzeF8Ss7e42wzKUQg";
+
+        /**
+         * api secret
+         */
+        String ACCESS_SECRET = "YfSlyyj3sHE8I7NI75gpmoZTDDugES";
+
+        /**
+         * 接口域名
+         */
+        String DOMAIN = "dysmsapi.aliyuncs.com";//域名
+
+        /**
+         * 接口版本
+         */
+        String VERSION = "2017-05-25";//版本
+
+        /**
+         * 接口名称-发送发送短信
+         */
+        String ACTION_SEND_SMS = "SendSms";
+
+        /**
+         * 短信签名
+         */
+        String SIGN_NAME = "极客课堂";
+
+        /**
+         * 短信模板-测试
+         */
+        String TEST_TEMPLATE_CODE = "SMS_175580242";
+
+        /**
+         * 短信验证码字段
+         */
+        String SMS_CODE_NAME = "smsCode";
+    }
+
+}

+ 2 - 1
lift-common/src/main/java/cn.com.ty.lift.common/constants/ApiConstants.java

@@ -53,5 +53,6 @@ public class ApiConstants {
     /**
      * 区域
      */
-    public  static final String AREA_PARENT_ATTR = "parent";
+    public static final String AREA_PARENT_ATTR = "parent";
+
 }

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

@@ -1,5 +1,7 @@
 package cn.com.ty.lift.system.user.controller;
 
+import cn.com.ty.lift.common.aliservice.aliyunsms.AliyunSmsUtil;
+import cn.com.ty.lift.common.aliservice.constants.AliConstants;
 import cn.com.ty.lift.common.constants.ApiConstants;
 import cn.com.ty.lift.system.user.dao.entity.UserAccount;
 import cn.com.ty.lift.system.user.dao.entity.model.UserRequest;
@@ -7,6 +9,7 @@ import cn.com.ty.lift.system.user.service.ILoginService;
 import cn.com.ty.lift.system.user.service.IUserAccountService;
 import cn.com.ty.lift.system.utils.RandomValidateCodeUtil;
 import cn.com.xwy.boot.web.dto.RestResponse;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -113,4 +116,42 @@ public class LoginController {
         return RestResponse.ok(null, ApiConstants.RESULT_SUCCESS, "验证通过");
     }
 
+    /**
+     * @description
+     * @date 2019/11/27 10:03 AM
+     * @param request
+     * @param mobile 手机号
+     * @return
+     */
+    @RequestMapping("/smsCode")
+    @ResponseBody
+    public RestResponse smsCode(HttpServletRequest request, String mobile){
+        if(StringUtils.isNotBlank(mobile)){
+            String smsCode = AliyunSmsUtil.sendSmsCode(mobile, AliConstants.SmsConstants.TEST_TEMPLATE_CODE);
+            if(StringUtils.isNotBlank(smsCode)){
+                request.getSession().setAttribute(AliConstants.SmsConstants.SMS_CODE_NAME, smsCode);
+                return RestResponse.ok(smsCode, ApiConstants.RESULT_SUCCESS, "发送验证码成功");
+            }
+            return RestResponse.error(ApiConstants.RESULT_ERROR, "手机号不存在,发送验证码失败");
+        }
+        return RestResponse.error(ApiConstants.RESULT_ERROR, "手机号为空");
+    }
+
+    /**
+     * @description 校验短信验证码
+     * @date 2019/11/27 10:03 AM
+     * @param request
+     * @param inputSmsCode 输入的短信验证码
+     * @return
+     */
+    @RequestMapping("/checkSmsCode")
+    @ResponseBody
+    public RestResponse checkSmsCode(HttpServletRequest request, String inputSmsCode){
+        String smsCode = (String) request.getSession().getAttribute(AliConstants.SmsConstants.SMS_CODE_NAME);
+        if(StringUtils.isNotBlank(inputSmsCode) && inputSmsCode.equals(smsCode)){
+            return RestResponse.ok(null, ApiConstants.RESULT_SUCCESS, "短信验证码校验成功");
+        }
+        return RestResponse.error(ApiConstants.RESULT_ERROR, "短信验证码校验失败");
+    }
+
 }

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

@@ -68,4 +68,5 @@ public class UserController {
     public RestResponse deleteUser(UserRequest userRequest){
         return userService.deleteUser(userRequest);
     }
+
 }

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

@@ -12,6 +12,7 @@ public class UserRequest {
     private Long userId;//用户id
     private Long roleId;//角色id
     private Long companyId;//公司id
+    private String account;//账号(小梯号)
     private String mobile;//手机号
     private String password;//密码
     private String name;//用户真实姓名

+ 0 - 1
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/IUserService.java

@@ -51,5 +51,4 @@ public interface IUserService{
      * @return
      */
     RestResponse deleteUser(UserRequest userRequest);
-
 }

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

@@ -37,6 +37,8 @@ public class UserService implements IUserService {
         String password = userRequest.getPassword();
         UserAccount userAccount = new UserAccount();
         userAccount.setMobile(userRequest.getMobile());
+        //设置账号(小梯号)
+        userAccount.setAccount(userRequest.getAccount());
         userAccount.setCreateDate(new Date());
         UserInfo userInfo = new UserInfo();
         userInfo.setName(userRequest.getName());

+ 3 - 170
lift-system-service/src/main/resources/mapper/UserAccountMapper.xml

@@ -22,176 +22,6 @@
 		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.user.dao.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.user.dao.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.user.dao.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.user.dao.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>
 
 	<!--通过账户对象,多维度查询用户账户信息 -->
 	<select id="getByUserAccount" parameterType="cn.com.ty.lift.system.user.dao.entity.UserAccount" resultType="cn.com.ty.lift.system.user.dao.entity.UserAccount">
@@ -199,6 +29,9 @@
 		<include refid="Base_Column_List" />
 		from user_account
 		where 1 = 1
+		<if test="userId != null">
+			and <![CDATA[ user_id <> #{userId, jdbcType=BIGINT} ]]>
+		</if>
 		<if test="mobile != null">
 			and mobile = #{mobile,jdbcType=VARCHAR}
 		</if>