package com.ruoyi.web.controller.ss;

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

import com.ruoyi.ss.storeApply.domain.dto.StoreApplyApprovalDTO;
import com.ruoyi.ss.storeApply.service.StoreApplyConverter;
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.storeApply.domain.StoreApply;
import com.ruoyi.ss.storeApply.domain.StoreApplyVO;
import com.ruoyi.ss.storeApply.domain.StoreApplyQuery;
import com.ruoyi.ss.storeApply.service.StoreApplyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 店铺审核Controller
 *
 * @author ruoyi
 * @date 2024-08-03
 */
@RestController
@RequestMapping("/ss/storeApply")
public class StoreApplyController extends BaseController
{
    @Autowired
    private StoreApplyService storeApplyService;

    @Autowired
    private StoreApplyConverter storeApplyConverter;

    /**
     * 查询店铺审核列表
     */
    @PreAuthorize("@ss.hasPermi('ss:storeApply:list')")
    @GetMapping("/list")
    public TableDataInfo list(StoreApplyQuery query)
    {
        startPage();
        startOrderBy();
        List<StoreApplyVO> list = storeApplyService.selectStoreApplyList(query);
        return getDataTable(list);
    }

    /**
     * 导出店铺审核列表
     */
    @PreAuthorize("@ss.hasPermi('ss:storeApply:export')")
    @Log(title = "店铺审核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StoreApplyQuery query)
    {
        List<StoreApplyVO> list = storeApplyService.selectStoreApplyList(query);
        ExcelUtil<StoreApplyVO> util = new ExcelUtil<StoreApplyVO>(StoreApplyVO.class);
        util.exportExcel(response, list, "店铺审核数据");
    }

    /**
     * 获取店铺审核详细信息
     */
    @PreAuthorize("@ss.hasPermi('ss:storeApply:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(storeApplyService.selectStoreApplyById(id));
    }

    /**
     * 新增店铺审核
     */
    @PreAuthorize("@ss.hasPermi('ss:storeApply:add')")
    @Log(title = "店铺审核", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StoreApply storeApply)
    {
        return toAjax(storeApplyService.insertStoreApply(storeApply));
    }

    /**
     * 修改店铺审核
     */
    @PreAuthorize("@ss.hasPermi('ss:storeApply:edit')")
    @Log(title = "店铺审核", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StoreApply storeApply)
    {
        return toAjax(storeApplyService.updateStoreApply(storeApply));
    }

    /**
     * 删除店铺审核
     */
    @PreAuthorize("@ss.hasPermi('ss:storeApply:remove')")
    @Log(title = "店铺审核", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(storeApplyService.deleteStoreApplyByIds(ids));
    }

    /**
     * 审核店铺
     */
    @PreAuthorize("@ss.hasPermi('ss:storeApply:approval')")
    @Log(title = "店铺审核", businessType = BusinessType.OTHER)
	@PutMapping("/approval")
    public AjaxResult approval(@RequestBody @Validated StoreApplyApprovalDTO dto) {
        return toAjax(storeApplyService.approval(storeApplyConverter.toBO(dto)));
    }


}
