package com.ruoyi.system.controller;

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

import com.ruoyi.system.domain.Area;
import com.ruoyi.system.domain.MobileMiddle;
import com.ruoyi.system.service.IAreaService;
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.system.domain.MobileNotify;
import com.ruoyi.system.service.IMobileNotifyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 语音通知号码Controller
 * 
 * @author ruoyi
 * @date 2025-05-13
 */
@RestController
@RequestMapping("/system/MobileNotify")
public class MobileNotifyController extends BaseController
{
    @Autowired
    private IMobileNotifyService mobileNotifyService;
    @Autowired
    private IAreaService areaService;
    /**
     * 查询语音通知号码列表
     */
    @PreAuthorize("@ss.hasPermi('system:MobileNotify:list')")
    @GetMapping("/list")
    public TableDataInfo list(MobileNotify mobileNotify)
    {
        startPage();
        List<MobileNotify> list = mobileNotifyService.selectMobileNotifyList(mobileNotify);
        for(MobileNotify mobileNotify1:list){
            Area srea =  areaService.selectAreaById(Long.valueOf(mobileNotify1.getCityId()));
            mobileNotify1.setCityName(srea.getTitle());
        }
        return getDataTable(list);

    }

    /**
     * 导出语音通知号码列表
     */
    @PreAuthorize("@ss.hasPermi('system:MobileNotify:export')")
    @Log(title = "语音通知号码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MobileNotify mobileNotify)
    {
        List<MobileNotify> list = mobileNotifyService.selectMobileNotifyList(mobileNotify);
        ExcelUtil<MobileNotify> util = new ExcelUtil<MobileNotify>(MobileNotify.class);
        util.exportExcel(response, list, "语音通知号码数据");
    }

    /**
     * 获取语音通知号码详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:MobileNotify:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mobileNotifyService.selectMobileNotifyById(id));
    }

    /**
     * 新增语音通知号码
     */
    @PreAuthorize("@ss.hasPermi('system:MobileNotify:add')")
    @Log(title = "语音通知号码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MobileNotify mobileNotify)
    {
        return toAjax(mobileNotifyService.insertMobileNotify(mobileNotify));
    }

    /**
     * 修改语音通知号码
     */
    @PreAuthorize("@ss.hasPermi('system:MobileNotify:edit')")
    @Log(title = "语音通知号码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MobileNotify mobileNotify)
    {
        return toAjax(mobileNotifyService.updateMobileNotify(mobileNotify));
    }

    /**
     * 删除语音通知号码
     */
    @PreAuthorize("@ss.hasPermi('system:MobileNotify:remove')")
    @Log(title = "语音通知号码", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mobileNotifyService.deleteMobileNotifyByIds(ids));
    }
}
