package com.miaxis.app.xxx.controller;

import com.miaxis.app.xxx.domain.TMClassRecordDetail;
import com.miaxis.app.xxx.service.ITMClassRecordDetailService;
import com.miaxis.common.annotation.Log;
import com.miaxis.common.core.controller.BaseController;
import com.miaxis.common.core.domain.Response;
import com.miaxis.common.core.page.ResponsePageInfo;
import com.miaxis.common.enums.BusinessTypeEnum;
import com.miaxis.common.utils.poi.ExcelUtil;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 【电子教学日志】Controller
 *
 * @author miaxis
 * @date 2021-01-11
 */
@RestController
@RequestMapping("/xxx/detail")
@Api(tags={"【app-电子教学日志】"})
public class TMClassRecordDetailController extends BaseController{
    @Autowired
    private ITMClassRecordDetailService tMClassRecordDetailService;

    /**
     * 查询电子教学日志列表
     */
    //@PreAuthorize("@ss.hasPermi('xxx:detail:list')")
    @GetMapping("/list")
    @ApiOperation("查询电子教学日志列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
    })
    public ResponsePageInfo<TMClassRecordDetail> list(@ModelAttribute TMClassRecordDetail tMClassRecordDetail){
        startPage();
        List<TMClassRecordDetail> list = tMClassRecordDetailService.queryList(tMClassRecordDetail);
        return toResponsePageInfo(list);
    }

    /**
     * 导出电子教学日志列表
     */
   // @PreAuthorize("@ss.hasPermi('xxx:detail:export')")
    @Log(title = "电子教学日志", businessType = BusinessTypeEnum.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出电子教学日志列表Excel")
    public Response<String> export(@ModelAttribute TMClassRecordDetail tMClassRecordDetail){
        List<TMClassRecordDetail> list = tMClassRecordDetailService.queryList(tMClassRecordDetail);
        ExcelUtil<TMClassRecordDetail> util = new ExcelUtil<TMClassRecordDetail>(TMClassRecordDetail.class);
        return util.exportExcel(list, "detail");
    }

    /**
     * 获取电子教学日志详细信息
     */
    //@PreAuthorize("@ss.hasPermi('xxx:detail:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取电子教学日志详细信息")
    public Response<TMClassRecordDetail> getInfo(
            @ApiParam(name = "id", value = "电子教学日志参数", required = true)
            @PathVariable("id") Long id
    ){
        return Response.success(tMClassRecordDetailService.getById(id));
    }

    /**
     * 新增电子教学日志
     */
    //@PreAuthorize("@ss.hasPermi('xxx:detail:add')")
    @Log(title = "电子教学日志", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    @ApiOperation("新增电子教学日志")
    public Response<Integer> add(@RequestBody TMClassRecordDetail tMClassRecordDetail){
        if (tMClassRecordDetail == null){
            return Response.error();
        }
        return toResponse(tMClassRecordDetailService.save(tMClassRecordDetail) ? 1 : 0);
    }

    /**
     * 修改电子教学日志
     */
    //@PreAuthorize("@ss.hasPermi('xxx:detail:edit')")
    @Log(title = "电子教学日志", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    @ApiOperation("修改电子教学日志")
    public Response<Integer> edit(@RequestBody TMClassRecordDetail tMClassRecordDetail){
        return toResponse(tMClassRecordDetailService.updateById(tMClassRecordDetail) ? 1 : 0);
    }

    /**
     * 删除电子教学日志
     */
    //@PreAuthorize("@ss.hasPermi('xxx:detail:remove')")
    @Log(title = "电子教学日志", businessType = BusinessTypeEnum.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除电子教学日志")
    public  Response<Integer> remove(
            @ApiParam(name = "ids", value = "电子教学日志ids参数", required = true)
            @PathVariable Long[] ids
    ){
        return toResponse(tMClassRecordDetailService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
