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.TRkReceivingGoods;
import com.zbf.system.service.ITRkReceivingGoodsService;

/**
 * 收货单Controller
 *
 * @author tony
 * @date 2024-06-18
 */
@RestController
@RequestMapping("/system/rkRecevinggoods")
public class TRkReceivingGoodsController extends BaseController
{
    @Autowired
    private ITRkReceivingGoodsService tRkReceivingGoodsService;

/**
 * 查询收货单列表
 */
@PreAuthorize("@ss.hasPermi('system:rkRecevinggoods:list')")
@GetMapping("/list")
    public TableDataInfo list(TRkReceivingGoods tRkReceivingGoods)
    {
        startPage();
        tRkReceivingGoods.setDeptId(getDeptId());
        List<TRkReceivingGoods> list = tRkReceivingGoodsService.selectTRkReceivingGoodsList(tRkReceivingGoods);
        return getDataTable(list);
    }

    /**
     * 导出收货单列表
     */
    @PreAuthorize("@ss.hasPermi('system:rkRecevinggoods:export')")
    @Log(title = "收货单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TRkReceivingGoods tRkReceivingGoods)
    {
        tRkReceivingGoods.setDeptId(getDeptId());
        List<TRkReceivingGoods> list = tRkReceivingGoodsService.selectTRkReceivingGoodsList(tRkReceivingGoods);
        ExcelUtil<TRkReceivingGoods> util = new ExcelUtil<TRkReceivingGoods>(TRkReceivingGoods.class);
        util.exportExcel(response, list, "收货单数据");
    }

    /**
     * 获取收货单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:rkRecevinggoods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tRkReceivingGoodsService.selectTRkReceivingGoodsById(id));
    }

    /**
     * 新增收货单
     */
    @PreAuthorize("@ss.hasPermi('system:rkRecevinggoods:add')")
    @Log(title = "收货单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TRkReceivingGoods tRkReceivingGoods)
    {
        tRkReceivingGoods.setId(OrderCodeFactory.getOrderCode("R", ""));
        return toAjax(tRkReceivingGoodsService.insertTRkReceivingGoods(tRkReceivingGoods));
    }

    /**
     * 修改收货单
     */
    @PreAuthorize("@ss.hasPermi('system:rkRecevinggoods:edit')")
    @Log(title = "收货单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TRkReceivingGoods tRkReceivingGoods)
    {
        return toAjax(tRkReceivingGoodsService.updateTRkReceivingGoods(tRkReceivingGoods));
    }

    /**
     * 删除收货单
     */
    @PreAuthorize("@ss.hasPermi('system:rkRecevinggoods:remove')")
    @Log(title = "收货单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tRkReceivingGoodsService.deleteTRkReceivingGoodsByIds(ids));
    }

    /**
     * 启用
     */
    @PreAuthorize("@ss.hasPermi('system:rkRecevinggoods:remove')")
    @Log(title = "收货单", businessType = BusinessType.UPDATE)
    @DeleteMapping("/disable/{ids}")
    public AjaxResult disable(@PathVariable String[] ids)
    {
        return toAjax(tRkReceivingGoodsService.disabledTRkReceivingGoodsByIds(ids));
    }

    /**
     * 禁用
     */
    @PreAuthorize("@ss.hasPermi('system:rkRecevinggoods:edit')")
    @Log(title = "收货单", businessType = BusinessType.UPDATE)
    @DeleteMapping("/enable/{ids}")
    public AjaxResult enable(@PathVariable String[] ids)
    {
        return toAjax(tRkReceivingGoodsService.enableTRkReceivingGoodsByIds(ids));
    }

    /**
     * 修改状态
     */
    @PreAuthorize("@ss.hasPermi('system:rkRecevinggoods:edit')")
    @Log(title = "收货单", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody TRkReceivingGoods tRkReceivingGoods) {
        return toAjax(tRkReceivingGoodsService.updateStatus(tRkReceivingGoods));
    }

}

