手表绑定增加只能绑定本单位验证

This commit is contained in:
wanghao
2026-03-27 10:58:40 +08:00
parent 7aa25f5f3a
commit fc347944a0
@@ -151,7 +151,6 @@ public class WatchDeviceServiceImpl extends ServiceImpl<WatchDeviceMapper, Watch
private AsyncTaskExecutor asyncTaskExecutor; private AsyncTaskExecutor asyncTaskExecutor;
private RequestAttributes requestAttributes = null; private RequestAttributes requestAttributes = null;
private final ToolExportHandler toolExportHandler = new ToolExportHandler(); private final ToolExportHandler toolExportHandler = new ToolExportHandler();
@Autowired @Autowired
@@ -293,8 +292,18 @@ public class WatchDeviceServiceImpl extends ServiceImpl<WatchDeviceMapper, Watch
if (watchDevice == null) { if (watchDevice == null) {
return Result.error("该监测工具不存在"); return Result.error("该监测工具不存在");
} }
// 新增手表只能绑定给本单位的人
LoginUser userById = sysBaseAPI.getUserById(dto.getBindUserId());
if (userById.getOrgCode() == null || dto.getOrgCode() == null ||
userById.getOrgCode().length() < 6 || dto.getOrgCode().length() < 6 ||
!userById.getOrgCode().substring(0, 6).equals(dto.getOrgCode().substring(0, 6))) {
return Result.error("手表只能绑定给本单位人员");
}
if (isDeviceAlreadyBound(watchDevice, dto)) { if (isDeviceAlreadyBound(watchDevice, dto)) {
return Result.error("该设备已绑定该员工"); return Result.error("该设备已绑定");
} }
// 查询员工是否有绑定 // 查询员工是否有绑定
List<WatchDevice> deviceByUserIdList = getDeviceByUserId(dto.getBindUserId()); List<WatchDevice> deviceByUserIdList = getDeviceByUserId(dto.getBindUserId());
@@ -322,9 +331,8 @@ public class WatchDeviceServiceImpl extends ServiceImpl<WatchDeviceMapper, Watch
// 初始化开关数据 // 初始化开关数据
unbindUserAndInitDeviceSwitch(dto); unbindUserAndInitDeviceSwitch(dto);
} }
LoginUser userById = sysBaseAPI.getUserById(dto.getBindUserId());
// 此处修改 只有是职工的是才赋值单位信息 // 此处修改 只有是职工的是才赋值单位信息
if (dto.getIsEmployee()){ if (dto.getIsEmployee()) {
SysDepart inDepart = sysCache.getDepartByOrgCode(userById.getOrgCode()); SysDepart inDepart = sysCache.getDepartByOrgCode(userById.getOrgCode());
dto.setOrgCode(inDepart.getOrgCode()); dto.setOrgCode(inDepart.getOrgCode());
SysDepart thirdDepart = sysCache.getDepartByOrgCode(GlobalUtils.getThirdDepartOrgCode(userById.getOrgCode())); SysDepart thirdDepart = sysCache.getDepartByOrgCode(GlobalUtils.getThirdDepartOrgCode(userById.getOrgCode()));
@@ -396,7 +404,7 @@ public class WatchDeviceServiceImpl extends ServiceImpl<WatchDeviceMapper, Watch
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Result unbundleUser(BindUserDTO dto){ public Result unbundleUser(BindUserDTO dto) {
WatchDevice watchDevice = getDeviceByWatchNo(dto.getWatchNo()); WatchDevice watchDevice = getDeviceByWatchNo(dto.getWatchNo());
if (watchDevice == null) { if (watchDevice == null) {
return Result.error("该设备不存在"); return Result.error("该设备不存在");
@@ -422,7 +430,7 @@ public class WatchDeviceServiceImpl extends ServiceImpl<WatchDeviceMapper, Watch
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Result unbundleDevice(String watchNo){ public Result unbundleDevice(String watchNo) {
BindUserDTO dto = new BindUserDTO(); BindUserDTO dto = new BindUserDTO();
dto.setBindUserId(GlobalUtils.getLoginUser().getId()); dto.setBindUserId(GlobalUtils.getLoginUser().getId());
dto.setWatchNo(watchNo); dto.setWatchNo(watchNo);
@@ -530,7 +538,7 @@ public class WatchDeviceServiceImpl extends ServiceImpl<WatchDeviceMapper, Watch
watchBindHis.setBindUserId(dto.getBindUserId()); watchBindHis.setBindUserId(dto.getBindUserId());
watchBindHis.setCreateDate(new Date()); watchBindHis.setCreateDate(new Date());
watchBindHis.setUpdateDate(null); watchBindHis.setUpdateDate(null);
if (dto.getIsEmployee()){ if (dto.getIsEmployee()) {
watchBindHis.setDeptId(dto.getDeptId()); watchBindHis.setDeptId(dto.getDeptId());
watchBindHis.setOrgCode(dto.getOrgCode()); watchBindHis.setOrgCode(dto.getOrgCode());
} }
@@ -1610,26 +1618,26 @@ public class WatchDeviceServiceImpl extends ServiceImpl<WatchDeviceMapper, Watch
vo.setSex(user.getSex()); vo.setSex(user.getSex());
vo.setAge(user.getAge()); vo.setAge(user.getAge());
SysDepart secondDepart = sysCache.getDepartByOrgCode(GlobalUtils.getSecondDepartOrgCode(user.getOrgCode())); SysDepart secondDepart = sysCache.getDepartByOrgCode(GlobalUtils.getSecondDepartOrgCode(user.getOrgCode()));
if (ObjUtil.isNotEmpty(secondDepart)){ if (ObjUtil.isNotEmpty(secondDepart)) {
vo.setUnitCode(secondDepart.getOrgCode()); vo.setUnitCode(secondDepart.getOrgCode());
vo.setUnitName(secondDepart.getDepartName()); vo.setUnitName(secondDepart.getDepartName());
} }
SysDepart thirdDepart = sysCache.getDepartByOrgCode(GlobalUtils.getThirdDepartOrgCode(user.getOrgCode())); SysDepart thirdDepart = sysCache.getDepartByOrgCode(GlobalUtils.getThirdDepartOrgCode(user.getOrgCode()));
if (ObjUtil.isNotEmpty(thirdDepart)){ if (ObjUtil.isNotEmpty(thirdDepart)) {
vo.setOrgCode(thirdDepart.getOrgCode()); vo.setOrgCode(thirdDepart.getOrgCode());
vo.setOrgName(thirdDepart.getDepartName()); vo.setOrgName(thirdDepart.getDepartName());
} }
EmployeeHeightWeight userWeightInfo = GlobalUtils.getCloudResultData(sysBaseAPI.appUserFindUserHeightWeight(userId)); EmployeeHeightWeight userWeightInfo = GlobalUtils.getCloudResultData(sysBaseAPI.appUserFindUserHeightWeight(userId));
if (null != userWeightInfo){ if (null != userWeightInfo) {
vo.setHeight(StrUtil.isNotEmpty(userWeightInfo.getHeight())?Double.parseDouble(userWeightInfo.getHeight()):null); vo.setHeight(StrUtil.isNotEmpty(userWeightInfo.getHeight()) ? Double.parseDouble(userWeightInfo.getHeight()) : null);
vo.setWeight(StrUtil.isNotEmpty(userWeightInfo.getWeight())?Double.parseDouble(userWeightInfo.getWeight()):null); vo.setWeight(StrUtil.isNotEmpty(userWeightInfo.getWeight()) ? Double.parseDouble(userWeightInfo.getWeight()) : null);
} }
if (null != sdc){ if (null != sdc) {
vo.setWalkingSum(sdc.getStepValue()); vo.setWalkingSum(sdc.getStepValue());
vo.setWalkRunCalorie(sdc.getCalorieValue() / 1000); vo.setWalkRunCalorie(sdc.getCalorieValue() / 1000);
} }
if (null != workout){ if (null != workout) {
vo.setFitnessCalorie(workout.getCalorieTotalValue()); vo.setFitnessCalorie(workout.getCalorieTotalValue());
} }
Page<UserDayCalorieInfoVo> resultPage = new Page<>(); Page<UserDayCalorieInfoVo> resultPage = new Page<>();
@@ -1698,7 +1706,7 @@ public class WatchDeviceServiceImpl extends ServiceImpl<WatchDeviceMapper, Watch
// 获取该用户消耗数据 // 获取该用户消耗数据
List<WatchStatUserInfoDayWorkout> workoutList = workoutUserMap.get(userId); List<WatchStatUserInfoDayWorkout> workoutList = workoutUserMap.get(userId);
if (CollUtil.isNotEmpty(workoutList)){ if (CollUtil.isNotEmpty(workoutList)) {
// 获取该用户当日消耗数据 // 获取该用户当日消耗数据
WatchStatUserInfoDayWorkout dayWorkout = workoutList.stream().filter(item -> item.getDataDate().equals(cn.hutool.core.date.DateUtil.parse(date, "yyyy-MM-dd"))).findFirst().orElse(null); WatchStatUserInfoDayWorkout dayWorkout = workoutList.stream().filter(item -> item.getDataDate().equals(cn.hutool.core.date.DateUtil.parse(date, "yyyy-MM-dd"))).findFirst().orElse(null);
if (dayWorkout != null) { if (dayWorkout != null) {
@@ -2229,7 +2237,7 @@ public class WatchDeviceServiceImpl extends ServiceImpl<WatchDeviceMapper, Watch
cloudResultData.add(user); cloudResultData.add(user);
// 判断是否绑定手表 // 判断是否绑定手表
List<WatchDevice> watchDeviceList = watchDeviceMapper.selectList(new LambdaQueryWrapper<WatchDevice>() List<WatchDevice> watchDeviceList = watchDeviceMapper.selectList(new LambdaQueryWrapper<WatchDevice>()
.in(WatchDevice::getBindUserId, cloudResultData.stream().map(FamilyMembersVO::getFamilyMembersId).collect(Collectors.toList()))); .in(WatchDevice::getBindUserId, cloudResultData.stream().map(FamilyMembersVO::getFamilyMembersId).collect(Collectors.toList())));
if (CollUtil.isEmpty(watchDeviceList)) { if (CollUtil.isEmpty(watchDeviceList)) {
return new ArrayList<>(); return new ArrayList<>();
} }
@@ -2251,20 +2259,20 @@ public class WatchDeviceServiceImpl extends ServiceImpl<WatchDeviceMapper, Watch
healthFamilyVO.setIsSelf(familyMembersVO.getIsSelf()); healthFamilyVO.setIsSelf(familyMembersVO.getIsSelf());
} }
// 获取心率周 // 获取心率周
int rateWeek = cn.hutool.core.date.DateUtil.dayOfWeek(healthFamilyVO.getRateTime())-1; int rateWeek = cn.hutool.core.date.DateUtil.dayOfWeek(healthFamilyVO.getRateTime()) - 1;
healthFamilyVO.setRateWeek(rateWeek==0?7:rateWeek); healthFamilyVO.setRateWeek(rateWeek == 0 ? 7 : rateWeek);
// 获取血氧周 // 获取血氧周
int oxygenWeek = cn.hutool.core.date.DateUtil.dayOfWeek(healthFamilyVO.getBloodOxygenTime())-1; int oxygenWeek = cn.hutool.core.date.DateUtil.dayOfWeek(healthFamilyVO.getBloodOxygenTime()) - 1;
healthFamilyVO.setBloodOxygenWeek(oxygenWeek==0?7:oxygenWeek); healthFamilyVO.setBloodOxygenWeek(oxygenWeek == 0 ? 7 : oxygenWeek);
// 获取压力周 // 获取压力周
int pressureWeek = cn.hutool.core.date.DateUtil.dayOfWeek(healthFamilyVO.getPressureTime())-1; int pressureWeek = cn.hutool.core.date.DateUtil.dayOfWeek(healthFamilyVO.getPressureTime()) - 1;
healthFamilyVO.setPressureWeek(pressureWeek==0?7:pressureWeek); healthFamilyVO.setPressureWeek(pressureWeek == 0 ? 7 : pressureWeek);
// 获取体温周 // 获取体温周
int temperatureWeek = cn.hutool.core.date.DateUtil.dayOfWeek(healthFamilyVO.getTempTime())-1; int temperatureWeek = cn.hutool.core.date.DateUtil.dayOfWeek(healthFamilyVO.getTempTime()) - 1;
healthFamilyVO.setTempWeek(temperatureWeek==0?7:temperatureWeek); healthFamilyVO.setTempWeek(temperatureWeek == 0 ? 7 : temperatureWeek);
// 获取睡眠周 // 获取睡眠周
int sleepWeek = cn.hutool.core.date.DateUtil.dayOfWeek(healthFamilyVO.getSleepTime())-1; int sleepWeek = cn.hutool.core.date.DateUtil.dayOfWeek(healthFamilyVO.getSleepTime()) - 1;
healthFamilyVO.setSleepWeek(sleepWeek==0?7:sleepWeek); healthFamilyVO.setSleepWeek(sleepWeek == 0 ? 7 : sleepWeek);
} }
return list; return list;
} }
@@ -2274,7 +2282,7 @@ public class WatchDeviceServiceImpl extends ServiceImpl<WatchDeviceMapper, Watch
healthFamilyVO.setUserId(userId); healthFamilyVO.setUserId(userId);
// 判断是否绑定手表 // 判断是否绑定手表
WatchDevice watchDevice = watchDeviceMapper.selectOne(new LambdaQueryWrapper<WatchDevice>() WatchDevice watchDevice = watchDeviceMapper.selectOne(new LambdaQueryWrapper<WatchDevice>()
.eq(WatchDevice::getBindUserId, userId),false); .eq(WatchDevice::getBindUserId, userId), false);
if (ObjUtil.isEmpty(watchDevice)) { if (ObjUtil.isEmpty(watchDevice)) {
return healthFamilyVO; return healthFamilyVO;
} }
@@ -2288,7 +2296,7 @@ public class WatchDeviceServiceImpl extends ServiceImpl<WatchDeviceMapper, Watch
Map<String, DictModel> exerciseType = watchExerciseType.stream().collect(Collectors.toMap(DictModel::getValue, Function.identity())); Map<String, DictModel> exerciseType = watchExerciseType.stream().collect(Collectors.toMap(DictModel::getValue, Function.identity()));
for (HealthFamilyVO familyVO : list) { for (HealthFamilyVO familyVO : list) {
DictModel dictModel = exerciseType.get(familyVO.getWorkoutType()); DictModel dictModel = exerciseType.get(familyVO.getWorkoutType());
if (ObjUtil.isNotEmpty(dictModel)){ if (ObjUtil.isNotEmpty(dictModel)) {
familyVO.setDurationName(dictModel.getText()); familyVO.setDurationName(dictModel.getText());
} }
} }
@@ -2301,11 +2309,11 @@ public class WatchDeviceServiceImpl extends ServiceImpl<WatchDeviceMapper, Watch
} }
@Override @Override
public void deleteKeyUser(String userId,String errorType) { public void deleteKeyUser(String userId, String errorType) {
LambdaUpdateWrapper<WatchKeyUser> wrapper = new LambdaUpdateWrapper<>(); LambdaUpdateWrapper<WatchKeyUser> wrapper = new LambdaUpdateWrapper<>();
wrapper.eq(WatchKeyUser::getUserId, userId); wrapper.eq(WatchKeyUser::getUserId, userId);
wrapper.eq(ObjUtil.isNotEmpty(errorType),WatchKeyUser::getErrorType, errorType); wrapper.eq(ObjUtil.isNotEmpty(errorType), WatchKeyUser::getErrorType, errorType);
wrapper.set(WatchKeyUser::getDelFlag,1); wrapper.set(WatchKeyUser::getDelFlag, 1);
keyUserMapper.update(wrapper); keyUserMapper.update(wrapper);
} }