Commit bffaa226 authored by wanghao's avatar wanghao

1 给所有设备上电 断电

parent 2650274c
...@@ -88,6 +88,22 @@ public class TStoreyInfoController extends BaseController ...@@ -88,6 +88,22 @@ public class TStoreyInfoController extends BaseController
return tStoreyInfoService.batchReadingCabinetStatus(fEquipmentCode); return tStoreyInfoService.batchReadingCabinetStatus(fEquipmentCode);
} }
/**
* 给所有设备下电
*/
@GetMapping(value = "/powerOffAllStore")
public AjaxResult powerOffAllStore() {
return tStoreyInfoService.powerOffAllStore();
}
/**
* 给所有设备上电
*/
@GetMapping(value = "/powerOnAllStore")
public AjaxResult powerOnAllStore() {
return tStoreyInfoService.powerOnAllStore();
}
/** /**
* 获取老化层信息详细信息 * 获取老化层信息详细信息
*/ */
......
...@@ -62,6 +62,8 @@ public interface TStoreyInfoMapper ...@@ -62,6 +62,8 @@ public interface TStoreyInfoMapper
*/ */
public int updateTStoreyInfo(TStoreyInfo tStoreyInfo); public int updateTStoreyInfo(TStoreyInfo tStoreyInfo);
public int updateAllStatusAndAgingStartTime(TStoreyInfo tStoreyInfo);
public int updateBatch(@Param("storeyInfos") List<TStoreyInfo> storeyInfos); public int updateBatch(@Param("storeyInfos") List<TStoreyInfo> storeyInfos);
/** /**
......
...@@ -45,6 +45,10 @@ public interface ITStoreyInfoService ...@@ -45,6 +45,10 @@ public interface ITStoreyInfoService
public AjaxResult batchReadingCabinetStatus(String fEquipmentCode); public AjaxResult batchReadingCabinetStatus(String fEquipmentCode);
public AjaxResult powerOffAllStore();
public AjaxResult powerOnAllStore();
/** /**
* 新增老化层信息 * 新增老化层信息
* *
......
package com.zehong.system.service.impl; package com.zehong.system.service.impl;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
import com.serotonin.modbus4j.ModbusMaster; import com.serotonin.modbus4j.ModbusMaster;
import com.serotonin.modbus4j.exception.ErrorResponseException; import com.serotonin.modbus4j.exception.ErrorResponseException;
...@@ -35,6 +39,8 @@ public class TStoreyInfoServiceImpl implements ITStoreyInfoService ...@@ -35,6 +39,8 @@ public class TStoreyInfoServiceImpl implements ITStoreyInfoService
@Resource @Resource
private TEquipmentInfoMapper equipmentInfoMapper; private TEquipmentInfoMapper equipmentInfoMapper;
private final ExecutorService executorService = Executors.newFixedThreadPool(10);
/** /**
* 查询老化层信息 * 查询老化层信息
* *
...@@ -166,6 +172,120 @@ public class TStoreyInfoServiceImpl implements ITStoreyInfoService ...@@ -166,6 +172,120 @@ public class TStoreyInfoServiceImpl implements ITStoreyInfoService
return tStoreyInfoMapper.queryByDepartmentId(fEquipmentId); return tStoreyInfoMapper.queryByDepartmentId(fEquipmentId);
} }
public AjaxResult powerOffAllStore() {
List<String> types = Arrays.asList("1", "2");
List<TEquipmentInfo> equipmentInfos = equipmentInfoMapper.selectTEquipmentList(types);
if (equipmentInfos.size() == 0) {
return AjaxResult.error("无设备信息!!!");
}
// 收集所有异步任务
List<CompletableFuture<TEquipmentInfo>> futures = equipmentInfos.stream()
.map(equipmentInfo -> CompletableFuture.supplyAsync(() -> {
ModbusMaster master = null;
List<Integer> registerOffsets = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
try {
master = Modbus4jUtils.getMaster(equipmentInfo.getfPowerOutageIp(), equipmentInfo.getfPowerOutagePort());
for (Integer registerOffset : registerOffsets) {
Boolean aBoolean = Modbus4jUtils.readCoilStatus(master, 1, registerOffset);
if (aBoolean) {
Modbus4jUtils.writeCoil(master, 1, registerOffset, false);
}
}
} catch (ModbusInitException | ModbusTransportException | ErrorResponseException e) {
throw new RuntimeException(e);
} finally {
// 建议在这里关闭master连接,避免资源泄露
if (master != null) {
try {
master.destroy();
} catch (Exception e) {
// 处理关闭异常
}
}
}
return equipmentInfo;
}, executorService))
.collect(Collectors.toList());
// 等待所有异步任务完成
CompletableFuture<Void> allFutures = CompletableFuture.allOf(
futures.toArray(new CompletableFuture[0])
);
// 所有任务完成后执行数据库更新
allFutures.thenRun(() -> {
TStoreyInfo tStoreyInfo = new TStoreyInfo();
tStoreyInfo.setfStatus("0");
tStoreyInfo.setfAgingStartTime(null);
tStoreyInfoMapper.updateAllStatusAndAgingStartTime(tStoreyInfo);
}).join(); // 阻塞等待所有操作完成
return AjaxResult.success();
}
/**
* 批量开灯
* @return r
*/
@Override
public AjaxResult powerOnAllStore() {
List<String> types = Arrays.asList("1", "2");
List<TEquipmentInfo> equipmentInfos = equipmentInfoMapper.selectTEquipmentList(types);
if (equipmentInfos.size() == 0) {
return AjaxResult.error("无设备信息!!!");
}
// 收集所有异步任务
List<CompletableFuture<TEquipmentInfo>> futures = equipmentInfos.stream()
.map(equipmentInfo -> CompletableFuture.supplyAsync(() -> {
ModbusMaster master = null;
List<Integer> registerOffsets = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
try {
master = Modbus4jUtils.getMaster(equipmentInfo.getfPowerOutageIp(), equipmentInfo.getfPowerOutagePort());
for (Integer registerOffset : registerOffsets) {
Boolean aBoolean = Modbus4jUtils.readCoilStatus(master, 1, registerOffset);
if (!aBoolean) {
Modbus4jUtils.writeCoil(master, 1, registerOffset, true);
}
}
} catch (ModbusInitException | ModbusTransportException | ErrorResponseException e) {
throw new RuntimeException(e);
} finally {
// 建议在这里关闭master连接,避免资源泄露
if (master != null) {
try {
master.destroy();
} catch (Exception e) {
// 处理关闭异常
}
}
}
return equipmentInfo;
}, executorService))
.collect(Collectors.toList());
// 等待所有异步任务完成
CompletableFuture<Void> allFutures = CompletableFuture.allOf(
futures.toArray(new CompletableFuture[0])
);
// 所有任务完成后执行数据库更新
allFutures.thenRun(() -> {
TStoreyInfo tStoreyInfo = new TStoreyInfo();
tStoreyInfo.setfStatus("1");
tStoreyInfo.setfAgingStartTime(DateUtils.getNowDate());
tStoreyInfoMapper.updateAllStatusAndAgingStartTime(tStoreyInfo);
}).join(); // 阻塞等待所有操作完成
return AjaxResult.success();
}
/** /**
* 批量读取设备状态 * 批量读取设备状态
* @param fEquipmentCode f * @param fEquipmentCode f
......
...@@ -168,6 +168,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -168,6 +168,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</trim> </trim>
where f_storey_id = #{fStoreyId} where f_storey_id = #{fStoreyId}
</update> </update>
<update id="updateAllStatusAndAgingStartTime" parameterType="TStoreyInfo">
update t_storey_info
<trim prefix="SET" suffixOverrides=",">
<if test="fStatus != null">f_status = #{fStatus},</if>
<if test="fAgingStartTime != null">f_aging_start_time = #{fAgingStartTime},</if>
<if test="fAgingStartTime == null">f_aging_start_time = null,</if>
</trim>
</update>
<update id="unbindByCode" parameterType="TStoreyInfo"> <update id="unbindByCode" parameterType="TStoreyInfo">
update t_storey_info update t_storey_info
......
...@@ -83,3 +83,17 @@ export function batchReadingCabinetStatus(fEquipmentCode) { ...@@ -83,3 +83,17 @@ export function batchReadingCabinetStatus(fEquipmentCode) {
method: 'get' method: 'get'
}) })
} }
export function powerOnAllStore() {
return request({
url: '/storey/powerOnAllStore',
method: 'get'
})
}
export function powerOffAllStore() {
return request({
url: '/storey/powerOffAllStore',
method: 'get'
})
}
...@@ -63,6 +63,24 @@ ...@@ -63,6 +63,24 @@
@click="handleReading" @click="handleReading"
>批量读取设备状态</el-button> >批量读取设备状态</el-button>
</el-col> </el-col>
<el-col :span="1.5">
<el-button
type="warning"
plain
icon="el-icon-reading"
size="mini"
@click="handleAllPowerOn"
>所有设备上电</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"
plain
icon="el-icon-reading"
size="mini"
@click="handleAllPowerOff"
>所有设备断电</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row> </el-row>
...@@ -184,7 +202,7 @@ ...@@ -184,7 +202,7 @@
</template> </template>
<script> <script>
import { listStorey, getStorey, delStorey, addStorey, updateStorey, exportStorey,PowerOn,PowerOutage ,batchReadingCabinetStatus} from "@/api/storey/storey"; import { listStorey, getStorey, delStorey, addStorey, updateStorey, exportStorey,PowerOn,PowerOutage ,batchReadingCabinetStatus,powerOnAllStore,powerOffAllStore} from "@/api/storey/storey";
export default { export default {
name: "Info", name: "Info",
...@@ -386,12 +404,32 @@ export default { ...@@ -386,12 +404,32 @@ export default {
} }
}) })
}).catch(() => { }).catch(() => {
this.$message({
type: 'info',
message: '取消输入'
});
}); });
}, },
handleAllPowerOff() {
this.$confirm('是否确认给所有设备断电?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
return powerOffAllStore();
}).then(() => {
this.getList();
this.msgSuccess("断电成功");
}).catch(() => {});
},
handleAllPowerOn() {
this.$confirm('是否确认给所有设备上电?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
return powerOnAllStore();
}).then(() => {
this.getList();
this.msgSuccess("上电成功");
}).catch(() => {});
},
/** 导出按钮操作 */ /** 导出按钮操作 */
handleExport() { handleExport() {
const queryParams = this.queryParams; const queryParams = this.queryParams;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment