package com.ktg.iscs.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ktg.common.annotation.Log;
import com.ktg.common.core.controller.BaseController;
import com.ktg.common.enums.BusinessType;
import com.ktg.common.pojo.CommonResult;
import com.ktg.iscs.domain.IsMotor;
import com.ktg.iscs.domain.dto.motor.MotorMoveDTO;
import com.ktg.iscs.service.IIsMotorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
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 cgj
 * @date 2025-09-04
 */
@Api(tags = "电机")
@RestController
@RequestMapping("/iscs/motor")
public class IsMotorController extends BaseController
{
    @Autowired
    private IIsMotorService isMotorService;

    @ApiOperation("查询电机-分页")
    @Parameters({
            @Parameter(name = "page", description = "Page"),
            @Parameter(name = "isMotor", description = "实体参数")
    })
    @PreAuthorize("@ss.hasPermi('iscs:motor:list')")
    @GetMapping("/getIsMotorPage")
    public CommonResult<Page<IsMotor>> getIsMotorPage(Page<IsMotor> page, IsMotor isMotor)
    {
        Page<IsMotor> result = isMotorService.getIsMotorPage(page, isMotor);
        return CommonResult.success(result);
    }

    @ApiOperation("获取电机详细信息")
    @Parameter(name = "motorId", description = "motorId")
    @PreAuthorize("@ss.hasPermi('iscs:motor:query')")
    @GetMapping(value = "/selectIsMotorById")
    public CommonResult<IsMotor> selectIsMotorById(Long motorId)
    {
        return CommonResult.success(isMotorService.selectIsMotorById(motorId));
    }

    @ApiOperation("新增电机")
    @PreAuthorize("@ss.hasPermi('iscs:motor:add')")
    @Log(title = "电机", businessType = BusinessType.INSERT)
    @PostMapping("/insertIsMotor")
    public CommonResult<Boolean> insertIsMotor(@RequestBody @Parameter(name = "isMotor", description = "新增数据类,放到body") IsMotor isMotor)
    {
        return CommonResult.success(isMotorService.save(isMotor));
    }

    @ApiOperation("修改电机")
    @PreAuthorize("@ss.hasPermi('iscs:motor:edit')")
    @Log(title = "电机", businessType = BusinessType.UPDATE)
    @PostMapping("/updateIsMotor")
    public CommonResult<Boolean> updateIsMotor(@RequestBody @Parameter(name = "isMotor", description = "修改数据类,放到body") IsMotor isMotor)
    {
        return CommonResult.success(isMotorService.updateIsMotor(isMotor));
    }

    @ApiOperation("删除电机")
    @PreAuthorize("@ss.hasPermi('iscs:motor:remove')")
    @Log(title = "电机", businessType = BusinessType.DELETE)
	@PostMapping("/deleteIsMotorByMotorIds")
    public CommonResult<Boolean> deleteIsMotorByMotorIds(String motorIds)
    {
        return CommonResult.success(isMotorService.deleteIsMotorByMotorIds(motorIds));
    }

    @ApiOperation("查询电机-list")
    @Parameters({
            @Parameter(name = "lotoId", description = "锁控柜id")
    })
    // @PreAuthorize("@ss.hasPermi('iscs:motor:list')")
    @GetMapping("/getIsMotorListByLotoId")
    public CommonResult<List<IsMotor>> getIsMotorListByLotoId(Long lotoId)
    {
        List<IsMotor> isMotorListByLotoId = isMotorService.getIsMotorListByLotoId(lotoId);
        return CommonResult.success(isMotorListByLotoId);
    }


    @ApiOperation("移动电机")
    @PreAuthorize("@ss.hasPermi('iscs:motor:edit')")
    @Log(title = "电机", businessType = BusinessType.UPDATE)
    @PostMapping("/updateIsMotorMove")
    public CommonResult<Boolean> updateIsMotorMove(@RequestBody @Parameter(name = "dto", description = "修改数据类,放到body") MotorMoveDTO dto)
    {
        return CommonResult.success(isMotorService.updateIsMotorMove(dto));
    }


}
