package com.fs.his.controller;

import java.util.List;

import com.fs.his.param.FsDrugReportCountParam;
import com.fs.his.vo.FsDrugReportCountListVO;
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.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.his.domain.FsDrugReportCount;
import com.fs.his.service.IFsDrugReportCountService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 咨询统计Controller
 *
 * @author fs
 * @date 2024-04-28
 */
@RestController
@RequestMapping("/his/drugReportCount")
public class FsDrugReportCountController extends BaseController
{
    @Autowired
    private IFsDrugReportCountService fsDrugReportCountService;

    /**
     * 查询咨询统计列表
     */
    @PreAuthorize("@ss.hasPermi('his:drugReportCount:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsDrugReportCountParam fsDrugReportCount)
    {
        startPage();
        List<FsDrugReportCountListVO> list = fsDrugReportCountService.selectFsDrugReportCountListVO(fsDrugReportCount);
        for (FsDrugReportCountListVO vo : list){
            if (vo.getPhone() != null) {
                vo.setPhone(vo.getPhone().replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2"));
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出咨询统计列表
     */
    @PreAuthorize("@ss.hasPermi('his:drugReportCount:export')")
    @Log(title = "咨询统计", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsDrugReportCountParam fsDrugReportCount)
    {
        List<FsDrugReportCountListVO> list = fsDrugReportCountService.selectFsDrugReportCountListVO(fsDrugReportCount);
        for (FsDrugReportCountListVO vo : list){
            if (vo.getPhone() != null) {
                vo.setPhone(vo.getPhone().replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2"));
            }
        }
        ExcelUtil<FsDrugReportCountListVO> util = new ExcelUtil<FsDrugReportCountListVO>(FsDrugReportCountListVO.class);
        return util.exportExcel(list, "咨询统计数据");
    }

    /**
     * 获取咨询统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('his:drugReportCount:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fsDrugReportCountService.selectFsDrugReportCountById(id));
    }

    /**
     * 新增咨询统计
     */
    @PreAuthorize("@ss.hasPermi('his:drugReportCount:add')")
    @Log(title = "咨询统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsDrugReportCount fsDrugReportCount)
    {
        return toAjax(fsDrugReportCountService.insertFsDrugReportCount(fsDrugReportCount));
    }

    /**
     * 修改咨询统计
     */
    @PreAuthorize("@ss.hasPermi('his:drugReportCount:edit')")
    @Log(title = "咨询统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsDrugReportCount fsDrugReportCount)
    {
        return toAjax(fsDrugReportCountService.updateFsDrugReportCount(fsDrugReportCount));
    }

    /**
     * 删除咨询统计
     */
    @PreAuthorize("@ss.hasPermi('his:drugReportCount:remove')")
    @Log(title = "咨询统计", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fsDrugReportCountService.deleteFsDrugReportCountByIds(ids));
    }
}
