package com.example.removetolocal.service.impl;

import com.example.removetolocal.newtrain.dao.TrainThemeDao;
import com.example.removetolocal.newtrain.dao.TrainUserDao;
import com.example.removetolocal.newtrain.entity.TrainTheme;
import com.example.removetolocal.newuser.domin.Units;
import com.example.removetolocal.newuser.domin.User;
import com.example.removetolocal.oldtrain.dao.DevTrainDao;
import com.example.removetolocal.oldtrain.dao.DevTrainEnrollDao;
import com.example.removetolocal.service.TrainService;
import com.example.removetolocal.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Author zjm
 * @Description TODO
 * @Date 2020/12/25 下午3:39
 * @Version 1.0
 */
public class TrainServiceImpl implements TrainService {
    @Autowired
    TrainThemeDao trainThemeDao;
    @Autowired
    TrainUserDao trainUserDao;
    @Autowired
    DevTrainDao devTrainDao;
    @Autowired
    DevTrainEnrollDao devTrainEnrollDao;
    @Autowired
    UserService userService;
    @Override
    public void trainDcToNew() {
        devTrainDao.findAll().forEach(
                devTrain -> {
                  TrainTheme trainTheme=devTrain.toTrainTheme();
                  User user= userService.getUserByOldId(devTrain.getCreateuser());
                  trainTheme.setOriginatorId(user.getUserId());
                  trainTheme.setOriginatorName(user.getName());
                  Units units= userService.getUnitByOldId(devTrain.getHost());
                  trainTheme.setUnitsId(units.getUnitId());
                  trainTheme.setUnitsName(units.getName());

                  TrainTheme trainTheme1= trainThemeDao.save(trainTheme);


                }
        );

    }
}
