package com.zg.project.information.controller;

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

import com.zg.project.wisdom.domain.GysJh;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zg.framework.aspectj.lang.annotation.Log;
import com.zg.framework.aspectj.lang.enums.BusinessType;
import com.zg.project.information.domain.PcdeDetail;
import com.zg.project.information.service.IPcdeDetailService;
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;
import org.springframework.web.multipart.MultipartFile;

/**
 * 库位明细Controller
 * 
 * @author zg
 * @date 2025-05-29
 */
@RestController
@RequestMapping("/information/pcdedetail")
public class PcdeDetailController extends BaseController
{
    @Autowired
    private IPcdeDetailService pcdeDetailService;

    /**
     * 查询库位明细列表
     */
    @PreAuthorize("@ss.hasPermi('information:pcdedetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(PcdeDetail pcdeDetail)
    {
        startPage();
        List<PcdeDetail> list = pcdeDetailService.selectPcdeDetailList(pcdeDetail);
        return getDataTable(list);
    }

    /**
     * 获取未被入库单据使用的库位列表
     */
    @PreAuthorize("@ss.hasPermi('information:pcdedetail:list')")
    @GetMapping("/getAll")
     public AjaxResult getAll()
    {
        List<PcdeDetail> list = pcdeDetailService.getAllPcde();
        return success(list);
    }

    /**
     * 导出库位明细列表
     */
    @PreAuthorize("@ss.hasPermi('information:pcdedetail:export')")
    @Log(title = "库位明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PcdeDetail pcdeDetail)
    {
        List<PcdeDetail> list = pcdeDetailService.selectPcdeDetailList(pcdeDetail);
        ExcelUtil<PcdeDetail> util = new ExcelUtil<PcdeDetail>(PcdeDetail.class);
        util.exportExcel(response, list, "库位明细数据");
    }

    /**
     * 导入供应计划数据（全部新增，不校验重复）
     */
    @PreAuthorize("@ss.hasPermi('information:pcdedetail:import')")
    @Log(title = "库位明细", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(@RequestParam("file") MultipartFile file) throws Exception {
        ExcelUtil<PcdeDetail> util = new ExcelUtil<>(PcdeDetail.class);
        List<PcdeDetail> list = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = pcdeDetailService.importPcdeDetail(list, operName);
        return AjaxResult.success(message);
    }


    /**
     * 获取库位明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('information:pcdedetail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pcdeDetailService.selectPcdeDetailById(id));
    }

    /**
     * 新增库位明细
     */
    @PreAuthorize("@ss.hasPermi('information:pcdedetail:add')")
    @Log(title = "库位明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody PcdeDetail pcdeDetail)
    {
        return toAjax(pcdeDetailService.insertPcdeDetail(pcdeDetail));
    }

    /**
     * 修改库位明细
     */
    @PreAuthorize("@ss.hasPermi('information:pcdedetail:edit')")
    @Log(title = "库位明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PcdeDetail pcdeDetail)
    {
        return toAjax(pcdeDetailService.updatePcdeDetail(pcdeDetail));
    }

    /**
     * 删除库位明细
     */
    @PreAuthorize("@ss.hasPermi('information:pcdedetail:remove')")
    @Log(title = "库位明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pcdeDetailService.deletePcdeDetailByIds(ids));
    }
}
