diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/entity/StationEntity.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/entity/StationEntity.java index 802d236..4d93882 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/entity/StationEntity.java +++ b/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; } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationController.java index d5e1d1a..c57b6bf 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationController.java +++ b/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> 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)); + } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/StationMapper.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/StationMapper.java index 5795087..4f45e33 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/StationMapper.java +++ b/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 { List getStationCount(); - + /** + * 查询不带数据权限站点信息 + * @param wrapper wrapper + * @return 站点列表 + */ + List listWithOutAuth(@Param(Constants.WRAPPER) Wrapper wrapper); List stationVoCount(); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/StationMapper.xml b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/StationMapper.xml index c955341..12d48ac 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/StationMapper.xml +++ b/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 + diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationService.java index 2338e6c..00e2e35 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationService.java +++ b/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 { */ boolean instanceProject(StationEntity req); + boolean instanceFdpStation(StationEntity req); + /** * 删除站点 * @param id 站点ID,按逗号分隔 @@ -129,4 +132,16 @@ public interface IStationService extends BaseService { boolean updateById(StationEntity req); List accessHydropower(); + + @Override + @Deprecated + boolean removeByMap(Map columnMap); + + @Override + boolean save(StationEntity entity); + + Boolean createStation(StationEntity station); + + Boolean updateStation(StationEntity station); + } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java index cbfd039..48de2c3 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java +++ b/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 BaseServiceImpllambdaQuery() - .eq(StationEntity::getCode, req.getCode()).or().eq(StationEntity::getName, req.getName()); - } else { - lwq = Wrappers.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 list = super.list(lwq); - Assert.isTrue(CollectionUtil.isEmpty(list), () -> { - throw new ServiceException("该站点名/编码已有对应记录,请找到相应记录做修改处理"); - }); - // 新建站点的所属机构 - Assert.isTrue(this.buildDept(req), () -> { - throw new ServiceException("创建/修改机构失败!"); - }); - Optional 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 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 luw = Wrappers.lambdaUpdate().set(StationEntity::getDeletedId, id).eq(StationEntity::getId, id); + this.update(luw); + return SqlHelper.retBool(getBaseMapper().deleteById(id)); + } + + @Override + public boolean removeByIds(Collection idList) { + if (CollectionUtils.isEmpty(idList)) { + return false; } - 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(); + idList.forEach(id -> { + LambdaUpdateWrapper luw = Wrappers.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 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 pushResult = questionClient.submitStationInfo(configVO.getFdpStationType(), req.getCode(), "运维平台推送"); + if(pushResult.isSuccess()) { + LambdaUpdateWrapper luq = Wrappers.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 queryWrapper) { + List removeStations = this.list(queryWrapper); + removeStations.forEach(station -> { + LambdaUpdateWrapper luw = Wrappers.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 luq = Wrappers.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 lqw = Wrappers.lambdaQuery() + .eq(StationEntity::getSignage, entity.getSignage()) + .ne(StationEntity::getId, entity.getId()); + List 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 wq = Wrappers.lambdaQuery().eq(StationEntity::getSignage, entity.getSignage()); + List 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 idList) { - LambdaQueryWrapper lqw = Wrappers.lambdaQuery().in(StationEntity::getId, idList); - List 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 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 buildResult = deptClient.createOrUpdateDept(request); + if (buildResult.isSuccess()) { + // 所属机构回传 + R 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; } }