package cn.ezhizao.project.business.controller;

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

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.BizNoCurrentReject;
import cn.ezhizao.project.business.service.IBizNoCurrentRejectService;
import cn.ezhizao.project.system.service.ISysUserService;
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;


/**
 * 非本序废品Controller
 *
 * @author ezhizao
 * @date 2024-05-12
 */
@RestController
@RequestMapping("/business/noCurrentReject")
public class BizNoCurrentRejectController extends BaseController
{
    @Resource
    private IBizNoCurrentRejectService bizNonCurrentRejectService;

    @Resource
    private ISysUserService sysUserService;

    /**
     * 查询非本序废品列表
     */
    @PreAuthorize("@ss.hasPermi('business:noCurrentReject:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizNoCurrentReject bizNoCurrentReject) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizNoCurrentReject);
        startPage();
        List<BizNoCurrentReject> list = bizNonCurrentRejectService.getList(bizNoCurrentReject);
        return getDataTable(list);
    }

    /**
     * 导出非本序废品列表
     */
    @PreAuthorize("@ss.hasPermi('business:noCurrentReject:export')")
    @Log(title = "非本序废品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizNoCurrentReject bizNoCurrentReject) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizNoCurrentReject);
        List<BizNoCurrentReject> list = bizNonCurrentRejectService.getList(bizNoCurrentReject);
        ExcelUtil<BizNoCurrentReject> util = new ExcelUtil<BizNoCurrentReject>(BizNoCurrentReject.class);
        util.exportExcel(response, list, "非本序废品数据");
    }

    /**
     * 获取非本序废品详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:noCurrentReject:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizNonCurrentRejectService.getById(id));
    }

    @GetMapping(value = "userList/{data}")
    public TableDataInfo getUserList(@PathVariable("data") String data)
    {
        return getDataTable(sysUserService.selectUserByCode(data));
    }
    /**
     * 新增非本序废品
     */
    @PreAuthorize("@ss.hasPermi('business:noCurrentReject:save')")
    @Log(title = "非本序废品保存")
    @PostMapping("/save")
    public AjaxResult save(@RequestBody BizNoCurrentReject bizNoCurrentReject) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizNoCurrentReject);
        boolean flag ;
        if(bizNoCurrentReject.getId() != null){
            flag=   bizNonCurrentRejectService.saveOrUpdate(bizNoCurrentReject);
        }else{
            flag= bizNonCurrentRejectService.save(bizNoCurrentReject);
        }
        return toAjax(flag);
    }

    /**
     * 修改非本序废品
     */
    @PreAuthorize("@ss.hasPermi('business:noCurrentReject:edit')")
    @Log(title = "非本序废品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizNoCurrentReject bizNoCurrentReject) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizNoCurrentReject);
        return toAjax(bizNonCurrentRejectService.updateById(bizNoCurrentReject));
    }

    /**
     * 删除非本序废品
     */
    @PreAuthorize("@ss.hasPermi('business:noCurrentReject:remove')")
    @Log(title = "非本序废品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(bizNonCurrentRejectService.removeBatchByIds(ids));
    }
}
