package com.fs.his.controller;

import java.util.List;

import com.fs.his.param.FsTestReportParam;
import com.fs.his.vo.FsTestReportListVO;
import com.fs.his.vo.FsTestReportVO;
import com.fs.his.vo.FsUserCouponListVO;
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.FsTestReport;
import com.fs.his.service.IFsTestReportService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 测试报告Controller
 *
 * @author fs
 * @date 2023-09-04
 */
@RestController
@RequestMapping("/his/testReport")
public class FsTestReportController extends BaseController
{
    @Autowired
    private IFsTestReportService fsTestReportService;

    /**
     * 查询测试报告列表
     */
    @PreAuthorize("@ss.hasPermi('his:testReport:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsTestReportParam fsTestReport)
    {
        startPage();
        List<FsTestReportListVO> list = fsTestReportService.selectFsTestReportListVO(fsTestReport);
        for (FsTestReportListVO vo : list) {
            if (vo.getPhone()!=null&&vo.getPhone()!=""){
                vo.setPhone(vo.getPhone().replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2"));
            }

        }
        return getDataTable(list);
    }

    /**
     * 导出测试报告列表
     */
    @PreAuthorize("@ss.hasPermi('his:testReport:export')")
    @Log(title = "测试报告", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsTestReportParam fsTestReport)
    {
        List<FsTestReportListVO> list = fsTestReportService.selectFsTestReportListVO(fsTestReport);
        for (FsTestReportListVO vo : list) {
            if (vo.getPhone()!=null&&vo.getPhone()!=""){
                vo.setPhone(vo.getPhone().replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2"));
            }

        }
        ExcelUtil<FsTestReportListVO> util = new ExcelUtil<FsTestReportListVO>(FsTestReportListVO.class);
        return util.exportExcel(list, "测试报告数据");
    }

    /**
     * 获取测试报告详细信息
     */
    @PreAuthorize("@ss.hasPermi('his:testReport:query')")
    @GetMapping(value = "/{reportId}")
    public AjaxResult getInfo(@PathVariable("reportId") Long reportId)
    {
        FsTestReportVO  fsTestReportVO = fsTestReportService.selectFsTestReportByReportIdVO(reportId);
        if (fsTestReportVO.getPhone()!=null){
            fsTestReportVO.setPhone(fsTestReportVO.getPhone().replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2"));
        }
        return AjaxResult.success(fsTestReportVO);
    }

    /**
     * 新增测试报告
     */
    @PreAuthorize("@ss.hasPermi('his:testReport:add')")
    @Log(title = "测试报告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsTestReport fsTestReport)
    {
        return toAjax(fsTestReportService.insertFsTestReport(fsTestReport));
    }

    /**
     * 修改测试报告
     */
    @PreAuthorize("@ss.hasPermi('his:testReport:edit')")
    @Log(title = "测试报告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsTestReport fsTestReport)
    {

        return toAjax(fsTestReportService.updateFsTestReport(fsTestReport));
    }

    /**
     * 删除测试报告
     */
    @PreAuthorize("@ss.hasPermi('his:testReport:remove')")
    @Log(title = "测试报告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reportIds}")
    public AjaxResult remove(@PathVariable Long[] reportIds)
    {
        return toAjax(fsTestReportService.deleteFsTestReportByReportIds(reportIds));
    }
}
