package com.xinelu.manage.service.specialdiseasetriggercondition.impl;

import com.xinelu.common.utils.SecurityUtils;
import com.xinelu.manage.domain.specialdiseasetriggercondition.SpecialDiseaseTriggerCondition;
import com.xinelu.manage.dto.specialdiseasetriggercondition.TriggerConditionDTO;
import com.xinelu.manage.mapper.specialdiseasetriggercondition.SpecialDiseaseTriggerConditionMapper;
import com.xinelu.manage.service.specialdiseasetriggercondition.ISpecialDiseaseTriggerConditionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;


/**
 * 触发条件关系Service业务层处理
 *
 * @author xinelu
 * @date 2024-03-18
 */
@Service
public class SpecialDiseaseTriggerConditionServiceImpl implements ISpecialDiseaseTriggerConditionService {
    @Resource
    private SpecialDiseaseTriggerConditionMapper specialDiseaseTriggerConditionMapper;

    /**
     * 查询触发条件关系
     *
     * @param id 触发条件关系主键
     * @return 触发条件关系
     */
    @Override
    public SpecialDiseaseTriggerCondition selectSpecialDiseaseTriggerConditionById(Long id) {
        return specialDiseaseTriggerConditionMapper.selectSpecialDiseaseTriggerConditionById(id);
    }

    /**
     * 查询触发条件关系列表
     *
     * @param specialDiseaseTriggerCondition 触发条件关系
     * @return 触发条件关系
     */
    @Override
    public List<SpecialDiseaseTriggerCondition> selectSpecialDiseaseTriggerConditionList(SpecialDiseaseTriggerCondition specialDiseaseTriggerCondition) {
        return specialDiseaseTriggerConditionMapper.selectSpecialDiseaseTriggerConditionList(specialDiseaseTriggerCondition);
    }

    /**
     * 新增触发条件关系
     *
     * @param triggerConditionList 触发条件关系
     * @return 结果
     */
    @Override
    public int insertSpecialDiseaseTriggerCondition(TriggerConditionDTO triggerConditionList) {
        triggerConditionList.getTriggerConditionList().forEach(item -> item.setCreateTime(LocalDateTime.now()));
        triggerConditionList.getTriggerConditionList().forEach(item -> item.setCreateBy(SecurityUtils.getUsername()));
        return specialDiseaseTriggerConditionMapper.insertTriggerConditionList(triggerConditionList.getTriggerConditionList());
    }

    /**
     * 修改触发条件关系
     *
     * @param specialDiseaseTriggerCondition 触发条件关系
     * @return 结果
     */
    @Override
    public int updateSpecialDiseaseTriggerCondition(SpecialDiseaseTriggerCondition specialDiseaseTriggerCondition) {
        specialDiseaseTriggerCondition.setUpdateTime(LocalDateTime.now());
        specialDiseaseTriggerCondition.setUpdateBy(SecurityUtils.getUsername());
        return specialDiseaseTriggerConditionMapper.updateSpecialDiseaseTriggerCondition(specialDiseaseTriggerCondition);
    }

    /**
     * 批量删除触发条件关系
     *
     * @param ids 需要删除的触发条件关系主键
     * @return 结果
     */
    @Override
    public int deleteSpecialDiseaseTriggerConditionByIds(Long[] ids) {
        return specialDiseaseTriggerConditionMapper.deleteSpecialDiseaseTriggerConditionByIds(ids);
    }

    /**
     * 删除触发条件关系信息
     *
     * @param id 触发条件关系主键
     * @return 结果
     */
    @Override
    public int deleteSpecialDiseaseTriggerConditionById(Long id) {
        return specialDiseaseTriggerConditionMapper.deleteSpecialDiseaseTriggerConditionById(id);
    }
}
