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.YjSense;
import com.ruoyi.basic.service.impl.YjSenseServiceImpl;
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 = "035-瑜伽常识", description = "提供瑜伽常识相关的API")
@RestController
@RequestMapping("/api/sense")
public class SenseController {
    @Resource
    private YjSenseServiceImpl service;

    /**
     * 瑜伽常识 列表
     * @param visitStore
     * @return
     */
    @ApiOperation(value = "获取瑜伽常识列表")
    @PostMapping("/getList")
    public RestResponse getList(@RequestBody Map map){
        Long visitStore=Long.parseLong(map.get("visitStore").toString());
        List<YjSense> list= service.list(new QueryWrapper<YjSense>()
                .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 sense
     * @return
     */
    @ApiOperation(value = "瑜伽常识详情")
    @PostMapping("/getOne")
    public RestResponse getOne(@RequestBody YjSense sense){
        service.update(new UpdateWrapper<YjSense>()
                .setSql("read_num=read_num+1")
                .eq("id",sense.getId()));//阅读量
        YjSense i=service.getById(sense.getId());
        return new RestResponse().setSuccess(true).setMessage("成功").setData(i);
    }
}
