package com.ruoyi.web.controller.shipping.controller;

import java.util.List;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.shipping.domain.TTemporaryFile;
import com.ruoyi.shipping.service.ITTemporaryFileService;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 凯和商务端上传箱信息暂存数据Controller
 * 
 * @author ruoyi
 * @date 2021-07-01
 */
@RestController
@RequestMapping("/warehouse/file")
public class TTemporaryFileController extends BaseController
{
    @Autowired
    private ITTemporaryFileService tTemporaryFileService;

    /**
     * 查询凯和商务端上传箱信息暂存数据列表
     */
    //@PreAuthorize("@ss.hasPermi('warehouse:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(TTemporaryFile tTemporaryFile)
    {
        LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
        tTemporaryFile.setCreateBy(loginUser.getUser().getUserName());
        List<TTemporaryFile> temporaryFileList = tTemporaryFileService.selectTTemporaryFileList(tTemporaryFile,loginUser);
        startPage();
        List<TTemporaryFile> list = tTemporaryFileService.selectTTemporaryFileList(tTemporaryFile,loginUser);
        TableDataInfo dataTable = getDataTable(list);
        dataTable.setTotal(temporaryFileList.size());
        return dataTable;
        //return AjaxResult.success(list);
    }

    /**
     * 导出凯和商务端上传箱信息暂存数据列表
     */
    @PreAuthorize("@ss.hasPermi('warehouse:file:export')")
    @Log(title = "凯和商务端上传箱信息暂存数据", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TTemporaryFile tTemporaryFile)
    {
        LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
        List<TTemporaryFile> list = tTemporaryFileService.selectTTemporaryFileList(tTemporaryFile,loginUser);
        ExcelUtil<TTemporaryFile> util = new ExcelUtil<TTemporaryFile>(TTemporaryFile.class);
        return util.exportExcel(list, "file");
    }

    /**
     * 获取凯和商务端上传箱信息暂存数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehouse:file:query')")
    @GetMapping(value = "/{fId}")
    public AjaxResult getInfo(@PathVariable("fId") Long fId)
    {
        return AjaxResult.success(tTemporaryFileService.selectTTemporaryFileById(fId));
    }

    /**
     * 新增凯和商务端上传箱信息暂存数据
     */
    @PreAuthorize("@ss.hasPermi('warehouse:file:add')")
    @Log(title = "凯和商务端上传箱信息暂存数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TTemporaryFile tTemporaryFile)
    {
        LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
        return toAjax(tTemporaryFileService.insertTTemporaryFile(tTemporaryFile,loginUser));
    }

    /**
     * 修改凯和商务端上传箱信息暂存数据
     */
    @PreAuthorize("@ss.hasPermi('warehouse:file:edit')")
    @Log(title = "凯和商务端上传箱信息暂存数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TTemporaryFile tTemporaryFile)
    {
        return toAjax(tTemporaryFileService.updateTTemporaryFile(tTemporaryFile));
    }

    /**
     * 删除凯和商务端上传箱信息暂存数据
     */
    //@PreAuthorize("@ss.hasPermi('warehouse:file:remove')")
    @Log(title = "凯和商务端上传箱信息暂存数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/delete/{fileName}")
    public AjaxResult remove(@PathVariable String fileName)
    {
        LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
        return toAjax(tTemporaryFileService.deleteTTemporaryFilefileName(fileName,loginUser.getUser().getUserName()));
    }
}
