|
|
|
@ -1,11 +1,16 @@
|
|
|
|
|
package com.hnac.hzims.operational.station.service.impl; |
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper; |
|
|
|
|
import com.hnac.hzims.fdp.feign.IQuestionClient; |
|
|
|
|
import com.hnac.hzims.hzimsweather.response.air.Station; |
|
|
|
|
import com.hnac.hzims.operational.OperationalConstants; |
|
|
|
|
import com.hnac.hzims.operational.main.constant.HomePageConstant; |
|
|
|
|
import com.hnac.hzims.operational.main.entity.UserDeptEntity; |
|
|
|
@ -51,6 +56,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
import org.springframework.util.Assert; |
|
|
|
|
|
|
|
|
|
import java.io.Serializable; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.concurrent.ExecutionException; |
|
|
|
|
import java.util.concurrent.FutureTask; |
|
|
|
@ -73,33 +79,28 @@ public class StationServiceImpl extends BaseServiceImpl<StationMapper, StationEn
|
|
|
|
|
private final IStationAttributeService stationAttributeService; |
|
|
|
|
private final IStationPushConfigService stationPushConfigService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
public void buildStation(StationEntity req) { |
|
|
|
|
LambdaQueryWrapper lwq; |
|
|
|
|
if(Func.isEmpty(req.getId())) { |
|
|
|
|
lwq = Wrappers.<StationEntity>lambdaQuery() |
|
|
|
|
.eq(StationEntity::getCode, req.getCode()).or().eq(StationEntity::getName, req.getName()); |
|
|
|
|
} else { |
|
|
|
|
lwq = Wrappers.<StationEntity>lambdaQuery().ne(StationEntity::getId, req.getId()) |
|
|
|
|
.and(wrapper -> wrapper.eq(StationEntity::getCode, req.getCode()).or().eq(StationEntity::getName, req.getName())); |
|
|
|
|
this.createStation(req); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
List<StationEntity> list = super.list(lwq); |
|
|
|
|
Assert.isTrue(CollectionUtil.isEmpty(list), () -> { |
|
|
|
|
throw new ServiceException("该站点名/编码已有对应记录,请找到相应记录做修改处理"); |
|
|
|
|
}); |
|
|
|
|
// 新建站点的所属机构
|
|
|
|
|
Assert.isTrue(this.buildDept(req), () -> { |
|
|
|
|
throw new ServiceException("创建/修改机构失败!"); |
|
|
|
|
}); |
|
|
|
|
Optional<Integer> sort = Optional.ofNullable(this.getStationMaxOrder()); |
|
|
|
|
req.setSort(sort.isPresent() ? sort.get() + 1 : 1); |
|
|
|
|
this.pushStation(req); |
|
|
|
|
boolean updateResult = this.saveOrUpdate(req); |
|
|
|
|
Assert.isTrue(updateResult, () -> { |
|
|
|
|
throw new ServiceException("创建/修改站点信息失败!"); |
|
|
|
|
}); |
|
|
|
|
else { |
|
|
|
|
this.updateStation(req); |
|
|
|
|
} |
|
|
|
|
// // 新建站点的所属机构
|
|
|
|
|
// Assert.isTrue(this.buildDept(req), () -> {
|
|
|
|
|
// throw new ServiceException("创建/修改机构失败!");
|
|
|
|
|
// });
|
|
|
|
|
// Optional<Integer> sort = Optional.ofNullable(this.getStationMaxOrder());
|
|
|
|
|
// req.setSort(sort.isPresent() ? sort.get() + 1 : 1);
|
|
|
|
|
// this.pushStation(req);
|
|
|
|
|
// boolean updateResult = this.saveOrUpdate(req);
|
|
|
|
|
// Assert.isTrue(updateResult, () -> {
|
|
|
|
|
// throw new ServiceException("创建/修改站点信息失败!");
|
|
|
|
|
// });
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -144,19 +145,22 @@ public class StationServiceImpl extends BaseServiceImpl<StationMapper, StationEn
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean instanceProject(StationEntity req) { |
|
|
|
|
if (Func.isEmpty(req.getSecretKey()) || Func.isEmpty(req.getDataSource())) { |
|
|
|
|
return true; |
|
|
|
|
public boolean removeById(Serializable id) { |
|
|
|
|
LambdaUpdateWrapper<StationEntity> luw = Wrappers.<StationEntity>lambdaUpdate().set(StationEntity::getDeletedId, id).eq(StationEntity::getId, id); |
|
|
|
|
this.update(luw); |
|
|
|
|
return SqlHelper.retBool(getBaseMapper().deleteById(id)); |
|
|
|
|
} |
|
|
|
|
ProjectDTO projectDTO = new ProjectDTO(); |
|
|
|
|
projectDTO.setName(req.getName()); |
|
|
|
|
projectDTO.setSource(1); |
|
|
|
|
projectDTO.setSecretKey(req.getSecretKey()); |
|
|
|
|
projectDTO.setListenKind(req.getDataSource()); |
|
|
|
|
projectDTO.setId(req.getCode()); |
|
|
|
|
Result result = projectClient.saveOrUpdate(projectDTO); |
|
|
|
|
logger.info("operational:station:buildStation:" + req.getCode(), JSON.toJSONString(result)); |
|
|
|
|
return result.getCode() == ResultCode.SUCCESS.getCode() && result.isSuccess(); |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean removeByIds(Collection<? extends Serializable> idList) { |
|
|
|
|
if (CollectionUtils.isEmpty(idList)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
idList.forEach(id -> { |
|
|
|
|
LambdaUpdateWrapper<StationEntity> luw = Wrappers.<StationEntity>lambdaUpdate().set(StationEntity::getDeletedId, id).eq(StationEntity::getId, id); |
|
|
|
|
this.update(luw); |
|
|
|
|
}); |
|
|
|
|
return SqlHelper.retBool(getBaseMapper().deleteBatchIds(idList)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@ -742,16 +746,154 @@ public class StationServiceImpl extends BaseServiceImpl<StationMapper, StationEn
|
|
|
|
|
return this.list(queryWrapper); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean removeByMap(Map<String, Object> columnMap) { |
|
|
|
|
throw new UnsupportedOperationException("该方法已被禁止使用"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean instanceFdpStation(StationEntity req) { |
|
|
|
|
StationPushConfigEntity config = StationPushConfigEntity.builder().stationType(req.getType()).build(); |
|
|
|
|
StationPushConfigVO configVO = stationPushConfigService.getOne(BeanUtil.copy(config, StationPushConfigDTO.class)); |
|
|
|
|
if (ObjectUtil.isNotEmpty(configVO) && configVO.getIsPush()) { |
|
|
|
|
log.info("{}站点开始智能诊断站点推送", req.getCode()); |
|
|
|
|
R<Boolean> pushResult = questionClient.submitStationInfo(configVO.getFdpStationType(), req.getCode(), "运维平台推送"); |
|
|
|
|
if(pushResult.isSuccess()) { |
|
|
|
|
LambdaUpdateWrapper<StationEntity> luq = Wrappers.<StationEntity>lambdaUpdate().set(StationEntity::getIsPushFdp, true).eq(StationEntity::getId, req.getId()); |
|
|
|
|
return this.update(luq); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
throw new ServiceException("站点推送智能诊断失败!"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean remove(Wrapper<StationEntity> queryWrapper) { |
|
|
|
|
List<StationEntity> removeStations = this.list(queryWrapper); |
|
|
|
|
removeStations.forEach(station -> { |
|
|
|
|
LambdaUpdateWrapper<StationEntity> luw = Wrappers.<StationEntity>lambdaUpdate().set(StationEntity::getDeletedId, station.getId()).eq(StationEntity::getId, station.getId()); |
|
|
|
|
this.update(luw); |
|
|
|
|
}); |
|
|
|
|
return SqlHelper.retBool(getBaseMapper().delete(queryWrapper)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean instanceProject(StationEntity req) { |
|
|
|
|
if (Func.isEmpty(req.getSecretKey()) || Func.isEmpty(req.getDataSource())) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
ProjectDTO projectDTO = new ProjectDTO(); |
|
|
|
|
projectDTO.setName(req.getName()); |
|
|
|
|
projectDTO.setSource(1); |
|
|
|
|
projectDTO.setSecretKey(req.getSecretKey()); |
|
|
|
|
projectDTO.setListenKind(req.getDataSource()); |
|
|
|
|
projectDTO.setId(req.getCode()); |
|
|
|
|
Result result = projectClient.saveOrUpdate(projectDTO); |
|
|
|
|
logger.info("operational:station:buildStation:" + req.getCode(), JSON.toJSONString(result)); |
|
|
|
|
if(result.getCode() == ResultCode.SUCCESS.getCode() && result.isSuccess()) { |
|
|
|
|
LambdaUpdateWrapper<StationEntity> luq = Wrappers.<StationEntity>lambdaUpdate().set(StationEntity::getIsPushProject, true).eq(StationEntity::getId, req.getId()); |
|
|
|
|
return this.update(luq); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
throw new ServiceException("站点推送数据平台失败!"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean updateById(StationEntity entity) { |
|
|
|
|
if(Func.isNotEmpty(entity.getHigherDept())) { |
|
|
|
|
StationEntity station = this.getById(entity.getId()); |
|
|
|
|
Assert.isTrue(entity.getHigherDept().equals(station.getHigherDept()),() -> { |
|
|
|
|
throw new ServiceException("站点的上级机构不可更改!"); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
if(Func.isNotEmpty(entity.getSignage())) { |
|
|
|
|
LambdaQueryWrapper<StationEntity> lqw = Wrappers.<StationEntity>lambdaQuery() |
|
|
|
|
.eq(StationEntity::getSignage, entity.getSignage()) |
|
|
|
|
.ne(StationEntity::getId, entity.getId()); |
|
|
|
|
List<StationEntity> stations = this.getBaseMapper().listWithOutAuth(lqw); |
|
|
|
|
Assert.isTrue(CollectionUtil.isEmpty(stations),() -> { |
|
|
|
|
throw new ServiceException("站点两票标识平台已存在,请检查后重新填入!"); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
// 创建站点机构
|
|
|
|
|
this.createStationDept(entity); |
|
|
|
|
return super.updateById(entity); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean save(StationEntity entity) { |
|
|
|
|
// 检查两票标识唯一性
|
|
|
|
|
if(StringUtil.isNotBlank(entity.getSignage())) { |
|
|
|
|
LambdaQueryWrapper<StationEntity> wq = Wrappers.<StationEntity>lambdaQuery().eq(StationEntity::getSignage, entity.getSignage()); |
|
|
|
|
List<StationEntity> stations = this.getBaseMapper().listWithOutAuth(wq); |
|
|
|
|
Assert.isTrue(CollectionUtil.isEmpty(stations),() -> { |
|
|
|
|
throw new ServiceException("站点两票标识平台已存在,请检查后重新填入!"); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
// 创建站点机构
|
|
|
|
|
this.createStationDept(entity); |
|
|
|
|
return super.save(entity); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 删除新建站点时绑定的数据(项目、智能诊断站点) |
|
|
|
|
* |
|
|
|
|
* @param idList id集合 |
|
|
|
|
* 创建站点机构 |
|
|
|
|
* @param entity 站点信息 |
|
|
|
|
*/ |
|
|
|
|
private void deleteStation(List<Long> idList) { |
|
|
|
|
LambdaQueryWrapper<StationEntity> lqw = Wrappers.<StationEntity>lambdaQuery().in(StationEntity::getId, idList); |
|
|
|
|
List<StationEntity> stationEntityList = this.list(lqw); |
|
|
|
|
// if(CollectionUtil.isNotEmpty(stationEntityList)) {
|
|
|
|
|
// stationEntityList.stream().map(StationEntity::getCode).forEach(code -> projectClient.delete());
|
|
|
|
|
// }
|
|
|
|
|
private void createStationDept(StationEntity entity) { |
|
|
|
|
//若所属机构不为空 则说明机构已建 获取所属机构
|
|
|
|
|
Dept request = new Dept(); |
|
|
|
|
R<Dept> existDeptR = sysClient.getDeptByStation(entity.getCode(), AuthUtil.getTenantId()); |
|
|
|
|
if(existDeptR.isSuccess() && Func.isNotEmpty(existDeptR.getData())) { |
|
|
|
|
if(!existDeptR.getData().getParentId().equals(entity.getHigherDept())) { |
|
|
|
|
throw new ServiceException("该站点编号已被其他机构使用,保存失败!"); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
entity.setRefDept(existDeptR.getData().getId()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
request.setStationId(entity.getCode()); |
|
|
|
|
request.setTenantId(AuthUtil.getTenantId()); |
|
|
|
|
request.setFullName(entity.getName()); |
|
|
|
|
request.setDeptName(entity.getName()); |
|
|
|
|
request.setParentId(entity.getHigherDept()); |
|
|
|
|
request.setDeptCategory(StationConstants.DeptCategoryEnum.STATION.getValue()); |
|
|
|
|
request.setSort(1); |
|
|
|
|
R<Void> buildResult = deptClient.createOrUpdateDept(request); |
|
|
|
|
if (buildResult.isSuccess()) { |
|
|
|
|
// 所属机构回传
|
|
|
|
|
R<Dept> deptByStation = sysClient.getDeptByStation(request.getStationId(), AuthUtil.getTenantId()); |
|
|
|
|
Long deptId = Optional.ofNullable(deptByStation).map(R::getData).map(Dept::getId).orElse(null); |
|
|
|
|
entity.setRefDept(deptId); |
|
|
|
|
entity.setCreateDept(deptId); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Boolean createStation(StationEntity station) { |
|
|
|
|
if(this.save(station)) { |
|
|
|
|
// 推送数据平台以及fdp
|
|
|
|
|
new Thread(() -> this.instanceProject(station),"数据平台推送").start(); |
|
|
|
|
new Thread(() -> this.instanceFdpStation(station),"fdp推送").start(); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Boolean updateStation(StationEntity station) { |
|
|
|
|
if(this.updateById(station)) { |
|
|
|
|
// 推送数据平台以及fdp
|
|
|
|
|
new Thread(() -> this.instanceProject(station),"数据平台推送").start(); |
|
|
|
|
new Thread(() -> this.instanceFdpStation(station),"fdp推送").start(); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|