42 Commits

Author SHA1 Message Date
0b0cc84eea Merge branch 'main' into fys-prod 2025-08-04 09:39:08 +08:00
ae393e8155 校验设备类型名称 2025-08-04 09:36:17 +08:00
38caba1fad 修改用户状态-强制下线 2025-08-04 09:35:59 +08:00
6626a1a35e 设备行为 2025-08-04 09:34:16 +08:00
4271085e78 用户注销 2025-08-01 09:58:33 +08:00
2cb4f5b83e 设备绑定优化2 2025-08-01 09:07:27 +08:00
a3a1d43dde Merge remote-tracking branch 'origin/main'
# Conflicts:
#	fys-admin/src/main/java/com/fuyuanshen/app/service/AppDeviceBizService.java
#	fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/AppDeviceBindRecord.java
2025-08-01 09:06:03 +08:00
5f4b12a320 设备绑定优化 2025-08-01 09:00:32 +08:00
f2c7549d6e Merge branch 'main' into fys-prod 2025-07-31 09:24:23 +08:00
7bd652f9b8 Merge remote-tracking branch 'upstream/main' 2025-07-31 09:23:34 +08:00
9ffdcace53 LngLonUtil.java 2025-07-28 10:41:09 +08:00
8cc969bbe6 Merge remote-tracking branch 'upstream/main' 2025-07-28 10:40:31 +08:00
6a900335ef LngLonUtil.java 2025-07-28 10:40:13 +08:00
f1806fa482 app用户登录 2025-07-24 14:49:40 +08:00
17ed75f54a Merge branch 'main' into fys-prod 2025-07-23 19:26:46 +08:00
0abc5d48c0 Merge remote-tracking branch 'upstream/main' 2025-07-23 19:26:12 +08:00
e7c8e245ba Merge remote-tracking branch 'upstream/main' 2025-07-23 11:01:01 +08:00
80b944cbf0 Merge remote-tracking branch 'upstream/main' into fys-prod
# Conflicts:
#	fys-admin/pom.xml
2025-07-23 10:57:03 +08:00
537cc0b2d7 Merge branch 'main' into fys-prod
# Conflicts:
#	pom.xml
2025-07-21 08:45:53 +08:00
8750bc8e10 Merge remote-tracking branch 'upstream/main' 2025-07-21 08:43:34 +08:00
6dde6c3a3b 去掉demo 2025-07-21 08:42:21 +08:00
bb096f53cd 去除demo模块 2025-07-19 16:16:22 +08:00
38724dbfad Merge branch 'main' into fys-prod 2025-07-19 15:58:51 +08:00
e9227dea89 Merge remote-tracking branch 'origin/main'
# Conflicts:
#	fys-admin/src/main/java/com/fuyuanshen/web/controller/CaptchaController.java
2025-07-19 14:24:21 +08:00
b369b28949 新增忘记密码手机短信验证码 2025-07-19 14:23:29 +08:00
f1d1528c40 Merge remote-tracking branch 'upstream/main'
# Conflicts:
#	fys-common/fys-common-core/src/main/java/com/fuyuanshen/common/core/constant/GlobalConstants.java
2025-07-19 10:26:52 +08:00
73e1df4232 Merge branch 'main' into fys-prod 2025-07-18 16:30:02 +08:00
fys
4e608b8f3a merge upstream 2025-07-18 16:24:05 +08:00
e35955f156 prod 2025-07-17 17:27:14 +08:00
3c2d97aaf2 提交 2025-07-17 17:17:30 +08:00
6ed1241a6d Merge remote-tracking branch 'upstream/main'
# Conflicts:
#	fys-modules/fys-app/src/main/resources/mapper/app/AppBusinessFileMapper.xml
2025-07-17 17:03:25 +08:00
1cf7c47ef9 正式环境配置提交 2025-07-14 16:28:54 +08:00
bdee8c8383 Merge remote-tracking branch 'origin/main' 2025-07-12 15:31:42 +08:00
6f4e18fb3f 文件管理代码优化 2025-07-12 15:31:27 +08:00
fys
3ca6b69709 merge upstream 2025-07-12 14:04:03 +08:00
e13e3c57a6 解绑问题修改2 2025-07-12 10:41:35 +08:00
56704f6014 个人中心修改 2025-07-12 10:18:12 +08:00
4f00c69f91 绑定优化2 2025-07-12 09:55:29 +08:00
fcd17634dc 绑定优化 2025-07-12 09:54:08 +08:00
24f0caacd5 绑定蓝牙问题解决 2025-07-12 09:52:14 +08:00
c73a700210 app登录配置修改 2025-07-11 17:39:53 +08:00
3ed2f97752 app接口功能实现 2025-07-11 16:40:20 +08:00
39 changed files with 1567 additions and 193 deletions

View File

@ -94,10 +94,10 @@
</dependency>
<!-- demo模块 -->
<!--<dependency>
<groupId>com.fuyuanshen</groupId>
<artifactId>fys-demo</artifactId>
</dependency>-->
<!-- <dependency> -->
<!-- <groupId>com.fuyuanshen</groupId> -->
<!-- <artifactId>fys-demo</artifactId> -->
<!-- </dependency> -->
<!-- 工作流模块 -->
<dependency>

View File

