package com.fs.doctor.controller;

import com.fs.common.annotation.Log;
import com.fs.common.config.LoginContextManager;
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.doctor.domain.DoctorBalanceLog;
import com.fs.doctor.service.IDoctorBalanceLogService;
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 2026-01-26
 */
@RestController
@RequestMapping("/doctor/log")
public class DoctorBalanceLogController extends BaseController
{
    @Autowired
    private IDoctorBalanceLogService doctorBalanceLogService;

    /**
     * 查询医生积分变动记录列表
     */
    @PreAuthorize("@ss.hasPermi('doctor:log:list')")
    @GetMapping("/list")
    public TableDataInfo list(DoctorBalanceLog doctorBalanceLog)
    {
        startPage();
        Long currentCompanyId = LoginContextManager.getCurrentCompanyId();
        doctorBalanceLog.setCompanyId(currentCompanyId);
        List<DoctorBalanceLog> list = doctorBalanceLogService.selectDoctorBalanceLogList(doctorBalanceLog);
        return getDataTable(list);
    }

    /**
     * 导出医生积分变动记录列表
     */
    @PreAuthorize("@ss.hasPermi('doctor:log:export')")
    @Log(title = "医生积分变动记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DoctorBalanceLog doctorBalanceLog)
    {
        Long currentCompanyId = LoginContextManager.getCurrentCompanyId();
        doctorBalanceLog.setCompanyId(currentCompanyId);
        List<DoctorBalanceLog> list = doctorBalanceLogService.selectDoctorBalanceLogList(doctorBalanceLog);
        ExcelUtil<DoctorBalanceLog> util = new ExcelUtil<DoctorBalanceLog>(DoctorBalanceLog.class);
        return util.exportExcel(list, "医生积分变动记录数据");
    }

    /**
     * 获取医生积分变动记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('doctor:log:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(doctorBalanceLogService.selectDoctorBalanceLogById(id));
    }

    /**
     * 新增医生积分变动记录
     */
    @PreAuthorize("@ss.hasPermi('doctor:log:add')")
    @Log(title = "医生积分变动记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DoctorBalanceLog doctorBalanceLog)
    {
        Long currentCompanyId = LoginContextManager.getCurrentCompanyId();
        doctorBalanceLog.setCompanyId(currentCompanyId);
        return toAjax(doctorBalanceLogService.insertDoctorBalanceLog(doctorBalanceLog));
    }

    /**
     * 修改医生积分变动记录
     */
    @PreAuthorize("@ss.hasPermi('doctor:log:edit')")
    @Log(title = "医生积分变动记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DoctorBalanceLog doctorBalanceLog)
    {
        Long currentCompanyId = LoginContextManager.getCurrentCompanyId();
        doctorBalanceLog.setCompanyId(currentCompanyId);
        return toAjax(doctorBalanceLogService.updateDoctorBalanceLog(doctorBalanceLog));
    }

    /**
     * 删除医生积分变动记录
     */
    @PreAuthorize("@ss.hasPermi('doctor:log:remove')")
    @Log(title = "医生积分变动记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(doctorBalanceLogService.deleteDoctorBalanceLogByIds(ids));
    }
}
