feat:部门硬件分组

This commit is contained in:
dzc committed 2025-01-15 17:01:22 +08:00
1 parent c67f020a6a
commit 33bec4fb22
11 files changed
+114 -78

No files matched your search

@@ -1,7 +1,6 @@
package com.bsd.pjcloud.hard.controller.hard;
import cn.hutool.core.util.ObjectUtil;
import com.bsd.pjcloud.common.core.util.BeanUtils;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.idempotent.annotation.Idempotent;
import com.bsd.pjcloud.hard.api.constant.HardTypeEnum;
@@ -120,8 +120,12 @@ public class HardManagerServiceImpl extends ServiceImpl<HardManagerMapper, HardM
if (ObjectUtil.isEmpty(mch)) {
throw new RuntimeException("商户不存在");
}
SysDept deptHardGroup = deptService.getParentDeptHardGroup(user.getDeptId()).getData();
if (ObjectUtil.isEmpty(deptHardGroup)) {
throw new RuntimeException("请设置顶级部门硬件分组");
}
dto.setHardGroupId(deptHardGroup.getHardGroupId());
dto.setDeptId(user.getDeptId());
dto.setHardGroupId(mch.getHardGroupId());
// mq地址和端口
dto.setMqSocketAddress(mqttConfig.getAndroidAddress());
dto.setMqSocketPort(mqttConfig.getAndroidPort());
@@ -129,7 +133,7 @@ public class HardManagerServiceImpl extends ServiceImpl<HardManagerMapper, HardM
baseMapper.insert(dto);
// topic
HardManagerEntity updateObj = HardManagerEntity.builder().id(dto.getId()).build();
String topic = createMqConfigByAction(mch.getHardGroupId(), null, null, 1) + "/#";
String topic = createMqConfigByAction(deptHardGroup.getHardGroupId(), null, null, 1) + "/#";
updateObj.setMainTopic(topic);
// client id
String clientId = createMqConfigByAction(null, null, dto.getId(), 2);
@@ -152,10 +156,14 @@ public class HardManagerServiceImpl extends ServiceImpl<HardManagerMapper, HardM
if (ObjectUtil.isEmpty(mch)) {
throw new RuntimeException("商户不存在");
}
dto.setHardGroupId(mch.getHardGroupId());
SysDept deptHardGroup = deptService.getParentDeptHardGroup(detail.getDeptId()).getData();
if (ObjectUtil.isEmpty(deptHardGroup)) {
throw new RuntimeException("请设置顶级部门硬件分组");
}
dto.setHardGroupId(deptHardGroup.getHardGroupId());
if (!ObjectUtil.equals(dto.getMerchantId(), detail.getMerchantId())) {
// topic
String topic = createMqConfigByAction(mch.getHardGroupId(), null, null, 1) + "/#";
String topic = createMqConfigByAction(deptHardGroup.getHardGroupId(), null, null, 1) + "/#";
dto.setMainTopic(topic);
// client id
String clientId = createMqConfigByAction(null, null, dto.getId(), 2);
-6
View File
@@ -79,12 +79,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>com.bsd</groupId>
<artifactId>pjcloud-wallet-api</artifactId>
<version>5.7.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<profiles>
<profile>
@@ -2,10 +2,10 @@ package com.bsd.pjcloud.mqtt.service;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.bsd.pjcloud.admin.api.entity.SysDept;
import com.bsd.pjcloud.admin.api.feign.RemoteDeptService;
import com.bsd.pjcloud.mqtt.dto.MqttBaseDto;
import com.bsd.pjcloud.mqtt.dto.MqttHardBaseMsg;
import com.bsd.pjcloud.wallet.api.feign.RemoteMchService;
import com.bsd.pjcloud.wallet.api.vo.MchManageVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@@ -17,9 +17,11 @@ import java.util.List;
@Component
public class MqttEventService {
static private final String TAG = "MqttEventService";
private final MqttService mqttService;
private final RemoteMchService remoteMchService;
private final RemoteDeptService remoteDeptService;
public <T extends MqttBaseDto> Boolean defaultAction(T dto) {
MqttHardBaseMsg msg = dto.getData();
@@ -29,10 +31,11 @@ public class MqttEventService {
}
public <T extends MqttBaseDto> void getTopicParamsByUserDeptId(T dto, Long deptId) {
MchManageVo mch = remoteMchService.getFirstMchByDeptId(deptId).getData();
if (ObjectUtil.isEmpty(mch)) {
SysDept dept = remoteDeptService.getParentDeptHardGroup(deptId).getData();
if (ObjectUtil.isEmpty(dept)) {
log.error("|{}|查找上级部门硬件分组失败deptId:|{}|dto:|{}|", TAG, deptId, JSON.toJSONString(dto));
return;
}
dto.setHardGroupId(mch.getHardGroupId());
dto.setHardGroupId(dept.getHardGroupId());
}
}
@@ -28,6 +28,7 @@ import lombok.EqualsAndHashCode;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.time.LocalDateTime;
/**
@@ -44,66 +45,72 @@ import java.time.LocalDateTime;
@EqualsAndHashCode(callSuper = true)
public class SysDept extends Model<SysDept> {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
@TableId(value = "dept_id", type = IdType.ASSIGN_ID)
@Schema(description = "部门id")
private Long deptId;
@TableId(value = "dept_id", type = IdType.ASSIGN_ID)
@Schema(description = "部门id")
private Long deptId;
/**
* 部门名称
*/
@NotBlank(message = "部门名称不能为空")
@Schema(description = "部门名称")
private String name;
/**
* 部门名称
*/
@NotBlank(message = "部门名称不能为空")
@Schema(description = "部门名称")
private String name;
/**
* 排序
*/
@NotNull(message = "排序值不能为空")
@Schema(description = "排序值")
private Integer sortOrder;
/**
* 硬件分类id
*/
@Schema(description = "硬件分类id")
private Long hardGroupId;
/**
* 创建人
*/
@TableField(fill = FieldFill.INSERT)
@Schema(description = "创建人")
private String createBy;
/**
* 排序
*/
@NotNull(message = "排序值不能为空")
@Schema(description = "排序值")
private Integer sortOrder;
/**
* 修改人
*/
@TableField(fill = FieldFill.UPDATE)
@Schema(description = "修改人")
private String updateBy;
/**
* 创建人
*/
@TableField(fill = FieldFill.INSERT)
@Schema(description = "创建人")
private String createBy;
/**
* 创建时间
*/
@Schema(description = "创建时间")
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 修改人
*/
@TableField(fill = FieldFill.UPDATE)
@Schema(description = "修改人")
private String updateBy;
/**
* 修改时间
*/
@Schema(description = "修改时间")
@TableField(fill = FieldFill.UPDATE)
private LocalDateTime updateTime;
/**
* 创建时间
*/
@Schema(description = "创建时间")
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 父级部门id
*/
@Schema(description = "父级部门id")
private Long parentId;
/**
* 修改时间
*/
@Schema(description = "修改时间")
@TableField(fill = FieldFill.UPDATE)
private LocalDateTime updateTime;
/**
* 是否删除 1:已删除 0:正常
*/
@TableLogic
@Schema(description = "删除标记,1:已删除,0:正常")
@TableField(fill = FieldFill.INSERT)
private String delFlag;
/**
* 父级部门id
*/
@Schema(description = "父级部门id")
private Long parentId;
/**
* 是否删除 1:已删除 0:正常
*/
@TableLogic
@Schema(description = "删除标记,1:已删除,0:正常")
@TableField(fill = FieldFill.INSERT)
private String delFlag;
}
@@ -84,4 +84,13 @@ public interface RemoteDeptService {
@NoToken
@GetMapping("/dept/getParentDeptList")
R<List<SysDept>> getParentDeptList(@RequestParam("deptId") Long deptId);
/**
* 查询部门所属的分组部门
* @param deptId
* @return
*/
@NoToken
@GetMapping("/dept/getParentDeptHardGroup")
R<SysDept> getParentDeptHardGroup(@RequestParam("deptId") Long deptId);
}
@@ -204,4 +204,16 @@ public class SysDeptController {
public R<List<SysDept>> getParentDeptList(@RequestParam("deptId") Long deptId) {
return R.ok(sysDeptService.getParentDeptList(deptId));
}
/**
* 查询部门所属的分组部门
*
* @param deptId
* @return
*/
@Inner
@GetMapping("/getParentDeptHardGroup")
public R<SysDept> getParentDeptHardGroup(@RequestParam("deptId") Long deptId) {
return R.ok(sysDeptService.getParentDeptHardGroup(deptId));
}
}
@@ -76,6 +76,8 @@ public interface SysDeptService extends IService<SysDept> {
*/
List<SysDept> getParentDeptList(Long deptId);
SysDept getParentDeptHardGroup(Long deptId);
/**
* 获取部门负责人
*
@@ -227,6 +227,13 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
return parentList;
}
@Override
public SysDept getParentDeptHardGroup(Long deptId) {
List<SysDept> parentDeptIds = getParentDeptList(deptId);
if (ObjectUtil.isEmpty(parentDeptIds)) return null;
return parentDeptIds.stream().filter(v -> ObjectUtil.isNotEmpty(v.getHardGroupId())).findFirst().get();
}
private void findParentDeptList(Long id, LinkedList<SysDept> parentList) {
SysDept currentDept = baseMapper.selectById(id);
if (currentDept != null) {
@@ -32,12 +32,6 @@ public class MchManageEntity extends Model<MchManageEntity> {
@Schema(description="主键")
private Long id;
/**
* 设备分组id
*/
@Schema(description="设备分组id")
private Long hardGroupId;
/**
* 绑定的部门id
*/
@@ -24,8 +24,6 @@ import com.bsd.pjcloud.wallet.service.MchManageService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Service;
@@ -59,7 +57,7 @@ public class MchManageServiceImpl extends ServiceImpl<MchManageMapper, MchManage
private final StringRedisTemplate redisTemplate;
@Override
@Cacheable(value = CacheConstants.WALLET_DETAIL, key = "#id", condition = "#id != null", unless = "#result == null")
// @Cacheable(value = CacheConstants.WALLET_DETAIL, key = "#id", condition = "#id != null", unless = "#result == null")
public MchManageEntity getById(Serializable id) {
return super.getById(id);
}
@@ -73,6 +71,9 @@ public class MchManageServiceImpl extends ServiceImpl<MchManageMapper, MchManage
if (existDeptId(dto.getDeptId(), null)) {
throw new CheckedException("该部门已经绑定过商户");
}
// 查询父部门
// dto.setHardGroupId();
baseMapper.insert(dto);
try {
MchCollectionCodeVo mchCollectionCode = new MchCollectionCodeVo();