@ -4,14 +4,13 @@ import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.exception.NotLoginException;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.fuyuanshen.app.model.AppSmsLoginBody;
import com.fuyuanshen.app.service.AppLoginService;
import com.fuyuanshen.common.core.constant.SystemConstants;
import com.fuyuanshen.common.core.domain.R;
import com.fuyuanshen.common.core.domain.model.RegisterBody;
import com.fuyuanshen.common.core.domain.model.SmsLoginBody;
import com.fuyuanshen.common.core.domain.model.AppLoginBody;
import com.fuyuanshen.common.core.domain.model.AppSmsRegisterBody;
import com.fuyuanshen.common.core.domain.model.PasswordLoginBody;
import com.fuyuanshen.common.core.utils.*;
import com.fuyuanshen.common.encrypt.annotation.ApiEncrypt;
import com.fuyuanshen.common.json.utils.JsonUtils;
import com.fuyuanshen.common.satoken.utils.LoginHelper;
import com.fuyuanshen.common.tenant.helper.TenantHelper;
@ -24,8 +23,8 @@ import com.fuyuanshen.system.service.ISysTenantService;
import com.fuyuanshen.web.domain.vo.LoginTenantVo;
import com.fuyuanshen.web.domain.vo.LoginVo;
import com.fuyuanshen.web.domain.vo.TenantListVo;
import com.fuyuanshen.web.service.AppRegisterService;
import com.fuyuanshen.web.service.IAuthStrategy;
import com.fuyuanshen.web.service.SysRegisterService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -51,7 +50,7 @@ import java.util.List;
public class AppAuthController {
private final AppLoginService loginService;
private final SysRegisterService registerService;
private final AppRegisterService registerService;
private final ISysConfigService configService;
private final ISysTenantService tenantService;
private final ISysClientService clientService;
@ -64,15 +63,15 @@ public class AppAuthController {
*/
// @ApiEncrypt
@PostMapping("/login")
public R<LoginVo> login(@RequestBody AppSmsLoginBody appSmsLoginBody) {
public R<LoginVo> login(@RequestBody AppLoginBody appLoginBody) {
// SmsLoginBody loginBody = JsonUtils.parseObject(body, SmsLoginBody.class);
ValidatorUtils.validate(appSmsLoginBody);
SmsLoginBody loginBody = new SmsLoginBody();
loginBody.setPhonenumber(appSmsLoginBody.getPhonenumber());
loginBody.setSmsCode(appSmsLoginBody.getSmsCode());
loginBody.setTenantId(appSmsLoginBody.getTenantId());
loginBody.setClientId("ca839698e245d60aa2f0e59bd52b34f8");
loginBody.setGrantType("appSms");
ValidatorUtils.validate(appLoginBody);
PasswordLoginBody loginBody = new PasswordLoginBody();
loginBody.setUsername(appLoginBody.getUserName());
loginBody.setPassword(appLoginBody.getPassword());
loginBody.setTenantId(appLoginBody.getTenantId());
loginBody.setClientId("835b15335d389c9fcfdf99421fa8019b");
loginBody.setGrantType("appPassword");
// 授权类型和客户端id
String clientId = loginBody.getClientId();
String grantType = loginBody.getGrantType();
@ -93,7 +92,14 @@ public class AppAuthController {
}
/**
* 用户注销
*/
@DeleteMapping("/cancelAccount")
public R<Void> cancelAccount() {
loginService.cancelAccount();
return R.ok("用户注销成功");
}
/**
* 退出登录
@ -107,12 +113,8 @@ public class AppAuthController {
/**
* 用户注册
*/
@ApiEncrypt
@PostMapping("/register")
public R<Void> register(@Validated @RequestBody RegisterBody user) {
if (!configService.selectRegisterEnabled(user.getTenantId())) {
return R.fail("当前系统没有开启注册功能!");
}
public R<Void> register(@Validated @RequestBody AppSmsRegisterBody user) {
registerService.register(user);
return R.ok();
}

View File

@ -0,0 +1,88 @@
package com.fuyuanshen.app.controller;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.core.util.RandomUtil;
import com.fuyuanshen.app.domain.dto.APPForgotPasswordDTO;
import com.fuyuanshen.app.domain.dto.APPForgotPasswordSmsDTO;
import com.fuyuanshen.app.domain.dto.APPUpdateUserDTO;
import com.fuyuanshen.app.domain.vo.APPUserInfoVo;
import com.fuyuanshen.app.service.IAppUserService;
import com.fuyuanshen.common.core.constant.Constants;
import com.fuyuanshen.common.core.constant.GlobalConstants;
import com.fuyuanshen.common.core.domain.R;
import com.fuyuanshen.common.ratelimiter.annotation.RateLimiter;
import com.fuyuanshen.common.redis.utils.RedisUtils;
import com.fuyuanshen.common.web.core.BaseController;
import jakarta.validation.constraints.NotBlank;
import lombok.RequiredArgsConstructor;
import org.dromara.sms4j.api.SmsBlend;
import org.dromara.sms4j.api.entity.SmsResponse;
import org.dromara.sms4j.core.factory.SmsFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.time.Duration;
import java.util.LinkedHashMap;
/**
* APP 用户管理
* @date 2025-06-27
*/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/user")
public class AppUserController extends BaseController {
private final IAppUserService appUserService;
/**
* 个人中心
*/
@GetMapping("/getUserInfo")
public R<APPUserInfoVo> getUserInfo() {
return R.ok(appUserService.getUserInfo());
}
/**
* 修改个人信息
*/
@PostMapping("/updateUser")
public R<Void> updateUser(@Validated @ModelAttribute APPUpdateUserDTO bo) {
return toAjax(appUserService.updateUser(bo));
}
/**
* 忘记密码
*/
@SaIgnore
@PostMapping("/forgotPassword")
public R<Void> forgotPassword(@RequestBody APPForgotPasswordDTO bo) {
return toAjax(appUserService.forgotPassword(bo));
}
/**
* 发送忘记密码短信
*
* @param phonenumber 用户手机号
*/
@SaIgnore
@RateLimiter(key = "#phonenumber", time = 60, count = 1)
@GetMapping("/sendForgotPasswordSms")
public R<Void> smsCode(@NotBlank(message = "{user.phonenumber.not.blank}") String phonenumber) {
String key = GlobalConstants.APP_FORGOT_PASSWORD_SMS_KEY + phonenumber;
String code = RandomUtil.randomNumbers(4);
RedisUtils.setCacheObject(key, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION));
// 验证码模板id 自行处理 (查数据库或写死均可)
String templateId = "";
LinkedHashMap<String, String> map = new LinkedHashMap<>(1);
map.put("code", code);
SmsBlend smsBlend = SmsFactory.getSmsBlend("config1");
SmsResponse smsResponse = smsBlend.sendMessage(phonenumber, map);
if (!smsResponse.isSuccess()) {
return R.fail(smsResponse.getData().toString());
}
return R.ok();
}
}

View File

@ -11,6 +11,6 @@ public class DeviceInstructDto {
/**
* 下发指令
*/
private Object instructValue;
private String instructValue;
}

View File

@ -2,7 +2,6 @@ package com.fuyuanshen.app.service;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -13,7 +12,6 @@ import com.fuyuanshen.app.domain.dto.APPReNameDTO;
import com.fuyuanshen.app.domain.dto.AppDeviceLogoUploadDto;
import com.fuyuanshen.app.domain.dto.DeviceInstructDto;
import com.fuyuanshen.app.domain.vo.APPDeviceTypeVo;
import com.fuyuanshen.app.domain.vo.AppDeviceBindRecordVo;
import com.fuyuanshen.app.domain.vo.AppDeviceDetailVo;
import com.fuyuanshen.app.domain.vo.AppPersonnelInfoVo;
import com.fuyuanshen.app.mapper.AppDeviceBindRecordMapper;
@ -38,10 +36,6 @@ import com.fuyuanshen.equipment.enums.BindingStatusEnum;
import com.fuyuanshen.equipment.enums.CommunicationModeEnum;
import com.fuyuanshen.equipment.mapper.DeviceMapper;
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
import static com.fuyuanshen.common.core.utils.Bitmap80x12Generator.*;
import static com.fuyuanshen.common.core.utils.ImageToCArrayConverter.convertHexToDecimal;
import com.fuyuanshen.equipment.utils.c.ReliableTextToBitmap;
import com.fuyuanshen.global.mqtt.config.MqttGateway;
import com.fuyuanshen.global.mqtt.constants.MqttConstants;
@ -53,6 +47,9 @@ import org.springframework.web.multipart.MultipartFile;
import java.time.Duration;
import java.util.*;
import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY;
import static com.fuyuanshen.common.core.utils.ImageToCArrayConverter.convertHexToDecimal;
@Slf4j
@Service
@ -66,7 +63,6 @@ public class AppDeviceBizService {
private final MqttGateway mqttGateway;
private final AppDeviceBindRecordMapper appDeviceBindRecordMapper;
public List<APPDeviceTypeVo> getTypeList() {
Long userId = AppLoginHelper.getUserId();
return appDeviceMapper.getTypeList(userId);
@ -83,23 +79,21 @@ public class AppDeviceBizService {
public int sendMessage(AppDeviceSendMsgBo bo) {
List<Long> deviceIds = bo.getDeviceIds();
if (deviceIds == null || deviceIds.isEmpty()) {
if(deviceIds == null || deviceIds.isEmpty()){
throw new ServiceException("请选择设备");
}
for (Long deviceId : deviceIds) {
for (Long deviceId : deviceIds){
Device deviceObj = deviceMapper.selectById(deviceId);
if (deviceObj == null) {
throw new ServiceException("设备不存在" + deviceId);
if(deviceObj==null) {
throw new ServiceException("设备不存在"+deviceId);
}
byte[] msg = ReliableTextToBitmap.textToBitmapBytes(bo.getSendMsg());
ArrayList<Integer> intData = new ArrayList<>();
intData.add(2);
buildArr(convertHexToDecimal(msg), intData);
Map<String, Object> map = new HashMap<>();
map.put("instruct", intData);
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + deviceObj.getDeviceImei(), 1, JSON.toJSONString(map));
log.info("发送设备消息topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + deviceObj.getDeviceImei(), bo.getSendMsg());
Map<String,Object> linkHashMap = new HashMap<>();
linkHashMap.put("message",msg);
String sendMsg = JSON.toJSONString(linkHashMap);
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY+deviceObj.getDeviceImei(), 1 ,sendMsg);
log.info("发送设备消息:{}", bo.getSendMsg());
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id", deviceId)
@ -136,27 +130,6 @@ public class AppDeviceBizService {
if (device.getBindingStatus() != null && device.getBindingStatus() == BindingStatusEnum.BOUND.getCode()) {
throw new RuntimeException("设备已绑定");
}
QueryWrapper<AppDeviceBindRecord> bindRecordQueryWrapper = new QueryWrapper<>();
bindRecordQueryWrapper.eq("device_id", device.getId());
AppDeviceBindRecord appDeviceBindRecord = appDeviceBindRecordMapper.selectOne(bindRecordQueryWrapper);
if (appDeviceBindRecord != null) {
UpdateWrapper<AppDeviceBindRecord> deviceUpdateWrapper = new UpdateWrapper<>();
deviceUpdateWrapper.eq("device_id", device.getId())
.set("binding_status", BindingStatusEnum.BOUND.getCode())
.set("binding_user_id", userId)
.set("update_time", new Date())
.set("binding_time", new Date());
return appDeviceBindRecordMapper.update(null, deviceUpdateWrapper);
} else {
AppDeviceBindRecord bindRecord = new AppDeviceBindRecord();
bindRecord.setDeviceId(device.getId());
bindRecord.setBindingUserId(userId);
bindRecord.setBindingTime(new Date());
bindRecord.setCreateBy(userId);
appDeviceBindRecordMapper.insert(bindRecord);
}
UpdateWrapper<Device> deviceUpdateWrapper = new UpdateWrapper<>();
deviceUpdateWrapper.eq("id", device.getId())
.set("binding_status", BindingStatusEnum.BOUND.getCode())
@ -184,7 +157,7 @@ public class AppDeviceBizService {
.set("binding_user_id", userId)
.set("binding_time", new Date());
return appDeviceBindRecordMapper.update(null, deviceUpdateWrapper);
} else {
}else{
AppDeviceBindRecord bindRecord = new AppDeviceBindRecord();
bindRecord.setDeviceId(device.getId());
bindRecord.setBindingUserId(userId);
@ -217,8 +190,8 @@ public class AppDeviceBizService {
}
UpdateWrapper<Device> deviceUpdateWrapper = new UpdateWrapper<>();
deviceUpdateWrapper.eq("id", device.getId())
.set("binding_user_id", null)
.set("binding_status", BindingStatusEnum.UNBOUND.getCode())
.set("binding_user_id", null)
.set("binding_time", null);
deviceMapper.update(null, deviceUpdateWrapper);
@ -278,70 +251,28 @@ public class AppDeviceBizService {
return vo;
}
public static void main(String[] args) {
byte[] unitName = generateFixedBitmapData("富源晟科技", 120);
byte[] position = generateFixedBitmapData("研发", 120);
byte[] name = generateFixedBitmapData("张三", 120);
byte[] id = generateFixedBitmapData("123456", 120);
// int[] intUnitNames = Bitmap80x12Generator.convertHexToDecimal(unitName);
// int[] intPosition = Bitmap80x12Generator.convertHexToDecimal(position);
// int[] intNames = Bitmap80x12Generator.convertHexToDecimal(position);
// int[] intIds = Bitmap80x12Generator.convertHexToDecimal(position);
// Map<String, Object> map = new HashMap<>();
// map.put("instruct", 2);
// System.out.println(JSON.toJSONString( map));
// StringBuilder sb = new StringBuilder();
// sb.append("[")
// buildStr(unitName, sb);
// System.out.println(sb.toString());
// Object[] arr = new Object[]{2, Bitmap80x12Generator , Arrays.toString(name), Arrays.toString(id)};
// System.out.println(Arrays.deepToString(arr));
// int[] a = new int[]{6,6,6,6,6,6};
ArrayList<Integer> intData = new ArrayList<>();
intData.add(2);
buildArr(convertHexToDecimal(unitName), intData);
buildArr(convertHexToDecimal(position), intData);
buildArr(convertHexToDecimal(name), intData);
buildArr(convertHexToDecimal(id), intData);
intData.add(0);
intData.add(0);
intData.add(0);
intData.add(0);
Map<String, Object> map = new HashMap<>();
map.put("instruct", intData);
System.out.println(JSON.toJSONString(map));
}
public boolean registerPersonInfo(AppPersonnelInfoBo bo) {
Long deviceId = bo.getDeviceId();
Device deviceObj = deviceMapper.selectById(deviceId);
if (deviceObj == null) {
if(deviceObj == null){
throw new RuntimeException("请先将设备入库!!!");
}
QueryWrapper<AppPersonnelInfo> qw = new QueryWrapper<AppPersonnelInfo>()
.eq("device_id", deviceId);
List<AppPersonnelInfoVo> appPersonnelInfoVos = appPersonnelInfoMapper.selectVoList(qw);
// unitName,position,name,id
byte[] unitName = generateFixedBitmapData(bo.getUnitName(), 120);
byte[] position = generateFixedBitmapData(bo.getPosition(), 120);
byte[] name = generateFixedBitmapData(bo.getName(), 120);
byte[] id = generateFixedBitmapData(bo.getCode(), 120);
ArrayList<Integer> intData = new ArrayList<>();
intData.add(2);
buildArr(convertHexToDecimal(unitName), intData);
buildArr(convertHexToDecimal(position), intData);
buildArr(convertHexToDecimal(name), intData);
buildArr(convertHexToDecimal(id), intData);
intData.add(0);
intData.add(0);
intData.add(0);
intData.add(0);
Map<String, Object> map = new HashMap<>();
map.put("instruct", intData);
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + deviceObj.getDeviceImei(), 1, JSON.toJSONString(map));
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + deviceObj.getDeviceImei(), bo);
byte[] unitName = ReliableTextToBitmap.textToBitmapBytes(bo.getUnitName());
byte[] position = ReliableTextToBitmap.textToBitmapBytes(bo.getPosition());
byte[] name = ReliableTextToBitmap.textToBitmapBytes(bo.getName());
byte[] id = ReliableTextToBitmap.textToBitmapBytes(bo.getCode());
Map<String,Object> linkHashMap = new HashMap<>();
linkHashMap.put("unitName",unitName);
linkHashMap.put("position",position);
linkHashMap.put("name",name);
linkHashMap.put("id",id);
String personnelInfo = JSON.toJSONString(linkHashMap);
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY+deviceObj.getDeviceImei(), 1 ,personnelInfo);
log.info("发送点阵数据到设备消息:{}", bo);
if (ObjectUtils.length(appPersonnelInfoVos) == 0) {
AppPersonnelInfo appPersonnelInfo = MapstructUtils.convert(bo, AppPersonnelInfo.class);
@ -373,9 +304,9 @@ public class AppDeviceBizService {
System.out.println("原始数据大小: " + largeData.length + " 字节");
int[] ints = convertHexToDecimal(largeData);
RedisUtils.setCacheObject("app_logo_data:" + device.getDeviceImei(), Arrays.toString(ints), Duration.ofSeconds(30 * 60L));
RedisUtils.setCacheObject(GLOBAL_REDIS_KEY+"app_logo_data:" + device.getDeviceImei(), Arrays.toString(ints), Duration.ofSeconds(30 * 60L));
String data = RedisUtils.getCacheObject("app_logo_data:" + device.getDeviceImei());
String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+"app_logo_data:" + device.getDeviceImei());
byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data);
byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, 0, 512);
@ -410,7 +341,7 @@ public class AppDeviceBizService {
if(device == null){
throw new ServiceException("设备不存在");
}
Integer instructValue = (Integer) params.getInstructValue();
Integer instructValue = Integer.parseInt(params.getInstructValue());
ArrayList<Integer> intData = new ArrayList<>();
intData.add(1);
intData.add(instructValue);
@ -434,7 +365,7 @@ public class AppDeviceBizService {
if(device == null){
throw new ServiceException("设备不存在");
}
String instructValue = (String)params.getInstructValue();
String instructValue = params.getInstructValue();
ArrayList<Integer> intData = new ArrayList<>();
intData.add(5);
String[] values = instructValue.split("\\.");
@ -466,7 +397,7 @@ public class AppDeviceBizService {
if(device == null){
throw new ServiceException("设备不存在");
}
Integer instructValue = (Integer) params.getInstructValue();
Integer instructValue = Integer.parseInt(params.getInstructValue());
ArrayList<Integer> intData = new ArrayList<>();
intData.add(4);
intData.add(instructValue);
@ -493,4 +424,5 @@ public class AppDeviceBizService {
}
return RedisUtils.getCacheObject("device:location:" + devices.get(0).getDeviceImei());
}
}

View File

@ -2,14 +2,11 @@ package com.fuyuanshen.app.service;
import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.fuyuanshen.app.domain.vo.AppRoleVo;
import com.fuyuanshen.app.domain.vo.AppUserVo;
import com.fuyuanshen.common.core.constant.Constants;
import com.fuyuanshen.common.core.constant.SystemConstants;
import com.fuyuanshen.common.core.constant.TenantConstants;
import com.fuyuanshen.common.core.domain.dto.RoleDTO;
import com.fuyuanshen.common.core.domain.model.AppLoginUser;
import com.fuyuanshen.common.core.enums.LoginType;
import com.fuyuanshen.common.core.exception.user.UserException;
@ -51,7 +48,7 @@ public class AppLoginService {
private Integer lockTime;
private final ISysTenantService tenantService;
private final IAppRoleService roleService;
private final IAppUserService appUserService;
/**
@ -184,5 +181,24 @@ public class AppLoginService {
throw new TenantException("tenant.expired");
}
}
public void cancelAccount() {
try {
AppLoginUser loginUser = AppLoginHelper.getLoginUser();
if (ObjectUtil.isNull(loginUser)) {
return;
}
appUserService.deleteWithValidByIds(Collections.singletonList(loginUser.getUserId()),true);
if (TenantHelper.isEnable() && LoginHelper.isSuperAdmin()) {
// 超级管理员 登出清除动态租户
TenantHelper.clearDynamic();
}
recordLogininfor(loginUser.getTenantId(), loginUser.getUsername(), Constants.LOGOUT, "用户注销成功");
} catch (NotLoginException ignored) {
} finally {
try {
StpUtil.logout();
} catch (NotLoginException ignored) {
}
}
}
}

View File

@ -0,0 +1,61 @@
package com.fuyuanshen.web.config;
import cn.hutool.core.lang.UUID;
import com.fuyuanshen.global.mqtt.config.MqttPropertiesConfig;
import com.fuyuanshen.web.handler.mqtt.DeviceReceiverMessageHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.core.MessageProducer;
import org.springframework.integration.mqtt.core.MqttPahoClientFactory;
import org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter;
import org.springframework.integration.mqtt.support.DefaultPahoMessageConverter;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageHandler;
/**
* @author: 默苍璃
* @date: 2025-08-0110:46
*/
@Configuration
public class CustomMqttInboundConfiguration {
@Autowired
private MqttPropertiesConfig mqttPropertiesConfig;
@Autowired
private MqttPahoClientFactory mqttPahoClientFactory;
@Autowired
private DeviceReceiverMessageHandler deviceReceiverMessageHandler;
@Bean
public MessageChannel customMqttChannel(){
return new DirectChannel();
}
@Bean
public MessageProducer customMessageProducer(){
String clientId = "custom_client_" + UUID.fastUUID();
MqttPahoMessageDrivenChannelAdapter adapter = new MqttPahoMessageDrivenChannelAdapter(
mqttPropertiesConfig.getUrl(),
clientId,
mqttPahoClientFactory,
"A/#", "B/#" // 直接指定这两个主题
);
adapter.setQos(1);
adapter.setConverter(new DefaultPahoMessageConverter());
adapter.setOutputChannel(customMqttChannel());
return adapter;
}
@Bean
@ServiceActivator(inputChannel = "customMqttChannel")
public MessageHandler customMessageHandler(){
return deviceReceiverMessageHandler;
}
}

View File

@ -63,11 +63,10 @@ public class CaptchaController {
String code = RandomUtil.randomNumbers(4);
RedisUtils.setCacheObject(key, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION));
// 验证码模板id 自行处理 (查数据库或写死均可)
String templateId = "SMS_322180518";
String templateId = "";
LinkedHashMap<String, String> map = new LinkedHashMap<>(1);
map.put("code", code);
SmsBlend smsBlend = SmsFactory.getSmsBlend("config1");
// SmsResponse smsResponse = smsBlend.sendMessage(phonenumber, templateId, map);
SmsResponse smsResponse = smsBlend.sendMessage(phonenumber, map);
if (!smsResponse.isSuccess()) {
log.error("验证码短信发送异常 => {}", smsResponse);

View File

@ -0,0 +1,50 @@
package com.fuyuanshen.web.enums;
/**
* @author: 默苍璃
* @date: 2025-08-0114:14
*/
public enum InstructType6170 {
EQUIPMENT_REPORTING(0, "设备启动"),
LIGHT_MODE(1, "灯光模式"),
/**
* 设备信息
* 单位/姓名/职位
*/
UNIT_INFO(2, "设备信息"),
BOOT_IMAGE(3, "开机图片"),
LASER_LIGHT(4, "激光灯"),
BRIGHTNESS(5, "亮度调节"),
LOCATION_DATA(11, "定位数据"),
UNKNOWN(-1, "未知操作");
private final int code;
private final String description;
InstructType6170(int code, String description) {
this.code = code;
this.description = description;
}
public int getCode() {
return code;
}
public String getDescription() {
return description;
}
public static InstructType6170 fromCode(int code) {
for (InstructType6170 type : values()) {
if (type.getCode() == code) {
return type;
}
}
// throw new IllegalArgumentException("未知的指令类型代码: " + code);
return UNKNOWN;
}
}

View File

@ -0,0 +1,264 @@
package com.fuyuanshen.web.handler.mqtt;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fuyuanshen.equipment.domain.Device;
import com.fuyuanshen.equipment.domain.DeviceLog;
import com.fuyuanshen.equipment.mapper.DeviceLogMapper;
import com.fuyuanshen.equipment.mapper.DeviceMapper;
import com.fuyuanshen.equipment.utils.map.GetAddressFromLatUtil;
import com.fuyuanshen.equipment.utils.map.LngLonUtil;
import com.fuyuanshen.web.enums.InstructType6170;
import com.fuyuanshen.web.enums.LightModeEnum6170;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.MessagingException;
import org.springframework.stereotype.Component;
/**
* 定义监听主题消息的处理器
*
* @author: 默苍璃
* @date: 2025-08-0110:19
*/
@Component
@Data
@AllArgsConstructor
@Slf4j
public class DeviceReceiverMessageHandler implements MessageHandler {
private final DeviceMapper deviceMapper;
private final DeviceLogMapper deviceLogMapper;
// 使用Jackson解析JSON
private static final ObjectMapper objectMapper = new ObjectMapper();
/**
* 处理接收的消息
*
* @param message
* @throws MessagingException
*/
@Override
public void handleMessage(Message<?> message) throws MessagingException {
// System.out.println("接收到的消息:" + message.getPayload());
MessageHeaders headers = message.getHeaders();
String receivedTopicName = (String) headers.get("mqtt_receivedTopic");
System.out.println("消息来自主题:" + receivedTopicName);
String payload = message.getPayload().toString();
if (receivedTopicName != null) {
// 1. 提取设备ID (从主题中获取)
String deviceImei = extractDeviceId(receivedTopicName);
Device device = deviceMapper.selectOne(new QueryWrapper<Device>().eq("device_imei", deviceImei));
if (device == null) {
log.info("不存在的设备IMEI: {}", deviceImei);
} else {
try {
JsonNode root = objectMapper.readTree(payload);
DeviceLog record = new DeviceLog();
// 手动设置租户ID
record.setTenantId(device.getTenantId()); // 从设备信息中获取租户ID
// 设备ID
record.setDeviceId(device.getId());
// 设备名称
record.setDeviceName(device.getDeviceName());
// 2. 处理instruct消息
if (root.has("instruct")) {
JsonNode instructNode = root.get("instruct");
if (instructNode.isArray()) {
boolean b = receivedTopicName.startsWith("B/");
record = parseInstruct(device, instructNode, b);
// 根据不同主题进行不同处理
if (receivedTopicName.startsWith("A/")) {
// 处理A主题的消息设备上传
record.setDataSource("设备上报");
} else if (receivedTopicName.startsWith("B/")) {
// 处理B主题的消息 (手动上传)
record.setDataSource("客户端操作");
}
}
deviceLogMapper.insert(record);
}
if (root.has("imei")) {
// 设备行为
record.setDeviceAction(InstructType6170.fromCode(0).getDescription());
record.setDataSource("设备上报");
record.setContent("设备启动");
deviceLogMapper.insert(record);
}
// 3. 处理state消息
// else if (root.has("state")) {
// JsonNode stateNode = root.get("state");
// if (stateNode.isArray()) {
// StateRecord record = parseState(device, stateNode);
// stateRepo.save(record);
// }
// }
} catch (Exception e) {
log.error("消息解析失败: {}", payload, e);
}
}
}
}
/**
* 从主题中提取设备ID(IMEI)
*
* @param topic
* @return
*/
private String extractDeviceId(String topic) {
// 处理 A/# 或 B/# 格式的主题,例如 B/861556078765285 或 A/861556078765285
String[] segments = topic.split("/");
if (segments.length >= 2) {
// 返回第二个段,即 / 后面的部分
return segments[1];
}
// 如果格式不符合预期,返回原主题
return topic;
}
/**
* 解析instruct消息
*
* @param device
* @param array
* @param b
* @return
*/
private DeviceLog parseInstruct(Device device, JsonNode array, boolean b) {
DeviceLog record = new DeviceLog();
record.setDeviceName(device.getDeviceName());
// 设备行为
record.setDeviceAction(InstructType6170.fromCode(array.get(0).asInt()).getDescription());
switch (array.get(0).asInt()) {
case 1: // 灯光模式
LightModeEnum6170 lightModeEnum6170 = LightModeEnum6170.fromCode(array.get(1).asInt());
record.setContent(lightModeEnum6170.getDescription());
break;
case 2: // 单位/姓名/职位
byte[] unitBytes = new byte[480];
for (int i = 1; i <= 480; i++) {
unitBytes[i - 1] = (byte) array.get(i).asInt();
}
// record.setUnitData(unitBytes);
break;
case 3: // 开机图片
// record.setImagePage(array.get(1).asInt());
byte[] imageBytes = new byte[512];
for (int i = 2; i <= 513; i++) {
imageBytes[i - 2] = (byte) array.get(i).asInt();
}
// record.setImageData(imageBytes);
break;
case 4: // 激光灯
int anInt = array.get(1).asInt();
if (anInt == 0) {
record.setContent("关闭激光灯");
} else if (anInt == 1) {
record.setContent("开启激光灯");
} else {
record.setContent("未知操作");
}
break;
case 5: // 亮度调节
record.setContent(+array.get(1).asInt() + "%");
break;
case 11: // 定位数据
if (b) {
break;
}
int i1 = array.get(1).asInt();
int i2 = array.get(2).asInt();
int i3 = array.get(3).asInt();
int i4 = array.get(4).asInt();
// 优雅的转换方式 Longitude and latitude
double latitude = i1 + i2 / 10.0;
double Longitude = i3 + i4 / 10.0;
// 84 ==》 高德
double[] doubles = LngLonUtil.gps84_To_Gcj02(latitude, Longitude);
String address = GetAddressFromLatUtil.getAdd(String.valueOf(doubles[1]), String.valueOf(doubles[0]));
record.setContent(address);
break;
}
return record;
}
/**
* 解析state消息
*
* @param device
* @param array
* @return
*/
// private StateRecord parseState(Device device, JsonNode array) {
// StateRecord record = new StateRecord();
// record.setDevice(device);
// record.setStateType(array.get(0).asInt());
//
// switch (record.getStateType()) {
// case 1: // 灯光状态
// record.setLightMode(array.get(1).asInt());
// record.setBrightness(array.get(2).asInt());
// break;
//
// case 2: // 设置结果
// record.setSetResult(array.get(1).asInt() == 1);
// break;
//
// case 3: // 图片更新状态
// record.setImagePage(array.get(1).asInt());
// break;
//
// case 4: // 激光灯状态
// record.setLaserStatus(array.get(1).asInt() == 1);
// break;
//
// case 5: // 亮度状态
// record.setBrightness(array.get(1).asInt());
// break;
//
// case 11: // 定位上报
// record.setLatitude(array.get(1).asDouble());
// record.setLongitude(array.get(2).asDouble());
// break;
//
// case 12: // 设备状态
// record.setMainLightGear(array.get(1).asInt());
// record.setLaserLightGear(array.get(2).asInt());
// record.setBattery(array.get(3).asInt());
// record.setChargeStatus(array.get(4).asInt());
// record.setDuration(array.get(5).asInt());
// break;
// }
// return record;
// }
}

View File

@ -0,0 +1,131 @@
package com.fuyuanshen.web.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fuyuanshen.app.domain.AppUser;
import com.fuyuanshen.app.domain.vo.AppUserVo;
import com.fuyuanshen.app.mapper.AppUserMapper;
import com.fuyuanshen.common.core.constant.Constants;
import com.fuyuanshen.common.core.constant.GlobalConstants;
import com.fuyuanshen.common.core.domain.model.AppSmsRegisterBody;
import com.fuyuanshen.common.core.enums.UserType;
import com.fuyuanshen.common.core.exception.BadRequestException;
import com.fuyuanshen.common.core.exception.user.CaptchaException;
import com.fuyuanshen.common.core.exception.user.CaptchaExpireException;
import com.fuyuanshen.common.core.exception.user.UserException;
import com.fuyuanshen.common.core.utils.MessageUtils;
import com.fuyuanshen.common.core.utils.ServletUtils;
import com.fuyuanshen.common.core.utils.SpringUtils;
import com.fuyuanshen.common.core.utils.StringUtils;
import com.fuyuanshen.common.log.event.LogininforEvent;
import com.fuyuanshen.common.redis.utils.RedisUtils;
import com.fuyuanshen.common.tenant.helper.TenantHelper;
import com.fuyuanshen.common.web.config.properties.CaptchaProperties;
import com.fuyuanshen.system.mapper.SysUserMapper;
import com.fuyuanshen.system.service.ISysUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.Date;
/**
* 注册校验方法
*
* @author Lion Li
*/
@RequiredArgsConstructor
@Service
public class AppRegisterService {
private final ISysUserService userService;
private final SysUserMapper userMapper;
private final CaptchaProperties captchaProperties;
private final AppUserMapper appUserMapper;
/**
* 注册
*/
public void register(AppSmsRegisterBody registerBody) {
String phoneNumber = registerBody.getPhoneNumber();
LambdaQueryWrapper<AppUser> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(AppUser::getPhonenumber, phoneNumber);
wrapper.eq(AppUser::getUserType, UserType.APP_USER.getUserType());
AppUserVo appUserVo = appUserMapper.selectVoOne(wrapper);
if (appUserVo != null) {
throw new BadRequestException("该手机号已被注册");
}
String verificationCode = RedisUtils.getCacheObject(GlobalConstants.CAPTCHA_CODE_KEY + phoneNumber);
if (verificationCode == null) {
throw new BadRequestException("验证码已过期");
}
if(!registerBody.getVerificationCode().equals(verificationCode)){
throw new BadRequestException("验证码错误");
}
String tenantId = registerBody.getTenantId();
String username = registerBody.getPhoneNumber();
String password = registerBody.getPassword();
AppUser appUser = new AppUser();
appUser.setUserName(username);
appUser.setNickName(username);
appUser.setPhonenumber(phoneNumber);
appUser.setPassword(password);
appUser.setUserType(UserType.APP_USER.getUserType());
appUser.setTenantId(tenantId);
appUser.setLoginIp(ServletUtils.getClientIP());
appUser.setStatus("0");
appUser.setDelFlag("0");
appUser.setCreateTime(new Date());
boolean exist = TenantHelper.dynamic(tenantId, () -> {
return appUserMapper.exists(new LambdaQueryWrapper<AppUser>()
.eq(AppUser::getUserName, appUser.getUserName()));
});
if (exist) {
throw new UserException("user.register.save.error", username);
}
appUserMapper.insert(appUser);
recordLogininfor(tenantId, username, Constants.REGISTER, MessageUtils.message("user.register.success"));
}
/**
* 校验验证码
*
* @param username 用户名
* @param code 验证码
* @param uuid 唯一标识
*/
public void validateCaptcha(String tenantId, String username, String code, String uuid) {
String verifyKey = GlobalConstants.CAPTCHA_CODE_KEY + StringUtils.blankToDefault(uuid, "");
String captcha = RedisUtils.getCacheObject(verifyKey);
RedisUtils.deleteObject(verifyKey);
if (captcha == null) {
recordLogininfor(tenantId, username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"));
throw new CaptchaExpireException();
}
if (!code.equalsIgnoreCase(captcha)) {
recordLogininfor(tenantId, username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error"));
throw new CaptchaException();
}
}
/**
* 记录登录信息
*
* @param tenantId 租户ID
* @param username 用户名
* @param status 状态
* @param message 消息内容
* @return
*/
private void recordLogininfor(String tenantId, String username, String status, String message) {
LogininforEvent logininforEvent = new LogininforEvent();
logininforEvent.setTenantId(tenantId);
logininforEvent.setUsername(username);
logininforEvent.setStatus(status);
logininforEvent.setMessage(message);
logininforEvent.setRequest(ServletUtils.getRequest());
SpringUtils.context().publishEvent(logininforEvent);
}
}

View File

@ -0,0 +1,125 @@
package com.fuyuanshen.web.service.impl;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.stp.parameter.SaLoginParameter;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fuyuanshen.app.domain.AppUser;
import com.fuyuanshen.app.domain.vo.AppUserVo;
import com.fuyuanshen.app.mapper.AppUserMapper;
import com.fuyuanshen.app.service.AppLoginService;
import com.fuyuanshen.common.core.constant.Constants;
import com.fuyuanshen.common.core.constant.GlobalConstants;
import com.fuyuanshen.common.core.constant.SystemConstants;
import com.fuyuanshen.common.core.domain.model.AppLoginUser;
import com.fuyuanshen.common.core.domain.model.PasswordLoginBody;
import com.fuyuanshen.common.core.enums.LoginType;
import com.fuyuanshen.common.core.enums.UserType;
import com.fuyuanshen.common.core.exception.user.CaptchaException;
import com.fuyuanshen.common.core.exception.user.CaptchaExpireException;
import com.fuyuanshen.common.core.exception.user.UserException;
import com.fuyuanshen.common.core.utils.MessageUtils;
import com.fuyuanshen.common.core.utils.StringUtils;
import com.fuyuanshen.common.core.utils.ValidatorUtils;
import com.fuyuanshen.common.json.utils.JsonUtils;
import com.fuyuanshen.common.redis.utils.RedisUtils;
import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
import com.fuyuanshen.common.satoken.utils.LoginHelper;
import com.fuyuanshen.common.tenant.helper.TenantHelper;
import com.fuyuanshen.common.web.config.properties.CaptchaProperties;
import com.fuyuanshen.system.domain.vo.SysClientVo;
import com.fuyuanshen.web.domain.vo.LoginVo;
import com.fuyuanshen.web.service.IAuthStrategy;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* 密码认证策略
*
* @author Michelle.Chung
*/
@Slf4j
@Service("appPassword" + IAuthStrategy.BASE_NAME)
@RequiredArgsConstructor
public class AppPasswordAuthStrategy implements IAuthStrategy {
private final CaptchaProperties captchaProperties;
private final AppLoginService loginService;
private final AppUserMapper appUserMapper;
@Override
public LoginVo login(String body, SysClientVo client) {
PasswordLoginBody loginBody = JsonUtils.parseObject(body, PasswordLoginBody.class);
ValidatorUtils.validate(loginBody);
String tenantId = loginBody.getTenantId();
String username = loginBody.getUsername();
String password = loginBody.getPassword();
String code = loginBody.getCode();
String uuid = loginBody.getUuid();
// boolean captchaEnabled = captchaProperties.getEnable();
// // 验证码开关
// if (captchaEnabled) {
// validateCaptcha(tenantId, username, code, uuid);
// }
AppLoginUser loginUser = TenantHelper.dynamic(tenantId, () -> {
AppUserVo user = loadUserByUsername(username);
loginService.checkLogin(LoginType.PASSWORD, tenantId, username, () -> !password.equals(user.getPassword()));
// 此处可根据登录用户的数据不同 自行创建 loginUser
return loginService.buildLoginUser(user);
});
loginUser.setClientKey(client.getClientKey());
loginUser.setDeviceType(client.getDeviceType());
SaLoginParameter model = new SaLoginParameter();
model.setDeviceType(client.getDeviceType());
// 自定义分配 不同用户体系 不同 token 授权时间 不设置默认走全局 yml 配置
// 例如: 后台用户30分钟过期 app用户1天过期
model.setTimeout(client.getTimeout());
model.setActiveTimeout(client.getActiveTimeout());
model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId());
// 生成token
AppLoginHelper.login(loginUser, model);
LoginVo loginVo = new LoginVo();
loginVo.setAccessToken(StpUtil.getTokenValue());
loginVo.setExpireIn(StpUtil.getTokenTimeout());
loginVo.setClientId(client.getClientId());
return loginVo;
}
/**
* 校验验证码
*
* @param username 用户名
* @param code 验证码
* @param uuid 唯一标识
*/
private void validateCaptcha(String tenantId, String username, String code, String uuid) {
String verifyKey = GlobalConstants.CAPTCHA_CODE_KEY + StringUtils.blankToDefault(uuid, "");
String captcha = RedisUtils.getCacheObject(verifyKey);
RedisUtils.deleteObject(verifyKey);
if (captcha == null) {
loginService.recordLogininfor(tenantId, username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"));
throw new CaptchaExpireException();
}
if (!code.equalsIgnoreCase(captcha)) {
loginService.recordLogininfor(tenantId, username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error"));
throw new CaptchaException();
}
}
private AppUserVo loadUserByUsername(String username) {
AppUserVo user = appUserMapper.selectVoOne(new LambdaQueryWrapper<AppUser>()
.eq(AppUser::getUserName, username)
.eq(AppUser::getUserType, UserType.APP_USER.getUserType()));
if (ObjectUtil.isNull(user)) {
log.info("登录用户:{} 不存在.", username);
throw new UserException("user.not.exists", username);
} else if (SystemConstants.DISABLE.equals(user.getStatus())) {
log.info("登录用户:{} 已被停用.", username);
throw new UserException("user.blocked", username);
}
return user;
}
}

View File

@ -49,9 +49,9 @@ spring:
driverClassName: com.mysql.cj.jdbc.Driver
# jdbc 所有参数配置参考 https://lionli.blog.csdn.net/article/details/122018562
# rewriteBatchedStatements=true 批处理优化 大幅提升批量插入更新删除性能(对数据库有性能损耗 使用批量操作应考虑性能问题)
url: jdbc:mysql://47.120.79.150:3306/fys-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
url: jdbc:mysql://120.79.224.186:3366/fys-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
username: root
password: Jq_123456#
password: 1fys@QWER..
# # 从库数据源
# slave:
# lazy: true
@ -98,13 +98,13 @@ spring:
spring.data:
redis:
# 地址
host: 47.120.79.150
host: 120.79.224.186
# 端口默认为6379
port: 6379
port: 26379
# 数据库索引
database: 2
# redis 密码必须配置
password: xhYc_djkl382^#780!
password: 1fys@QWER..
# 连接超时时间
timeout: 10s
# 是否开启ssl
@ -300,8 +300,8 @@ file:
# MQTT配置
mqtt:
username: admin
password: #YtvpSfCNG
url: tcp://47.120.79.150:2883
password: fys123456
url: tcp://47.107.152.87:1883
subClientId: fys_subClient
subTopic: A/#,worker/location/#
pubTopic: B/#

View File

@ -4,7 +4,7 @@ spring.servlet.multipart.location: /fys/server/temp
--- # 监控中心配置
spring.boot.admin.client:
# 增加客户端开关
enabled: true
enabled: false
url: http://localhost:9090/admin
instance:
service-host-type: IP
@ -16,7 +16,7 @@ spring.boot.admin.client:
--- # snail-job 配置
snail-job:
enabled: true
enabled: false
# 需要在 SnailJob 后台组管理创建对应名称的组,然后创建任务的时候选择对应的组,才能正确分派任务
group: "fys_group"
# SnailJob 接入验证令牌 详见 script/sql/ry_job.sql `sj_group_config`表
@ -177,11 +177,14 @@ sms:
# 框架定义的厂商名称标识,标定此配置是哪个厂商,详细请看厂商标识介绍部分
supplier: alibaba
# 有些称为accessKey有些称之为apiKey也有称为sdkKey或者appId。
access-key-id: 您的accessKey
access-key-id: LTAI5tJdDNpZootsPQ5hdELx
# 称为accessSecret有些称之为apiSecret
access-key-secret: 您的accessKeySecret
signature: 您的短信签名
sdk-app-id: 您的sdkAppId
access-key-secret: mU4WtffcCXpHPz5tLwQpaGtLsJXONt
#模板ID 非必须配置如果使用sendMessage的快速发送需此配置
template-id: SMS_322180518
#模板变量 上述模板的变量
templateName: code
signature: 湖北星汉研创科技
config2:
# 厂商标识,标定此配置是哪个厂商,详细请看厂商标识介绍部分
supplier: tencent
@ -277,11 +280,11 @@ justauth:
# MQTT配置
mqtt:
username: admin
password: #YtvpSfCNG
url: tcp://47.120.79.150:2883
password: fys123456
url: tcp://47.107.152.87:1883
subClientId: fys_subClient
subTopic: worker/alert/#,worker/location/#
pubTopic: worker/location
subTopic: A/#,worker/location/#
pubTopic: B/#
pubClientId: fys_pubClient

View File

@ -1,7 +1,7 @@
# 开发环境配置
server:
# 服务器的HTTP端口默认为8080
port: 8000
port: 8001
servlet:
# 应用的访问路径
context-path: /

View File

@ -22,6 +22,11 @@ public interface GlobalConstants {
*/
String DEVICE_SHARE_CODES_KEY = GLOBAL_REDIS_KEY + "device_share_codes:";
/**
* 验证码 redis key
*/
String APP_FORGOT_PASSWORD_SMS_KEY = GLOBAL_REDIS_KEY + "app_sms_forgotPassword:";
/**
* 防重提交 redis key
*/

View File

@ -0,0 +1,22 @@
package com.fuyuanshen.common.core.domain.model;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
@Data
public class AppLoginBody {
/**
* 手机号不能为空
*/
@NotBlank(message = "手机号不能为空")
private String userName;
/**
* 密码不能为空
*/
@NotBlank(message = "密码不能为空")
private String password;
private String tenantId;
}

View File

@ -0,0 +1,22 @@
package com.fuyuanshen.common.core.domain.model;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
@Data
public class AppSmsRegisterBody {
@NotBlank(message = "手机号不能为空")
private String phoneNumber;
@NotBlank(message = "密码不能为空")
private String password;
@NotBlank(message = "验证码不能为空")
private String verificationCode;
/**
* 租户ID
*/
private String tenantId;
}

View File

@ -18,14 +18,14 @@ public class PasswordLoginBody extends LoginBody {
* 用户名
*/
@NotBlank(message = "{user.username.not.blank}")
@Length(min = 2, max = 30, message = "{user.username.length.valid}")
// @Length(min = 2, max = 30, message = "{user.username.length.valid}")
private String username;
/**
* 用户密码
*/
@NotBlank(message = "{user.password.not.blank}")
@Length(min = 5, max = 30, message = "{user.password.length.valid}")
// @Length(min = 5, max = 30, message = "{user.password.length.valid}")
private String password;
}

View File

@ -1,14 +1,13 @@
package com.fuyuanshen.app.domain;
import com.baomidou.mybatisplus.annotation.*;
import com.fuyuanshen.common.mybatis.core.domain.BaseEntity;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fuyuanshen.common.tenant.core.TenantEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.io.Serial;
import java.util.Date;
/**
* 设备绑定关系对象 app_device_bind_record

View File

@ -1,13 +1,14 @@
package com.fuyuanshen.app.domain;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fuyuanshen.common.tenant.core.TenantEntity;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.io.Serial;
import java.util.Date;
/**
* APP用户信息对象 app_user
@ -95,5 +96,9 @@ public class AppUser extends TenantEntity {
*/
private String remark;
/**
* 地区
*/
private String region;
}

View File

@ -0,0 +1,19 @@
package com.fuyuanshen.app.domain.dto;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
@Data
public class APPForgotPasswordDTO {
@NotBlank(message = "手机号不能为空")
private String phoneNumber;
@NotBlank(message = "密码不能为空")
private String password;
@NotBlank(message = "验证码不能为空")
private String verificationCode;
}

View File

@ -0,0 +1,12 @@
package com.fuyuanshen.app.domain.dto;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
@Data
public class APPForgotPasswordSmsDTO {
@NotBlank(message = "手机号不能为空")
private String phoneNumber;
}

View File

@ -1,8 +1,6 @@
package com.fuyuanshen.app.domain.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;

View File

@ -0,0 +1,33 @@
package com.fuyuanshen.app.domain.dto;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;
/**
* @author: 默苍璃
* @date: 2025-06-1818:36
*/
@Data
public class APPUpdateUserDTO {
/**
* 用户昵称
*/
private String nickName;
/**
* 用户地区
*/
private String region;
/**
* 用户性别
*/
private String gender;
/**
* 用户头像
*/
private MultipartFile file;
}

View File

@ -0,0 +1,39 @@
package com.fuyuanshen.app.domain.vo;
import lombok.Data;
@Data
public class APPUserInfoVo {
/**
* 用户ID
*/
private Long id;
/**
* 用户昵称
*/
private String nickName;
/**
* 性别
*/
private String gender;
/**
* 手机号码
*/
private String phone;
/**
* 头像地址
*/
private String avatarPath;
/**
* 地区
*/
private String region;
}

View File

@ -23,4 +23,8 @@ public class AppFileVo {
* 文件url
*/
private String fileUrl;
/**
* 文件类型(1:操作说明2:产品参数)
*/
private Long fileType;
}

View File

@ -14,4 +14,5 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface AppUserMapper extends BaseMapperPlus<AppUser, AppUserVo> {
AppUser appFindByUsername(String phoneNumber);
}

View File

@ -1,9 +1,13 @@
package com.fuyuanshen.app.service;
import com.fuyuanshen.app.domain.vo.AppUserVo;
import com.fuyuanshen.app.domain.bo.AppUserBo;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
import com.fuyuanshen.app.domain.dto.APPForgotPasswordDTO;
import com.fuyuanshen.app.domain.dto.APPForgotPasswordSmsDTO;
import com.fuyuanshen.app.domain.dto.APPUpdateUserDTO;
import com.fuyuanshen.app.domain.vo.APPUserInfoVo;
import com.fuyuanshen.app.domain.vo.AppUserVo;
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
import java.util.Collection;
import java.util.List;
@ -65,4 +69,12 @@ public interface IAppUserService {
* @return 是否删除成功
*/
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
APPUserInfoVo getUserInfo();
int updateUser(APPUpdateUserDTO bo);
int forgotPassword(APPForgotPasswordDTO bo);
int sendForgotPasswordSms(APPForgotPasswordSmsDTO dto);
}

View File

@ -7,6 +7,7 @@ import com.fuyuanshen.common.mybatis.core.page.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@ -66,6 +67,8 @@ public class AppOperationVideoServiceImpl implements IAppOperationVideoService {
*/
@Override
public List<AppOperationVideoVo> queryList(AppOperationVideoBo bo) {
Long userId = AppLoginHelper.getUserId();
bo.setCreateBy(userId);
LambdaQueryWrapper<AppOperationVideo> lqw = buildQueryWrapper(bo);
return baseMapper.selectVoList(lqw);
}

View File

@ -1,24 +1,37 @@
package com.fuyuanshen.app.service.impl;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuyuanshen.app.domain.AppUser;
import com.fuyuanshen.app.domain.bo.AppUserBo;
import com.fuyuanshen.app.domain.dto.APPForgotPasswordDTO;
import com.fuyuanshen.app.domain.dto.APPForgotPasswordSmsDTO;
import com.fuyuanshen.app.domain.dto.APPUpdateUserDTO;
import com.fuyuanshen.app.domain.vo.APPUserInfoVo;
import com.fuyuanshen.app.domain.vo.AppUserVo;
import com.fuyuanshen.app.mapper.AppUserMapper;
import com.fuyuanshen.app.service.IAppUserService;
import com.fuyuanshen.common.core.constant.GlobalConstants;
import com.fuyuanshen.common.core.domain.model.AppLoginUser;
import com.fuyuanshen.common.core.exception.BadRequestException;
import com.fuyuanshen.common.core.utils.MapstructUtils;
import com.fuyuanshen.common.core.utils.StringUtils;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
import com.fuyuanshen.common.redis.utils.RedisUtils;
import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
import com.fuyuanshen.system.domain.vo.SysOssVo;
import com.fuyuanshen.system.service.ISysOssService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import com.fuyuanshen.app.domain.bo.AppUserBo;
import com.fuyuanshen.app.domain.vo.AppUserVo;
import com.fuyuanshen.app.domain.AppUser;
import com.fuyuanshen.app.mapper.AppUserMapper;
import com.fuyuanshen.app.service.IAppUserService;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Collection;
/**
* Service业务层处理
@ -33,6 +46,8 @@ public class AppUserServiceImpl implements IAppUserService {
private final AppUserMapper baseMapper;
private final ISysOssService sysOssService;
/**
* 查询APP用户信息
*
@ -139,4 +154,75 @@ public class AppUserServiceImpl implements IAppUserService {
}
return baseMapper.deleteByIds(ids) > 0;
}
@Override
public APPUserInfoVo getUserInfo() {
String username = AppLoginHelper.getUsername();
QueryWrapper<AppUser> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("user_name", username);
List<AppUser> appUsers = baseMapper.selectList(queryWrapper);
if(appUsers.isEmpty()){
throw new BadRequestException("用户不存在");
}
AppUser user = appUsers.get(0);
// AppUserVo user = baseMapper.selectVoById(userId);
APPUserInfoVo appUserVo = new APPUserInfoVo();
appUserVo.setId(user.getUserId());
appUserVo.setNickName(user.getNickName());
appUserVo.setGender(user.getSex());
appUserVo.setPhone(user.getPhonenumber());
appUserVo.setRegion(user.getRegion());
if(user.getAvatar() != null){
SysOssVo oss = sysOssService.getById(user.getAvatar());
if(oss != null){
appUserVo.setAvatarPath(oss.getUrl());
}
}
return appUserVo;
}
@Override
public int updateUser(APPUpdateUserDTO bo) {
AppLoginUser appUser = AppLoginHelper.getLoginUser();
AppUserVo appUserVo = baseMapper.selectVoById(appUser.getUserId());
if(appUserVo == null){
throw new BadRequestException("用户不存在");
}
AppUser updUser= new AppUser();
updUser.setUserId(appUser.getUserId());
updUser.setNickName(bo.getNickName());
if(bo.getFile() != null){
SysOssVo oss = sysOssService.upload(bo.getFile());
updUser.setAvatar(oss.getOssId());
}
updUser.setRegion(bo.getRegion());
updUser.setSex(bo.getGender());
return baseMapper.update(updUser, new LambdaQueryWrapper<AppUser>().eq(AppUser::getUserId, appUser.getUserId()));
}
@Override
public int forgotPassword(APPForgotPasswordDTO bo) {
AppUser appUser = baseMapper.appFindByUsername(bo.getPhoneNumber());
if (appUser == null) {
throw new BadRequestException("手机号不存在");
}
String verificationCode = RedisUtils.getCacheObject(GlobalConstants.APP_FORGOT_PASSWORD_SMS_KEY + bo.getPhoneNumber());
if (verificationCode == null) {
throw new BadRequestException("验证码已过期");
}
if(!bo.getVerificationCode().equals(verificationCode)){
throw new BadRequestException("验证码错误");
}
appUser.setPassword(bo.getPassword());
baseMapper.updateById(appUser);
return 1;
}
@Override
public int sendForgotPasswordSms(APPForgotPasswordSmsDTO dto) {
return 1;
}
}

View File

@ -7,6 +7,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="queryAppFileList" resultType="com.fuyuanshen.app.domain.vo.AppFileVo">
select a.id,a.business_id,a.file_id,b.file_name,b.url fileUrl from app_business_file a left join sys_oss b on a.file_id = b.oss_id
where 1=1
<if test="createBy != null">
a.create_by = #{createBy}
</if>
<if test="businessId != null">
and a.business_id = #{businessId}
</if>

View File

@ -4,4 +4,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fuyuanshen.app.mapper.AppUserMapper">
<select id="appFindByUsername" resultType="com.fuyuanshen.app.domain.AppUser">
select * from app_user where user_name = #{phoneNumber}
</select>
</mapper>

View File

@ -8,6 +8,8 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import jakarta.validation.constraints.*;
import java.util.List;
/**
* 设备日志业务对象 device_log
*
@ -22,9 +24,14 @@ public class DeviceLogBo extends BaseEntity {
/**
* ID
*/
@NotNull(message = "ID不能为空", groups = { EditGroup.class })
@NotNull(message = "ID不能为空", groups = {EditGroup.class})
private Long id;
/**
* 设备编号
*/
private List<Long> deviceIds;
/**
* 设备行为
*/

View File

@ -1,11 +1,16 @@
package com.fuyuanshen.equipment.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fuyuanshen.common.core.utils.MapstructUtils;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fuyuanshen.common.satoken.utils.LoginHelper;
import com.fuyuanshen.equipment.domain.DeviceAssignments;
import com.fuyuanshen.equipment.mapper.DeviceAssignmentsMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
@ -19,6 +24,7 @@ import com.fuyuanshen.equipment.service.IDeviceLogService;
import java.util.List;
import java.util.Map;
import java.util.Collection;
import java.util.stream.Collectors;
/**
* 设备日志Service业务层处理
@ -33,6 +39,9 @@ public class DeviceLogServiceImpl implements IDeviceLogService {
private final DeviceLogMapper baseMapper;
private final DeviceAssignmentsMapper deviceAssignmentsMapper;
/**
* 查询设备日志
*
@ -40,7 +49,7 @@ public class DeviceLogServiceImpl implements IDeviceLogService {
* @return 设备日志
*/
@Override
public DeviceLogVo queryById(Long id){
public DeviceLogVo queryById(Long id) {
return baseMapper.selectVoById(id);
}
@ -53,6 +62,8 @@ public class DeviceLogServiceImpl implements IDeviceLogService {
*/
@Override
public TableDataInfo<DeviceLogVo> queryPageList(DeviceLogBo bo, PageQuery pageQuery) {
LambdaQueryWrapper<DeviceLog> lqw = buildQueryWrapper(bo);
Page<DeviceLogVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
return TableDataInfo.build(result);
@ -71,16 +82,27 @@ public class DeviceLogServiceImpl implements IDeviceLogService {
}
private LambdaQueryWrapper<DeviceLog> buildQueryWrapper(DeviceLogBo bo) {
Long userId = LoginHelper.getUserId();
List<DeviceAssignments> assignments = deviceAssignmentsMapper.selectList(new QueryWrapper<DeviceAssignments>().eq("assignee_id", userId));
List<Long> deviceIds = assignments.stream().map(DeviceAssignments::getDeviceId).collect(Collectors.toList());
if (deviceIds.isEmpty()) {
deviceIds.add(-1L);
}
bo.setDeviceIds(deviceIds);
Map<String, Object> params = bo.getParams();
LambdaQueryWrapper<DeviceLog> lqw = Wrappers.lambdaQuery();
lqw.orderByAsc(DeviceLog::getId);
lqw.eq(StringUtils.isNotBlank(bo.getDeviceAction()), DeviceLog::getDeviceAction, bo.getDeviceAction());
lqw.orderByDesc(DeviceLog::getCreateTime);
lqw.like(StringUtils.isNotBlank(bo.getDeviceAction()), DeviceLog::getDeviceAction, bo.getDeviceAction());
lqw.like(StringUtils.isNotBlank(bo.getDeviceName()), DeviceLog::getDeviceName, bo.getDeviceName());
lqw.eq(StringUtils.isNotBlank(bo.getDataSource()), DeviceLog::getDataSource, bo.getDataSource());
lqw.eq(StringUtils.isNotBlank(bo.getContent()), DeviceLog::getContent, bo.getContent());
lqw.like(StringUtils.isNotBlank(bo.getContent()), DeviceLog::getContent, bo.getContent());
lqw.in(CollectionUtil.isNotEmpty(bo.getDeviceIds()), DeviceLog::getDeviceId, bo.getDeviceIds());
return lqw;
}
/**
* 新增设备日志
*
@ -114,8 +136,8 @@ public class DeviceLogServiceImpl implements IDeviceLogService {
/**
* 保存前的数据校验
*/
private void validEntityBeforeSave(DeviceLog entity){
//TODO 做一些数据校验,如唯一约束
private void validEntityBeforeSave(DeviceLog entity) {
// TODO 做一些数据校验,如唯一约束
}
/**
@ -127,8 +149,8 @@ public class DeviceLogServiceImpl implements IDeviceLogService {
*/
@Override
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if(isValid){
//TODO 做一些业务上的校验,判断是否需要校验
if (isValid) {
// TODO 做一些业务上的校验,判断是否需要校验
}
return baseMapper.deleteByIds(ids) > 0;
}

View File

@ -107,6 +107,13 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
@Override
@Transactional(rollbackFor = Exception.class)
public void create(DeviceType resources) {
// 校验设备类型名称
List<DeviceType> typeName = deviceTypeMapper.selectList(new QueryWrapper<DeviceType>().eq("type_name", resources.getTypeName()));
if (CollectionUtil.isNotEmpty(typeName)) {
throw new RuntimeException("设备类型名称已存在,无法新增!!!");
}
LoginUser loginUser = LoginHelper.getLoginUser();
resources.setCustomerId(loginUser.getUserId());
resources.setOwnerCustomerId(loginUser.getUserId());
@ -141,11 +148,23 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
if (deviceType == null) {
throw new RuntimeException("设备类型不存在");
}
List<Device> devices = deviceMapper.selectList(new QueryWrapper<Device>()
.eq("device_type", deviceTypeGrants.getDeviceTypeId()));
if (CollectionUtil.isNotEmpty(devices)) {
throw new RuntimeException("该设备类型已绑定设备,无法修改!!!");
}
// 校验设备类型名称
DeviceType dt = deviceTypeMapper.selectOne(new QueryWrapper<DeviceType>().eq("type_name", resources.getTypeName()));
if (dt != null && !dt.getId().equals(deviceType.getId())) {
throw new RuntimeException("设备类型名称已存在,无法修改!!!");
}
if (!Objects.equals(deviceType.getCustomerId(), LoginHelper.getUserId())) {
throw new RuntimeException("无权修改该设备类型");
}
// if (deviceMapper.countByTypeId(resources.getId()) > 0)
// throw new RuntimeException("该设备类型已被使用,无法删除");
BeanUtil.copyProperties(resources, deviceType);
deviceTypeMapper.updateById(deviceType);
}

View File

@ -0,0 +1,204 @@
package com.fuyuanshen.equipment.utils.c;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.util.Arrays;
public class DotMatrixDisplaySimulator extends JFrame {
private static final int WIDTH = 160;
private static final int HEIGHT = 80;
private static final int SCALE = 4; // 显示缩放比例
private JComboBox<Integer> fontSizeCombo;
private JComboBox<String> exampleCombo;
private JTextArea textInput;
private DotMatrixPanel displayPanel;
private final String[] examples = {
"紧急通知:现场危险,请立即撤离!",
"警告:高温区域,禁止入内!",
"系统故障:请立即联系技术人员处理",
"安全提示:请佩戴防护装备进入作业区",
"欢迎使用点阵显示屏模拟系统",
"现场危险,停止救援,紧急撤离至安全区域!"
};
public DotMatrixDisplaySimulator() {
super("160x80点阵显示屏模拟器");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(800, 600);
setLayout(new BorderLayout());
// 创建控制面板
JPanel controlPanel = new JPanel(new GridLayout(1, 4, 10, 10));
controlPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
// 字体大小选择
controlPanel.add(new JLabel("字体大小:"));
fontSizeCombo = new JComboBox<>(new Integer[]{8, 10, 12, 14, 16, 18, 20, 24});
fontSizeCombo.setSelectedItem(14);
controlPanel.add(fontSizeCombo);
// 示例选择
controlPanel.add(new JLabel("示例文本:"));
exampleCombo = new JComboBox<>(examples);
exampleCombo.addActionListener(e -> textInput.setText(examples[exampleCombo.getSelectedIndex()]));
controlPanel.add(exampleCombo);
// 文本输入
textInput = new JTextArea(examples[0]);
textInput.setLineWrap(true);
textInput.setWrapStyleWord(true);
JScrollPane textScroll = new JScrollPane(textInput);
textScroll.setBorder(BorderFactory.createTitledBorder("输入文本"));
// 点阵显示面板
displayPanel = new DotMatrixPanel();
// 添加组件
add(controlPanel, BorderLayout.NORTH);
add(textScroll, BorderLayout.CENTER);
add(displayPanel, BorderLayout.SOUTH);
// 添加事件监听器
fontSizeCombo.addActionListener(e -> displayPanel.repaint());
textInput.getDocument().addDocumentListener(new javax.swing.event.DocumentListener() {
public void changedUpdate(javax.swing.event.DocumentEvent e) { update(); }
public void removeUpdate(javax.swing.event.DocumentEvent e) { update(); }
public void insertUpdate(javax.swing.event.DocumentEvent e) { update(); }
private void update() {
displayPanel.repaint();
}
});
setLocationRelativeTo(null);
}
class DotMatrixPanel extends JPanel {
private final int panelWidth = WIDTH * SCALE;
private final int panelHeight = HEIGHT * SCALE;
public DotMatrixPanel() {
setPreferredSize(new Dimension(panelWidth, panelHeight + 50));
setBorder(BorderFactory.createTitledBorder("点阵预览 (160x80)"));
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
// 绘制点阵背景
g.setColor(Color.WHITE);
g.fillRect(0, 0, panelWidth, panelHeight);
// 绘制网格
g.setColor(new Color(240, 240, 240));
for (int x = 0; x <= WIDTH; x++) {
int xPos = x * SCALE;
g.drawLine(xPos, 0, xPos, panelHeight);
}
for (int y = 0; y <= HEIGHT; y++) {
int yPos = y * SCALE;
g.drawLine(0, yPos, panelWidth, yPos);
}
// 绘制文本
String text = textInput.getText();
int fontSize = (Integer) fontSizeCombo.getSelectedItem();
Font font = new Font("黑体", Font.PLAIN, fontSize);
// 创建虚拟点阵图像
BufferedImage img = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_BYTE_BINARY);
Graphics2D imgG = img.createGraphics();
imgG.setColor(Color.WHITE);
imgG.fillRect(0, 0, WIDTH, HEIGHT);
imgG.setColor(Color.BLACK);
imgG.setFont(font);
imgG.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
// 绘制文本到虚拟点阵
FontMetrics metrics = imgG.getFontMetrics();
int lineHeight = metrics.getHeight();
int yPos = metrics.getAscent();
String[] lines = text.split("\n");
int maxLines = HEIGHT / lineHeight;
int actualLines = Math.min(lines.length, maxLines);
int totalChars = 0;
for (int i = 0; i < actualLines; i++) {
String line = lines[i];
int lineWidth = metrics.stringWidth(line);
int maxChars = WIDTH / metrics.stringWidth(""); // 估算每行字数
// 截断超过宽度的文本
if (lineWidth > WIDTH) {
while (metrics.stringWidth(line) > WIDTH) {
line = line.substring(0, line.length() - 1);
}
line += "...";
}
// 居中显示文本
int xPos = (WIDTH - metrics.stringWidth(line)) / 2;
imgG.drawString(line, xPos, yPos);
totalChars += line.length();
yPos += lineHeight;
if (yPos + lineHeight > HEIGHT) break;
}
imgG.dispose();
// 绘制到预览面板
for (int y = 0; y < HEIGHT; y++) {
for (int x = 0; x < WIDTH; x++) {
int rgb = img.getRGB(x, y) & 0xFFFFFF;
if (rgb != 0xFFFFFF) { // 黑色像素
g.setColor(Color.BLACK);
g.fillRect(x * SCALE, y * SCALE, SCALE, SCALE);
}
}
}
// 显示统计信息
g.setColor(Color.BLACK);
g.setFont(new Font("宋体", Font.PLAIN, 12));
String info = String.format("字体大小: %dpt | 显示行数: %d/%d | 显示字数: %d",
fontSize, actualLines, maxLines, totalChars);
g.drawString(info, 10, panelHeight + 20);
String capacity = String.format("容量分析: %d×80点阵可显示%d-%d个汉字%dpt字体",
WIDTH,
(int)(WIDTH*HEIGHT/(fontSize*fontSize*1.2)),
(int)(WIDTH*HEIGHT/(fontSize*fontSize*0.8)),
fontSize);
g.drawString(capacity, 10, panelHeight + 35);
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
DotMatrixDisplaySimulator frame = new DotMatrixDisplaySimulator();
frame.setVisible(true);
// 显示使用提示
String message = "<html><div style='text-align:center;'><b>160×80点阵显示屏文字容量分析</b><br><br>"
+ "• 使用上方下拉菜单选择字体大小和示例文本<br>"
+ "• 在文本区域输入自定义内容<br>"
+ "• 点阵预览区域实时显示效果<br><br>"
+ "<b>容量参考:</b><br>"
+ "8-9pt约20字/行 × 10行 = 200字<br>"
+ "10-11pt约16字/行 × 8行 = 128字<br>"
+ "12-13pt约13字/行 × 6行 = 78字<br>"
+ "14-15pt约11字/行 × 5行 = 55字<br>"
+ "16-18pt约9字/行 × 4行 = 36字<br>"
+ "20-24pt约7字/行 × 3行 = 21字</div></html>";
JOptionPane.showMessageDialog(frame, message, "使用说明", JOptionPane.INFORMATION_MESSAGE);
});
}
}

View File

@ -0,0 +1,185 @@
package com.fuyuanshen.equipment.utils.c;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class TextToDotMatrix {
public static void main(String[] args) {
String text = "现场危险,停止救援,\n紧急撤离至安全区域";
int width = 160; // 点阵宽度
int height = 80; // 点阵高度
try {
// 1. 创建点阵图片
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);
Graphics2D g = image.createGraphics();
// 设置背景为白色
g.setColor(Color.WHITE);
g.fillRect(0, 0, width, height);
// 设置字体并居中显示文本
g.setColor(Color.BLACK);
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
// 自动调整字体大小以适应区域
Font font = findBestFitFont(text, width, height, g);
g.setFont(font);
// 计算文本位置并绘制
drawCenteredText(g, text, width, height);
g.dispose();
// 2. 生成二进制数组
List<Byte> byteList = new ArrayList<>();
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x += 8) {
byte b = 0;
for (int bit = 0; bit < 8; bit++) {
int xPos = x + bit;
if (xPos < width) {
int rgb = image.getRGB(xPos, y) & 0xFFFFFF;
if (rgb != 0xFFFFFF) { // 黑色像素
b |= (1 << (7 - bit));
}
}
}
byteList.add(b);
}
}
// 转换为字节数组
byte[] dotMatrixData = new byte[byteList.size()];
for (int i = 0; i < byteList.size(); i++) {
dotMatrixData[i] = byteList.get(i);
}
// 3. 保存预览图片
ImageIO.write(image, "png", new File("warning_display.png"));
System.out.println("预览图片已生成: warning_display.png");
// 4. 打印点阵数据信息
System.out.println("\n点阵数据信息:");
System.out.println("尺寸: " + width + "x" + height + " 像素");
System.out.println("数据大小: " + dotMatrixData.length + " 字节");
System.out.println("每行字节数: " + (width / 8));
System.out.println("总行数: " + height);
// 5. 打印二进制数组(十六进制格式)
System.out.println("\n点阵数据字节数组 (HEX):");
System.out.print("byte[] dotMatrixData = {");
for (int i = 0; i < dotMatrixData.length; i++) {
System.out.printf("0x%02X", dotMatrixData[i] & 0xFF);
if (i < dotMatrixData.length - 1) System.out.print(", ");
if (i % 16 == 15) System.out.println();
}
System.out.println("};\n");
// 6. 打印点阵图预览
System.out.println("点阵图预览 (缩小版):");
printTextPreview(image);
} catch (IOException e) {
e.printStackTrace();
}
}
// 自动寻找最佳字体大小
private static Font findBestFitFont(String text, int width, int height, Graphics2D g) {
int fontSize = 20; // 初始字体大小
Font bestFont = null;
int bestHeight = 0;
while (fontSize > 8) {
Font font = new Font("黑体", Font.BOLD, fontSize);
g.setFont(font);
FontMetrics metrics = g.getFontMetrics();
// 计算文本所需高度
String[] lines = text.split("\n");
int textHeight = metrics.getHeight() * lines.length;
// 检查是否超出高度
if (textHeight < height * 0.8) {
bestFont = font;
bestHeight = textHeight;
break;
}
fontSize--;
}
// 如果没有找到合适字体,使用最小字体
if (bestFont == null) {
bestFont = new Font("黑体", Font.BOLD, 8);
}
System.out.println("使用字体: " + bestFont.getSize() + "pt");
return bestFont;
}
// 居中绘制文本
private static void drawCenteredText(Graphics g, String text, int width, int height) {
FontMetrics metrics = g.getFontMetrics();
String[] lines = text.split("\n");
// 计算总文本高度
int totalHeight = metrics.getHeight() * lines.length;
// 计算起始Y位置
int y = (height - totalHeight) / 2 + metrics.getAscent();
for (String line : lines) {
// 计算X位置使文本居中
int x = (width - metrics.stringWidth(line)) / 2;
g.drawString(line, x, y);
y += metrics.getHeight();
}
}
// 打印文本预览
private static void printTextPreview(BufferedImage image) {
int width = image.getWidth();
int height = image.getHeight();
// 缩小预览比例
int scale = 4;
int previewWidth = width / scale;
int previewHeight = height / scale;
for (int y = 0; y < previewHeight; y++) {
for (int x = 0; x < previewWidth; x++) {
int pixelCount = 0;
for (int dy = 0; dy < scale; dy++) {
for (int dx = 0; dx < scale; dx++) {
int origX = x * scale + dx;
int origY = y * scale + dy;
if (origX < width && origY < height) {
int rgb = image.getRGB(origX, origY) & 0xFFFFFF;
if (rgb != 0xFFFFFF) { // 黑色像素
pixelCount++;
}
}
}
}
// 根据黑色像素密度选择字符
if (pixelCount > scale * scale * 0.7) {
System.out.print("██");
} else if (pixelCount > scale * scale * 0.4) {
System.out.print("▓▓");
} else if (pixelCount > scale * scale * 0.1) {
System.out.print("░░");
} else {
System.out.print(" ");
}
}
System.out.println();
}
}
}

16
pom.xml
View File

@ -83,10 +83,10 @@
<monitor.username>fys</monitor.username>
<monitor.password>123456</monitor.password>
</properties>
<activation>
<!-- 默认环境 -->
<activeByDefault>true</activeByDefault>
</activation>
<!-- <activation> -->
<!-- &lt;!&ndash; 默认环境 &ndash;&gt; -->
<!-- <activeByDefault>true</activeByDefault> -->
<!-- </activation> -->
</profile>
<profile>
<id>prod</id>
@ -96,10 +96,10 @@
<monitor.username>fys</monitor.username>
<monitor.password>123456</monitor.password>
</properties>
<!-- <activation> -->
<!-- &lt;!&ndash; 默认环境 &ndash;&gt; -->
<!-- <activeByDefault>true</activeByDefault> -->
<!-- </activation> -->
<activation>
<!-- 默认环境 -->
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>