package com.ruoyi.system.controller;

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

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

/**
 * 双向呼叫号码Controller
 * 
 * @author ruoyi
 * @date 2025-05-13
 */
@RestController
@RequestMapping("/system/MobileMiddle")
public class MobileMiddleController extends BaseController
{
    @Autowired
    private IMobileMiddleService mobileMiddleService;

    @Autowired
    private IAreaService areaService;
    /**
     * 查询双向呼叫号码列表
     */
    @PreAuthorize("@ss.hasPermi('system:MobileMiddle:list')")
    @GetMapping("/list")
    public TableDataInfo list(MobileMiddle mobileMiddle)
    {
        startPage();
        List<MobileMiddle> list = mobileMiddleService.selectMobileMiddleList(mobileMiddle);
        for(MobileMiddle mobileMiddle1:list){
            Area srea =  areaService.selectAreaById(mobileMiddle1.getCityId());
            mobileMiddle1.setCityName(srea.getTitle());
        }
        return getDataTable(list);
    }

    /**
     * 导出双向呼叫号码列表
     */
    @PreAuthorize("@ss.hasPermi('system:MobileMiddle:export')")
    @Log(title = "双向呼叫号码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MobileMiddle mobileMiddle)
    {
        List<MobileMiddle> list = mobileMiddleService.selectMobileMiddleList(mobileMiddle);
        ExcelUtil<MobileMiddle> util = new ExcelUtil<MobileMiddle>(MobileMiddle.class);
        util.exportExcel(response, list, "双向呼叫号码数据");
    }

    /**
     * 获取双向呼叫号码详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:MobileMiddle:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mobileMiddleService.selectMobileMiddleById(id));
    }

    /**
     * 新增双向呼叫号码
     */
    @PreAuthorize("@ss.hasPermi('system:MobileMiddle:add')")
    @Log(title = "双向呼叫号码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MobileMiddle mobileMiddle)
    {
        return toAjax(mobileMiddleService.insertMobileMiddle(mobileMiddle));
    }

    /**
     * 修改双向呼叫号码
     */
    @PreAuthorize("@ss.hasPermi('system:MobileMiddle:edit')")
    @Log(title = "双向呼叫号码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MobileMiddle mobileMiddle)
    {
        return toAjax(mobileMiddleService.updateMobileMiddle(mobileMiddle));
    }

    /**
     * 删除双向呼叫号码
     */
    @PreAuthorize("@ss.hasPermi('system:MobileMiddle:remove')")
    @Log(title = "双向呼叫号码", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mobileMiddleService.deleteMobileMiddleByIds(ids));
    }
}
