|  |  | 
 |  |  | package com.vincent.rsf.server.manager.service.impl; | 
 |  |  |  | 
 |  |  | import com.alibaba.fastjson.JSONArray; | 
 |  |  | 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.entity.BasStation; | 
 |  |  | import com.vincent.rsf.server.manager.mapper.DeviceSiteMapper; | 
 |  |  | import com.vincent.rsf.server.manager.entity.DeviceSite; | 
 |  |  | import com.vincent.rsf.server.manager.service.BasStationService; | 
 |  |  | 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.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.stereotype.Service; | 
 |  |  |  | 
 |  |  | import java.util.ArrayList; | 
 |  |  | 
 |  |  |  | 
 |  |  | @Service("deviceSiteService") | 
 |  |  | public class DeviceSiteServiceImpl extends ServiceImpl<DeviceSiteMapper, DeviceSite> implements DeviceSiteService { | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private BasStationService basStationService; | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 初始化站点 | 
 |  |  | 
 |  |  |         if (Objects.isNull(param.getDeviceSites()) || StringUtils.isBlank(param.getDeviceSites())) { | 
 |  |  |             throw new CoolException("初始化失败: 设备作业站点不能为空!!"); | 
 |  |  |         } | 
 |  |  |         if (Objects.isNull(param.getSites()) || StringUtils.isBlank(param.getSites())) { | 
 |  |  |         if (Objects.isNull(param.getSite()) || StringUtils.isBlank(param.getSite())) { | 
 |  |  |             throw new CoolException("初始化失败: 作业站点不能为空!!"); | 
 |  |  |         } | 
 |  |  |         if (Objects.isNull(param.getTypeIds()) || param.getTypeIds().isEmpty()) { | 
 |  |  |             throw new CoolException("初始化失败: 作业类型不能为空!!"); | 
 |  |  |         } | 
 |  |  |         List<String> sites = Arrays.asList(StringUtils.split(param.getSites(), ",")); | 
 |  |  |         if (Objects.isNull(param.getTarget()) || param.getTarget().isEmpty()) { | 
 |  |  |             throw new CoolException("初始化失败: 目标站点不能为空!!"); | 
 |  |  |         } | 
 |  |  |         List<String> sites = Arrays.asList(StringUtils.split(param.getSite(), ",")); | 
 |  |  |         List<String> dvSites = Arrays.asList(StringUtils.split(param.getDeviceSites(), ",")); | 
 |  |  |         List<String> targets = Arrays.asList(StringUtils.split(param.getTarget(), ",")); | 
 |  |  |         List<DeviceSite> deviceSites =  new ArrayList<>(); | 
 |  |  |         for (String site : sites) { | 
 |  |  |             BasStation basStation = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName, site)); | 
 |  |  |             if (null == basStation) { | 
 |  |  |                 throw new CoolException("初始化失败: 站点未找到!!"); | 
 |  |  |             } | 
 |  |  |             for (String deviceSite : dvSites) { | 
 |  |  |                 BasStation basStation2 = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName, deviceSite)); | 
 |  |  |                 if (null == basStation2) { | 
 |  |  |                     throw new CoolException("初始化失败: 作业站点未找到!!"); | 
 |  |  |                 } | 
 |  |  |                 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); | 
 |  |  |                     for (String target : targets) { | 
 |  |  |                         DeviceSite site1 = new DeviceSite(); | 
 |  |  |                         site1.setType(id + "") | 
 |  |  |                                 .setSite(site) | 
 |  |  |                                 .setDevice(param.getDeviceType()) | 
 |  |  |                                 .setDeviceSite(deviceSite) | 
 |  |  |                                 .setTarget(target) | 
 |  |  |                                 .setDeviceCode(param.getDeviceCode()) | 
 |  |  |                                 .setChannel(param.getChannel()) | 
 |  |  |                                 ; | 
 |  |  |                         deviceSites.add(site1); | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } |