package com.ruoyi.web.controller.columns;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.columns.YjStore;
import com.ruoyi.system.service.columns.IYjStoreService;
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 2025-10-31
 */
@RestController
@RequestMapping("/system/store")
public class YjStoreController extends BaseController
{
    @Autowired
    private IYjStoreService yjStoreService;

    /**
     * 查询门店列表
     */
    @PreAuthorize("@ss.hasPermi('system:store:list')")
    @GetMapping("/list")
    public TableDataInfo list(YjStore yjStore)
    {
        startPage();
        yjStore.setTenantId(SecurityUtils.getLoginUser().getNowTenantId());
        List<YjStore> list = yjStoreService.selectYjStoreList(yjStore);
        return getDataTable(list);
    }

    /**
     * 导出门店列表
     */
    @PreAuthorize("@ss.hasPermi('system:store:export')")
    @Log(title = "门店", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YjStore yjStore) throws IOException {
        List<YjStore> list = yjStoreService.selectYjStoreList(yjStore);
        ExcelUtil<YjStore> util = new ExcelUtil<YjStore>(YjStore.class);
        util.exportExcel(response, list, "门店数据");
    }

    /**
     * 获取门店详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:store:query')")
    @GetMapping(value = "/{deptId}")
    public AjaxResult getInfo(@PathVariable("deptId") Long deptId)
    {
        return AjaxResult.success(yjStoreService.selectYjStoreByDeptId(deptId));
    }

    /**
     * 新增门店
     */
    @PreAuthorize("@ss.hasPermi('system:store:add')")
    @Log(title = "门店", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YjStore yjStore)
    {
        return toAjax(yjStoreService.insertYjStore(yjStore));
    }

    /**
     * 修改门店
     */
    @PreAuthorize("@ss.hasPermi('system:store:edit')")
    @Log(title = "门店", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YjStore yjStore)
    {
        return toAjax(yjStoreService.updateYjStore(yjStore));
    }

    /**
     * 删除门店
     */
    @PreAuthorize("@ss.hasPermi('system:store:remove')")
    @Log(title = "门店", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deptIds}")
    public AjaxResult remove(@PathVariable Long[] deptIds)
    {
        return toAjax(yjStoreService.deleteYjStoreByDeptIds(deptIds));
    }
}
