| @@ -0,0 +1,132 @@ | |||
| package com.xueyi.system.digitalmans.controller; | |||
| import com.xueyi.common.core.web.result.AjaxResult; | |||
| import com.xueyi.common.core.web.validate.V_A; | |||
| import com.xueyi.common.core.web.validate.V_E; | |||
| import com.xueyi.common.log.annotation.Log; | |||
| import com.xueyi.common.log.enums.BusinessType; | |||
| import com.xueyi.common.security.annotation.Logical; | |||
| import com.xueyi.common.security.annotation.RequiresPermissions; | |||
| import com.xueyi.common.web.entity.controller.BaseController; | |||
| import com.xueyi.system.digitalmans.domain.dto.DmRemoteNotificationDto; | |||
| import com.xueyi.system.digitalmans.domain.query.DmRemoteNotificationQuery; | |||
| import com.xueyi.system.digitalmans.service.IDmRemoteNotificationService; | |||
| import org.springframework.validation.annotation.Validated; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import java.io.Serializable; | |||
| import java.util.List; | |||
| /** | |||
| * 远程通知管理 业务处理 | |||
| * | |||
| * @author xueyi | |||
| */ | |||
| @RestController | |||
| @RequestMapping("/remoteNotification") | |||
| public class DmRemoteNotificationController extends BaseController<DmRemoteNotificationQuery, DmRemoteNotificationDto, IDmRemoteNotificationService> { | |||
| /** 定义节点名称 */ | |||
| @Override | |||
| protected String getNodeName() { | |||
| return "远程通知" ; | |||
| } | |||
| /** | |||
| * 查询远程通知列表 | |||
| */ | |||
| @Override | |||
| @GetMapping("/list") | |||
| @RequiresPermissions(Auth.DM_REMOTE_NOTIFICATION_LIST) | |||
| public AjaxResult list(DmRemoteNotificationQuery remoteNotification) { | |||
| return super.list(remoteNotification); | |||
| } | |||
| /** | |||
| * 查询远程通知详细 | |||
| */ | |||
| @Override | |||
| @GetMapping(value = "/{id}") | |||
| @RequiresPermissions(Auth.DM_REMOTE_NOTIFICATION_SINGLE) | |||
| public AjaxResult getInfo(@PathVariable Serializable id) { | |||
| return super.getInfo(id); | |||
| } | |||
| /** | |||
| * 远程通知新增 | |||
| */ | |||
| @Override | |||
| @PostMapping | |||
| @RequiresPermissions(Auth.DM_REMOTE_NOTIFICATION_ADD) | |||
| @Log(title = "远程通知管理", businessType = BusinessType.INSERT) | |||
| public AjaxResult add(@Validated({V_A.class}) @RequestBody DmRemoteNotificationDto remoteNotification) { | |||
| return super.add(remoteNotification); | |||
| } | |||
| /** | |||
| * 远程通知修改 | |||
| */ | |||
| @Override | |||
| @PutMapping | |||
| @RequiresPermissions(Auth.DM_REMOTE_NOTIFICATION_EDIT) | |||
| @Log(title = "远程通知管理", businessType = BusinessType.UPDATE) | |||
| public AjaxResult edit(@Validated({V_E.class}) @RequestBody DmRemoteNotificationDto remoteNotification) { | |||
| return super.edit(remoteNotification); | |||
| } | |||
| /** | |||
| * 远程通知修改状态 | |||
| */ | |||
| @Override | |||
| @PutMapping("/status") | |||
| @RequiresPermissions(value = {Auth.DM_REMOTE_NOTIFICATION_EDIT, Auth.DM_REMOTE_NOTIFICATION_ES}, logical = Logical.OR) | |||
| @Log(title = "远程通知管理", businessType = BusinessType.UPDATE_STATUS) | |||
| public AjaxResult editStatus(@RequestBody DmRemoteNotificationDto remoteNotification) { | |||
| return super.editStatus(remoteNotification); | |||
| } | |||
| /** | |||
| * 远程通知批量删除 | |||
| */ | |||
| @Override | |||
| @DeleteMapping("/batch/{idList}") | |||
| @RequiresPermissions(Auth.DM_REMOTE_NOTIFICATION_DEL) | |||
| @Log(title = "远程通知管理", businessType = BusinessType.DELETE) | |||
| public AjaxResult batchRemove(@PathVariable List<Long> idList) { | |||
| return super.batchRemove(idList); | |||
| } | |||
| /** | |||
| * 远程通知批量删除 | |||
| */ | |||
| @GetMapping("/run/{id}") | |||
| @RequiresPermissions(Auth.DM_REMOTE_NOTIFICATION_DEL) | |||
| @Log(title = "远程通知管理", businessType = BusinessType.DELETE) | |||
| public AjaxResult run(@PathVariable Long id) { | |||
| return baseService.run(id) ? success() : error("通知发送失败!"); | |||
| } | |||
| /** | |||
| * 获取远程通知选择框列表 | |||
| */ | |||
| @Override | |||
| @GetMapping("/option") | |||
| public AjaxResult option() { | |||
| return super.option(); | |||
| } | |||
| interface Auth { | |||
| /** 系统 - 远程通知管理 - 列表 */ | |||
| String DM_REMOTE_NOTIFICATION_LIST = "digitalmans:remoteNotification:list"; | |||
| /** 系统 - 远程通知管理 - 详情 */ | |||
| String DM_REMOTE_NOTIFICATION_SINGLE = "digitalmans:remoteNotification:single"; | |||
| /** 系统 - 远程通知管理 - 新增 */ | |||
| String DM_REMOTE_NOTIFICATION_ADD = "digitalmans:remoteNotification:add"; | |||
| /** 系统 - 远程通知管理 - 修改 */ | |||
| String DM_REMOTE_NOTIFICATION_EDIT = "digitalmans:remoteNotification:edit"; | |||
| /** 系统 - 远程通知管理 - 修改状态 */ | |||
| String DM_REMOTE_NOTIFICATION_ES = "digitalmans:remoteNotification:es"; | |||
| /** 系统 - 远程通知管理 - 删除 */ | |||
| String DM_REMOTE_NOTIFICATION_DEL = "digitalmans:remoteNotification:delete"; | |||
| } | |||
| } | |||
| @@ -0,0 +1,24 @@ | |||
| package com.xueyi.system.digitalmans.domain.dto; | |||
| import com.xueyi.system.digitalmans.domain.po.DmRemoteNotificationPo; | |||
| import com.xueyi.system.resource.domain.dto.DmResourcesDto; | |||
| import lombok.Data; | |||
| import lombok.EqualsAndHashCode; | |||
| import java.io.Serial; | |||
| /** | |||
| * 远程通知 数据传输对象 | |||
| * | |||
| * @author xueyi | |||
| */ | |||
| @Data | |||
| @EqualsAndHashCode(callSuper = true) | |||
| public class DmRemoteNotificationDto extends DmRemoteNotificationPo { | |||
| @Serial | |||
| private static final long serialVersionUID = 1L; | |||
| DmResourcesDto resource; | |||
| } | |||
| @@ -0,0 +1,17 @@ | |||
| package com.xueyi.system.digitalmans.domain.model; | |||
| import com.xueyi.common.core.web.entity.model.BaseConverter; | |||
| import com.xueyi.system.digitalmans.domain.dto.DmRemoteNotificationDto; | |||
| import com.xueyi.system.digitalmans.domain.po.DmRemoteNotificationPo; | |||
| import com.xueyi.system.digitalmans.domain.query.DmRemoteNotificationQuery; | |||
| import org.mapstruct.Mapper; | |||
| import org.mapstruct.MappingConstants; | |||
| /** | |||
| * 远程通知 对象映射器 | |||
| * | |||
| * @author xueyi | |||
| */ | |||
| @Mapper(componentModel = MappingConstants.ComponentModel.SPRING) | |||
| public interface DmRemoteNotificationConverter extends BaseConverter<DmRemoteNotificationQuery, DmRemoteNotificationDto, DmRemoteNotificationPo> { | |||
| } | |||
| @@ -0,0 +1,59 @@ | |||
| package com.xueyi.system.digitalmans.domain.po; | |||
| import java.time.LocalDateTime; | |||
| import java.util.Date; | |||
| import com.fasterxml.jackson.annotation.JsonFormat; | |||
| import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | |||
| import com.fasterxml.jackson.databind.annotation.JsonSerialize; | |||
| import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer; | |||
| import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer; | |||
| import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer; | |||
| import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; | |||
| import com.xueyi.common.core.web.tenant.base.TBaseEntity; | |||
| import com.xueyi.system.digitalmans.domain.dto.DmRemoteNotificationDto; | |||
| import com.xueyi.common.core.annotation.Excel; | |||
| import com.baomidou.mybatisplus.annotation.TableName; | |||
| import lombok.Data; | |||
| import lombok.EqualsAndHashCode; | |||
| import java.io.Serial; | |||
| import static com.xueyi.common.core.constant.basic.EntityConstants.SORT; | |||
| import static com.xueyi.common.core.constant.basic.EntityConstants.REMARK; | |||
| /** | |||
| * 远程通知 持久化对象 | |||
| * | |||
| * @author xueyi | |||
| */ | |||
| @Data | |||
| @EqualsAndHashCode(callSuper = true) | |||
| @TableName(value = "dm_remote_notification", excludeProperty = { SORT, REMARK }) | |||
| public class DmRemoteNotificationPo extends TBaseEntity { | |||
| @Serial | |||
| private static final long serialVersionUID = 1L; | |||
| /** 资源类型 */ | |||
| @Excel(name = "资源类型") | |||
| protected Integer type; | |||
| /** resource_id */ | |||
| @Excel(name = "resource_id") | |||
| protected Long resourceId; | |||
| /** 播放次数 */ | |||
| @Excel(name = "播放次数") | |||
| protected Long recycle; | |||
| /** 启动时间 */ | |||
| @Excel(name = "启动时间") | |||
| @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | |||
| @JsonDeserialize(using = LocalDateTimeDeserializer.class) | |||
| @JsonSerialize(using = LocalDateTimeSerializer.class) | |||
| protected LocalDateTime startTime; | |||
| /** 数字人id */ | |||
| protected Long manId; | |||
| } | |||
| @@ -0,0 +1,20 @@ | |||
| package com.xueyi.system.digitalmans.domain.query; | |||
| import com.xueyi.system.digitalmans.domain.po.DmRemoteNotificationPo; | |||
| import lombok.Data; | |||
| import lombok.EqualsAndHashCode; | |||
| import java.io.Serial; | |||
| /** | |||
| * 远程通知 数据查询对象 | |||
| * | |||
| * @author xueyi | |||
| */ | |||
| @Data | |||
| @EqualsAndHashCode(callSuper = true) | |||
| public class DmRemoteNotificationQuery extends DmRemoteNotificationPo { | |||
| @Serial | |||
| private static final long serialVersionUID = 1L; | |||
| } | |||
| @@ -0,0 +1,13 @@ | |||
| package com.xueyi.system.digitalmans.manager; | |||
| import com.xueyi.system.digitalmans.domain.dto.DmRemoteNotificationDto; | |||
| import com.xueyi.system.digitalmans.domain.query.DmRemoteNotificationQuery; | |||
| import com.xueyi.common.web.entity.manager.IBaseManager; | |||
| /** | |||
| * 远程通知管理 数据封装层 | |||
| * | |||
| * @author xueyi | |||
| */ | |||
| public interface IDmRemoteNotificationManager extends IBaseManager<DmRemoteNotificationQuery, DmRemoteNotificationDto> { | |||
| } | |||
| @@ -0,0 +1,23 @@ | |||
| package com.xueyi.system.digitalmans.manager.impl; | |||
| import com.xueyi.system.digitalmans.domain.po.DmRemoteNotificationPo; | |||
| import com.xueyi.system.digitalmans.domain.dto.DmRemoteNotificationDto; | |||
| import com.xueyi.system.digitalmans.domain.query.DmRemoteNotificationQuery; | |||
| import com.xueyi.system.digitalmans.domain.model.DmRemoteNotificationConverter; | |||
| import com.xueyi.system.digitalmans.mapper.DmRemoteNotificationMapper; | |||
| import com.xueyi.common.web.entity.manager.impl.BaseManagerImpl; | |||
| import com.xueyi.system.digitalmans.manager.IDmRemoteNotificationManager; | |||
| import org.springframework.stereotype.Component; | |||
| import java.io.Serializable; | |||
| import java.util.List; | |||
| /** | |||
| * 远程通知管理 数据封装层处理 | |||
| * | |||
| * @author xueyi | |||
| */ | |||
| @Component | |||
| public class DmRemoteNotificationManager extends BaseManagerImpl<DmRemoteNotificationQuery, DmRemoteNotificationDto, DmRemoteNotificationPo, DmRemoteNotificationMapper, DmRemoteNotificationConverter> implements IDmRemoteNotificationManager { | |||
| } | |||
| @@ -0,0 +1,16 @@ | |||
| package com.xueyi.system.digitalmans.mapper; | |||
| import com.xueyi.system.digitalmans.domain.query.DmRemoteNotificationQuery; | |||
| import com.xueyi.system.digitalmans.domain.dto.DmRemoteNotificationDto; | |||
| import com.xueyi.system.digitalmans.domain.po.DmRemoteNotificationPo; | |||
| import com.xueyi.common.web.entity.mapper.BaseMapper; | |||
| import com.xueyi.common.datasource.annotation.Isolate; | |||
| /** | |||
| * 远程通知管理 数据层 | |||
| * | |||
| * @author xueyi | |||
| */ | |||
| @Isolate | |||
| public interface DmRemoteNotificationMapper extends BaseMapper<DmRemoteNotificationQuery, DmRemoteNotificationDto, DmRemoteNotificationPo> { | |||
| } | |||
| @@ -0,0 +1,20 @@ | |||
| package com.xueyi.system.digitalmans.service; | |||
| import com.xueyi.system.digitalmans.domain.query.DmRemoteNotificationQuery; | |||
| import com.xueyi.system.digitalmans.domain.dto.DmRemoteNotificationDto; | |||
| import com.xueyi.common.web.entity.service.IBaseService; | |||
| /** | |||
| * 远程通知管理 服务层 | |||
| * | |||
| * @author xueyi | |||
| */ | |||
| public interface IDmRemoteNotificationService extends IBaseService<DmRemoteNotificationQuery, DmRemoteNotificationDto> { | |||
| /** | |||
| * 立即发送通知 | |||
| * | |||
| * @param id Id | |||
| */ | |||
| boolean run(Long id); | |||
| } | |||
| @@ -0,0 +1,85 @@ | |||
| package com.xueyi.system.digitalmans.service.impl; | |||
| import com.alibaba.fastjson2.JSON; | |||
| import com.alibaba.fastjson2.JSONObject; | |||
| import com.xueyi.common.mqtt.connection.MqttTemplate; | |||
| import com.xueyi.system.digitalmans.domain.dto.DmDigitalmanDto; | |||
| import com.xueyi.system.digitalmans.domain.dto.DmRemoteNotificationDto; | |||
| import com.xueyi.system.digitalmans.domain.query.DmRemoteNotificationQuery; | |||
| import com.xueyi.system.digitalmans.service.IDmDigitalmanService; | |||
| import com.xueyi.system.digitalmans.service.IDmRemoteNotificationService; | |||
| import com.xueyi.system.digitalmans.manager.IDmRemoteNotificationManager; | |||
| import com.xueyi.common.web.entity.service.impl.BaseServiceImpl; | |||
| import com.xueyi.system.resource.manager.IDmResourcesManager; | |||
| import com.xueyi.system.resource.service.IDmResourcesService; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.beans.factory.annotation.Value; | |||
| import org.springframework.stereotype.Service; | |||
| import java.io.Serializable; | |||
| import java.util.List; | |||
| /** | |||
| * 远程通知管理 服务层处理 | |||
| * | |||
| * @author xueyi | |||
| */ | |||
| @Service | |||
| public class DmRemoteNotificationServiceImpl extends BaseServiceImpl<DmRemoteNotificationQuery, DmRemoteNotificationDto, IDmRemoteNotificationManager> implements IDmRemoteNotificationService { | |||
| @Autowired | |||
| MqttTemplate mqttTemplate; | |||
| @Autowired | |||
| IDmDigitalmanService dmDigitalManService; | |||
| @Autowired | |||
| IDmResourcesManager dmResourcesManager; | |||
| @Value("${spring.profiles.active}") | |||
| private String activeProfile; | |||
| /** | |||
| * 查询远程通知对象列表 | 数据权限 | |||
| * | |||
| * @param remoteNotification 远程通知对象 | |||
| * @return 远程通知对象集合 | |||
| */ | |||
| @Override | |||
| //@DataScope(userAlias = "createBy", mapperScope = {"DmRemoteNotificationMapper"}) | |||
| public List<DmRemoteNotificationDto> selectListScope(DmRemoteNotificationQuery remoteNotification) { | |||
| List<DmRemoteNotificationDto> dtoList = baseManager.selectList(remoteNotification); | |||
| dtoList.forEach(item->{ | |||
| item.setResource(dmResourcesManager.selectById(item.getResourceId())); | |||
| }); | |||
| return dtoList; | |||
| } | |||
| @Override | |||
| public DmRemoteNotificationDto selectById(Serializable id) { | |||
| DmRemoteNotificationDto dto = super.selectById(id); | |||
| dto.setResource(dmResourcesManager.selectById(dto.getResourceId())); | |||
| return dto; | |||
| } | |||
| @Override | |||
| public boolean run(Long id) { | |||
| DmRemoteNotificationDto dto = baseManager.selectById(id); | |||
| if (dto != null) { | |||
| // 根据resourceId获取图片对象 | |||
| dto.setResource(dmResourcesManager.selectById(dto.getResourceId())); | |||
| // 从数字人中获取设备号 | |||
| DmDigitalmanDto digitalmanDto = dmDigitalManService.selectById(dto.getManId()); | |||
| if (digitalmanDto != null) { | |||
| // 向/activeProfile/digital_man/deviceId/notify/realtime_broadcast发送消息 | |||
| // 将dto转换成json | |||
| JSONObject jsonObject = (JSONObject) JSON.toJSON(dto); | |||
| jsonObject.put("resourceType", 1); | |||
| jsonObject.put("msg", dto.getName()); | |||
| mqttTemplate.sendToMqtt("/" + activeProfile + "/" + "digital_man" + "/" + digitalmanDto.getDeviceId() + "/" + "notify" + "/" + "realtime_broadcast", jsonObject.toJSONString()); | |||
| return true; | |||
| } | |||
| } | |||
| return false; | |||
| } | |||
| } | |||