分页 关联查询 等
This commit is contained in:
parent
4f6079dbb5
commit
c5f1456046
|
|
@ -1,5 +1,6 @@
|
|||
package com.sqx.modules.course.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
|
@ -33,7 +34,7 @@ public class CourseCollectServiceImpl extends ServiceImpl<CourseCollectDao, Cour
|
|||
@Autowired
|
||||
private CourseDetailsService courseDetailsService;
|
||||
|
||||
private ReentrantReadWriteLock reentrantReadWriteLock=new ReentrantReadWriteLock(true);
|
||||
private ReentrantReadWriteLock reentrantReadWriteLock = new ReentrantReadWriteLock(true);
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = "app:courseCollect", key = "#courseCollect.userId")
|
||||
|
|
@ -44,15 +45,18 @@ public class CourseCollectServiceImpl extends ServiceImpl<CourseCollectDao, Cour
|
|||
QueryWrapper<CourseCollect> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("user_id", courseCollect.getUserId()).eq("classify", 3).eq("course_id", courseCollect.getCourseId());
|
||||
queryWrapper.orderByDesc("create_time");
|
||||
queryWrapper.last("limit 1");
|
||||
CourseCollect collect = baseMapper.selectOne(queryWrapper);
|
||||
if (collect != null) {
|
||||
collect.setUpdateTime(DateUtils.format(new Date()));
|
||||
collect.setCourseCollectId(courseCollect.getCourseCollectId());
|
||||
baseMapper.updateById(collect);
|
||||
return Result.success("操作成功!");
|
||||
PageHelper.startPage(1, 1);
|
||||
List<CourseCollect> courseCollects = baseMapper.selectList(queryWrapper);
|
||||
CourseCollect collect;
|
||||
if (CollectionUtil.isNotEmpty(courseCollects)) {
|
||||
collect = courseCollects.get(0);
|
||||
if (collect != null) {
|
||||
collect.setUpdateTime(DateUtils.format(new Date()));
|
||||
collect.setCourseCollectId(courseCollect.getCourseCollectId());
|
||||
baseMapper.updateById(collect);
|
||||
return Result.success("操作成功!");
|
||||
}
|
||||
}
|
||||
|
||||
collect = new CourseCollect()
|
||||
.setUserId(courseCollect.getUserId())
|
||||
.setCourseId(courseCollect.getCourseId())
|
||||
|
|
@ -63,37 +67,37 @@ public class CourseCollectServiceImpl extends ServiceImpl<CourseCollectDao, Cour
|
|||
baseMapper.insert(collect);
|
||||
return Result.success("操作成功!");
|
||||
}
|
||||
CourseCollect courseCollect1 = selectCourseCollectUserIdAnd(courseCollect.getUserId(), courseCollect.getCourseId(),courseCollect.getClassify(),courseCollect.getCourseDetailsId());
|
||||
CourseCollect courseCollect1 = selectCourseCollectUserIdAnd(courseCollect.getUserId(), courseCollect.getCourseId(), courseCollect.getClassify(), courseCollect.getCourseDetailsId());
|
||||
if (courseCollect.getType() == 1) {
|
||||
if(courseCollect1==null){
|
||||
if (courseCollect1 == null) {
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
courseCollect.setCreateTime(df.format(new Date()));
|
||||
courseCollect.setUpdateTime(courseCollect.getCreateTime());
|
||||
baseMapper.insert(courseCollect);
|
||||
if(courseCollect.getClassify()==2){
|
||||
if (courseCollect.getClassify() == 2) {
|
||||
CourseDetails courseDetails = courseDetailsService.getById(courseCollect.getCourseDetailsId());
|
||||
courseDetails.setGoodNum(courseDetails.getGoodNum()+1);
|
||||
courseDetails.setGoodNum(courseDetails.getGoodNum() + 1);
|
||||
courseDetailsService.updateById(courseDetails);
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
courseCollect1.setUpdateTime(DateUtils.format(new Date()));
|
||||
baseMapper.updateById(courseCollect1);
|
||||
}
|
||||
} else {
|
||||
if(courseCollect1!=null){
|
||||
if (courseCollect1 != null) {
|
||||
baseMapper.deleteById(courseCollect1.getCourseCollectId());
|
||||
if(courseCollect.getClassify()==2){
|
||||
if (courseCollect.getClassify() == 2) {
|
||||
CourseDetails courseDetails = courseDetailsService.getById(courseCollect.getCourseDetailsId());
|
||||
courseDetails.setGoodNum(courseDetails.getGoodNum()-1);
|
||||
courseDetails.setGoodNum(courseDetails.getGoodNum() - 1);
|
||||
courseDetailsService.updateById(courseDetails);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Result.success("操作成功!");
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("收藏短剧出错了!"+e.getMessage());
|
||||
}finally {
|
||||
log.error("收藏短剧出错了!" + e.getMessage());
|
||||
} finally {
|
||||
reentrantReadWriteLock.writeLock().unlock();
|
||||
}
|
||||
return Result.error("系统繁忙,请稍后再试!");
|
||||
|
|
@ -101,12 +105,12 @@ public class CourseCollectServiceImpl extends ServiceImpl<CourseCollectDao, Cour
|
|||
|
||||
@Override
|
||||
@CachePut(value = "app:courseCollect", key = "#userId")
|
||||
public Result selectByUserId(Integer page, Integer limit, Long userId,Integer classify) {
|
||||
PageHelper.startPage(page,limit);
|
||||
List<Course> courseList = baseMapper.selectCourseByCollect( userId,classify);
|
||||
public Result selectByUserId(Integer page, Integer limit, Long userId, Integer classify) {
|
||||
PageHelper.startPage(page, limit);
|
||||
List<Course> courseList = baseMapper.selectCourseByCollect(userId, classify);
|
||||
PageInfo<Course> pageInfo = new PageInfo<>(courseList);
|
||||
List<Course> courses = pageInfo.getList();
|
||||
if (courses != null && courses.size() > 0) {
|
||||
if (CollectionUtil.isNotEmpty(courseList)) {
|
||||
List<Course> courses = pageInfo.getList();
|
||||
for (Course course : courses) {
|
||||
course.setCourseClassification(courseClassificationDao.selectById(course.getClassifyId()));
|
||||
}
|
||||
|
|
@ -116,8 +120,8 @@ public class CourseCollectServiceImpl extends ServiceImpl<CourseCollectDao, Cour
|
|||
|
||||
|
||||
@Override
|
||||
public CourseCollect selectCourseCollectUserIdAnd(Long userId,Long courseId,Integer classify,Long courseDetailsId){
|
||||
return baseMapper.selectOne(new QueryWrapper<CourseCollect>().eq(courseDetailsId!=null,"course_details_id",courseDetailsId).eq("user_id",userId).eq("classify",classify).eq("course_id",courseId));
|
||||
public CourseCollect selectCourseCollectUserIdAnd(Long userId, Long courseId, Integer classify, Long courseDetailsId) {
|
||||
return baseMapper.selectOne(new QueryWrapper<CourseCollect>().eq(courseDetailsId != null, "course_details_id", courseDetailsId).eq("user_id", userId).eq("classify", classify).eq("course_id", courseId));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -247,7 +247,6 @@ public class CourseDetailsServiceImpl extends ServiceImpl<CourseDetailsDao, Cour
|
|||
|
||||
@Override
|
||||
public Result selectCourseDetailsList(Integer page, Integer limit, String token, String randomNum, Integer wxShow, Integer dyShow) {
|
||||
PageHelper.startPage(page, limit);
|
||||
Long userId = null;
|
||||
if (StringUtils.isNotEmpty(token)) {
|
||||
Claims claims = jwtUtils.getClaimByToken(token);
|
||||
|
|
@ -258,6 +257,7 @@ public class CourseDetailsServiceImpl extends ServiceImpl<CourseDetailsDao, Cour
|
|||
if(!Validator.isNumber(randomNum)){
|
||||
throw new SqxException("随机码必须是数字");
|
||||
};
|
||||
PageHelper.startPage(page, limit);
|
||||
List<CourseDetails> list = baseMapper.selectCourseDetailsList(randomNum, wxShow, dyShow);
|
||||
PageInfo<CourseDetails> pageInfo = new PageInfo<>(list);
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ package com.sqx.modules.discSpinning.controller;
|
|||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.sqx.common.utils.PageUtils;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.annotation.Login;
|
||||
import com.sqx.modules.discSpinning.entity.DiscSpinningRecord;
|
||||
|
|
@ -13,6 +16,8 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Api(value = "大转盘抽奖记录", tags = {"大转盘抽奖记录"})
|
||||
|
|
@ -33,8 +38,10 @@ public class DiscSpinningRecordController {
|
|||
@Login
|
||||
@GetMapping("/selectDiscSpinningRecord")
|
||||
@ApiOperation("查询大转盘抽奖记录")
|
||||
public Result selectDiscSpinningRecord(Integer page, Integer limit,@RequestAttribute("userId") Long userId) {
|
||||
return Result.success().put("data", discSpinningRecordService.page(new Page<>(page, limit), new QueryWrapper<DiscSpinningRecord>().eq("user_id",userId).orderByDesc("create_time")));
|
||||
public Result selectDiscSpinningRecord(Integer page, Integer limit, @RequestAttribute("userId") Long userId) {
|
||||
PageHelper.startPage(page, limit);
|
||||
List<DiscSpinningRecord> list = discSpinningRecordService.list(new QueryWrapper<DiscSpinningRecord>().eq("user_id", userId).orderByDesc("create_time"));
|
||||
return Result.success().put("data", PageUtils.page(new PageInfo<>(list), true));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package com.sqx.modules.discSpinning.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldStrategy;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import lombok.Data;
|
||||
|
|
@ -20,6 +22,7 @@ public class DiscSpinningRecord extends Model<DiscSpinningRecord> {
|
|||
|
||||
private Long sourceId;
|
||||
|
||||
@TableField(updateStrategy = FieldStrategy.NEVER)
|
||||
private Long userId;
|
||||
private String imgUrl;
|
||||
//描述
|
||||
|
|
|
|||
|
|
@ -55,22 +55,8 @@
|
|||
|
||||
<select id="selectCourseDetailsList" resultType="com.sqx.modules.course.entity.CourseDetails">
|
||||
select cd.*,
|
||||
MD5( `course_details_id` ) AS `uid`
|
||||
MD5(`course_details_id`) AS `uid`
|
||||
from course_details cd
|
||||
left join course c on c.course_id=cd.course_id
|
||||
where c.course_id is not null and c.is_delete=0 and cd.good=1
|
||||
<if test='null != wxShow and wxShow==1'>
|
||||
and c.wx_show = #{wxShow}
|
||||
</if>
|
||||
<if test='null != wxShow and wxShow==2'>
|
||||
and (c.wx_show = #{wxShow} or c.wx_show is null)
|
||||
</if>
|
||||
<if test='null != dyShow and dyShow==1'>
|
||||
and c.dy_show = #{dyShow}
|
||||
</if>
|
||||
<if test='null != dyShow and dyShow==2'>
|
||||
and (c.dy_show = #{dyShow} or c.dy_show is null)
|
||||
</if>
|
||||
order by SUBSTR(uid, ${randomNum}, 6)
|
||||
</select>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue