| | |
| | | package com.vincent.rsf.server.manager.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.vincent.rsf.framework.exception.CoolException; |
| | | import com.vincent.rsf.server.manager.controller.params.DeviceSiteParame; |
| | | import com.vincent.rsf.server.manager.mapper.DeviceSiteMapper; |
| | | import com.vincent.rsf.server.manager.entity.DeviceSite; |
| | | import com.vincent.rsf.server.manager.service.DeviceSiteService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | @Service("deviceSiteService") |
| | | public class DeviceSiteServiceImpl extends ServiceImpl<DeviceSiteMapper, DeviceSite> implements DeviceSiteService { |
| | | |
| | | /** |
| | | * 初始化站点 |
| | | * @param param |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean initSites(DeviceSiteParame param) { |
| | | if (param.getFlagInit() == 1) { |
| | | if (!this.remove(new LambdaQueryWrapper<>())) { |
| | | throw new CoolException("初始化失败: 删除站点失败!!"); |
| | | } |
| | | } |
| | | if (Objects.isNull(param.getDeviceSites()) || param.getDeviceSites().isEmpty()) { |
| | | throw new CoolException("初始化失败: 设备作业站点不能为空!!"); |
| | | } |
| | | if (Objects.isNull(param.getSites()) || param.getSites().isEmpty()) { |
| | | throw new CoolException("初始化失败: 作业站点不能为空!!"); |
| | | } |
| | | if (Objects.isNull(param.getTypeIds()) || param.getTypeIds().isEmpty()) { |
| | | throw new CoolException("初始化失败: 作业类型不能为空!!"); |
| | | } |
| | | List<DeviceSite> deviceSites = new ArrayList<>(); |
| | | for (String site : param.getSites()) { |
| | | for (String deviceSite : param.getDeviceSites()) { |
| | | for (Long id : param.getTypeIds()) { |
| | | DeviceSite site1 = new DeviceSite(); |
| | | site1.setType(id + "") |
| | | .setSite(site) |
| | | .setDevice(param.getDeviceType()) |
| | | .setDeviceSite(deviceSite) |
| | | .setDeviceCode(param.getDeviceCode()); |
| | | deviceSites.add(site1); |
| | | } |
| | | } |
| | | } |
| | | if (!this.saveBatch(deviceSites)) { |
| | | throw new CoolException("初始化失败: 数据保存失败!!"); |
| | | } |
| | | return true; |
| | | } |
| | | } |