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.resvo.WmsGoodsAppMapResVo;
import com.yunfeiyun.agmp.fms.domain.vo.WmsAssetgoodsVo;
import com.yunfeiyun.agmp.fms.service.IWmsAssetgoodsService;
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 杨晓辉
 * @date 2023-05-25
 */
@RestController
@RequestMapping("/wms/asset/goods")
public class WmsAssetgoodsController extends BaseController {
    @Autowired
    private IWmsAssetgoodsService wmsAssetgoodsService;

    /**
     * 查询货物列表
     */
    @PreAuthorize("@ss.hasPermi('wms:asset:goods:list')")
    @GetMapping("/list")
    public TableDataInfo list(WmsAssetgoodsVo wmsAssetgoodsVo)
    {
        startPage();
        List<WmsAssetgoodsVo> list = wmsAssetgoodsService.selectWmsAssetgoodsVoList(wmsAssetgoodsVo);
        return getDataTable(list);
    }

    /**
     * app端查询所有农资，无分页
     * */
    @PreAuthorize("@ss.hasPermi('wms:asset:goods:app:select:list')")
    @GetMapping("/app/select/json")
    public AjaxResult appList()
    {
        List<WmsGoodsAppMapResVo> list = wmsAssetgoodsService.selectWmsGoodsAppMapResVo();
        return success(list);
    }

    /**
     * 导出货物列表
     */
    @PreAuthorize("@ss.hasPermi('wms:asset:goods:export')")
    @Log(title = "货物", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsAssetgoodsVo wmsAssetGoodsVo)
    {
        List<WmsAssetgoodsVo> list = wmsAssetgoodsService.selectWmsAssetgoodsVoList(wmsAssetGoodsVo);
        ExcelUtil<WmsAssetgoodsVo> util = new ExcelUtil<WmsAssetgoodsVo>(WmsAssetgoodsVo.class);
        util.exportExcel(response, list, "货物数据");
    }

    /**
     * 获取货物详细信息
     */
    @PreAuthorize("@ss.hasPermi('wms:asset:goods:info')")
    @GetMapping(value = "/info")
    public AjaxResult getInfo(@RequestParam("goodsId") String goodsId)
    {
        return success(wmsAssetgoodsService.selectWmsAssetgoodsVoByGoodsId(goodsId));
    }
}
