package com.inspect.metadata.prodevmnt.controller;

import com.inspect.metadata.prodevmnt.domain.BasedataModelDevice;
import com.inspect.metadata.prodevmnt.service.IBasedataModelDeviceService;
import com.inspect.base.core.utils.poi.ExcelUtil;
import com.inspect.base.core.web.controller.BaseController;
import com.inspect.base.core.web.domain.AjaxResult;
import com.inspect.base.core.web.page.TableDataInfo;
import com.inspect.common.log.annotation.Log;
import com.inspect.common.log.enums.BizType;
import com.inspect.common.security.annotation.RequiresPermissions;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/modeldevice"})
public class BasedataModelDeviceController extends BaseController {
    private final IBasedataModelDeviceService basedataModelDeviceService;

    public BasedataModelDeviceController(IBasedataModelDeviceService basedataModelDeviceService) {
        this.basedataModelDeviceService = basedataModelDeviceService;
    }

    @RequiresPermissions({"basedata:modeldevice:list"})
    @GetMapping({"/list"})
    public TableDataInfo list(BasedataModelDevice basedataModelDevice) {
        this.startPage();
        List<BasedataModelDevice> list = this.basedataModelDeviceService.selectBasedataModelDeviceList(basedataModelDevice);
        return this.getDataTable(list);
    }

    @RequiresPermissions({"basedata:modeldevice:export"})
    @Log(
            title = "三维生产设备",
            businessType = BizType.EXPORT
    )
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, BasedataModelDevice basedataModelDevice) {
        List<BasedataModelDevice> list = this.basedataModelDeviceService.selectBasedataModelDeviceList(basedataModelDevice);
        ExcelUtil<BasedataModelDevice> util = new ExcelUtil<>(BasedataModelDevice.class);
        util.exportExcel(response, list, "三维生产设备数据");
    }

    @RequiresPermissions({"basedata:modeldevice:query"})
    @GetMapping({"/{modelDeviceId}"})
    public AjaxResult getInfo(@PathVariable("modelDeviceId") String modelDeviceId) {
        return AjaxResult.success(this.basedataModelDeviceService.selectBasedataModelDeviceByModelDeviceId(modelDeviceId));
    }

    @RequiresPermissions({"basedata:modeldevice:add"})
    @Log(
            title = "三维生产设备",
            businessType = BizType.INSERT
    )
    @PostMapping
    public AjaxResult add(@RequestBody BasedataModelDevice basedataModelDevice) {
        return this.toAjax(this.basedataModelDeviceService.insertBasedataModelDevice(basedataModelDevice));
    }

    @RequiresPermissions({"basedata:modeldevice:edit"})
    @Log(
            title = "三维生产设备",
            businessType = BizType.UPDATE
    )
    @PostMapping({"/edit"})
    public AjaxResult edit(@RequestBody BasedataModelDevice basedataModelDevice) {
        return this.toAjax(this.basedataModelDeviceService.updateBasedataModelDevice(basedataModelDevice));
    }

    @RequiresPermissions({"basedata:modeldevice:remove"})
    @Log(
            title = "三维生产设备",
            businessType = BizType.DELETE
    )
    @PostMapping({"/remove/{modelDeviceIds}"})
    public AjaxResult remove(@PathVariable String[] modelDeviceIds) {
        return this.toAjax(this.basedataModelDeviceService.deleteBasedataModelDeviceByModelDeviceIds(modelDeviceIds));
    }
}
