package com.zg.project.information.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.DeliveryMtd;
import com.zg.project.information.service.IDeliveryMtdService;
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-10-24
 */
@RestController
@RequestMapping("/information/delivery")
public class DeliveryMtdController extends BaseController
{
    @Autowired
    private IDeliveryMtdService deliveryMtdService;

    /**
     * 查询配送系统物料字典列表
     */
    @PreAuthorize("@ss.hasPermi('information:delivery:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeliveryMtd deliveryMtd)
    {
        startPage();
        List<DeliveryMtd> list = deliveryMtdService.selectDeliveryMtdList(deliveryMtd);
        return getDataTable(list);
    }

    /**
     * 导出配送系统物料字典列表
     */
    @PreAuthorize("@ss.hasPermi('information:delivery:export')")
    @Log(title = "配送系统物料字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeliveryMtd deliveryMtd)
    {
        List<DeliveryMtd> list = deliveryMtdService.selectDeliveryMtdList(deliveryMtd);
        ExcelUtil<DeliveryMtd> util = new ExcelUtil<DeliveryMtd>(DeliveryMtd.class);
        util.exportExcel(response, list, "配送系统物料字典数据");
    }

    @PreAuthorize("@ss.hasPermi('information:delivery:import')")
    @Log(title = "配送系统物料字典", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(@RequestParam("file") MultipartFile file) throws Exception
    {
        if (file == null || file.isEmpty()) {
            return AjaxResult.error("导入文件不能为空");
        }
        ExcelUtil<DeliveryMtd> util = new ExcelUtil<>(DeliveryMtd.class);
        List<DeliveryMtd> list = util.importExcel(file.getInputStream());
        int handled = deliveryMtdService.importDeliveryMtd(list, getUsername());
        return success("导入成功，共处理 " + handled + " 条");
    }

    /**
     * 获取配送系统物料字典详细信息
     */
    @PreAuthorize("@ss.hasPermi('information:delivery:query')")
    @GetMapping(value = "/{Id}")
    public AjaxResult getInfo(@PathVariable("Id") Long Id)
    {
        return success(deliveryMtdService.selectDeliveryMtdById(Id));
    }

    /**
     * 新增配送系统物料字典
     */
    @PreAuthorize("@ss.hasPermi('information:delivery:add')")
    @Log(title = "配送系统物料字典", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeliveryMtd deliveryMtd)
    {
        return toAjax(deliveryMtdService.insertDeliveryMtd(deliveryMtd));
    }

    /**
     * 修改配送系统物料字典
     */
    @PreAuthorize("@ss.hasPermi('information:delivery:edit')")
    @Log(title = "配送系统物料字典", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeliveryMtd deliveryMtd)
    {
        return toAjax(deliveryMtdService.updateDeliveryMtd(deliveryMtd));
    }

    /**
     * 删除配送系统物料字典
     */
    @PreAuthorize("@ss.hasPermi('information:delivery:remove')")
    @Log(title = "配送系统物料字典", businessType = BusinessType.DELETE)
	@DeleteMapping("/{Ids}")
    public AjaxResult remove(@PathVariable Long[] Ids)
    {
        return toAjax(deliveryMtdService.deleteDeliveryMtdByIds(Ids));
    }
}
