commit
2411badad4
@ -1,18 +1,25 @@
|
||||
package com.stdiet.web.controller.custom;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.stdiet.common.core.controller.BaseController;
|
||||
import com.stdiet.common.core.domain.AjaxResult;
|
||||
import com.stdiet.common.utils.DateUtils;
|
||||
import com.stdiet.common.utils.StringUtils;
|
||||
import com.stdiet.common.utils.sign.AesUtils;
|
||||
import com.stdiet.custom.domain.SysOrderPause;
|
||||
import com.stdiet.custom.domain.SysWxAdLog;
|
||||
import com.stdiet.custom.service.*;
|
||||
import com.stdiet.custom.utils.CookieUtils;
|
||||
import com.stdiet.custom.utils.HttpRequestUtils;
|
||||
import com.stdiet.system.service.ISysDictTypeService;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -38,6 +45,7 @@ public class SysWapController extends BaseController {
|
||||
@Autowired
|
||||
ISysSmsConfirmServie iSysSmsConfirmServie;
|
||||
|
||||
|
||||
/**
|
||||
* 客户食谱详情
|
||||
*
|
||||
@ -140,6 +148,29 @@ public class SysWapController extends BaseController {
|
||||
return toAjax(iSysWxSaleAccountService.logWxAd(sysWxAdLog));
|
||||
}
|
||||
|
||||
@GetMapping(value = "/getCookie")
|
||||
public AjaxResult getCookie(@RequestParam String phone, HttpServletResponse response) {
|
||||
String tokenStr = phone + "_" + new Date().getTime() + "_" + RandomStringUtils.random(8);
|
||||
Cookie cookie = new Cookie("token", AesUtils.encrypt(tokenStr));
|
||||
cookie.setMaxAge(24 * 60 * 60);
|
||||
cookie.setSecure(true);
|
||||
cookie.setHttpOnly(true);
|
||||
cookie.setPath("/");
|
||||
response.addCookie(cookie);
|
||||
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
@GetMapping(value = "/checkCookie")
|
||||
public AjaxResult checkCookie(HttpServletRequest request) {
|
||||
JSONObject resultObj = CookieUtils.checkCookieValida(request, "token");
|
||||
if (resultObj.getInteger("code") == 200) {
|
||||
return AjaxResult.success(resultObj.getString("msg"));
|
||||
} else {
|
||||
return AjaxResult.error(resultObj.getInteger("code"), resultObj.getString("msg"));
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping(value = "/getCode")
|
||||
public AjaxResult getCode(@RequestParam String phone) {
|
||||
|
||||
@ -159,13 +190,23 @@ public class SysWapController extends BaseController {
|
||||
}
|
||||
|
||||
@GetMapping(value = "/checkCode")
|
||||
public AjaxResult checkCode(@RequestParam String phone, @RequestParam String code) {
|
||||
public AjaxResult checkCode(@RequestParam String phone, @RequestParam String code, HttpServletResponse response) {
|
||||
|
||||
if (StringUtils.isEmpty(code)) {
|
||||
return AjaxResult.error(50002, "验证码不能为空");
|
||||
}
|
||||
|
||||
|
||||
int checkCode = iSysSmsConfirmServie.checkSmsCode(phone, code);
|
||||
if (checkCode == 0) {
|
||||
return AjaxResult.success();
|
||||
String tokenStr = phone + "_" + new Date().getTime() + "_" + RandomStringUtils.randomAlphanumeric(8);
|
||||
Cookie cookie = new Cookie("token", AesUtils.encrypt(tokenStr));
|
||||
cookie.setMaxAge(24 * 60 * 60);
|
||||
cookie.setSecure(true);
|
||||
cookie.setHttpOnly(true);
|
||||
cookie.setPath("/");
|
||||
response.addCookie(cookie);
|
||||
return new AjaxResult(20000, "登录成功");
|
||||
} else if (checkCode == 1) {
|
||||
return AjaxResult.error(50003, "验证码失效");
|
||||
} else if (checkCode == 2) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.stdiet.web.controller.custom;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aliyun.vod20170321.models.GetPlayInfoResponseBody;
|
||||
import com.stdiet.common.core.controller.BaseController;
|
||||
import com.stdiet.common.core.domain.AjaxResult;
|
||||
@ -8,14 +9,18 @@ import com.stdiet.common.utils.AliyunVideoUtils;
|
||||
import com.stdiet.common.utils.StringUtils;
|
||||
import com.stdiet.common.utils.oss.AliyunOSSUtils;
|
||||
import com.stdiet.custom.domain.SysNutritionalVideo;
|
||||
import com.stdiet.custom.domain.SysOrder;
|
||||
import com.stdiet.custom.domain.SysVideoClassify;
|
||||
import com.stdiet.custom.dto.response.NutritionalVideoResponse;
|
||||
import com.stdiet.custom.dto.response.VideoClassifyResponse;
|
||||
import com.stdiet.custom.service.ISysNutritionalVideoService;
|
||||
import com.stdiet.custom.service.ISysOrderService;
|
||||
import com.stdiet.custom.service.ISysVideoClassifyService;
|
||||
import com.stdiet.custom.utils.CookieUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@ -29,18 +34,34 @@ public class VideoWebInterfaceController extends BaseController {
|
||||
@Autowired
|
||||
private ISysNutritionalVideoService sysNutritionalVideoService;
|
||||
|
||||
@Autowired
|
||||
private ISysOrderService iSysOrderService;
|
||||
|
||||
/**
|
||||
* 查询视频分类目录列表
|
||||
*/
|
||||
@GetMapping("/getAllClassify")
|
||||
public TableDataInfo getClassifyAndVideo(SysVideoClassify sysVideoClassify)
|
||||
{
|
||||
public TableDataInfo getClassifyAndVideo(SysVideoClassify sysVideoClassify, HttpServletRequest request) {
|
||||
|
||||
JSONObject result = CookieUtils.checkCookieValida(request, "token");
|
||||
if (result.getInteger("code") != 200) {
|
||||
TableDataInfo errInfo = new TableDataInfo();
|
||||
errInfo.setCode(result.getInteger("code"));
|
||||
errInfo.setMsg(result.getString("msg"));
|
||||
return errInfo;
|
||||
}
|
||||
|
||||
// 检查是否已消费
|
||||
SysOrder order = new SysOrder();
|
||||
order.setPhone(result.getString("phone"));
|
||||
List<SysOrder> orders = iSysOrderService.selectSysOrderList(order);
|
||||
|
||||
//不分页则不需要传pageNum、pageSize参数
|
||||
startPage();
|
||||
//父级分类ID 0表示主分类
|
||||
sysVideoClassify.setParentId(0L);
|
||||
//客户类型 0 未付费客户 1已付费客户
|
||||
sysVideoClassify.setUserType(1);
|
||||
sysVideoClassify.setParentId(sysVideoClassify.getParentId() == null ? 0L : sysVideoClassify.getParentId());
|
||||
//客户类型 0未付费客户-playLevel根据上传的标记 1已付费客户-playLevel全为0
|
||||
sysVideoClassify.setUserType(orders.size() > 0 ? 1 : 0);
|
||||
List<VideoClassifyResponse> list = sysVideoClassifyService.getAllClassifyAndVideo(sysVideoClassify);
|
||||
return getDataTable(list);
|
||||
}
|
||||
@ -48,17 +69,22 @@ public class VideoWebInterfaceController extends BaseController {
|
||||
|
||||
/**
|
||||
* 根据视频videoId获取视频详情以及播放地址
|
||||
*
|
||||
* @param videoId 阿里云中对应videoId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getVideoDetail/{videoId}")
|
||||
public AjaxResult getVideoDetail(@PathVariable("videoId") String videoId)
|
||||
{
|
||||
if(StringUtils.isEmpty(videoId)){
|
||||
public AjaxResult getVideoDetail(@PathVariable("videoId") String videoId, HttpServletRequest request) {
|
||||
JSONObject result = CookieUtils.checkCookieValida(request, "token");
|
||||
if (result.getInteger("code") != 200) {
|
||||
return AjaxResult.error(result.getInteger("code"), result.getString("msg"));
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(videoId)) {
|
||||
return AjaxResult.error("视频加载失败");
|
||||
}
|
||||
SysNutritionalVideo sysNutritionalVideo = sysNutritionalVideoService.selectSysNutritionalVideByVideoId(videoId);
|
||||
if(sysNutritionalVideo == null){
|
||||
if (sysNutritionalVideo == null) {
|
||||
return AjaxResult.error("视频加载失败");
|
||||
}
|
||||
NutritionalVideoResponse nutritionalVideoResponse = new NutritionalVideoResponse();
|
||||
@ -69,7 +95,7 @@ public class VideoWebInterfaceController extends BaseController {
|
||||
//播放地址
|
||||
nutritionalVideoResponse.setPlayUrl(playList.get(0).getPlayURL());
|
||||
}
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return AjaxResult.error("视频加载失败");
|
||||
}
|
||||
@ -91,12 +117,13 @@ public class VideoWebInterfaceController extends BaseController {
|
||||
|
||||
/**
|
||||
* 更新视频播放次数
|
||||
*
|
||||
* @param videoId 阿里云中对应videoId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/updateVideoPlayNum")
|
||||
public AjaxResult updateVideoPlayNum(@RequestParam(value = "videoId") String videoId) {
|
||||
if(StringUtils.isEmpty(videoId)){
|
||||
if (StringUtils.isEmpty(videoId)) {
|
||||
return AjaxResult.error("更新失败");
|
||||
}
|
||||
return toAjax(sysNutritionalVideoService.updateVideoPlayNum(videoId));
|
||||
|
@ -23,6 +23,17 @@ public class VideoResponse implements Serializable {
|
||||
//播放次数
|
||||
private Integer playNum;
|
||||
|
||||
// 播放等级
|
||||
private Integer playLevel;
|
||||
|
||||
public void setPlayLevel(Integer playLevel) {
|
||||
this.playLevel = playLevel;
|
||||
}
|
||||
|
||||
public Integer getPlayLevel() {
|
||||
return playLevel;
|
||||
}
|
||||
|
||||
public String getVideoId() {
|
||||
return videoId;
|
||||
}
|
||||
|
@ -0,0 +1,55 @@
|
||||
package com.stdiet.custom.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.stdiet.common.utils.StringUtils;
|
||||
import com.stdiet.common.utils.sign.AesUtils;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
||||
public class CookieUtils {
|
||||
|
||||
public static String getCookieValue(HttpServletRequest req, String cookieName) {
|
||||
Cookie[] cookies = req.getCookies();
|
||||
if (StringUtils.isNull(cookies)) {
|
||||
return null;
|
||||
}
|
||||
return Arrays.stream(cookies)
|
||||
.filter(c -> c.getName().equals(cookieName))
|
||||
.findFirst()
|
||||
.map(Cookie::getValue)
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public static JSONObject checkCookieValida(HttpServletRequest req, String cookieName) {
|
||||
JSONObject resultObj = new JSONObject();
|
||||
|
||||
String token = getCookieValue(req, "token");
|
||||
if (StringUtils.isEmpty(token)) {
|
||||
resultObj.put("code", 50102);
|
||||
resultObj.put("msg", "请重新登录");
|
||||
return resultObj;
|
||||
}
|
||||
|
||||
String tokenStr = AesUtils.decrypt(token);
|
||||
String[] vals = tokenStr.split("_");
|
||||
String phone = vals[0];
|
||||
Long fromDate = Long.parseLong(vals[1]);
|
||||
String randomCode = vals[2];
|
||||
|
||||
resultObj.put("code", 200);
|
||||
resultObj.put("phone", phone);
|
||||
|
||||
|
||||
if (new Date().getTime() - fromDate > 24 * 60 * 60 * 1000) {
|
||||
resultObj.put("code", 50102);
|
||||
resultObj.put("msg", "请重新登录");
|
||||
return resultObj;
|
||||
}
|
||||
|
||||
return resultObj;
|
||||
}
|
||||
}
|
@ -5,16 +5,16 @@
|
||||
<mapper namespace="com.stdiet.custom.mapper.SysVideoClassifyMapper">
|
||||
|
||||
<resultMap type="SysVideoClassify" id="SysVideoClassifyResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="cateName" column="cate_name" />
|
||||
<result property="parentId" column="parent_id" />
|
||||
<result property="orderNum" column="order_num" />
|
||||
<result property="payFlag" column="pay_flag" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="delFlag" column="del_flag" />
|
||||
<result property="id" column="id"/>
|
||||
<result property="cateName" column="cate_name"/>
|
||||
<result property="parentId" column="parent_id"/>
|
||||
<result property="orderNum" column="order_num"/>
|
||||
<result property="payFlag" column="pay_flag"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="createBy" column="create_by"/>
|
||||
<result property="updateTime" column="update_time"/>
|
||||
<result property="updateBy" column="update_by"/>
|
||||
<result property="delFlag" column="del_flag"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectSysVideoClassifyVo">
|
||||
@ -32,7 +32,7 @@
|
||||
|
||||
<select id="selectSysVideoClassifyById" parameterType="Long" resultMap="SysVideoClassifyResult">
|
||||
<include refid="selectSysVideoClassifyVo"/>
|
||||
where id = #{id} and del_flag = 0
|
||||
where id = #{id} and del_flag = 0
|
||||
</select>
|
||||
|
||||
<insert id="insertSysVideoClassify" parameterType="SysVideoClassify">
|
||||
@ -91,7 +91,8 @@
|
||||
</update>
|
||||
|
||||
<select id="getAllClassify" resultMap="SysVideoClassifyResult" parameterType="SysVideoClassify">
|
||||
select id, cate_name, parent_id, order_num, pay_flag, create_time, create_by, update_time, update_by, del_flag from sys_video_classify
|
||||
select id, cate_name, parent_id, order_num, pay_flag, create_time, create_by, update_time, update_by, del_flag
|
||||
from sys_video_classify
|
||||
where del_flag = 0
|
||||
<if test="parentId != null">
|
||||
and parent_id = #{parentId}
|
||||
@ -100,9 +101,9 @@
|
||||
</select>
|
||||
|
||||
<resultMap type="com.stdiet.custom.dto.response.VideoClassifyResponse" id="VideoClassifyOneResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="cateName" column="cate_name" />
|
||||
<result property="userType" column="userType"></result>
|
||||
<result property="id" column="id"/>
|
||||
<result property="cateName" column="cate_name"/>
|
||||
<result property="userType" column="userType"/>
|
||||
<!-- 查询子分类 -->
|
||||
<association property="childrenClassify" column="{userType=userType,id=id}" select="getTwoAllClassifyAndVideo"/>
|
||||
<!-- 查询子视频 -->
|
||||
@ -110,19 +111,20 @@
|
||||
</resultMap>
|
||||
|
||||
<resultMap type="com.stdiet.custom.dto.response.VideoClassifyResponse" id="VideoClassifyTwoResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="cateName" column="cate_name" />
|
||||
<result property="id" column="id"/>
|
||||
<result property="cateName" column="cate_name"/>
|
||||
<result property="userType" column="userType"></result>
|
||||
<!-- 查询子分类 -->
|
||||
<association property="childrenClassify" column="{userType=userType,id=id}" select="getThreeAllClassifyAndVideo"/>
|
||||
<association property="childrenClassify" column="{userType=userType,id=id}"
|
||||
select="getThreeAllClassifyAndVideo"/>
|
||||
<!-- 查询子视频 -->
|
||||
<association property="childrenVideo" column="{userType=userType,id=id}" select="getAllVideoByClassify"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap type="com.stdiet.custom.dto.response.VideoClassifyResponse" id="VideoClassifyThreeResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="cateName" column="cate_name" />
|
||||
<result property="userType" column="userType" ></result>
|
||||
<result property="id" column="id"/>
|
||||
<result property="cateName" column="cate_name"/>
|
||||
<result property="userType" column="userType"></result>
|
||||
<!-- 查询子视频 -->
|
||||
<association property="childrenVideo" column="{userType=userType,id=id}" select="getAllVideoByClassify"/>
|
||||
</resultMap>
|
||||
@ -146,16 +148,14 @@
|
||||
</select>
|
||||
|
||||
<select id="getAllVideoByClassify" resultType="com.stdiet.custom.dto.response.VideoResponse">
|
||||
select snv.video_id as videoId, snv.title, snv.cover_url as coverUrl,snv.play_num as playNum
|
||||
from sys_nutritional_video snv where cate_id = #{id} and del_flag = 0 and show_flag = 1
|
||||
<if test="userType != null">
|
||||
<if test="userType == 0">
|
||||
and pay_level = 0
|
||||
</if>
|
||||
<if test="userType == 1">
|
||||
and (pay_level = 0 or pay_level = 1)
|
||||
</if>
|
||||
select snv.video_id as videoId, snv.title, snv.cover_url as coverUrl, snv.play_num as playNum
|
||||
<if test="userType == null or userType == 0">
|
||||
, snv.pay_level as playLevel
|
||||
</if>
|
||||
<if test="userType == 1">
|
||||
, 0 as playLevel
|
||||
</if>
|
||||
from sys_nutritional_video snv where cate_id = #{id} and del_flag = 0 and show_flag = 1
|
||||
order by priority_level desc,id asc
|
||||
</select>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user