| @@ -26,6 +26,8 @@ public class DmResourcesPo extends TBaseEntity { | |||
| public static final Integer TYPE_PIC = 1; | |||
| public static final Integer TYPE_VIDEO = 2; | |||
| public static final Integer TYPE_PDF = 3; | |||
| /** 资源tag */ | |||
| @Excel(name = "资源tag") | |||
| protected String tag; | |||
| @@ -8,4 +8,16 @@ import com.xueyi.common.core.utils.core.pool.NumberPool; | |||
| * @author xueyi | |||
| */ | |||
| public class NumberUtil extends cn.hutool.core.util.NumberUtil implements NumberPool { | |||
| /** | |||
| * @Author yangkai | |||
| * @Description 判断数字是否为null,为null返回0 | |||
| * @Date 2023/9/21 | |||
| * @Param | |||
| * @return | |||
| **/ | |||
| public static int getNumber(Integer number) { | |||
| return number == null ? 0 : number; | |||
| } | |||
| } | |||
| @@ -26,6 +26,8 @@ public class MimeTypeUtil { | |||
| public static final String[] VIDEO_EXTENSION = {"mp4", "avi", "rmvb", "webm"}; | |||
| public static final String PDF_EXTENSION = "pdf"; | |||
| public static final String[] DEFAULT_ALLOWED_EXTENSION = { | |||
| // 图片 | |||
| "bmp", "gif", "jpg", "jpeg", "png", | |||
| @@ -34,7 +36,15 @@ public class MimeTypeUtil { | |||
| // 压缩文件 | |||
| "rar", "zip", "gz", "bz2", | |||
| // 视频格式 | |||
| "mp4", "avi", "rmvb", | |||
| "mp4", "avi", "rmvb", "mkv", "wmv", "rm", "rmvb", "flv", "webm", | |||
| "pdf"}; | |||
| public static final String[] EXCEPT_ALLOWED_EXTENSION = { | |||
| // 图片 | |||
| "bmp", "gif", "jpg", "jpeg", "png", | |||
| // 视频格式 | |||
| "mp4", "avi", "rmvb", "mkv", "wmv", "rm", "rmvb", "flv", "webm", | |||
| "pdf"}; | |||
| @@ -0,0 +1,46 @@ | |||
| package com.xueyi.common.redis.utils; | |||
| import com.alibaba.fastjson2.JSONObject; | |||
| import com.xueyi.common.core.utils.core.NumberUtil; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.data.redis.core.RedisTemplate; | |||
| import javax.annotation.PostConstruct; | |||
| import java.io.Serializable; | |||
| import java.util.List; | |||
| import java.util.concurrent.TimeUnit; | |||
| import java.util.stream.Collectors; | |||
| /** | |||
| * @author yk | |||
| * @description | |||
| * @date 2023-09-21 13:57 | |||
| */ | |||
| public class RedisUtil { | |||
| private static RedisTemplate<String, Serializable> redisTemplate; | |||
| @Autowired | |||
| RedisTemplate<String, Serializable> redisTemplate2; | |||
| @PostConstruct | |||
| public void init() { | |||
| redisTemplate = redisTemplate2; | |||
| } | |||
| public static Integer getNumberVal(String key) { | |||
| return NumberUtil.getNumber((Integer) redisTemplate.opsForValue().get(key)); | |||
| } | |||
| public static void expire(String key, int seconds) { | |||
| redisTemplate.expire(key, seconds, TimeUnit.SECONDS); | |||
| } | |||
| public static List<JSONObject> getJsonList(String key) { | |||
| return redisTemplate.opsForList().range(key, 0, -1).stream().map(json-> JSONObject.parseObject(json.toString())).collect(Collectors.toList()); | |||
| } | |||
| public static Boolean existed(String key){ | |||
| return redisTemplate.hasKey(key); | |||
| } | |||
| } | |||
| @@ -1,2 +1,3 @@ | |||
| com.xueyi.common.redis.configure.RedisConfig | |||
| com.xueyi.common.redis.service.RedisService | |||
| com.xueyi.common.redis.service.RedisService | |||
| com.xueyi.common.redis.utils.RedisUtil | |||
| @@ -15,6 +15,7 @@ import com.xueyi.common.core.web.validate.V_E; | |||
| import com.xueyi.common.datasource.annotation.Master; | |||
| import com.xueyi.common.log.annotation.Log; | |||
| import com.xueyi.common.log.enums.BusinessType; | |||
| import com.xueyi.common.redis.utils.RedisUtil; | |||
| import com.xueyi.common.security.annotation.InnerAuth; | |||
| import com.xueyi.common.security.annotation.RequiresPermissions; | |||
| import com.xueyi.common.web.entity.controller.BaseController; | |||
| @@ -66,6 +67,7 @@ import org.springframework.web.bind.annotation.RestController; | |||
| import java.io.Serializable; | |||
| import java.text.ParseException; | |||
| import java.time.Duration; | |||
| import java.util.ArrayList; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| import java.util.stream.Collectors; | |||
| @@ -405,40 +407,60 @@ public class DmDigitalmanController extends BaseController<DmDigitalmanQuery, Dm | |||
| serviceTimeCount += (System.currentTimeMillis() - dto.getActivateTime().getTime())/3600000; | |||
| } | |||
| Integer meetingServiceCount = (Integer) redisTemplate.opsForValue().get("dashboard:meeting"); | |||
| Integer serverTimes = (Integer) redisTemplate.opsForValue().get("dashboard:server"); | |||
| Integer recognition = (Integer) redisTemplate.opsForValue().get("dashboard:recognition"); | |||
| Integer receptionCount = (Integer) redisTemplate.opsForValue().get("dashboard:create_visitor_info"); | |||
| Integer visitorCount = (Integer) redisTemplate.opsForValue().get("dashboard:register_visitor"); | |||
| Integer attendanceCount = (Integer) redisTemplate.opsForValue().get("dashboard:attendance"); | |||
| Integer openDoorCount = (Integer) redisTemplate.opsForValue().get("dashboard:open_door"); | |||
| Integer conversationDuration = (Integer) redisTemplate.opsForValue().get("dashboard:conversation-duration"); | |||
| Integer conversationTimes = (Integer) redisTemplate.opsForValue().get("dashboard:conversation-times"); | |||
| Integer meetingServiceCount = RedisUtil.getNumberVal("dashboard:meeting"); | |||
| Integer serverTimes = RedisUtil.getNumberVal("dashboard:server"); | |||
| Integer recognition = RedisUtil.getNumberVal("dashboard:recognition"); | |||
| Integer receptionCount = RedisUtil.getNumberVal("dashboard:create_visitor_info"); | |||
| Integer visitorCount = RedisUtil.getNumberVal("dashboard:register_visitor"); | |||
| Integer attendanceCount = RedisUtil.getNumberVal("dashboard:attendance"); | |||
| Integer openDoorCount = RedisUtil.getNumberVal("dashboard:open_door"); | |||
| Integer conversationDuration = RedisUtil.getNumberVal("dashboard:conversation-duration"); | |||
| Integer conversationTimes = RedisUtil.getNumberVal("dashboard:conversation-times"); | |||
| Integer broadcastCount = RedisUtil.getNumberVal("dashboard:broadcast-count"); | |||
| List<JSONObject> knowledgeList = new ArrayList<>(); | |||
| if (RedisUtil.existed("dashboard:knowledge-consume")) { | |||
| knowledgeList = RedisUtil.getJsonList("dashboard:knowledge-consume"); | |||
| //取值后清除缓存list,5秒后过期 | |||
| RedisUtil.expire("dashboard:knowledge-consume", 5); | |||
| } | |||
| List<JSONObject> skillList = new ArrayList<>(); | |||
| if (RedisUtil.existed("dashboard:skill-consume")) { | |||
| skillList = RedisUtil.getJsonList("dashboard:skill-consume"); | |||
| //取值后清除缓存list,5秒后过期 | |||
| RedisUtil.expire("dashboard:skill-consume", 5); | |||
| } | |||
| JSONArray jsonArray = new JSONArray(); | |||
| // JSONArray jsonArray2 = new JSONArray(); | |||
| for (int i = 0; i < 7; i++) { | |||
| // 最近三十天的数据,服务人次,知识库增量 | |||
| for (int i = 0; i < 30; i++) { | |||
| Date date = DateUtils.addDays(new Date(), -i); | |||
| String dateStr2 = DateUtils.formatDate(date, "yyyy-MM-dd"); | |||
| JSONObject json2 = new JSONObject(); | |||
| json2.put("date", dateStr2); | |||
| json2.put("serviceTimes", (Integer) redisTemplate.opsForValue().get("dashboard:server-chart:"+dateStr2)); | |||
| json2.put("knowledgeNums", (Integer) redisTemplate.opsForValue().get("dashboard:server-chart:"+dateStr2)); | |||
| json2.put("serviceTimes", RedisUtil.getNumberVal("dashboard:server-chart:"+dateStr2)); | |||
| json2.put("knowledgeNums", RedisUtil.getNumberVal("dashboard:server-chart:"+dateStr2)); | |||
| jsonArray.add(json2); | |||
| } | |||
| JSONObject json = new JSONObject(); | |||
| json.put("manCount",dtos2.size()); | |||
| json.put("chatTimes",conversationTimes); | |||
| json.put("chatDurationCount",conversationDuration); | |||
| json.put("serviceTimeCount",serviceTimeCount); | |||
| json.put("servicePerCount",serverTimes); | |||
| json.put("recognizedPersonCount",recognition); | |||
| json.put("meetingServiceCount",meetingServiceCount); | |||
| json.put("receptionCount",receptionCount); | |||
| json.put("visitorCount",visitorCount); | |||
| json.put("attendanceCount",attendanceCount); | |||
| json.put("openDoorCount",openDoorCount); | |||
| json.put("serverCharts",jsonArray); | |||
| json.put("manCount",dtos2.size());//数字人数 | |||
| json.put("recognizedPersonCount", recognition);//注册人员总数 | |||
| json.put("serviceTimeCount",serviceTimeCount);//总服务时间 | |||
| json.put("chatTimes",conversationTimes);//对话次数 | |||
| json.put("chatDurationCount",conversationDuration);//对话时长 | |||
| json.put("servicePerCount",serverTimes);//用户使用频次?改成服务人次 | |||
| json.put("serviceTotal",meetingServiceCount+receptionCount+visitorCount+attendanceCount+openDoorCount+broadcastCount); | |||
| json.put("meetingServiceCount", meetingServiceCount);//会议 | |||
| json.put("receptionCount",receptionCount);//接待 | |||
| json.put("visitorCount",visitorCount);//访客 | |||
| json.put("attendanceCount",attendanceCount);//考勤 | |||
| json.put("openDoorCount",openDoorCount);//门禁 | |||
| json.put("broadcastCount",broadcastCount);//播报 | |||
| json.put("knowledgeConsume",knowledgeList);//实时知识库调用 | |||
| json.put("skillConsume",skillList);//实时技能调用 | |||
| json.put("serverCharts",jsonArray);// | |||
| log.info(json.toJSONString()); | |||
| return R.ok(json); | |||
| } | |||
| @@ -68,14 +68,14 @@ public class DmBroadcastManager extends BaseManagerImpl<DmBroadcastQuery, DmBroa | |||
| log.info("editBroadcastResourceMerge newList:{}",newList); | |||
| idList.removeAll(newList);//从原图片列表中取新列表的差集进行删除 | |||
| // idList.removeAll(newList);//从原图片列表中取新列表的差集进行删除 | |||
| //批量删除 | |||
| if (idList.size() > 0) { | |||
| broadcastResourceMergeMapper.deleteBatchIds(idList); | |||
| } | |||
| //批量更新 | |||
| //批量新增 | |||
| if (broadcastResourceMerges.size() > 0) { | |||
| broadcastResourceMergeMapper.updateBatch(broadcastResourceMerges); | |||
| broadcastResourceMergeMapper.insertBatch(broadcastResourceMerges); | |||
| } | |||
| } | |||
| @@ -138,6 +138,8 @@ public class DmResourcesController extends BaseController<DmResourcesQuery, DmRe | |||
| private static final String PARAM_RESOURCE_ID = "resource_id"; | |||
| private static final String PARAM_URL = "url"; | |||
| private static final String PARAM_TYPE = "type"; | |||
| /** | |||
| * 头像上传 | |||
| */ | |||
| @@ -146,37 +148,65 @@ public class DmResourcesController extends BaseController<DmResourcesQuery, DmRe | |||
| public AjaxResult upload(@RequestParam("file") MultipartFile file) { | |||
| if (!file.isEmpty()) { | |||
| String extension = FileTypeUtil.getExtension(file); | |||
| if (!CharSequenceUtil.equalsAnyIgnoreCase(extension, MimeTypeUtil.IMAGE_EXTENSION) | |||
| && !CharSequenceUtil.equalsAnyIgnoreCase(extension, MimeTypeUtil.VIDEO_EXTENSION)) { | |||
| return error("文件格式不正确,请上传" + Arrays.toString(MimeTypeUtil.IMAGE_EXTENSION) + Arrays.toString(MimeTypeUtil.IMAGE_EXTENSION) + "格式"); | |||
| logger.info("文件类型:" + extension+",上传开始..."); | |||
| if (!CharSequenceUtil.equalsAnyIgnoreCase(extension, MimeTypeUtil.EXCEPT_ALLOWED_EXTENSION)) { | |||
| return error("文件格式不正确,请上传" + Arrays.toString(MimeTypeUtil.EXCEPT_ALLOWED_EXTENSION) + "格式"); | |||
| } | |||
| R<SysFile> fileResult = remoteFileService.upload(file); | |||
| if (ObjectUtil.isNull(fileResult) || ObjectUtil.isNull(fileResult.getData())) | |||
| return error("文件服务异常,请联系管理员!"); | |||
| String url = fileResult.getData().getUrl(); | |||
| // 预留人脸识别与图像质量监测接口,如果监测异常返回错误 | |||
| DmResourcesDto dto = new DmResourcesDto(); | |||
| dto.setName(file.getOriginalFilename()); | |||
| dto.setUrl(url); | |||
| if (CharSequenceUtil.equalsAnyIgnoreCase(extension, MimeTypeUtil.IMAGE_EXTENSION) ) { | |||
| dto.setType(DmResourcesPo.TYPE_PIC); | |||
| } | |||
| if (CharSequenceUtil.equalsAnyIgnoreCase(extension, MimeTypeUtil.VIDEO_EXTENSION)) { | |||
| dto.setType(DmResourcesPo.TYPE_VIDEO); | |||
| } | |||
| dto.setFileSize(fileResult.getData().getSize()); | |||
| if(MimeTypeUtil.PDF_EXTENSION.equalsIgnoreCase(extension)) { | |||
| R<List<SysFile>> fileResult = remoteFileService.uploadPdf(file); | |||
| if (ObjectUtil.isNull(fileResult) || ObjectUtil.isNull(fileResult.getData())) | |||
| return error("文件服务异常,请联系管理员!"); | |||
| JSONArray ja = new JSONArray(); | |||
| for (SysFile sf : fileResult.getData()) { | |||
| String url = sf.getUrl(); | |||
| DmResourcesDto dto = new DmResourcesDto(); | |||
| dto.setName(file.getOriginalFilename()); | |||
| dto.setUrl(url); | |||
| dto.setType(DmResourcesPo.TYPE_PIC); | |||
| dto.setFileSize(sf.getSize()); | |||
| iDmResourcesService.addOne(dto); | |||
| JSONObject jo = new JSONObject(); | |||
| jo.put(PARAM_RESOURCE_ID, dto.getId()); | |||
| jo.put(PARAM_URL, url); | |||
| iDmResourcesService.addOne(dto); | |||
| JSONObject jo = new JSONObject(); | |||
| jo.put(PARAM_RESOURCE_ID, dto.getId()); | |||
| jo.put(PARAM_URL, url); | |||
| jo.put(PARAM_TYPE, dto.getType()); | |||
| ja.add(jo); | |||
| } | |||
| AjaxResult ajax = success(); | |||
| ajax.put(AjaxResult.RESULT_TAG, ja); | |||
| logger.info("上传文件成功,返回数据:" + ajax.toJson().toJSONString()); | |||
| return ajax; | |||
| } else { | |||
| R<SysFile> fileResult = remoteFileService.upload(file); | |||
| if (ObjectUtil.isNull(fileResult) || ObjectUtil.isNull(fileResult.getData())) | |||
| return error("文件服务异常,请联系管理员!"); | |||
| String url = fileResult.getData().getUrl(); | |||
| DmResourcesDto dto = new DmResourcesDto(); | |||
| dto.setName(file.getOriginalFilename()); | |||
| dto.setUrl(url); | |||
| if (CharSequenceUtil.equalsAnyIgnoreCase(extension, MimeTypeUtil.IMAGE_EXTENSION) ) { | |||
| dto.setType(DmResourcesPo.TYPE_PIC); | |||
| } | |||
| if (CharSequenceUtil.equalsAnyIgnoreCase(extension, MimeTypeUtil.VIDEO_EXTENSION)) { | |||
| dto.setType(DmResourcesPo.TYPE_VIDEO); | |||
| } | |||
| dto.setFileSize(fileResult.getData().getSize()); | |||
| iDmResourcesService.addOne(dto); | |||
| JSONObject jo = new JSONObject(); | |||
| jo.put(PARAM_RESOURCE_ID, dto.getId()); | |||
| jo.put(PARAM_URL, url); | |||
| jo.put(PARAM_TYPE, dto.getType()); | |||
| AjaxResult ajax = success(); | |||
| ajax.put(AjaxResult.RESULT_TAG, jo); | |||
| logger.info("上传文件成功,返回数据:" + ajax.toJson().toJSONString()); | |||
| return ajax; | |||
| } | |||
| AjaxResult ajax = success(); | |||
| ajax.put(AjaxResult.RESULT_TAG, jo); | |||
| return ajax; | |||
| } | |||
| return error("上传图片异常,请联系管理员!"); | |||
| return error("上传文件异常,请联系管理员!"); | |||
| } | |||
| /** | |||
| @@ -215,7 +245,7 @@ public class DmResourcesController extends BaseController<DmResourcesQuery, DmRe | |||
| ajax.put(AjaxResult.RESULT_TAG, ja); | |||
| return ajax; | |||
| } | |||
| return error("上传图片异常,请联系管理员!"); | |||
| return error("上传PDF文件异常,请联系管理员!"); | |||
| } | |||
| /** | |||