package com.fs.company.controller.course;

import com.alibaba.fastjson.JSON;
import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.DateUtils;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.course.domain.FsCourseFinishTemp;
import com.fs.course.service.IFsCourseFinishTempService;
import com.fs.course.vo.FsCourseFinishTempListVO;
import com.fs.framework.security.LoginUser;
import com.fs.framework.security.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 完课模板Controller
 *
 * @author fs
 * @date 2024-12-19
 */
@RestController
@RequestMapping("/course/courseFinishTemp")
public class FsCourseFinishTempController extends BaseController
{
    @Autowired
    private IFsCourseFinishTempService fsCourseFinishTempService;

    /**
     * 查询完课模板列表
     */
    @PreAuthorize("@ss.hasPermi('courseFinishTemp:course:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsCourseFinishTemp fsCourseFinishTemp)
    {
        startPage();

        LoginUser loginUser = SecurityUtils.getLoginUser();
        fsCourseFinishTemp.setCompanyId(loginUser.getCompany().getCompanyId());
        List<FsCourseFinishTempListVO> list = fsCourseFinishTempService.selectFsCourseFinishTempListVO(fsCourseFinishTemp);
        return getDataTable(list);
    }


    /**
     * 导出完课模板列表
     */
    @PreAuthorize("@ss.hasPermi('courseFinishTemp:course:export')")
    @Log(title = "完课模板", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsCourseFinishTemp fsCourseFinishTemp)
    {
        List<FsCourseFinishTemp> list = fsCourseFinishTempService.selectFsCourseFinishTempList(fsCourseFinishTemp);
        ExcelUtil<FsCourseFinishTemp> util = new ExcelUtil<FsCourseFinishTemp>(FsCourseFinishTemp.class);
        return util.exportExcel(list, "完课模板数据");
    }

    /**
     * 获取完课模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('courseFinishTemp:course:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
//        return AjaxResult.success(fsCourseFinishTempService.selectFsCourseFinishTempById(id));
        return AjaxResult.success(fsCourseFinishTempService.selectFsCourseFinishTempByIdVO(id));
    }

    /**
     * 新增完课模板
     */
    @PreAuthorize("@ss.hasPermi('courseFinishTemp:course:add')")
    @Log(title = "完课模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsCourseFinishTemp fsCourseFinishTemp)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        fsCourseFinishTemp.setCompanyId(loginUser.getCompany().getCompanyId());
        fsCourseFinishTemp.setCreateBy(String.valueOf(loginUser.getUser().getUserId()));
        return toAjax(fsCourseFinishTempService.insertFsCourseFinishTemp(fsCourseFinishTemp));
    }

    /**
     * 修改完课模板
     */
    @PreAuthorize("@ss.hasPermi('courseFinishTemp:course:edit')")
    @Log(title = "完课模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsCourseFinishTemp fsCourseFinishTemp)
    {
        return toAjax(fsCourseFinishTempService.updateFsCourseFinishTemp(fsCourseFinishTemp));
    }

    /**
     * 删除完课模板
     */
    @PreAuthorize("@ss.hasPermi('courseFinishTemp:course:remove')")
    @Log(title = "完课模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fsCourseFinishTempService.deleteFsCourseFinishTempByIds(ids));
    }


    @Log(title = "完课模板", businessType = BusinessType.UPDATE)
    @PostMapping("/updateStatusBatch")
    public AjaxResult updateStatusBatch(@RequestBody FsCourseFinishTemp fsCourseFinishTemp)
    {
        fsCourseFinishTemp.setUpdateTime(DateUtils.getNowDate());

        return toAjax(fsCourseFinishTempService.updateFsCourseFinishTempBatch(fsCourseFinishTemp));
    }

}
