package com.zhongzheng.controller.inform;

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

import com.zhongzheng.modules.course.bo.CourseQueryBo;
import com.zhongzheng.modules.course.vo.CourseUserEducationTypeVo;
import com.zhongzheng.modules.course.vo.CourseVo;
import com.zhongzheng.modules.goods.bo.GoodsAttachedQueryBo;
import com.zhongzheng.modules.goods.bo.GoodsQueryBo;
import com.zhongzheng.modules.goods.domain.Goods;
import com.zhongzheng.modules.goods.vo.GoodsAttachedVo;
import com.zhongzheng.modules.grade.bo.ClassGradeQueryBo;
import com.zhongzheng.modules.grade.service.IClassGradeService;
import com.zhongzheng.modules.grade.vo.ClassGradeStudentVo;
import com.zhongzheng.modules.grade.vo.ClassGradeUserListVo;
import com.zhongzheng.modules.grade.vo.ClassGradeVo;
import com.zhongzheng.modules.inform.bo.InformUserQueryBo;
import com.zhongzheng.modules.inform.service.IInformUserService;
import com.zhongzheng.modules.inform.vo.CourseInformVo;
import com.zhongzheng.modules.inform.vo.GoodsInformAttachedVo;
import com.zhongzheng.modules.inform.vo.InformUserVo;
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.inform.vo.InformVo;
import com.zhongzheng.modules.inform.bo.InformQueryBo;
import com.zhongzheng.modules.inform.bo.InformAddBo;
import com.zhongzheng.modules.inform.bo.InformEditBo;
import com.zhongzheng.modules.inform.service.IInformService;
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-11-23
 */
@Api(value = "【通知】控制器", tags = {"【通知】管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/inform")
public class InformController extends BaseController {

    private final IInformService iInformService;

    private final IClassGradeService iClassGradeService;

    private final IInformUserService iInformUserService;

    /**
     * 查询【通知】列表
     */
    @ApiOperation("查询【通知】列表")
    @PreAuthorize("@ss.hasPermi('system:inform:list')")
    @GetMapping("/list")
    public TableDataInfo<InformVo> list(InformQueryBo bo) {
        startPage();
        List<InformVo> list = iInformService.listInform(bo);
        return getDataTable(list);
    }

    /**
     * 查询通知绑定学员列表
     */
    @ApiOperation("查询通知绑定学员列表")
    @PreAuthorize("@ss.hasPermi('system:user:list')")
    @GetMapping("/listInformUser")
    public TableDataInfo<InformUserVo> list(InformUserQueryBo bo) {
        startPage();
        List<InformUserVo> list = iInformUserService.queryUserList(bo);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
 /*   @ApiOperation("导出【请填写功能名称】列表")
    @PreAuthorize("@ss.hasPermi('system:inform:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<InformVo> export(InformQueryBo bo) {
        List<InformVo> list = iInformService.listInform(bo);
        ExcelUtil<InformVo> util = new ExcelUtil<InformVo>(InformVo.class);
        return util.exportExcel(list, "通知");
    }*/

    /**
     * 获取【通知】详细信息
     */
    @ApiOperation("获取【通知】详细信息")
    @PreAuthorize("@ss.hasPermi('system:inform:query')")
    @GetMapping("/{informId}")
    public AjaxResult<InformVo> getInfo(@PathVariable("informId" ) Long informId) {
        return AjaxResult.success(iInformService.queryById(informId));
    }

    /**
     * 新增【通知】
     */
    @ApiOperation("新增【通知】")
    @PreAuthorize("@ss.hasPermi('system:inform:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody InformAddBo bo) {
        return toAjax(iInformService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 查询班级列表
     */
    @ApiOperation("查询班级列表下的学员")
    @PreAuthorize("@ss.hasPermi('system:grade:list')")
    @GetMapping("/listGrade")
    public TableDataInfo<ClassGradeUserListVo> listGradeInform(ClassGradeQueryBo bo) {
        startPage();
        List<ClassGradeUserListVo> list = iClassGradeService.listGradeInform(bo);
        return getDataTable(list);
    }

    /**
     * 查询班级列表
     */
    @ApiOperation("查询未分班下的学员")
    @PreAuthorize("@ss.hasPermi('system:grade:list')")
    @GetMapping("/listGradeStudy")
    public TableDataInfo<ClassGradeStudentVo> listGradeStudy(ClassGradeQueryBo bo) {
        startPage();
        List<ClassGradeStudentVo> list = iClassGradeService.listGradeStudy(bo);
        return getDataTable(list);
    }


    /**
     * 查询业务层次下的学员
     */
    @ApiOperation("查询业务层次下的学员")
    @PreAuthorize("@ss.hasPermi('system:grade:list')")
    @GetMapping("/listGradeService")
    public TableDataInfo<CourseUserEducationTypeVo> listGradeService(ClassGradeQueryBo bo) {
        startPage();
        List<CourseUserEducationTypeVo> list = iClassGradeService.listGradeService(bo);
        return getDataTable(list);
    }

    /**
     * 查询商品課程列表
     */
    @ApiOperation("查询商品課程列表")
    @PreAuthorize("@ss.hasPermi('system:course:list')")
    @GetMapping("/listGoodsCourse")
    public TableDataInfo<CourseInformVo> listGoodsCourse(GoodsQueryBo bo) {
        startPage();
        List<CourseInformVo> list = iInformService.listGoodsCourse(bo);
        return getDataTable(list);
    }



    /**
     * 查询题目业务层次关系列表
     */
    @ApiOperation("查询商品题库列表")
    @PreAuthorize("@ss.hasPermi('system:business:list')")
    @GetMapping("/bank/list")
    public AjaxResult<List<GoodsInformAttachedVo>> bankList(GoodsAttachedQueryBo bo) {
        List<GoodsInformAttachedVo> list = iInformService.bankList(bo);
        return AjaxResult.success(list);
    }


    /**
     * 有多少学员无该课程或题库
     */
    @ApiOperation("有多少学员无该课程或题库")
    @PreAuthorize("@ss.hasPermi('grade:grade:select')")
    @PostMapping("/selectNum")
    public AjaxResult<Integer> selectNum(@RequestBody InformAddBo bo) {
        Integer Num = iInformService.selectNum(bo);

        return AjaxResult.success(Num);
    }

    /**
     * 修改【通知】
     */
    @ApiOperation("修改【通知】")
    @PreAuthorize("@ss.hasPermi('system:inform:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult<Void> edit(@RequestBody InformEditBo bo) {
        return toAjax(iInformService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 修改【请填写功能名称】
     */
    @ApiOperation("修改【分类】，重修發送失敗人員")
    @PreAuthorize("@ss.hasPermi('system:inform:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("editClassifyId")
    public AjaxResult<Void> editClassifyId(@RequestBody InformEditBo bo) {
        return toAjax(iInformService.editClassifyId(bo) ? 1 : 0);
    }

}
