package com.fs.company.controller.store;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.framework.security.LoginUser;
import com.fs.his.param.FsDrugReportCountParam;
import com.fs.his.service.IFsDrugReportCountService;
import com.fs.his.vo.FsDrugReportCountListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

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

    /**
     * 查询咨询统计列表
     */
    @PreAuthorize("@ss.hasPermi('store:drugReportCount:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsDrugReportCountParam fsDrugReportCount)
    {
        startPage();
        LoginUser loginUser = com.fs.framework.security.SecurityUtils.getLoginUser();
        fsDrugReportCount.setCompanyId(loginUser.getUser().getCompanyId());
        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('store:drugReportCount:export')")
    @Log(title = "咨询统计", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsDrugReportCountParam fsDrugReportCount)
    {
        LoginUser loginUser = com.fs.framework.security.SecurityUtils.getLoginUser();
        fsDrugReportCount.setCompanyId(loginUser.getUser().getCompanyId());
        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('store:drugReportCount:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fsDrugReportCountService.selectFsDrugReportCountById(id));
    }





}
