package cn.ezhizao.project.business.deptUser.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.deptUser.domain.BizDeptProcess;
import cn.ezhizao.project.business.deptUser.service.IBizDeptProcessService;
import cn.ezhizao.project.business.innerTurnover.domain.BizInnerTurnover;
import org.springframework.web.bind.annotation.*;

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


/**
 * deptProcessController
 *
 * @author ezhizao
 * @date 2023-12-11
 */
@RestController
@RequestMapping("/business/deptProcess")
public class BizDeptProcessController extends BaseController
{
    @Resource
    private IBizDeptProcessService bizDeptProcessService;
    @Resource
    HttpServletRequest request;

    /**
     * 查询deptProcess列表
     */
//    @PreAuthorize("@ss.hasPermi('business:deptProcess:list')")
    @Log(title = "资源组工段绑定的工序查询", businessType = BusinessType.SELECT)
    @GetMapping("/list")
    public TableDataInfo list(BizDeptProcess bizDeptProcess) throws NoSuchFieldException, IllegalAccessException
    {
//        final String tenantId = request.getHeader("tenantId");
//        bizDeptProcess.setTenantId(Long.valueOf(tenantId));
        //如果传入的flag不是空，代表在报工信息页面对工艺的工序和工段资源分配的工序取交集，不需要让其分页
        if(bizDeptProcess.getFlag()==null) {
            startPage();
        }
        List<BizDeptProcess> list = bizDeptProcessService.getList(bizDeptProcess);
        return getDataTable(list);
    }

    /**
     * 导出deptProcess列表
     */
//    @PreAuthorize("@ss.hasPermi('business:deptProcess:export')")

    @Log(title = "工段下资源组绑定的工序导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizDeptProcess bizDeptProcess) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizDeptProcess);
        List<BizDeptProcess> list = bizDeptProcessService.getList(bizDeptProcess);
        ExcelUtil<BizDeptProcess> util = new ExcelUtil<BizDeptProcess>(BizDeptProcess.class);
        util.exportExcel(response, list, "deptProcess数据");
    }

    /**
     * 获取deptProcess详细信息
     */
//    @PreAuthorize("@ss.hasPermi('business:deptProcess:query')")
    @Log(title = "资源组工段绑定的工序查询详细信息", businessType = BusinessType.SELECT)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizDeptProcessService.getById(id));
    }

    /**
     * 新增deptProcess
     */
//    @PreAuthorize("@ss.hasPermi('business:deptProcess:add')")
    @Log(title = "资源组工段绑定的工序保存", businessType = BusinessType.INSERT)
    @PostMapping("/save")
    public AjaxResult add(@RequestBody List<BizDeptProcess> bizDeptProcess) throws NoSuchFieldException, IllegalAccessException
    {
        boolean batch = bizDeptProcessService.saveBatch(bizDeptProcess);
        return toAjax(batch);
    }

    /**
     * 修改deptProcess
     */
//    @PreAuthorize("@ss.hasPermi('business:deptProcess:edit')")
    @Log(title = "资源组工段绑定的工序修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizDeptProcess bizDeptProcess) throws NoSuchFieldException, IllegalAccessException
    {
//        final String tenantId = request.getHeader("tenantId");
//        bizDeptProcess.setTenantId(Long.valueOf(tenantId));
        return toAjax(bizDeptProcessService.updateById(bizDeptProcess));
    }

    /**
     * 删除deptProcess
     */
//    @PreAuthorize("@ss.hasPermi('business:deptProcess:remove')")
    @Log(title = "资源组工段绑定的工序删除", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(bizDeptProcessService.removeBatchByIds(ids));
    }
}
