package com.cf.imes.module.executor.controller.admin.goods;

import com.cf.imes.module.executor.controller.admin.rawgoods.vo.RawGoodsImportRespVO;
import com.cf.imes.module.executor.controller.admin.rawgoods.vo.RawGoodsSaveReqVO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.cf.imes.framework.common.pojo.PageParam;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.framework.common.util.object.BeanUtils;
import static com.cf.imes.framework.common.pojo.CommonResult.success;

import com.cf.imes.framework.excel.core.util.ExcelUtils;

import com.cf.imes.framework.operatelog.core.annotations.OperateLog;
import static com.cf.imes.framework.operatelog.core.enums.OperateTypeEnum.*;

import com.cf.imes.module.executor.controller.admin.goods.vo.*;
import com.cf.imes.module.executor.dal.dataobject.goods.GoodsDO;
import com.cf.imes.module.executor.service.goods.GoodsService;

@Tag(name = "管理后台 - 生产单商品对应")
@RestController
@RequestMapping("/executor/goods")
@Validated
public class GoodsController {

    @Resource
    private GoodsService goodsService;

//    新建生产单新板材商品对应
    @PostMapping("/create")
    @Operation(summary = "对应生产单商品")
    @PreAuthorize("@ss.hasPermission('executor:goods:create')")
    public CommonResult<Boolean> createGoods(@Valid @RequestBody List<GoodsSaveReqVO> createReqVOS) {
        return success(goodsService.createCorrespondsGoods(createReqVOS));
    }

    @PutMapping("/update")
    @Operation(summary = "修改对应生产单商品")
    @PreAuthorize("@ss.hasPermission('executor:goods:update')")
    public CommonResult<Boolean> updateGoods(@Valid @RequestBody GoodsSaveReqVO updateReqVO) {
        goodsService.updateGoods(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除对应生产单商品")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('executor:goods:delete')")
    public CommonResult<Boolean> deleteGoods(@RequestParam("id") Long id) {
        goodsService.deleteGoods(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得对应生产单商品")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('executor:goods:query')")
    public CommonResult<GoodsRespVO> getGoods(@RequestParam("id") Long id) {
        GoodsDO goods = goodsService.getGoods(id);
        return success(BeanUtils.toBean(goods, GoodsRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得对应生产单商品分页")
    @PreAuthorize("@ss.hasPermission('executor:goods:query')")
    public CommonResult<PageResult<GoodsRespVO>> getGoodsPage(@Valid GoodsPageReqVO pageReqVO) {
        PageResult<GoodsDO> pageResult = goodsService.getGoodsPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, GoodsRespVO.class));
    }
}