package com.siwei.center.scene.listener;
import cn.hutool.core.collection.CollUtil;
import com.google.common.collect.Lists;
import com.siwei.center.scene.mapper.SceneTypeMapper;
import com.siwei.center.scene.pojo.po.SceneInfo;
import com.siwei.center.scene.pojo.po.SceneType;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* 设备树初始化
* @author 英俊潇洒小美女
* @date 2022/06/30
*/
@Component
public class SceneInfoEventListener implements ApplicationListener<ApplicationReadyEvent> {
@Resource
private SceneTypeMapper sceneTypeMapper;
@Override
public void onApplicationEvent(ApplicationReadyEvent event) {
//设备类型初始化
ArrayList<SceneType> sceneTypes = Lists.newArrayList();
SceneType equipmentType = new SceneType().setId(1L).setTypeName("设备").setIsSysType(1).setIsOperable(0).setCreateTime(LocalDateTime.now()).setUpdateTime(LocalDateTime.now());
SceneType sceneType = new SceneType().setId(2L).setTypeName("部件").setIsSysType(1).setIsOperable(0).setCreateTime(LocalDateTime.now()).setUpdateTime(LocalDateTime.now());
SceneType partType = new SceneType().setId(3L).setTypeName("电表").setIsSysType(1).setIsOperable(0).setCreateTime(LocalDateTime.now()).setUpdateTime(LocalDateTime.now());
SceneType componentsType = new SceneType().setId(4L).setTypeName("零件").setIsSysType(1).setIsOperable(0).setCreateTime(LocalDateTime.now()).setUpdateTime(LocalDateTime.now());
SceneType wholePlantType = new SceneType().setId(5L).setTypeName("全厂").setIsSysType(1).setIsOperable(1).setCreateTime(LocalDateTime.now()).setUpdateTime(LocalDateTime.now());
SceneType lineType = new SceneType().setId(6L).setTypeName("产线").setIsSysType(1).setIsOperable(1).setCreateTime(LocalDateTime.now()).setUpdateTime(LocalDateTime.now());
SceneType workshopType = new SceneType().setId(7L).setTypeName("车间").setIsSysType(1).setIsOperable(1).setCreateTime(LocalDateTime.now()).setUpdateTime(LocalDateTime.now());
sceneTypes.add(equipmentType);
sceneTypes.add(sceneType);
sceneTypes.add(partType);
sceneTypes.add(componentsType);
sceneTypes.add(wholePlantType);
sceneTypes.add(lineType);
sceneTypes.add(workshopType);
List<Long> typeIds = sceneTypes.stream().map(SceneType::getId).collect(Collectors.toList());
List<SceneType> typeList = sceneTypeMapper.selectBatchIds(typeIds);
if (CollUtil.isEmpty(typeList)){
sceneTypeMapper.insertBatch(sceneTypes);
}
}
}
java springBoot 通过ApplicationListener实现数据初始化
最新推荐文章于 2023-03-07 22:15:19 发布