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.service.impl.YjInheritServiceImpl;
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 = "031-瑜伽传承", description = "提供瑜伽传承相关的API")
@RestController
@RequestMapping("/api/inherit")
public class InheritController {

    @Resource
    private YjInheritServiceImpl inheritService;

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

}
