package com.ruoyi.web.controller.basic;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.ruoyi.RestResponse;
import com.ruoyi.basic.domain.YjInherit;
import com.ruoyi.basic.domain.YjPracticeMoments;
import com.ruoyi.basic.service.impl.YjPracticeMomentsServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 练习瞬间
 */
@Api(tags = "033-练习瞬间", description = "提供练习瞬间相关的API")
@RestController
@RequestMapping("/api/moments")
public class PracticeMomentsController {

    @Resource
    private YjPracticeMomentsServiceImpl momentsService;

    /**
     * 练习瞬间列表
     * @param visitStore
     * @return
     */
    @ApiOperation(value = "获取练习瞬间列表")
    @PostMapping("/getList")
    public RestResponse getList(@RequestBody  Map map){
        Long visitStore=Long.parseLong(map.get("visitStore").toString());
        List<YjPracticeMoments> list=momentsService.list(new QueryWrapper<YjPracticeMoments>()
                .select("id,title,image,read_num,start_time,modify_time")
                .eq("dept_id",visitStore)
                .eq("status",true)
                .orderByDesc("modify_time"));
        return new RestResponse().setSuccess(true).setMessage("成功").setData(list);
    }

    /**
     * 练习瞬间详情
     * @param moments
     * @return
     */
    @ApiOperation(value = "获取练习瞬间详情")
    @PostMapping("/getOne")
    public RestResponse getOne(@RequestBody YjPracticeMoments moments){
        momentsService.update(new UpdateWrapper<YjPracticeMoments>()
                .setSql("read_num=read_num+1")
                .eq("id",moments.getId()));//阅读量
        YjPracticeMoments m=momentsService.getOne(new QueryWrapper<YjPracticeMoments>()
                .eq("id",moments.getId()));
        return new RestResponse().setSuccess(true).setMessage("成功").setData(m);
    }
}
