package cn.ezhizao.project.business.controller;

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

import cn.ezhizao.framework.web.controller.BaseController;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.ezhizao.framework.aspectj.lang.annotation.Log;
import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
import cn.ezhizao.project.business.domain.BizProductionPlanDetailSubDetailEquipment;
import cn.ezhizao.project.business.service.IBizProductionPlanDetailSubDetailEquipmentService;
import cn.ezhizao.framework.web.domain.AjaxResult;
import cn.ezhizao.common.utils.poi.ExcelUtil;
import cn.ezhizao.framework.web.page.TableDataInfo;

/**
 * 子计划对应的工序指定的使用设备 Controller
 *
 * @author ezhizao
 * @date 2023-11-15
 */
@RestController
@RequestMapping("/business/equipment")
public class BizProductionPlanDetailSubDetailEquipmentController extends BaseController {
    @Resource
    private IBizProductionPlanDetailSubDetailEquipmentService bizProductionPlanDetailSubDetailEquipmentService;
    @Resource
    HttpServletRequest request;

    /**
     * 子计划对应的工序指定的使用设备 列表
     */

    @GetMapping("/list")
    public TableDataInfo list(BizProductionPlanDetailSubDetailEquipment bizProductionPlanDetailSubDetailEquipment) throws NoSuchFieldException, IllegalAccessException
    {
        String tenantId = request.getHeader("tenantId");
        bizProductionPlanDetailSubDetailEquipment.setTenantId(Long.valueOf(tenantId));
        //startPage();
        List<BizProductionPlanDetailSubDetailEquipment> list = bizProductionPlanDetailSubDetailEquipmentService.getList(bizProductionPlanDetailSubDetailEquipment);
        return getDataTable(list);
    }

    /**
     * 导出子计划对应的工序指定的使用设备 列表
     */
    @PreAuthorize("@ss.hasPermi('business:equipment:export')")
    @Log(title = "子计划对应的工序指定的使用设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizProductionPlanDetailSubDetailEquipment bizProductionPlanDetailSubDetailEquipment) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizProductionPlanDetailSubDetailEquipment);
        Map<String, Object> data = new HashMap<>();
        data.put("bizProductionPlanDetailSubDetailEquipment", bizProductionPlanDetailSubDetailEquipment);
        List<BizProductionPlanDetailSubDetailEquipment> list = bizProductionPlanDetailSubDetailEquipmentService.getList(data);
        ExcelUtil<BizProductionPlanDetailSubDetailEquipment> util = new ExcelUtil<BizProductionPlanDetailSubDetailEquipment>(BizProductionPlanDetailSubDetailEquipment.class);
        util.exportExcel(response, list, "生产计划明细数据");
    }

    /**
     * 获取子计划对应的工序指定的使用设备 详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:equipment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizProductionPlanDetailSubDetailEquipmentService.getById(id));
    }

    /**
     * 新增子计划对应的工序指定的使用设备
     */

    @Log(title = "生产计划明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizProductionPlanDetailSubDetailEquipment bizProductionPlanDetailSubDetailEquipment) throws NoSuchFieldException, IllegalAccessException
    {
        String tenantId = request.getHeader("tenantId");
        bizProductionPlanDetailSubDetailEquipment.setTenantId(Long.valueOf(tenantId));
        return toAjax(bizProductionPlanDetailSubDetailEquipmentService.save(bizProductionPlanDetailSubDetailEquipment));
    }
    /**
     * 新增子计划对应的工序指定的使用设备
     */

    @Log(title = "生产计划明细", businessType = BusinessType.INSERT)
    @PostMapping("/saveBatch")
    public AjaxResult saveBatch(@RequestBody List<BizProductionPlanDetailSubDetailEquipment> bizProductionPlanDetailSubDetailEquipment) throws NoSuchFieldException, IllegalAccessException {
        String tenantId = request.getHeader("tenantId");
        for (BizProductionPlanDetailSubDetailEquipment item : bizProductionPlanDetailSubDetailEquipment) {
            item.setTenantId(Long.valueOf(tenantId));
        }
        boolean batch = bizProductionPlanDetailSubDetailEquipmentService.saveBatch(bizProductionPlanDetailSubDetailEquipment);
        return toAjax(batch);
    }
    /**
     * 修改子计划对应的工序指定的使用设备
     */

    @Log(title = "生产计划明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizProductionPlanDetailSubDetailEquipment bizProductionPlanDetailSubDetailEquipment) throws NoSuchFieldException, IllegalAccessException
    {
        String tenantId = request.getHeader("tenantId");
        bizProductionPlanDetailSubDetailEquipment.setTenantId(Long.valueOf(tenantId));
        return toAjax(bizProductionPlanDetailSubDetailEquipmentService.updateById(bizProductionPlanDetailSubDetailEquipment));
    }

    /**
     * 删除子计划对应的工序指定的使用设备
     */

    @Log(title = "生产计划明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(bizProductionPlanDetailSubDetailEquipmentService.removeBatchByIds(ids));
    }
}
