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 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.UserCourseAnswerVo;
import com.zhongzheng.modules.user.bo.UserCourseAnswerQueryBo;
import com.zhongzheng.modules.user.bo.UserCourseAnswerAddBo;
import com.zhongzheng.modules.user.bo.UserCourseAnswerEditBo;
import com.zhongzheng.modules.user.service.IUserCourseAnswerService;
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-15
 */
@Api(value = "答疑控制器", tags = {"答疑管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/app/answer")
public class UserCourseAnswerController extends BaseController {

    private final IUserCourseAnswerService iUserCourseAnswerService;

    private final WxTokenService wxTokenService;
    /**
     * 查询答疑列表
     */
    @ApiOperation("查询答疑列表")
    @GetMapping("/list")
    public TableDataInfo<UserCourseAnswerVo> list(UserCourseAnswerQueryBo bo) {
        startPage();
        List<UserCourseAnswerVo> list = iUserCourseAnswerService.queryList(bo);
        return getDataTable(list);
    }


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

    /**
     * 修改答疑
     */
    @ApiOperation("修改答疑")
    @Log(title = "答疑", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult<Void> edit(@RequestBody UserCourseAnswerEditBo bo) {
        return toAjax(iUserCourseAnswerService.updateByEditBo(bo) ? 1 : 0);
    }


}
