package cn.ezhizao.project.business.controller;

import cn.ezhizao.common.utils.poi.ExcelUtil;
import cn.ezhizao.framework.aspectj.lang.annotation.Log;
import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.framework.web.domain.AjaxResult;
import cn.ezhizao.framework.web.page.TableDataInfo;
import cn.ezhizao.project.business.domain.BizProductionPlanDetail;
import cn.ezhizao.project.business.service.IBizProductionPlanDetailService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 生产计划明细Controller
 *
 * @author ruoyi
 * @date 2023-11-15
 */
@RestController
@RequestMapping("/business/productionPlanDetail")
public class BizProductionPlanDetailController extends BaseController {
    @Resource
    private IBizProductionPlanDetailService bizProductionPlanDetailService;

    /**
     * 查询生产计划明细列表
     */
    @PreAuthorize("@ss.hasPermi('business:productionPlanDetail:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody Map<String, Object> data) throws NoSuchFieldException, IllegalAccessException {
        startPage();
        List<BizProductionPlanDetail> list = bizProductionPlanDetailService.getList(data);
        return getDataTable(list);
    }

    /**
     * 获取生产计划明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:productionPlanDetail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(bizProductionPlanDetailService.getById(id));
    }

    /**
     * 新增生产计划明细
     */
    @PreAuthorize("@ss.hasPermi('business:productionPlanDetail:add')")
    @Log(title = "生产计划明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizProductionPlanDetail bizProductionPlanDetail) throws NoSuchFieldException, IllegalAccessException {
        setTenantId(bizProductionPlanDetail);
        return toAjax(bizProductionPlanDetailService.save(bizProductionPlanDetail));
    }

    /**
     * 修改生产计划明细
     */
    @PreAuthorize("@ss.hasPermi('business:productionPlanDetail:edit')")
    @Log(title = "生产计划明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizProductionPlanDetail bizProductionPlanDetail) throws NoSuchFieldException, IllegalAccessException {
        setTenantId(bizProductionPlanDetail);
        return toAjax(bizProductionPlanDetailService.updateById(bizProductionPlanDetail));
    }

    /**
     * 删除生产计划明细
     */
    @PreAuthorize("@ss.hasPermi('business:productionPlanDetail:remove')")
    @Log(title = "生产计划明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(bizProductionPlanDetailService.removeBatchByIds(ids));
    }
}
