package com.zg.project.wisdom.controller;

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

import com.zg.project.wisdom.domain.vo.StockStatisticVO;
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.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zg.framework.aspectj.lang.annotation.Log;
import com.zg.framework.aspectj.lang.enums.BusinessType;
import com.zg.project.wisdom.domain.RkInfo;
import com.zg.project.wisdom.service.IRkInfoService;
import com.zg.framework.web.controller.BaseController;
import com.zg.framework.web.domain.AjaxResult;
import com.zg.common.utils.poi.ExcelUtil;
import com.zg.framework.web.page.TableDataInfo;

/**
 * 库存单据明细Controller
 * 
 * @author zg
 * @date 2026-01-20
 */
@RestController
@RequestMapping("/wisdom/stock")
public class RkInfoController extends BaseController
{
    @Autowired
    private IRkInfoService rkInfoService;

    /**
     * 查询库存单据明细列表
     */
    @PreAuthorize("@ss.hasPermi('wisdom:stock:list')")
    @GetMapping("/list")
    public TableDataInfo list(RkInfo rkInfo)
    {
        startPage();
        List<RkInfo> list = rkInfoService.selectRkInfoList(rkInfo);
        return getDataTable(list);
    }

    /**
     * 导出库存单据明细列表
     */
    @PreAuthorize("@ss.hasPermi('wisdom:stock:export')")
    @Log(title = "库存单据明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RkInfo rkInfo)
    {
        List<RkInfo> list = rkInfoService.selectRkInfoList(rkInfo);
        ExcelUtil<RkInfo> util = new ExcelUtil<RkInfo>(RkInfo.class);
        util.exportExcel(response, list, "库存单据明细数据");
    }

    /**
     * 获取库存单据明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('wisdom:stock:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rkInfoService.selectRkInfoById(id));
    }

    /**
     * 新增库存单据明细
     */
    @PreAuthorize("@ss.hasPermi('wisdom:stock:add')")
    @Log(title = "库存单据明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RkInfo rkInfo)
    {
        return toAjax(rkInfoService.insertRkInfo(rkInfo));
    }

    /**
     * 修改库存单据明细
     */
    @PreAuthorize("@ss.hasPermi('wisdom:stock:edit')")
    @Log(title = "库存单据明细", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody RkInfo rkInfo)
    {
        return toAjax(rkInfoService.updateRkInfo(rkInfo));
    }

    /**
     * 删除库存单据明细
     */
    @PreAuthorize("@ss.hasPermi('wisdom:stock:remove')")
    @Log(title = "库存单据明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rkInfoService.deleteRkInfoByIds(ids));
    }

    /**
     * 库存统计（随查询条件动态变化）
     */
    @PostMapping("/statistic")
    public AjaxResult statistic(@RequestBody RkInfo query) {
        return AjaxResult.success(rkInfoService.getStockStatistic(query));
    }

}
