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

import com.casic.missiles.modular.system.service.IDeviceTypeService;
import com.casic.missiles.core.base.controller.BaseController;
import com.casic.missiles.core.base.response.ResponseData;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.mapper.EntityWrapper;

import java.util.List;

import com.casic.missiles.core.common.constant.factory.PageFactory;
import org.springframework.web.bind.annotation.RequestParam;
import com.casic.missiles.modular.system.model.DeviceType;

/**
 * 设备类型控制器(暂不使用 保留)
 *
 * @author dev
 * @Date 2019-05-23 18:09:17
 */
//@Controller
//@RequestMapping("/deviceType")
public class DeviceTypeController extends BaseController {


    @Autowired
    private IDeviceTypeService deviceTypeService;


    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return deviceTypeService.selectList(null);
    }

    /**
     * 获取分页列表
     */
    @RequestMapping(value = "/listPage")
    @ResponseBody
    public Object listPage(String condition) {
        Page<DeviceType> page = new PageFactory<DeviceType>().defaultPage();
        EntityWrapper<DeviceType> query = new EntityWrapper<>();
        page = deviceTypeService.selectPage(page, query);
        return super.packForBT(page);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(DeviceType deviceType) {
        deviceTypeService.insert(deviceType);
        return ResponseData.success();
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam String deviceTypeId) {
        deviceTypeService.deleteById(deviceTypeId);
        return ResponseData.success();
    }

    /**
     * 批量删除
     */
    @RequestMapping(value = "/batchDelete")
    @ResponseBody
    public Object delete(@RequestParam("deviceTypeIds") List<String> deviceTypeIds) {
        deviceTypeService.deleteBatchIds(deviceTypeIds);
        return ResponseData.success();
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(DeviceType deviceType) {
        deviceTypeService.updateById(deviceType);
        return ResponseData.success();
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{deviceTypeId}")
    @ResponseBody
    public Object detail(@PathVariable("deviceTypeId") String deviceTypeId) {

        return ResponseData.success(deviceTypeService.selectById(deviceTypeId));
    }
}
