package com.zbf.web.controller.system;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zbf.common.core.domain.AjaxResult;
import com.zbf.system.domain.vo.TMiStockVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;


import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zbf.common.core.controller.BaseController;
import com.zbf.system.domain.TMiStock;
import com.zbf.system.service.ITMiStockService;
import com.zbf.common.core.page.TableDataInfo;

/**
 * 库存Controller
 *
 * @author tony
 * @date 2024-06-12
 */
@RestController
@RequestMapping("/TMiBatchAdjustment/batch")
@Api(value = "库存批次调整", tags = {"库存管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class TMiBatchAdjustmentController extends BaseController {

    private final ITMiStockService tMiStockService;

    /**
     * 查询库存列表
     */
    @ApiOperation("查询库存列表")
//    @PreAuthorize("@ss.hasPermi('TMiBatchAdjustment:batch:list')")
    @GetMapping("/list")
    public TableDataInfo list(TMiStock tMiStock) {
        startPage();
        List<TMiStock> listed = tMiStockService.list(new LambdaQueryWrapper<TMiStock>());
        return getDataTable(listed);
    }

    /**
     * 修改批次号
     * @param stockId
     * @param value
     * @return
     */
    @GetMapping("update/{stockId}/{value}")
    public AjaxResult update(@PathVariable String[] stockId, @PathVariable String value) {
            // 将数组转换为列表
        List<String> ids = Arrays.asList(stockId);
        // 调用服务层方法进行处理
        boolean success = tMiStockService.updates(ids,value);
        // 根据操作结果返回相应的AjaxResult
        return success ? AjaxResult.success("批次号修改成功。") : AjaxResult.error("批次号修改失败。");
    }

    /**
     * 生产日期
     * @param stockId
     * @param value
     * @return
     */
    @GetMapping("updateDate/{stockId}/{value}")
    public AjaxResult updateDate(@PathVariable String[] stockId, @PathVariable Date value) {
        // 将数组转换为列表
        List<String> ids = Arrays.asList(stockId);
        // 调用服务层方法进行处理
        boolean success = tMiStockService.updateDate(ids,value);
        // 根据操作结果返回相应的AjaxResult
        return success ? AjaxResult.success("生产日期修改成功。") : AjaxResult.error("生产日期修改失败。");
    }





    /**
     * 获取库存详细信息
     */
    @ApiOperation("获取库存详细信息")
    @PreAuthorize("@ss.hasPermi('system:stock:query')")
    @GetMapping(value = "/{stockId}")
    public AjaxResult getInfo(@PathVariable("stockId") String stockId)
    {
        return success(tMiStockService.getById(stockId));
    }




}
