package com.cyksj.service.mange.form.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cyksj.mapper.manage.form.QuestionnairePromotionMapper;
import com.cyksj.model.entity.QuestionnairePromotion;
import com.cyksj.service.mange.form.QuestionnairePromotionService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/*
 *项目名: netflix
 *文件名: QuestionnairePromotionServiceImpl
 *创建者: JavaZou
 *创建时间:2023/6/14 11:42
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class QuestionnairePromotionServiceImpl extends ServiceImpl<QuestionnairePromotionMapper, QuestionnairePromotion> implements QuestionnairePromotionService {
	private final QuestionnairePromotionMapper promotionMapper;

	@Override
	public Long saveOrUpdatePromotion(QuestionnairePromotion promotion) {
		if (promotion.getId() == null) {
			promotionMapper.insert(promotion);
			return promotion.getId();
		}
		QuestionnairePromotion db = promotionMapper.selectById(promotion.getId());
		if (db.getIsUp()) {
			promotion.setTemplateId(null);
			promotion.setIsUp(true);
		}
		promotionMapper.updateById(promotion);
		return promotion.getId();
	}
}
