package com.ruoyi.controller;

import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.cs.domain.CsMessageInfo;
import com.ruoyi.cs.domain.template.CsExpansionRecordTemplate;
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.cs.domain.CsExpansionRecord;
import com.ruoyi.cs.service.ICsExpansionRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 扩容记录Controller
 *
 * @author ruoyi
 * @date 2024-05-29
 */
@RestController
@RequestMapping("/cs/csExpansionRecord")
public class CsExpansionRecordController extends BaseController
{
    @Resource
    private ICsExpansionRecordService csExpansionRecordService;

    /**
     * 查询扩容记录列表
     */
    @PreAuthorize("@ss.hasPermi('cs:csExpansionRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(CsExpansionRecord csExpansionRecord)
    {
        startPage();
        csExpansionRecord.setDelFlag("0");
        List<CsExpansionRecord> list = csExpansionRecordService.selectCsExpansionRecordList(csExpansionRecord);
        return getDataTable(list);
    }

    /**
     * 导出扩容记录列表
     */
    @PreAuthorize("@ss.hasPermi('cs:csExpansionRecord:export')")
    @Log(title = "扩容记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CsExpansionRecord csExpansionRecord)
    {
        csExpansionRecord.setDelFlag("0");
        List<CsExpansionRecord> list = csExpansionRecordService.selectCsExpansionRecordList(csExpansionRecord);
        ExcelUtil<CsExpansionRecord> util = new ExcelUtil<CsExpansionRecord>(CsExpansionRecord.class);
        util.exportExcel(response, list, "扩容记录数据");
    }

    /**
     * 导出扩容记录列表模版
     */
    @Log(title = "扩容记录模版", businessType = BusinessType.EXPORT)
    @PostMapping("/exportTemplate")
    public void exportTemplate(HttpServletResponse response)
    {
        ExcelUtil<CsExpansionRecordTemplate> util = new ExcelUtil<CsExpansionRecordTemplate>(CsExpansionRecordTemplate.class);
        util.exportExcel(response, null, "扩容记录数据模版");
    }

    /**
     * 获取扩容记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('cs:csExpansionRecord:query')")
    @GetMapping(value = "/{expansionRecordId}")
    public AjaxResult getInfo(@PathVariable("expansionRecordId") String expansionRecordId)
    {
        return AjaxResult.success(csExpansionRecordService.selectCsExpansionRecordByExpansionRecordId(expansionRecordId));
    }

    /**
     * 新增扩容记录
     */
    @PreAuthorize("@ss.hasPermi('cs:csExpansionRecord:add')")
    @Log(title = "扩容记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CsExpansionRecord csExpansionRecord)
    {
        return toAjax(csExpansionRecordService.insertCsExpansionRecord(csExpansionRecord));
    }

    /**
     * 修改扩容记录
     */
    @PreAuthorize("@ss.hasPermi('cs:csExpansionRecord:edit')")
    @Log(title = "扩容记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CsExpansionRecord csExpansionRecord)
    {
        return toAjax(csExpansionRecordService.updateCsExpansionRecord(csExpansionRecord));
    }

    /**
     * 删除扩容记录
     */
    @PreAuthorize("@ss.hasPermi('cs:csExpansionRecord:remove')")
    @Log(title = "扩容记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{expansionRecordIds}")
    public AjaxResult remove(@PathVariable String[] expansionRecordIds)
    {
        return toAjax(csExpansionRecordService.deleteCsExpansionRecordByExpansionRecordIds(expansionRecordIds));
    }

    /**
     * 查询消息分页列表
     *
     * @param csMessageInfo
     * @return
     */
    @GetMapping("/searchMessagePageList")
    public TableDataInfo searchMessagePageList(CsMessageInfo csMessageInfo)
    {
        startPage();
        List<CsMessageInfo> list = csExpansionRecordService.searchMessageList(csMessageInfo);
        return getDataTable(list);
    }

    /**
     * 查询用户列表
     *
     * @return
     */
    @GetMapping("/searchMemberList")
    public AjaxResult searchMemberList(){
        List<Map<String,Object>> memberList = csExpansionRecordService.searchMemberList();
        return AjaxResult.success(memberList);
    }

    /**
     * 查询单位列表
     *
     * @return
     */
    @GetMapping("/searchCompanyList")
    public AjaxResult searchCompanyList(){
        List<Map<String,Object>> companyList = csExpansionRecordService.searchCompanyList();
        return AjaxResult.success(companyList);
    }

}
