package com.zbf.web.controller.system;

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.TRkWareNoticeTabBak;
import com.zbf.system.domain.TRkXnWareNoticeTabBak;
import com.zbf.system.domain.TckXnOrderdetailBak;
import com.zbf.system.mapper.TRkWareNoticeTabBakMapper;
import com.zbf.system.mapper.TRkXnWareNoticeTabBakMapper;
import com.zbf.system.service.ITRkWareNoticeTabBakService;
import com.zbf.system.service.ITRkXnWareNoticeTabBakService;
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 org.springframework.web.multipart.MultipartFile;

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

/**
 * 入库通知单明细备份Controller
 *
 * @author tony
 * @date 2024-06-14
 */
@RestController
@RequestMapping("/system/rkXnWareNoticeTabBak")
public class TRkXnWareNoticeTabBakController extends BaseController
{
    @Autowired
    private ITRkXnWareNoticeTabBakService tRkWareNoticeTabBakService;

    @Autowired
    private TRkXnWareNoticeTabBakMapper tRkWareNoticeTabBakMapper;

/**
 * 查询入库通知单明细备份列表
 */
@GetMapping("/list")
@EnhanceDataList(entityType = TRkXnWareNoticeTabBak.class)
    public TableDataInfo list(TRkXnWareNoticeTabBak tRkWareNoticeTabBak)
    {
        startPage();
//        tMiStock.setDeptId(getDeptId());
        if (tRkWareNoticeTabBak.getDate()!=null){
            String[] date = tRkWareNoticeTabBak.getDate();
            tRkWareNoticeTabBak.setStartTime(date[0]);
            tRkWareNoticeTabBak.setEndTime(date[1]);
        }
        List<TRkXnWareNoticeTabBak> list = tRkWareNoticeTabBakService.selectTRkWareNoticeTabBakList(tRkWareNoticeTabBak);
        return getDataTable(list);
    }

    @GetMapping("/listSupplier")
    @EnhanceDataList(entityType = TRkWareNoticeTabBak.class)
    public TableDataInfo listSupplier()
    {
        TRkXnWareNoticeTabBak tRkWareNoticeTabBak = new TRkXnWareNoticeTabBak();
        List<TRkXnWareNoticeTabBak> list = tRkWareNoticeTabBakService.selectTRkWareNoticeTabBakList(tRkWareNoticeTabBak);
        return getDataTable(list);
    }




    @GetMapping("/syList")
    public TableDataInfo syList(TRkWareNoticeTabBak tRkWareNoticeTabBak)
    {
        if (tRkWareNoticeTabBak.getDate()!=null){
            String[] date = tRkWareNoticeTabBak.getDate();
            tRkWareNoticeTabBak.setStartTime(date[0]);
            tRkWareNoticeTabBak.setEndTime(date[1]);
        }
        List<TRkXnWareNoticeTabBak> list = tRkWareNoticeTabBakMapper.selectTRkWareNoticeTabBakLists();
        return getDataTable(list);
    }

    @GetMapping("/listTotal")
    public AjaxResult listTotal(TRkXnWareNoticeTabBak tRkWareNoticeTabBak)
    {
        if (tRkWareNoticeTabBak.getDate()!=null){
            String[] date = tRkWareNoticeTabBak.getDate();
            tRkWareNoticeTabBak.setStartTime(date[0]);
            tRkWareNoticeTabBak.setEndTime(date[1]);
        }
        List<TRkXnWareNoticeTabBak> list = tRkWareNoticeTabBakService.select(tRkWareNoticeTabBak);
        return AjaxResult.success(list);
    }



