package com.zbf.web.controller.system;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zbf.common.annotation.Log;
import com.zbf.common.core.controller.BaseController;
import com.zbf.common.core.domain.AjaxResult;
import com.zbf.common.core.page.TableDataInfo;
import com.zbf.common.enums.BusinessType;
import com.zbf.common.utils.OrderCodeFactory;
import com.zbf.common.utils.poi.ExcelUtil;
import com.zbf.system.domain.TOngoodsshelf;
import com.zbf.system.service.ITOngoodsshelfService;
import com.zbf.web.controller.section.EnhanceDataList;

/**
 * 入库任务Controller
 *
 * @author tony
 * @date 2024-06-14
 */
@RestController
@RequestMapping("/system/ongoodsshelf")
public class TOngoodsshelfController extends BaseController {
    @Autowired
    private ITOngoodsshelfService tOngoodsshelfService;

    /**
     * 查询入库任务列表
     */
    @PreAuthorize("@ss.hasPermi('system:ongoodsshelf:list')")
    @EnhanceDataList(entityType = TOngoodsshelf.class)
    @GetMapping("/list")
    public TableDataInfo list(TOngoodsshelf tOngoodsshelf) {
        startPage();
        // tOngoodsshelf.setDeptId(getDeptId());
        List<TOngoodsshelf> list = tOngoodsshelfService.selectTOngoodsshelfList(tOngoodsshelf);
        return getDataTable(list);
    }

    /**
     * 导出入库任务列表
     */
    @PreAuthorize("@ss.hasPermi('system:ongoodsshelf:export')")
    @Log(title = "入库任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TOngoodsshelf tOngoodsshelf) {
        // tOngoodsshelf.setDeptId(getDeptId());
        List<TOngoodsshelf> list = tOngoodsshelfService.selectTOngoodsshelfList(tOngoodsshelf);
        ExcelUtil<TOngoodsshelf> util = new ExcelUtil<TOngoodsshelf>(TOngoodsshelf.class);
        util.exportExcel(response, list, "入库任务数据");
    }

    /**
     * 获取入库任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:ongoodsshelf:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(tOngoodsshelfService.selectTOngoodsshelfById(id));
    }

    /**
     * 新增入库任务
     */
    @PreAuthorize("@ss.hasPermi('system:ongoodsshelf:add')")
    @Log(title = "入库任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TOngoodsshelf tOngoodsshelf) {
        tOngoodsshelf.setDeptId(getDeptId());
        tOngoodsshelf.setId(OrderCodeFactory.getOrderCode("SHELF", ""));
        return toAjax(tOngoodsshelfService.insertTOngoodsshelf(tOngoodsshelf));
    }

    /**
     * 修改入库任务
     */
    @PreAuthorize("@ss.hasPermi('system:ongoodsshelf:edit')")
    @Log(title = "入库任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TOngoodsshelf tOngoodsshelf) {
        return toAjax(tOngoodsshelfService.updateTOngoodsshelf(tOngoodsshelf));
    }

    /**
     * 删除入库任务
     */
    @PreAuthorize("@ss.hasPermi('system:ongoodsshelf:remove')")
    @Log(title = "入库任务", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(tOngoodsshelfService.deleteTOngoodsshelfByIds(ids));
    }

    /**
     * 启用
     */
    @PreAuthorize("@ss.hasPermi('system:ongoodsshelf:remove')")
    @Log(title = "入库任务", businessType = BusinessType.UPDATE)
    @DeleteMapping("/disable/{ids}")
    public AjaxResult disable(@PathVariable String[] ids) {
        return toAjax(tOngoodsshelfService.disabledTOngoodsshelfByIds(ids));
    }

    /**
     * 禁用
     */
    @PreAuthorize("@ss.hasPermi('system:ongoodsshelf:edit')")
    @Log(title = "入库任务", businessType = BusinessType.UPDATE)
    @DeleteMapping("/enable/{ids}")
    public AjaxResult enable(@PathVariable String[] ids) {
        return toAjax(tOngoodsshelfService.enableTOngoodsshelfByIds(ids));
    }

    /**
     * 修改状态
     */
    @PreAuthorize("@ss.hasPermi('system:ongoodsshelf:edit')")
    @Log(title = "入库任务", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody TOngoodsshelf tOngoodsshelf) {
        return toAjax(tOngoodsshelfService.updateStatus(tOngoodsshelf));
    }

    /**
     * 查询入库任务列表
     */
    @GetMapping("/selectList")
    public AjaxResult selectList(TOngoodsshelf tOngoodsshelf) {
        // tOngoodsshelf.setDeptId(getDeptId());
        List<TOngoodsshelf> list = tOngoodsshelfService.selectTOngoodsshelfList(tOngoodsshelf);
        return success(list);
    }
}

