fix: 修改asset_type值处理逻辑

This commit is contained in:
tanghao
2021-07-13 16:10:17 +08:00
parent 8817ee5533
commit 763cbe3e93

View File

@@ -4,6 +4,7 @@ import cn.hutool.log.Log;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nis.dao.AssetTypeConfDao;
import com.nis.dao.DcDao;
import com.nis.dao.SqlDao;
import com.nis.entity.AssetTypeConf;
import com.nis.entity.Dc;
import com.nis.entity.Idc;
@@ -30,6 +31,9 @@ public class AssetTypeConfServiceImpl extends ServiceImpl<AssetTypeConfDao, Asse
@Autowired
private SysDictService sysDictService;
@Autowired
private SqlDao sqlDao;
@Override
public void handler() {
// 初始化数据
@@ -37,31 +41,32 @@ public class AssetTypeConfServiceImpl extends ServiceImpl<AssetTypeConfDao, Asse
}
public void initData() {
List<SysDictEntity> types = sysDictService.queryDatas("assetType");
List<AssetTypeConf> list = this.list();
List<AssetTypeConf> assetTypeConfs = new ArrayList<AssetTypeConf>();
Map<String, AssetTypeConf> nameAndData = list.stream().collect(Collectors.toMap(AssetTypeConf::getName, Function.identity()));
for(SysDictEntity type : types) {
AssetTypeConf assetTypeConf = nameAndData.get(type.getValue());
if(ToolUtil.isEmpty(assetTypeConf)) {
assetTypeConf = new AssetTypeConf();
assetTypeConf.setPid(0);
assetTypeConf.setVm(0);
assetTypeConf.setVmh(0);
assetTypeConf.setName(type.getValue());
assetTypeConf.setRemark("");
assetTypeConf.setBuildIn(0);
assetTypeConf.setAuthProtocol(0);
assetTypeConf.setSnmpEnable(0);
assetTypeConf.setSnmpCollect(0);
assetTypeConf.setSshCollect(0);
assetTypeConf.setSshCollectScript("");
assetTypeConfs.add(assetTypeConf);
}
}
if(ToolUtil.isNotEmpty(assetTypeConfs)) {
this.saveBatch(assetTypeConfs);
}
/*List<SysDictEntity> types = sysDictService.queryDatas("assetType");
List<AssetTypeConf> list = this.list();
List<AssetTypeConf> assetTypeConfs = new ArrayList<AssetTypeConf>();
Map<String, AssetTypeConf> nameAndData = list.stream().collect(Collectors.toMap(AssetTypeConf::getName, Function.identity()));
for(SysDictEntity type : types) {
AssetTypeConf assetTypeConf = nameAndData.get(type.getValue());
if(ToolUtil.isEmpty(assetTypeConf)) {
assetTypeConf = new AssetTypeConf();
assetTypeConf.setPid(0);
assetTypeConf.setVm(0);
assetTypeConf.setVmh(0);
assetTypeConf.setName(type.getValue());
assetTypeConf.setRemark("");
assetTypeConf.setBuildIn(0);
assetTypeConf.setAuthProtocol(0);
assetTypeConf.setSnmpEnable(0);
assetTypeConf.setSnmpCollect(0);
assetTypeConf.setSshCollect(0);
assetTypeConf.setSshCollectScript("");
assetTypeConfs.add(assetTypeConf);
}
}
if(ToolUtil.isNotEmpty(assetTypeConfs)) {
this.saveBatch(assetTypeConfs);
}*/
sqlDao.execute("INSERT INTO asset_type_conf(`pid`, `vm`, `vmh`, `name`, `remark`, `build_in`, `auth_protocol`, `snmp_enable`, `snmp_collect`, `ssh_collect`, `ssh_collect_script`) VALUES (0, '0', '0', 'Other', '', '1', 0, 0, 0, 0, '')");
}
}