package com.dayou.controller;

import com.dayou.annotation.OperLog;
import com.dayou.vo.NoteCountVO;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.RestController;
import com.dayou.controller.BaseController;
import com.dayou.service.INoteService;
import com.dayou.entity.Note;
import com.dayou.common.RestResponse;
import org.springframework.web.bind.annotation.*;
import com.dayou.utils.ConvertUtil;
import com.dayou.utils.HttpKit;
import com.dayou.exception.ErrorCode;
import java.util.Date;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.http.MediaType;
import org.springframework.web.multipart.MultipartFile;
/**
 * 便签
 *
 * @author wucl
 * @since 2023-01-12
 */
@RestController
@RequestMapping("note")
@Slf4j
public class NoteController extends BaseController {
    @Autowired
    private INoteService noteService;

    /**
    * 便签列表
    */
    @GetMapping("")
    public RestResponse<Page<Note>> page(Note note, Page page){
        Page<Note> pages=noteService.selectPage(page,note);
        return RestResponse.data(pages);
    }

    /**
     * 便签详情
     */
    @GetMapping("/{id}")
    public RestResponse<Note> detail(@PathVariable Long id){
        Note xNote =noteService.detail(id);
        return RestResponse.data(xNote);
     }

    /**
     * 便签新增
     */
    @OperLog(title = "新增便签")
    @PostMapping("")
    public RestResponse<Boolean> save(@RequestBody Note note) {
        Boolean ret = noteService.add(note);
        return RestResponse.data(ret);
    }

    /**
     * 便签更新
     */
    @OperLog(title = "更新便签")
    @PutMapping("")
    public RestResponse<Boolean> update(@RequestBody Note note) {
        Boolean ret = noteService.update(note);
        return RestResponse.data(ret);
    }

    /**
     * 便签删除
     */
    @OperLog(title = "删除便签")
    @DeleteMapping("/{id}")
    public RestResponse<Boolean> delete(@PathVariable Long id) {
        Boolean ret = noteService.delete(id);
        return RestResponse.data(ret);
    }

    /**
     * 单日便签列表
     */
    @GetMapping("/list")
    public RestResponse<List<Note>> list(Note note){
        List<Note> list = noteService.getList(note);
        return RestResponse.data(list);
    }

    /**
     * 每日便签数量
     */
    @GetMapping("/count/{userId}")
    public RestResponse<List<NoteCountVO>> list(@PathVariable("userId") Long userId){
        List<NoteCountVO> result = noteService.getCount(userId);
        return RestResponse.data(result);
    }
}

