src/main/java/org/springblade/common/handler/SocketEntity.java
@@ -4,10 +4,10 @@ @Data public class SocketEntity { //当前设备号 //当前设备编号 private String current; //目标设备 //目标设备编号 private String target; //消息 src/main/java/org/springblade/common/handler/SocketIOService.java
@@ -50,16 +50,8 @@ @Autowired private SocketIOServer socketIOServer; @Autowired private IFunctionService functionService; @Autowired private IModulesService modulesService; /** * Spring IoC容器创建之后,在加载SocketIOConfiguration Bean之后启动 * * @throws Exception */ @PostConstruct private void autoStartup() throws Exception { @@ -68,8 +60,6 @@ /** * Spring IoC容器在销毁SocketIOConfiguration Bean之前关闭,避免重启项目服务端口占用问题 * * @throws Exception */ @PreDestroy private void autoStop() throws Exception { @@ -83,12 +73,20 @@ /** * 连接时 * * @param client */ @OnConnect public void onConnect(SocketIOClient client) { log.info(client.getSessionId().toString()); String connectInfo = client.getHandshakeData().getSingleUrlParam("connectInfo"); SocketEntity socketEntity = parseMsg(connectInfo); if (clientMap.containsKey(socketEntity.getCurrent())){ client.sendEvent("connectError",R.fail("连接已存在")); log.info("设备{}连接失败",socketEntity.getCurrent()); }else { clientMap.put(socketEntity.getCurrent(),client); client.sendEvent("connectOk",R.success("连接成功")); log.info("设备{}连接成功",socketEntity.getCurrent()); } } /** @@ -101,32 +99,6 @@ @OnEvent(value = "msg") public void OnEvent(SocketIOClient client, AckRequest ackRequest, String data) { log.info("发来消息:" + data); } /** * 添加进clientMap */ @OnEvent(value = "putInClientMap") public void OnEventPutInClientMap(SocketIOClient client, AckRequest ackRequest, String data) { FunctionEntity functionEntity = new FunctionEntity(); SocketEntity socketEntity = parseMsg(data); //判断是否是控制器 if (StringUtil.isBlank(socketEntity.getTarget())) { //媒体端 functionEntity.setModulesId(socketEntity.getCurrent()); } else { //控制器 functionEntity.setModulesId(socketEntity.getTarget()); } List<FunctionEntity> all = functionService.getAll(functionEntity); if (all.size() > 0) { clientMap.put(socketEntity.getCurrent(), client); client.sendEvent("connectOk", R.data(all)); } else { client.sendEvent("connectError", R.fail("该模块不存在")); } } /** @@ -152,7 +124,7 @@ public void OnEventMenuChange(SocketIOClient client, AckRequest ackRequest, String data) { log.info("菜单变更:" + data); SocketEntity socketEntity = parseMsg(data); log.info("目标客户端:{}", clientMap.get(socketEntity.getTarget()).getSessionId().toString()); log.info("控制的设备是:{}", parseMsg(client.getHandshakeData().getSingleUrlParam("connectInfo")).getTarget()); clientMap.get(socketEntity.getTarget()).sendEvent("menuChange", socketEntity.getMsg()); } @@ -163,12 +135,14 @@ */ @OnDisconnect() public void OnEvent(SocketIOClient client) { clientMap.forEach((e, socketIOClient) -> { if (socketIOClient.equals(client)) { clientMap.remove(e); log.info("{}断开连接", e); String connectInfo = client.getHandshakeData().getSingleUrlParam("connectInfo"); SocketEntity socketEntity = parseMsg(connectInfo); clientMap.forEach((key,value)->{ if (value.getSessionId().equals(client.getSessionId())){ clientMap.remove(key); } }); log.info("设备{}断开连接",socketEntity.getCurrent()); } public void stop() { @@ -207,7 +181,7 @@ } /** * 解析客户端连接请求中的参数,转化为实体类 * 解析参数,转化为实体类 */ private SocketEntity parseMsg(String msg) { return JSON.parseObject(msg, SocketEntity.class); src/main/java/org/springblade/modules/modules/controller/FunctionController.java
@@ -24,6 +24,8 @@ import lombok.AllArgsConstructor; import javax.validation.Valid; import lombok.SneakyThrows; import org.springblade.core.oss.model.BladeFile; import org.springblade.core.secure.BladeUser; import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Query; @@ -32,9 +34,11 @@ import org.springblade.modules.modules.entity.FunctionEntity; import org.springblade.modules.modules.service.IFunctionService; import org.springblade.modules.modules.vo.FunctionVO; import org.springblade.modules.resource.builder.oss.OssBuilder; import org.springframework.web.bind.annotation.*; import com.baomidou.mybatisplus.core.metadata.IPage; import org.springblade.core.boot.ctrl.BladeController; import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -51,6 +55,10 @@ public class FunctionController extends BladeController { private final IFunctionService modulesFunctionService; /** * 对象存储构建类 */ private final OssBuilder ossBuilder; /** * 功能表 详情 @@ -90,8 +98,8 @@ @GetMapping("/all") @ApiOperationSupport(order = 3) @ApiOperation(value = "分页", notes = "传入modulesFunction") public R getAll(FunctionEntity function) { List<FunctionEntity> functionEntities = modulesFunctionService.getAll(function); public R getAll(FunctionVO function) { List<FunctionVO> functionEntities = modulesFunctionService.getAll(function); return R.data(functionEntities); } @@ -135,5 +143,23 @@ return R.status(modulesFunctionService.deleteLogic(Func.toLongList(ids))); } /** * 上传文件并保存至附件表 * * @param file 文件 * @return ObjectStat */ @SneakyThrows @PostMapping("/put-file-attach") public R putFileAttach(@RequestParam MultipartFile file) { String fileName = file.getOriginalFilename(); BladeFile bladeFile = ossBuilder.template().putFile(fileName, file.getInputStream()); return R.success("添加成功"); } } src/main/java/org/springblade/modules/modules/mapper/FunctionMapper.java
@@ -46,5 +46,5 @@ * @param function * @return */ List<FunctionEntity> getAll(@Param("function") FunctionEntity function); List<FunctionVO> getAll(@Param("function") FunctionVO function); } src/main/java/org/springblade/modules/modules/mapper/FunctionMapper.xml
@@ -3,7 +3,7 @@ <mapper namespace="org.springblade.modules.modules.mapper.FunctionMapper"> <!-- 通用查询映射结果 --> <resultMap id="modulesFunctionResultMap" type="org.springblade.modules.modules.entity.FunctionEntity"> <resultMap id="modulesFunctionResultMap" type="org.springblade.modules.modules.vo.FunctionVO"> <result column="id" property="id"/> <result column="modules_id" property="modulesId"/> <result column="name" property="name"/> @@ -11,6 +11,7 @@ <result column="type" property="type"/> <result column="sort" property="sort"/> <result column="file_url" property="fileUrl" typeHandler="com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler"/> <result column="code" property="equipmentCode"/> <result column="tenant_id" property="tenantId"/> <result column="create_user" property="createUser"/> <result column="create_dept" property="createDept"/> @@ -27,12 +28,18 @@ </select> <select id="getAll" resultMap="modulesFunctionResultMap"> select * from sys_modules_function where is_deleted = 0 select func.*,equipment.code from sys_modules_function func LEFT JOIN sys_modules modules ON modules.id = func.modules_id AND modules.is_deleted = 0 LEFT JOIN sys_equipment equipment ON equipment.id = modules.equipment_id where func.is_deleted = 0 <if test="function.modulesId !=null and function.modulesId !=''"> AND modules_id = #{function.modulesId} </if> ORDER BY property ASC,sort ASC <if test="function.equipmentCode !=null and function.equipmentCode !=''"> AND equipment.code = #{function.equipmentCode} </if> ORDER BY func.property ASC,func.sort ASC </select> src/main/java/org/springblade/modules/modules/service/IFunctionService.java
@@ -45,5 +45,5 @@ * @param function * @return */ List<FunctionEntity> getAll(FunctionEntity function); List<FunctionVO> getAll(FunctionVO function); } src/main/java/org/springblade/modules/modules/service/impl/FunctionServiceImpl.java
@@ -42,7 +42,7 @@ } @Override public List<FunctionEntity> getAll(FunctionEntity function) { public List<FunctionVO> getAll(FunctionVO function) { return baseMapper.getAll(function); } src/main/java/org/springblade/modules/modules/vo/FunctionVO.java
@@ -32,4 +32,6 @@ public class FunctionVO extends FunctionEntity { private static final long serialVersionUID = 1L; private String equipmentCode; }