package com.ruoyi.web.controller.system;

import java.util.List;
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.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ClewPhone;
import com.ruoyi.system.service.IClewPhoneService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 线索手机号Controller
 *
 * @author ruoyi
 * @date 2023-07-19
 */
@Controller
@RequestMapping("/system/phone")
public class ClewPhoneController extends BaseController
{
    private String prefix = "system/phone";

    @Autowired
    private IClewPhoneService clewPhoneService;

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

    /**
     * 查询线索手机号列表
     */
    @RequiresPermissions("system:phone:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ClewPhone clewPhone)
    {
        startPage();
        List<ClewPhone> list = clewPhoneService.selectClewPhoneList(clewPhone);
        list.forEach(model->{
            if(model.getSourceApp() != null && model.getSourceApp() == 2L){
                model.setSourceAppName("大象处理逾期");
            }else {
                model.setSourceAppName("黑猫搞定逾期");
            }
        });
        return getDataTable(list);
    }

    /**
     * 导出线索手机号列表
     */
    @RequiresPermissions("system:phone:export")
    @Log(title = "线索手机号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ClewPhone clewPhone)
    {
        List<ClewPhone> list = clewPhoneService.selectClewPhoneList(clewPhone);
        ExcelUtil<ClewPhone> util = new ExcelUtil<ClewPhone>(ClewPhone.class);
        return util.exportExcel(list, "线索手机号数据");
    }

    /**
     * 新增线索手机号
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存线索手机号
     */
    @RequiresPermissions("system:phone:add")
    @Log(title = "线索手机号", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ClewPhone clewPhone)
    {
        return toAjax(clewPhoneService.insertClewPhone(clewPhone));
    }

    /**
     * 修改线索手机号
     */
    @RequiresPermissions("system:phone:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ClewPhone clewPhone = clewPhoneService.selectClewPhoneById(id);
        mmap.put("clewPhone", clewPhone);
        return prefix + "/edit";
    }

    /**
     * 修改保存线索手机号
     */
    @RequiresPermissions("system:phone:edit")
    @Log(title = "线索手机号", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ClewPhone clewPhone)
    {
        return toAjax(clewPhoneService.updateClewPhone(clewPhone));
    }

    /**
     * 删除线索手机号
     */
    @RequiresPermissions("system:phone:remove")
    @Log(title = "线索手机号", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(clewPhoneService.deleteClewPhoneByIds(ids));
    }
}
