Browse Source

# 站点建站逻辑修改

zhongwei
haungxing 9 months ago
parent
commit
38af246896
  1. 9
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/entity/StationEntity.java
  2. 7
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationController.java
  3. 9
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/StationMapper.java
  4. 9
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/StationMapper.xml
  5. 15
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationService.java
  6. 230
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java

9
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/entity/StationEntity.java

@ -177,4 +177,13 @@ public class StationEntity extends TenantEntity implements Serializable {
@QueryField(condition = SqlCondition.EQUAL)
@ApiModelProperty("所属国家")
private String refCountry;
@ApiModelProperty("是否推送数据平台")
private Boolean isPushProject;
@ApiModelProperty("是否推送FDP")
private Boolean isPushFdp;
@ApiModelProperty("删除记录ID")
private Long deletedId;
}

7
hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationController.java

@ -207,4 +207,11 @@ public class StationController extends BladeController {
public R<List<StationEntity>> accessHydropower() {
return R.data(stationService.accessHydropower());
}
@PostMapping("/instanceFdpStation")
@ApiOperationSupport(order = 100)
@ApiOperation(value = "实例化FDP站点", notes = "实例化FDP站点")
public R instanceFdpStation(@RequestBody StationEntity req) {
return R.status(stationService.instanceFdpStation(req));
}
}

9
hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/StationMapper.java

@ -1,6 +1,8 @@
package com.hnac.hzims.operational.station.mapper;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.hnac.hzims.operational.main.vo.StationCountVo;
import com.hnac.hzims.operational.station.entity.StationEntity;
import com.hnac.hzims.operational.station.vo.HzimsStationCountVo;
@ -276,6 +278,11 @@ public interface StationMapper extends UserDataScopeBaseMapper<StationEntity> {
List<HzimsStationCountVo> getStationCount();
/**
* 查询不带数据权限站点信息
* @param wrapper wrapper
* @return 站点列表
*/
List<StationEntity> listWithOutAuth(@Param(Constants.WRAPPER) Wrapper wrapper);
List<StationsVo> stationVoCount();
}

9
hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/StationMapper.xml

@ -455,4 +455,13 @@
select date_format(create_time,'%Y') year, count(1) count
from hzims_station group by year
</select>
<select id="listWithOutAuth" resultType="com.hnac.hzims.operational.station.entity.StationEntity">
select * from `hzims_station`
<where>
`is_deleted` = 0
<if test="ew!=null and ew.sqlSegment!=null and ew.sqlSegment != ''">
and ${ew.sqlSegment}
</if>
</where>
</select>
</mapper>

15
hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationService.java

@ -1,5 +1,6 @@
package com.hnac.hzims.operational.station.service;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hnac.hzims.operational.main.vo.StationCountVo;
@ -38,6 +39,8 @@ public interface IStationService extends BaseService<StationEntity> {
*/
boolean instanceProject(StationEntity req);
boolean instanceFdpStation(StationEntity req);
/**
* 删除站点
* @param id 站点ID按逗号分隔
@ -129,4 +132,16 @@ public interface IStationService extends BaseService<StationEntity> {
boolean updateById(StationEntity req);
List<StationEntity> accessHydropower();
@Override
@Deprecated
boolean removeByMap(Map<String, Object> columnMap);
@Override
boolean save(StationEntity entity);
Boolean createStation(StationEntity station);
Boolean updateStation(StationEntity station);
}

230
hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java

@ -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()));
if(Func.isEmpty(req.getId())) {
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;
}
}

Loading…
Cancel
Save