package cn.pluss.platform.controller.device;

import cn.pluss.platform.api.Result;
import cn.pluss.platform.base.BaseModelController;
import cn.pluss.platform.device.DeviceSpecService;
import cn.pluss.platform.device.DeviceTransferService;
import cn.pluss.platform.device.DeviceTypeService;
import cn.pluss.platform.entity.DeviceSpec;
import cn.pluss.platform.entity.DeviceType;
import cn.pluss.platform.entity.UserLevel;
import cn.pluss.platform.entity.UserRole;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;


/**
 * TODO
 *
 * @author crystal
 * @date 2022/4/15 10:58
 */
@Controller
@RequestMapping("deviceSpec")
public class DeviceSpecController extends BaseModelController<DeviceSpecService, DeviceSpec> {

    @Resource
    private DeviceTypeService deviceTypeService;

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

    @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}, value = {"/detail/{id}", "/detail"})
    public String detail(HttpServletRequest request, @PathVariable(value = "id", required = false) Integer id) {
        List<DeviceType> typeList = deviceTypeService.list();
        if (id != null) {
            DeviceSpec entity = baseService.getById(id);
            request.setAttribute("entity", entity);
        }
        request.setAttribute("codeList", typeList);
        return "device/spec/detail";
    }

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