package com.tuoheng.admin.controller;

import com.tuoheng.admin.request.cycle.AddInspectionCycleRequest;
import com.tuoheng.admin.request.cycle.EditInspectionCycleRequest;
import com.tuoheng.admin.request.cycle.QueryInspectionCyclePageListRequest;
import com.tuoheng.admin.service.cycle.InspectionCycleService;
import com.tuoheng.common.core.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 周期任务前端控制器
 *
 * @author wanjing
 * @team tuoheng
 * @date 2023-08-23
 */
@Slf4j
@RestController
@RequestMapping("/inspection/cycle")
public class InspectionCycleController {

    @Autowired
    private InspectionCycleService inspectionCycleService;

    /**
     * 查询周期任务分页列表
     */
    @GetMapping("/page/list")
    public JsonResult getPagelist(QueryInspectionCyclePageListRequest request) {
//        log.info("进入查询巡检任务分页列表接口");
        return inspectionCycleService.selectPageList(request);
    }

    /**
     * 根据周期任务id获取周期任务详情
     * @param id
     * @return
     */
    @GetMapping("/info/{id}")
    public JsonResult getOne(@PathVariable("id") String id){
        return inspectionCycleService.getInfo(id);
    }

    /**
     * 新增周期任务
     */
    @PostMapping("/add")
    public JsonResult add(@RequestBody AddInspectionCycleRequest request) {
//        log.info("进入添加周期任务接口");
        return inspectionCycleService.insert(request);
    }

    /**
     * 修改周期任务
     */
    @PutMapping("/edit")
    public JsonResult edit(@RequestBody EditInspectionCycleRequest request) {
//        log.info("进入修改周期任务接口, id={}", request.getId());
        return inspectionCycleService.update(request);
    }

    /**
     * 删除周期任务
     */
    @DeleteMapping("/{ids}")
    public JsonResult delete(@PathVariable("ids") List<String> idList) {
//        log.info("进入删除周期任务接口, idList={}", idList);
        return inspectionCycleService.deleteByIdList(idList);
    }

    /**
     * 周期任务启用/禁用
     */
    @PutMapping("/{id}/{isEnable}")
    public JsonResult update(@PathVariable("id") String id, @PathVariable("isEnable") Integer isEnable) {
        log.info("进入周期任务启用/禁用, id={}，isEnable={}", id, isEnable);
        return inspectionCycleService.updateEnable(id, isEnable);
    }

}
