package com.srs.web.controller.comprehensive;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.srs.comprehensive.domain.SrsMajors;
import com.srs.comprehensive.domain.SrsStudent;
import com.srs.comprehensive.service.ICascaderDataStudentService;
import com.srs.comprehensive.service.ISrsMajorsService;
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.srs.common.annotation.Log;
import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.enums.BusinessType;

import com.srs.common.utils.poi.ExcelUtil;
import com.srs.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author srs
 * @date 2023-06-27
 */
@RestController
@RequestMapping("/system/majors")
public class SrsMajorsController extends BaseController
{
    @Autowired
    private ISrsMajorsService srsMajorsService;
    @Resource
    private ICascaderDataStudentService cascaderDataStudentService;
    /**
     * 查询【请填写功能名称】列表
     */
//    @PreAuthorize("@ss.hasPermi('system:majors:list')")
    @GetMapping("/list")
    public TableDataInfo list(SrsMajors srsMajors)
    {
        startPage();
        List<SrsMajors> list = srsMajorsService.selectSrsMajorsList(srsMajors);
        return getDataTable(list);
    }
    /**
     * 查询专业名字列表 以及所有上级
     */

    @GetMapping("/name")
    public AjaxResult listNameAll()
    {

        return AjaxResult.success(cascaderDataStudentService.getCascadeData(2));

    }

    /**
     * 导出【请填写功能名称】列表
     */
//    @PreAuthorize("@ss.hasPermi('system:majors:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SrsMajors srsMajors)
    {
        List<SrsMajors> list = srsMajorsService.selectSrsMajorsList(srsMajors);
        ExcelUtil<SrsMajors> util = new ExcelUtil<SrsMajors>(SrsMajors.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:majors:query')")
    @GetMapping(value = "/{majorId}")
    public AjaxResult getInfo(@PathVariable("majorId") Long majorId)
    {
        return success(srsMajorsService.selectSrsMajorsByMajorId(majorId));
    }

    /**
     * 新增【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('system:majors:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SrsMajors srsMajors)
    {
        return toAjax(srsMajorsService.insertSrsMajors(srsMajors));
    }

    /**
     * 修改【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('system:majors:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody SrsMajors srsMajors)
    {
        return toAjax(srsMajorsService.updateSrsMajors(srsMajors));
    }

    /**
     * 删除【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('system:majors:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@PostMapping("/delete/{majorIds}")
    public AjaxResult remove(@PathVariable Long[] majorIds)
    {
        return toAjax(srsMajorsService.deleteSrsMajorsByMajorIds(majorIds));
    }

    @PostMapping("/dataSync")
    public AjaxResult dataSync(){
        return  AjaxResult.success(srsMajorsService.dataSync());
    }

}
