package com.kym.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.kym.common.R;
import com.kym.common.annotation.SysLog;
import com.kym.entity.WashDevice;
import com.kym.entity.queryParams.DeviceQueryParams;
import com.kym.service.WashDeviceService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 网点设备
 * </p>
 *
 * @author skyline
 * @since 2023-08-12
 */
@RestController
@RequestMapping("/washDevice")
public class WashDeviceController {

    private final WashDeviceService washDeviceService;


    public WashDeviceController(WashDeviceService washDeviceService) {
        this.washDeviceService = washDeviceService;
    }


    @SaCheckPermission("washDevice.list")
    @SysLog("站点列表")
    @PostMapping("list")
    R<?> listStation(@RequestBody DeviceQueryParams params) {
        return R.success(washDeviceService.list(params));
    }

    @SaCheckPermission("washDevice.list")
    @SysLog("详情")
    @GetMapping("detail/{id}")
    R<?> detail(@PathVariable long id) {
        return R.success(washDeviceService.detail(id));
    }

    @SaCheckPermission("washDevice.remove")
    @SysLog("删除")
    @GetMapping("remove/{id}")
    R<?> remove(@PathVariable long id) {
        washDeviceService.remove(id);
        return R.success();
    }

    @SaCheckPermission("washDevice.modify")
    @SysLog("修改")
    @PostMapping("modify")
    R<?> modify(@RequestBody WashDevice washDevice) {
        washDeviceService.modify(washDevice);
        return R.success();
    }

    @SaCheckPermission("washDevice.add")
    @SysLog("新建")
    @PostMapping("add")
    R<?> add(@RequestBody WashDevice station) {
        washDeviceService.add(station);
        return R.success();
    }

    /**
     * 停止设备关闭订单
     *
     * @param shortId
     * @return
     */
    @SysLog("结算")
    @PostMapping(value = "/stopDevice/{shortId}")
    R<?> stopDevice(@PathVariable("shortId") String shortId) {
        washDeviceService.stopDevice(shortId);
        return R.success();
    }

    @SaCheckPermission("washDevice.modify")
    @SysLog("批量更新设备序号")
    @PostMapping("batchUpdateSequence")
    R<?> batchUpdateSequence(@RequestBody List<WashDevice> devices) {
        washDeviceService.batchUpdateSequence(devices);
        return R.success();
    }


}
