|
|
@ -1,11 +1,14 @@ |
|
|
|
package com.hnac.hzims.operational.station.service.impl; |
|
|
|
package com.hnac.hzims.operational.station.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.hnac.hzims.common.service.UserAuthDataService; |
|
|
|
import com.hnac.hzims.common.service.UserAuthDataService; |
|
|
|
import com.hnac.hzims.operational.OperationalConstants; |
|
|
|
import com.hnac.hzims.operational.OperationalConstants; |
|
|
|
|
|
|
|
import com.hnac.hzims.operational.data.service.HzimsDataService; |
|
|
|
import com.hnac.hzims.operational.main.vo.StationCountVo; |
|
|
|
import com.hnac.hzims.operational.main.vo.StationCountVo; |
|
|
|
|
|
|
|
import com.hnac.hzims.operational.station.StationConstants; |
|
|
|
import com.hnac.hzims.operational.station.entity.ControlUsersEntity; |
|
|
|
import com.hnac.hzims.operational.station.entity.ControlUsersEntity; |
|
|
|
import com.hnac.hzims.operational.station.entity.StationEntity; |
|
|
|
import com.hnac.hzims.operational.station.entity.StationEntity; |
|
|
|
import com.hnac.hzims.operational.station.mapper.ControlUsersMapper; |
|
|
|
import com.hnac.hzims.operational.station.mapper.ControlUsersMapper; |
|
|
@ -15,10 +18,14 @@ import com.hnac.hzims.operational.station.vo.HzimsStationCountVo; |
|
|
|
import com.hnac.hzims.operational.station.vo.StationAndDeptVo; |
|
|
|
import com.hnac.hzims.operational.station.vo.StationAndDeptVo; |
|
|
|
import com.hnac.hzims.operational.station.vo.StationVO; |
|
|
|
import com.hnac.hzims.operational.station.vo.StationVO; |
|
|
|
import com.hnac.hzims.operational.station.wrapper.StationWrapper; |
|
|
|
import com.hnac.hzims.operational.station.wrapper.StationWrapper; |
|
|
|
|
|
|
|
import com.hnac.hzinfo.sdk.core.response.Result; |
|
|
|
|
|
|
|
import com.hnac.hzinfo.sdk.project.ProjectClient; |
|
|
|
|
|
|
|
import com.hnac.hzinfo.sdk.project.dto.ProjectDTO; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
|
|
|
|
import org.springblade.core.log.logger.BladeLogger; |
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
import org.springblade.core.mp.support.Condition; |
|
|
|
import org.springblade.core.mp.support.Condition; |
|
|
|
import org.springblade.core.mp.support.Query; |
|
|
|
import org.springblade.core.mp.support.Query; |
|
|
@ -27,13 +34,16 @@ import org.springblade.core.secure.utils.AuthUtil; |
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
import org.springblade.core.tool.utils.*; |
|
|
|
import org.springblade.core.tool.utils.*; |
|
|
|
import org.springblade.system.entity.Dept; |
|
|
|
import org.springblade.system.entity.Dept; |
|
|
|
|
|
|
|
import org.springblade.system.feign.IDeptClient; |
|
|
|
import org.springblade.system.feign.ISysClient; |
|
|
|
import org.springblade.system.feign.ISysClient; |
|
|
|
import org.springblade.system.user.entity.User; |
|
|
|
import org.springblade.system.user.entity.User; |
|
|
|
|
|
|
|
|
|
|
|
import org.springblade.system.user.feign.IUserClient; |
|
|
|
import org.springblade.system.user.feign.IUserClient; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
import java.util.concurrent.Executors; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -44,8 +54,46 @@ import java.util.stream.Collectors; |
|
|
|
@Slf4j |
|
|
|
@Slf4j |
|
|
|
public class StationServiceImpl extends BaseServiceImpl<StationMapper, StationEntity> implements IStationService { |
|
|
|
public class StationServiceImpl extends BaseServiceImpl<StationMapper, StationEntity> implements IStationService { |
|
|
|
private final ISysClient sysClient; |
|
|
|
private final ISysClient sysClient; |
|
|
|
|
|
|
|
private final IDeptClient deptClient; |
|
|
|
private final UserAuthDataService userAuthDataService; |
|
|
|
private final UserAuthDataService userAuthDataService; |
|
|
|
private final IUserClient userClient; |
|
|
|
private final IUserClient userClient; |
|
|
|
|
|
|
|
private final ProjectClient projectClient; |
|
|
|
|
|
|
|
private final BladeLogger logger; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void buildStation(StationEntity req) { |
|
|
|
|
|
|
|
// 新建站点的所属机构
|
|
|
|
|
|
|
|
Assert.isTrue(this.buildDept(req),() -> { |
|
|
|
|
|
|
|
throw new ServiceException("创建/修改机构失败!"); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
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())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<StationEntity> list = super.list(lwq); |
|
|
|
|
|
|
|
Assert.isTrue(CollectionUtil.isEmpty(list),() -> { |
|
|
|
|
|
|
|
throw new ServiceException("该站点名/编码已有对应记录,请找到相应记录做修改处理"); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
Optional<Integer> sort = Optional.ofNullable(this.getStationMaxOrder()); |
|
|
|
|
|
|
|
req.setSort(sort.isPresent() ? sort.get()+1 : 1); |
|
|
|
|
|
|
|
Assert.isTrue(this.saveOrUpdate(req),() -> { |
|
|
|
|
|
|
|
throw new ServiceException("创建/修改站点信息失败!"); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
// 为画面导入创建工程
|
|
|
|
|
|
|
|
new Thread(() -> { |
|
|
|
|
|
|
|
ProjectDTO projectDTO = new ProjectDTO(); |
|
|
|
|
|
|
|
projectDTO.setName(req.getName()); |
|
|
|
|
|
|
|
projectDTO.setSource(1); |
|
|
|
|
|
|
|
Result result = projectClient.saveOrUpdate(projectDTO); |
|
|
|
|
|
|
|
logger.info("operational:station:buildStation:"+req.getCode(), JSON.toJSONString(result)); |
|
|
|
|
|
|
|
}).start(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public IPage<StationVO> list(StationEntity req, Query query) { |
|
|
|
public IPage<StationVO> list(StationEntity req, Query query) { |
|
|
@ -493,4 +541,34 @@ public class StationServiceImpl extends BaseServiceImpl<StationMapper, StationEn |
|
|
|
return this.baseMapper.getStationCount(); |
|
|
|
return this.baseMapper.getStationCount(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 通过站点编辑所属机构 |
|
|
|
|
|
|
|
* @param stationEntity 站点信息 |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private boolean buildDept(StationEntity stationEntity) { |
|
|
|
|
|
|
|
//若所属机构不为空 则说明机构已建 获取所属机构
|
|
|
|
|
|
|
|
Dept request = new Dept(); |
|
|
|
|
|
|
|
if(Func.isNotEmpty(stationEntity.getRefDept())) { |
|
|
|
|
|
|
|
R<Dept> deptResult = sysClient.getDept(stationEntity.getRefDept()); |
|
|
|
|
|
|
|
if(deptResult.isSuccess() && Func.isNotEmpty(deptResult.getData())) { |
|
|
|
|
|
|
|
request = deptResult.getData(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
request.setStationId(stationEntity.getCode()); |
|
|
|
|
|
|
|
request.setTenantId(AuthUtil.getTenantId()); |
|
|
|
|
|
|
|
request.setFullName(stationEntity.getName()); |
|
|
|
|
|
|
|
request.setDeptName(stationEntity.getName()); |
|
|
|
|
|
|
|
request.setParentId(stationEntity.getHigherDept()); |
|
|
|
|
|
|
|
request.setDeptCategory(StationConstants.DeptCategoryEnum.STATION.getValue()); |
|
|
|
|
|
|
|
request.setSort(1); |
|
|
|
|
|
|
|
R<Boolean> buildResult = deptClient.createOrUpdateDept(request); |
|
|
|
|
|
|
|
if(buildResult.isSuccess()) { |
|
|
|
|
|
|
|
// 所属机构回传
|
|
|
|
|
|
|
|
R<Dept> deptByStation = sysClient.getDeptByStation(request.getStationId(), AuthUtil.getTenantId()); |
|
|
|
|
|
|
|
stationEntity.setRefDept(Optional.ofNullable(deptByStation).map(R::getData).map(Dept::getId).orElse(null)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return buildResult.isSuccess(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|