package com.ruoyi.web.controller.ss;

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

import com.ruoyi.common.core.domain.ValidGroup;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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.storeStaff.domain.StoreStaff;
import com.ruoyi.ss.storeStaff.domain.StoreStaffVO;
import com.ruoyi.ss.storeStaff.domain.StoreStaffQuery;
import com.ruoyi.ss.storeStaff.service.StoreStaffService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 店铺员工Controller
 *
 * @author ruoyi
 * @date 2024-11-13
 */
@RestController
@RequestMapping("/ss/storeStaff")
public class StoreStaffController extends BaseController
{
    @Autowired
    private StoreStaffService storeStaffService;

    /**
     * 查询店铺员工列表
     */
    @PreAuthorize("@ss.hasPermi('ss:storeStaff:list')")
    @GetMapping("/list")
    public TableDataInfo list(StoreStaffQuery query)
    {
        startPage();
        startOrderBy();
        List<StoreStaffVO> list = storeStaffService.selectStoreStaffList(query);
        return getDataTable(list);
    }

    /**
     * 导出店铺员工列表
     */
    @PreAuthorize("@ss.hasPermi('ss:storeStaff:export')")
    @Log(title = "店铺员工", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StoreStaffQuery query)
    {
        List<StoreStaffVO> list = storeStaffService.selectStoreStaffList(query);
        ExcelUtil<StoreStaffVO> util = new ExcelUtil<StoreStaffVO>(StoreStaffVO.class);
        util.exportExcel(response, list, "店铺员工数据");
    }

    /**
     * 获取店铺员工详细信息
     */
    @PreAuthorize("@ss.hasPermi('ss:storeStaff:query')")
    @GetMapping(value = "/{employId}")
    public AjaxResult getInfo(@PathVariable("employId") Long employId)
    {
        return success(storeStaffService.selectStoreStaffByEmployId(employId));
    }

    /**
     * 新增店铺员工
     */
    @PreAuthorize("@ss.hasPermi('ss:storeStaff:add')")
    @Log(title = "店铺员工", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated(ValidGroup.Create.class) StoreStaff storeStaff)
    {
        storeStaff.setCreateBy(getUsername());
        return toAjax(storeStaffService.insertStoreStaff(storeStaff));
    }

    /**
     * 修改店铺员工
     */
    @PreAuthorize("@ss.hasPermi('ss:storeStaff:edit')")
    @Log(title = "店铺员工", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody @Validated(ValidGroup.Update.class) StoreStaff storeStaff)
    {
        return toAjax(storeStaffService.updateStoreStaff(storeStaff));
    }

    /**
     * 删除店铺员工
     */
    @PreAuthorize("@ss.hasPermi('ss:storeStaff:remove')")
    @Log(title = "店铺员工", businessType = BusinessType.DELETE)
	@DeleteMapping("/{employIds}")
    public AjaxResult remove(@PathVariable List<Long> employIds)
    {
        return toAjax(storeStaffService.deleteStoreStaffByEmployIds(employIds));
    }
}
