package com.ruoyi.web.v2.v1.controller;


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.v2.v1.model.JsWorkshop;
import com.ruoyi.web.v2.v1.service.IJsWorkshopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

import static com.ruoyi.common.core.domain.AjaxResult.success;

/**
 * <p>
 * v2.0生产车间管理 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-05-21
 */
@RestController
@RequestMapping("/js-workshop")
@Api("2.0生产车间管理")
public class JsWorkshopController {

    @Autowired
    private IJsWorkshopService workshopService;

    @ApiOperation("生产车间管理管理添加")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody JsWorkshop workshop){
        return workshopService.add(workshop);
    }

    @ApiOperation("生产车间管理管理修改")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody JsWorkshop workshop){
        return workshopService.edit(workshop);
    }

    @ApiOperation("生产车间管理管理删除")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody Map<String, String> paramsMap) {
        String ids = paramsMap.get("ids");
        return workshopService.delete(ids);
    }

    @ApiOperation("生产车间管理管理列表")
    @PostMapping("/list")
    public AjaxResult listAll(@RequestBody Map<String, String> paramsMap){
        String workshopType = paramsMap.get("workshopType");
        return workshopService.listAll(workshopType);
    }

    @ApiOperation("生产车间管理管理分页")
    @GetMapping("/page")
    public AjaxResult page(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize
            , @RequestParam(value = "workshopName", required = false) String workshopName
            ,@RequestParam(value = "workshopNum", required = false) String workshopNum
            ,@RequestParam(value = "workshopType", required = false) String workshopType) {
        return workshopService.page(pageNum, pageSize, workshopName,workshopNum,workshopType);
    }

    @ApiOperation("生产车间管理管理详情")
    @PostMapping("/listById")
    public AjaxResult listById(@RequestBody Map<String, String> paramsMap){
        String id = paramsMap.get("id");
        return success(workshopService.getById(id));
    }
}
