package com.zhongzheng.controller.course;

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.course.bo.CoursePhotoLogAddBo;
import com.zhongzheng.modules.course.bo.CoursePhotoLogQueryBo;
import com.zhongzheng.modules.course.bo.CourseQueryBo;
import com.zhongzheng.modules.course.service.ICoursePhotoLogService;
import com.zhongzheng.modules.course.vo.CoursePhotoLogVo;
import com.zhongzheng.modules.user.entity.ClientLoginUser;
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.common.utils.poi.ExcelUtil;
import com.zhongzheng.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 用户节拍照记录Controller
 *
 * @author hjl
 * @date 2022-01-12
 */
@Api(value = "用户节拍照记录控制器", tags = {"用户节拍照记录管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/course/photo/log")
public class CoursePhotoLogController extends BaseController {

    private final ICoursePhotoLogService iCoursePhotoLogService;


    private final WxTokenService wxTokenService;


    /**
     * 获取用户节拍照记录详细信息
     */
    @ApiOperation("获取用户节拍照记录最后详细信息")
    @GetMapping("/getLastInfo")
    public AjaxResult<List<CoursePhotoLogVo>> getLastInfo(CoursePhotoLogQueryBo bo) {
        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        return AjaxResult.success(iCoursePhotoLogService.getLastInfo(bo));
    }
    /**
     * 新增用户节拍照记录
     */
    @ApiOperation("新增用户节拍照记录")
    @Log(title = "用户节拍照记录", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody CoursePhotoLogAddBo bo) {
        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        return toAjax(iCoursePhotoLogService.insertByAddBo(bo) ? 1 : 0);
    }

}
