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.BizProductionPlanDetailSubDetail;
import cn.ezhizao.project.business.service.IBizProductionPlanDetailSubDetailService;
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;

/**
 * 生产子计划明细Controller
 *
 * @author ezhizao
 * @date 2023-11-15
 */
@RestController
@RequestMapping("/business/planDetailSubDetail")
public class BizProductionPlanDetailSubDetailController extends BaseController
{
    @Resource
    private IBizProductionPlanDetailSubDetailService bizProductionPlanDetailSubDetailService;

    /**
     * 查询生产子计划明细列表
     */
    @PreAuthorize("@ss.hasPermi('business:planDetailSubDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizProductionPlanDetailSubDetail bizProductionPlanDetailSubDetail) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizProductionPlanDetailSubDetail);
        startPage();
        List<BizProductionPlanDetailSubDetail> list = bizProductionPlanDetailSubDetailService.getList(bizProductionPlanDetailSubDetail);
        return getDataTable(list);
    }

    /**
     * 导出生产子计划明细列表
     */
    @PreAuthorize("@ss.hasPermi('business:planDetailSubDetail:export')")
    @Log(title = "生产子计划明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizProductionPlanDetailSubDetail bizProductionPlanDetailSubDetail) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizProductionPlanDetailSubDetail);
        List<BizProductionPlanDetailSubDetail> list = bizProductionPlanDetailSubDetailService.getList(bizProductionPlanDetailSubDetail);
        ExcelUtil<BizProductionPlanDetailSubDetail> util = new ExcelUtil<BizProductionPlanDetailSubDetail>(BizProductionPlanDetailSubDetail.class);
        util.exportExcel(response, list, "生产子计划明细数据");
    }

    /**
     * 获取生产子计划明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:planDetailSubDetail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        BizProductionPlanDetailSubDetail bizProductionPlanDetailSubDetail = new BizProductionPlanDetailSubDetail();
        bizProductionPlanDetailSubDetail.setId(id);
        List<BizProductionPlanDetailSubDetail> list = bizProductionPlanDetailSubDetailService.getList(bizProductionPlanDetailSubDetail);
        if (list.size() > 1) {
            return error();
        }
        return success(list.get(0));
    }

    /**
     * 新增生产子计划明细
     */
    @PreAuthorize("@ss.hasPermi('business:planDetailSubDetail:add')")
    @Log(title = "生产子计划明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizProductionPlanDetailSubDetail bizProductionPlanDetailSubDetail) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizProductionPlanDetailSubDetail);
        return toAjax(bizProductionPlanDetailSubDetailService.saveOrUpdate(bizProductionPlanDetailSubDetail));
    }

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

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