package com.jjt.ws.controller;

import com.jjt.common.annotation.Log;
import com.jjt.common.core.controller.BaseController;
import com.jjt.common.core.domain.AjaxResult;
import com.jjt.common.core.page.TableDataInfo;
import com.jjt.common.enums.BusinessType;
import com.jjt.common.utils.poi.ExcelUtil;
import com.jjt.ws.domain.TwinWorkshop;
import com.jjt.ws.service.ITwinWorkshopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 车间管理Controller
 *
 * @author wukai
 * @date 2025-01-17
 */
@Api(tags = "车间管理")
@RestController
@RequestMapping("/ws/workshop")
public class TwinWorkshopController extends BaseController {
    @Resource
    private ITwinWorkshopService twinWorkshopService;

    /**
     * 查询车间管理列表
     */
    @ApiOperation("查询车间管理列表")
    @PreAuthorize("@ss.hasPermi('ws:workshop:list')")
    @GetMapping("/list")
    public TableDataInfo list(TwinWorkshop twinWorkshop) {
        startPage();
        List<TwinWorkshop> list = twinWorkshopService.selectTwinWorkshopList(twinWorkshop);
        return getDataTable(list);
    }

    /**
     * 导出车间管理列表
     */
    @ApiOperation("导出车间管理列表")
    @PreAuthorize("@ss.hasPermi('ws:workshop:export')")
    @Log(title = "车间管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TwinWorkshop twinWorkshop) {
        List<TwinWorkshop> list = twinWorkshopService.selectTwinWorkshopList(twinWorkshop);
        ExcelUtil<TwinWorkshop> util = new ExcelUtil<TwinWorkshop>(TwinWorkshop.class);
        util.exportExcel(response, list, "车间管理数据");
    }

    /**
     * 获取车间管理详细信息
     */
    @ApiOperation("获取车间管理详细信息")
    @PreAuthorize("@ss.hasPermi('ws:workshop:query')")
    @GetMapping(value = "/{wsId}")
    public AjaxResult getInfo(@PathVariable("wsId") Long wsId) {
        return success(twinWorkshopService.selectTwinWorkshopByWsId(wsId));
    }

    /**
     * 新增车间管理
     */
    @ApiOperation("新增车间管理")
    @PreAuthorize("@ss.hasPermi('ws:workshop:add')")
    @Log(title = "车间管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TwinWorkshop twinWorkshop) {
        return toAjax(twinWorkshopService.insertTwinWorkshop(twinWorkshop));
    }

    /**
     * 修改车间管理
     */
    @ApiOperation("修改车间管理")
    @PreAuthorize("@ss.hasPermi('ws:workshop:edit')")
    @Log(title = "车间管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TwinWorkshop twinWorkshop) {
        return toAjax(twinWorkshopService.updateTwinWorkshop(twinWorkshop));
    }

    /**
     * 删除车间管理
     */
    @ApiOperation("删除车间管理")
    @PreAuthorize("@ss.hasPermi('ws:workshop:remove')")
    @Log(title = "车间管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{wsIds}")
    public AjaxResult remove(@PathVariable Long[] wsIds) {
        return toAjax(twinWorkshopService.deleteTwinWorkshopByWsIds(wsIds));
    }
}
