// com/fs/his/service/impl/FsDoctorCommonDiagnoseServiceImpl.java
package com.fs.his.service.impl;

import com.fs.common.core.domain.R;
import com.fs.his.mapper.FsDoctorCommonDiagnoseMapper;
import com.fs.his.param.FsDoctorCommonDiagnose;
import com.fs.his.service.IFsDoctorCommonDiagnoseService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class FsDoctorCommonDiagnoseServiceImpl implements IFsDoctorCommonDiagnoseService {

    @Autowired
    private FsDoctorCommonDiagnoseMapper mapper;

    @Override
    public PageInfo<FsDoctorCommonDiagnose> getList(FsDoctorCommonDiagnose param, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<FsDoctorCommonDiagnose> fsDoctorCommonDiagnoses = mapper.selectList(param);
        return new PageInfo<>(fsDoctorCommonDiagnoses);
    }

    @Override
    public R add(FsDoctorCommonDiagnose diagnose) {
        if (StringUtils.isEmpty(diagnose.getDiagnose())) {
            return R.error("诊断内容不能为空");
        }
        // 可选：检查是否重复
        // int count = mapper.countByDoctorIdAndDiagnose(diagnose.getDoctorId(), diagnose.getDiagnose());
        // if (count > 0) return R.error("该诊断已存在");

        diagnose.setCreateTime(new java.util.Date());
        int result = mapper.insert(diagnose);
        return result > 0 ? R.ok() : R.error("新增失败");
    }

    @Override
    public R edit(FsDoctorCommonDiagnose diagnose) {
        if (diagnose.getCommonDiagnoseId() == null) {
            return R.error("ID不能为空");
        }
        if (StringUtils.isEmpty(diagnose.getDiagnose())) {
            return R.error("诊断内容不能为空");
        }
        int result = mapper.updateById(diagnose);
        return result > 0 ? R.ok() : R.error("编辑失败");
    }

    @Override
    public R delete(Long id) {
        if (id == null) {
            return R.error("ID不能为空");
        }
        int result = mapper.deleteById(id);
        return result > 0 ? R.ok() : R.error("删除失败");
    }
}