Commit 00966bfd by 魏文甫

init

1 parent 84d5074c
......@@ -9,7 +9,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication
@EnableTransactionManagement
@ServletComponentScan
@MapperScan("com.server.web.common.mapper")
@MapperScan({"com.server.web.common.mapper","com.server.web.common.mapping"})
public class Application {
public static void main(String[] args) {
......
......@@ -19,8 +19,10 @@ import java.util.concurrent.TimeUnit;
* Created by 豆腐干Sama on 2018/12/6.
*/
@RestController
@RequestMapping(value = BaseController.WX_NAMESPACE + "/user",produces = "application/json")
@RequestMapping(value = BaseController.WX_NAMESPACE + "/user", produces = "application/json")
public class UserController extends BaseController {
@GetMapping("/userData")
public Map userData(HttpServletRequest request) {
TKzyUser loginUser = getLoginUser(request);
......@@ -29,25 +31,27 @@ public class UserController extends BaseController {
@PostMapping("/register")
public Map register(HttpServletRequest request) {
TKzyUser user= getLoginUser(request);
TKzyUser user = getLoginUser(request);
String phone = request.getParameter("phone");
String verifyCode = request.getParameter("verifyCode");
String wxOpenId = request.getParameter("wxOpenId");
if(phone==null||!phone.matches("^((1[3-9]))\\d{9}$")){
return returnError("0","请输入有效的手机号码",null);
String fullName = request.getParameter("fullName");
String userCategory = request.getParameter("userCategory");
if (phone == null || !phone.matches("^((1[3-9]))\\d{9}$")) {
return returnError("0", "请输入有效的手机号码", null);
}
if(verifyCode==null){
return returnError("0","请输入有效的验证码!",null);
if (verifyCode == null) {
return returnError("0", "请输入有效的验证码!", null);
}
if (user== null) {
return returnError("0","未登录",null);
if (user == null) {
return returnError("0", "未登录", null);
}
ValueOperations operations = redisTemplate.opsForValue();
String cacheCode = (String)operations.get("Kzy_WX_LOGIN_SMS_PHONE_" + phone);
String cacheCode = (String) operations.get("Kzy_WX_LOGIN_SMS_PHONE_" + phone);
if (StringUtils.isEmpty(cacheCode) || !cacheCode.equals(verifyCode)) {
return returnError("0","短信验证码有误,或已失效!",null);
return returnError("0", "短信验证码有误,或已失效!", null);
} else {
redisTemplate.delete("Kzy_WX_LOGIN_SMS_PHONE_" + phone);
}
......@@ -58,22 +62,20 @@ public class UserController extends BaseController {
if (!CollectionUtils.isEmpty(users)) {
TKzyUser user1 = users.get(0);
if (!StringUtils.isEmpty(user1.getWxOpenid()) && !wxOpenId.equals(user1.getWxOpenid())) {
return returnError("0","该微信已绑定其他手机号",null);
return returnError("0", "该微信已绑定其他手机号", null);
}
}
String fullName = request.getParameter("fullName");
String duty = request.getParameter("duty");
user.setWxOpenid(wxOpenId);
user.setCreateDt(new Date());
user.setDuty(duty);
user.setUserCategory(userCategory==null?null:Integer.valueOf(userCategory));
user.setFullName(fullName);
user.setPhone(phone);
user.setStatus(1);
userMapper.insertSelective(user);
request.getSession().setAttribute(WX_USER_SESSION_KEY,user);
request.getSession().setAttribute(WX_USER_SESSION_KEY, user);
return returnSuccess(user);
}
......@@ -82,7 +84,7 @@ public class UserController extends BaseController {
public Map update(HttpServletRequest request) {
TKzyUser loginUser = getLoginUser(request);
if (loginUser == null) {
return returnError("0","用户未登录",null);
return returnError("0", "用户未登录", null);
}
String wxOpenId = request.getParameter("wxOpenId");
......@@ -94,53 +96,54 @@ public class UserController extends BaseController {
loginUser.setFullName(fullName);
userMapper.updateByPrimaryKeySelective(loginUser);
request.getSession().setAttribute(WX_USER_SESSION_KEY,loginUser);
request.getSession().setAttribute(WX_USER_SESSION_KEY, loginUser);
return returnSuccess(loginUser);
}
/**
* 发送短信
*
* @param request
* @return
*/
@ResponseBody
@RequestMapping(path = "/sendMessageCode", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json")
public Map<String, Object> sendMessageCode(HttpServletRequest request) {
Map<String,Object> resultMap = new HashMap<String,Object>();
resultMap.put("status","0");
resultMap.put("message","");
Map<String, Object> resultMap = new HashMap<String, Object>();
resultMap.put("status", "0");
resultMap.put("message", "");
String imgVerifyCode = request.getParameter("imgVerifyCode");
String phone = request.getParameter("phone");
String failPhone = request.getSession().getAttribute("fail_"+phone)==null?null:request.getSession().getAttribute("fail_"+phone).toString();
String failPhone = request.getSession().getAttribute("fail_" + phone) == null ? null : request.getSession().getAttribute("fail_" + phone).toString();
int count = 0;
if(failPhone!=null && org.apache.commons.lang.math.NumberUtils.isNumber(failPhone)){
if (failPhone != null && org.apache.commons.lang.math.NumberUtils.isNumber(failPhone)) {
count = Integer.valueOf(failPhone);
}
if(phone==null||!phone.matches("^((1[3-9]))\\d{9}$")){
resultMap.put("message","请输入有效的手机号码!");
request.getSession().setAttribute("fail_"+phone,count+1);
if(count+1>=3){
resultMap.put("imgFlag","1");
if (phone == null || !phone.matches("^((1[3-9]))\\d{9}$")) {
resultMap.put("message", "请输入有效的手机号码!");
request.getSession().setAttribute("fail_" + phone, count + 1);
if (count + 1 >= 3) {
resultMap.put("imgFlag", "1");
}
return resultMap;
}
ValueOperations vv = redisTemplate.opsForValue();
if(imgVerifyCode!=null&&!"".equals(imgVerifyCode)){
String redisImageCode = (String)vv.get("Kzy_IMAGE_CODE_" + phone);
if(redisImageCode==null||!redisImageCode.toUpperCase().equals(imgVerifyCode.toUpperCase())){
resultMap.put("message","请输入正确的图形验证码!");
if (imgVerifyCode != null && !"".equals(imgVerifyCode)) {
String redisImageCode = (String) vv.get("Kzy_IMAGE_CODE_" + phone);
if (redisImageCode == null || !redisImageCode.toUpperCase().equals(imgVerifyCode.toUpperCase())) {
resultMap.put("message", "请输入正确的图形验证码!");
return resultMap;
} else {
redisTemplate.delete("Kzy_IMAGE_CODE_"+phone);
redisTemplate.delete("Kzy_IMAGE_CODE_" + phone);
}
}
if(vv.get("Kzy_WX_LOGIN_SMS_PHONE_FLAG_" + phone)!=null){//缓存标识,缓存里存在,表示还在有效期内,不重复发送
resultMap.put("message","您发送的短信验证码尚在有效期,无需重复发送");
request.getSession().setAttribute("fail_"+phone,count+1);
if(count+1>=3){
resultMap.put("imgFlag","1");
if (vv.get("Kzy_WX_LOGIN_SMS_PHONE_FLAG_" + phone) != null) {//缓存标识,缓存里存在,表示还在有效期内,不重复发送
resultMap.put("message", "您发送的短信验证码尚在有效期,无需重复发送");
request.getSession().setAttribute("fail_" + phone, count + 1);
if (count + 1 >= 3) {
resultMap.put("imgFlag", "1");
}
return resultMap;
}
......@@ -148,19 +151,19 @@ public class UserController extends BaseController {
try {
boolean sendFlag = sendSmsCode(phone, "46886", randomCode);
if (sendFlag) {
logger.error("短信验证码发送成功");
vv.set("Kzy_WX_LOGIN_SMS_PHONE_" + phone,randomCode,5, TimeUnit.MINUTES);//缓存验证码,验证成功之后再手动销毁
logger.error("短信验证码发送成功");
vv.set("Kzy_WX_LOGIN_SMS_PHONE_" + phone, randomCode, 5, TimeUnit.MINUTES);//缓存验证码,验证成功之后再手动销毁
//测试用,上线去掉
System.out.println(phone+"999微信注册登录验证码为:"+randomCode);
resultMap.put("data","");
resultMap.put("status","1");
resultMap.put("message","发送成功~");
System.out.println(phone + "999微信注册登录验证码为:" + randomCode);
resultMap.put("data", "");
resultMap.put("status", "1");
resultMap.put("message", "发送成功~");
} else {
resultMap.put("message","短信验证码发送失败");
resultMap.put("message", "短信验证码发送失败");
}
} catch (Exception e) {
resultMap.put("message","发送短信验证码服务异常");
resultMap.put("message", "发送短信验证码服务异常");
}
return resultMap;
......@@ -196,13 +199,14 @@ public class UserController extends BaseController {
String phone = request.getParameter("phone");
if (!StringUtils.isEmpty(phone)) {
logger.error("获取图形验证码手机号:" + phone);
vv.set("Kzy_IMAGE_CODE_"+phone,verifyImgCode,1,TimeUnit.MINUTES);
vv.set("Kzy_IMAGE_CODE_" + phone, verifyImgCode, 1, TimeUnit.MINUTES);
}
} catch (IOException e) {
e.printStackTrace();
logger.error("生成验证码失败", e);
}
}
public static String generateVerifyCode(int verifySize) {
String sources = "ABCDEFGHJKMNPQRSTUVWXYZ2345689";
int codesLen = sources.length();
......@@ -214,16 +218,16 @@ public class UserController extends BaseController {
return verifyCode.toString();
}
public boolean sendSmsCode(String phone, String templateId, String code) throws Exception{
if(StringUtils.hasText(phone)&&StringUtils.hasText(templateId)&&StringUtils.hasText(code)){
HashMap<String, Object> smsResult = SendSMSUtil.sendTemplateSMS(phone,templateId,new String[]{code});
public boolean sendSmsCode(String phone, String templateId, String code) throws Exception {
if (StringUtils.hasText(phone) && StringUtils.hasText(templateId) && StringUtils.hasText(code)) {
HashMap<String, Object> smsResult = SendSMSUtil.sendTemplateSMS(phone, templateId, new String[]{code});
logger.error("/sendSmsCode =============>sendSmsCode-smsResult=" + smsResult);
if("000000".equals(smsResult.get("statusCode"))){
if ("000000".equals(smsResult.get("statusCode"))) {
return true;
}else{
} else {
return false;
}
}else{
} else {
return false;
}
......
......@@ -64,14 +64,6 @@
</javaClientGenerator>
<table tableName="t_base_banner" schema="sc"><generatedKey column="ID" sqlStatement="MySql" identity="true"/></table>
<table tableName="t_base_first_class" schema="sc"><generatedKey column="ID" sqlStatement="MySql" identity="true"/></table>
<table tableName="t_base_second_class" schema="sc"><generatedKey column="ID" sqlStatement="MySql" identity="true"/></table>
<table tableName="t_kzy_comment" schema="sc"><generatedKey column="ID" sqlStatement="MySql" identity="true"/></table>
<table tableName="t_kzy_course" schema="sc"><generatedKey column="ID" sqlStatement="MySql" identity="true"/></table>
<table tableName="t_kzy_information" schema="sc"><generatedKey column="ID" sqlStatement="MySql" identity="true"/></table>
<table tableName="t_kzy_relation_class" schema="sc"><generatedKey column="ID" sqlStatement="MySql" identity="true"/></table>
<table tableName="t_kzy_user" schema="sc"><generatedKey column="ID" sqlStatement="MySql" identity="true"/></table>
<table tableName="t_kzy_user_integral_flowing" schema="sc"><generatedKey column="ID" sqlStatement="MySql" identity="true"/></table>
</context>
</generatorConfiguration>
\ No newline at end of file
......@@ -289,275 +289,4 @@
create_dt = #{createDt,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=BIGINT}
</update>
<resultMap id="BaseResultMap" type="com.server.web.common.model.TBaseBanner">
<constructor>
<idArg column="id" javaType="java.lang.Long" jdbcType="BIGINT" />
<arg column="title" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="pic_url" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="weight" javaType="java.lang.Integer" jdbcType="INTEGER" />
<arg column="url" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="remark" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="is_delete" javaType="java.lang.Integer" jdbcType="INTEGER" />
<arg column="is_up" javaType="java.lang.Integer" jdbcType="INTEGER" />
<arg column="create_dt" javaType="java.util.Date" jdbcType="TIMESTAMP" />
</constructor>
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
id, title, pic_url, weight, url, remark, is_delete, is_up, create_dt
</sql>
<select id="selectByExample" parameterType="com.server.web.common.model.TBaseBannerExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from t_base_banner
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from t_base_banner
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from t_base_banner
where id = #{id,jdbcType=BIGINT}
</delete>
<delete id="deleteByExample" parameterType="com.server.web.common.model.TBaseBannerExample">
delete from t_base_banner
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="com.server.web.common.model.TBaseBanner">
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
SELECT LAST_INSERT_ID()
</selectKey>
insert into t_base_banner (title, pic_url, weight,
url, remark, is_delete,
is_up, create_dt)
values (#{title,jdbcType=VARCHAR}, #{picUrl,jdbcType=VARCHAR}, #{weight,jdbcType=INTEGER},
#{url,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, #{isDelete,jdbcType=INTEGER},
#{isUp,jdbcType=INTEGER}, #{createDt,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="com.server.web.common.model.TBaseBanner">
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
SELECT LAST_INSERT_ID()
</selectKey>
insert into t_base_banner
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="title != null">
title,
</if>
<if test="picUrl != null">
pic_url,
</if>
<if test="weight != null">
weight,
</if>
<if test="url != null">
url,
</if>
<if test="remark != null">
remark,
</if>
<if test="isDelete != null">
is_delete,
</if>
<if test="isUp != null">
is_up,
</if>
<if test="createDt != null">
create_dt,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="title != null">
#{title,jdbcType=VARCHAR},
</if>
<if test="picUrl != null">
#{picUrl,jdbcType=VARCHAR},
</if>
<if test="weight != null">
#{weight,jdbcType=INTEGER},
</if>
<if test="url != null">
#{url,jdbcType=VARCHAR},
</if>
<if test="remark != null">
#{remark,jdbcType=VARCHAR},
</if>
<if test="isDelete != null">
#{isDelete,jdbcType=INTEGER},
</if>
<if test="isUp != null">
#{isUp,jdbcType=INTEGER},
</if>
<if test="createDt != null">
#{createDt,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.server.web.common.model.TBaseBannerExample" resultType="java.lang.Long">
select count(*) from t_base_banner
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
update t_base_banner
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=BIGINT},
</if>
<if test="record.title != null">
title = #{record.title,jdbcType=VARCHAR},
</if>
<if test="record.picUrl != null">
pic_url = #{record.picUrl,jdbcType=VARCHAR},
</if>
<if test="record.weight != null">
weight = #{record.weight,jdbcType=INTEGER},
</if>
<if test="record.url != null">
url = #{record.url,jdbcType=VARCHAR},
</if>
<if test="record.remark != null">
remark = #{record.remark,jdbcType=VARCHAR},
</if>
<if test="record.isDelete != null">
is_delete = #{record.isDelete,jdbcType=INTEGER},
</if>
<if test="record.isUp != null">
is_up = #{record.isUp,jdbcType=INTEGER},
</if>
<if test="record.createDt != null">
create_dt = #{record.createDt,jdbcType=TIMESTAMP},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
update t_base_banner
set id = #{record.id,jdbcType=BIGINT},
title = #{record.title,jdbcType=VARCHAR},
pic_url = #{record.picUrl,jdbcType=VARCHAR},
weight = #{record.weight,jdbcType=INTEGER},
url = #{record.url,jdbcType=VARCHAR},
remark = #{record.remark,jdbcType=VARCHAR},
is_delete = #{record.isDelete,jdbcType=INTEGER},
is_up = #{record.isUp,jdbcType=INTEGER},
create_dt = #{record.createDt,jdbcType=TIMESTAMP}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="com.server.web.common.model.TBaseBanner">
update t_base_banner
<set>
<if test="title != null">
title = #{title,jdbcType=VARCHAR},
</if>
<if test="picUrl != null">
pic_url = #{picUrl,jdbcType=VARCHAR},
</if>
<if test="weight != null">
weight = #{weight,jdbcType=INTEGER},
</if>
<if test="url != null">
url = #{url,jdbcType=VARCHAR},
</if>
<if test="remark != null">
remark = #{remark,jdbcType=VARCHAR},
</if>
<if test="isDelete != null">
is_delete = #{isDelete,jdbcType=INTEGER},
</if>
<if test="isUp != null">
is_up = #{isUp,jdbcType=INTEGER},
</if>
<if test="createDt != null">
create_dt = #{createDt,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.server.web.common.model.TBaseBanner">
update t_base_banner
set title = #{title,jdbcType=VARCHAR},
pic_url = #{picUrl,jdbcType=VARCHAR},
weight = #{weight,jdbcType=INTEGER},
url = #{url,jdbcType=VARCHAR},
remark = #{remark,jdbcType=VARCHAR},
is_delete = #{isDelete,jdbcType=INTEGER},
is_up = #{isUp,jdbcType=INTEGER},
create_dt = #{createDt,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=BIGINT}
</update>
</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="com.server.web.common.mapping.CommentMapper" >
</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="com.server.web.common.mapping.CourseMapper" >
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="callSettersOnNulls" value="true"/>
<setting name="cacheEnabled" value="true"/>
<setting name="lazyLoadingEnabled" value="true"/>
<setting name="aggressiveLazyLoading" value="true"/>
<setting name="multipleResultSetsEnabled" value="true"/>
<setting name="useColumnLabel" value="true"/>
<setting name="useGeneratedKeys" value="false"/>
<setting name="autoMappingBehavior" value="PARTIAL"/>
<setting name="defaultExecutorType" value="SIMPLE"/>
<setting name="mapUnderscoreToCamelCase" value="true"/>
<setting name="localCacheScope" value="SESSION"/>
<setting name="jdbcTypeForNull" value="NULL"/>
<setting name="logImpl" value="LOG4J"/>
</settings>
<typeAliases>
<typeAlias alias="Integer" type="java.lang.Integer" />
<typeAlias alias="Long" type="java.lang.Long" />
<typeAlias alias="HashMap" type="java.util.HashMap" />
<typeAlias alias="LinkedHashMap" type="java.util.LinkedHashMap" />
<typeAlias alias="ArrayList" type="java.util.ArrayList" />
<typeAlias alias="LinkedList" type="java.util.LinkedList" />
</typeAliases>
</configuration>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!