package com.xinelu.familydoctor.service.impl;

import com.xinelu.common.utils.SecurityUtils;
import com.xinelu.familydoctor.entity.EvaluateAdviceTemplate;
import com.xinelu.familydoctor.mapper.EvaluateAdviceTemplateMapper;
import com.xinelu.familydoctor.service.EvaluateAdviceTemplateService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author gaoyu
 * @description 自我评估处方模板实现类
 * @date 2023-10-16 16:58
 */
@Service
public class EvaluateAdviceTemplateServiceImpl implements EvaluateAdviceTemplateService {
    @Resource
    private EvaluateAdviceTemplateMapper evaluateAdviceTemplateMapper;

    @Override
    public List<EvaluateAdviceTemplate> findList(EvaluateAdviceTemplate entity) {
        return evaluateAdviceTemplateMapper.findList(entity);
    }

    @Override
    public EvaluateAdviceTemplate getTemplate(String templateType) {
        return evaluateAdviceTemplateMapper.getTemplateByType(templateType);
    }

    @Override
    public void save(EvaluateAdviceTemplate entity) {
        if (entity.getId() == null) {
            entity.setCreateTime(new Date());
            entity.setCreateBy(SecurityUtils.getUserId());
            entity.setDelFlag("1");
            evaluateAdviceTemplateMapper.insert(entity);
        } else {
            entity.setUpdateBy(SecurityUtils.getUserId());
            entity.setUpdateTime(new Date());
            evaluateAdviceTemplateMapper.update(entity);
        }
    }

    @Override
    public void changeStatus(EvaluateAdviceTemplate entity) {
        entity.setUpdateBy(SecurityUtils.getUserId());
        entity.setUpdateTime(new Date());
        evaluateAdviceTemplateMapper.update(entity);
    }

    @Override
    public void delTemplate(Long id) {
        EvaluateAdviceTemplate entity = new EvaluateAdviceTemplate();
        entity.setId(id);
        entity.setDelFlag("2");
        entity.setUpdateBy(SecurityUtils.getUserId());
        entity.setUpdateTime(new Date());
        evaluateAdviceTemplateMapper.update(entity);
    }
}
