package com.ruoyi.mall.controller;

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.mall.domain.MallSchoolPosition;
import com.ruoyi.mall.service.IMallSchoolPositionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学校定位Controller
 *
 * @author ruoyi
 * @date 2023-10-28
 */
@RestController
@RequestMapping("/mall/mallSchoolPosition")
public class MallSchoolPositionController extends BaseController
{
    @Autowired
    private IMallSchoolPositionService mallSchoolPositionService;

    /**
     * 查询学校定位列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSchoolPosition:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallSchoolPosition mallSchoolPosition)
    {
        startPage();
        List<MallSchoolPosition> list = mallSchoolPositionService.selectMallSchoolPositionList(mallSchoolPosition);
        return getDataTable(list);
    }

    /**
     * 导出学校定位列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSchoolPosition:export')")
    @Log(title = "学校定位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallSchoolPosition mallSchoolPosition)
    {
        List<MallSchoolPosition> list = mallSchoolPositionService.selectMallSchoolPositionList(mallSchoolPosition);
        ExcelUtil<MallSchoolPosition> util = new ExcelUtil<MallSchoolPosition>(MallSchoolPosition.class);
        util.exportExcel(response, list, "学校定位数据");
    }

    /**
     * 获取学校定位详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSchoolPosition:query')")
    @GetMapping(value = "/{positionId}")
    public AjaxResult getInfo(@PathVariable("positionId") Long positionId)
    {
        return AjaxResult.success(mallSchoolPositionService.selectMallSchoolPositionByPositionId(positionId));
    }

    /**
     * 新增学校定位
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSchoolPosition:add')")
    @Log(title = "学校定位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallSchoolPosition mallSchoolPosition)
    {
        return toAjax(mallSchoolPositionService.insertMallSchoolPosition(mallSchoolPosition));
    }

    /**
     * 修改学校定位
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSchoolPosition:edit')")
    @Log(title = "学校定位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallSchoolPosition mallSchoolPosition)
    {
        return toAjax(mallSchoolPositionService.updateMallSchoolPosition(mallSchoolPosition));
    }

    /**
     * 删除学校定位
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSchoolPosition:remove')")
    @Log(title = "学校定位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{positionIds}")
    public AjaxResult remove(@PathVariable Long[] positionIds)
    {
        return toAjax(mallSchoolPositionService.deleteMallSchoolPositionByPositionIds(positionIds));
    }

    /**
     * 定位列表
     * @return 结果
     */
    @GetMapping("/selectPositionList")
    public AjaxResult selectPositionList(){
        return AjaxResult.success(mallSchoolPositionService.selectPositionList());
    }
}
