This commit is contained in:
aikai 2024-06-12 20:13:19 +08:00
commit bbc8e4c6a6
27 changed files with 506 additions and 165 deletions

View File

@ -14,6 +14,9 @@ import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.github.yulichang.toolkit.SpringContentUtils;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionSynchronization;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.web.socket.WebSocketSession;
import javax.annotation.Resource;
@ -40,6 +43,7 @@ public class AttendanceWebSocketMessageListener implements WebSocketMessageListe
private AttendanceMachineApi attendanceMachineApi;
@Override
@Transactional(rollbackFor = Exception.class)
public void onMessage(WebSocketSession session, AttendanceSendMessage message) {
StringRedisTemplate redisTemplate = SpringContentUtils.getBean(StringRedisTemplate.class);
@ -91,46 +95,55 @@ public class AttendanceWebSocketMessageListener implements WebSocketMessageListe
}
if (object1.get("cmd").equals(AttendanceConstants.CMD_TO_CLIENT)) {
System.out.println("进来了"+ System.currentTimeMillis());
// 获取响应数据
DeviceResponseDTO dto = JsonUtils.parseObject2(object1.get("data").toString(), DeviceResponseDTO.class);
// 获取设备号
String deviceNo = object1.get("from").toString();
String requestId = object1.get("extra").toString().split("_")[0];
String userId = object1.get("extra").toString().split("_")[1];
if (dto != null) {
// 更新下发数据
AttendanceUpdateDTO attendanceUpdateDTO = new AttendanceUpdateDTO();
List<DistributeRecordDTO> recordDTOs = new ArrayList<>();
// 更新下发记录表
if (dto.getDelFailed() == null) {
// 在事务提交后更新下发记录
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
@Override
public void afterCommit() {
DistributeRecordDTO recordDTO = new DistributeRecordDTO();
recordDTO.setCode(dto.getCode());
recordDTO.setResult(dto.getMsg());
recordDTO.setUserId(dto.getUserId() == null ? Long.valueOf(userId) : Long.valueOf(dto.getUserId()));
recordDTO.setRequestId(requestId);
recordDTO.setUpdater(userId);
recordDTOs.add(recordDTO);
}else {
List<DistributeRecordDTO> recordDTOs = new ArrayList<>();
// 更新下发记录表
for (DeviceResponseDTO.DeleteUser info : dto.getDelFailed()) {
// 更新下发记录表
if (dto.getDelFailed() == null) {
DistributeRecordDTO deleteRecord = new DistributeRecordDTO();
deleteRecord.setCode(info.getCode());
deleteRecord.setResult(info.getMsg());
deleteRecord.setUserId(Long.valueOf(info.getUserId()));
deleteRecord.setRequestId(requestId);
deleteRecord.setUpdater(userId);
recordDTOs.add(deleteRecord);
DistributeRecordDTO recordDTO = new DistributeRecordDTO();
recordDTO.setCode(dto.getCode());
recordDTO.setResult(dto.getMsg());
recordDTO.setUserId(dto.getUserId() == null ? Long.valueOf(userId) : Long.valueOf(dto.getUserId()));
recordDTO.setRequestId(requestId);
recordDTO.setUpdater(userId);
recordDTOs.add(recordDTO);
} else {
// 更新下发记录表
for (DeviceResponseDTO.DeleteUser info : dto.getDelFailed()) {
DistributeRecordDTO deleteRecord = new DistributeRecordDTO();
deleteRecord.setCode(info.getCode());
deleteRecord.setResult(info.getMsg());
deleteRecord.setUserId(Long.valueOf(info.getUserId()));
deleteRecord.setRequestId(requestId);
deleteRecord.setUpdater(userId);
recordDTOs.add(deleteRecord);
}
}
// 更新下发记录表
attendanceMachineApi.updateDistributeRecord(recordDTOs);
}
}
// 更新下发记录表
attendanceMachineApi.updateDistributeRecord(recordDTOs);
});
// 响应失败的情况
if (dto.getCode() != 0) {
@ -139,8 +152,8 @@ public class AttendanceWebSocketMessageListener implements WebSocketMessageListe
webSocketMessageSender.sendObject(object1.get("to").toString(), "attendance-message-send", object1);
}else {
redisTemplate.opsForValue().set(object1.get("from").toString() + "msg", dto.getCode() + "_" + dto.getMsg(), 30, TimeUnit.SECONDS);
redisTemplate.opsForValue().set(object1.get("from").toString(), "false", 30, TimeUnit.SECONDS);
redisTemplate.opsForValue().set(deviceNo + "msg", dto.getCode() + "_" + dto.getMsg(), 30, TimeUnit.SECONDS);
redisTemplate.opsForValue().set(deviceNo, "false", 30, TimeUnit.SECONDS);
}
return;
@ -151,20 +164,20 @@ public class AttendanceWebSocketMessageListener implements WebSocketMessageListe
case "addUserRet":
// 更新设备绑定用户信息
attendanceUpdateDTO.setUserId(Collections.singletonList(Long.valueOf(dto.getUserId())));
attendanceUpdateDTO.setDeviceNo(object1.get("from").toString());
attendanceUpdateDTO.setDeviceNo(deviceNo);
attendanceUpdateDTO.setMethod(0);
// 更新设备绑定用户信息
attendanceMachineApi.updateAttendance(attendanceUpdateDTO);
break;
case "delMultiUserRet":
List<String> userIds = JsonUtils.parseArray(redisTemplate.opsForValue().get(object1.get("from").toString()), String.class);
List<String> userIds = JsonUtils.parseArray(redisTemplate.opsForValue().get(deviceNo), String.class);
if (dto.getDelFailed() != null) {
userIds.removeAll(convertList(dto.getDelFailed(), DeviceResponseDTO.DeleteUser::getUserId));
}
// 更新设备绑定用户信息
attendanceUpdateDTO.setUserId(userIds.stream().map(Long::valueOf).collect(Collectors.toList()));
attendanceUpdateDTO.setDeviceNo(object1.get("from").toString());
attendanceUpdateDTO.setDeviceNo(deviceNo);
attendanceUpdateDTO.setMethod(1);
// 更新设备绑定用户信息
@ -172,20 +185,24 @@ public class AttendanceWebSocketMessageListener implements WebSocketMessageListe
break;
case "setPasswordRet":
// 更新设备密码
String value = redisTemplate.opsForValue().get(object1.get("from").toString());
String value = redisTemplate.opsForValue().get(deviceNo);
if (value != null) {
String oldPassword = value.split("-")[0];
String newPassword = value.split("-")[1];
attendanceMachineApi.updateDevicePassword(object1.get("from").toString(), oldPassword, newPassword);
attendanceMachineApi.updateDevicePassword(deviceNo, oldPassword, newPassword);
}
break;
}
redisTemplate.delete(object1.get("from").toString());
redisTemplate.delete(deviceNo);
}
if (!object1.get("to").toString().isEmpty()) {
webSocketMessageSender.sendObject(object1.get("to").toString(), "attendance-message-send", object1);
}
}
}

