package com.zg.project.wisdom.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.wisdom.domain.GysJh;
import com.zg.project.wisdom.service.IGysJhService;
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-28
 */
@RestController
@RequestMapping("/plan/jh")
public class GysJhController extends BaseController
{
    @Autowired
    private IGysJhService gysJhService;

    /**
     * 查询供应计划列表
     */
    @PreAuthorize("@ss.hasPermi('plan:jh:list')")
    @GetMapping("/list")
    public TableDataInfo list(GysJh gysJh)
    {
        startPage();
        List<GysJh> list = gysJhService.selectGysJhList(gysJh);
        return getDataTable(list);
    }

    /**
     * 根据sapNo查询供应计划列表
     * @param sapNo
     * @return
     */
    @PreAuthorize("@ss.hasPermi('plan:jh:list')")
    @GetMapping("/getBySapNo")
    public AjaxResult getBySapNo(String sapNo)
    {
        List<GysJh> list = gysJhService.getBySapNo(sapNo);
        return success(list);
    }

    /**
     * 导出供应计划列表
     */
    @PreAuthorize("@ss.hasPermi('plan:jh:export')")
    @Log(title = "供应计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GysJh gysJh)
    {
        List<GysJh> list = gysJhService.selectGysJhList(gysJh);
        ExcelUtil<GysJh> util = new ExcelUtil<GysJh>(GysJh.class);
        util.exportExcel(response, list, "供应计划数据");
    }

    /**
     * 导入供应计划数据（全部新增，不校验重复）
     */
    @PreAuthorize("@ss.hasPermi('wisdom:jh:import')")
    @Log(title = "供应计划", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(@RequestParam("file") MultipartFile file) throws Exception {
        ExcelUtil<GysJh> util = new ExcelUtil<>(GysJh.class);
        List<GysJh> jhList = util.importExcel(file.getInputStream());
        String operName = getUsername();

        String message = gysJhService.importGysJhList(jhList, operName);
        return AjaxResult.success(message);
    }

    /**
     * 获取供应计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('plan:jh:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(gysJhService.selectGysJhById(id));
    }

    /**
     * 新增供应计划
     */
    @PreAuthorize("@ss.hasPermi('plan:jh:add')")
    @Log(title = "供应计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GysJh gysJh)
    {
        return toAjax(gysJhService.insertGysJh(gysJh));
    }

    /**
     * 修改供应计划
     */
    @PreAuthorize("@ss.hasPermi('plan:jh:edit')")
    @Log(title = "供应计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GysJh gysJh)
    {
        return toAjax(gysJhService.updateGysJh(gysJh));
    }

    /**
     * 删除供应计划
     */
    @PreAuthorize("@ss.hasPermi('plan:jh:remove')")
    @Log(title = "供应计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gysJhService.deleteGysJhByIds(ids));
    }
}
