代码优化

This commit is contained in:
zzc 2024-12-22 23:36:04 +08:00
parent 00634e17f2
commit ff1006b8e9
6 changed files with 48 additions and 6 deletions

View File

@ -346,6 +346,7 @@ public class EqHomeController extends BaseController {
@PostMapping("/list")
public TableDataInfo<EqEquipmentVo> list(EqAppHomeBo bo, PageQuery pageQuery){
//当前用户为家庭主体 切换用户后需要传输用户id
//zc todo 需要返回半开门设置
Long currentUserId = LoginHelper.getUserId();
boolean shared=true;
List<Long> equipmentIdIds=null;

View File

@ -100,6 +100,12 @@ public class EqEquipmentVo implements Serializable {
@ExcelDictFormat(dictType = "eq_line_status")
private Integer lineStatus;
/**
* //半开门功能开关 false
* //半开门功能开关 true
*/
private Boolean PartOpenSwitch;
/**
* 绑定时间
*/

View File

@ -3,6 +3,7 @@ package org.dromara.web.service.impl;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.MessageUtils;
import org.dromara.common.core.utils.StringUtils;
@ -97,6 +98,7 @@ public class EqEquipmentServiceImpl implements IEqEquipmentService {
}
record.setStatus(telemetryMsg.getOpenPercentage());
record.setFaultStatus(telemetryMsg.getGarageException());
record.setPartOpenSwitch(telemetryMsg.getPartOpenSwitch());
//开合状态
record.setOpenStatus(telemetryMsg.getOpenPercentage());
@ -432,6 +434,7 @@ public class EqEquipmentServiceImpl implements IEqEquipmentService {
//2.查询OTA资源包
// DeviceOtaPackages deviceOtaPackages = iotService.httpOtaLastPackages(profileIdId);
List<DeviceOtaPackages> list = iotService.httpOtaPackages(profileIdId);
if (CollUtil.isEmpty(list)) throw new ServiceException("未获取到OTA资源包");
DeviceOtaPackages lastOtaPackage = list.get(0);
DeviceOtaPackages currentOtaPackage = null;

View File

@ -16,12 +16,17 @@ import org.dromara.web.config.LastWebSocketParamDto;
import org.dromara.web.controller.app.EqDeviceController;
import org.dromara.web.controller.app.EqHomeController;
import org.dromara.web.domain.bo.EqAppHomeBo;
import org.dromara.web.domain.bo.EqUserConfigBo;
import org.dromara.web.domain.vo.EqEquipmentDetailVo;
import org.dromara.web.domain.vo.EqEquipmentVo;
import org.dromara.web.domain.vo.EqUserConfigVo;
import org.dromara.web.service.IEqUserConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Locale;
/**
* @ClassName : WebSocketHandler
@ -39,18 +44,23 @@ public class WebSocketBusinessHandler implements WebSocketApi {
@Autowired
private EqHomeController homeController;
@Autowired
private IEqUserConfigService userConfigService;
@Override
public void dealWithDetailMsg(LoginUser loginUser, String msg) {
EqAppHomeBo bo = null;
String sendMsg = "";
R<EqEquipmentDetailVo> deviceMsg = null;
boolean isTrue = true;
Long userId = loginUser.getUserId();
try {
initLanguage(userId);
bo = JSON.parseObject(msg, EqAppHomeBo.class);
LastWebSocketParamDto dto = new LastWebSocketParamDto();
dto.setMethod(Constants.METHOD_EQ_DETAIL);
dto.setBo(bo);
RedisUtils.setCacheObject(Constants.WEBSOCKET_METHOD+loginUser.getUserId(),dto);
RedisUtils.setCacheObject(Constants.WEBSOCKET_METHOD+ userId,dto);
} catch (Exception e) {
log.error("参数错误");
isTrue = false;
@ -68,7 +78,19 @@ public class WebSocketBusinessHandler implements WebSocketApi {
// EqEquipmentDetailVo data = deviceMsg.getData();
sendMsg = JsonUtils.toJsonString(deviceMsg);
log.info("socket详情发送{}",sendMsg);
sendMsg(sendMsg,loginUser.getUserId());
sendMsg(sendMsg, userId);
}
private void initLanguage(Long userId) {
EqUserConfigBo userConfigBo = new EqUserConfigBo();
userConfigBo.setUserId(userId);
List<EqUserConfigVo> eqUserConfigVos = userConfigService.queryList(userConfigBo);
if(!eqUserConfigVos.isEmpty()){
EqUserConfigVo eqUserConfigVo = eqUserConfigVos.get(0);
String languageType = eqUserConfigVo.getLanguageType();
String[] languages = languageType.split("_");
LocaleContextHolder.setDefaultLocale(new Locale(languages[0], languages[1]));
}
}
@Override
@ -76,12 +98,14 @@ public class WebSocketBusinessHandler implements WebSocketApi {
EqAppHomeBo bo = null;
String sendMsg = "";
boolean isTure = true;
Long userId = loginUser.getUserId();
try {
initLanguage(userId);
bo = JSON.parseObject(msg, EqAppHomeBo.class);
LastWebSocketParamDto dto = new LastWebSocketParamDto();
dto.setMethod(Constants.METHOD_EQ_LIST);
dto.setBo(bo);
RedisUtils.setCacheObject(Constants.WEBSOCKET_METHOD +loginUser.getUserId(),dto);
RedisUtils.setCacheObject(Constants.WEBSOCKET_METHOD + userId,dto);
} catch (Exception e) {
log.error("参数错误");
sendMsg = "参数错误";
@ -102,7 +126,7 @@ public class WebSocketBusinessHandler implements WebSocketApi {
}
sendMsg = isTure? JsonUtils.toJsonString(list):sendMsg;
log.info("socket列表发送{}",sendMsg);
sendMsg(sendMsg,loginUser.getUserId());
sendMsg(sendMsg, userId);
}

View File

@ -2,15 +2,19 @@ package org.dromara.common.core.utils;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.MessageSource;
import org.springframework.context.NoSuchMessageException;
import org.springframework.context.i18n.LocaleContextHolder;
import java.util.Locale;
/**
* 获取i18n资源文件
*
* @author Lion Li
*/
@Slf4j
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class MessageUtils {
@ -25,7 +29,9 @@ public class MessageUtils {
*/
public static String message(String code, Object... args) {
try {
return MESSAGE_SOURCE.getMessage(code, args, LocaleContextHolder.getLocale());
Locale locale = LocaleContextHolder.getLocale();
// if (locale.toLanguageTag().equals("en")) locale = Locale.CHINA;//zc change with userid because socket I18n
return MESSAGE_SOURCE.getMessage(code, args, locale);
} catch (NoSuchMessageException e) {
return code;
}

View File

@ -41,7 +41,9 @@ public class SecurityConfig {
new AntPathRequestMatcher(adminContextPath + "/assets/**"),
new AntPathRequestMatcher(adminContextPath + "/login"),
new AntPathRequestMatcher("/actuator"),
new AntPathRequestMatcher("/actuator/**")
new AntPathRequestMatcher("/actuator/**"),
new AntPathRequestMatcher("/protocal"),
new AntPathRequestMatcher("/protocal/**")
).permitAll()
.anyRequest().authenticated())
.formLogin((formLogin) ->