package com.yida.data.system.service.impl;

import cc.mrbird.febs.common.redis.service.RedisService;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yida.data.common.core.entity.CurrentUser;
import com.yida.data.common.core.entity.constant.CachePrefixConstant;
import com.yida.data.common.core.entity.instructions.EduInstructionsType;
import com.yida.data.system.mapper.EduInstructionsTypeMapper;
import com.yida.data.system.service.EduInstructionsTypeService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * Service实现
 *
 * @author wjm
 * @date 2021-08-30 15:54:24
 */
@Service
@RequiredArgsConstructor
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class EduInstructionsTypeServiceImpl extends ServiceImpl
        <EduInstructionsTypeMapper, EduInstructionsType> implements EduInstructionsTypeService {

    private final EduInstructionsTypeMapper eduInstructionsTypeMapper;

    @Resource
    private RedisService redisService;

    @Override
    public List<EduInstructionsType> selectInstructionsTypeList() {
//        //查询父列表，parentCode为null
//        List<EduInstructionsType> list = list(Wrappers.lambdaQuery(new EduInstructionsType())
//                .isNull(EduInstructionsType::getParentTypeCode));
//        //遍历父列表查询子列表
//        for (EduInstructionsType eduInstructionsType : list) {
//            List<EduInstructionsType> listSon = list(Wrappers.lambdaQuery(new EduInstructionsType())
//                    .eq(EduInstructionsType::getParentTypeCode, eduInstructionsType.getTypeCode()));
//            eduInstructionsType.setInstructionsTypes(listSon);
//        }
        return this.list();
    }


    @Override
    public void saveData(EduInstructionsType eduInstructionsType, CurrentUser currentUser) {
        if (ObjectUtils.isEmpty(eduInstructionsType.getId())) {
            //新增
            eduInstructionsType.setCreateDate(LocalDateTime.now());
            eduInstructionsType.setCreateId(currentUser.getUserId());
        } else {
            //编辑
            eduInstructionsType.setUpdateDate(LocalDateTime.now());
            eduInstructionsType.setUpdateId(currentUser.getUserId());
        }
        this.saveOrUpdate(eduInstructionsType);
    }

}
