Commit 196d891d authored by liqin's avatar liqin 💬

Merge branch 'master' of http://111.203.232.171:8888/licc/shop-mall into master

 Conflicts:
	wisenergy-common/wisenergy-common.iml
	wisenergy-mapper/wisenergy-mapper.iml
	wisenergy-model/wisenergy-model.iml
	wisenergy-parent.iml
	wisenergy-service/wisenergy-service.iml
	wisenergy-web-admin/wisenergy-web-admin.iml
parents b9d3f845 697d26af
......@@ -158,6 +158,18 @@
<artifactId>hutool-all</artifactId>
<version>4.6.17</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
<!-- 阿里短信依赖-->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.4.0</version>
</dependency>
</dependencies>
<!-- MAVEN构建 -->
......
......@@ -41,21 +41,35 @@ public class Constants {
//一秒
public final static Integer SECOND_INT = 1;
//一分钟
public final static Integer MINUTE_INT = SECOND_INT * 60;
public final static Integer MINUTE_INT = SECOND_INT * 180;
//半小时
public final static Integer HALF_HOUR_INT = MINUTE_INT * 30;
}
//正则的一些常量
public static class RegConstant{
//手机号正则
public static String PHONE_REGSTR = "^[1][0-9]{10}$";
public static String PHONE_REGSTR = "^1[0-9]{10}$";
//密码正则
public static String PASSWORD_REGSTR = "^([A-Z]|[a-z]|[0-9]|[_]){6,10}$";
}
//SMS相关常量
public static class Sms{
public static class TemplateCode{
public static String LOGIN_OR_REGISTER="SMS_197895260";
//对存入redis的tokn用户进行标注
public static String LOGIN_BZ_REGISTER="xts";
//身份验证验证码
public static String LOGIN_SF_REGISTER="SMS_212170059";
//登录确认验证码
public static String LOGIN_DL_REGISTER="SMS_212170058";
//登录异常验证码
public static String LOGIN_DLYC_REGISTER="SMS_212170057";
//用户注册验证码
public static String LOGIN_ZC_REGISTER="SMS_212170056";
//修改密码验证码
public static String LOGIN_XGMM_REGISTER= "SMS_212170055";
// 信息变更验证码
public static String LOGIN_XXBG_REGISTER= "SMS_212170054";
}
public static class CodeType{
......@@ -69,5 +83,6 @@ public class Constants {
public static String PROJECT_PRIFIX="xts";
public static String SMS_PRIFIX="sms";
public static String TOKEN_PRIFIX="token";
public static String BANK_PRIFIX="bank";
}
}
package cn.wisenergy.common.utils;
import java.util.zip.CRC32;
/**
*
* @author eaves.zhu
*/
public class DeviceIdUtil {
/**
* @author eaves.zhu
* @param deviceId
* @return int
* CRC32
*/
public static long getCRC32(String deviceId){
CRC32 crc32 = new CRC32();
crc32.update(deviceId.getBytes());
long tmp = crc32.getValue();
return tmp;
}
}
\ No newline at end of file
package cn.wisenergy.common.utils;
import java.math.BigDecimal;
/**
* @Description 数字相关工具类
* @Date 2019-08-22 17:08
* @Author est team
* Version 1.0
**/
public class MathUtils {
/**
* 返回一个4位随机数
* @return
*/
public static String random(){
int random = (int) ((Math.random() * 9 + 1) * 1000);
return random + "";
}
/**
* 格式化BigDecimal,返回保留相应的小数
* @param decimal
* @param num
* @return
*/
public static BigDecimal formatDecimal(BigDecimal decimal, int num){
BigDecimal result = decimal.setScale(num,BigDecimal.ROUND_HALF_UP);
return result;
}
/**
* 格式化BigDecimal,默认保留两位小数
* @param decimal
* @return
*/
public static BigDecimal formatDecimal(BigDecimal decimal){
BigDecimal result = formatDecimal(decimal, Constants.Common.DECIMAL_DIGITS);
return result;
}
}
package cn.wisenergy.common.utils;
import org.apache.log4j.Logger;
/**
*
* @author zen.wang zenyes@gmail.com
*/
public class ShareCodeUtil {
/** 自定义进制(0,1没有加入,容易与o,l混淆) */
private static final char[] r=new char[]{'F', 'L', 'G', 'W', '5', 'X', 'C', '3', '9', 'Z', 'M', '6', '7', 'Y', 'R', 'T', '2', 'H', 'S', '8', 'D', 'V', 'E', 'J', '4', 'K', 'Q', 'P', 'U', 'A', 'N', 'B'};
/** 进制长度 */
private static final int binLen=r.length;
private static Logger logger = Logger.getLogger(ShareCodeUtil.class);
private static final long startNumber = 100048576L;
// private static final long startNumber = 0L;
/**
*
* @param id ID
* @return 随机码
*/
public static String idToCode(long id,long costomStartNumber) {
if(costomStartNumber<0){
costomStartNumber = startNumber;
}
id += costomStartNumber;
char[] buf=new char[32];
int charPos=32;
while((id / binLen) > 0) {
int ind=(int)(id % binLen);
// System.out.println(num + "-->" + ind);
buf[--charPos]=r[ind];
id /= binLen;
}
buf[--charPos]=r[(int)(id % binLen)];
// System.out.println(num + "-->" + num % binLen);
String str=new String(buf, charPos, (32 - charPos));
return str.toUpperCase();
}
public static String idToCode(long idL){
return idToCode(idL,-1L);
}
public static String idToCode(String id){
long idL = Long.parseLong(id);
return idToCode(idL,-1L);
}
public static String idToCode(String id,long costomStartNumber){
long idL = Long.parseLong(id);
return idToCode(idL,costomStartNumber);
}
public static long codeToId(String code) {
code = code.toUpperCase();
char chs[]=code.toCharArray();
long res=0L;
for(int i=0; i < chs.length; i++) {
int ind=0;
for(int j=0; j < binLen; j++) {
if(chs[i] == r[j]) {
ind=j;
break;
}
}
if(i > 0) {
res=res * binLen + ind;
} else {
res=ind;
}
// logger.debug(ind + "-->" + res);
}
res -= startNumber;
return res;
}
}
\ No newline at end of file
package cn.wisenergy.web.sms;
package cn.wisenergy.common.utils;
import cn.wisenergy.common.utils.StringUtil;
import cn.wisenergy.web.config.SmsConfig;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest;
......
package cn.wisenergy.mapper;
import cn.wisenergy.model.app.BankInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
/**
* @author 86187
*/
public interface BankInfoMapper extends BaseMapper<BankInfo> {
/**
* 添加银行卡信息
*
* @param bankInfo 银行卡信息
* @return 1
*/
int add(BankInfo bankInfo);
/**
* 编辑银行卡信息
*
* @param bankInfo 银行卡信息
* @return 1
*/
int edit(BankInfo bankInfo);
/**
* 删除银行卡信息
*
* @param id 银行卡id
* @return 1
*/
int delById(@Param("id") Integer id);
/**
* 通过用户id,获取用户银行卡信息
*
* @param userId 用户id
* @return 1
*/
BankInfo getByUserId(@Param("userId") String userId);
}
package cn.wisenergy.mapper;
import cn.wisenergy.model.app.AccountInfo;
import cn.wisenergy.model.app.LastMonthAccount;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
public interface LastAccountMapper extends BaseMapper<LastMonthAccount> {
/**
* 通过userId 和 yearMonth获取账户信息
*
* @param userId 用户id
* @param yearMonth 年月
* @return 账户信息
*/
LastMonthAccount getByUserIdAndTime(@Param("userId") String userId, @Param("yearMonth") String yearMonth);
}
......@@ -9,4 +9,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
public interface RecommendUserMapper extends BaseMapper<RecommendUser> {
RecommendUser getByUserId(String userId);
Integer zcByUserId(String userId);
}
package cn.wisenergy.mapper;
import cn.wisenergy.model.app.TradeRecord;
import cn.wisenergy.model.vo.AccumulatedIncomeVo;
import cn.wisenergy.model.vo.WithdrawalRecordVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
/**
......@@ -44,5 +47,21 @@ public interface TradeRecordMapper extends BaseMapper<TradeRecord> {
* @param userId 用户id
* @return 用户交易列表
*/
List<TradeRecord> getByUserIdAndTime(@Param("userId") String userId,@Param("yearMonth") String yearMonth);
List<TradeRecord> getByUserIdAndTime(@Param("userId") String userId,@Param("yearMonth") Date yearMonth);
/**
* 获取不包括本月的六个月的累计收益
* @param userId 用户id
* @return 累计收益
*/
List<AccumulatedIncomeVo> getSixMonthIncome(@Param("userId") String userId);
/**
* 根据用户id 或 年月 ,获取用户本月交易提现列表
* @param userId 用户id
* @param yearMonth 年月
* @return 交易列表
*/
List<WithdrawalRecordVo> getWithdrawalRecord(@Param("userId") String userId, Date yearMonth);
}
......@@ -53,7 +53,7 @@ public interface UsersMapper extends BaseMapper<User> {
* @param userId 用户id
* @return 用户信息
*/
User getByUserId(@Param("userId") String userId);
Integer getByUserId(@Param("userId") String userId);
/**
* 获取用户信息
......@@ -76,6 +76,17 @@ public interface UsersMapper extends BaseMapper<User> {
public List<User> getUsersListByMap(Map<String,Object> param);
//根据手机号查询用户Integer
Integer queryUsersByPhone(@Param("beInvitedCode")String userId);
Integer queryUsersByPhone(@Param("userId")String userId);
/**
* 用户注册
* @param userId
* @param inviteCode
* @param beInvitedCode
* @param userLevel
*/
Integer save(@Param("userId")String userId, @Param("inviteCode") String inviteCode, @Param("beInvitedCode") String beInvitedCode, @Param("userLevel") Integer userLevel);
Integer insertbyint(@Param("userId")String userId, @Param("beInvitedCode") String beInvitedCode);
Integer edit1(@Param("userId")String userId);
Integer getuserIdById(@Param("userId")String userId);
}
<?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.wisenergy.mapper.BankInfoMapper">
<resultMap id="bankMap" type="cn.wisenergy.model.app.BankInfo">
<id column="id" property="id"/>
<result column="user_id" property="userId"/>
<result column="name" property="name"/>
<result column="bank_name" property="bankName"/>
<result column="card_number" property="cardNumber"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
</resultMap>
<sql id="table">
bank_info
</sql>
<sql id="cols_all">
id,
<include refid="cols_exclude_id"/>
</sql>
<sql id="cols_exclude_id">
user_id,name,bank_name,card_number,create_time,update_time
</sql>
<sql id="vals">
#{userId},#{name},#{bankName},#{cardNumber},now(),now()
</sql>
<sql id="updateCondition">
<if test="userId != null">user_id = #{userId},</if>
<if test="name != null">name = #{name},</if>
<if test="bankName != null">bank_name =#{bankName},</if>
<if test="cardNumber != null">card_number =#{cardNumber},</if>
update_time =now()
</sql>
<sql id="criteria">
<if test="id != null">id = #{id}</if>
<if test="userId != null">and user_id = #{userId}</if>
<if test="name != null">and name = #{name}</if>
<if test="bankName != null">and bank_name =#{bankName}</if>
<if test="cardNumber != null">and card_number =#{cardNumber}</if>
<if test="createTime != null">and create_time &gt;= #{createTime}</if>
<if test="updateTime != null">and #{updateTime} &gt;= update_time</if>
</sql>
<insert id="add" parameterType="cn.wisenergy.model.app.BankInfo" keyProperty="id" useGeneratedKeys="true">
insert into
<include refid="table"/>
(<include refid="cols_exclude_id"/>)
value(
<include refid="vals"/>
)
</insert>
<update id="edit" parameterType="cn.wisenergy.model.app.BankInfo">
UPDATE
<include refid="table"/>
<set>
<include refid="updateCondition"/>
</set>
<where>
id = #{id}
</where>
</update>
<delete id="delById" parameterType="java.lang.Integer">
delete from
<include refid="table"/>
where id = #{id}
</delete>
<select id="getByUserId" resultType="cn.wisenergy.model.app.BankInfo">
select
<include refid="cols_all"/>
from
<include refid="table"/>
<where>
user_id=#{userId}
</where>
</select>
</mapper>
\ No newline at end of file
<?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.wisenergy.mapper.LastAccountMapper">
<resultMap id="AccountMap" type="cn.wisenergy.model.app.LastMonthAccount">
<id column="id" property="id"/>
<result column="user_id" property="userId"/>
<result column="user_level" property="userLevel"/>
<result column="year_month" property="yearMonth"/>
<result column="extract_money" property="extractMoney"/>
<result column="earnings_month" property="earningsMonth"/>
<result column="frozen_money" property="frozenMoney"/>
<result column="earnings_total" property="earningsTotal"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
</resultMap>
<sql id="table">
last_month_account_info
</sql>
<sql id="cols_all">
id,
<include refid="cols_exclude_id"/>
</sql>
<sql id="cols_exclude_id">
user_id,user_level,year_month,extract_money,earnings_month,frozen_money,earnings_total,create_time,update_time
</sql>
<sql id="vals">
#{userId},#{userLevel},#{yearMonth},#{extractMoney},#{earningsMonth},#{frozenMoney},
#{earningsTotal},now(),now()
</sql>
<sql id="updateCondition">
<if test="userId != null">user_id = #{userId},</if>
<if test="userLevel != null">user_level = #{userLevel},</if>
<if test="yearMonth != null">year_month =#{yearMonth},</if>
<if test="extractMoney != null">extract_money =#{extractMoney},</if>
<if test="earningsMonth != null">earnings_month =#{earningsMonth},</if>
<if test="frozenMoney != null">frozen_money =#{frozenMoney},</if>
<if test="earningsTotal != null">earnings_total =#{earningsTotal},</if>
update_time =now()
</sql>
<sql id="criteria">
<if test="id != null">id = #{id}</if>
<if test="userId != null">and user_id = #{userId}</if>
<if test="userLevel != null">and user_level = #{userLevel}</if>
<if test="yearMonth != null">and year_month =#{yearMonth}</if>
<if test="extractMoney != null">and extract_money =#{extractMoney}</if>
<if test="earningsMonth != null">and earnings_month =#{earningsMonth}</if>
<if test="frozenMoney != null">and frozen_money =#{frozenMoney}</if>
<if test="earningsTotal != null">and earnings_total =#{earningsTotal}</if>
<if test="createTime != null">and create_time &gt;= #{createTime}</if>
<if test="updateTime != null">and #{updateTime} &gt;= update_time</if>
</sql>
<select id="getByUserIdAndTime" resultType="cn.wisenergy.model.app.LastMonthAccount">
select
<include refid="cols_all"/>
from
<include refid="table"/>
<where>
user_id=#{userId}
and year_month=#{yearMonth}
</where>
</select>
</mapper>
\ No newline at end of file
......@@ -71,5 +71,15 @@
user_id=#{userId}
</where>
</select>
<!--根据用户邀请码更新直推表-->
<select id="zcByUserId" >
select
id
from
<include refid="table"/>
<where>
user_id=#{userId}
</where>
</select>
</mapper>
\ No newline at end of file
......@@ -8,6 +8,8 @@
<result column="trade_no" property="tradeNo"/>
<result column="status" property="status"/>
<result column="task_id" property="taskId"/>
<result column="money" property="money"/>
<result column="card_number" property="cardNumber"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
</resultMap>
......@@ -22,11 +24,11 @@
</sql>
<sql id="cols_exclude_id">
user_id,trade_type,trade_no,status,task_id,create_time,update_time
user_id,trade_type,trade_no,status,task_id,money,card_number,create_time,update_time
</sql>
<sql id="vals">
#{userId},#{tradeType},#{tradeNo},#{status},#{taskId}, now(),now()
#{userId},#{tradeType},#{tradeNo},#{status},#{taskId},#{money},#{cardNumber},now(),now()
</sql>
<sql id="updateCondition">
......@@ -35,6 +37,8 @@
<if test="tradeNo != null">trade_no =#{tradeNo},</if>
<if test="status != null">status =#{status},</if>
<if test="taskId != null">task_id =#{taskId},</if>
<if test="money != null">money =#{money},</if>
<if test="cardNumber != null">card_number =#{cardNumber},</if>
update_time =now()
</sql>
......@@ -45,6 +49,8 @@
<if test="tradeNo != null">and trade_no =#{tradeNo}</if>
<if test="status != null">and status =#{status}</if>
<if test="taskId != null">and task_id =#{taskId}</if>
<if test="money != null">and money =#{money}</if>
<if test="cardNumber != null">and card_number =#{cardNumber}</if>
<if test="createTime != null">and create_time &gt;= #{createTime}</if>
<if test="updateTime != null">and #{updateTime} &gt;= update_time</if>
</sql>
......@@ -90,8 +96,42 @@
from
<include refid="table"/>
<where>
<if test="userId">
user_id=#{userId}
and year_time=#{yearTime}
</if>
<if test="yearMonth != null">
AND(
YEAR(year_month) = YEAR(#{yearMonth})
AND MONTH(year_month) = MONTH(#{yearMonth}))
</if>
</where>
</select>
<select id="getSixMonthIncome" resultType="cn.wisenergy.model.vo.AccumulatedIncomeVo">
SELECT user_id as userId,sum(money) as income ,
date_format(create_time,'%Y-%m') as yearMonth
FROM
<include refid="table"/>
WHERE date_format(create_time,'%Y-%m') &lt; date_format(now(),'%Y-%m')
and date_format(create_time,'%Y-%m') >= date_format(now() - interval 7 month,'%Y-%m')
and (status=1 or status=3)
group by user_id ,create_time desc;
</select>
<select id="getWithdrawalRecord" resultType="cn.wisenergy.model.vo.WithdrawalRecordVo">
select user_id as userId, status as status, money as money, update_time as moneyTime
from
<include refid="table"/>
<where>
(status=2 or status=3)
<if test="userId">
and user_id=#{userId}
</if>
<if test="yearMonth != null">
AND(
YEAR(update_time) = YEAR(#{yearMonth})
AND MONTH(update_time) = MONTH(#{yearMonth}))
</if>
</where>
</select>
......
......@@ -145,9 +145,12 @@
</where>
</select>
<!--用户添加-->
<!--用户注册-->
<insert id="save">
insert into user(user_id,password) value (#{userId},#{password})
insert into user(user_id,invite_code,be_invited_code,user_level) value (#{userId},#{inviteCode},#{beInvitedCode},#{userLevel})
</insert>
<insert id="insertbyint">
insert into user(user_id,be_invited_code) value (#{userId},#{beInvitedCode})
</insert>
<select id="queryUsersByPhone" resultType="java.lang.Integer">
......@@ -159,6 +162,27 @@
user_id=#{userId}
</where>
</select>
<select id="getuserIdById" resultType="cn.wisenergy.model.app.User">
select
id
from
<include refid="table"/>
<where>
user_id=#{userId}
</where>
</select>
<update id="edit1" parameterType="cn.wisenergy.model.app.User">
UPDATE
<include refid="table"/>
<set>
<if test="userLevel != null">user_level =#{userLevel},</if>
<if test="inviteCode != null">invite_code =#{inviteCode},</if>
update_time =now()
</set>
<where>
user_id = #{userId}
</where>
</update>
<!--分页查询所有用户信息 -->
<select id="getUsersListByMap" resultType="cn.wisenergy.model.app.User" parameterType="java.util.Map">
......
package cn.wisenergy.model.app;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @author 86187
* @ Description: 银行卡信息实体类
* @ Author : 86187
* @ Date : 2021/3/3 15:55
*/
@Data
@ApiModel("BankInfo")
public class BankInfo {
/**
* 主键id
*/
@ApiModelProperty(value = "主键id", name = "id")
private Integer id;
/**
* 用户id
*/
@ApiModelProperty(value = "用户id", name = "userId")
private String userId;
/**
* 姓名
*/
@ApiModelProperty(value = "姓名", name = "name")
private String name;
/**
* 银行卡名称
*/
@ApiModelProperty(value = "银行卡名称", name = "bankName")
private String bankName;
/**
* 银行卡卡号
*/
@ApiModelProperty(value = "银行卡卡号", name = "cardNumber")
private String cardNumber;
/**
* 创建时间
*/
@ApiModelProperty(value = "创建时间", name = "createTime")
private Date createTime;
/**
* 更新时间
*/
@ApiModelProperty(value = "更新时间", name = "updateTime")
private Date updateTime;
}
package cn.wisenergy.model.app;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
*@ Description: 上月账户实体类
*@ Author : 86187
*@ Date : 2021/3/3 11:24
* @author 86187
*/
@Data
@ApiModel
public class LastMonthAccount implements Serializable {
/**
* 账户主键id
*/
@ApiModelProperty(name = "id", value = "管理员主键id")
private Integer id;
/**
* 用户id
*/
@ApiModelProperty(name = "userId", value = "用户id")
private String userId;
/**
* 用户等级
*/
@ApiModelProperty(name = "userLevel", value = "用户等级")
private Integer userLevel;
/**
* 年月
*/
@ApiModelProperty(name = "yearMonth", value = "年月")
private String yearMonth;
/**
* 可提现金额
*/
@ApiModelProperty(name = "extractMoney", value = "可提现金额")
private BigDecimal extractMoney;
/**
* 本月收益
*/
@ApiModelProperty(name = "earningsMonth", value = "本月收益")
private BigDecimal earningsMonth;
/**
* 冻结金额
*/
@ApiModelProperty(name = "frozenMoney", value = "冻结金额")
private BigDecimal frozenMoney;
/**
* 累计收益
*/
@ApiModelProperty(name = "earningsTotal", value = "累计收益")
private BigDecimal earningsTotal;
/**
* 创建时间
*/
@ApiModelProperty(name = "createTime", value = "创建时间")
private Date createTime;
/**
* 修改时间
*/
@ApiModelProperty(name = "updateTime", value = "修改时间")
private Date updateTime;
}
......@@ -44,7 +44,7 @@ public class Page<T> implements Serializable {
this.list = list;
}
public Page(int pageNo, int pageSize, Integer total) {
public Page(int pageNo, int pageSize,Integer total) {
pageNo = (pageNo==0 )? DEFAULT_PAGE_NO : pageNo;
pageSize = (pageSize==0 )?DEFAULT_PAGE_SIZE : pageSize;
this.beginPos=(pageNo-1)*pageSize;
......
package cn.wisenergy.model.app;
import java.io.Serializable;
import java.util.Date;
import java.math.BigDecimal;
/***
* 短信记录
*/
public class SmsLog implements Serializable {
/**
* 短信记录
* Created by m1991 on 2021/2/28 22:56
*/
public class SmsLog {
//
private Long id;
//短信类型(0:注册、登录验证码,1:修改密码,2:订单状态通知信息)
......@@ -30,70 +30,91 @@ public class SmsLog implements Serializable {
//是否删除(0:否,1:是)
private Integer isDelete;
//get set 方法
public void setId (Long id){
this.id=id;
public Long getId() {
return id;
}
public Long getId(){
return this.id;
public void setId(Long id) {
this.id = id;
}
public void setCodeType (Integer codeType){
this.codeType=codeType;
public Integer getCodeType() {
return codeType;
}
public Integer getCodeType(){
return this.codeType;
public void setCodeType(Integer codeType) {
this.codeType = codeType;
}
public void setPhone (String phone){
this.phone=phone;
public String getPhone() {
return phone;
}
public String getPhone(){
return this.phone;
public void setPhone(String phone) {
this.phone = phone;
}
public void setMessage (String message){
this.message=message;
public String getMessage() {
return message;
}
public String getMessage(){
return this.message;
public void setMessage(String message) {
this.message = message;
}
public void setFailInfo (String failInfo){
this.failInfo=failInfo;
public String getFailInfo() {
return failInfo;
}
public String getFailInfo(){
return this.failInfo;
public void setFailInfo(String failInfo) {
this.failInfo = failInfo;
}
public void setStatus (Integer status){
this.status=status;
public Integer getStatus() {
return status;
}
public Integer getStatus(){
return this.status;
public void setStatus(Integer status) {
this.status = status;
}
public void setCreatedUserId (Long createdUserId){
this.createdUserId=createdUserId;
public Long getCreatedUserId() {
return createdUserId;
}
public Long getCreatedUserId(){
return this.createdUserId;
public void setCreatedUserId(Long createdUserId) {
this.createdUserId = createdUserId;
}
public void setUpdatedUserId (Long updatedUserId){
this.updatedUserId=updatedUserId;
public Long getUpdatedUserId() {
return updatedUserId;
}
public Long getUpdatedUserId(){
return this.updatedUserId;
public void setUpdatedUserId(Long updatedUserId) {
this.updatedUserId = updatedUserId;
}
public void setCreatdTime (Date creatdTime){
this.creatdTime=creatdTime;
public Date getCreatdTime() {
return creatdTime;
}
public Date getCreatdTime(){
return this.creatdTime;
public void setCreatdTime(Date creatdTime) {
this.creatdTime = creatdTime;
}
public void setUpdatedTime (Date updatedTime){
this.updatedTime=updatedTime;
public Date getUpdatedTime() {
return updatedTime;
}
public Date getUpdatedTime(){
return this.updatedTime;
public void setUpdatedTime(Date updatedTime) {
this.updatedTime = updatedTime;
}
public void setIsDelete (Integer isDelete){
this.isDelete=isDelete;
public Integer getIsDelete() {
return isDelete;
}
public Integer getIsDelete(){
return this.isDelete;
public void setIsDelete(Integer isDelete) {
this.isDelete = isDelete;
}
}
......@@ -61,6 +61,12 @@ public class TradeRecord implements Serializable {
@ApiModelProperty(name = "money", value = "金额")
private BigDecimal money;
/**
* 银行卡卡号
*/
@ApiModelProperty(name = "cardNumber", value = "银行卡卡号")
private String cardNumber;
/**
* 创建时间
*/
......
......@@ -105,4 +105,99 @@ public class User extends Model<User> implements Serializable{
@ApiModelProperty(name = "updateTime", value = "修改时间")
private Date updateTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public int getUserLevel() {
return userLevel;
}
public void setUserLevel(int userLevel) {
this.userLevel = userLevel;
}
public BigDecimal getCrossBorderLine() {
return crossBorderLine;
}
public void setCrossBorderLine(BigDecimal crossBorderLine) {
this.crossBorderLine = crossBorderLine;
}
public String getIdCardNumber() {
return idCardNumber;
}
public void setIdCardNumber(String idCardNumber) {
this.idCardNumber = idCardNumber;
}
public String getFansNickname() {
return fansNickname;
}
public void setFansNickname(String fansNickname) {
this.fansNickname = fansNickname;
}
public String getFansId() {
return fansId;
}
public void setFansId(String fansId) {
this.fansId = fansId;
}
public String getInviteCode() {
return inviteCode;
}
public void setInviteCode(String inviteCode) {
this.inviteCode = inviteCode;
}
public String getBeInvitedCode() {
return beInvitedCode;
}
public void setBeInvitedCode(String beInvitedCode) {
this.beInvitedCode = beInvitedCode;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
}
......@@ -25,14 +25,21 @@ public class WithdrawalAmountVo {
/**
* 上月未提
*/
@ApiModelProperty(value = "上月未提",name = "lastMoneyNot")
@ApiModelProperty(value = "上月未提", name = "lastMoneyNot")
private BigDecimal lastMoneyNot;
/**
* 本月可提现
*/
@ApiModelProperty(value = "本月可提现",name = "currentMoneyCan")
@ApiModelProperty(value = "本月可提现", name = "currentMoneyCan")
private BigDecimal currentMoneyCan;
/**
* 提现规则
*/
@ApiModelProperty(value = "提现规则", name = "withdrawRule")
private String withdrawRule;
}
package cn.wisenergy.model.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
/**
*@ Description: 提现记录Vo
*@ Author : 86187
*@ Date : 2021/3/3 14:51
* @author 86187
*/
@Data
@ApiModel("WithdrawalRecordVo")
public class WithdrawalRecordVo {
/**
* 用户id
*/
@ApiModelProperty(value = "用户id",name = "userId")
private String userId;
/**
* 提现状态 2:银行处理中 3 :提现成功
*/
@ApiModelProperty(value = "提现状态 2:银行处理中 3 :提现成功",name = "status")
private Integer status;
/**
* 提现金额
*/
@ApiModelProperty(value = "提现金额",name = "money")
private BigDecimal money;
/**
* 提现时间
*/
@ApiModelProperty(value = "提现时间",name = "moneyTime")
private Date moneyTime;
}
......@@ -69,28 +69,6 @@
<artifactId>itext-asian</artifactId>
<version>5.2.0</version>
</dependency>
<!--有赞SDK-->
<dependency>
<groupId>com.youzan.cloud</groupId>
<artifactId>open-sdk-core</artifactId>
<version>1.0.7-RELEASE</version>
</dependency>
<dependency>
<groupId>com.youzan.cloud</groupId>
<artifactId>open-sdk-gen</artifactId>
<version>1.0.7.78771202102051104-RELEASE</version>
</dependency>
<dependency>
<groupId>com.youzan.cloud</groupId>
<artifactId>open-sdk-api</artifactId>
<version>1.0.7-RELEASE</version>
</dependency>
<dependency>
<groupId>com.youzan.cloud</groupId>
<artifactId>open-sdk-common</artifactId>
<version>1.0.7-RELEASE</version>
</dependency>
</dependencies>
<!-- MAVEN构建 -->
......
package cn.wisenergy.service.app;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.app.BankInfo;
/**
* @author 86187
*/
public interface BankService {
/**
* 保存银行卡信息
*
* @param bankInfo 银行卡信息
* @return 银行卡信息
*/
R<BankInfo> add(BankInfo bankInfo);
/**
* 编辑银行卡信息
*
* @param bankInfo 银行卡信息
* @return 银行卡信息
*/
R<BankInfo> edit(BankInfo bankInfo);
/**
* 获取银行卡信息
*
* @param userId 用户id
* @return 银行卡信息
*/
R<BankInfo> getByUserId(String userId);
/**
* 银行卡提现发送验证码
*
* @param userId 用户主键id
* @return true 成功 false 失败
*/
R<Boolean> bankWithdrawSendSms(String userId);
/**
* 用户提现到银行卡
*
* @param userId 用户标识
* @return true 成功 false 失败
*/
R<Boolean> userWithdrawBank(String userId);
}
......@@ -3,8 +3,6 @@ package cn.wisenergy.service.app;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.app.User;
import java.util.List;
/**
* @ Description: 用户接口
* @ Author : 86187
......@@ -19,16 +17,27 @@ public interface UserService {
* @param userId 用户id
* @return 用户信息
*/
R<User> getById(String userId);
R<Integer> getById(String userId);
/**
* 获取用户信息
* @param userId 用户id
* @return 用户信息
*/
User getByUserId(String userId);
Integer getByUserId(String userId);
//根据手机号查询用户
public User queryUsersByPhone(String id);
//根据OpenId查询用户
public User queryUsersByOpenId(String openId);
/**
*用户注册
*/
Integer userByZx(String userId, String beInvitedCode);
// Integer selectbyint(String userId,String beInvitedCode);
//
// Integer getuserIdById(String userId);
}
package cn.wisenergy.service.app;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.vo.AccumulatedIncomeVo;
import cn.wisenergy.model.vo.MoneyPackageDetailVo;
import cn.wisenergy.model.vo.MoneyPackageVo;
import cn.wisenergy.model.vo.WithdrawalAmountVo;
import cn.wisenergy.model.vo.*;
import java.util.List;
......@@ -46,4 +43,15 @@ public interface WalletService {
* @return 当月总收益
*/
R<MoneyPackageDetailVo> queryIncomeDetail(String userId);
/**
* 获取提现记录 userId 为空 查全部 不为空,查当前用户
*
* @param userId 用户唯一标识
* @param yearMonth 年月
* @return 提现记录列表
*/
R<List<WithdrawalRecordVo>> getWithdrawalRecord(String userId, String yearMonth);
}
package cn.wisenergy.service.app.impl;
import cn.wisenergy.common.utils.*;
import cn.wisenergy.mapper.BankInfoMapper;
import cn.wisenergy.mapper.UsersMapper;
import cn.wisenergy.model.app.BankInfo;
import cn.wisenergy.model.app.User;
import cn.wisenergy.service.app.BankService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @author 86187
* @ Description: 银行卡相关接口实现
* @ Author : 86187
* @ Date : 2021/3/3 16:28
*/
@Service
@Slf4j
public class BankServiceImpl extends ServiceImpl<BankInfoMapper, BankInfo> implements BankService {
@Autowired
private BankInfoMapper bankInfoMapper;
@Autowired
private UsersMapper usersMapper;
@Autowired
private SmsUtils smsUtils;
@Autowired
private RedisUtils redisUtils;
@Override
public R<BankInfo> add(BankInfo bankInfo) {
log.info("shop-mall[]BankServiceImpl[]add[]input.param.bankInfo:" + bankInfo);
if (null == bankInfo) {
return R.error("入参不能为空!");
}
int count = bankInfoMapper.add(bankInfo);
if (count == 0) {
return R.error("保存用户银行卡信息失败!");
}
return R.ok(bankInfo);
}
@Override
public R<BankInfo> edit(BankInfo bankInfo) {
log.info("shop-mall[]BankServiceImpl[]edit[]input.param.bankInfo:" + bankInfo);
if (null == bankInfo) {
return R.error("入参不能为空!");
}
//获取用户银行卡信息
BankInfo old = bankInfoMapper.selectById(bankInfo.getId());
if (null == old) {
return R.error("用户银行卡信息不存在!");
}
old.setBankName(bankInfo.getBankName());
old.setCardNumber(bankInfo.getCardNumber());
old.setName(bankInfo.getName());
//编辑
int count = bankInfoMapper.edit(old);
if (count == 0) {
return R.error("编辑用户银行卡信息失败!");
}
return R.ok(old);
}
@Override
public R<BankInfo> getByUserId(String userId) {
log.info("shop-mall[]BankServiceImpl[]getByUserId[]input.param.userId:" + userId);
if (StringUtils.isBlank(userId)) {
return R.error("入参不能为空!");
}
BankInfo bankInfo = bankInfoMapper.getByUserId(userId);
return R.ok(bankInfo);
}
@Override
public R<Boolean> bankWithdrawSendSms(String userId) {
log.info("shop-mall[]BankServiceImpl[]edit[]input.param.userId:" + userId);
if (StringUtils.isBlank(userId)) {
return R.error("入参不能为空!");
}
//1、获取用户信息
User user = usersMapper.selectById(userId);
if (null == user) {
return R.error("用户信息不存在!");
}
//2、调用发送短信验证码接口
String templateCode = "";
String code = MathUtils.random();
boolean bool = smsUtils.sendMessage(user.getUserId(), templateCode, code);
if (!bool) {
return R.error("验证码发送失败,请重发!");
}
//缓存code到redis
String phone = user.getUserId();
String key = StringUtil.formatKeyWithPrefix(Constants.RedisKey.BANK_PRIFIX, Constants.RedisKey.SMS_PRIFIX, phone, code + "");
boolean cache = redisUtils.set(key, code, Constants.Duration.MINUTE_INT);
if (!cache) {
return R.error("缓存验证码失败!");
}
return R.ok(0, true);
}
@Override
public R<Boolean> userWithdrawBank(String userId) {
return null;
}
}
package cn.wisenergy.service.app.impl;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.common.utils.ShareCodeUtil;
import cn.wisenergy.mapper.RecommendUserMapper;
import cn.wisenergy.mapper.UsersMapper;
import cn.wisenergy.model.app.User;
import cn.wisenergy.service.app.UserService;
......@@ -10,6 +12,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.xml.transform.Result;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -27,14 +31,18 @@ public class UserServiceImpl extends ServiceImpl<UsersMapper, User> implements U
@Autowired
private UsersMapper usersMapper;
//直推表
@Autowired
private RecommendUserMapper recommendUserMapper;
@Override
public R<User> getById(String userId) {
public R<Integer> getById(String userId) {
return R.ok(usersMapper.getByUserId(userId));
}
@Override
public User getByUserId(String userId) {
public Integer getByUserId(String userId) {
return usersMapper.getByUserId(userId);
}
......@@ -51,4 +59,41 @@ public class UserServiceImpl extends ServiceImpl<UsersMapper, User> implements U
return null;
}
@Override
public User queryUsersByOpenId(String id) {
return null;
}
@Override
public Integer userByZx(String userId, String beInvitedCode) {
/**
* 判断用户等级是否为空,空的话填写0
*/
if(null==beInvitedCode || ""==beInvitedCode){
beInvitedCode= String.valueOf(1);
}
// 插入用户手机号与推荐人邀请码
usersMapper.insertbyint(userId,beInvitedCode);
//根据插入的用户手机号,查询用户唯一ID
Integer yqm=usersMapper.getByUserId(userId);
//用户唯一ID调用生成6位邀请码
String inviteCode= ShareCodeUtil.idToCode(yqm);
//根据用户手机号,更新用户信息
User user = new User();
user.setInviteCode(inviteCode);
user.setUserLevel(0);
usersMapper.updateById(user);
//插入直推用户表
//插入用户团队表
//根据邀请码查询推荐人的普通用户字段+1
Integer a=recommendUserMapper.zcByUserId(userId);
if(null!=a && 0 != a){
}
//根据邀请码递归所有团队成员普通用户+1
}
}
......@@ -3,8 +3,10 @@ package cn.wisenergy.service.app.impl;
import cn.wisenergy.common.utils.DateUtil;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.mapper.AccountMapper;
import cn.wisenergy.mapper.LastAccountMapper;
import cn.wisenergy.mapper.TradeRecordMapper;
import cn.wisenergy.model.app.AccountInfo;
import cn.wisenergy.model.app.LastMonthAccount;
import cn.wisenergy.model.app.TradeRecord;
import cn.wisenergy.model.enums.TradeRecordEnum;
import cn.wisenergy.model.vo.*;
......@@ -18,6 +20,7 @@ import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
......@@ -35,6 +38,9 @@ public class WalletServiceImpl implements WalletService {
@Autowired
private TradeRecordMapper tradeRecordMapper;
@Autowired
private LastAccountMapper lastAccountMapper;
@Override
public R<MoneyPackageVo> getMoneyPackage(String userId) {
......@@ -70,17 +76,29 @@ public class WalletServiceImpl implements WalletService {
Date date = new Date();
String yearMonth = DateUtil.convertDateToStr(date, PATTERN);
WithdrawalAmountVo withdrawalAmountVo = new WithdrawalAmountVo();
withdrawalAmountVo.setUserId(userId);
//1、获取用户账户信息
AccountInfo accountInfo = accountMapper.getByUserIdAndTime(userId, yearMonth);
if (null == accountInfo) {
return R.error("用户账户信息不存在!");
withdrawalAmountVo.setCurrentMoneyCan(new BigDecimal(0));
} else {
withdrawalAmountVo.setCurrentMoneyCan(accountInfo.getExtractMoney());
}
WithdrawalAmountVo withdrawalAmountVo = new WithdrawalAmountVo();
withdrawalAmountVo.setUserId(userId);
withdrawalAmountVo.setCurrentMoneyCan(accountInfo.getExtractMoney());
//TODO 获取上月为提现
//2、 获取上月未提现
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.MONTH, -1);
Date lastDate = cal.getTime();
String lastMonthTime = DateUtil.convertDateToStr(lastDate, PATTERN);
LastMonthAccount lastMonthAccount = lastAccountMapper.getByUserIdAndTime(userId, lastMonthTime);
if (null == lastMonthAccount) {
withdrawalAmountVo.setLastMoneyNot(new BigDecimal(0));
} else {
withdrawalAmountVo.setLastMoneyNot(lastMonthAccount.getExtractMoney());
}
return R.ok(withdrawalAmountVo);
}
......@@ -91,22 +109,9 @@ public class WalletServiceImpl implements WalletService {
return R.error("入参为空!");
}
List<TradeRecord> list = tradeRecordMapper.getByUserId(userId);
if (CollectionUtils.isEmpty(list)) {
return R.ok(new ArrayList<>());
}
List<AccumulatedIncomeVo> result = new ArrayList<>();
for (TradeRecord tradeRecord : list) {
AccumulatedIncomeVo incomeVo = new AccumulatedIncomeVo();
incomeVo.setUserId(tradeRecord.getUserId());
String yearMonth = DateUtil.convertDateToStr(tradeRecord.getCreateTime(), PATTERN);
incomeVo.setYearMonth(yearMonth);
incomeVo.setIncome(tradeRecord.getMoney());
result.add(incomeVo);
}
return R.ok(result);
//获取不包括本月在内的六个月的收益
List<AccumulatedIncomeVo> list = tradeRecordMapper.getSixMonthIncome(userId);
return R.ok(list);
}
@Override
......@@ -125,7 +130,7 @@ public class WalletServiceImpl implements WalletService {
}
//获取本月交易记录
List<TradeRecord> list = tradeRecordMapper.getByUserIdAndTime(userId, yearMonth);
List<TradeRecord> list = tradeRecordMapper.getByUserIdAndTime(userId, date);
if (CollectionUtils.isEmpty(list)) {
return R.ok(new MoneyPackageDetailVo());
}
......@@ -149,4 +154,16 @@ public class WalletServiceImpl implements WalletService {
return R.ok(detailVo);
}
@Override
public R<List<WithdrawalRecordVo>> getWithdrawalRecord(String userId, String yearMonth) {
log.info("shop-mall[]WalletServiceImpl[]queryIncomeDetail[]input.param.yearMonth:" + yearMonth);
if (StringUtils.isBlank(yearMonth)) {
return R.error("入参为空!");
}
Date date = DateUtil.convertStrToDate(yearMonth, PATTERN);
List<WithdrawalRecordVo> list = tradeRecordMapper.getWithdrawalRecord(userId, date);
return R.ok(list);
}
}
package cn.wisenergy.service.cache;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.nio.charset.Charset;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@Slf4j
@Component
public class RedisService {
public static final String PREFIX = "sales_activity";
protected static final long DEFAULT_EXPIRE = 10 * 24 * 60 * 60L;
@Resource(name = "redisTemplate")
private RedisTemplate redisTemplate;
private static RedisTemplate<String, Object> template = null;
/**
* 生成key
*
* @param keys
* @return
*/
public String buildKey(Object... keys) {
StringBuilder sb = new StringBuilder();
if (keys.length == 1) {
sb.append(keys);
return sb.toString();
}
for (Object key : keys) {
sb.append(key).append(":");
}
if (sb.length() > 1) {
sb.deleteCharAt(sb.length() - 1);
}
return sb.toString();
}
/**
* 指定缓存失效时间
*
* @param key 键
* @param time 时间(秒)
* @return
*/
public boolean expire(String key, long time) {
try {
if (time > 0) {
getRedisTemplate().expire(key, time, TimeUnit.SECONDS);
}
return true;
} catch (Exception e) {
log.error(e.getMessage(), e);
return false;
}
}
/**
* 根据key 获取过期时间
*
* @param key 键 不能为null
* @return 时间(秒) 返回0代表为永久有效
*/
public long getExpire(String key) {
return getRedisTemplate().getExpire(key, TimeUnit.SECONDS);
}
/**
* 判断key是否存在
*
* @param key 键
* @return true 存在 false不存在
*/
public boolean hasKey(String key) {
try {
return getRedisTemplate().hasKey(key);
} catch (Exception e) {
log.error(e.getMessage(), e);
return false;
}
}
/**
* 删除缓存
*
* @param key 可以传一个值 或多个
*/
public void del(String... key) {
if (key != null && key.length > 0) {
if (key.length == 1) {
getRedisTemplate().delete(key[0]);
} else {
getRedisTemplate().delete(CollectionUtils.arrayToList(key));
}
}
}
// ============================String=============================
/**
* 普通缓存获取
*
* @param key 键
* @return 值
*/
public Object get(String key) {
return key == null ? null : getRedisTemplate().opsForValue().get(key);
}
/**
* 普通缓存放入
*
* @param key 键
* @param value 值
* @return true成功 false失败
*/
public boolean set(String key, Object value) {
try {
getRedisTemplate().opsForValue().set(key, value);
return true;
} catch (Exception e) {
log.error(e.getMessage(), e);
return false;
}
}
/**
* 模糊查询
*
* @param activityCode 查询语句
* @return 查询结果
*/
public Set keys(String activityCode) {
try {
StringBuilder sb = new StringBuilder(10);
sb.append(PREFIX).append(":")
.append(activityCode)
.append(":")
.append("*");
return getRedisTemplate().keys(sb.toString());
} catch (Exception e) {
log.error(e.getMessage(), e);
return null;
}
}
/**
* 普通缓存放入并设置时间
*
* @param key 键
* @param value 值
* @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期
* @return true成功 false 失败
*/
public boolean set(String key, Object value, long time) {
try {
if (time > 0) {
getRedisTemplate().opsForValue().set(key, value, time, TimeUnit.SECONDS);
} else {
set(key, value);
}
return true;
} catch (Exception e) {
log.error(e.getMessage(), e);
return false;
}
}
/**
* 递增
*
* @param key 键
* @param delta 要增加几(大于0)
* @return
*/
public long incr(String key, long delta) {
if (delta < 0) {
throw new RuntimeException("递增因子必须大于0");
}
return getRedisTemplate().opsForValue().increment(key, delta);
}
/**
* 递减
*
* @param key 键
* @param delta 要减少几(小于0)
* @return
*/
public long decr(String key, long delta) {
if (delta < 0) {
throw new RuntimeException("递减因子必须大于0");
}
return getRedisTemplate().opsForValue().increment(key, -delta);
}
// ================================Map=================================
/**
* HashGet
*
* @param key 键 不能为null
* @param item 项 不能为null
* @return 值
*/
public Object hget(String key, String item) {
return getRedisTemplate().opsForHash().get(key, item);
}
/**
* 获取hashKey对应的所有键值
*
* @param key 键
* @return 对应的多个键值
*/
public Map<Object, Object> hmget(String key) {
return getRedisTemplate().opsForHash().entries(key);
}
/**
* HashSet
*
* @param key 键
* @param map 对应多个键值
* @return true 成功 false 失败
*/
public boolean hmset(String key, Map<String, Object> map) {
try {
getRedisTemplate().opsForHash().putAll(key, map);
return true;
} catch (Exception e) {
log.error(e.getMessage(), e);
return false;
}
}
/**
* HashSet 并设置时间
*
* @param key 键
* @param map 对应多个键值
* @param time 时间(秒)
* @return true成功 false失败
*/
public boolean hmset(String key, Map<String, Object> map, long time) {
try {
getRedisTemplate().opsForHash().putAll(key, map);
if (time > 0) {
expire(key, time);
}
return true;
} catch (Exception e) {
log.error(e.getMessage(), e);
return false;
}
}
/**
* 向一张hash表中放入数据,如果不存在将创建
*
* @param key 键
* @param item 项
* @param value 值
* @return true 成功 false失败
*/
public boolean hset(String key, String item, Object value) {
try {
getRedisTemplate().opsForHash().put(key, item, value);
return true;
} catch (Exception e) {
log.error(e.getMessage(), e);
return false;
}
}
/**
* 向一张hash表中放入数据,如果不存在将创建
*
* @param key 键
* @param item 项
* @param value 值
* @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间
* @return true 成功 false失败
*/
public boolean hset(String key, String item, Object value, long time) {
try {
getRedisTemplate().opsForHash().put(key, item, value);
if (time > 0) {
expire(key, time);
}
return true;
} catch (Exception e) {
log.error(e.getMessage(), e);
return false;
}
}
/**
* 删除hash表中的值
*
* @param key 键 不能为null
* @param item 项 可以使多个 不能为null
*/
public void hdel(String key, Object... item) {
getRedisTemplate().opsForHash().delete(key, item);
}
/**
* 判断hash表中是否有该项的值
*
* @param key 键 不能为null
* @param item 项 不能为null
* @return true 存在 false不存在
*/
public boolean hHasKey(String key, String item) {
return getRedisTemplate().opsForHash().hasKey(key, item);
}
/**
* hash递增 如果不存在,就会创建一个 并把新增后的值返回
*
* @param key 键
* @param item 项
* @param by 要增加几(大于0)
* @return
*/
public double hincr(String key, String item, double by) {
return getRedisTemplate().opsForHash().increment(key, item, by);
}
/**
* hash递减
*
* @param key 键
* @param item 项
* @param by 要减少记(小于0)
* @return
*/
public double hdecr(String key, String item, double by) {
return getRedisTemplate().opsForHash().increment(key, item, -by);
}
// ============================set=============================
/**
* 根据key获取Set中的所有值
*
* @param key 键
* @return
*/
public Set<Object> sGet(String key) {
try {
return getRedisTemplate().opsForSet().members(key);
} catch (Exception e) {
log.error(e.getMessage(), e);
return null;
}
}
/**
* 根据value从一个set中查询,是否存在
*
* @param key 键
* @param value 值
* @return true 存在 false不存在
*/
public boolean sHasKey(String key, Object value) {
try {
return getRedisTemplate().opsForSet().isMember(key, value);
} catch (Exception e) {
log.error(e.getMessage(), e);
return false;
}
}
/**
* 将数据放入set缓存
*
* @param key 键
* @param values 值 可以是多个
* @return 成功个数
*/
public long sSet(String key, Object... values) {
try {
return getRedisTemplate().opsForSet().add(key, values);
} catch (Exception e) {
log.error(e.getMessage(), e);
return 0;
}
}
/**
* 将set数据放入缓存
*
* @param key 键
* @param time 时间(秒)
* @param values 值 可以是多个
* @return 成功个数
*/
public long sSetAndTime(String key, long time, Object... values) {
try {
Long count = getRedisTemplate().opsForSet().add(key, values);
if (time > 0)
expire(key, time);
return count;
} catch (Exception e) {
log.error(e.getMessage(), e);
return 0;
}
}
/**
* 获取set缓存的长度
*
* @param key 键
* @return
*/
public long sGetSetSize(String key) {
try {
return getRedisTemplate().opsForSet().size(key);
} catch (Exception e) {
log.error(e.getMessage(), e);
return 0;
}
}
/**
* 移除值为value的
*
* @param key 键
* @param values 值 可以是多个
* @return 移除的个数
*/
public long setRemove(String key, Object... values) {
try {
Long count = getRedisTemplate().opsForSet().remove(key, values);
return count;
} catch (Exception e) {
log.error(e.getMessage(), e);
return 0;
}
}
// ===============================list=================================
/**
* 获取list缓存的内容
*
* @param key 键
* @param start 开始
* @param end 结束 0 到 -1代表所有值
* @return
*/
public List<Object> lGet(String key, long start, long end) {
try {
return getRedisTemplate().opsForList().range(key, start, end);
} catch (Exception e) {
log.error(e.getMessage(), e);
return null;
}
}
/**
* 获取list缓存的长度
*
* @param key 键
* @return
*/
public long lGetListSize(String key) {
try {
return getRedisTemplate().opsForList().size(key);
} catch (Exception e) {
log.error(e.getMessage(), e);
return 0;
}
}
/**
* 通过索引 获取list中的值
*
* @param key 键
* @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推
* @return
*/
public Object lGetIndex(String key, long index) {
try {
return getRedisTemplate().opsForList().index(key, index);
} catch (Exception e) {
log.error(e.getMessage(), e);
return null;
}
}
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @return
*/
public boolean lSet(String key, Object value) {
try {
getRedisTemplate().opsForList().rightPush(key, value);
return true;
} catch (Exception e) {
log.error(e.getMessage(), e);
return false;
}
}
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @param time 时间(秒)
* @return
*/
public boolean lSet(String key, Object value, long time) {
try {
getRedisTemplate().opsForList().rightPush(key, value);
if (time > 0) {
expire(key, time);
}
return true;
} catch (Exception e) {
log.error(e.getMessage(), e);
return false;
}
}
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @return
*/
public boolean lSet(String key, List<Object> value) {
try {
getRedisTemplate().opsForList().rightPushAll(key, value);
return true;
} catch (Exception e) {
log.error(e.getMessage(), e);
return false;
}
}
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @param time 时间(秒)
* @return
*/
public boolean lSet(String key, List<Object> value, long time) {
try {
getRedisTemplate().opsForList().rightPushAll(key, value);
if (time > 0) {
expire(key, time);
}
return true;
} catch (Exception e) {
log.error(e.getMessage(), e);
return false;
}
}
/**
* 根据索引修改list中的某条数据
*
* @param key 键
* @param index 索引
* @param value 值
* @return
*/
public boolean lUpdateIndex(String key, long index, Object value) {
try {
getRedisTemplate().opsForList().set(key, index, value);
return true;
} catch (Exception e) {
log.error(e.getMessage(), e);
return false;
}
}
/**
* 移除N个值为value
*
* @param key 键
* @param count 移除多少个
* @param value 值
* @return 移除的个数
*/
public long lRemove(String key, long count, Object value) {
try {
Long remove = getRedisTemplate().opsForList().remove(key, count, value);
return remove;
} catch (Exception e) {
log.error(e.getMessage(), e);
return 0;
}
}
public void deleteInvalidRedisKey(String activityCode) {
StringBuilder sb = new StringBuilder(10);
sb.append(PREFIX).append(":").append(activityCode).append(":").append("*");
byte[] bytes = sb.toString().getBytes(Charset.defaultCharset());
redisTemplate.execute(new RedisCallback() {
@Override
public Object doInRedis(RedisConnection connection) throws DataAccessException {
Set<byte[]> keys = connection.keys(bytes);
for (byte[] key : keys) {
connection.del(key);
}
return null;
}
});
}
private RedisTemplate getRedisTemplate() {
if (null == template) {
template = new RedisTemplate<String, Object>();
template.setConnectionFactory(redisTemplate.getConnectionFactory());
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(om);
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
// key采用String的序列化方式
template.setKeySerializer(stringRedisSerializer);
// hash的key也采用String的序列化方式
template.setHashKeySerializer(stringRedisSerializer);
// value序列化方式采用jackson
template.setValueSerializer(jackson2JsonRedisSerializer);
// hash的value序列化方式采用jackson
template.setHashValueSerializer(jackson2JsonRedisSerializer);
template.afterPropertiesSet();
}
return template;
}
}
package cn.wisenergy.web.admin.controller.app;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.app.BankInfo;
import cn.wisenergy.service.app.BankService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
* @author 86187
*/
@Api(tags = "提现银行卡管理")
@RestController
@RequestMapping("/bank")
@Slf4j
public class BankController {
@Autowired
private BankService bankService;
@ApiOperation(value = "保存用户银行卡信息", notes = "保存用户银行卡信息", httpMethod = "POST")
@ApiImplicitParam(name = "bankInfo", value = "银行卡信息", dataType = "BankInfo")
@PostMapping("/add")
public R<BankInfo> add(@RequestBody BankInfo bankInfo) {
log.info("shop-mall[]BankController[]add[]input.param.bankInfo:" + bankInfo);
if (null == bankInfo) {
return R.error("入参为空!");
}
return bankService.add(bankInfo);
}
@ApiOperation(value = "编辑用户银行卡信息", notes = "编辑用户银行卡信息", httpMethod = "POST")
@ApiImplicitParam(name = "bankInfo", value = "银行卡信息", dataType = "BankInfo")
@PostMapping("/edit")
public R<BankInfo> edit(@RequestBody BankInfo bankInfo) {
log.info("shop-mall[]BankController[]edit[]input.param.bankInfo:" + bankInfo);
if (null == bankInfo) {
return R.error("入参为空!");
}
return bankService.edit(bankInfo);
}
@ApiOperation(value = "获取银行卡信息", notes = "获取银行卡信息", httpMethod = "GET")
@ApiImplicitParam(name = "userId", value = "用户id", dataType = "String")
@GetMapping("/getByUserId")
public R<BankInfo> getByUserId(String userId) {
return bankService.getByUserId(userId);
}
@ApiOperation(value = "提现发送短信验证码", notes = "提现发送短信验证码", httpMethod = "GET")
@ApiImplicitParam(name = "userId", value = "用户id", dataType = "String")
@GetMapping("/sendSmsCode")
public R<Boolean> sendSmsCode(String userId) {
return bankService.bankWithdrawSendSms(userId);
}
}
package cn.wisenergy.web.sms;
package cn.wisenergy.web.admin.controller.app;
import cn.wisenergy.common.utils.Constants;
import cn.wisenergy.common.utils.RedisUtils;
import cn.wisenergy.common.utils.SmsUtils;
import cn.wisenergy.common.utils.StringUtil;
import cn.wisenergy.web.sms.*;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -17,26 +23,37 @@ public class SmsController {
@Autowired
private RedisUtils redisUtils;
/**
*
* @param phone
* @param codeType 0注册/登录验证 1修改密码 2订单通知信息
* @return
* @throws Exception
*/
@ApiOperation(value = "发送验证码", notes = "发送验证码", httpMethod = "POST", produces = "application/json; charset=UTF-8")
@ApiImplicitParams({
@ApiImplicitParam(name = "phone", value = "用户手机号", required = true, dataType = "String"),
@ApiImplicitParam(name = "codeType", value = "验证码", dataType = "Integer")})
@RequestMapping("/verifyCode")
public Result verifyCode(String phone,Integer codeType) throws Exception {
//判断phone和codeType是否符合输入类型
if(!phone.matches(Constants.RegConstant.PHONE_REGSTR)){
throw new BaseException(ResultEnum.PHONE_ERROR);
}
if(codeType!=Constants.Sms.CodeType.LOGIN_OR_REGISTER && codeType!=Constants.Sms.CodeType.PASS_UPDATE && codeType!=Constants.Sms.CodeType.ORDER_NOTICE){
if(!codeType.equals(Constants.Sms.CodeType.LOGIN_OR_REGISTER) && !codeType.equals(Constants.Sms.CodeType.PASS_UPDATE) && !codeType.equals(Constants.Sms.CodeType.ORDER_NOTICE)){
throw new BaseException(ResultEnum.CODETYPE_ERROR);
}
String key= StringUtil.formatKeyWithPrefix(Constants.RedisKey.PROJECT_PRIFIX,Constants.RedisKey.SMS_PRIFIX,phone,codeType+"");
//判断是否超过60S
String oldCode=redisUtils.getValue(key);
if(!StringUtils.isBlank(oldCode)){
String Codekey=redisUtils.getValue(key);
if(!StringUtils.isBlank(Codekey)){
throw new BaseException(ResultEnum.CODESEND_ERROR);
}
//生成随机数
String code= MathUtils.random();
//保存至Redis
redisUtils.set(key,code,Constants.Duration.MINUTE_INT);
boolean flag=smsUtils.sendMessage(phone,Constants.Sms.TemplateCode.LOGIN_OR_REGISTER,code);
redisUtils.set(Codekey,code,Constants.Duration.MINUTE_INT);
boolean flag=smsUtils.sendMessage(phone,Constants.Sms.TemplateCode.LOGIN_DL_REGISTER,code);
return flag? ResultUtils.returnSuccess():ResultUtils.returnFail();
}
}
\ No newline at end of file
package cn.wisenergy.web.sms;
package cn.wisenergy.web.admin.controller.app;
//import cn.est.config.UserConfig;
//import cn.est.constants.ResultEnum;
//import cn.est.dto.Result;
//import cn.est.po.Brand;
//import cn.est.service.BrandService;
//import cn.est.utils.ResultUtils;
//import cn.est.utils.SmsUtils;
//import cn.est.utils.StringUtil;
import cn.wisenergy.common.utils.SmsUtils;
import cn.wisenergy.web.sms.Result;
import cn.wisenergy.web.sms.ResultUtils;
import cn.wisenergy.web.sms.ShareCodeUtil;
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.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@Controller
@Api(tags = "短信服务测试,邀请码测试")
@RestController
@RequestMapping("/ZX")
@Slf4j
public class TestController {
// @Autowired
......@@ -25,6 +28,7 @@ public class TestController {
// @Autowired
// private UserConfig useronfig;
@ApiOperation(value = "测试Hello Wolrd", notes = "测试", httpMethod = "POST", produces = "application/json; charset=UTF-8")
@RequestMapping("/index")
@ResponseBody
public String index() {
......@@ -49,17 +53,17 @@ public class TestController {
public static void main(String [] args){
String b = ShareCodeUtil.idToCode(123456);
String a= ShareCodeUtil.idToCode(0,0+1);
String b = ShareCodeUtil.idToCode(1);
String a= ShareCodeUtil.idToCode(1,0+1);
System.out.println(b);
}
@ApiOperation(value = "测试短信服务,发送手机号", notes = "测试短信服务,发送手机号", httpMethod = "POST", produces = "application/json; charset=UTF-8")
@RequestMapping("/testSms")
@ResponseBody
public Result testException()throws Exception{
// System.out.println(useronfig.getUserName()+"---"+useronfig.getSex());
return smsUtils.sendMessage("18518666833","SMS_212170059","2111")?ResultUtils.returnSuccess():ResultUtils.returnFail();
return smsUtils.sendMessage("19919990669","SMS_212170059","2111")? ResultUtils.returnSuccess():ResultUtils.returnFail();
}
}
......@@ -79,49 +79,4 @@ public class UserController extends BaseController {
return R.ok(token);
}
// /**
// * 手机号登录
// * @param userId
// * @param sms
// * @return
// * @throws Exception
// */
// @ApiOperation(value = "获取用户手机号登录接口", notes = "获取用户手机号登录接口", httpMethod = "POST")
// @ApiImplicitParams({
// @ApiImplicitParam(name = "userId", value = "用户手机号", required = true, dataType = "String"),
// @ApiImplicitParam(name = "sms", value = "短信验证码", required = true, dataType = "String")})
// @RequestMapping("/login/sms")
// public Result loginBySms(String userId, String sms)throws Exception{
// User users=null;
// String key= StringUtil.formatKeyWithPrefix(Constants.RedisKey.PROJECT_PRIFIX,Constants.RedisKey.SMS_PRIFIX,userId,Constants.Sms.CodeType.LOGIN_OR_REGISTER+"");
// String redisCode=redisUtils.getValue(key);
// if(StringUtil.isBlank(redisCode) || !sms.equals(redisCode)){
// throw new BaseException(ResultEnum.FAIL_VERIFY);
// }
// redisUtils.delete(key);
// //根据手机号判断用户是否存在
// //不存在则保存用户信息
// users=userService.queryUsersByPhone(userId);
// if(null==users){
// users=new User();
//// users.setAccount(phone);
//// users.setUserName(phone);
//// userService.qdtxAddUsers(users);
// }
// String token=createToken(users);
// if(!StringUtil.isBlank(token)){
// return ResultUtils.returnDataSuccess(StringUtil.createSimpleMap("token",token));
// }
// return ResultUtils.returnFail();
// }
//
// public String createToken(User users)throws Exception{
// String token=StringUtil.createToken();
// //保存token
// String tokenKey=StringUtil.formatKeyWithPrefix(Constants.RedisKey.PROJECT_PRIFIX,Constants.RedisKey.TOKEN_PRIFIX,token);
// UsersDto usersDto=new UsersDto();
// BeanUtils.copyProperties(users,usersDto);
// redisUtils.set(tokenKey, JSONObject.toJSONString(usersDto),Constants.Duration.HALF_HOUR_INT);
// return token;
// }
}
package cn.wisenergy.web.admin.controller.app;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.vo.AccumulatedIncomeVo;
import cn.wisenergy.model.vo.MoneyPackageDetailVo;
import cn.wisenergy.model.vo.MoneyPackageVo;
import cn.wisenergy.model.vo.WithdrawalAmountVo;
import cn.wisenergy.model.vo.*;
import cn.wisenergy.service.app.WalletService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
......@@ -77,4 +75,19 @@ public class WalletController {
return walletService.queryIncomeDetail(userId);
}
@ApiOperation(value = "提现记录", notes = "提现记录", httpMethod = "GET")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId", value = "用户id", dataType = "String"),
@ApiImplicitParam(name = "yearMonth", value = "时间(yyyy-MM-dd)", dataType = "String", required = true)
})
@GetMapping("/getWithdrawalRecord")
public R<List<WithdrawalRecordVo>> getWithdrawalRecord(String userId, String yearMonth) {
log.info("shop-mall[]WalletController[]getWithdrawalRecord[]input.param.userId:{},yearMonth:" + userId, yearMonth);
if (StringUtils.isBlank(yearMonth)) {
return R.error("入参不能为空!");
}
return walletService.getWithdrawalRecord(userId, yearMonth);
}
}
package cn.wisenergy.web.admin.controller.app;
import cn.wisenergy.web.sms.*;
import cn.wisenergy.common.utils.RedisUtils;
import cn.wisenergy.common.utils.StringUtil;
import cn.wisenergy.model.app.User;
import cn.wisenergy.model.app.UsersDto;
import cn.wisenergy.service.app.UserService;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
*
* Created by m1991 on 2021/3/2 13:35
*/
@Api(tags = "登录/注册")
@Slf4j
@RequestMapping("/api/user/login/sms")
@RestController
public class loginController {
@Autowired
private RedisUtils redisUtils;
@Autowired
private UserService usersService;
@Autowired
private Result result;
/**
* 手机登录接口
* @param userId
* @param sms
* @return
* @throws Exception
*/
@ApiOperation(value = "登录", notes = "登录", httpMethod = "POST", produces = "application/json; charset=UTF-8")
@ApiImplicitParams({
@ApiImplicitParam(name = "sms", value = "验证码", dataType = "String"),
@ApiImplicitParam(name = "userId", value = "用户手机号", required = true, dataType = "String")})
@RequestMapping("/login/sms")
public Result loginBySms(String userId,String sms)throws Exception{
User users=null;
String key= StringUtil.formatKeyWithPrefix(Constants.RedisKey.PROJECT_PRIFIX,Constants.RedisKey.SMS_PRIFIX,userId,Constants.Sms.CodeType.LOGIN_OR_REGISTER+"");
String redisCode=redisUtils.getValue(key);
if(StringUtil.isBlank(redisCode) || !sms.equals(redisCode)){
throw new BaseException(ResultEnum.FAIL_VERIFY);
}
redisUtils.delete(key);
//根据手机号判断用户是否存在
//不存在则保存用户信息--修改为提示用户注册
users=usersService.queryUsersByPhone(userId);
if(null==users){
throw new BaseException(ResultEnum.FAIL_ACCOUNT_NOT_EXIST);
// users=new User();
// users.setUserId(userId);
// usersService.qdtxAddUsers(users);;
}
String token=createToken(users);
if(!StringUtil.isBlank(token)){
return ResultUtils.returnDataSuccess(StringUtil.createSimpleMap("token",token));
}
return ResultUtils.returnFail();
}
public String createToken(User users)throws Exception{
String token=StringUtil.createToken();
//保存token
String tokenKey=StringUtil.formatKeyWithPrefix(Constants.RedisKey.PROJECT_PRIFIX,Constants.RedisKey.TOKEN_PRIFIX,token);
UsersDto usersDto=new UsersDto();
BeanUtils.copyProperties(users,usersDto);
redisUtils.set(tokenKey, JSONObject.toJSONString(usersDto),Constants.Duration.HALF_HOUR_INT);
return token;
}
@ApiOperation(value = "获取用户登录token信息", notes = "获取用户登录token信息", httpMethod = "POST", produces = "application/json; charset=UTF-8")
@RequestMapping("/info")
public Result info(HttpServletRequest request)throws Exception{
String token=request.getHeader("token");
String tokenKey=StringUtil.formatKeyWithPrefix(Constants.RedisKey.PROJECT_PRIFIX,Constants.RedisKey.TOKEN_PRIFIX,token);
String userDtoJson=redisUtils.getValue(tokenKey);
if(StringUtil.isBlank(userDtoJson)){
throw new BaseException(ResultEnum.FILE_NOT_LOGIN);
}
UsersDto usersDto=JSONObject.parseObject(userDtoJson,UsersDto.class);
usersDto.setPassword(null);
return ResultUtils.returnDataSuccess(userDtoJson);
}
//用户注册
@ApiOperation(value = "用户注册", notes = "用户注册", httpMethod = "POST", produces = "application/json; charset=UTF-8")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId", value = "用户手机号", required = true, dataType = "String"),
@ApiImplicitParam(name = "beInvitedCode", value = "推荐人邀请码", dataType = "String"),
@ApiImplicitParam(name = "sms", value = "验证码", dataType = "String")
})
@RequestMapping("/register")
public Result register(@RequestParam String userId, @RequestParam String beInvitedCode, String sms)throws Exception {
User users=null;
String key= StringUtil.formatKeyWithPrefix(Constants.RedisKey.PROJECT_PRIFIX,Constants.RedisKey.SMS_PRIFIX,userId,Constants.Sms.CodeType.LOGIN_OR_REGISTER+"");
String redisCode=redisUtils.getValue(key);
if(StringUtil.isBlank(redisCode) || !sms.equals(redisCode)){
throw new BaseException(ResultEnum.FAIL_VERIFY);
}
redisUtils.delete(key);
//判断phone是否符合输入类型
if(!userId.matches(Constants.RegConstant.PHONE_REGSTR)){
throw new BaseException(ResultEnum.PHONE_ERROR);
}
usersService.userByZx(userId,beInvitedCode);
return ResultUtils.returnFail("注册成功!","0");
}
}
......@@ -63,6 +63,8 @@ public class ShiroConfig {
filterChainDefinitionMap.put("/webjars/springfox-swagger-ui/**", "anon");
filterChainDefinitionMap.put("/swagger-resources/**", "anon");
filterChainDefinitionMap.put("/v2/api-docs", "anon");
filterChainDefinitionMap.put("/api/sms/verifyCode", "anon");
filterChainDefinitionMap.put("/api/sms/**", "anon");
filterChainDefinitionMap.put("/upload_flowChart/**", "anon");//图片地址
filterChainDefinitionMap.put("/webSocket/**", "anon");//socket
filterChainDefinitionMap.put("/message/**", "anon");//消息推送接口
......
package cn.wisenergy.web.sms;
/***
* 系统中保存的一些常量
*/
/**
* Created by m1991 on 2021/2/28 22:50
*/
public class Constants {
//通用常量
public static class Common{
//否
public final static Integer NOT = 0;
//是
public final static Integer YES = 1;
//女
public final static Integer SEX_WOMEN = 0;
//男
public final static Integer SEX_MAN = 1;
//数据精度
public final static Integer DECIMAL_DIGITS = 2;
}
//访问来源
public static class SourceType{
//访问来源-APP
public final static Integer APP = 0;
//访问来源-PC
public final static Integer PC = 1;
}
//连接符
public static class Connnector{
//逗号
public final static String COMMA_ = ",";
//下划线
public final static String UNDERLINE = "_";
//冒号
public final static String COLON=":";
}
//时长
public static class Duration{
//一秒
public final static Integer SECOND_INT = 1;
//一分钟
public final static Integer MINUTE_INT = SECOND_INT * 60;
//半小时
public final static Integer HALF_HOUR_INT = MINUTE_INT * 30;
}
//正则的一些常量
public static class RegConstant{
//手机号正则
public static String PHONE_REGSTR = "^[1][0-9]{10}$";
//密码正则
public static String PASSWORD_REGSTR = "^([A-Z]|[a-z]|[0-9]|[_]){6,10}$";
}
//SMS相关常量
public static class Sms{
public static class TemplateCode{
public static String LOGIN_OR_REGISTER="SMS_197895260";
}
public static class CodeType{
public static Integer LOGIN_OR_REGISTER=0;
public static Integer PASS_UPDATE=1;
public static Integer ORDER_NOTICE=2;
}
}
//RedisKey相关的常量
public static class RedisKey{
public static String PROJECT_PRIFIX="xts";
public static String SMS_PRIFIX="sms";
public static String TOKEN_PRIFIX="token";
}
}
......@@ -16,7 +16,7 @@ public enum ResultEnum {
FAIL_LOGIN("1002", "登录失败"),
FAIL_VERIFY("1003", "验证码错误"),
FAIL_ACCOUNT_EXIST("1004", "账号已存在"),
FAIL_ACCOUNT_NOT_EXIST("1005", "账号不存在"),
FAIL_ACCOUNT_NOT_EXIST("1005", "账号不存在,请注册!"),
FAIL_TIMESTAMP_NOT_NULL("1006", "时间戳不能为空"),
FAIL_VISIT_SOURCE_NOT_NULL("1007", "访问来源不能为空"),
PHONE_ERROR("1008","手机号码格式不正确"),
......
......@@ -67,9 +67,9 @@ public class ValidateParamInterceptor extends HandlerInterceptorAdapter {
// 阿里支付
map.put("/api/pay/alipay", Arrays.asList("orderNo", "amount"));
// 验证码登录、注册接口
map.put("/api/sms/login/sms", Arrays.asList("phone", "sms"));
map.put("/api/sms/login/sms", Arrays.asList("userId", "sms"));
// 发送验证码接口
map.put("/api/sms/verifyCode", Arrays.asList("phone", "codeType"));
map.put("/api/sms/verifyCode", Arrays.asList("userId", "codeType"));
return map;
}
......
......@@ -43,12 +43,12 @@ spring:
max-file-size: 10MB
# 总限制
max-request-size: 20MB
# 192.168.110.165 adm4HYservice$
redis:
database: 0
host: 192.168.110.165
host: 127.0.0.1
port: 6379
password: adm4HYservice$ # 密码(默认为空)
password: 123456 # 密码(默认为空)
timeout: 6000ms # 连接超时时长(毫秒)
jedis:
pool:
......@@ -70,3 +70,11 @@ jwt:
expire: 14400
logging:
config: classpath:logback-spring.xml
sms:
accessKeyId: LTAI4G6xmYPhjrS18Bxz5Kqu
secret: l3ZuSn2XjsFZXaB3yb8O5ASRJh3DDe
regionId: cn-hangzhou
domain: dysmsapi.aliyuncs.com
version: 2017-05-25
action: SendSms
signName: 西田森生物科技
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment