package cn.pluss.platform.controller.device;

import cn.pluss.platform.api.Result;
import cn.pluss.platform.base.BaseModelController;
import cn.pluss.platform.device.DeviceTypeService;
import cn.pluss.platform.entity.DeviceType;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;

/**
 * @author SSS
 */
@RequestMapping("/deviceType")
@Controller
public class DeviceTypeController extends BaseModelController<DeviceTypeService, DeviceType> {

    @GetMapping("/index")
    public String list() {
        return "device/type/list";
    }

    @Override
    public Result<Page<DeviceType>> page(Page<DeviceType> page, DeviceType condition, OrderItem orderItem) {
        orderItem.setColumn("id").setAsc(false);
        return super.page(page, condition, orderItem);
    }

    @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}, value = {"/detail/{id}", "/detail"})
    public String detail(HttpServletRequest request, @PathVariable(value = "id", required = false) Integer id) {
        if (id != null) {
            DeviceType entity = baseService.getById(id);
            request.setAttribute("entity", entity);
        }
        return "device/type/detail";
    }


}
