package com.bonus.material.codeCollection.controller;

import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.log.enums.OperaType;
import com.bonus.common.security.utils.SecurityUtils;
import com.bonus.material.codeCollection.domain.WsMaInfo;
import com.bonus.material.codeCollection.service.WsMaInfoService;
import com.bonus.material.common.annotation.PreventRepeatSubmit;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 机具信息控制器
 * 提供机具信息的 RESTful API 接口，实现增删改查功能
 */
@RestController
@RequestMapping("/wsMaInfo")
public class WsMaInfoController extends BaseController {

    @Resource
    private WsMaInfoService service;

    @ApiOperation(value = "根据ID获取机具信息")
    @SysLog(title = "机具信息查询", businessType = OperaType.QUERY, logType = 1, module = "机具管理->查询")
    @GetMapping("/{id}")
    public AjaxResult getById(@PathVariable Integer id) {
        return service.getById(id);
    }

    @ApiOperation(value = "查询所有机具信息列表")
    @SysLog(title = "机具信息列表查询", businessType = OperaType.QUERY, logType = 1, module = "机具管理->查询")
    @GetMapping("/list")
    public AjaxResult getAll() {
        List<WsMaInfo> list = service.getAll();
        return AjaxResult.success(list);
    }

    @ApiOperation(value = "新增机具信息")
    @SysLog(title = "机具信息新增", businessType = OperaType.INSERT, logType = 1, module = "机具管理->新增")
    @PostMapping("/addWsMaInfo")
    public AjaxResult save(@RequestBody WsMaInfo info) {
        info.setOptUser(SecurityUtils.getLoginUser().getSysUser().getNickName());

        return service.save(info);
    }

    @ApiOperation(value = "更新机具信息")
    @SysLog(title = "机具信息更新", businessType = OperaType.UPDATE, logType = 1, module = "机具管理->更新")
    @PostMapping("/updateWsMaInfo")
    public AjaxResult update(@RequestBody WsMaInfo info) {
        return service.update(info);
    }

    @ApiOperation(value = "删除机具信息")
    @SysLog(title = "机具信息删除", businessType = OperaType.DELETE, logType = 1, module = "机具管理->删除")
    @PostMapping("/{id}")
    public AjaxResult delete(@PathVariable Integer id) {
        return service.delete(id);
    }

    @ApiOperation(value = "获取机具类型")
    @SysLog(title = "获取机具类型", businessType = OperaType.DELETE, logType = 1, module = "获取机具类型")
    @PostMapping("/getMaTypeData")
    public AjaxResult getMaTypeData() {
        return service.getMaTypeData();
    }


    @ApiOperation(value = "获取机具规格")
    @SysLog(title = "获取机具规格", businessType = OperaType.DELETE, logType = 1, module = "获取机具规格")
    @PostMapping("/getMaModeData")
    public AjaxResult getMaModeData(@RequestBody WsMaInfo info) {
        return service.getMaModeData(info.getParentId());
    }

    @ApiOperation(value = "获取出厂厂家")
    @SysLog(title = "获取出厂厂家", businessType = OperaType.DELETE, logType = 1, module = "获取出厂厂家")
    @PostMapping("/getSupplier")
    public AjaxResult getSupplier() {
        return service.getSupplier();
    }

}
