package com.fs.his.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.fs.common.utils.ParseUtils;
import com.fs.common.utils.SecurityUtils;
import com.fs.his.param.FsFollowReportParam;
import com.fs.his.vo.FsFollowReportListVO;
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.FsFollowReport;
import com.fs.his.service.IFsFollowReportService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 咨询报告Controller
 *
 * @author fs
 * @date 2024-01-29
 */
@RestController
@RequestMapping("/his/FsFollowReport")
public class FsFollowReportController extends BaseController
{
    @Autowired
    private IFsFollowReportService fsFollowReportService;

    /**
     * 查询咨询报告列表
     */
    @PreAuthorize("@ss.hasPermi('his:FsFollowReport:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsFollowReportParam fsFollowReport)
    {
        startPage();
        List<FsFollowReportListVO> list = fsFollowReportService.selectFsFollowReportListVO(fsFollowReport);
        for (FsFollowReportListVO fsFollowReportListVO : list) {
            fsFollowReportListVO.setPhone(ParseUtils.parsePhone(fsFollowReportListVO.getPhone()));
        }
        return getDataTable(list);
    }

    /**
     * 导出咨询报告列表
     */
    @PreAuthorize("@ss.hasPermi('his:FsFollowReport:export')")
    @Log(title = "咨询报告", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsFollowReportParam fsFollowReport)
    {
        logger.info("zx>\n【咨询报告】：{}", SecurityUtils.getUserId());
        if (fsFollowReportService.isEntityNull(fsFollowReport)){
            return AjaxResult.error("请筛选数据导出");
        }
        Long count = fsFollowReportService.selectFsFollowReportListVOCount(fsFollowReport);
        if (count>30000){
            return AjaxResult.error("导出数据不可超过3w条");
        }
        List<FsFollowReportListVO> list = fsFollowReportService.selectFsFollowReportListVO(fsFollowReport);

        for (FsFollowReportListVO fsFollowReportListVO : list) {
            fsFollowReportListVO.setPhone(ParseUtils.parsePhone(fsFollowReportListVO.getPhone()));
        }ExcelUtil<FsFollowReportListVO> util = new ExcelUtil<FsFollowReportListVO>(FsFollowReportListVO.class);
        return util.exportExcel(list, "咨询报告数据");
    }

    /**
     * 获取咨询报告详细信息
     */
    @PreAuthorize("@ss.hasPermi('his:FsFollowReport:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fsFollowReportService.selectFsFollowReportById(id));
    }

    /**
     * 新增咨询报告
     */
    @PreAuthorize("@ss.hasPermi('his:FsFollowReport:add')")
    @Log(title = "咨询报告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsFollowReport fsFollowReport)
    {
        return toAjax(fsFollowReportService.insertFsFollowReport(fsFollowReport));
    }

    /**
     * 修改咨询报告
     */
    @PreAuthorize("@ss.hasPermi('his:FsFollowReport:edit')")
    @Log(title = "咨询报告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsFollowReport fsFollowReport)
    {
        return toAjax(fsFollowReportService.updateFsFollowReport(fsFollowReport));
    }

    /**
     * 删除咨询报告
     */
    @PreAuthorize("@ss.hasPermi('his:FsFollowReport:remove')")
    @Log(title = "咨询报告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fsFollowReportService.deleteFsFollowReportByIds(ids));
    }
}
