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.YjHealthy;
import com.ruoyi.basic.service.impl.YjHealthyServiceImpl;
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 = "036-健康饮食", description = "提供健康饮食相关的API")
@RestController
@RequestMapping("/api/healthy")
public class HealthyController {
    @Resource
    private YjHealthyServiceImpl service;

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

    /**
     * 健康饮食详情
     * @param healthy
     * @return
     */
    @ApiOperation(value = "健康饮食详情")
    @PostMapping("/getOne")
    public RestResponse getOne(@RequestBody YjHealthy healthy){
        service.update(new UpdateWrapper<YjHealthy>()
                .setSql("read_num=read_num+1")
                .eq("id",healthy.getId()));//阅读量
        YjHealthy i=service.getById(healthy.getId());
        return new RestResponse().setSuccess(true).setMessage("成功").setData(i);
    }
}