View File

@ -1,8 +1,9 @@
package cn.iocoder.yudao.module.system.service.equipment;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.dal.dataobject.equipment.DistributeRecordDO;
import cn.iocoder.yudao.module.system.dal.mysql.equipment.DistributeRecordMapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@ -34,8 +35,11 @@ public class DistributeRecordServiceImpl implements DistributeRecordService {
for (DistributeRecordDO updateDO : updateReqVO) {
distributeRecordMapper.update(updateDO,
new LambdaQueryWrapperX<DistributeRecordDO>()
DistributeRecordDO updateVO = BeanUtils.toBean(updateDO, DistributeRecordDO.class);
updateVO.setRequestId(null);
updateVO.setUserId(null);
distributeRecordMapper.update(updateVO,
new LambdaUpdateWrapper<DistributeRecordDO>()
.eq(DistributeRecordDO::getUserId, updateDO.getUserId())
.eq(DistributeRecordDO::getRequestId, updateDO.getRequestId()));
}

View File

@ -57,7 +57,7 @@ public interface UsersExtService {
/**
* 删除用户人脸信息
*/
String deleteUser(Long userId);
void deleteUser(Long userId);
/**
* 获得用户信息拓展

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.system.service.equipment;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.json.JSONObject;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
@ -28,7 +29,9 @@ import cn.iocoder.yudao.module.system.service.user.AdminUserService;
import cn.iocoder.yudao.module.system.service.websocket.WebsocketService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.github.yulichang.toolkit.SpringContentUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@ -197,7 +200,7 @@ public class UsersExtServiceImpl implements UsersExtService {
}
@Override
public String deleteUser(Long userId) {
public void deleteUser(Long userId) {
//校验 当前用户人脸信息是否已存在
UsersExtDO usersExtDO = usersExtMapper.selectOne(UsersExtDO::getUserId, userId);
@ -214,17 +217,14 @@ public class UsersExtServiceImpl implements UsersExtService {
.setCmd("delMultiUser")
.setUser_ids(new String[]{String.valueOf(usersExtDO.getUserId())});
try {
for (String deviceNo : deviceNos) {
// 删除的用户Id 存在redis中
StringRedisTemplate redisTemplate = SpringContentUtils.getBean(StringRedisTemplate.class);
for (String deviceNo : deviceNos) {
websocketService.sendSn(deviceNo, userVO, 0);
}
} catch (RuntimeException ex) {
return ex.getMessage();
redisTemplate.opsForValue().set(deviceNo, new JSONObject(userVO).get("user_ids").toString());
websocketService.sendSn(deviceNo, userVO, 0);
}
}
return null;
}
private void validateUsersExtExists(Long userId) {

View File

@ -21,6 +21,7 @@ import org.springframework.context.annotation.Lazy;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import javax.annotation.Resource;
import java.util.List;
@ -85,7 +86,7 @@ public class FactoryUserServiceImpl implements FactoryUserService{
AdminUserDO user = BeanUtils.toBean(createReqVO, AdminUserDO.class);
user.setDeptId(deptDO.getId());
user.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 默认开启
user.setPassword(encodePassword("123456")); // 设置默认密码
user.setPassword(encodePassword()); // 设置默认密码
user.setUserType(2); // 设置用户类型为 工厂用户
userMapper.insert(user);
@ -114,8 +115,10 @@ public class FactoryUserServiceImpl implements FactoryUserService{
// 发送指令至 考勤设备 下发员工
websocketService.sendSn(machineDO.getDeviceNo(), addUserVO, 1);
}
} catch (RuntimeException ex) {
} catch (Exception ex) {
// 手动回滚
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ex.getMessage();
}
@ -183,8 +186,10 @@ public class FactoryUserServiceImpl implements FactoryUserService{
// 发送指令至 考勤设备 修改员工信息
websocketService.sendSn(machineDO.getDeviceNo(), addUserVO, 1);
}
}catch (RuntimeException ex) {
}catch (Exception ex) {
// 手动回滚
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ex.getMessage();
}
@ -202,7 +207,16 @@ public class FactoryUserServiceImpl implements FactoryUserService{
userMapper.deleteById(id);
// 同步删除用户拓展信息
return usersExtService.deleteUser(id);
try {
usersExtService.deleteUser(id);
} catch (Exception ex) {
// 手动回滚
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ex.getMessage();
}
return null;
}
private void validateId(Long id) {
@ -215,10 +229,9 @@ public class FactoryUserServiceImpl implements FactoryUserService{
/**
* 对密码进行加密
*
* @param password 密码
* @return 加密后的密码
*/
private String encodePassword(String password) {
return passwordEncoder.encode(password);
private String encodePassword() {
return passwordEncoder.encode("123456");
}
}

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.system.service.websocket;
import cn.hutool.json.JSONObject;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
import cn.iocoder.yudao.module.infra.api.websocket.WebSocketSenderApi;
@ -11,7 +12,6 @@ import com.xingyuv.http.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.Collections;
@ -47,11 +47,13 @@ public class WebsocketServiceImpl implements WebsocketService{
.setExtra(requestId + "_" + getLoginUserId())
.setData(data);
JSONObject dataJson = new JSONObject(data);
// 设置 设备下发记录
DistributeRecordDO recordDO = new DistributeRecordDO();
recordDO.setRequestId(requestId);
recordDO.setDeviceNo(deviceNo);
recordDO.setUserId(getLoginUserId());
recordDO.setUserId(dataJson.get("user_id") == null ? getLoginUserId() : Long.valueOf(dataJson.get("user_id").toString()));
recordDO.setType(type);
recordDO.setResult("通讯失败");
@ -60,7 +62,10 @@ public class WebsocketServiceImpl implements WebsocketService{
// 设备租户ID
TenantContextHolder.setTenantId(1L);
stringRedisTemplate.opsForValue().set(deviceNo, "true");
if (StringUtil.isEmpty(stringRedisTemplate.opsForValue().get(deviceNo))) {
stringRedisTemplate.opsForValue().set(deviceNo, "true");
}
// 发送修改密码命令给设备
webSocketSenderApi.sendSN(deviceNo, "attendance-message-send", JsonUtils.toJsonString(baseVO));
@ -88,6 +93,7 @@ public class WebsocketServiceImpl implements WebsocketService{
}
Long currentTime = System.currentTimeMillis();
if (currentTime - startTime > 30000) {
throw exception(REQUEST_FAILURE);
}
}

View File

@ -73,6 +73,7 @@
) read_user ON user.id = read_user.user_id
WHERE
user.deleted = 0
AND user.status = 0
AND read_user.data_scope != 5
) result
WHERE

View File

@ -1,32 +1,37 @@
package cn.iocoder.yudao.module.smartfactory.controller.admin.device.cameradevice;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;
import cn.iocoder.yudao.module.smartfactory.controller.admin.device.cameradevice.vo.*;
import cn.iocoder.yudao.module.smartfactory.controller.admin.device.cameradevice.vo.CameraDevicePageReqVO;
import cn.iocoder.yudao.module.smartfactory.controller.admin.device.cameradevice.vo.CameraDeviceRespVO;
import cn.iocoder.yudao.module.smartfactory.controller.admin.device.cameradevice.vo.CameraDeviceSaveReqVO;
import cn.iocoder.yudao.module.smartfactory.controller.admin.device.cameradevice.vo.CameraUpdateStatusReqVO;
import cn.iocoder.yudao.module.smartfactory.controller.admin.factoryinfo.vo.FactorySimpleRespVO;
import cn.iocoder.yudao.module.smartfactory.controller.admin.factoryinfo.vo.FactoryTreeRespVO;
import cn.iocoder.yudao.module.smartfactory.convert.cameradevice.CameraDeviceConvert;
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.device.cameradevice.CameraDeviceDO;
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.factoryinfo.FactoryInfoDO;
import cn.iocoder.yudao.module.smartfactory.service.device.cameradevice.CameraDeviceService;
import cn.iocoder.yudao.module.smartfactory.service.factoryinfo.FactoryInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
@Tag(name = "管理后台 - 设备-监控摄像头")
@RestController
@ -37,6 +42,9 @@ public class CameraDeviceController {
@Resource
private CameraDeviceService cameraDeviceService;
@Resource
private FactoryInfoService factoryInfoService;
@PostMapping("/create")
@Operation(summary = "创建设备-监控摄像头")
@PreAuthorize("@ss.hasPermission('smartfactory:camera-device:create')")
@ -52,6 +60,15 @@ public class CameraDeviceController {
return success(true);
}
@PutMapping("/update-status")
@Operation(summary = "更新设备-监控摄像头状态")
@PreAuthorize("@ss.hasPermission('smartfactory:camera-device:update')")
public CommonResult<Boolean> updateCameraDevice(@Valid @RequestBody CameraUpdateStatusReqVO updateReqVO) {
cameraDeviceService.updateCameraDeviceStatus(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除设备-监控摄像头")
@Parameter(name = "id", description = "编号", required = true)
@ -74,21 +91,58 @@ public class CameraDeviceController {
@Operation(summary = "获得设备-监控摄像头分页")
@PreAuthorize("@ss.hasPermission('smartfactory:camera-device:query')")
public CommonResult<PageResult<CameraDeviceRespVO>> getCameraDevicePage(@Valid CameraDevicePageReqVO pageReqVO) {
PageResult<CameraDeviceDO> pageResult = cameraDeviceService.getCameraDevicePage(pageReqVO);
return success(BeanUtils.toBean(pageResult, CameraDeviceRespVO.class));
PageResult<CameraDeviceRespVO> pageData = BeanUtils.toBean(pageResult, CameraDeviceRespVO.class);
List<CameraDeviceRespVO> pageList = pageData.getList();
// 获得工厂信息
List<FactoryInfoDO> factoryInfoDOS = factoryInfoService.getFactoryList(convertList(pageList, CameraDeviceRespVO::getFactoryId));
Map<Long, FactoryInfoDO> factoryMap = convertMap(factoryInfoDOS, FactoryInfoDO::getId);
pageList.forEach(data -> {
data.setFactoryName(factoryMap.get(data.getFactoryId()).getName());
});
return success(pageData);
}
@GetMapping("/export-excel")
@Operation(summary = "导出设备-监控摄像头 Excel")
@PreAuthorize("@ss.hasPermission('smartfactory:camera-device:export')")
@OperateLog(type = EXPORT)
public void exportCameraDeviceExcel(@Valid CameraDevicePageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<CameraDeviceDO> list = cameraDeviceService.getCameraDevicePage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "设备-监控摄像头.xls", "数据", CameraDeviceRespVO.class,
BeanUtils.toBean(list, CameraDeviceRespVO.class));
}
@GetMapping("/camera-tree")
@Operation(summary = "获得设备-监控摄像头Tree")
@PreAuthorize("@ss.hasPermission('smartfactory:camera-device:query')")
public CommonResult<FactoryTreeRespVO> getCameraDeviceTree() {
FactoryTreeRespVO data = new FactoryTreeRespVO();
List<FactorySimpleRespVO> info = new ArrayList<>();
// 获取工厂信息
List<FactoryInfoDO> factoryInfo = factoryInfoService.getFactoryList();
List<Long> factoryIds = convertList(factoryInfo, FactoryInfoDO::getId);
// 获取监控设备信息
List<CameraDeviceDO> cameraDeviceDOS = cameraDeviceService.getListCameraList(factoryIds);
Map<Long, List<CameraDeviceDO>> cameraMap = cameraDeviceDOS.stream().collect(Collectors.groupingBy(CameraDeviceDO::getFactoryId));
if (!CollUtil.isEmpty(factoryInfo)) {
Map<String, List<FactoryInfoDO>> infoDOMap = factoryInfo.stream().collect(Collectors.groupingBy(FactoryInfoDO::getType));
for (String key : infoDOMap.keySet()) {
switch (key) {
case "1":
data = BeanUtils.toBean(infoDOMap.get(key).get(0), FactoryTreeRespVO.class);
break;
case "2":
info.addAll(0, CameraDeviceConvert.INSTANCE.convertList(infoDOMap.get(key), cameraMap));
break;
case "3":
info.addAll(CameraDeviceConvert.INSTANCE.convertList(infoDOMap.get(key), cameraMap));
break;
}
}
data.setSubsidiary(info);
}
return success(data);
}
}

View File

@ -19,6 +19,9 @@ public class CameraDeviceRespVO {
@ExcelProperty("工厂id")
private Long factoryId;
@Schema(description = "工厂名称")
private String factoryName;
@Schema(description = "设备名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
@ExcelProperty("设备名称")
private String name;

View File

@ -38,6 +38,9 @@ public class CameraDeviceSaveReqVO {
@Schema(description = "流媒体地址", example = "https://www.iocoder.cn")
private String streamUrl;
@Schema(description = "排序")
private Integer sort;
@Schema(description = "是否在大屏显示 0否 1是", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "是否在大屏显示 0否 1是不能为空")
private Integer isShow;

View File

@ -0,0 +1,22 @@
package cn.iocoder.yudao.module.smartfactory.controller.admin.device.cameradevice.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "管理后台 - 设备-监控摄像头 Response VO")
@Data
public class CameraSimpleRespVO {
@Schema(description = "工厂id", requiredMode = Schema.RequiredMode.REQUIRED, example = "32023")
@ExcelProperty("工厂id")
private Long factoryId;
@Schema(description = "设备名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
@ExcelProperty("设备名称")
private String name;
@Schema(description = "设备编号", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("设备编号")
private String code;
}

View File

@ -0,0 +1,23 @@
package cn.iocoder.yudao.module.smartfactory.controller.admin.device.cameradevice.vo;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - 监控设备更新状态 Request VO")
@Data
public class CameraUpdateStatusReqVO {
@Schema(description = "设备编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@NotNull(message = "设备编号不能为空")
private Long id;
@Schema(description = "状态,见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "状态不能为空")
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
private Integer status;
}

View File

@ -1,19 +1,16 @@
package cn.iocoder.yudao.module.smartfactory.controller.admin.factoryinfo;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.smartfactory.controller.admin.factoryinfo.vo.FactoryInfoPageReqVO;
import cn.iocoder.yudao.module.smartfactory.controller.admin.factoryinfo.vo.FactoryInfoRespVO;
import cn.iocoder.yudao.module.smartfactory.controller.admin.factoryinfo.vo.FactoryInfoSaveReqVO;
import cn.iocoder.yudao.module.smartfactory.controller.admin.factoryinfo.vo.FactorySimpleRespVO;
import cn.iocoder.yudao.module.smartfactory.controller.admin.factoryinfo.vo.*;
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.factoryinfo.FactoryInfoDO;
import cn.iocoder.yudao.module.smartfactory.service.factoryinfo.FactoryInfoService;
import cn.iocoder.yudao.module.system.api.dict.DictDataApi;
import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -25,10 +22,9 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@ -43,9 +39,6 @@ public class FactoryInfoController {
@Resource
private FactoryInfoService factoryInfoService;
@Resource
private DictDataApi dictDataApi;
@PostMapping("/create")
@Operation(summary = "创建工厂信息")
@PreAuthorize("@ss.hasPermission('smartfactory:factory-info:create')")
@ -100,36 +93,32 @@ public class FactoryInfoController {
@GetMapping("/get-tree")
@Operation(summary = "获得工厂树结构")
@PreAuthorize("@ss.hasPermission('smartfactory:factory-info:query')")
public CommonResult<Map<FactorySimpleRespVO, Map<String, List<FactorySimpleRespVO>>>> getFactoryTree() {
public CommonResult<FactoryTreeRespVO> getFactoryTree() {
Map<FactorySimpleRespVO, Map<String, List<FactorySimpleRespVO>>> data = new HashMap<>();
FactoryTreeRespVO data = new FactoryTreeRespVO();
List<FactorySimpleRespVO> info = new ArrayList<>();
List<FactoryInfoDO> factoryInfo = factoryInfoService.getFactoryList();
if (!CollUtil.isEmpty(factoryInfo)) {
// 获取所有工厂类型
List<DictDataRespDTO> dictDataDTOs = dictDataApi.getDictDataList("sf_factory_type").getCheckedData();
Map<String, List<FactoryInfoDO>> infoDOMap = factoryInfo.stream().collect(Collectors.groupingBy(FactoryInfoDO::getType));
for (String key : infoDOMap.keySet()) {
Map<String, List<FactorySimpleRespVO>> subdataMap = new HashMap<>();
for (DictDataRespDTO dto : dictDataDTOs) {
if (!"1".equals(dto.getValue())) {
List<FactorySimpleRespVO> subData = BeanUtils.toBean(
factoryInfo.stream().filter(info -> info.getType().equals(dto.getValue())).collect(Collectors.toList()),
FactorySimpleRespVO.class);
subdataMap.put(dto.getLabel(), subData);
switch (key) {
case "1":
data = BeanUtils.toBean(infoDOMap.get(key).get(0), FactoryTreeRespVO.class);
break;
case "2":
info.addAll(0, BeanUtils.toBean(infoDOMap.get(key), FactorySimpleRespVO.class));
break;
case "3":
info.addAll(BeanUtils.toBean(infoDOMap.get(key), FactorySimpleRespVO.class));
break;
}
}
data.setSubsidiary(info);
}
// 获得type为1 即总公司的工厂信息
Optional<FactoryInfoDO> factoryInfoDO = factoryInfo.stream().filter(info -> "1".equals(info.getType())).findFirst();
FactorySimpleRespVO headOfficeVO = BeanUtils.toBean(
factoryInfoDO.orElse(null), FactorySimpleRespVO.class);
data.put(headOfficeVO, subdataMap);
return success(data);
}
@ -153,5 +142,4 @@ public class FactoryInfoController {
ExcelUtils.write(response, "工厂信息.xls", "数据", FactoryInfoRespVO.class,
BeanUtils.toBean(list, FactoryInfoRespVO.class));
}
}

View File

@ -1,9 +1,12 @@
package cn.iocoder.yudao.module.smartfactory.controller.admin.factoryinfo.vo;
import cn.iocoder.yudao.module.smartfactory.controller.admin.device.cameradevice.vo.CameraSimpleRespVO;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
@Schema(description = "管理后台 - 工厂信息 Response VO")
@Data
@ExcelIgnoreUnannotated
@ -17,4 +20,7 @@ public class FactorySimpleRespVO {
@Schema(description = "工厂简称", requiredMode = Schema.RequiredMode.REQUIRED, example = "第一工厂")
private String shortName;
@Schema(description = "监控列表")
private List<CameraSimpleRespVO> subsidiary;
}

View File

@ -0,0 +1,23 @@
package cn.iocoder.yudao.module.smartfactory.controller.admin.factoryinfo.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
@Schema(description = "管理后台 - 工厂信息数结构 Response VO")
@Data
public class FactoryTreeRespVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "28794")
private Long id;
@Schema(description = "工厂名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "江西省南昌市第一工厂")
private String name;
@Schema(description = "工厂简称", requiredMode = Schema.RequiredMode.REQUIRED, example = "第一工厂")
private String shortName;
@Schema(description = "列表")
private List<FactorySimpleRespVO> subsidiary;
}

View File

@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
/**
* 工厂管理-工厂列表
@ -28,6 +29,7 @@ public class HikController {
@GetMapping("/getCameraUrl")
@Operation(summary = "视频播放->查询播放地址")
@PermitAll
public CommonResult<String> getCameraUrl(String cameraCode) {
String url = hikService.getPreviewUrlsApi(cameraCode, 0);
return CommonResult.success(url);
@ -35,6 +37,7 @@ public class HikController {
@GetMapping("/replayUrl")
@Operation(summary = "视频播放->回放流")
@PermitAll
public CommonResult<JSONObject> getReplayUrl(CameraReplayDTO cameraReplayDTO) {
JSONObject replayUrl = hikService.getReplayUrl(cameraReplayDTO);
return CommonResult.success(replayUrl);
@ -42,9 +45,10 @@ public class HikController {
@GetMapping("/operate")
@Operation(summary = "视频->云台操作")
@PermitAll
public CommonResult<String> operate(CameraOperateDTO dto) {
//判断操作权限
Long cameraFactoryId = dto.getFactoryId();
// Long cameraFactoryId = dto.getFactoryId();
// Long userFactoryId = SecurityUtils.getFactoryId();
// if (cameraFactoryId == null || userFactoryId == null) {
// throw new ServiceException("没有权限操控该摄像头,请联系管理员");

View File

@ -62,11 +62,12 @@ public class FactoryScreenDataController {
}
@GetMapping("/getFactoryOperateData")
@Operation(summary = "大屏工厂运营数据 调用接口 http://znkj.ispt.com.cn/prod-api/screen/detail/dateList?factoryId=10000011")
@Operation(summary = "大屏工厂数据分析")
@OperateLog(enable = false) // 避免 Post 请求被记录操作日志
@PermitAll
public CommonResult<OperateDataRespVO> getFactoryOperateData(@RequestParam Long factoryId) {
OperateDataRespVO factoryOperateDataRespVO = screenDataService.getFactoryOperateData(factoryId);
public CommonResult<List<ScreenTotalDataVO>> getFactoryOperateData(@RequestParam Long factoryId) {
List<ScreenTotalDataVO> factoryOperateDataRespVO = screenDataService.getFactoryOperateData(factoryId);
return success(factoryOperateDataRespVO);
}

View File

@ -6,8 +6,6 @@ import lombok.Data;
/**
* 功能描述
*
* @author: yj
* @date: 2024年03月05日 13:55
*/
@Schema(description = "大屏数据 - 工厂摄像头数据 Response VO")
@Data
@ -28,9 +26,6 @@ public class FactoryCameraDataRespVO {
@Schema(description = "设备类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
private Integer type;
@Schema(description = "设备图片", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://xx.com/ss.jpg")
private String imgUrl ;
@Schema(description = "推流地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "ws://hik.znkj.ispt.com.cn:559/openUrl/Koe0Kg8")
private String streamUrl ;

View File

@ -0,0 +1,21 @@
package cn.iocoder.yudao.module.smartfactory.controller.admin.screendata.factory.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "大屏工厂数据分析 VO")
@Data
public class ScreenTotalDataVO {
@Schema(description = "类型")
private Integer dateType;
@Schema(description = "入库")
private Integer inNum;
@Schema(description = "出库")
private Integer outNum;
@Schema(description = "破损")
private Integer damageNum;
}

View File

@ -0,0 +1,33 @@
package cn.iocoder.yudao.module.smartfactory.convert.cameradevice;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.smartfactory.controller.admin.device.cameradevice.vo.CameraSimpleRespVO;
import cn.iocoder.yudao.module.smartfactory.controller.admin.factoryinfo.vo.FactorySimpleRespVO;
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.device.cameradevice.CameraDeviceDO;
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.factoryinfo.FactoryInfoDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
import java.util.Map;
@Mapper
public interface CameraDeviceConvert {
CameraDeviceConvert INSTANCE = Mappers.getMapper(CameraDeviceConvert.class);
default List<FactorySimpleRespVO> convertList(List<FactoryInfoDO> infoDOS, Map<Long, List<CameraDeviceDO>> cameraMap) {
return CollectionUtils.convertList(infoDOS, data -> convert(data, cameraMap.get(data.getId())));
}
default FactorySimpleRespVO convert(FactoryInfoDO infoDO, List<CameraDeviceDO> cameraDeviceDOS) {
FactorySimpleRespVO respVO = BeanUtils.toBean(infoDO, FactorySimpleRespVO.class);
List<CameraSimpleRespVO> cameraList = BeanUtils.toBean(cameraDeviceDOS, CameraSimpleRespVO.class);
return respVO.setSubsidiary(cameraList);
}
}

View File

@ -54,6 +54,10 @@ public class CameraDeviceDO extends BaseDO {
* 流媒体地址
*/
private String streamUrl;
/**
* 排序
*/
private Integer sort;
/**
* 是否在大屏显示 0否 1是
*/

View File

@ -23,7 +23,7 @@ public interface CameraDeviceMapper extends BaseMapperX<CameraDeviceDO> {
.eqIfPresent(CameraDeviceDO::getType, reqVO.getType())
.eqIfPresent(CameraDeviceDO::getStatus, reqVO.getStatus())
.betweenIfPresent(CameraDeviceDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(CameraDeviceDO::getId));
.orderByAsc(CameraDeviceDO::getSort));
}
}

View File

@ -1,9 +1,13 @@
package cn.iocoder.yudao.module.smartfactory.service.device.cameradevice;
import javax.validation.*;
import cn.iocoder.yudao.module.smartfactory.controller.admin.device.cameradevice.vo.*;
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.device.cameradevice.CameraDeviceDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.smartfactory.controller.admin.device.cameradevice.vo.CameraDevicePageReqVO;
import cn.iocoder.yudao.module.smartfactory.controller.admin.device.cameradevice.vo.CameraDeviceSaveReqVO;
import cn.iocoder.yudao.module.smartfactory.controller.admin.device.cameradevice.vo.CameraUpdateStatusReqVO;
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.device.cameradevice.CameraDeviceDO;
import javax.validation.Valid;
import java.util.List;
/**
* 设备-监控摄像头 Service 接口
@ -50,4 +54,23 @@ public interface CameraDeviceService {
*/
PageResult<CameraDeviceDO> getCameraDevicePage(CameraDevicePageReqVO pageReqVO);
/**
* 获得指定工厂下的监控摄像头列表
* @param factoryId 工厂编号
* @return 监控摄像头列表
*/
List<CameraDeviceDO> getListCameraByFactoryId(Long factoryId);
/**
* 获得指定监控摄像头列表
* @param factoryIds 工厂编号
* @return 监控摄像头列表
*/
List<CameraDeviceDO> getListCameraList(List<Long> factoryIds);
/**
* 更新监控设备状态
* @param updateReqVO 更新信息
*/
void updateCameraDeviceStatus(CameraUpdateStatusReqVO updateReqVO);
}

View File

@ -4,12 +4,14 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.smartfactory.controller.admin.device.cameradevice.vo.CameraDevicePageReqVO;
import cn.iocoder.yudao.module.smartfactory.controller.admin.device.cameradevice.vo.CameraDeviceSaveReqVO;
import cn.iocoder.yudao.module.smartfactory.controller.admin.device.cameradevice.vo.CameraUpdateStatusReqVO;
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.device.cameradevice.CameraDeviceDO;
import cn.iocoder.yudao.module.smartfactory.dal.mysql.device.cameradevice.CameraDeviceMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.smartfactory.enums.ErrorCodeConstants.CAMERA_DEVICE_NOT_EXISTS;
@ -68,4 +70,25 @@ public class CameraDeviceServiceImpl implements CameraDeviceService {
return cameraDeviceMapper.selectPage(pageReqVO);
}
@Override
public List<CameraDeviceDO> getListCameraByFactoryId(Long factoryId) {
return cameraDeviceMapper.selectList(CameraDeviceDO::getFactoryId, factoryId);
}
@Override
public List<CameraDeviceDO> getListCameraList(List<Long> factoryIds) {
return cameraDeviceMapper.selectList(CameraDeviceDO::getFactoryId, factoryIds);
}
@Override
public void updateCameraDeviceStatus(CameraUpdateStatusReqVO updateReqVO) {
// 校验存在
validateCameraDeviceExists(updateReqVO.getId());
// 更新
CameraDeviceDO updateObj = BeanUtils.toBean(updateReqVO, CameraDeviceDO.class);
cameraDeviceMapper.updateById(updateObj);
}
}

View File

@ -251,7 +251,7 @@ public class FactoryDataServiceImpl implements FactoryDataService {
@Override
public FactoryDataTotalVO getDataTotal(Long factoryId, LocalDate[] date) {
return dataMapper.selectDataSum(factoryId, date);
return dataMapper.selectDataSum(factoryId, date) == null ? new FactoryDataTotalVO() : dataMapper.selectDataSum(factoryId, date);
}
@Override

View File

@ -45,7 +45,7 @@ public interface ScreenDataService {
* @param factoryId factoryId是null查询所有工厂运营数据
* @return
*/
OperateDataRespVO getFactoryOperateData(Long factoryId);
List<ScreenTotalDataVO> getFactoryOperateData(Long factoryId);
/**
* 大屏工厂滚屏数据查询

View File

@ -6,8 +6,11 @@ import cn.hutool.core.date.Month;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.smartfactory.controller.admin.factorydata.vo.FactoryDataTotalVO;
import cn.iocoder.yudao.module.smartfactory.controller.admin.screendata.factory.vo.*;
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.device.cameradevice.CameraDeviceDO;
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.factorydata.FactoryDataDO;
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.factorydataoverview.FactoryDataOverviewDO;
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.factoryinfo.FactoryInfoDO;
@ -15,16 +18,22 @@ import cn.iocoder.yudao.module.smartfactory.dal.dataobject.packagedata.PackageDa
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.screenfactoryextra.ScreenFactoryExtraDO;
import cn.iocoder.yudao.module.smartfactory.dal.mysql.factorydataoverview.FactoryDataOverviewMapper;
import cn.iocoder.yudao.module.smartfactory.framework.util.HttpUtil;
import cn.iocoder.yudao.module.smartfactory.service.device.cameradevice.CameraDeviceService;
import cn.iocoder.yudao.module.smartfactory.service.factorydata.FactoryDataService;
import cn.iocoder.yudao.module.smartfactory.service.factorydataoverview.FactoryDataOverviewService;
import cn.iocoder.yudao.module.smartfactory.service.factoryinfo.FactoryInfoService;
import cn.iocoder.yudao.module.smartfactory.service.hik.HikService;
import cn.iocoder.yudao.module.smartfactory.service.packagedata.PackageDataService;
import cn.iocoder.yudao.module.smartfactory.service.screenfactoryextra.ScreenFactoryExtraService;
import cn.iocoder.yudao.module.smartfactory.service.staff.StaffService;
import jodd.util.StringUtil;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.stream.Collectors;
@ -52,6 +61,12 @@ public class ScreenDataServiceImpl implements ScreenDataService {
@Resource
private FactoryDataOverviewMapper factoryDataOverviewMapper;
@Resource
private CameraDeviceService cameraDeviceService;
@Resource
private HikService hikService;
@Override
public List<ProvincesDataRespVO> getProvincesData(String code) {
return factoryInfoService.getProvincesData(code);
@ -68,8 +83,57 @@ public class ScreenDataServiceImpl implements ScreenDataService {
}
@Override
public OperateDataRespVO getFactoryOperateData(Long factoryId) {
return null;
public List<ScreenTotalDataVO> getFactoryOperateData(Long factoryId) {
// 获取当前日期
LocalDate currentDate = LocalDate.now();
// 获取本周的开始日期周一
LocalDate startOfWeek = currentDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
// 获取本周的结束日期周日
LocalDate endOfWeek = currentDate.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
// 获取本月的开始日期
LocalDate startOfMonth = currentDate.with(TemporalAdjusters.firstDayOfMonth());
// 获取本月的结束日期
LocalDate endOfMonth = currentDate.with(TemporalAdjusters.lastDayOfMonth());
// 获取今日出入库总数
FactoryDataTotalVO toDayVO = factoryDataService.getDataTotal(factoryId, new LocalDate[]{currentDate, currentDate});
// 设置今日出入数据
ScreenTotalDataVO toDayTotalDataVO = new ScreenTotalDataVO()
.setDateType(1)
.setInNum(toDayVO.getInTotal())
.setOutNum(toDayVO.getOutTotal())
.setDamageNum(toDayVO.getDamageNum());
// 获取昨日出入库总数
FactoryDataTotalVO yesterdayVO = factoryDataService.getDataTotal(factoryId,
new LocalDate[]{currentDate.minusDays(1), currentDate.minusDays(1)});
// 设置昨日出入数据
ScreenTotalDataVO yesterdayTotalDataVO = new ScreenTotalDataVO()
.setDateType(2)
.setInNum(yesterdayVO.getInTotal())
.setOutNum(yesterdayVO.getOutTotal())
.setDamageNum(yesterdayVO.getDamageNum());
// 获取本周出入库总数
FactoryDataTotalVO weekVO = factoryDataService.getDataTotal(factoryId, new LocalDate[]{startOfWeek, endOfWeek});
// 设置本周出入数据
ScreenTotalDataVO weekTotalDataVO = new ScreenTotalDataVO()
.setDateType(3)
.setInNum(weekVO.getInTotal())
.setOutNum(weekVO.getOutTotal())
.setDamageNum(weekVO.getDamageNum());
// 获取本月出入库总数
FactoryDataTotalVO monthVO = factoryDataService.getDataTotal(factoryId, new LocalDate[]{startOfMonth, endOfMonth});
// 设置本月出入数据
ScreenTotalDataVO monthTotalDataVO = new ScreenTotalDataVO()
.setDateType(4)
.setInNum(monthVO.getInTotal())
.setOutNum(monthVO.getOutTotal())
.setDamageNum(monthVO.getDamageNum());
return Arrays.asList(toDayTotalDataVO, yesterdayTotalDataVO, weekTotalDataVO, monthTotalDataVO);
}
@Override
@ -79,7 +143,16 @@ public class ScreenDataServiceImpl implements ScreenDataService {
@Override
public List<FactoryCameraDataRespVO> getFactoryCamerasData(Long factoryId) {
return null;
List<CameraDeviceDO> cameraDeviceDOS = cameraDeviceService.getListCameraByFactoryId(factoryId);
cameraDeviceDOS.forEach(data -> {
String url = hikService.getPreviewUrlsApi(data.getCode(), 1);
if (!StringUtil.isEmpty(url)) {
data.setStreamUrl(url);
}
});
return BeanUtils.toBean(cameraDeviceDOS, FactoryCameraDataRespVO.class);
}
@ -316,33 +389,34 @@ public class ScreenDataServiceImpl implements ScreenDataService {
public ObtainFactoryInboundAndOutboundStatusVO getObtainFactoryInboundAndOutboundStatus(Long factoryId) {
ObtainFactoryInboundAndOutboundStatusVO vo = new ObtainFactoryInboundAndOutboundStatusVO();
Date today = new Date();
//本日打包数
Date beginDay = DateUtil.beginOfDay(today);
Date endDay = DateUtil.endOfDay(today);
// 获取当前日期
LocalDate currentDate = LocalDate.now();
// 获取本月的开始日期
LocalDate startOfMonth = currentDate.with(TemporalAdjusters.firstDayOfMonth());
// 获取本月的结束日期
LocalDate endOfMonth = currentDate.with(TemporalAdjusters.lastDayOfMonth());
List<FactoryDataDO> dayList = factoryDataService.getByTimeAndFactoryId(factoryId, beginDay, endDay);
Integer outTotalNum = dayList.stream().filter(a -> a.getDataType() == 1).mapToInt(FactoryDataDO::getTotalNum).sum();
Integer inTotalNum = dayList.stream().filter(a -> a.getDataType() == 2).mapToInt(FactoryDataDO::getTotalNum).sum();
vo.setOutToday(outTotalNum);
vo.setInToday(inTotalNum);
// 获取今日出入库总数
FactoryDataTotalVO toDayVO = factoryDataService.getDataTotal(factoryId, new LocalDate[]{currentDate, currentDate});
vo.setOutToday(toDayVO.getOutTotal());
vo.setInToday(toDayVO.getInTotal());
//本月打包數
Date beginMonth = DateUtil.beginOfMonth(today);
Date endMonth = DateUtil.endOfMonth(today);
List<FactoryDataDO> monthList = factoryDataService.getByTimeAndFactoryId(factoryId, beginMonth, endMonth);
Integer outMonthNum = monthList.stream().filter(a -> a.getDataType() == 1).mapToInt(FactoryDataDO::getTotalNum).sum();
Integer inMonthNum = monthList.stream().filter(a -> a.getDataType() == 2).mapToInt(FactoryDataDO::getTotalNum).sum();
vo.setOutMonth(outMonthNum);
vo.setInMonth(inMonthNum);
Random random = new Random();
int randomNumber = random.nextInt(21); // 生成0到20之间的随机数
vo.setDamagedTotal(randomNumber);
FactoryDataTotalVO monthVO = factoryDataService.getDataTotal(factoryId, new LocalDate[]{startOfMonth, endOfMonth});
vo.setOutMonth(monthVO.getOutTotal());
vo.setInMonth(monthVO.getInTotal());
random = new Random();
double increaseCompared = (random.nextDouble() * 4) - 2; // 生成-2到2之间的随机数
increaseCompared = Math.round(increaseCompared * 100.0) / 100.0; // 保留两位小数
// 获取昨日出入库总数
FactoryDataTotalVO yesterdayVO = factoryDataService.getDataTotal(factoryId,
new LocalDate[]{currentDate.minusDays(1), currentDate.minusDays(1)});
// 设置今日破损数
vo.setDamagedTotal(toDayVO.getDamageNum());
// 设置同昨日比较 百分比
double increaseCompared = Math.round(toDayVO.getDamageNum() - yesterdayVO.getDamageNum() * 100.0) / 100.0; // 保留两位小数
vo.setIncreaseCompared(increaseCompared);
return vo;
}
}