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.YjAppreciate;
import com.ruoyi.basic.service.impl.YjAppreciateServiceImpl;
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 = "034-瑜伽欣赏", description = "提供瑜伽欣赏相关的API")
@RestController
@RequestMapping("/api/appreciate")
public class AppreciateController {

    @Resource
    private YjAppreciateServiceImpl service;

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