package com.yida.data.school.transaction.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yida.data.common.core.entity.apply.EduApplyFunction;
import com.yida.data.common.core.entity.constant.FebsConstant;
import com.yida.data.school.transaction.mapper.EduApplyFunctionMapper;
import com.yida.data.school.transaction.mapper.EduApplyMapper;
import com.yida.data.school.transaction.service.EduApplyFunctionService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

import cc.mrbird.febs.common.redis.service.RedisService;


@Service
public class EduApplyFunctionServiceImpl extends ServiceImpl<EduApplyFunctionMapper, EduApplyFunction> implements EduApplyFunctionService {

    @Autowired
    private RedisService redisService;
    @Resource
    private EduApplyFunctionMapper eduApplyFunctionMapper;
    @Resource
    private EduApplyMapper eduApplyMapper;


    //新增应用功能
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void insertEduApplyFunctionService(EduApplyFunction eduApplyFunction) {
        String applyName = eduApplyMapper.selectById(eduApplyFunction.getApplyId()).getApplyName();
        redisService.set(FebsConstant.EDU_FUNCTION + applyName, eduApplyFunction.getFunctionName());
        eduApplyFunctionMapper.insert(eduApplyFunction);

    }

    //修改应用功能
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void upDataEduApplyFunctionService(EduApplyFunction eduApplyFunction) {


        String applyName = eduApplyMapper.selectById(eduApplyFunction.getApplyId()).getApplyName();
        redisService.del(FebsConstant.EDU_FUNCTION + applyName);
        eduApplyFunctionMapper.updateById(eduApplyFunction);
        redisService.del(FebsConstant.EDU_FUNCTION + applyName);
    }

    //删除应用功能
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void removeEduApplyFunctionService(Long productId) {
        Long applyId = eduApplyFunctionMapper.selectById(productId).getApplyId();
        String applyName = eduApplyMapper.selectById(applyId).getApplyName();
        redisService.del(FebsConstant.EDU_FUNCTION + applyName);
        eduApplyFunctionMapper.deleteById(productId);

    }
}
