From b25be0c44f74a27d5cb82185078c2a7c01c63cb4 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Mon, 5 Feb 2024 11:08:08 +0800 Subject: [PATCH] =?UTF-8?q?#=20=E8=AE=BE=E5=A4=87=E5=A4=87=E4=BB=BD?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=88=86=E7=BB=84=E8=BF=98=E5=8E=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../emParam/entity/ParamBackupsDetailEntity.java | 6 +++ .../emParam/controller/ParamBackupsController.java | 7 ++++ .../emParam/service/IParamBackupsService.java | 4 ++ .../service/impl/ParamBackupsServiceImpl.java | 49 ++++++++++++++++++++++ .../equipment/src/main/resources/db/1.0.2.sql | 3 ++ 5 files changed, 69 insertions(+) create mode 100644 hzims-service/equipment/src/main/resources/db/1.0.2.sql diff --git a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/emParam/entity/ParamBackupsDetailEntity.java b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/emParam/entity/ParamBackupsDetailEntity.java index 269580c..7dbd983 100644 --- a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/emParam/entity/ParamBackupsDetailEntity.java +++ b/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") private Long backupsId; + @ApiModelProperty("参数分组") + private Long modelClassifyId; + + @ApiModelProperty("参数分组名称") + private String modelClassifyName; + @ApiModelProperty("参数名称") @QueryField(condition = SqlCondition.LIKE) private String name; diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/emParam/controller/ParamBackupsController.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/emParam/controller/ParamBackupsController.java index c6ccb84..d27ff95 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/emParam/controller/ParamBackupsController.java +++ b/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)); } + @GetMapping("/reductionParam") + @ApiOperation("根据备份ID还原参数") + @ApiOperationSupport(order = 6) + public R reductionParam(@RequestParam @ApiParam(value = "备份ID",required = true) Long id) { + return R.status(paramBackupsService.reductionParam(id)); + } + } diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/emParam/service/IParamBackupsService.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/emParam/service/IParamBackupsService.java index 4e73022..787b06e 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/emParam/service/IParamBackupsService.java +++ b/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.entity.ParamBackupsEntity; import com.hnac.hzims.emParam.vo.ParamBackupsVO; +import io.swagger.annotations.ApiParam; import org.springblade.core.mp.base.BaseService; import org.springblade.core.tool.utils.BeanUtil; import org.springblade.core.tool.utils.Func; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; public interface IParamBackupsService extends BaseService { @@ -18,6 +20,8 @@ public interface IParamBackupsService extends BaseService { Boolean updateById(ParamBackupsDTO request); + Boolean reductionParam(Long id); + default LambdaQueryWrapper getQueryWrapper(ParamBackupsDTO request) { ParamBackupsEntity paramBackupsEntity = BeanUtil.copy(request, ParamBackupsEntity.class); LambdaQueryWrapper queryWrapper = Condition.getQueryWrapper(ParamBackupsEntity.class, paramBackupsEntity); diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/emParam/service/impl/ParamBackupsServiceImpl.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/emParam/service/impl/ParamBackupsServiceImpl.java index b1af8de..b9e8f0b 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/emParam/service/impl/ParamBackupsServiceImpl.java +++ b/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; +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 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 paramList = backup.getDetailList(); + Assert.isTrue(CollectionUtil.isNotEmpty(paramList),() -> { + throw new ServiceException("备份参数不能为空!"); + }); + Map> 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 = paramList.stream().map(this::convert).collect(Collectors.toList()); + controlBatchDTO.setCtrls(ctrl); + log.info("{}", JSON.toJSONString(controlBatchDTO)); + Result 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; + } + } diff --git a/hzims-service/equipment/src/main/resources/db/1.0.2.sql b/hzims-service/equipment/src/main/resources/db/1.0.2.sql new file mode 100644 index 0000000..5e91c65 --- /dev/null +++ b/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 '参数分组名称'; \ No newline at end of file