    /**
     * 导出入库通知单明细备份列表
     */
//    @PreAuthorize("@ss.hasPermi('system:rkWareNoticeTabBak:export')")
    @Log(title = "入库通知单明细备份", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TRkXnWareNoticeTabBak tRkWareNoticeTabBak)
    {
        List<TRkXnWareNoticeTabBak> list = tRkWareNoticeTabBakService.selectTRkWareNoticeTabBakList(tRkWareNoticeTabBak);
        ExcelUtil<TRkXnWareNoticeTabBak> util = new ExcelUtil<>(TRkXnWareNoticeTabBak.class);
        util.exportExcel(response, list, "入库通知单明细备份数据");
    }
    /**
     * 导入
     */
    @Log(title = "出库数据", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception
    {
        ExcelUtil<TRkXnWareNoticeTabBak> util = new ExcelUtil<TRkXnWareNoticeTabBak>(TRkXnWareNoticeTabBak.class);
        List<TRkXnWareNoticeTabBak> trList = util.importExcel(file.getInputStream());
        String message = tRkWareNoticeTabBakService.importData(trList, "");
        return AjaxResult.success(message);
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<TRkXnWareNoticeTabBak> util = new ExcelUtil<TRkXnWareNoticeTabBak>(TRkXnWareNoticeTabBak.class);
        util.importTemplateExcel(response,"虚拟出库记录");
    }


    /**
     * 获取入库通知单明细备份详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:rkWareNoticeTabBak:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tRkWareNoticeTabBakService.selectTRkWareNoticeTabBakById(id));
    }

    /**
     * 新增入库通知单明细备份
     */
    @PreAuthorize("@ss.hasPermi('system:rkWareNoticeTabBak:add')")
    @Log(title = "入库通知单明细备份", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TRkXnWareNoticeTabBak tRkWareNoticeTabBak)
    {
        tRkWareNoticeTabBak.setId(OrderCodeFactory.getOrderCode("TRKTAB", ""));
        return toAjax(tRkWareNoticeTabBakService.insertTRkWareNoticeTabBak(tRkWareNoticeTabBak));
    }

    /**
     * 修改入库通知单明细备份
     */
    @PreAuthorize("@ss.hasPermi('system:rkWareNoticeTabBak:edit')")
    @Log(title = "入库通知单明细备份", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TRkXnWareNoticeTabBak tRkWareNoticeTabBak)
    {
        return toAjax(tRkWareNoticeTabBakService.updateTRkWareNoticeTabBak(tRkWareNoticeTabBak));
    }

    /**
     * 删除入库通知单明细备份
     */
    @PreAuthorize("@ss.hasPermi('system:rkWareNoticeTabBak:remove')")
    @Log(title = "入库通知单明细备份", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tRkWareNoticeTabBakService.deleteTRkWareNoticeTabBakByIds(ids));
    }

    /**
     * 启用
     */
    @PreAuthorize("@ss.hasPermi('system:rkWareNoticeTabBak:remove')")
    @Log(title = "入库通知单明细备份", businessType = BusinessType.UPDATE)
    @DeleteMapping("/disable/{ids}")
    public AjaxResult disable(@PathVariable String[] ids)
    {
        return toAjax(tRkWareNoticeTabBakService.disabledTRkWareNoticeTabBakByIds(ids));
    }

    /**
     * 禁用
     */
    @PreAuthorize("@ss.hasPermi('system:rkWareNoticeTabBak:edit')")
    @Log(title = "入库通知单明细备份", businessType = BusinessType.UPDATE)
    @DeleteMapping("/enable/{ids}")
    public AjaxResult enable(@PathVariable String[] ids)
    {
        return toAjax(tRkWareNoticeTabBakService.enableTRkWareNoticeTabBakByIds(ids));
    }

    /**
     * 修改状态
     */
    @PreAuthorize("@ss.hasPermi('system:rkWareNoticeTabBak:edit')")
    @Log(title = "入库通知单明细备份", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody TRkXnWareNoticeTabBak tRkWareNoticeTabBak) {
        return toAjax(tRkWareNoticeTabBakService.updateStatus(tRkWareNoticeTabBak));
    }

}

