package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.ss.mapping.domain.StoreMapping;
import com.ruoyi.ss.mapping.domain.StoreMappingVO;
import com.ruoyi.ss.mapping.domain.StoreMappingQuery;
import com.ruoyi.ss.mapping.service.IStoreMappingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 系统与第三方店铺映射关系Controller
 *
 * @author qzz
 * @date 2025-03-18
 */
@RestController
@RequestMapping("/system/mapping")
public class StoreMappingController extends BaseController
{
    @Autowired
    private IStoreMappingService storeMappingService;

    /**
     * 查询系统与第三方店铺映射关系列表
     */
    @PreAuthorize("@ss.hasPermi('system:mapping:list')")
    @GetMapping("/list")
    public TableDataInfo list(StoreMappingQuery query)
    {
        startPage();
        startOrderBy();
        List<StoreMappingVO> list = storeMappingService.selectStoreMappingList(query);
        return getDataTable(list);
    }

    /**
     * 导出系统与第三方店铺映射关系列表
     */
    @PreAuthorize("@ss.hasPermi('system:mapping:export')")
    @Log(title = "系统与第三方店铺映射关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StoreMappingQuery query)
    {
        List<StoreMappingVO> list = storeMappingService.selectStoreMappingList(query);
        ExcelUtil<StoreMappingVO> util = new ExcelUtil<StoreMappingVO>(StoreMappingVO.class);
        util.exportExcel(response, list, "系统与第三方店铺映射关系数据");
    }

    /**
     * 获取系统与第三方店铺映射关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:mapping:query')")
    @GetMapping(value = "/{storeId}")
    public AjaxResult getInfo(@PathVariable("storeId") Long storeId)
    {
        return success(storeMappingService.selectStoreMappingByStoreId(storeId));
    }

    /**
     * 新增系统与第三方店铺映射关系
     */
    @PreAuthorize("@ss.hasPermi('system:mapping:add')")
    @Log(title = "系统与第三方店铺映射关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StoreMapping storeMapping)
    {
        return toAjax(storeMappingService.insertStoreMapping(storeMapping));
    }

    /**
     * 修改系统与第三方店铺映射关系
     */
    @PreAuthorize("@ss.hasPermi('system:mapping:edit')")
    @Log(title = "系统与第三方店铺映射关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StoreMapping storeMapping)
    {
        return toAjax(storeMappingService.updateStoreMapping(storeMapping));
    }

    /**
     * 删除系统与第三方店铺映射关系
     */
    @PreAuthorize("@ss.hasPermi('system:mapping:remove')")
    @Log(title = "系统与第三方店铺映射关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{storeIds}")
    public AjaxResult remove(@PathVariable Long[] storeIds)
    {
        return toAjax(storeMappingService.deleteStoreMappingByStoreIds(storeIds));
    }
}
