package com.yunfeiyun.agmp.fms.controller;

import com.yunfeiyun.agmp.common.annotation.Log;
import com.yunfeiyun.agmp.common.core.controller.BaseController;
import com.yunfeiyun.agmp.common.core.domain.AjaxResult;
import com.yunfeiyun.agmp.common.core.page.TableDataInfo;
import com.yunfeiyun.agmp.common.enums.BusinessType;
import com.yunfeiyun.agmp.common.utils.poi.ExcelUtil;
import com.yunfeiyun.agmp.fms.domain.TssTracecodeapply;
import com.yunfeiyun.agmp.fms.domain.reqvo.TssTracecodeapplyReqVo;
import com.yunfeiyun.agmp.fms.domain.resvo.TssTraceCodeApplyResVo;
import com.yunfeiyun.agmp.fms.domain.resvo.TssTracecodeapplyManagerListResVo;
import com.yunfeiyun.agmp.fms.service.ITssScanrcdService;
import com.yunfeiyun.agmp.fms.service.ITssTracecodeapplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 溯源码生成单Controller
 * 
 * @author 杨晓辉
 * @date 2023-07-04
 */
@RestController
@RequestMapping("/tss/tracecodeapply")
public class TssTracecodeapplyController extends BaseController
{
    @Autowired
    private ITssTracecodeapplyService tssTracecodeapplyService;
    @Autowired
    private ITssScanrcdService tssScanrcdService;


    /**
     * 查询溯源码生成单列表
     */
    @PreAuthorize("@ss.hasPermi('tss:tracecodeapply:list')")
    @GetMapping("/list")
    public TableDataInfo list(TssTracecodeapply tssTracecodeapply)
    {
        startPage();
        List<TssTraceCodeApplyResVo> list = tssTracecodeapplyService.selectTssTraceCodeApplyResVoList(tssTracecodeapply);
        return getDataTable(list);
    }
    /**
     * 查询溯源码生成单列表
     */
    @PreAuthorize("@ss.hasPermi('tss:tracecodeapply:manager/list')")
    @GetMapping("/manager/list")
    public TableDataInfo managerList(TssTracecodeapplyReqVo tssTracecodeapply)
    {
        startPage();
        List<TssTracecodeapplyManagerListResVo> list = tssTracecodeapplyService.selectTssTracecodeapplyManagerListResVoList(tssTracecodeapply);
        return getDataTable(list);
    }


    /**
     * 导出溯源码生成单列表
     */
    @PreAuthorize("@ss.hasPermi('tss:tracecodeapply:export')")
    @Log(title = "溯源码生成单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TssTracecodeapply tssTracecodeapply)
    {
        List<TssTracecodeapply> list = tssTracecodeapplyService.selectTssTracecodeapplyList(tssTracecodeapply);
        ExcelUtil<TssTracecodeapply> util = new ExcelUtil<TssTracecodeapply>(TssTracecodeapply.class);
        util.exportExcel(response, list, "溯源码生成单数据");
    }

    /**
     * 获取溯源码生成单详细信息
     */
    @PreAuthorize("@ss.hasPermi('tss:tracecodeapply:info')")
    @GetMapping(value = "/info/{tarcecodeapplyId}")
    public AjaxResult getInfo(@PathVariable("tarcecodeapplyId") String tarcecodeapplyId)
    {
        return success(tssTracecodeapplyService.selectTssTracecodeapplyByTarcecodeapplyId(tarcecodeapplyId));
    }

    /**
     * 新增溯源码生成单
     */
    @PreAuthorize("@ss.hasPermi('tss:tracecodeapply:add')")
    @Log(title = "溯源码生成单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody TssTracecodeapply tssTracecodeapply)
    {
        return toAjax(tssTracecodeapplyService.insertTssTracecodeapply(tssTracecodeapply));
    }

    /**
     * 修改溯源码生成单
     */
    @PreAuthorize("@ss.hasPermi('tss:tracecodeapply:edit')")
    @Log(title = "溯源码生成单", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody TssTracecodeapply tssTracecodeapply)
    {
        return toAjax(tssTracecodeapplyService.updateTssTracecodeapply(tssTracecodeapply));
    }

    /**
     * 删除溯源码生成单
     */
    @PreAuthorize("@ss.hasPermi('tss:tracecodeapply:delete')")
    @Log(title = "溯源码生成单", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{tarcecodeapplyIds}")
    public AjaxResult remove(@PathVariable String[] tarcecodeapplyIds)
    {
        return toAjax(tssTracecodeapplyService.deleteTssTracecodeapplyByTarcecodeapplyIds(tarcecodeapplyIds));
    }


    /**
     * app扫溯源码查询页面，不做任何数据权限
     */
    @GetMapping("/app/query/source")
    public AjaxResult appQuerySource(String tarcecodeapplyno,HttpServletRequest httpServletRequest)
    {
        tssScanrcdService.saveScanrcdInfo(tarcecodeapplyno,httpServletRequest);
        return success(tssTracecodeapplyService.appQuerySource(tarcecodeapplyno));
    }

    /**
     * app扫溯源码查询页面，不做任何数据权限
     */
    @GetMapping("/app/query/source/info")
    public AjaxResult appQuerySourceInfo(String tarcecodeapplyno,String tssSourceperiodId)
    {
        return success(tssTracecodeapplyService.appQuerySourceInfo(tarcecodeapplyno,tssSourceperiodId));
    }



}
