package com.miaxis.train.controller;

import com.miaxis.train.domain.TMTrainRecord;
import com.miaxis.train.service.ITMTrainRecordService;
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-14
 */
@RestController
@RequestMapping("/train/record")
@Api(tags={"【app-训练明细（终端上次明细）】"})
public class TMTrainRecordController extends BaseController{
    @Autowired
    private ITMTrainRecordService tMTrainRecordService;

    /**
     * 查询训练明细（终端上次明细）列表
     */
    //@PreAuthorize("@ss.hasPermi('train:record: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<TMTrainRecord> list(@ModelAttribute TMTrainRecord tMTrainRecord){
        startPage();
        List<TMTrainRecord> list = tMTrainRecordService.queryList(tMTrainRecord);
        return toResponsePageInfo(list);
    }

    /**
     * 导出训练明细（终端上次明细）列表
     */
   // @PreAuthorize("@ss.hasPermi('train:record:export')")
    @Log(title = "训练明细（终端上次明细）", businessType = BusinessTypeEnum.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出训练明细（终端上次明细）列表Excel")
    public Response<String> export(@ModelAttribute TMTrainRecord tMTrainRecord){
        List<TMTrainRecord> list = tMTrainRecordService.queryList(tMTrainRecord);
        ExcelUtil<TMTrainRecord> util = new ExcelUtil<TMTrainRecord>(TMTrainRecord.class);
        return util.exportExcel(list, "record");
    }

    /**
     * 获取训练明细（终端上次明细）详细信息
     */
    //@PreAuthorize("@ss.hasPermi('train:record:query')")
    @GetMapping(value = "/{rnum}")
    @ApiOperation("获取训练明细（终端上次明细）详细信息")
    public Response<TMTrainRecord> getInfo(
            @ApiParam(name = "rnum", value = "训练明细（终端上次明细）参数", required = true)
            @PathVariable("rnum") String rnum
    ){
        return Response.success(tMTrainRecordService.getById(rnum));
    }

    /**
     * 新增训练明细（终端上次明细）
     */
    //@PreAuthorize("@ss.hasPermi('train:record:add')")
    @Log(title = "训练明细（终端上次明细）", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    @ApiOperation("新增训练明细（终端上次明细）")
    public Response<Integer> add(@RequestBody TMTrainRecord tMTrainRecord){
        return toResponse(tMTrainRecordService.save(tMTrainRecord) ? 1 : 0);
    }

    /**
     * 修改训练明细（终端上次明细）
     */
    //@PreAuthorize("@ss.hasPermi('train:record:edit')")
    @Log(title = "训练明细（终端上次明细）", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    @ApiOperation("修改训练明细（终端上次明细）")
    public Response<Integer> edit(@RequestBody TMTrainRecord tMTrainRecord){
        return toResponse(tMTrainRecordService.updateById(tMTrainRecord) ? 1 : 0);
    }

    /**
     * 删除训练明细（终端上次明细）
     */
    //@PreAuthorize("@ss.hasPermi('train:record:remove')")
    @Log(title = "训练明细（终端上次明细）", businessType = BusinessTypeEnum.DELETE)
	@DeleteMapping("/{rnums}")
    @ApiOperation("删除训练明细（终端上次明细）")
    public  Response<Integer> remove(
            @ApiParam(name = "rnums", value = "训练明细（终端上次明细）ids参数", required = true)
            @PathVariable String[] rnums
    ){
        return toResponse(tMTrainRecordService.removeByIds(Arrays.asList(rnums)) ? 1 : 0);
    }
}
