package com.casic.missiles.modular.system.controller;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.casic.missiles.core.base.controller.BaseController;
import com.casic.missiles.core.page.PageFactory;
import com.casic.missiles.model.response.ResponseData;
import com.casic.missiles.model.response.SuccessResponseData;
import com.casic.missiles.modular.system.model.DeviceImei;
import com.casic.missiles.modular.system.service.IDeviceImeiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * @author cz
 * @date 2022-7-8
 */
@RestController
@RequestMapping("/device/simManage")
public class DeviceImeiController extends BaseController {

    private final IDeviceImeiService deviceImeiService;

    public DeviceImeiController(IDeviceImeiService deviceImeiService) {
        this.deviceImeiService = deviceImeiService;
    }

    /**
     * 获取分页列表SMI
     */
    @RequestMapping(value = "/listPage")
    public Object deviceImeiListPage(String devcode) {
        //  devcode	否	string	设备编号
        Page<Map<String,Object>> page = PageFactory.defaultPage();
        ResponseData responseData = deviceImeiService.deviceImeiListPage(page, devcode);
        responseData.setData(super.packForBT(page));
        return responseData;
    }

    /**
     * 新增SMI
     */
    @RequestMapping(value = "/add")
    public Object addImei(@RequestBody DeviceImei deviceImei) {
        return deviceImeiService.addImei(deviceImei);
    }

    /**
     * 更新SMI
     */
    @RequestMapping(value = "/update")
    public Object editImei(@RequestBody DeviceImei deviceImei) {
        return deviceImeiService.editImei(deviceImei);
    }

    /**
     * 删除imei
     */
    @RequestMapping(value = "/delete/{id}")
    public Object deleteImei(@PathVariable("id") Long id) {
        return deviceImeiService.deleteImei(id);
    }

    /**
     * 批量导入SMI
     */
    @RequestMapping(value = "/batchImport")
    public Object importImei(@RequestParam("file") MultipartFile uploadFile) {
        return deviceImeiService.importImeiList(uploadFile);
    }
}
