package com.yunyan.web.controller.business;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.yunyan.common.annotation.Log;
import com.yunyan.common.core.controller.BaseController;
import com.yunyan.common.core.domain.AjaxResult;
import com.yunyan.common.enums.BusinessType;
import com.yunyan.business.domain.CourseCode;
import com.yunyan.business.service.ICourseCodeService;
import com.yunyan.common.utils.poi.ExcelUtil;
import com.yunyan.common.core.page.TableDataInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.yunyan.common.core.domain.AjaxResultVo;
import com.yunyan.common.utils.SecurityUtils;
import java.util.Date;

/**
 * 科目编码管理Controller
 *
 * @author yunyan
 * @date 2023-07-31
 */
@Api(tags = "4.0.4科目编码管理")
@RestController
@RequestMapping("/business/courseCode")
public class CourseCodeController extends BaseController
{
    @Autowired
    private ICourseCodeService courseCodeService;

    /**
     * 查询科目编码管理列表
     */
    @ApiOperation(value="查询科目编码管理列表", notes="查询科目编码管理列表")
    @PreAuthorize("@ss.hasPermi('business:courseCode:list')")
    @GetMapping("/list")
    public TableDataInfo<CourseCode> list(CourseCode courseCode)
    {
        startPage();
        List<CourseCode> list = courseCodeService.selectCourseCodeList(courseCode);
        return getDataTable(list);
    }

    /**
     * 导出科目编码管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:courseCode:export')")
    @Log(title = "科目编码管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CourseCode courseCode)
    {
        List<CourseCode> list = courseCodeService.selectCourseCodeList(courseCode);
        ExcelUtil<CourseCode> util = new ExcelUtil<CourseCode>(CourseCode.class);
        util.exportExcel(response, list, "科目编码管理数据");
    }

    /**
     * 获取科目编码管理详细信息
     */
    @ApiOperation(value="获取科目编码管理详细信息", notes="获取科目编码管理详细信息")
    @PreAuthorize("@ss.hasPermi('business:courseCode:query')")
    @GetMapping(value = "/detail/{id}")
    public AjaxResultVo getInfo(@PathVariable("id") Long id)
    {
        return AjaxResultVo.success(courseCodeService.getById(id));
    }

    /**
     * 新增科目编码管理
     */
    @ApiOperation(value="新增科目编码管理", notes="新增科目编码管理")
    @PreAuthorize("@ss.hasPermi('business:courseCode:add')")
    @Log(title = "科目编码管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody CourseCode dto)
    {
        return toAjax(courseCodeService.save(dto));
    }

    /**
     * 修改科目编码管理
     */
    @ApiOperation(value="修改科目编码管理", notes="修改科目编码管理")
    @PreAuthorize("@ss.hasPermi('business:courseCode:edit')")
    @Log(title = "科目编码管理", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody CourseCode dto)
    {
        return toAjax(courseCodeService.updateById(dto));
    }

    /**
     * 删除科目编码管理
     */
    @ApiOperation(value="删除科目编码管理", notes="删除科目编码管理")
    @PreAuthorize("@ss.hasPermi('business:courseCode:remove')")
    @Log(title = "科目编码管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(courseCodeService.removeByIds(Arrays.asList(ids)));
    }

}
