package com.benyun.project.third.area.controller;


import com.benyun.common.utils.poi.ExcelUtil;
import com.benyun.framework.aspectj.lang.annotation.Log;
import com.benyun.framework.aspectj.lang.enums.BusinessType;
import com.benyun.framework.web.controller.BaseController;
import com.benyun.framework.web.domain.AjaxResult;
import com.benyun.framework.web.page.TableDataInfo;
import com.benyun.project.third.area.domain.OmsArea;
import com.benyun.project.third.area.service.IOmsAreaService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 行政区划数据Controller
 *
 * @author benyun
 * @date 2023-12-14
 */
@Controller
@RequestMapping("/system/area")
public class OmsAreaController extends BaseController
{
    private String prefix = "system/area";

    @Autowired
    private IOmsAreaService omsAreaService;

    @RequiresPermissions("system:area:view")
    @GetMapping()
    public String area()
    {
        return prefix + "/area";
    }

    /**
     * 查询行政区划数据列表
     */
    @RequiresPermissions("system:area:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OmsArea omsArea)
    {
        startPage();
        List<OmsArea> list = omsAreaService.selectOmsAreaList(omsArea);
        return getDataTable(list);
    }

    /**
     * 导出行政区划数据列表
     */
    @RequiresPermissions("system:area:export")
    @Log(title = "行政区划数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OmsArea omsArea)
    {
        List<OmsArea> list = omsAreaService.selectOmsAreaList(omsArea);
        ExcelUtil<OmsArea> util = new ExcelUtil<OmsArea>(OmsArea.class);
        return util.exportExcel(list, "行政区划数据数据");
    }

    /**
     * 新增行政区划数据
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存行政区划数据
     */
    @RequiresPermissions("system:area:add")
    @Log(title = "行政区划数据", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OmsArea omsArea)
    {
        return toAjax(omsAreaService.insertOmsArea(omsArea));
    }

    /**
     * 修改行政区划数据
     */
    @RequiresPermissions("system:area:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        OmsArea omsArea = omsAreaService.selectOmsAreaById(id);
        mmap.put("omsArea", omsArea);
        return prefix + "/edit";
    }

    /**
     * 修改保存行政区划数据
     */
    @RequiresPermissions("system:area:edit")
    @Log(title = "行政区划数据", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OmsArea omsArea)
    {
        return toAjax(omsAreaService.updateOmsArea(omsArea));
    }

    /**
     * 删除行政区划数据
     */
    @RequiresPermissions("system:area:remove")
    @Log(title = "行政区划数据", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(omsAreaService.deleteOmsAreaByIds(ids));
    }
}
