|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package com.hnac.hzims.emParam.service.impl; |
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import com.hnac.hzims.emParam.dto.ParamBackupsDTO; |
|
|
|
@ -9,12 +10,19 @@ import com.hnac.hzims.emParam.mapper.ParamBackupsDetailMapper;
|
|
|
|
|
import com.hnac.hzims.emParam.mapper.ParamBackupsMapper; |
|
|
|
|
import com.hnac.hzims.emParam.service.IParamBackupsDetailService; |
|
|
|
|
import com.hnac.hzims.emParam.service.IParamBackupsService; |
|
|
|
|
import com.hnac.hzims.emParam.vo.ParamBackupsDetailVO; |
|
|
|
|
import com.hnac.hzims.emParam.vo.ParamBackupsVO; |
|
|
|
|
import com.hnac.hzims.emParam.wrapper.ParamBackupsDetailWrapper; |
|
|
|
|
import com.hnac.hzinfo.sdk.core.response.Result; |
|
|
|
|
import com.hnac.hzinfo.sdk.v5.control.ControlClient; |
|
|
|
|
import com.hnac.hzinfo.sdk.v5.control.dto.ControlBatchDTO; |
|
|
|
|
import com.hnac.hzinfo.sdk.v5.control.dto.Ctrl; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
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.secure.utils.AuthUtil; |
|
|
|
|
import org.springblade.core.tool.utils.BeanUtil; |
|
|
|
|
import org.springblade.core.tool.utils.CollectionUtil; |
|
|
|
|
import org.springblade.core.tool.utils.Func; |
|
|
|
@ -24,7 +32,9 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.util.Assert; |
|
|
|
|
|
|
|
|
|
import javax.sql.rowset.serial.SerialException; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.Objects; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
@ -34,6 +44,8 @@ import java.util.stream.Collectors;
|
|
|
|
|
public class ParamBackupsServiceImpl extends BaseServiceImpl<ParamBackupsMapper, ParamBackupsEntity> implements IParamBackupsService { |
|
|
|
|
|
|
|
|
|
private final IParamBackupsDetailService detailService; |
|
|
|
|
private final ControlClient controlClient; |
|
|
|
|
private final BladeLogger logger; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@Transactional |
|
|
|
@ -86,5 +98,42 @@ public class ParamBackupsServiceImpl extends BaseServiceImpl<ParamBackupsMapper,
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Boolean reductionParam(Long id) { |
|
|
|
|
ParamBackupsVO backup = this.detail(id); |
|
|
|
|
List<ParamBackupsDetailVO> paramList = backup.getDetailList(); |
|
|
|
|
Assert.isTrue(CollectionUtil.isNotEmpty(paramList),() -> { |
|
|
|
|
throw new ServiceException("备份参数不能为空!"); |
|
|
|
|
}); |
|
|
|
|
Map<Long, List<ParamBackupsDetailVO>> detailMap = paramList.stream().collect(Collectors.groupingBy(ParamBackupsDetailVO::getModelClassifyId)); |
|
|
|
|
detailMap.forEach((classifyId,list) -> { |
|
|
|
|
ControlBatchDTO controlBatchDTO = new ControlBatchDTO(); |
|
|
|
|
controlBatchDTO.setProjectId(backup.getStationCode()); |
|
|
|
|
controlBatchDTO.setDeviceCode(backup.getEmCode()); |
|
|
|
|
controlBatchDTO.setDelay(backup.getDelay()); |
|
|
|
|
controlBatchDTO.setOperator(String.valueOf(AuthUtil.getUserId())); |
|
|
|
|
controlBatchDTO.setMachineCode(backup.getMachineCode()); |
|
|
|
|
List<Ctrl> ctrl = paramList.stream().map(this::convert).collect(Collectors.toList()); |
|
|
|
|
controlBatchDTO.setCtrls(ctrl); |
|
|
|
|
log.info("{}", JSON.toJSONString(controlBatchDTO)); |
|
|
|
|
Result<Object> result = controlClient.batchSendToDevice(controlBatchDTO); |
|
|
|
|
if(!result.isSuccess()) { |
|
|
|
|
logger.error("equipment:ParamServiceImpl:distribute", "下发参数传参为:" + JSON.toJSONString(controlBatchDTO) + ";下发结果为:" + JSON.toJSONString(result)); |
|
|
|
|
throw new ServiceException("参数还原调用下发接口失败,返回结果为:"+result.getMsg()); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Ctrl convert(ParamBackupsDetailVO param) { |
|
|
|
|
Ctrl result = new Ctrl(); |
|
|
|
|
result.setSignage(param.getSignage()); |
|
|
|
|
Map params = new HashMap(1){{ |
|
|
|
|
put(param.getSignage(),param.getValue()); |
|
|
|
|
}}; |
|
|
|
|
result.setParams(params); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|