package com.zhongzheng.controller.user;

import java.util.List;
import java.util.Arrays;

import com.zhongzheng.common.utils.ServletUtils;
import com.zhongzheng.framework.web.service.WxTokenService;
import com.zhongzheng.modules.user.entity.ClientLoginUser;
import com.zhongzheng.modules.user.vo.UserDateNoteVo;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhongzheng.common.annotation.Log;
import com.zhongzheng.common.core.controller.BaseController;
import com.zhongzheng.common.core.domain.AjaxResult;
import com.zhongzheng.common.enums.BusinessType;
import com.zhongzheng.modules.user.vo.UserNoteVo;
import com.zhongzheng.modules.user.bo.UserNoteQueryBo;
import com.zhongzheng.modules.user.bo.UserNoteAddBo;
import com.zhongzheng.modules.user.bo.UserNoteEditBo;
import com.zhongzheng.modules.user.service.IUserNoteService;
import com.zhongzheng.common.utils.poi.ExcelUtil;
import com.zhongzheng.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 用户笔记记录Controller
 *
 * @author ruoyi
 * @date 2021-12-14
 */
@Api(value = "用户笔记记录控制器", tags = {"用户笔记记录管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/user/note")
public class UserNoteController extends BaseController {

    private final IUserNoteService iUserNoteService;

    private final WxTokenService wxTokenService;

    /**
     * 查询用户笔记记录列表
     */
    @ApiOperation("查询用户笔记记录列表")
    @GetMapping("/listDate")
    public TableDataInfo<UserDateNoteVo> listDate(UserNoteQueryBo bo) {
        startPage();
        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        List<UserDateNoteVo> list = iUserNoteService.listDate(bo);
        return getDataTable(list);
    }


    /**
     * 新增用户笔记记录
     */
    @ApiOperation("新增用户笔记记录")
    @Log(title = "用户笔记记录", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody UserNoteAddBo bo) {
        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        return toAjax(iUserNoteService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改用户笔记记录
     */
    @ApiOperation("修改用户笔记记录")
    @Log(title = "用户笔记记录", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult<Void> edit(@RequestBody UserNoteEditBo bo) {
        return toAjax(iUserNoteService.updateByEditBo(bo) ? 1 : 0);
    }

}
