Browse Source

# 设备备份参数分组还原

zhongwei
haungxing 10 months ago
parent
commit
b25be0c44f
  1. 6
      hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/emParam/entity/ParamBackupsDetailEntity.java
  2. 7
      hzims-service/equipment/src/main/java/com/hnac/hzims/emParam/controller/ParamBackupsController.java
  3. 4
      hzims-service/equipment/src/main/java/com/hnac/hzims/emParam/service/IParamBackupsService.java
  4. 49
      hzims-service/equipment/src/main/java/com/hnac/hzims/emParam/service/impl/ParamBackupsServiceImpl.java
  5. 3
      hzims-service/equipment/src/main/resources/db/1.0.2.sql

6
hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/emParam/entity/ParamBackupsDetailEntity.java

@ -20,6 +20,12 @@ public class ParamBackupsDetailEntity extends TenantEntity implements Serializab
@ApiModelProperty("备份主表ID") @ApiModelProperty("备份主表ID")
private Long backupsId; private Long backupsId;
@ApiModelProperty("参数分组")
private Long modelClassifyId;
@ApiModelProperty("参数分组名称")
private String modelClassifyName;
@ApiModelProperty("参数名称") @ApiModelProperty("参数名称")
@QueryField(condition = SqlCondition.LIKE) @QueryField(condition = SqlCondition.LIKE)
private String name; private String name;

7
hzims-service/equipment/src/main/java/com/hnac/hzims/emParam/controller/ParamBackupsController.java

@ -64,4 +64,11 @@ public class ParamBackupsController extends BladeController {
return R.status(paramBackupsService.updateById(request)); return R.status(paramBackupsService.updateById(request));
} }
@GetMapping("/reductionParam")
@ApiOperation("根据备份ID还原参数")
@ApiOperationSupport(order = 6)
public R reductionParam(@RequestParam @ApiParam(value = "备份ID",required = true) Long id) {
return R.status(paramBackupsService.reductionParam(id));
}
} }

4
hzims-service/equipment/src/main/java/com/hnac/hzims/emParam/service/IParamBackupsService.java

@ -5,10 +5,12 @@ import com.hnac.hzims.common.utils.Condition;
import com.hnac.hzims.emParam.dto.ParamBackupsDTO; import com.hnac.hzims.emParam.dto.ParamBackupsDTO;
import com.hnac.hzims.emParam.entity.ParamBackupsEntity; import com.hnac.hzims.emParam.entity.ParamBackupsEntity;
import com.hnac.hzims.emParam.vo.ParamBackupsVO; import com.hnac.hzims.emParam.vo.ParamBackupsVO;
import io.swagger.annotations.ApiParam;
import org.springblade.core.mp.base.BaseService; import org.springblade.core.mp.base.BaseService;
import org.springblade.core.tool.utils.BeanUtil; import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
public interface IParamBackupsService extends BaseService<ParamBackupsEntity> { public interface IParamBackupsService extends BaseService<ParamBackupsEntity> {
@ -18,6 +20,8 @@ public interface IParamBackupsService extends BaseService<ParamBackupsEntity> {
Boolean updateById(ParamBackupsDTO request); Boolean updateById(ParamBackupsDTO request);
Boolean reductionParam(Long id);
default LambdaQueryWrapper<ParamBackupsEntity> getQueryWrapper(ParamBackupsDTO request) { default LambdaQueryWrapper<ParamBackupsEntity> getQueryWrapper(ParamBackupsDTO request) {
ParamBackupsEntity paramBackupsEntity = BeanUtil.copy(request, ParamBackupsEntity.class); ParamBackupsEntity paramBackupsEntity = BeanUtil.copy(request, ParamBackupsEntity.class);
LambdaQueryWrapper<ParamBackupsEntity> queryWrapper = Condition.getQueryWrapper(ParamBackupsEntity.class, paramBackupsEntity); LambdaQueryWrapper<ParamBackupsEntity> queryWrapper = Condition.getQueryWrapper(ParamBackupsEntity.class, paramBackupsEntity);

49
hzims-service/equipment/src/main/java/com/hnac/hzims/emParam/service/impl/ParamBackupsServiceImpl.java

@ -1,5 +1,6 @@
package com.hnac.hzims.emParam.service.impl; 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.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hnac.hzims.emParam.dto.ParamBackupsDTO; 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.mapper.ParamBackupsMapper;
import com.hnac.hzims.emParam.service.IParamBackupsDetailService; import com.hnac.hzims.emParam.service.IParamBackupsDetailService;
import com.hnac.hzims.emParam.service.IParamBackupsService; 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.vo.ParamBackupsVO;
import com.hnac.hzims.emParam.wrapper.ParamBackupsDetailWrapper; 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.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
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.secure.utils.AuthUtil;
import org.springblade.core.tool.utils.BeanUtil; import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.Func;
@ -24,7 +32,9 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import javax.sql.rowset.serial.SerialException; import javax.sql.rowset.serial.SerialException;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -34,6 +44,8 @@ import java.util.stream.Collectors;
public class ParamBackupsServiceImpl extends BaseServiceImpl<ParamBackupsMapper, ParamBackupsEntity> implements IParamBackupsService { public class ParamBackupsServiceImpl extends BaseServiceImpl<ParamBackupsMapper, ParamBackupsEntity> implements IParamBackupsService {
private final IParamBackupsDetailService detailService; private final IParamBackupsDetailService detailService;
private final ControlClient controlClient;
private final BladeLogger logger;
@Override @Override
@Transactional @Transactional
@ -86,5 +98,42 @@ public class ParamBackupsServiceImpl extends BaseServiceImpl<ParamBackupsMapper,
return false; 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;
}
} }

3
hzims-service/equipment/src/main/resources/db/1.0.2.sql

@ -0,0 +1,3 @@
-- 参数分组还原添加字段
alter table `HZIMS_PARAM_BACKUPS_DETAIL` add column `model_classify_id` BIGINT(20) COMMENT '参数分组';
alter table `HZIMS_PARAM_BACKUPS_DETAIL` add column `model_classify_name` BIGINT(20) COMMENT '参数分组名称';
Loading…
Cancel
Save