package com.zbf.web.controller.system;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.xml.crypto.Data;

import com.zbf.web.controller.section.EnhanceDataList;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
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;
import com.zbf.common.annotation.Log;
import com.zbf.common.core.controller.BaseController;
import com.zbf.common.core.domain.AjaxResult;
import com.zbf.common.enums.BusinessType;
import com.zbf.system.domain.TCkPickingwavegoodsBak;
import com.zbf.system.service.ITCkPickingwavegoodsBakService;
import com.zbf.common.utils.poi.ExcelUtil;
import com.zbf.common.core.page.TableDataInfo;

/**
 * 出库任务历史Controller
 *
 * @author tony
 * @date 2024-06-14
 */
@RestController
@RequestMapping("/system/ckPickingWavegoodsbak")
public class TCkPickingwavegoodsBakController extends BaseController {
    @Autowired
    private ITCkPickingwavegoodsBakService tCkPickingwavegoodsBakService;

    /**
     * 查询出库任务历史列表
     */
    @PreAuthorize("@ss.hasPermi('system:ckPickingWavegoodsbak:list')")
    @GetMapping("/list")
    @EnhanceDataList(entityType = TCkPickingwavegoodsBak.class)
    public TableDataInfo list(TCkPickingwavegoodsBak tCkPickingwavegoodsBak) {
        startPage();
        tCkPickingwavegoodsBak.setDeptId(getDeptId());
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date now = new Date();
        String formattedDate = formatter.format(now);
        tCkPickingwavegoodsBak.setWareDate(formattedDate);
        if (tCkPickingwavegoodsBak.getDate()!=null){
            String[] date = tCkPickingwavegoodsBak.getDate();
            tCkPickingwavegoodsBak.setStartTime(date[0]);
            tCkPickingwavegoodsBak.setEndTime(date[1]);
        }
        List<TCkPickingwavegoodsBak> list = tCkPickingwavegoodsBakService.selectTCkPickingwavegoodsBakList(tCkPickingwavegoodsBak);
        return getDataTable(list);
    }

    /**
     * 导出出库任务历史列表
     */
    @PreAuthorize("@ss.hasPermi('system:ckPickingWavegoodsbak:export')")
    @Log(title = "出库任务历史", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TCkPickingwavegoodsBak tCkPickingwavegoodsBak) {
        tCkPickingwavegoodsBak.setDeptId(getDeptId());
        List<TCkPickingwavegoodsBak> list = tCkPickingwavegoodsBakService.selectTCkPickingwavegoodsBakList(tCkPickingwavegoodsBak);
        ExcelUtil<TCkPickingwavegoodsBak> util = new ExcelUtil<TCkPickingwavegoodsBak>(TCkPickingwavegoodsBak.class);
        util.exportExcel(response, list, "出库任务历史数据");
    }

    /**
     * 获取出库任务历史详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:ckPickingWavegoodsbak:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(tCkPickingwavegoodsBakService.selectTCkPickingwavegoodsBakById(id));
    }

    /**
     * 新增出库任务历史
     */
    @PreAuthorize("@ss.hasPermi('system:ckPickingWavegoodsbak:add')")
    @Log(title = "出库任务历史", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCkPickingwavegoodsBak tCkPickingwavegoodsBak) {
        tCkPickingwavegoodsBak.setDeptId(getDeptId());
        return toAjax(tCkPickingwavegoodsBakService.insertTCkPickingwavegoodsBak(tCkPickingwavegoodsBak));
    }

    /**
     * 修改出库任务历史
     */
    @PreAuthorize("@ss.hasPermi('system:ckPickingWavegoodsbak:edit')")
    @Log(title = "出库任务历史", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCkPickingwavegoodsBak tCkPickingwavegoodsBak) {
        return toAjax(tCkPickingwavegoodsBakService.updateTCkPickingwavegoodsBak(tCkPickingwavegoodsBak));
    }

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

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

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

    /**
     * 修改状态
     */
    @PreAuthorize("@ss.hasPermi('system:ckPickingWavegoodsbak:edit')")
    @Log(title = "出库任务历史", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody TCkPickingwavegoodsBak tCkPickingwavegoodsBak) {
        return toAjax(tCkPickingwavegoodsBakService.updateStatus(tCkPickingwavegoodsBak));
    }

}

