package com.fs.oms.controller;

import java.util.Date;
import java.util.List;

import com.alipay.api.domain.WarehouseVO;
import com.fs.common.utils.ServletUtils;
import com.fs.core.security.LoginUser;
import com.fs.core.web.service.TokenService;
import com.fs.oms.domain.OmsWarehouse;
import com.fs.oms.param.OmsStoreAddParam;
import com.fs.oms.service.IOmsWarehouseService;
import com.fs.oms.vo.OmsStoreVO;
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.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.oms.domain.OmsStore;
import com.fs.oms.service.IOmsStoreService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 网店Controller
 *
 * @author fs
 * @date 2023-05-18
 */
@RestController
@RequestMapping("/oms/store")
public class OmsStoreController extends BaseController
{
    @Autowired
    private IOmsStoreService omsStoreService;

    @Autowired
    private TokenService tokenService;

    @Autowired
    private IOmsWarehouseService omsWarehouseService;

    /**
     * 查询网店列表
     */
    @PreAuthorize("@ss.hasPermi('oms:store:list')")
    @GetMapping("/list")
    public TableDataInfo list(OmsStore omsStore)
    {
        startPage();
        List<OmsStoreVO> list = omsStoreService.selectOmsStoreListVO(omsStore);
        return getDataTable(list);
    }

    /**
     * 导出网店列表
     */
    @PreAuthorize("@ss.hasPermi('oms:store:export')")
    @Log(title = "网店", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OmsStore omsStore)
    {
        List<OmsStore> list = omsStoreService.selectOmsStoreList(omsStore);
        ExcelUtil<OmsStore> util = new ExcelUtil<OmsStore>(OmsStore.class);
        return util.exportExcel(list, "store");
    }

    /**
     * 获取网店详细信息
     */
    @PreAuthorize("@ss.hasPermi('oms:store:query')")
    @GetMapping(value = "/{storeId}")
    public AjaxResult getInfo(@PathVariable("storeId") Long storeId)
    {
        return AjaxResult.success(omsStoreService.selectOmsStoreById(storeId));
    }

    /**
     * 新增网店
     */
    @PreAuthorize("@ss.hasPermi('oms:store:add')")
    @Log(title = "网店", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OmsStoreAddParam omsStore) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        String operName = loginUser.getUsername();
        return toAjax(omsStoreService.insertOmsStore(omsStore,loginUser.getUser().getUserId()));
    }

    /**
     * 修改网店
     */
    @PreAuthorize("@ss.hasPermi('oms:store:edit')")
    @Log(title = "网店", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OmsStoreAddParam omsStore)
    {
        return toAjax(omsStoreService.updateOmsStore(omsStore));
    }

    /**
     * 删除网店
     */
    @PreAuthorize("@ss.hasPermi('oms:store:remove')")
    @Log(title = "网店", businessType = BusinessType.DELETE)
	@DeleteMapping("/{storeIds}")
    public AjaxResult remove(@PathVariable Long[] storeIds)
    {
        return toAjax(omsStoreService.deleteOmsStoreByIds(storeIds));
    }
}
