package com.ruoyi.project.business.controller;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.business.dto.TpCaseElevatorDto;
import com.ruoyi.project.business.dto.TpParaRelatedCaseDto;
import com.ruoyi.project.business.dto.TpParaValidationDto;
import com.ruoyi.project.business.service.ITpParaRelatedCaseService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;


/**
 * @author jubs
 */
@RestController
@RequestMapping("/business/case")
public class TpParaRelatedCaseController extends BaseController {
    @Resource
    private ITpParaRelatedCaseService tpParaRelatedCaseService;


    @PostMapping("saveOrUpdate")
    public AjaxResult saveOrUpdate(@RequestBody TpParaRelatedCaseDto data) {
        return AjaxResult.success(tpParaRelatedCaseService.saveOrUpdateDto(data));
    }


    @GetMapping("getTableList")
    public TableDataInfo getTableList(TpParaRelatedCaseDto data) {
        startPage();
//        return getDataTable(tpParaRelatedCaseService.getTableList(data));
        return tpParaRelatedCaseService.getTableList(data);
    }

    @GetMapping("getInfoById/{id}")
    public AjaxResult getInfoById(@PathVariable Long id) {
        return AjaxResult.success(tpParaRelatedCaseService.getInfoById(id));
    }

    @PostMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody TpParaRelatedCaseDto param) {
        return AjaxResult.success(tpParaRelatedCaseService.changeStatus(param));
    }

    @GetMapping("/initRelation")
    public TableDataInfo initRelation(TpParaValidationDto param) {
        startPage();
        List<TpCaseElevatorDto> relationEnters = tpParaRelatedCaseService.initData(param.getId());
        return getDataTable(relationEnters);
    }

    @GetMapping("/getInfoByTpElevatorModelId/{elevatorModelId}")
    public AjaxResult getInfoByTpElevatorModelId(@PathVariable Long elevatorModelId) {
        return AjaxResult.success(tpParaRelatedCaseService.getInfoByTpElevatorModelId(elevatorModelId));
    }

    @DeleteMapping("/delete")
    public AjaxResult delete(@RequestParam("id") Long id, @RequestParam(value = "updateTime",required = false) Date updateTime) {
        return AjaxResult.success(tpParaRelatedCaseService.deleteById(id, updateTime));
    }


}
