package com.zbf.web.controller.system;

import com.alibaba.druid.util.StringUtils;
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.poi.ExcelUtil;
import com.zbf.system.domain.TckOrderdetailBak;
import com.zbf.system.domain.TckOrdersBak;
import com.zbf.system.service.ITckOrdersBakService;
import com.zbf.web.controller.section.EnhanceDataList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 出库单历史表Controller
 *
 * @author tony
 * @date 2024-07-03
 */
@RestController
@RequestMapping("/system/tckOrdersbak")
public class TckOrdersBakController extends BaseController
{
    @Autowired
    private ITckOrdersBakService tckOrdersBakService;

    /**
     * 查询出库单历史表列表
     */
    @PreAuthorize("@ss.hasPermi('system:tckOrdersbak:list')")
    @EnhanceDataList(entityType = TckOrdersBak.class)
    @GetMapping("/list")
    public TableDataInfo list(TckOrdersBak tckOrdersBak)
    {
        startPage();
        List<TckOrdersBak> list = tckOrdersBakService.selectTckOrdersBakList(tckOrdersBak);
        return getDataTable(list);
    }

   /* *
     * 查询出库单历史表列表(退库入库)*/
    @EnhanceDataList(entityType = TckOrdersBak.class)
    @GetMapping("/selectList")
    public TableDataInfo ckOrders(TckOrderdetailBak tckOrderdetailBak)
    {
        startPage();
        if(!StringUtils.isEmpty(tckOrderdetailBak.getStartDate())) {
            tckOrderdetailBak.setStartDate(tckOrderdetailBak.getStartDate() + " 00:00:00");
        }

        if(!StringUtils.isEmpty(tckOrderdetailBak.getEndDate())) {
            tckOrderdetailBak.setEndDate(tckOrderdetailBak.getEndDate() + " 23:59:59");
        }
        List<TckOrderdetailBak> list = tckOrdersBakService.selectReturnTckOrdersBakList(tckOrderdetailBak);
        return getDataTable(list);
    }


    /**
     * 导出出库单历史表列表
     */
    @PreAuthorize("@ss.hasPermi('system:tckOrdersbak:export')")
    @Log(title = "出库单历史表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TckOrdersBak tckOrdersBak)
    {
        List<TckOrdersBak> list = tckOrdersBakService.selectTckOrdersBakList(tckOrdersBak);
        ExcelUtil<TckOrdersBak> util = new ExcelUtil<TckOrdersBak>(TckOrdersBak.class);
        util.exportExcel(response, list, "出库单历史表数据");
    }

    /**
     * 获取出库单历史表详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:tckOrdersbak:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tckOrdersBakService.selectTckOrdersBakById(id));
    }

    /**
     * 新增出库单历史表
     */
    @PreAuthorize("@ss.hasPermi('system:tckOrdersbak:add')")
    @Log(title = "出库单历史表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TckOrdersBak tckOrdersBak)
    {
        return toAjax(tckOrdersBakService.insertTckOrdersBak(tckOrdersBak));
    }

    /**
     * 修改出库单历史表
     */
    @PreAuthorize("@ss.hasPermi('system:tckOrdersbak:edit')")
    @Log(title = "出库单历史表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TckOrdersBak tckOrdersBak)
    {
        return toAjax(tckOrdersBakService.updateTckOrdersBak(tckOrdersBak));
    }

    /**
     * 删除出库单历史表
     */
    @PreAuthorize("@ss.hasPermi('system:tckOrdersbak:remove')")
    @Log(title = "出库单历史表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tckOrdersBakService.deleteTckOrdersBakByIds(ids));
    }

    /**
     * 启用
     */
    @PreAuthorize("@ss.hasPermi('system:tckOrdersbak:remove')")
    @Log(title = "出库单历史表", businessType = BusinessType.UPDATE)
    @DeleteMapping("/disable/{ids}")
    public AjaxResult disable(@PathVariable String[] ids)
    {
        return toAjax(tckOrdersBakService.disabledTckOrdersBakByIds(ids));
    }

    /**
     * 禁用
     */
    @PreAuthorize("@ss.hasPermi('system:tckOrdersbak:edit')")
    @Log(title = "出库单历史表", businessType = BusinessType.UPDATE)
    @DeleteMapping("/enable/{ids}")
    public AjaxResult enable(@PathVariable String[] ids)
    {
        return toAjax(tckOrdersBakService.enableTckOrdersBakByIds(ids));
    }

    /**
     * 修改状态
     */
    @PreAuthorize("@ss.hasPermi('system:tckOrdersbak:edit')")
    @Log(title = "出库单历史表", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody TckOrdersBak tckOrdersBak) {
        return toAjax(tckOrdersBakService.updateStatus(tckOrdersBak));
    }

}

