package com.fs.store.controller;

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.store.domain.FsTestReport;
import com.fs.store.param.FsTestReportParam;
import com.fs.store.service.IFsTestReportService;
import com.fs.store.vo.FsTestReportListVO;
import com.fs.store.vo.FsTestReportVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 测试报告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) {
            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(FsTestReport fsTestReport)
    {
        List<FsTestReport> list = fsTestReportService.selectFsTestReportList(fsTestReport);
        ExcelUtil<FsTestReport> util = new ExcelUtil<FsTestReport>(FsTestReport.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();
    }

    /**
     * 新增测试报告
     */
    @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));
    }
}
