|
@@ -1,7 +1,9 @@
|
|
package com.xy.service;
|
|
package com.xy.service;
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.xy.collections.list.JArrayList;
|
|
import com.xy.collections.list.JArrayList;
|
|
import com.xy.collections.list.JList;
|
|
import com.xy.collections.list.JList;
|
|
@@ -22,6 +24,7 @@ import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
@@ -174,6 +177,73 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
|
|
return queryPage(page);
|
|
return queryPage(page);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @ApiOperation("商户设备授权")
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public R<Boolean> mercDeviceAuth(DeviceInfoDto.MercDeviceAuthDto auth) {
|
|
|
|
+ Long mercId = auth.getMercId();
|
|
|
|
+ //商户最终设备列表
|
|
|
|
+ List<Long> deviceIds = auth.getDeviceIds();
|
|
|
|
+ List<DeviceInfo> devices = getDevicesByMercId(mercId);
|
|
|
|
+ //取消商户设备授权
|
|
|
|
+ if (CollUtil.isEmpty(deviceIds)) {
|
|
|
|
+ if (CollUtil.isEmpty(devices)) {
|
|
|
|
+ return R.ok(Boolean.TRUE);
|
|
|
|
+ }
|
|
|
|
+ return R.ok(removeMerRefDevices(devices));
|
|
|
|
+ }
|
|
|
|
+ //更新商户设备授权
|
|
|
|
+ List<DeviceInfo> deviceInfos = this.listByIds(deviceIds);
|
|
|
|
+ deviceInfos.forEach(deviceInfo -> {
|
|
|
|
+ //绑定关系
|
|
|
|
+ deviceInfo.setMercId(mercId);
|
|
|
|
+ });
|
|
|
|
+ updateBatchById(deviceInfos);
|
|
|
|
+ //原来存在的设备关系,不在最终设备列表中的移除
|
|
|
|
+ if (CollUtil.isNotEmpty(devices)) {
|
|
|
|
+ List<Long> oldIds = new ArrayList<>();
|
|
|
|
+ List<Long> removeIds = new ArrayList<>();
|
|
|
|
+ devices.forEach(device -> oldIds.add(device.getDeviceId()));
|
|
|
|
+ oldIds.forEach(deviceId -> {
|
|
|
|
+ //不在最终设备列表中的待移除
|
|
|
|
+ if (!deviceIds.contains(deviceId)) {
|
|
|
|
+ removeIds.add(deviceId);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ if (CollUtil.isNotEmpty(removeIds)) {
|
|
|
|
+ List<DeviceInfo> removeList = this.listByIds(removeIds);
|
|
|
|
+ removeMerRefDevices(removeList);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return R.ok(Boolean.TRUE);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 批量移除商户设备绑定关系
|
|
|
|
+ *
|
|
|
|
+ * @param deviceInfos
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private Boolean removeMerRefDevices(List<DeviceInfo> deviceInfos) {
|
|
|
|
+ deviceInfos.forEach(deviceInfo -> {
|
|
|
|
+ //-1 释放关系
|
|
|
|
+ deviceInfo.setMercId(-1L);
|
|
|
|
+ });
|
|
|
|
+ //批量更新
|
|
|
|
+ updateBatchById(deviceInfos);
|
|
|
|
+ return updateBatchById(deviceInfos);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取商户设备列表
|
|
|
|
+ *
|
|
|
|
+ * @param mercId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private List<DeviceInfo> getDevicesByMercId(Long mercId) {
|
|
|
|
+ return list(Wrappers.<DeviceInfo>lambdaQuery().eq(DeviceInfo::getMercId, mercId));
|
|
|
|
+ }
|
|
|
|
+
|
|
private R<PageBean<DeviceInfoDto.Vo2>> queryPage(DeviceInfoDto.Page page) {
|
|
private R<PageBean<DeviceInfoDto.Vo2>> queryPage(DeviceInfoDto.Page page) {
|
|
IPage<DeviceInfoQueryPage> iPage = baseMapper.queryPage(toIPage(page.getPage()), page);
|
|
IPage<DeviceInfoQueryPage> iPage = baseMapper.queryPage(toIPage(page.getPage()), page);
|
|
return R.ok(toPageBean(DeviceInfoDto.Vo2.class, iPage));
|
|
return R.ok(toPageBean(DeviceInfoDto.Vo2.class, iPage));
|